4 * Internals for the memory allocator
12 * This is a temporary hack. In Syslinux 5 this will be a pointer to
15 typedef size_t malloc_tag_t
;
23 struct free_arena_header
;
26 * This structure should be a power of two. This becomes the
31 size_t attrs
; /* Bits 0..1: Type
33 4..31: MSB of the size */
34 struct free_arena_header
*next
, *prev
;
49 #define ARENA_SIZE_MASK (~(uintptr_t)(sizeof(struct arena_header)-1))
50 #define ARENA_HEAP_MASK ((size_t)0xc)
51 #define ARENA_HEAP_POS 2
52 #define ARENA_TYPE_MASK ((size_t)0x3)
54 #define ARENA_ALIGN_UP(p) ((char *)(((uintptr_t)(p) + ~ARENA_SIZE_MASK) \
56 #define ARENA_ALIGN_DOWN(p) ((char *)((uintptr_t)(p) & ARENA_SIZE_MASK))
58 #define ARENA_SIZE_GET(attrs) ((attrs) & ARENA_SIZE_MASK)
59 #define ARENA_HEAP_GET(attrs) (((attrs) & ARENA_HEAP_MASK) >> ARENA_HEAP_POS)
60 #define ARENA_TYPE_GET(attrs) ((attrs) & ARENA_TYPE_MASK)
62 #define ARENA_SIZE_SET(attrs, size) \
63 ((attrs) = ((size) & ARENA_SIZE_MASK) | ((attrs) & ~ARENA_SIZE_MASK))
64 #define ARENA_HEAP_SET(attrs, heap) \
65 ((attrs) = (((heap) << ARENA_HEAP_POS) & ARENA_HEAP_MASK) | \
66 ((attrs) & ~ARENA_HEAP_MASK))
67 #define ARENA_TYPE_SET(attrs, type) \
68 ((attrs) = ((attrs) & ~ARENA_TYPE_MASK) | \
69 ((type) & ARENA_TYPE_MASK))
72 * This structure should be no more than twice the size of the
75 struct free_arena_header
{
76 struct arena_header a
;
77 struct free_arena_header
*next_free
, *prev_free
;
78 size_t _pad
[2]; /* Pad to 2*sizeof(struct arena_header) */
81 extern struct free_arena_header __malloc_head
[NHEAP
];
82 void __inject_free_block(struct free_arena_header
*ah
);