1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include <sys/cdefs.h>
- #define MIN(x,y) ({ \
- const typeof(x) _x = (x); \
- const typeof(y) _y = (y); \
- (void) (&_x == &_y); \
- _x < _y ? _x : _y; })
- #define INT_BIT (CHAR_BIT * sizeof (size_t))
- #define BLOCKLOG (INT_BIT > 16 ? 12 : 9)
- #define BLOCKSIZE (1 << BLOCKLOG)
- #define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
- #define HEAP (INT_BIT > 16 ? 4194304 : 65536)
- #define FINAL_FREE_BLOCKS 8
- union info {
- struct {
- size_t type;
- union {
- struct {
- size_t nfree;
- size_t first;
- } frag;
- size_t size;
- } info;
- } busy;
- struct {
- size_t size;
- size_t next;
- size_t prev;
- } free;
- };
- #define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1)
- #define ADDRESS(B) ((void *) (((B) - 1) * BLOCKSIZE + _heapbase))
- struct list {
- struct list *next;
- struct list *prev;
- };
- struct alignlist
- {
- struct alignlist *next;
- __ptr_t aligned;
- __ptr_t exact;
- };
- extern struct alignlist *_aligned_blocks;
- extern char *_heapbase;
- extern union info *_heapinfo;
- extern size_t _heapindex;
- extern size_t _heaplimit;
- extern void *__malloc_unlocked (size_t size);
- extern void __free_unlocked(void *ptr);
|