multi_heap_internal.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. /* Opaque handle to a heap block */
  15. typedef const struct heap_block *multi_heap_block_handle_t;
  16. /* Internal definitions for the "implementation" of the multi_heap API,
  17. as defined in multi_heap.c.
  18. If heap poisioning is disabled, these are aliased directly to the public API.
  19. If heap poisoning is enabled, wrapper functions call each of these.
  20. */
  21. void *multi_heap_malloc_impl(multi_heap_handle_t heap, size_t size);
  22. void *multi_heap_aligned_alloc_impl(multi_heap_handle_t heap, size_t size, size_t alignment);
  23. void multi_heap_free_impl(multi_heap_handle_t heap, void *p);
  24. void multi_heap_aligned_free_impl(multi_heap_handle_t heap, void *p);
  25. void *multi_heap_realloc_impl(multi_heap_handle_t heap, void *p, size_t size);
  26. multi_heap_handle_t multi_heap_register_impl(void *start, size_t size);
  27. void multi_heap_get_info_impl(multi_heap_handle_t heap, multi_heap_info_t *info);
  28. size_t multi_heap_free_size_impl(multi_heap_handle_t heap);
  29. size_t multi_heap_minimum_free_size_impl(multi_heap_handle_t heap);
  30. size_t multi_heap_get_allocated_size_impl(multi_heap_handle_t heap, void *p);
  31. void *multi_heap_get_block_address_impl(multi_heap_block_handle_t block);
  32. /* Some internal functions for heap poisoning use */
  33. /* Check an allocated block's poison bytes are correct. Called by multi_heap_check(). */
  34. bool multi_heap_internal_check_block_poisoning(void *start, size_t size, bool is_free, bool print_errors);
  35. /* Fill a region of memory with the free or malloced pattern.
  36. Called when merging blocks, to overwrite the old block header.
  37. */
  38. void multi_heap_internal_poison_fill_region(void *start, size_t size, bool is_free);
  39. /* Allow heap poisoning to lock/unlock the heap to avoid race conditions
  40. if multi_heap_check() is running concurrently.
  41. */
  42. void multi_heap_internal_lock(multi_heap_handle_t heap);
  43. void multi_heap_internal_unlock(multi_heap_handle_t heap);
  44. /* Some internal functions for heap debugging code to use */
  45. /* Get the handle to the first (fixed free) block in a heap */
  46. multi_heap_block_handle_t multi_heap_get_first_block(multi_heap_handle_t heap);
  47. /* Get the handle to the next block in a heap, with validation */
  48. multi_heap_block_handle_t multi_heap_get_next_block(multi_heap_handle_t heap, multi_heap_block_handle_t block);
  49. /* Test if a heap block is free */
  50. bool multi_heap_is_free(const multi_heap_block_handle_t block);
  51. /* Get the data address of a heap block */
  52. void *multi_heap_get_block_address(multi_heap_block_handle_t block);
  53. /* Get the owner identification for a heap block */
  54. void *multi_heap_get_block_owner(multi_heap_block_handle_t block);