123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- #define MALLOC_ALIGNMENT \
- (__alignof__ (double) > sizeof (size_t) ? __alignof__ (double) : sizeof (size_t))
- #define MALLOC_PAGE_SIZE sysconf(_SC_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_free_area *__malloc_mmb_heap;
- #ifdef MALLOC_MMB_DEBUGGING
- # include <stdio.h>
- 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 < sizeof (size_t) \
- ? sizeof (size_t) \
- : 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))
- #include <bits/uClibc_mutex.h>
- #ifdef __UCLIBC_HAS_THREADS__
- # define MALLOC_USE_LOCKING
- #endif
- #ifdef MALLOC_USE_SBRK
- __UCLIBC_MUTEX_EXTERN(__malloc_sbrk_lock) attribute_hidden;
- # define __malloc_lock_sbrk() __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE (__malloc_sbrk_lock)
- # define __malloc_unlock_sbrk() __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE (__malloc_sbrk_lock)
- #else
- # define __malloc_lock_sbrk() (void)0
- # define __malloc_unlock_sbrk() (void)0
- #endif
- #ifdef MALLOC_DEBUGGING
- extern void __malloc_debug_init (void) attribute_hidden;
- #define MALLOC_DEBUG_INDENT_SIZE 3
- extern int __malloc_debug attribute_hidden, __malloc_check attribute_hidden;
- # 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 attribute_hidden;
- extern void __malloc_debug_printf (int indent, const char *fmt, ...) attribute_hidden;
- #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_free_area *__malloc_heap attribute_hidden;
- #ifdef __UCLIBC_HAS_THREADS__
- __UCLIBC_MUTEX_EXTERN(__malloc_heap_lock)
- # ifndef __LINUXTHREADS_OLD__
- attribute_hidden
- # endif
- ;
- # ifdef __UCLIBC_UCLINUX_BROKEN_MUNMAP__
- __UCLIBC_MUTEX_EXTERN(__malloc_mmb_heap_lock)
- # ifndef __LINUXTHREADS_OLD__
- attribute_hidden
- # endif
- ;
- # endif
- #endif
|