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 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #pragma once 15 16 #define MULTI_HEAP_DEFAULT_INT_LOCK (1) 17 18 /* Opaque handle to a heap block */ 19 typedef const struct heap_block *multi_heap_block_handle_t; 20 21 /* Internal definitions for the "implementation" of the multi_heap API, 22 as defined in multi_heap.c. 23 24 If heap poisioning is disabled, these are aliased directly to the public API. 25 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 void multi_heap_free_impl(multi_heap_handle_t heap, void *p); 30 void *multi_heap_realloc_impl(multi_heap_handle_t heap, void *p, size_t size); 31 multi_heap_handle_t multi_heap_register_impl(void *start, size_t size); 32 void multi_heap_get_info_impl(multi_heap_handle_t heap, multi_heap_info_t *info); 33 size_t multi_heap_free_size_impl(multi_heap_handle_t heap); 34 size_t multi_heap_minimum_free_size_impl(multi_heap_handle_t heap); 35 size_t multi_heap_get_allocated_size_impl(multi_heap_handle_t heap, void *p); 36 void *multi_heap_get_block_address_impl(multi_heap_block_handle_t block); 37 38 /* Some internal functions for heap poisoning use */ 39 40 /* Check an allocated block's poison bytes are correct. Called by multi_heap_check(). */ 41 bool multi_heap_internal_check_block_poisoning(void *start, size_t size, bool is_free, bool print_errors); 42 43 /* Fill a region of memory with the free or malloced pattern. 44 Called when merging blocks, to overwrite the old block header. 45 */ 46 void multi_heap_internal_poison_fill_region(void *start, size_t size, bool is_free); 47 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 53 void multi_heap_internal_unlock(multi_heap_handle_t heap); 54 55 /* Some internal functions for heap debugging code to use */ 56 57 /* Get the handle to the first (fixed free) block in a heap */ 58 multi_heap_block_handle_t multi_heap_get_first_block(multi_heap_handle_t heap); 59 60 /* Get the handle to the next block in a heap, with validation */ 61 multi_heap_block_handle_t multi_heap_get_next_block(multi_heap_handle_t heap, multi_heap_block_handle_t block); 62 63 /* Test if a heap block is free */ 64 bool multi_heap_is_free(const multi_heap_block_handle_t block); 65 66 /* Get the data address of a heap block */ 67 void *multi_heap_get_block_address(multi_heap_block_handle_t block); 68 69 /* Get the owner identification for a heap block */ 70 void *multi_heap_get_block_owner(multi_heap_block_handle_t block); 71