1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CHRE_PLATFORM_HEAP_BLOCK_HEADER_H_ 18 #define CHRE_PLATFORM_HEAP_BLOCK_HEADER_H_ 19 20 #include <cstddef> 21 #include <cstdint> 22 23 namespace chre { 24 25 /** 26 * Header to store allocation details for tracking. 27 * We use a union to ensure proper memory alignment. 28 */ 29 union HeapBlockHeader { 30 struct { 31 /** 32 * Pointer to the next header (to form a linked list). 33 * @see mFirstHeader 34 */ 35 HeapBlockHeader *next = nullptr; 36 37 //! The amount of memory in bytes allocated (not including header). 38 uint32_t bytes; 39 40 //! The ID of nanoapp requesting memory allocation. 41 uint16_t instanceId; 42 } data; 43 44 //! Makes sure header is a multiple of the size of max_align_t 45 max_align_t aligner; 46 }; 47 48 } // namespace chre 49 50 #endif // CHRE_PLATFORM_HEAP_BLOCK_HEADER_H_ 51