multi_heap_internal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. /* Define a structure that contains some function pointers that point to OS-related functions.
  8. An instance of this structure will be provided to the heap in ROM for use if needed.
  9. */
  10. typedef struct {
  11. void (*lock)(void *lock);
  12. void (*unlock)(void *lock);
  13. } multi_heap_os_funcs_t;
  14. /** @brief Initialize structure pointer that points a structure that contains OS-related functions pointers.
  15. *
  16. * @param heap_os_funcs Points to a structure that contains some OS-related function pointers.
  17. * @return None.
  18. *
  19. */
  20. void multi_heap_os_funcs_init(multi_heap_os_funcs_t *heap_os_funcs);
  21. /* Opaque handle to a heap block */
  22. typedef const struct block_header_t *multi_heap_block_handle_t;
  23. /* Internal definitions for the "implementation" of the multi_heap API,
  24. as defined in multi_heap.c.
  25. If heap poisioning is disabled, these are aliased directly to the public API.
  26. If heap poisoning is enabled, wrapper functions call each of these.
  27. */
  28. void *multi_heap_malloc_impl(multi_heap_handle_t heap, size_t size);
  29. /* Allocate a memory region of minimum `size` bytes, aligned on `alignment`. */
  30. void *multi_heap_aligned_alloc_impl(multi_heap_handle_t heap, size_t size, size_t alignment);
  31. /* Allocate a memory region of minimum `size` bytes, where memory's `offset` is aligned on `alignment`. */
  32. void *multi_heap_aligned_alloc_impl_offs(multi_heap_handle_t heap, size_t size, size_t alignment, size_t offset);
  33. void multi_heap_free_impl(multi_heap_handle_t heap, void *p);
  34. void *multi_heap_realloc_impl(multi_heap_handle_t heap, void *p, size_t size);
  35. multi_heap_handle_t multi_heap_register_impl(void *start, size_t size);
  36. void multi_heap_get_info_impl(multi_heap_handle_t heap, multi_heap_info_t *info);
  37. size_t multi_heap_free_size_impl(multi_heap_handle_t heap);
  38. size_t multi_heap_minimum_free_size_impl(multi_heap_handle_t heap);
  39. size_t multi_heap_get_allocated_size_impl(multi_heap_handle_t heap, void *p);
  40. void *multi_heap_get_block_address_impl(multi_heap_block_handle_t block);
  41. /* Some internal functions for heap poisoning use */
  42. /* Check an allocated block's poison bytes are correct. Called by multi_heap_check(). */
  43. bool multi_heap_internal_check_block_poisoning(void *start, size_t size, bool is_free, bool print_errors);
  44. /* Fill a region of memory with the free or malloced pattern.
  45. Called when merging blocks, to overwrite the old block header.
  46. */
  47. void multi_heap_internal_poison_fill_region(void *start, size_t size, bool is_free);
  48. /* Allow heap poisoning to lock/unlock the heap to avoid race conditions
  49. if multi_heap_check() is running concurrently.
  50. */
  51. void multi_heap_internal_lock(multi_heap_handle_t heap);
  52. void multi_heap_internal_unlock(multi_heap_handle_t heap);
  53. /* Some internal functions for heap debugging code to use */
  54. /* Get the handle to the first (fixed free) block in a heap */
  55. multi_heap_block_handle_t multi_heap_get_first_block(multi_heap_handle_t heap);
  56. /* Get the handle to the next block in a heap, with validation */
  57. multi_heap_block_handle_t multi_heap_get_next_block(multi_heap_handle_t heap, multi_heap_block_handle_t block);
  58. /* Test if a heap block is free */
  59. bool multi_heap_is_free(const multi_heap_block_handle_t block);
  60. /* Get the data address of a heap block */
  61. void *multi_heap_get_block_address(multi_heap_block_handle_t block);
  62. /* Get the owner identification for a heap block */
  63. void *multi_heap_get_block_owner(multi_heap_block_handle_t block);