4 * Internals for the memory allocator
12 extern struct semaphore __malloc_semaphore
;
15 * This is a temporary hack. In Syslinux 5 this will be a pointer to
18 typedef size_t malloc_tag_t
;
38 #define ARENA_MAGIC 0x20130117
40 struct free_arena_header
;
43 * This structure should be a power of two. This becomes the
48 size_t attrs
; /* Bits 0..1: Type
50 4..31: MSB of the size */
51 struct free_arena_header
*next
, *prev
;
54 unsigned long _pad
[3];
59 /* Pad to 2*sizeof(struct arena_header) */
60 #define ARENA_PADDING ((2 * sizeof(struct arena_header)) - \
61 (sizeof(struct arena_header) + \
62 sizeof(struct free_arena_header *) + \
63 sizeof(struct free_arena_header *)))
66 * This structure should be no more than twice the size of the
69 struct free_arena_header
{
70 struct arena_header a
;
71 struct free_arena_header
*next_free
, *prev_free
;
72 size_t _pad
[ARENA_PADDING
];
75 #define ARENA_SIZE_MASK (~(uintptr_t)(sizeof(struct arena_header)-1))
76 #define ARENA_HEAP_MASK ((size_t)0xc)
77 #define ARENA_HEAP_POS 2
78 #define ARENA_TYPE_MASK ((size_t)0x3)
80 #define ARENA_ALIGN_UP(p) ((char *)(((uintptr_t)(p) + ~ARENA_SIZE_MASK) \
82 #define ARENA_ALIGN_DOWN(p) ((char *)((uintptr_t)(p) & ARENA_SIZE_MASK))
84 #define ARENA_SIZE_GET(attrs) ((attrs) & ARENA_SIZE_MASK)
85 #define ARENA_HEAP_GET(attrs) (((attrs) & ARENA_HEAP_MASK) >> ARENA_HEAP_POS)
86 #define ARENA_TYPE_GET(attrs) ((attrs) & ARENA_TYPE_MASK)
88 #define ARENA_SIZE_SET(attrs, size) \
89 ((attrs) = ((size) & ARENA_SIZE_MASK) | ((attrs) & ~ARENA_SIZE_MASK))
90 #define ARENA_HEAP_SET(attrs, heap) \
91 ((attrs) = (((heap) << ARENA_HEAP_POS) & ARENA_HEAP_MASK) | \
92 ((attrs) & ~ARENA_HEAP_MASK))
93 #define ARENA_TYPE_SET(attrs, type) \
94 ((attrs) = ((attrs) & ~ARENA_TYPE_MASK) | \
95 ((type) & ARENA_TYPE_MASK))
97 extern struct free_arena_header __core_malloc_head
[NHEAP
];
98 void __inject_free_block(struct free_arena_header
*ah
);