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 /* Opaque handle to a heap block */
17 typedef const struct block_header_t *multi_heap_block_handle_t;
18 
19 /* Internal definitions for the "implementation" of the multi_heap API,
20    as defined in multi_heap.c.
21 
22    If heap poisioning is disabled, these are aliased directly to the public API.
23 
24    If heap poisoning is enabled, wrapper functions call each of these.
25 */
26 
27 void *multi_heap_malloc_impl(multi_heap_handle_t heap, size_t size);
28 
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 
32 /* Allocate a memory region of minimum `size` bytes, where memory's `offset` is aligned on `alignment`. */
33 void *multi_heap_aligned_alloc_impl_offs(multi_heap_handle_t heap, size_t size, size_t alignment, size_t offset);
34 
35 void multi_heap_free_impl(multi_heap_handle_t heap, void *p);
36 void *multi_heap_realloc_impl(multi_heap_handle_t heap, void *p, size_t size);
37 multi_heap_handle_t multi_heap_register_impl(void *start, size_t size);
38 void multi_heap_get_info_impl(multi_heap_handle_t heap, multi_heap_info_t *info);
39 size_t multi_heap_free_size_impl(multi_heap_handle_t heap);
40 size_t multi_heap_minimum_free_size_impl(multi_heap_handle_t heap);
41 size_t multi_heap_get_allocated_size_impl(multi_heap_handle_t heap, void *p);
42 void *multi_heap_get_block_address_impl(multi_heap_block_handle_t block);
43 
44 /* Some internal functions for heap poisoning use */
45 
46 /* Check an allocated block's poison bytes are correct. Called by multi_heap_check(). */
47 bool multi_heap_internal_check_block_poisoning(void *start, size_t size, bool is_free, bool print_errors);
48 
49 /* Fill a region of memory with the free or malloced pattern.
50    Called when merging blocks, to overwrite the old block header.
51 */
52 void multi_heap_internal_poison_fill_region(void *start, size_t size, bool is_free);
53 
54 /* Allow heap poisoning to lock/unlock the heap to avoid race conditions
55    if multi_heap_check() is running concurrently.
56 */
57 void multi_heap_internal_lock(multi_heap_handle_t heap);
58 
59 void multi_heap_internal_unlock(multi_heap_handle_t heap);
60 
61 /* Some internal functions for heap debugging code to use */
62 
63 /* Get the handle to the first (fixed free) block in a heap */
64 multi_heap_block_handle_t multi_heap_get_first_block(multi_heap_handle_t heap);
65 
66 /* Get the handle to the next block in a heap, with validation */
67 multi_heap_block_handle_t multi_heap_get_next_block(multi_heap_handle_t heap, multi_heap_block_handle_t block);
68 
69 /* Test if a heap block is free */
70 bool multi_heap_is_free(const multi_heap_block_handle_t block);
71 
72 /* Get the data address of a heap block */
73 void *multi_heap_get_block_address(multi_heap_block_handle_t block);
74 
75 /* Get the owner identification for a heap block */
76 void *multi_heap_get_block_owner(multi_heap_block_handle_t block);
77