multi_heap_internal.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 block_header_t *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. /* Allocate a memory region of minimum `size` bytes, aligned on `alignment`. */
  23. void *multi_heap_aligned_alloc_impl(multi_heap_handle_t heap, size_t size, size_t alignment);
  24. /* Allocate a memory region of minimum `size` bytes, where memory's `offset` is aligned on `alignment`. */
  25. void *multi_heap_aligned_alloc_impl_offs(multi_heap_handle_t heap, size_t size, size_t alignment, size_t offset);
  26. void multi_heap_free_impl(multi_heap_handle_t heap, void *p);
  27. void *multi_heap_realloc_impl(multi_heap_handle_t heap, void *p, size_t size);
  28. multi_heap_handle_t multi_heap_register_impl(void *start, size_t size);
  29. void multi_heap_get_info_impl(multi_heap_handle_t heap, multi_heap_info_t *info);
  30. size_t multi_heap_free_size_impl(multi_heap_handle_t heap);
  31. size_t multi_heap_minimum_free_size_impl(multi_heap_handle_t heap);
  32. size_t multi_heap_get_allocated_size_impl(multi_heap_handle_t heap, void *p);
  33. void *multi_heap_get_block_address_impl(multi_heap_block_handle_t block);
  34. /* Some internal functions for heap poisoning use */
  35. /* Check an allocated block's poison bytes are correct. Called by multi_heap_check(). */
  36. bool multi_heap_internal_check_block_poisoning(void *start, size_t size, bool is_free, bool print_errors);
  37. /* Fill a region of memory with the free or malloced pattern.
  38. Called when merging blocks, to overwrite the old block header.
  39. */
  40. void multi_heap_internal_poison_fill_region(void *start, size_t size, bool is_free);
  41. /* Allow heap poisoning to lock/unlock the heap to avoid race conditions
  42. if multi_heap_check() is running concurrently.
  43. */
  44. void multi_heap_internal_lock(multi_heap_handle_t heap);
  45. void multi_heap_internal_unlock(multi_heap_handle_t heap);
  46. /* Some internal functions for heap debugging code to use */
  47. /* Get the handle to the first (fixed free) block in a heap */
  48. multi_heap_block_handle_t multi_heap_get_first_block(multi_heap_handle_t heap);
  49. /* Get the handle to the next block in a heap, with validation */
  50. multi_heap_block_handle_t multi_heap_get_next_block(multi_heap_handle_t heap, multi_heap_block_handle_t block);
  51. /* Test if a heap block is free */
  52. bool multi_heap_is_free(const multi_heap_block_handle_t block);
  53. /* Get the data address of a heap block */
  54. void *multi_heap_get_block_address(multi_heap_block_handle_t block);
  55. /* Get the owner identification for a heap block */
  56. void *multi_heap_get_block_owner(multi_heap_block_handle_t block);