File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 3333 * field accessors since we can't use natural syntax.
3434 *
3535 * The fields are:
36- * SIZE_AND_USED: the total size (including header) of the chunk in
37- * 8-byte units. The bottom bit stores a "used" flag.
3836 * LEFT_SIZE: The size of the left (next lower chunk in memory)
3937 * neighbor chunk.
38+ * SIZE_AND_USED: the total size (including header) of the chunk in
39+ * 8-byte units. The bottom bit stores a "used" flag.
4040 * FREE_PREV: Chunk ID of the previous node in a free list.
4141 * FREE_NEXT: Chunk ID of the next node in a free list.
4242 *
4343 * The free lists are circular lists, one for each power-of-two size
4444 * category. The free list pointers exist only for free chunks,
4545 * obviously. This memory is part of the user's buffer when
4646 * allocated.
47+ *
48+ * The field order is so that allocated buffers are immediately bounded
49+ * by SIZE_AND_USED of the current chunk at the bottom, and LEFT_SIZE of
50+ * the following chunk at the top. This ordering allows for quick buffer
51+ * overflow detection by testing left_chunk(c + chunk_size(c)) == c.
4752 */
4853typedef size_t chunkid_t ;
4954
55+ enum chunk_fields { LEFT_SIZE , SIZE_AND_USED , FREE_PREV , FREE_NEXT };
56+
5057#define CHUNK_UNIT 8U
5158
5259typedef struct { char bytes [CHUNK_UNIT ]; } chunk_unit_t ;
5360
54- enum chunk_fields { LEFT_SIZE , SIZE_AND_USED , FREE_PREV , FREE_NEXT };
55-
5661struct z_heap_bucket {
5762 chunkid_t next ;
5863};
You can’t perform that action at this time.
0 commit comments