123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #define MALLOC_ALIGNMENT (sizeof (double))
- extern size_t __pagesize;
- libc_hidden_proto(__pagesize)
- #define MALLOC_PAGE_SIZE __pagesize
- #define MALLOC_HEAP_EXTEND_SIZE MALLOC_PAGE_SIZE
- #define MALLOC_UNMAP_THRESHOLD (8*MALLOC_PAGE_SIZE)
- #define MALLOC_MIN_SIZE (2*MALLOC_PAGE_SIZE)
- #define MALLOC_REALLOC_MIN_FREE_SIZE (HEAP_MIN_SIZE + 16)
- #ifdef __ARCH_USE_MMU__
- # define MALLOC_USE_SBRK
- #endif
- #ifdef __UCLIBC_UCLINUX_BROKEN_MUNMAP__
- struct malloc_mmb
- {
- void *mem;
- size_t size;
- struct malloc_mmb *next;
- };
- extern struct malloc_mmb *__malloc_mmapped_blocks;
- extern struct heap __malloc_mmb_heap;
- #ifdef MALLOC_MMB_DEBUGGING
- # include <stdio.h>
- extern int __putc(int c, FILE *stream) attribute_hidden;
- extern int __malloc_mmb_debug;
- # define MALLOC_MMB_DEBUG(indent, fmt, args...) \
- (__malloc_mmb_debug ? __malloc_debug_printf (indent, fmt , ##args) : 0)
- # define MALLOC_MMB_DEBUG_INDENT(indent) \
- (__malloc_mmb_debug ? __malloc_debug_indent (indent) : 0)
- # ifndef MALLOC_DEBUGGING
- # define MALLOC_DEBUGGING
- # endif
- #else
- # define MALLOC_MMB_DEBUG(fmt, args...) (void)0
- # define MALLOC_MMB_DEBUG_INDENT(indent) (void)0
- #endif
- #endif
- #define MALLOC_HEADER_SIZE MALLOC_ALIGNMENT
- #define MALLOC_SETUP(base, size) \
- (MALLOC_SET_SIZE (base, size), (void *)((char *)base + MALLOC_HEADER_SIZE))
- #define MALLOC_SET_SIZE(base, size) (*(size_t *)(base) = (size))
- #define MALLOC_BASE(addr) ((void *)((char *)addr - MALLOC_HEADER_SIZE))
- #define MALLOC_SIZE(addr) (*(size_t *)MALLOC_BASE(addr))
- #ifdef __UCLIBC_HAS_THREADS__
- # include <pthread.h>
- # define MALLOC_USE_LOCKING
- typedef pthread_mutex_t malloc_mutex_t;
- # define MALLOC_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
- # ifdef MALLOC_USE_SBRK
- extern malloc_mutex_t __malloc_sbrk_lock;
- # define __malloc_lock_sbrk() __pthread_mutex_lock (&__malloc_sbrk_lock)
- # define __malloc_unlock_sbrk() __pthread_mutex_unlock (&__malloc_sbrk_lock)
- # endif
- #else
- # define __malloc_lock_sbrk() (void)0
- # define __malloc_unlock_sbrk() (void)0
- #endif
- #ifndef likely
- #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
- #define likely(cond) __builtin_expect(!!(int)(cond), 1)
- #define unlikely(cond) __builtin_expect((int)(cond), 0)
- #else
- #define likely(cond) (cond)
- #define unlikely(cond) (cond)
- #endif
- #endif
- #ifdef MALLOC_DEBUGGING
- extern void __malloc_debug_init (void);
- #define MALLOC_DEBUG_INDENT_SIZE 3
- extern int __malloc_debug, __malloc_check;
- # define MALLOC_DEBUG(indent, fmt, args...) \
- (__malloc_debug ? __malloc_debug_printf (indent, fmt , ##args) : 0)
- # define MALLOC_DEBUG_INDENT(indent) \
- (__malloc_debug ? __malloc_debug_indent (indent) : 0)
- extern int __malloc_debug_cur_indent;
- extern void __malloc_debug_printf (int indent, const char *fmt, ...);
- #define __malloc_debug_indent(indent) (__malloc_debug_cur_indent += indent)
- #define __malloc_debug_set_indent(level) (__malloc_debug_cur_indent = level)
- #else
- # define MALLOC_DEBUG(fmt, args...) (void)0
- # define MALLOC_DEBUG_INDENT(indent) (void)0
- #endif
- #define MALLOC_ROUND_DOWN(sz, power_of_2_size) \
- ((sz) & ~(power_of_2_size - 1))
- #define MALLOC_ROUND_UP(sz, power_of_2_size) \
- MALLOC_ROUND_DOWN ((sz) + (power_of_2_size - 1), (power_of_2_size))
- #define MALLOC_ROUND_DOWN_TO_PAGE_SIZE(sz) \
- MALLOC_ROUND_DOWN (sz, MALLOC_PAGE_SIZE)
- #define MALLOC_ROUND_UP_TO_PAGE_SIZE(sz) \
- MALLOC_ROUND_UP (sz, MALLOC_PAGE_SIZE)
- extern struct heap __malloc_heap;
|