3 * Copyright (c) 2021 Project CHIP Authors
4 * Copyright 2019 Google Inc. All Rights Reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <sys/types.h>
26 #include <type_traits>
32 // Initializes the heap (set start and end blocks)
33 void PrivateHeapInit(void * heap, size_t size);
35 // Allocates a new block on the specified heap
36 void * PrivateHeapAlloc(void * heap, size_t size);
38 // Marks the specified block as free
39 void PrivateHeapFree(void * ptr);
41 // Reallocate a block to a new size
43 // - null ptr value represents an Alloc
44 // - zero size represents a Free
45 void * PrivateHeapRealloc(void * heap, void * ptr, size_t size);
47 void PrivateHeapDump(void * ptr);
54 // Heap structure, exposed for tests
56 // +---------+---------+-----+ +---------+-----------+
57 // | prev: 0 | next: n | ... | ....<n_bytes> .... | prev: n | next: ... |
58 // +---------+---------+-----+ +---------+-----------+
60 struct PrivateHeapBlockHeader
65 uint32_t checksum; // super-basic attempt to detect errors
68 } // namespace internal
70 constexpr size_t kPrivateHeapAllocationAlignment = std::alignment_of<max_align_t>::value;
72 #endif // ifdef __cplusplus