SDL  2.0
SDL_malloc.c File Reference
#include "../SDL_internal.h"
#include "SDL_stdinc.h"
#include <windows.h>
+ Include dependency graph for SDL_malloc.c:

Go to the source code of this file.

Data Structures

struct  mallinfo
 
struct  sbinptr
 
struct  tbinptr
 
struct  msegmentptr
 
struct  mstate
 
struct  malloc_params
 

Macros

#define LACKS_SYS_TYPES_H
 
#define LACKS_STDIO_H
 
#define LACKS_STRINGS_H
 
#define LACKS_STRING_H
 
#define LACKS_STDLIB_H
 
#define ABORT
 
#define USE_LOCKS   1
 
#define WIN32   1
 
#define WIN32_LEAN_AND_MEAN
 
#define HAVE_MMAP   1
 
#define HAVE_MORECORE   0
 
#define LACKS_UNISTD_H
 
#define LACKS_SYS_PARAM_H
 
#define LACKS_SYS_MMAN_H
 
#define LACKS_STRING_H
 
#define LACKS_STRINGS_H
 
#define LACKS_SYS_TYPES_H
 
#define LACKS_ERRNO_H
 
#define LACKS_FCNTL_H
 
#define MALLOC_FAILURE_ACTION
 
#define MMAP_CLEARS   0 /* WINCE and some others apparently don't clear */
 
#define MAX_SIZE_T   (~(size_t)0)
 
#define ONLY_MSPACES   0
 
#define MSPACES   0
 
#define MALLOC_ALIGNMENT   ((size_t)8U)
 
#define FOOTERS   0
 
#define ABORT_ON_ASSERT_FAILURE   1
 
#define PROCEED_ON_ERROR   0
 
#define INSECURE   0
 
#define HAVE_MREMAP   0
 
#define MORECORE_CONTIGUOUS   0
 
#define DEFAULT_GRANULARITY   ((size_t)64U * (size_t)1024U)
 
#define DEFAULT_TRIM_THRESHOLD   ((size_t)2U * (size_t)1024U * (size_t)1024U)
 
#define DEFAULT_MMAP_THRESHOLD   ((size_t)256U * (size_t)1024U)
 
#define USE_BUILTIN_FFS   0
 
#define USE_DEV_RANDOM   0
 
#define NO_MALLINFO   0
 
#define MALLINFO_FIELD_TYPE   size_t
 
#define memset   SDL_memset
 
#define memcpy   SDL_memcpy
 
#define malloc   SDL_malloc
 
#define calloc   SDL_calloc
 
#define realloc   SDL_realloc
 
#define free   SDL_free
 
#define M_TRIM_THRESHOLD   (-1)
 
#define M_GRANULARITY   (-2)
 
#define M_MMAP_THRESHOLD   (-3)
 
#define dlcalloc   calloc
 
#define dlfree   free
 
#define dlmalloc   malloc
 
#define dlmemalign   memalign
 
#define dlrealloc   realloc
 
#define dlvalloc   valloc
 
#define dlpvalloc   pvalloc
 
#define dlmallinfo   mallinfo
 
#define dlmallopt   mallopt
 
#define dlmalloc_trim   malloc_trim
 
#define dlmalloc_stats   malloc_stats
 
#define dlmalloc_usable_size   malloc_usable_size
 
#define dlmalloc_footprint   malloc_footprint
 
#define dlmalloc_max_footprint   malloc_max_footprint
 
#define dlindependent_calloc   independent_calloc
 
#define dlindependent_comalloc   independent_comalloc
 
#define assert(x)
 
#define SIZE_T_SIZE   (sizeof(size_t))
 
#define SIZE_T_BITSIZE   (sizeof(size_t) << 3)
 
#define SIZE_T_ZERO   ((size_t)0)
 
#define SIZE_T_ONE   ((size_t)1)
 
#define SIZE_T_TWO   ((size_t)2)
 
#define TWO_SIZE_T_SIZES   (SIZE_T_SIZE<<1)
 
#define FOUR_SIZE_T_SIZES   (SIZE_T_SIZE<<2)
 
#define SIX_SIZE_T_SIZES   (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES)
 
#define HALF_MAX_SIZE_T   (MAX_SIZE_T / 2U)
 
#define CHUNK_ALIGN_MASK   (MALLOC_ALIGNMENT - SIZE_T_ONE)
 
#define is_aligned(A)   (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0)
 
#define align_offset(A)
 
#define MFAIL   ((void*)(MAX_SIZE_T))
 
#define CMFAIL   ((char*)(MFAIL)) /* defined for convenience */
 
#define IS_MMAPPED_BIT   (SIZE_T_ONE)
 
#define USE_MMAP_BIT   (SIZE_T_ONE)
 
#define CALL_MMAP(s)   win32mmap(s)
 
#define CALL_MUNMAP(a, s)   win32munmap((a), (s))
 
#define DIRECT_MMAP(s)   win32direct_mmap(s)
 
#define CALL_MREMAP(addr, osz, nsz, mv)   MFAIL
 
#define CALL_MORECORE(S)   MFAIL
 
#define USE_NONCONTIGUOUS_BIT   (4U)
 
#define EXTERN_BIT   (8U)
 
#define MLOCK_T   long
 
#define INITIAL_LOCK(l)   *(l)=0
 
#define ACQUIRE_LOCK(l)   win32_acquire_lock(l)
 
#define RELEASE_LOCK(l)   win32_release_lock(l)
 
#define USE_LOCK_BIT   (2U)
 
#define ACQUIRE_MORECORE_LOCK()
 
#define RELEASE_MORECORE_LOCK()
 
#define ACQUIRE_MAGIC_INIT_LOCK()   ACQUIRE_LOCK(&magic_init_mutex);
 
#define RELEASE_MAGIC_INIT_LOCK()   RELEASE_LOCK(&magic_init_mutex);
 
#define MCHUNK_SIZE   (sizeof(mchunk))
 
#define CHUNK_OVERHEAD   (SIZE_T_SIZE)
 
#define MMAP_CHUNK_OVERHEAD   (TWO_SIZE_T_SIZES)
 
#define MMAP_FOOT_PAD   (FOUR_SIZE_T_SIZES)
 
#define MIN_CHUNK_SIZE   ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)
 
#define chunk2mem(p)   ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
 
#define mem2chunk(mem)   ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES))
 
#define align_as_chunk(A)   (mchunkptr)((A) + align_offset(chunk2mem(A)))
 
#define MAX_REQUEST   ((-MIN_CHUNK_SIZE) << 2)
 
#define MIN_REQUEST   (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)
 
#define pad_request(req)   (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)
 
#define request2size(req)   (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req))
 
#define PINUSE_BIT   (SIZE_T_ONE)
 
#define CINUSE_BIT   (SIZE_T_TWO)
 
#define INUSE_BITS   (PINUSE_BIT|CINUSE_BIT)
 
#define FENCEPOST_HEAD   (INUSE_BITS|SIZE_T_SIZE)
 
#define cinuse(p)   ((p)->head & CINUSE_BIT)
 
#define pinuse(p)   ((p)->head & PINUSE_BIT)
 
#define chunksize(p)   ((p)->head & ~(INUSE_BITS))
 
#define clear_pinuse(p)   ((p)->head &= ~PINUSE_BIT)
 
#define clear_cinuse(p)   ((p)->head &= ~CINUSE_BIT)
 
#define chunk_plus_offset(p, s)   ((mchunkptr)(((char*)(p)) + (s)))
 
#define chunk_minus_offset(p, s)   ((mchunkptr)(((char*)(p)) - (s)))
 
#define next_chunk(p)   ((mchunkptr)( ((char*)(p)) + ((p)->head & ~INUSE_BITS)))
 
#define prev_chunk(p)   ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) ))
 
#define next_pinuse(p)   ((next_chunk(p)->head) & PINUSE_BIT)
 
#define get_foot(p, s)   (((mchunkptr)((char*)(p) + (s)))->prev_foot)
 
#define set_foot(p, s)   (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s))
 
#define set_size_and_pinuse_of_free_chunk(p, s)   ((p)->head = (s|PINUSE_BIT), set_foot(p, s))
 
#define set_free_with_pinuse(p, s, n)   (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s))
 
#define is_mmapped(p)   (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_MMAPPED_BIT))
 
#define overhead_for(p)   (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD)
 
#define calloc_must_clear(p)   (1)
 
#define leftmost_child(t)   ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])
 
#define is_mmapped_segment(S)   ((S)->sflags & IS_MMAPPED_BIT)
 
#define is_extern_segment(S)   ((S)->sflags & EXTERN_BIT)
 
#define NSMALLBINS   (32U)
 
#define NTREEBINS   (32U)
 
#define SMALLBIN_SHIFT   (3U)
 
#define SMALLBIN_WIDTH   (SIZE_T_ONE << SMALLBIN_SHIFT)
 
#define TREEBIN_SHIFT   (8U)
 
#define MIN_LARGE_SIZE   (SIZE_T_ONE << TREEBIN_SHIFT)
 
#define MAX_SMALL_SIZE   (MIN_LARGE_SIZE - SIZE_T_ONE)
 
#define MAX_SMALL_REQUEST   (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)
 
#define gm   (&_gm_)
 
#define is_global(M)   ((M) == &_gm_)
 
#define is_initialized(M)   ((M)->top != 0)
 
#define use_lock(M)   ((M)->mflags & USE_LOCK_BIT)
 
#define enable_lock(M)   ((M)->mflags |= USE_LOCK_BIT)
 
#define disable_lock(M)   ((M)->mflags &= ~USE_LOCK_BIT)
 
#define use_mmap(M)   ((M)->mflags & USE_MMAP_BIT)
 
#define enable_mmap(M)   ((M)->mflags |= USE_MMAP_BIT)
 
#define disable_mmap(M)   ((M)->mflags &= ~USE_MMAP_BIT)
 
#define use_noncontiguous(M)   ((M)->mflags & USE_NONCONTIGUOUS_BIT)
 
#define disable_contiguous(M)   ((M)->mflags |= USE_NONCONTIGUOUS_BIT)
 
#define set_lock(M, L)
 
#define page_align(S)   (((S) + (mparams.page_size)) & ~(mparams.page_size - SIZE_T_ONE))
 
#define granularity_align(S)   (((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
 
#define is_page_aligned(S)   (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0)
 
#define is_granularity_aligned(S)   (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0)
 
#define segment_holds(S, A)   ((char*)(A) >= S->base && (char*)(A) < S->base + S->size)
 
#define should_trim(M, s)   ((s) > (M)->trim_check)
 
#define TOP_FOOT_SIZE   (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
 
#define GLOBALLY_INITIALIZE()   (mparams.page_size == 0 && init_mparams())
 
#define PREACTION(M)   ((GLOBALLY_INITIALIZE() || use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0)
 
#define POSTACTION(M)   { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); }
 
#define CORRUPTION_ERROR_ACTION(m)   ABORT
 
#define USAGE_ERROR_ACTION(m, p)   ABORT
 
#define check_free_chunk(M, P)
 
#define check_inuse_chunk(M, P)
 
#define check_malloced_chunk(M, P, N)
 
#define check_mmapped_chunk(M, P)
 
#define check_malloc_state(M)
 
#define check_top_chunk(M, P)
 
#define is_small(s)   (((s) >> SMALLBIN_SHIFT) < NSMALLBINS)
 
#define small_index(s)   ((s) >> SMALLBIN_SHIFT)
 
#define small_index2size(i)   ((i) << SMALLBIN_SHIFT)
 
#define MIN_SMALL_INDEX   (small_index(MIN_CHUNK_SIZE))
 
#define smallbin_at(M, i)   ((sbinptr)((char*)&((M)->smallbins[(i)<<1])))
 
#define treebin_at(M, i)   (&((M)->treebins[i]))
 
#define compute_tree_index(S, I)
 
#define bit_for_tree_index(i)   (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2)
 
#define leftshift_for_tree_index(i)
 
#define minsize_for_tree_index(i)
 
#define idx2bit(i)   ((binmap_t)(1) << (i))
 
#define mark_smallmap(M, i)   ((M)->smallmap |= idx2bit(i))
 
#define clear_smallmap(M, i)   ((M)->smallmap &= ~idx2bit(i))
 
#define smallmap_is_marked(M, i)   ((M)->smallmap & idx2bit(i))
 
#define mark_treemap(M, i)   ((M)->treemap |= idx2bit(i))
 
#define clear_treemap(M, i)   ((M)->treemap &= ~idx2bit(i))
 
#define treemap_is_marked(M, i)   ((M)->treemap & idx2bit(i))
 
#define compute_bit2idx(X, I)
 
#define least_bit(x)   ((x) & -(x))
 
#define left_bits(x)   ((x<<1) | -(x<<1))
 
#define same_or_left_bits(x)   ((x) | -(x))
 
#define ok_address(M, a)   ((char*)(a) >= (M)->least_addr)
 
#define ok_next(p, n)   ((char*)(p) < (char*)(n))
 
#define ok_cinuse(p)   cinuse(p)
 
#define ok_pinuse(p)   pinuse(p)
 
#define ok_magic(M)   (1)
 
#define RTCHECK(e)   (e)
 
#define mark_inuse_foot(M, p, s)
 
#define set_inuse(M, p, s)
 
#define set_inuse_and_pinuse(M, p, s)
 
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)   ((p)->head = (s|PINUSE_BIT|CINUSE_BIT))
 
#define insert_small_chunk(M, P, S)
 
#define unlink_small_chunk(M, P, S)
 
#define unlink_first_small_chunk(M, B, P, I)
 
#define replace_dv(M, P, S)
 
#define insert_large_chunk(M, X, S)
 
#define unlink_large_chunk(M, X)
 
#define insert_chunk(M, P, S)
 
#define unlink_chunk(M, P, S)
 
#define internal_malloc(m, b)   dlmalloc(b)
 
#define internal_free(m, mem)   dlfree(mem)
 
#define fm   gm
 

Typedefs

typedef size_t bindex_t
 
typedef unsigned int binmap_t
 
typedef unsigned int flag_t
 

Functions

voiddlmalloc (size_t)
 
void dlfree (void *)
 
voiddlcalloc (size_t, size_t)
 
voiddlrealloc (void *, size_t)
 
voiddlmemalign (size_t, size_t)
 
voiddlvalloc (size_t)
 
int dlmallopt (int, int)
 
size_t dlmalloc_footprint (void)
 
size_t dlmalloc_max_footprint (void)
 
struct mallinfo dlmallinfo (void)
 
void ** dlindependent_calloc (size_t, size_t, void **)
 
void ** dlindependent_comalloc (size_t, size_t *, void **)
 
voiddlpvalloc (size_t)
 
int dlmalloc_trim (size_t)
 
size_t dlmalloc_usable_size (void *)
 
void dlmalloc_stats (void)
 
static voidwin32mmap (size_t size)
 
static voidwin32direct_mmap (size_t size)
 
static int win32munmap (void *ptr, size_t size)
 
static int win32_acquire_lock (MLOCK_T *sl)
 
static void win32_release_lock (MLOCK_T *sl)
 
static msegmentptr segment_holding (mstate m, char *addr)
 
static int has_segment_link (mstate m, msegmentptr ss)
 
static int init_mparams (void)
 
static int change_mparam (int param_number, int value)
 
static struct mallinfo internal_mallinfo (mstate m)
 
static void internal_malloc_stats (mstate m)
 
static voidmmap_alloc (mstate m, size_t nb)
 
static mchunkptr mmap_resize (mstate m, mchunkptr oldp, size_t nb)
 
static void init_top (mstate m, mchunkptr p, size_t psize)
 
static void init_bins (mstate m)
 
static voidprepend_alloc (mstate m, char *newbase, char *oldbase, size_t nb)
 
static void add_segment (mstate m, char *tbase, size_t tsize, flag_t mmapped)
 
static voidsys_alloc (mstate m, size_t nb)
 
static size_t release_unused_segments (mstate m)
 
static int sys_trim (mstate m, size_t pad)
 
static voidtmalloc_large (mstate m, size_t nb)
 
static voidtmalloc_small (mstate m, size_t nb)
 
static voidinternal_realloc (mstate m, void *oldmem, size_t bytes)
 
static voidinternal_memalign (mstate m, size_t alignment, size_t bytes)
 
static void ** ialloc (mstate m, size_t n_elements, size_t *sizes, int opts, void *chunks[])
 
void ** dlindependent_calloc (size_t n_elements, size_t elem_size, void *chunks[])
 
void ** dlindependent_comalloc (size_t n_elements, size_t sizes[], void *chunks[])
 

Variables

static MLOCK_T magic_init_mutex
 
static struct malloc_params mparams
 
static struct malloc_state _gm_
 

Macro Definition Documentation

#define ABORT

Definition at line 61 of file SDL_malloc.c.

Referenced by init_mparams().

#define ABORT_ON_ASSERT_FAILURE   1

Definition at line 561 of file SDL_malloc.c.

#define ACQUIRE_LOCK (   l)    win32_acquire_lock(l)

Definition at line 1515 of file SDL_malloc.c.

#define ACQUIRE_MAGIC_INIT_LOCK ( )    ACQUIRE_LOCK(&magic_init_mutex);

Definition at line 1538 of file SDL_malloc.c.

Referenced by init_mparams().

#define ACQUIRE_MORECORE_LOCK ( )

Definition at line 1533 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define align_as_chunk (   A)    (mchunkptr)((A) + align_offset(chunk2mem(A)))
#define align_offset (   A)
Value:
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\
#define CHUNK_ALIGN_MASK
Definition: SDL_malloc.c:1332
unsigned int size_t
#define MALLOC_ALIGNMENT
Definition: SDL_malloc.c:552

Definition at line 1338 of file SDL_malloc.c.

Referenced by add_segment(), init_top(), and mmap_alloc().

#define bit_for_tree_index (   i)    (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2)

Definition at line 2331 of file SDL_malloc.c.

#define CALL_MMAP (   s)    win32mmap(s)

Definition at line 1429 of file SDL_malloc.c.

Referenced by sys_alloc().

#define CALL_MORECORE (   S)    MFAIL

Definition at line 1444 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define CALL_MREMAP (   addr,
  osz,
  nsz,
  mv 
)    MFAIL

Definition at line 1438 of file SDL_malloc.c.

Referenced by mmap_resize(), and sys_trim().

#define CALL_MUNMAP (   a,
  s 
)    win32munmap((a), (s))

Definition at line 1430 of file SDL_malloc.c.

Referenced by dlfree(), release_unused_segments(), and sys_trim().

#define calloc   SDL_calloc

Definition at line 642 of file SDL_malloc.c.

Referenced by decode_edid().

#define calloc_must_clear (   p)    (1)

Definition at line 1795 of file SDL_malloc.c.

Referenced by dlcalloc().

#define check_free_chunk (   M,
 
)

Definition at line 2255 of file SDL_malloc.c.

Referenced by dlfree(), and prepend_alloc().

#define check_inuse_chunk (   M,
 
)

Definition at line 2256 of file SDL_malloc.c.

Referenced by dlfree(), ialloc(), internal_memalign(), and internal_realloc().

#define check_malloc_state (   M)

Definition at line 2259 of file SDL_malloc.c.

Referenced by internal_mallinfo(), and internal_malloc_stats().

#define check_malloced_chunk (   M,
  P,
 
)

Definition at line 2257 of file SDL_malloc.c.

Referenced by dlmalloc(), prepend_alloc(), and sys_alloc().

#define check_mmapped_chunk (   M,
 
)

Definition at line 2258 of file SDL_malloc.c.

Referenced by mmap_alloc(), and mmap_resize().

#define check_top_chunk (   M,
 
)

Definition at line 2260 of file SDL_malloc.c.

Referenced by add_segment(), dlmalloc(), prepend_alloc(), sys_alloc(), and sys_trim().

#define CHUNK_ALIGN_MASK   (MALLOC_ALIGNMENT - SIZE_T_ONE)

Definition at line 1332 of file SDL_malloc.c.

Referenced by add_segment(), mmap_alloc(), and mmap_resize().

#define chunk_minus_offset (   p,
  s 
)    ((mchunkptr)(((char*)(p)) - (s)))

Definition at line 1763 of file SDL_malloc.c.

Referenced by dlfree().

#define CHUNK_OVERHEAD   (SIZE_T_SIZE)

Definition at line 1705 of file SDL_malloc.c.

Referenced by ialloc(), and internal_memalign().

#define chunk_plus_offset (   p,
  s 
)    ((mchunkptr)(((char*)(p)) + (s)))
#define cinuse (   p)    ((p)->head & CINUSE_BIT)
#define CINUSE_BIT   (SIZE_T_TWO)

Definition at line 1747 of file SDL_malloc.c.

Referenced by internal_memalign(), mmap_alloc(), and mmap_resize().

#define clear_cinuse (   p)    ((p)->head &= ~CINUSE_BIT)

Definition at line 1759 of file SDL_malloc.c.

#define clear_pinuse (   p)    ((p)->head &= ~PINUSE_BIT)

Definition at line 1758 of file SDL_malloc.c.

#define clear_smallmap (   M,
  i 
)    ((M)->smallmap &= ~idx2bit(i))

Definition at line 2352 of file SDL_malloc.c.

#define clear_treemap (   M,
  i 
)    ((M)->treemap &= ~idx2bit(i))

Definition at line 2356 of file SDL_malloc.c.

#define CMFAIL   ((char*)(MFAIL)) /* defined for convenience */

Definition at line 1353 of file SDL_malloc.c.

Referenced by mmap_alloc(), mmap_resize(), sys_alloc(), and sys_trim().

#define compute_bit2idx (   X,
  I 
)
Value:
{\
unsigned int Y = X - 1;\
unsigned int K = Y >> (16-4) & 16;\
unsigned int N = K; Y >>= K;\
N += K = Y >> (8-3) & 8; Y >>= K;\
N += K = Y >> (4-2) & 4; Y >>= K;\
N += K = Y >> (2-1) & 2; Y >>= K;\
N += K = Y >> (1-0) & 1; Y >>= K;\
I = (bindex_t)(N + Y);\
}
size_t bindex_t
Definition: SDL_malloc.c:1694
#define I(x, y, z)
Definition: SDL_test_md5.c:76

Definition at line 2374 of file SDL_malloc.c.

Referenced by dlmalloc(), tmalloc_large(), and tmalloc_small().

#define compute_tree_index (   S,
  I 
)
Value:
{\
if (X == 0)\
I = 0;\
else if (X > 0xFFFF)\
else {\
unsigned int Y = (unsigned int)X;\
unsigned int N = ((Y - 0x100) >> 16) & 8;\
unsigned int K = (((Y <<= N) - 0x1000) >> 16) & 4;\
N += K;\
N += K = (((Y <<= K) - 0x4000) >> 16) & 2;\
K = 14 - N + ((Y <<= K) >> 15);\
I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\
}\
}
#define TREEBIN_SHIFT
Definition: SDL_malloc.c:2060
unsigned int size_t
#define NTREEBINS
Definition: SDL_malloc.c:2057
#define I(x, y, z)
Definition: SDL_test_md5.c:76

Definition at line 2311 of file SDL_malloc.c.

Referenced by tmalloc_large().

#define CORRUPTION_ERROR_ACTION (   m)    ABORT

Definition at line 2242 of file SDL_malloc.c.

Referenced by tmalloc_large(), and tmalloc_small().

#define DEFAULT_GRANULARITY   ((size_t)64U * (size_t)1024U)

Definition at line 609 of file SDL_malloc.c.

Referenced by init_mparams().

#define DEFAULT_MMAP_THRESHOLD   ((size_t)256U * (size_t)1024U)

Definition at line 621 of file SDL_malloc.c.

Referenced by init_mparams().

#define DEFAULT_TRIM_THRESHOLD   ((size_t)2U * (size_t)1024U * (size_t)1024U)

Definition at line 614 of file SDL_malloc.c.

Referenced by init_mparams().

#define DIRECT_MMAP (   s)    win32direct_mmap(s)

Definition at line 1431 of file SDL_malloc.c.

Referenced by mmap_alloc().

#define disable_contiguous (   M)    ((M)->mflags |= USE_NONCONTIGUOUS_BIT)

Definition at line 2128 of file SDL_malloc.c.

Referenced by sys_alloc().

#define disable_lock (   M)    ((M)->mflags &= ~USE_LOCK_BIT)

Definition at line 2121 of file SDL_malloc.c.

#define disable_mmap (   M)    ((M)->mflags &= ~USE_MMAP_BIT)

Definition at line 2125 of file SDL_malloc.c.

Referenced by ialloc().

#define dlcalloc   calloc

Definition at line 715 of file SDL_malloc.c.

#define dlfree   free

Definition at line 716 of file SDL_malloc.c.

Referenced by dlrealloc().

#define dlindependent_calloc   independent_calloc

Definition at line 729 of file SDL_malloc.c.

#define dlindependent_comalloc   independent_comalloc

Definition at line 730 of file SDL_malloc.c.

#define dlmallinfo   mallinfo

Definition at line 722 of file SDL_malloc.c.

#define dlmalloc   malloc

Definition at line 717 of file SDL_malloc.c.

Referenced by dlcalloc(), and dlrealloc().

#define dlmalloc_footprint   malloc_footprint

Definition at line 727 of file SDL_malloc.c.

#define dlmalloc_max_footprint   malloc_max_footprint

Definition at line 728 of file SDL_malloc.c.

void dlmalloc_stats   malloc_stats

Definition at line 725 of file SDL_malloc.c.

#define dlmalloc_trim   malloc_trim

Definition at line 724 of file SDL_malloc.c.

#define dlmalloc_usable_size   malloc_usable_size

Definition at line 726 of file SDL_malloc.c.

#define dlmallopt   mallopt

Definition at line 723 of file SDL_malloc.c.

#define dlmemalign   memalign

Definition at line 718 of file SDL_malloc.c.

Referenced by dlpvalloc(), and dlvalloc().

#define dlpvalloc   pvalloc

Definition at line 721 of file SDL_malloc.c.

#define dlrealloc   realloc

Definition at line 719 of file SDL_malloc.c.

#define dlvalloc   valloc

Definition at line 720 of file SDL_malloc.c.

#define enable_lock (   M)    ((M)->mflags |= USE_LOCK_BIT)

Definition at line 2120 of file SDL_malloc.c.

#define enable_mmap (   M)    ((M)->mflags |= USE_MMAP_BIT)

Definition at line 2124 of file SDL_malloc.c.

Referenced by ialloc().

#define EXTERN_BIT   (8U)

Definition at line 1451 of file SDL_malloc.c.

#define FENCEPOST_HEAD   (INUSE_BITS|SIZE_T_SIZE)
#define fm   gm

Referenced by dlfree().

#define FOOTERS   0

Definition at line 555 of file SDL_malloc.c.

#define FOUR_SIZE_T_SIZES   (SIZE_T_SIZE<<2)

Definition at line 1327 of file SDL_malloc.c.

Referenced by add_segment().

#define free   SDL_free

Definition at line 644 of file SDL_malloc.c.

#define get_foot (   p,
  s 
)    (((mchunkptr)((char*)(p) + (s)))->prev_foot)

Definition at line 1773 of file SDL_malloc.c.

#define GLOBALLY_INITIALIZE ( )    (mparams.page_size == 0 && init_mparams())

Definition at line 2204 of file SDL_malloc.c.

#define granularity_align (   S)    (((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))

Definition at line 2140 of file SDL_malloc.c.

Referenced by mmap_alloc(), mmap_resize(), and sys_alloc().

#define HALF_MAX_SIZE_T   (MAX_SIZE_T / 2U)

Definition at line 1329 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define HAVE_MMAP   1

Definition at line 512 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define HAVE_MORECORE   0

Definition at line 513 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define HAVE_MREMAP   0

Definition at line 582 of file SDL_malloc.c.

#define idx2bit (   i)    ((binmap_t)(1) << (i))

Definition at line 2348 of file SDL_malloc.c.

Referenced by dlmalloc(), and tmalloc_large().

#define INITIAL_LOCK (   l)    *(l)=0

Definition at line 1514 of file SDL_malloc.c.

Referenced by init_mparams().

#define INSECURE   0

Definition at line 570 of file SDL_malloc.c.

#define insert_chunk (   M,
  P,
 
)
Value:
if (is_small(S)) insert_small_chunk(M, P, S)\
else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); }
#define insert_small_chunk(M, P, S)
Definition: SDL_malloc.c:2995
#define is_small(s)
Definition: SDL_malloc.c:2286
#define insert_large_chunk(M, X, S)
Definition: SDL_malloc.c:3066

Definition at line 3207 of file SDL_malloc.c.

Referenced by add_segment(), dlfree(), prepend_alloc(), and tmalloc_large().

#define insert_large_chunk (   M,
  X,
 
)

Definition at line 3066 of file SDL_malloc.c.

Referenced by release_unused_segments().

#define insert_small_chunk (   M,
  P,
 
)
Value:
{\
mchunkptr B = smallbin_at(M, I);\
mchunkptr F = B;\
if (!smallmap_is_marked(M, I))\
else if (RTCHECK(ok_address(M, B->fd)))\
F = B->fd;\
else {\
}\
B->fd = P;\
F->bk = P;\
P->fd = F;\
P->bk = B;\
}
size_t bindex_t
Definition: SDL_malloc.c:1694
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
#define assert(x)
Definition: SDL_malloc.c:1240
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2242
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
#define I(x, y, z)
Definition: SDL_test_md5.c:76
#define small_index(s)
Definition: SDL_malloc.c:2287
#define F(x, y, z)
Definition: SDL_test_md5.c:73
#define smallmap_is_marked(M, i)
Definition: SDL_malloc.c:2353
#define mark_smallmap(M, i)
Definition: SDL_malloc.c:2351
#define ok_address(M, a)
Definition: SDL_malloc.c:2428

Definition at line 2995 of file SDL_malloc.c.

#define internal_free (   m,
  mem 
)    dlfree(mem)

Definition at line 3229 of file SDL_malloc.c.

Referenced by internal_memalign(), and internal_realloc().

#define internal_malloc (   m,
  b 
)    dlmalloc(b)

Definition at line 3228 of file SDL_malloc.c.

Referenced by ialloc(), internal_memalign(), and internal_realloc().

#define INUSE_BITS   (PINUSE_BIT|CINUSE_BIT)

Definition at line 1748 of file SDL_malloc.c.

Referenced by dlfree().

#define is_aligned (   A)    (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0)

Definition at line 1335 of file SDL_malloc.c.

Referenced by add_segment(), and mmap_alloc().

#define is_extern_segment (   S)    ((S)->sflags & EXTERN_BIT)

Definition at line 1975 of file SDL_malloc.c.

Referenced by release_unused_segments(), sys_alloc(), and sys_trim().

#define is_global (   M)    ((M) == &_gm_)

Definition at line 2112 of file SDL_malloc.c.

Referenced by sys_alloc().

#define is_granularity_aligned (   S)    (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0)

Definition at line 2145 of file SDL_malloc.c.

#define is_initialized (   M)    ((M)->top != 0)

Definition at line 2113 of file SDL_malloc.c.

Referenced by internal_mallinfo(), internal_malloc_stats(), sys_alloc(), and sys_trim().

#define is_mmapped (   p)    (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_MMAPPED_BIT))

Definition at line 1784 of file SDL_malloc.c.

Referenced by ialloc(), internal_memalign(), and internal_realloc().

#define IS_MMAPPED_BIT   (SIZE_T_ONE)

Definition at line 1363 of file SDL_malloc.c.

Referenced by dlfree(), mmap_alloc(), mmap_resize(), and sys_alloc().

#define is_mmapped_segment (   S)    ((S)->sflags & IS_MMAPPED_BIT)

Definition at line 1974 of file SDL_malloc.c.

Referenced by release_unused_segments(), and sys_trim().

#define is_page_aligned (   S)    (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0)

Definition at line 2143 of file SDL_malloc.c.

Referenced by sys_alloc().

#define is_small (   s)    (((s) >> SMALLBIN_SHIFT) < NSMALLBINS)

Definition at line 2286 of file SDL_malloc.c.

Referenced by mmap_resize().

#define LACKS_ERRNO_H

Definition at line 520 of file SDL_malloc.c.

#define LACKS_FCNTL_H

Definition at line 521 of file SDL_malloc.c.

#define LACKS_STDIO_H

Definition at line 57 of file SDL_malloc.c.

#define LACKS_STDLIB_H

Definition at line 60 of file SDL_malloc.c.

#define LACKS_STRING_H

Definition at line 517 of file SDL_malloc.c.

#define LACKS_STRING_H

Definition at line 517 of file SDL_malloc.c.

#define LACKS_STRINGS_H

Definition at line 518 of file SDL_malloc.c.

#define LACKS_STRINGS_H

Definition at line 518 of file SDL_malloc.c.

#define LACKS_SYS_MMAN_H

Definition at line 516 of file SDL_malloc.c.

#define LACKS_SYS_PARAM_H

Definition at line 515 of file SDL_malloc.c.

#define LACKS_SYS_TYPES_H

Definition at line 519 of file SDL_malloc.c.

#define LACKS_SYS_TYPES_H

Definition at line 519 of file SDL_malloc.c.

#define LACKS_UNISTD_H

Definition at line 514 of file SDL_malloc.c.

#define least_bit (   x)    ((x) & -(x))

Definition at line 2389 of file SDL_malloc.c.

Referenced by dlmalloc(), tmalloc_large(), and tmalloc_small().

#define left_bits (   x)    ((x<<1) | -(x<<1))

Definition at line 2392 of file SDL_malloc.c.

Referenced by dlmalloc(), and tmalloc_large().

#define leftmost_child (   t)    ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])

Definition at line 1907 of file SDL_malloc.c.

Referenced by tmalloc_large(), and tmalloc_small().

#define leftshift_for_tree_index (   i)
Value:
((i == NTREEBINS-1)? 0 : \
((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2)))
#define TREEBIN_SHIFT
Definition: SDL_malloc.c:2060
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NTREEBINS
Definition: SDL_malloc.c:2057
#define SIZE_T_BITSIZE
Definition: SDL_malloc.c:1319
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324

Definition at line 2335 of file SDL_malloc.c.

Referenced by tmalloc_large().

#define M_GRANULARITY   (-2)

Definition at line 654 of file SDL_malloc.c.

Referenced by change_mparam().

#define M_MMAP_THRESHOLD   (-3)

Definition at line 655 of file SDL_malloc.c.

Referenced by change_mparam().

#define M_TRIM_THRESHOLD   (-1)

Definition at line 653 of file SDL_malloc.c.

Referenced by change_mparam().

#define MALLINFO_FIELD_TYPE   size_t

Definition at line 636 of file SDL_malloc.c.

#define malloc   SDL_malloc

Definition at line 641 of file SDL_malloc.c.

Referenced by SDL_BWin::DirectConnected(), glGetConfig(), and main().

#define MALLOC_ALIGNMENT   ((size_t)8U)

Definition at line 552 of file SDL_malloc.c.

Referenced by init_mparams(), internal_memalign(), and sys_alloc().

#define MALLOC_FAILURE_ACTION

Definition at line 522 of file SDL_malloc.c.

Referenced by internal_memalign(), internal_realloc(), and sys_alloc().

#define mark_inuse_foot (   M,
  p,
  s 
)

Definition at line 2466 of file SDL_malloc.c.

Referenced by mmap_alloc(), and mmap_resize().

#define mark_smallmap (   M,
  i 
)    ((M)->smallmap |= idx2bit(i))

Definition at line 2351 of file SDL_malloc.c.

#define mark_treemap (   M,
  i 
)    ((M)->treemap |= idx2bit(i))

Definition at line 2355 of file SDL_malloc.c.

#define MAX_REQUEST   ((-MIN_CHUNK_SIZE) << 2)

Definition at line 1724 of file SDL_malloc.c.

Referenced by dlmalloc(), internal_memalign(), internal_realloc(), and sys_trim().

#define MAX_SIZE_T   (~(size_t)0)

Definition at line 539 of file SDL_malloc.c.

Referenced by dlcalloc(), dlmalloc(), init_mparams(), and sys_trim().

#define MAX_SMALL_REQUEST   (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)

Definition at line 2063 of file SDL_malloc.c.

Referenced by dlmalloc().

#define MAX_SMALL_SIZE   (MIN_LARGE_SIZE - SIZE_T_ONE)

Definition at line 2062 of file SDL_malloc.c.

#define MCHUNK_SIZE   (sizeof(mchunk))

Definition at line 1700 of file SDL_malloc.c.

Referenced by init_mparams().

#define mem2chunk (   mem)    ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES))
#define memcpy   SDL_memcpy

Definition at line 640 of file SDL_malloc.c.

Referenced by SDL_BWin::DirectConnected(), internal_realloc(), and SDL_memcpy().

#define memset   SDL_memset

Definition at line 639 of file SDL_malloc.c.

Referenced by dlcalloc(), ialloc(), main(), and SDL_memset().

#define MFAIL   ((void*)(MAX_SIZE_T))

Definition at line 1352 of file SDL_malloc.c.

Referenced by sys_trim(), win32direct_mmap(), and win32mmap().

#define MIN_LARGE_SIZE   (SIZE_T_ONE << TREEBIN_SHIFT)

Definition at line 2061 of file SDL_malloc.c.

#define MIN_REQUEST   (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)

Definition at line 1725 of file SDL_malloc.c.

Referenced by dlmalloc().

#define MIN_SMALL_INDEX   (small_index(MIN_CHUNK_SIZE))

Definition at line 2289 of file SDL_malloc.c.

#define minsize_for_tree_index (   i)
Value:
((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \
(((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1)))
#define TREEBIN_SHIFT
Definition: SDL_malloc.c:2060
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324

Definition at line 2340 of file SDL_malloc.c.

#define MLOCK_T   long

Definition at line 1492 of file SDL_malloc.c.

#define MMAP_CHUNK_OVERHEAD   (TWO_SIZE_T_SIZES)

Definition at line 1709 of file SDL_malloc.c.

#define MMAP_CLEARS   0 /* WINCE and some others apparently don't clear */

Definition at line 523 of file SDL_malloc.c.

#define MMAP_FOOT_PAD   (FOUR_SIZE_T_SIZES)

Definition at line 1711 of file SDL_malloc.c.

Referenced by dlfree(), mmap_alloc(), and mmap_resize().

#define MORECORE_CONTIGUOUS   0

Definition at line 596 of file SDL_malloc.c.

Referenced by sys_alloc().

#define MSPACES   0

Definition at line 548 of file SDL_malloc.c.

#define next_chunk (   p)    ((mchunkptr)( ((char*)(p)) + ((p)->head & ~INUSE_BITS)))

Definition at line 1766 of file SDL_malloc.c.

Referenced by internal_mallinfo(), internal_malloc_stats(), and sys_alloc().

#define next_pinuse (   p)    ((next_chunk(p)->head) & PINUSE_BIT)

Definition at line 1770 of file SDL_malloc.c.

#define NO_MALLINFO   0

Definition at line 633 of file SDL_malloc.c.

#define NSMALLBINS   (32U)

Definition at line 2056 of file SDL_malloc.c.

Referenced by init_bins().

#define NTREEBINS   (32U)

Definition at line 2057 of file SDL_malloc.c.

#define ok_address (   M,
  a 
)    ((char*)(a) >= (M)->least_addr)

Definition at line 2428 of file SDL_malloc.c.

Referenced by dlfree(), internal_realloc(), tmalloc_large(), and tmalloc_small().

#define ok_cinuse (   p)    cinuse(p)

Definition at line 2432 of file SDL_malloc.c.

Referenced by dlfree(), and internal_realloc().

#define ok_magic (   M)    (1)

Definition at line 2447 of file SDL_malloc.c.

Referenced by dlfree(), and dlrealloc().

#define ok_next (   p,
  n 
)    ((char*)(p) < (char*)(n))

Definition at line 2430 of file SDL_malloc.c.

Referenced by dlfree(), internal_realloc(), tmalloc_large(), and tmalloc_small().

#define ok_pinuse (   p)    pinuse(p)

Definition at line 2434 of file SDL_malloc.c.

Referenced by dlfree(), and internal_realloc().

#define ONLY_MSPACES   0

Definition at line 542 of file SDL_malloc.c.

#define overhead_for (   p)    (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD)

Definition at line 1788 of file SDL_malloc.c.

Referenced by dlmalloc_usable_size(), and internal_realloc().

#define pad_request (   req)    (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)

Definition at line 1728 of file SDL_malloc.c.

Referenced by add_segment(), and dlmalloc().

#define page_align (   S)    (((S) + (mparams.page_size)) & ~(mparams.page_size - SIZE_T_ONE))

Definition at line 2136 of file SDL_malloc.c.

Referenced by sys_alloc().

#define pinuse (   p)    ((p)->head & PINUSE_BIT)

Definition at line 1755 of file SDL_malloc.c.

Referenced by dlfree(), and prepend_alloc().

#define PINUSE_BIT   (SIZE_T_ONE)

Definition at line 1746 of file SDL_malloc.c.

Referenced by dlfree(), dlmalloc(), init_top(), internal_realloc(), prepend_alloc(), and sys_alloc().

#define POSTACTION (   M)    { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); }
#define PREACTION (   M)    ((GLOBALLY_INITIALIZE() || use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0)
#define prev_chunk (   p)    ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) ))

Definition at line 1767 of file SDL_malloc.c.

#define PROCEED_ON_ERROR   0

Definition at line 564 of file SDL_malloc.c.

#define realloc   SDL_realloc

Definition at line 643 of file SDL_malloc.c.

#define RELEASE_LOCK (   l)    win32_release_lock(l)

Definition at line 1516 of file SDL_malloc.c.

#define RELEASE_MAGIC_INIT_LOCK ( )    RELEASE_LOCK(&magic_init_mutex);

Definition at line 1539 of file SDL_malloc.c.

Referenced by init_mparams().

#define RELEASE_MORECORE_LOCK ( )

Definition at line 1534 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define replace_dv (   M,
  P,
 
)
Value:
{\
size_t DVS = M->dvsize;\
if (DVS != 0) {\
mchunkptr DV = M->dv;\
insert_small_chunk(M, DV, DVS);\
}\
M->dvsize = S;\
M->dv = P;\
}
#define assert(x)
Definition: SDL_malloc.c:1240
unsigned int size_t
#define insert_small_chunk(M, P, S)
Definition: SDL_malloc.c:2995
#define is_small(s)
Definition: SDL_malloc.c:2286

Definition at line 3052 of file SDL_malloc.c.

Referenced by dlmalloc(), and tmalloc_small().

#define request2size (   req)    (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req))

Definition at line 1732 of file SDL_malloc.c.

Referenced by ialloc(), internal_memalign(), and internal_realloc().

#define RTCHECK (   e)    (e)

Definition at line 2456 of file SDL_malloc.c.

Referenced by dlfree(), internal_realloc(), tmalloc_large(), and tmalloc_small().

#define same_or_left_bits (   x)    ((x) | -(x))

Definition at line 2395 of file SDL_malloc.c.

#define segment_holds (   S,
 
)    ((char*)(A) >= S->base && (char*)(A) < S->base + S->size)
#define set_foot (   p,
  s 
)    (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s))

Definition at line 1774 of file SDL_malloc.c.

#define set_free_with_pinuse (   p,
  s,
  n 
)    (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s))

Definition at line 1781 of file SDL_malloc.c.

Referenced by add_segment(), dlfree(), and prepend_alloc().

#define set_inuse (   M,
  p,
  s 
)
Value:
((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\
((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)
GLdouble s
Definition: SDL_opengl.h:2063
GLfloat GLfloat p
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
SDL_EventEntry * head
Definition: SDL_events.c:81
#define PINUSE_BIT
Definition: SDL_malloc.c:1746

Definition at line 2469 of file SDL_malloc.c.

Referenced by internal_memalign(), and internal_realloc().

#define set_inuse_and_pinuse (   M,
  p,
  s 
)
Value:
((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)
GLdouble s
Definition: SDL_opengl.h:2063
GLfloat GLfloat p
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
SDL_EventEntry * head
Definition: SDL_events.c:81
#define PINUSE_BIT
Definition: SDL_malloc.c:1746

Definition at line 2474 of file SDL_malloc.c.

Referenced by dlmalloc(), tmalloc_large(), and tmalloc_small().

#define set_lock (   M,
 
)
Value:
((M)->mflags = (L)?\
((M)->mflags | USE_LOCK_BIT) :\
((M)->mflags & ~USE_LOCK_BIT))
#define USE_LOCK_BIT
Definition: SDL_malloc.c:1523

Definition at line 2130 of file SDL_malloc.c.

#define set_size_and_pinuse_of_free_chunk (   p,
  s 
)    ((p)->head = (s|PINUSE_BIT), set_foot(p, s))

Definition at line 1777 of file SDL_malloc.c.

Referenced by dlfree(), dlmalloc(), prepend_alloc(), tmalloc_large(), and tmalloc_small().

#define set_size_and_pinuse_of_inuse_chunk (   M,
  p,
  s 
)    ((p)->head = (s|PINUSE_BIT|CINUSE_BIT))
#define should_trim (   M,
  s 
)    ((s) > (M)->trim_check)

Definition at line 2179 of file SDL_malloc.c.

Referenced by dlfree().

#define SIX_SIZE_T_SIZES   (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES)

Definition at line 1328 of file SDL_malloc.c.

Referenced by mmap_alloc(), and mmap_resize().

#define SIZE_T_BITSIZE   (sizeof(size_t) << 3)

Definition at line 1319 of file SDL_malloc.c.

Referenced by tmalloc_large().

#define SIZE_T_ONE   ((size_t)1)
#define SIZE_T_SIZE   (sizeof(size_t))

Definition at line 1318 of file SDL_malloc.c.

Referenced by add_segment(), dlmalloc(), ialloc(), mmap_alloc(), and mmap_resize().

#define SIZE_T_TWO   ((size_t)2)

Definition at line 1325 of file SDL_malloc.c.

#define SIZE_T_ZERO   ((size_t)0)

Definition at line 1323 of file SDL_malloc.c.

#define small_index (   s)    ((s) >> SMALLBIN_SHIFT)

Definition at line 2287 of file SDL_malloc.c.

Referenced by dlmalloc().

#define small_index2size (   i)    ((i) << SMALLBIN_SHIFT)

Definition at line 2288 of file SDL_malloc.c.

Referenced by dlmalloc().

#define smallbin_at (   M,
  i 
)    ((sbinptr)((char*)&((M)->smallbins[(i)<<1])))

Definition at line 2292 of file SDL_malloc.c.

Referenced by dlmalloc(), and init_bins().

#define SMALLBIN_SHIFT   (3U)

Definition at line 2058 of file SDL_malloc.c.

#define SMALLBIN_WIDTH   (SIZE_T_ONE << SMALLBIN_SHIFT)

Definition at line 2059 of file SDL_malloc.c.

#define smallmap_is_marked (   M,
  i 
)    ((M)->smallmap & idx2bit(i))

Definition at line 2353 of file SDL_malloc.c.

#define treebin_at (   M,
  i 
)    (&((M)->treebins[i]))

Definition at line 2293 of file SDL_malloc.c.

Referenced by tmalloc_large(), and tmalloc_small().

#define TREEBIN_SHIFT   (8U)

Definition at line 2060 of file SDL_malloc.c.

#define treemap_is_marked (   M,
  i 
)    ((M)->treemap & idx2bit(i))

Definition at line 2357 of file SDL_malloc.c.

#define TWO_SIZE_T_SIZES   (SIZE_T_SIZE<<1)

Definition at line 1326 of file SDL_malloc.c.

#define unlink_chunk (   M,
  P,
 
)
Value:
if (is_small(S)) unlink_small_chunk(M, P, S)\
else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); }
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3134
#define unlink_small_chunk(M, P, S)
Definition: SDL_malloc.c:3014
#define is_small(s)
Definition: SDL_malloc.c:2286

Definition at line 3211 of file SDL_malloc.c.

Referenced by dlfree(), and prepend_alloc().

#define unlink_first_small_chunk (   M,
  B,
  P,
  I 
)
Value:
{\
mchunkptr F = P->fd;\
assert(P != B);\
assert(P != F);\
if (B == F)\
else if (RTCHECK(ok_address(M, F))) {\
B->fd = F;\
F->bk = B;\
}\
else {\
}\
}
#define clear_smallmap(M, i)
Definition: SDL_malloc.c:2352
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
#define assert(x)
Definition: SDL_malloc.c:1240
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2242
#define small_index2size(i)
Definition: SDL_malloc.c:2288
#define I(x, y, z)
Definition: SDL_test_md5.c:76
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define F(x, y, z)
Definition: SDL_test_md5.c:73
#define ok_address(M, a)
Definition: SDL_malloc.c:2428

Definition at line 3034 of file SDL_malloc.c.

Referenced by dlmalloc().

#define unlink_large_chunk (   M,
 
)

Definition at line 3134 of file SDL_malloc.c.

Referenced by release_unused_segments(), tmalloc_large(), and tmalloc_small().

#define unlink_small_chunk (   M,
  P,
 
)
Value:
{\
mchunkptr F = P->fd;\
mchunkptr B = P->bk;\
assert(P != B);\
assert(P != F);\
if (F == B)\
else if (RTCHECK((F == smallbin_at(M,I) || ok_address(M, F)) &&\
(B == smallbin_at(M,I) || ok_address(M, B)))) {\
F->bk = B;\
B->fd = F;\
}\
else {\
}\
}
size_t bindex_t
Definition: SDL_malloc.c:1694
#define clear_smallmap(M, i)
Definition: SDL_malloc.c:2352
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
#define assert(x)
Definition: SDL_malloc.c:1240
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2242
#define small_index2size(i)
Definition: SDL_malloc.c:2288
#define I(x, y, z)
Definition: SDL_test_md5.c:76
#define small_index(s)
Definition: SDL_malloc.c:2287
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define F(x, y, z)
Definition: SDL_test_md5.c:73
#define ok_address(M, a)
Definition: SDL_malloc.c:2428

Definition at line 3014 of file SDL_malloc.c.

#define USAGE_ERROR_ACTION (   m,
  p 
)    ABORT

Definition at line 2246 of file SDL_malloc.c.

Referenced by dlfree(), dlrealloc(), and internal_realloc().

#define USE_BUILTIN_FFS   0

Definition at line 627 of file SDL_malloc.c.

#define USE_DEV_RANDOM   0

Definition at line 630 of file SDL_malloc.c.

#define use_lock (   M)    ((M)->mflags & USE_LOCK_BIT)

Definition at line 2119 of file SDL_malloc.c.

#define USE_LOCK_BIT   (2U)

Definition at line 1523 of file SDL_malloc.c.

Referenced by init_mparams().

#define USE_LOCKS   1

Definition at line 62 of file SDL_malloc.c.

#define use_mmap (   M)    ((M)->mflags & USE_MMAP_BIT)

Definition at line 2123 of file SDL_malloc.c.

Referenced by ialloc(), and sys_alloc().

#define USE_MMAP_BIT   (SIZE_T_ONE)

Definition at line 1364 of file SDL_malloc.c.

Referenced by init_mparams().

#define use_noncontiguous (   M)    ((M)->mflags & USE_NONCONTIGUOUS_BIT)

Definition at line 2127 of file SDL_malloc.c.

Referenced by sys_alloc().

#define USE_NONCONTIGUOUS_BIT   (4U)

Definition at line 1448 of file SDL_malloc.c.

Referenced by init_mparams().

#define WIN32   1

Definition at line 506 of file SDL_malloc.c.

#define WIN32_LEAN_AND_MEAN

Definition at line 510 of file SDL_malloc.c.

Typedef Documentation

typedef size_t bindex_t

Definition at line 1694 of file SDL_malloc.c.

typedef unsigned int binmap_t

Definition at line 1695 of file SDL_malloc.c.

typedef unsigned int flag_t

Definition at line 1696 of file SDL_malloc.c.

Function Documentation

static void add_segment ( mstate  m,
char *  tbase,
size_t  tsize,
flag_t  mmapped 
)
static

Definition at line 3408 of file SDL_malloc.c.

References align_offset, assert, check_top_chunk, chunk2mem, CHUNK_ALIGN_MASK, chunk_plus_offset, FENCEPOST_HEAD, FOUR_SIZE_T_SIZES, init_top(), insert_chunk, is_aligned, MIN_CHUNK_SIZE, pad_request, segment_holding(), set_free_with_pinuse, set_size_and_pinuse_of_inuse_chunk, SIZE_T_SIZE, and TOP_FOOT_SIZE.

Referenced by sys_alloc().

3409 {
3410  /* Determine locations and sizes of segment, fenceposts, old top */
3411  char *old_top = (char *) m->top;
3412  msegmentptr oldsp = segment_holding(m, old_top);
3413  char *old_end = oldsp->base + oldsp->size;
3414  size_t ssize = pad_request(sizeof(struct malloc_segment));
3415  char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
3416  size_t offset = align_offset(chunk2mem(rawsp));
3417  char *asp = rawsp + offset;
3418  char *csp = (asp < (old_top + MIN_CHUNK_SIZE)) ? old_top : asp;
3419  mchunkptr sp = (mchunkptr) csp;
3420  msegmentptr ss = (msegmentptr) (chunk2mem(sp));
3421  mchunkptr tnext = chunk_plus_offset(sp, ssize);
3422  mchunkptr p = tnext;
3423  int nfences = 0;
3424 
3425  /* reset top to new space */
3426  init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
3427 
3428  /* Set up segment record */
3429  assert(is_aligned(ss));
3431  *ss = m->seg; /* Push current record */
3432  m->seg.base = tbase;
3433  m->seg.size = tsize;
3434  m->seg.sflags = mmapped;
3435  m->seg.next = ss;
3436 
3437  /* Insert trailing fenceposts */
3438  for (;;) {
3439  mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);
3440  p->head = FENCEPOST_HEAD;
3441  ++nfences;
3442  if ((char *) (&(nextp->head)) < old_end)
3443  p = nextp;
3444  else
3445  break;
3446  }
3447  assert(nfences >= 2);
3448 
3449  /* Insert the rest of old top into a bin as an ordinary free chunk */
3450  if (csp != old_top) {
3451  mchunkptr q = (mchunkptr) old_top;
3452  size_t psize = csp - old_top;
3453  mchunkptr tn = chunk_plus_offset(q, psize);
3454  set_free_with_pinuse(q, psize, tn);
3455  insert_chunk(m, q, psize);
3456  }
3457 
3458  check_top_chunk(m, m->top);
3459 }
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3207
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2087
GLfloat GLfloat p
const GLfloat * m
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
#define set_free_with_pinuse(p, s, n)
Definition: SDL_malloc.c:1781
GLintptr offset
#define assert(x)
Definition: SDL_malloc.c:1240
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define FOUR_SIZE_T_SIZES
Definition: SDL_malloc.c:1327
#define CHUNK_ALIGN_MASK
Definition: SDL_malloc.c:1332
#define is_aligned(A)
Definition: SDL_malloc.c:1335
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
static void init_top(mstate m, mchunkptr p, size_t psize)
Definition: SDL_malloc.c:3316
static msegmentptr segment_holding(mstate m, char *addr)
Definition: SDL_malloc.c:2154
#define pad_request(req)
Definition: SDL_malloc.c:1728
#define align_offset(A)
Definition: SDL_malloc.c:1338
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
static int change_mparam ( int  param_number,
int  value 
)
static

Definition at line 2590 of file SDL_malloc.c.

References malloc_params::granularity, init_mparams(), M_GRANULARITY, M_MMAP_THRESHOLD, M_TRIM_THRESHOLD, malloc_params::mmap_threshold, mparams, malloc_params::page_size, and malloc_params::trim_threshold.

Referenced by dlmallopt().

2591 {
2592  size_t val = (size_t) value;
2593  init_mparams();
2594  switch (param_number) {
2595  case M_TRIM_THRESHOLD:
2597  return 1;
2598  case M_GRANULARITY:
2599  if (val >= mparams.page_size && ((val & (val - 1)) == 0)) {
2601  return 1;
2602  } else
2603  return 0;
2604  case M_MMAP_THRESHOLD:
2606  return 1;
2607  default:
2608  return 0;
2609  }
2610 }
#define M_MMAP_THRESHOLD
Definition: SDL_malloc.c:655
#define M_GRANULARITY
Definition: SDL_malloc.c:654
unsigned int size_t
GLuint GLfloat * val
size_t trim_threshold
Definition: SDL_malloc.c:2103
size_t page_size
Definition: SDL_malloc.c:2100
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
GLsizei const GLfloat * value
#define M_TRIM_THRESHOLD
Definition: SDL_malloc.c:653
size_t granularity
Definition: SDL_malloc.c:2101
static int init_mparams(void)
Definition: SDL_malloc.c:2512
size_t mmap_threshold
Definition: SDL_malloc.c:2102
void * dlcalloc ( size_t  n_elements,
size_t  elem_size 
)

Definition at line 4406 of file SDL_malloc.c.

References calloc_must_clear, dlmalloc, MAX_SIZE_T, mem2chunk, and memset.

4407 {
4408  void *mem;
4409  size_t req = 0;
4410  if (n_elements != 0) {
4411  req = n_elements * elem_size;
4412  if (((n_elements | elem_size) & ~(size_t) 0xffff) &&
4413  (req / n_elements != elem_size))
4414  req = MAX_SIZE_T; /* force downstream failure on overflow */
4415  }
4416  mem = dlmalloc(req);
4417  if (mem != 0 && calloc_must_clear(mem2chunk(mem)))
4418  memset(mem, 0, req);
4419  return mem;
4420 }
#define memset
Definition: SDL_malloc.c:639
#define MAX_SIZE_T
Definition: SDL_malloc.c:539
#define dlmalloc
Definition: SDL_malloc.c:717
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
#define calloc_must_clear(p)
Definition: SDL_malloc.c:1795
void dlfree ( void mem)

Definition at line 4309 of file SDL_malloc.c.

References CALL_MUNMAP, check_free_chunk, check_inuse_chunk, chunk_minus_offset, chunk_plus_offset, chunksize, cinuse, fm, insert_chunk, INUSE_BITS, IS_MMAPPED_BIT, mem2chunk, MMAP_FOOT_PAD, ok_address, ok_cinuse, ok_magic, ok_next, ok_pinuse, pinuse, PINUSE_BIT, POSTACTION, PREACTION, RTCHECK, set_free_with_pinuse, set_size_and_pinuse_of_free_chunk, should_trim, sys_trim(), unlink_chunk, and USAGE_ERROR_ACTION.

4310 {
4311  /*
4312  Consolidate freed chunks with preceeding or succeeding bordering
4313  free chunks, if they exist, and then place in a bin. Intermixed
4314  with special cases for top, dv, mmapped chunks, and usage errors.
4315  */
4316 
4317  if (mem != 0) {
4318  mchunkptr p = mem2chunk(mem);
4319 #if FOOTERS
4320  mstate fm = get_mstate_for(p);
4321  if (!ok_magic(fm)) {
4322  USAGE_ERROR_ACTION(fm, p);
4323  return;
4324  }
4325 #else /* FOOTERS */
4326 #define fm gm
4327 #endif /* FOOTERS */
4328  if (!PREACTION(fm)) {
4329  check_inuse_chunk(fm, p);
4330  if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) {
4331  size_t psize = chunksize(p);
4332  mchunkptr next = chunk_plus_offset(p, psize);
4333  if (!pinuse(p)) {
4334  size_t prevsize = p->prev_foot;
4335  if ((prevsize & IS_MMAPPED_BIT) != 0) {
4336  prevsize &= ~IS_MMAPPED_BIT;
4337  psize += prevsize + MMAP_FOOT_PAD;
4338  if (CALL_MUNMAP((char *) p - prevsize, psize) == 0)
4339  fm->footprint -= psize;
4340  goto postaction;
4341  } else {
4342  mchunkptr prev = chunk_minus_offset(p, prevsize);
4343  psize += prevsize;
4344  p = prev;
4345  if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */
4346  if (p != fm->dv) {
4347  unlink_chunk(fm, p, prevsize);
4348  } else if ((next->head & INUSE_BITS) ==
4349  INUSE_BITS) {
4350  fm->dvsize = psize;
4351  set_free_with_pinuse(p, psize, next);
4352  goto postaction;
4353  }
4354  } else
4355  goto erroraction;
4356  }
4357  }
4358 
4359  if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) {
4360  if (!cinuse(next)) { /* consolidate forward */
4361  if (next == fm->top) {
4362  size_t tsize = fm->topsize += psize;
4363  fm->top = p;
4364  p->head = tsize | PINUSE_BIT;
4365  if (p == fm->dv) {
4366  fm->dv = 0;
4367  fm->dvsize = 0;
4368  }
4369  if (should_trim(fm, tsize))
4370  sys_trim(fm, 0);
4371  goto postaction;
4372  } else if (next == fm->dv) {
4373  size_t dsize = fm->dvsize += psize;
4374  fm->dv = p;
4376  goto postaction;
4377  } else {
4378  size_t nsize = chunksize(next);
4379  psize += nsize;
4380  unlink_chunk(fm, next, nsize);
4382  if (p == fm->dv) {
4383  fm->dvsize = psize;
4384  goto postaction;
4385  }
4386  }
4387  } else
4388  set_free_with_pinuse(p, psize, next);
4389  insert_chunk(fm, p, psize);
4390  check_free_chunk(fm, p);
4391  goto postaction;
4392  }
4393  }
4394  erroraction:
4395  USAGE_ERROR_ACTION(fm, p);
4396  postaction:
4397  POSTACTION(fm);
4398  }
4399  }
4400 #if !FOOTERS
4401 #undef fm
4402 #endif /* FOOTERS */
4403 }
#define USAGE_ERROR_ACTION(m, p)
Definition: SDL_malloc.c:2246
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
#define fm
#define ok_cinuse(p)
Definition: SDL_malloc.c:2432
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3207
#define cinuse(p)
Definition: SDL_malloc.c:1754
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
GLfloat GLfloat p
#define set_free_with_pinuse(p, s, n)
Definition: SDL_malloc.c:1781
#define IS_MMAPPED_BIT
Definition: SDL_malloc.c:1363
#define ok_pinuse(p)
Definition: SDL_malloc.c:2434
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define CALL_MUNMAP(a, s)
Definition: SDL_malloc.c:1430
#define INUSE_BITS
Definition: SDL_malloc.c:1748
static int sys_trim(mstate m, size_t pad)
Definition: SDL_malloc.c:3706
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2256
#define unlink_chunk(M, P, S)
Definition: SDL_malloc.c:3211
#define ok_next(p, n)
Definition: SDL_malloc.c:2430
#define chunk_minus_offset(p, s)
Definition: SDL_malloc.c:1763
#define should_trim(M, s)
Definition: SDL_malloc.c:2179
#define PREACTION(M)
Definition: SDL_malloc.c:2206
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define MMAP_FOOT_PAD
Definition: SDL_malloc.c:1711
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
#define pinuse(p)
Definition: SDL_malloc.c:1755
#define check_free_chunk(M, P)
Definition: SDL_malloc.c:2255
#define ok_address(M, a)
Definition: SDL_malloc.c:2428
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
#define ok_magic(M)
Definition: SDL_malloc.c:2447
void** dlindependent_calloc ( size_t  ,
size_t  ,
void **   
)
void** dlindependent_calloc ( size_t  n_elements,
size_t  elem_size,
void chunks[] 
)

Definition at line 4454 of file SDL_malloc.c.

References gm, and ialloc().

4455 {
4456  size_t sz = elem_size; /* serves as 1-element array */
4457  return ialloc(gm, n_elements, &sz, 3, chunks);
4458 }
static void ** ialloc(mstate m, size_t n_elements, size_t *sizes, int opts, void *chunks[])
Definition: SDL_malloc.c:4049
#define gm
Definition: SDL_malloc.c:2111
void** dlindependent_comalloc ( size_t  ,
size_t ,
void **   
)
void** dlindependent_comalloc ( size_t  n_elements,
size_t  sizes[],
void chunks[] 
)

Definition at line 4461 of file SDL_malloc.c.

References gm, and ialloc().

4462 {
4463  return ialloc(gm, n_elements, sizes, 0, chunks);
4464 }
static void ** ialloc(mstate m, size_t n_elements, size_t *sizes, int opts, void *chunks[])
Definition: SDL_malloc.c:4049
#define gm
Definition: SDL_malloc.c:2111
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
struct mallinfo dlmallinfo ( void  )

Definition at line 4510 of file SDL_malloc.c.

References gm, and internal_mallinfo().

4511 {
4512  return internal_mallinfo(gm);
4513 }
#define gm
Definition: SDL_malloc.c:2111
static struct mallinfo internal_mallinfo(mstate m)
Definition: SDL_malloc.c:2905
void * dlmalloc ( size_t  bytes)

Definition at line 4175 of file SDL_malloc.c.

References assert, check_malloced_chunk, check_top_chunk, chunk2mem, chunk_plus_offset, chunksize, compute_bit2idx, gm, i, idx2bit, least_bit, left_bits, MAX_REQUEST, MAX_SIZE_T, MAX_SMALL_REQUEST, MIN_CHUNK_SIZE, MIN_REQUEST, pad_request, PINUSE_BIT, POSTACTION, PREACTION, replace_dv, set_inuse_and_pinuse, set_size_and_pinuse_of_free_chunk, set_size_and_pinuse_of_inuse_chunk, SIZE_T_SIZE, small_index, small_index2size, smallbin_at, sys_alloc(), tmalloc_large(), tmalloc_small(), and unlink_first_small_chunk.

4176 {
4177  /*
4178  Basic algorithm:
4179  If a small request (< 256 bytes minus per-chunk overhead):
4180  1. If one exists, use a remainderless chunk in associated smallbin.
4181  (Remainderless means that there are too few excess bytes to
4182  represent as a chunk.)
4183  2. If it is big enough, use the dv chunk, which is normally the
4184  chunk adjacent to the one used for the most recent small request.
4185  3. If one exists, split the smallest available chunk in a bin,
4186  saving remainder in dv.
4187  4. If it is big enough, use the top chunk.
4188  5. If available, get memory from system and use it
4189  Otherwise, for a large request:
4190  1. Find the smallest available binned chunk that fits, and use it
4191  if it is better fitting than dv chunk, splitting if necessary.
4192  2. If better fitting than any binned chunk, use the dv chunk.
4193  3. If it is big enough, use the top chunk.
4194  4. If request size >= mmap threshold, try to directly mmap this chunk.
4195  5. If available, get memory from system and use it
4196 
4197  The ugly goto's here ensure that postaction occurs along all paths.
4198  */
4199 
4200  if (!PREACTION(gm)) {
4201  void *mem;
4202  size_t nb;
4203  if (bytes <= MAX_SMALL_REQUEST) {
4204  bindex_t idx;
4205  binmap_t smallbits;
4206  nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes);
4207  idx = small_index(nb);
4208  smallbits = gm->smallmap >> idx;
4209 
4210  if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */
4211  mchunkptr b, p;
4212  idx += ~smallbits & 1; /* Uses next bin if idx empty */
4213  b = smallbin_at(gm, idx);
4214  p = b->fd;
4215  assert(chunksize(p) == small_index2size(idx));
4216  unlink_first_small_chunk(gm, b, p, idx);
4218  mem = chunk2mem(p);
4219  check_malloced_chunk(gm, mem, nb);
4220  goto postaction;
4221  }
4222 
4223  else if (nb > gm->dvsize) {
4224  if (smallbits != 0) { /* Use chunk in next nonempty smallbin */
4225  mchunkptr b, p, r;
4226  size_t rsize;
4227  bindex_t i;
4228  binmap_t leftbits =
4229  (smallbits << idx) & left_bits(idx2bit(idx));
4230  binmap_t leastbit = least_bit(leftbits);
4231  compute_bit2idx(leastbit, i);
4232  b = smallbin_at(gm, i);
4233  p = b->fd;
4234  assert(chunksize(p) == small_index2size(i));
4235  unlink_first_small_chunk(gm, b, p, i);
4236  rsize = small_index2size(i) - nb;
4237  /* Fit here cannot be remainderless if 4byte sizes */
4238  if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE)
4240  else {
4242  r = chunk_plus_offset(p, nb);
4244  replace_dv(gm, r, rsize);
4245  }
4246  mem = chunk2mem(p);
4247  check_malloced_chunk(gm, mem, nb);
4248  goto postaction;
4249  }
4250 
4251  else if (gm->treemap != 0
4252  && (mem = tmalloc_small(gm, nb)) != 0) {
4253  check_malloced_chunk(gm, mem, nb);
4254  goto postaction;
4255  }
4256  }
4257  } else if (bytes >= MAX_REQUEST)
4258  nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */
4259  else {
4260  nb = pad_request(bytes);
4261  if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) {
4262  check_malloced_chunk(gm, mem, nb);
4263  goto postaction;
4264  }
4265  }
4266 
4267  if (nb <= gm->dvsize) {
4268  size_t rsize = gm->dvsize - nb;
4269  mchunkptr p = gm->dv;
4270  if (rsize >= MIN_CHUNK_SIZE) { /* split dv */
4271  mchunkptr r = gm->dv = chunk_plus_offset(p, nb);
4272  gm->dvsize = rsize;
4275  } else { /* exhaust dv */
4276  size_t dvs = gm->dvsize;
4277  gm->dvsize = 0;
4278  gm->dv = 0;
4279  set_inuse_and_pinuse(gm, p, dvs);
4280  }
4281  mem = chunk2mem(p);
4282  check_malloced_chunk(gm, mem, nb);
4283  goto postaction;
4284  }
4285 
4286  else if (nb < gm->topsize) { /* Split top */
4287  size_t rsize = gm->topsize -= nb;
4288  mchunkptr p = gm->top;
4289  mchunkptr r = gm->top = chunk_plus_offset(p, nb);
4290  r->head = rsize | PINUSE_BIT;
4292  mem = chunk2mem(p);
4293  check_top_chunk(gm, gm->top);
4294  check_malloced_chunk(gm, mem, nb);
4295  goto postaction;
4296  }
4297 
4298  mem = sys_alloc(gm, nb);
4299 
4300  postaction:
4301  POSTACTION(gm);
4302  return mem;
4303  }
4304 
4305  return 0;
4306 }
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
static void * sys_alloc(mstate m, size_t nb)
Definition: SDL_malloc.c:3465
size_t bindex_t
Definition: SDL_malloc.c:1694
static void * tmalloc_large(mstate m, size_t nb)
Definition: SDL_malloc.c:3772
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
GLfloat GLfloat p
#define replace_dv(M, P, S)
Definition: SDL_malloc.c:3052
#define compute_bit2idx(X, I)
Definition: SDL_malloc.c:2374
#define assert(x)
Definition: SDL_malloc.c:1240
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define small_index2size(i)
Definition: SDL_malloc.c:2288
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define MIN_REQUEST
Definition: SDL_malloc.c:1725
#define unlink_first_small_chunk(M, B, P, I)
Definition: SDL_malloc.c:3034
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
#define gm
Definition: SDL_malloc.c:2111
static void * tmalloc_small(mstate m, size_t nb)
Definition: SDL_malloc.c:3847
#define MAX_SIZE_T
Definition: SDL_malloc.c:539
#define idx2bit(i)
Definition: SDL_malloc.c:2348
#define MAX_SMALL_REQUEST
Definition: SDL_malloc.c:2063
#define PREACTION(M)
Definition: SDL_malloc.c:2206
#define check_malloced_chunk(M, P, N)
Definition: SDL_malloc.c:2257
#define left_bits(x)
Definition: SDL_malloc.c:2392
#define MAX_REQUEST
Definition: SDL_malloc.c:1724
#define small_index(s)
Definition: SDL_malloc.c:2287
#define chunksize(p)
Definition: SDL_malloc.c:1756
unsigned int binmap_t
Definition: SDL_malloc.c:1695
#define pad_request(req)
Definition: SDL_malloc.c:1728
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
GLboolean GLboolean GLboolean b
#define least_bit(x)
Definition: SDL_malloc.c:2389
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
#define set_inuse_and_pinuse(M, p, s)
Definition: SDL_malloc.c:2474
size_t dlmalloc_footprint ( void  )

Definition at line 4497 of file SDL_malloc.c.

References gm.

4498 {
4499  return gm->footprint;
4500 }
#define gm
Definition: SDL_malloc.c:2111
size_t dlmalloc_max_footprint ( void  )

Definition at line 4503 of file SDL_malloc.c.

References gm.

4504 {
4505  return gm->max_footprint;
4506 }
#define gm
Definition: SDL_malloc.c:2111
void dlmalloc_stats ( void  )

Definition at line 4517 of file SDL_malloc.c.

References gm, and internal_malloc_stats().

4518 {
4520 }
#define gm
Definition: SDL_malloc.c:2111
static void internal_malloc_stats(mstate m)
Definition: SDL_malloc.c:2946
int dlmalloc_trim ( size_t  pad)

Definition at line 4486 of file SDL_malloc.c.

References gm, POSTACTION, PREACTION, and sys_trim().

4487 {
4488  int result = 0;
4489  if (!PREACTION(gm)) {
4490  result = sys_trim(gm, pad);
4491  POSTACTION(gm);
4492  }
4493  return result;
4494 }
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
GLuint64EXT * result
static int sys_trim(mstate m, size_t pad)
Definition: SDL_malloc.c:3706
#define gm
Definition: SDL_malloc.c:2111
#define PREACTION(M)
Definition: SDL_malloc.c:2206
size_t dlmalloc_usable_size ( void mem)

Definition at line 4523 of file SDL_malloc.c.

References chunksize, cinuse, mem2chunk, and overhead_for.

4524 {
4525  if (mem != 0) {
4526  mchunkptr p = mem2chunk(mem);
4527  if (cinuse(p))
4528  return chunksize(p) - overhead_for(p);
4529  }
4530  return 0;
4531 }
#define cinuse(p)
Definition: SDL_malloc.c:1754
GLfloat GLfloat p
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define overhead_for(p)
Definition: SDL_malloc.c:1788
int dlmallopt ( int  param_number,
int  value 
)

Definition at line 4534 of file SDL_malloc.c.

References change_mparam().

4535 {
4536  return change_mparam(param_number, value);
4537 }
static int change_mparam(int param_number, int value)
Definition: SDL_malloc.c:2590
GLsizei const GLfloat * value
void * dlmemalign ( size_t  alignment,
size_t  bytes 
)

Definition at line 4448 of file SDL_malloc.c.

References gm, and internal_memalign().

4449 {
4450  return internal_memalign(gm, alignment, bytes);
4451 }
#define gm
Definition: SDL_malloc.c:2111
static void * internal_memalign(mstate m, size_t alignment, size_t bytes)
Definition: SDL_malloc.c:3959
void * dlpvalloc ( size_t  bytes)

Definition at line 4476 of file SDL_malloc.c.

References dlmemalign, init_mparams(), mparams, malloc_params::page_size, and SIZE_T_ONE.

4477 {
4478  size_t pagesz;
4479  init_mparams();
4480  pagesz = mparams.page_size;
4481  return dlmemalign(pagesz,
4482  (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE));
4483 }
#define dlmemalign
Definition: SDL_malloc.c:718
size_t page_size
Definition: SDL_malloc.c:2100
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
static int init_mparams(void)
Definition: SDL_malloc.c:2512
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
void * dlrealloc ( void oldmem,
size_t  bytes 
)

Definition at line 4423 of file SDL_malloc.c.

References dlfree, dlmalloc, gm, internal_realloc(), mem2chunk, ok_magic, and USAGE_ERROR_ACTION.

4424 {
4425  if (oldmem == 0)
4426  return dlmalloc(bytes);
4427 #ifdef REALLOC_ZERO_BYTES_FREES
4428  if (bytes == 0) {
4429  dlfree(oldmem);
4430  return 0;
4431  }
4432 #endif /* REALLOC_ZERO_BYTES_FREES */
4433  else {
4434 #if ! FOOTERS
4435  mstate m = gm;
4436 #else /* FOOTERS */
4437  mstate m = get_mstate_for(mem2chunk(oldmem));
4438  if (!ok_magic(m)) {
4439  USAGE_ERROR_ACTION(m, oldmem);
4440  return 0;
4441  }
4442 #endif /* FOOTERS */
4443  return internal_realloc(m, oldmem, bytes);
4444  }
4445 }
#define USAGE_ERROR_ACTION(m, p)
Definition: SDL_malloc.c:2246
static void * internal_realloc(mstate m, void *oldmem, size_t bytes)
Definition: SDL_malloc.c:3889
const GLfloat * m
#define gm
Definition: SDL_malloc.c:2111
#define dlmalloc
Definition: SDL_malloc.c:717
#define dlfree
Definition: SDL_malloc.c:716
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
#define ok_magic(M)
Definition: SDL_malloc.c:2447
void * dlvalloc ( size_t  bytes)

Definition at line 4467 of file SDL_malloc.c.

References dlmemalign, init_mparams(), mparams, and malloc_params::page_size.

4468 {
4469  size_t pagesz;
4470  init_mparams();
4471  pagesz = mparams.page_size;
4472  return dlmemalign(pagesz, bytes);
4473 }
#define dlmemalign
Definition: SDL_malloc.c:718
size_t page_size
Definition: SDL_malloc.c:2100
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
static int init_mparams(void)
Definition: SDL_malloc.c:2512
static int has_segment_link ( mstate  m,
msegmentptr  ss 
)
static

Definition at line 2167 of file SDL_malloc.c.

Referenced by sys_trim().

2168 {
2169  msegmentptr sp = &m->seg;
2170  for (;;) {
2171  if ((char *) sp >= ss->base && (char *) sp < ss->base + ss->size)
2172  return 1;
2173  if ((sp = sp->next) == 0)
2174  return 0;
2175  }
2176 }
const GLfloat * m
static void** ialloc ( mstate  m,
size_t  n_elements,
size_t sizes,
int  opts,
void chunks[] 
)
static

Definition at line 4049 of file SDL_malloc.c.

References assert, check_inuse_chunk, chunk2mem, CHUNK_OVERHEAD, chunk_plus_offset, chunksize, disable_mmap, enable_mmap, i, internal_malloc, is_mmapped, mem2chunk, memset, POSTACTION, PREACTION, request2size, set_size_and_pinuse_of_inuse_chunk, SIZE_T_SIZE, and use_mmap.

Referenced by dlindependent_calloc(), and dlindependent_comalloc().

4050 {
4051  /*
4052  This provides common support for independent_X routines, handling
4053  all of the combinations that can result.
4054 
4055  The opts arg has:
4056  bit 0 set if all elements are same size (using sizes[0])
4057  bit 1 set if elements should be zeroed
4058  */
4059 
4060  size_t element_size; /* chunksize of each element, if all same */
4061  size_t contents_size; /* total size of elements */
4062  size_t array_size; /* request size of pointer array */
4063  void *mem; /* malloced aggregate space */
4064  mchunkptr p; /* corresponding chunk */
4065  size_t remainder_size; /* remaining bytes while splitting */
4066  void **marray; /* either "chunks" or malloced ptr array */
4067  mchunkptr array_chunk; /* chunk for malloced ptr array */
4068  flag_t was_enabled; /* to disable mmap */
4069  size_t size;
4070  size_t i;
4071 
4072  /* compute array length, if needed */
4073  if (chunks != 0) {
4074  if (n_elements == 0)
4075  return chunks; /* nothing to do */
4076  marray = chunks;
4077  array_size = 0;
4078  } else {
4079  /* if empty req, must still return chunk representing empty array */
4080  if (n_elements == 0)
4081  return (void **) internal_malloc(m, 0);
4082  marray = 0;
4083  array_size = request2size(n_elements * (sizeof(void *)));
4084  }
4085 
4086  /* compute total element size */
4087  if (opts & 0x1) { /* all-same-size */
4088  element_size = request2size(*sizes);
4089  contents_size = n_elements * element_size;
4090  } else { /* add up all the sizes */
4091  element_size = 0;
4092  contents_size = 0;
4093  for (i = 0; i != n_elements; ++i)
4094  contents_size += request2size(sizes[i]);
4095  }
4096 
4097  size = contents_size + array_size;
4098 
4099  /*
4100  Allocate the aggregate chunk. First disable direct-mmapping so
4101  malloc won't use it, since we would not be able to later
4102  free/realloc space internal to a segregated mmap region.
4103  */
4104  was_enabled = use_mmap(m);
4105  disable_mmap(m);
4106  mem = internal_malloc(m, size - CHUNK_OVERHEAD);
4107  if (was_enabled)
4108  enable_mmap(m);
4109  if (mem == 0)
4110  return 0;
4111 
4112  if (PREACTION(m))
4113  return 0;
4114  p = mem2chunk(mem);
4115  remainder_size = chunksize(p);
4116 
4117  assert(!is_mmapped(p));
4118 
4119  if (opts & 0x2) { /* optionally clear the elements */
4120  memset((size_t *) mem, 0, remainder_size - SIZE_T_SIZE - array_size);
4121  }
4122 
4123  /* If not provided, allocate the pointer array as final part of chunk */
4124  if (marray == 0) {
4125  size_t array_chunk_size;
4126  array_chunk = chunk_plus_offset(p, contents_size);
4127  array_chunk_size = remainder_size - contents_size;
4128  marray = (void **) (chunk2mem(array_chunk));
4129  set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size);
4130  remainder_size = contents_size;
4131  }
4132 
4133  /* split out elements */
4134  for (i = 0;; ++i) {
4135  marray[i] = chunk2mem(p);
4136  if (i != n_elements - 1) {
4137  if (element_size != 0)
4138  size = element_size;
4139  else
4140  size = request2size(sizes[i]);
4141  remainder_size -= size;
4143  p = chunk_plus_offset(p, size);
4144  } else { /* the final element absorbs any overallocation slop */
4145  set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size);
4146  break;
4147  }
4148  }
4149 
4150 #if DEBUG
4151  if (marray != chunks) {
4152  /* final element must have exactly exhausted chunk */
4153  if (element_size != 0) {
4154  assert(remainder_size == element_size);
4155  } else {
4156  assert(remainder_size == request2size(sizes[i]));
4157  }
4158  check_inuse_chunk(m, mem2chunk(marray));
4159  }
4160  for (i = 0; i != n_elements; ++i)
4161  check_inuse_chunk(m, mem2chunk(marray[i]));
4162 
4163 #endif /* DEBUG */
4164 
4165  POSTACTION(m);
4166  return marray;
4167 }
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
#define request2size(req)
Definition: SDL_malloc.c:1732
GLuint GLfloat GLfloat GLfloat x1
unsigned int flag_t
Definition: SDL_malloc.c:1696
GLfloat GLfloat p
const GLfloat * m
#define memset
Definition: SDL_malloc.c:639
#define assert(x)
Definition: SDL_malloc.c:1240
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
GLfixed GLfixed x2
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define CHUNK_OVERHEAD
Definition: SDL_malloc.c:1705
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2256
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLsizeiptr size
#define PREACTION(M)
Definition: SDL_malloc.c:2206
#define enable_mmap(M)
Definition: SDL_malloc.c:2124
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define use_mmap(M)
Definition: SDL_malloc.c:2123
#define internal_malloc(m, b)
Definition: SDL_malloc.c:3228
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
#define disable_mmap(M)
Definition: SDL_malloc.c:2125
#define is_mmapped(p)
Definition: SDL_malloc.c:1784
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
static void init_bins ( mstate  m)
static

Definition at line 3333 of file SDL_malloc.c.

References i, NSMALLBINS, and smallbin_at.

Referenced by sys_alloc().

3334 {
3335  /* Establish circular links for smallbins */
3336  bindex_t i;
3337  for (i = 0; i < NSMALLBINS; ++i) {
3338  sbinptr bin = smallbin_at(m, i);
3339  bin->fd = bin->bk = bin;
3340  }
3341 }
size_t bindex_t
Definition: SDL_malloc.c:1694
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
const GLfloat * m
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NSMALLBINS
Definition: SDL_malloc.c:2056
static int init_mparams ( void  )
static

Definition at line 2512 of file SDL_malloc.c.

References ABORT, ACQUIRE_MAGIC_INIT_LOCK, DEFAULT_GRANULARITY, malloc_params::default_mflags, DEFAULT_MMAP_THRESHOLD, DEFAULT_TRIM_THRESHOLD, gm, malloc_params::granularity, INITIAL_LOCK, malloc_params::magic, MALLOC_ALIGNMENT, MAX_SIZE_T, MCHUNK_SIZE, MIN_CHUNK_SIZE, malloc_params::mmap_threshold, mparams, malloc_params::page_size, RELEASE_MAGIC_INIT_LOCK, SIZE_T_ONE, malloc_params::trim_threshold, USE_LOCK_BIT, USE_MMAP_BIT, and USE_NONCONTIGUOUS_BIT.

Referenced by change_mparam(), dlpvalloc(), dlvalloc(), and sys_alloc().

2513 {
2514  if (mparams.page_size == 0) {
2515  size_t s;
2516 
2519 #if MORECORE_CONTIGUOUS
2521 #else /* MORECORE_CONTIGUOUS */
2524 #endif /* MORECORE_CONTIGUOUS */
2525 
2526 #if (FOOTERS && !INSECURE)
2527  {
2528 #if USE_DEV_RANDOM
2529  int fd;
2530  unsigned char buf[sizeof(size_t)];
2531  /* Try to use /dev/urandom, else fall back on using time */
2532  if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 &&
2533  read(fd, buf, sizeof(buf)) == sizeof(buf)) {
2534  s = *((size_t *) buf);
2535  close(fd);
2536  } else
2537 #endif /* USE_DEV_RANDOM */
2538  s = (size_t) (time(0) ^ (size_t) 0x55555555U);
2539 
2540  s |= (size_t) 8U; /* ensure nonzero */
2541  s &= ~(size_t) 7U; /* improve chances of fault for bad values */
2542 
2543  }
2544 #else /* (FOOTERS && !INSECURE) */
2545  s = (size_t) 0x58585858U;
2546 #endif /* (FOOTERS && !INSECURE) */
2548  if (mparams.magic == 0) {
2549  mparams.magic = s;
2550  /* Set up lock for main malloc area */
2551  INITIAL_LOCK(&gm->mutex);
2552  gm->mflags = mparams.default_mflags;
2553  }
2555 
2556 #ifndef WIN32
2557  mparams.page_size = malloc_getpagesize;
2560 #else /* WIN32 */
2561  {
2562  SYSTEM_INFO system_info;
2563  GetSystemInfo(&system_info);
2564  mparams.page_size = system_info.dwPageSize;
2565  mparams.granularity = system_info.dwAllocationGranularity;
2566  }
2567 #endif /* WIN32 */
2568 
2569  /* Sanity-check configuration:
2570  size_t must be unsigned and as wide as pointer type.
2571  ints must be at least 4 bytes.
2572  alignment must be at least 8.
2573  Alignment, min chunk size, and page size must all be powers of 2.
2574  */
2575  if ((sizeof(size_t) != sizeof(char *)) ||
2576  (MAX_SIZE_T < MIN_CHUNK_SIZE) ||
2577  (sizeof(int) < 4) ||
2578  (MALLOC_ALIGNMENT < (size_t) 8U) ||
2579  ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT - SIZE_T_ONE)) != 0) ||
2580  ((MCHUNK_SIZE & (MCHUNK_SIZE - SIZE_T_ONE)) != 0) ||
2582  || ((mparams.page_size & (mparams.page_size - SIZE_T_ONE)) != 0))
2583  ABORT;
2584  }
2585  return 0;
2586 }
#define DEFAULT_MMAP_THRESHOLD
Definition: SDL_malloc.c:621
#define INITIAL_LOCK(l)
Definition: SDL_malloc.c:1514
flag_t default_mflags
Definition: SDL_malloc.c:2104
#define ACQUIRE_MAGIC_INIT_LOCK()
Definition: SDL_malloc.c:1538
GLdouble s
Definition: SDL_opengl.h:2063
EGLSurface EGLnsecsANDROID time
Definition: eglext.h:518
#define DEFAULT_TRIM_THRESHOLD
Definition: SDL_malloc.c:614
#define ABORT
Definition: SDL_malloc.c:61
#define MCHUNK_SIZE
Definition: SDL_malloc.c:1700
#define USE_NONCONTIGUOUS_BIT
Definition: SDL_malloc.c:1448
unsigned int size_t
size_t trim_threshold
Definition: SDL_malloc.c:2103
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
size_t page_size
Definition: SDL_malloc.c:2100
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
#define gm
Definition: SDL_malloc.c:2111
#define USE_MMAP_BIT
Definition: SDL_malloc.c:1364
#define MALLOC_ALIGNMENT
Definition: SDL_malloc.c:552
#define MAX_SIZE_T
Definition: SDL_malloc.c:539
#define DEFAULT_GRANULARITY
Definition: SDL_malloc.c:609
GLenum GLuint GLenum GLsizei const GLchar * buf
#define RELEASE_MAGIC_INIT_LOCK()
Definition: SDL_malloc.c:1539
size_t granularity
Definition: SDL_malloc.c:2101
#define USE_LOCK_BIT
Definition: SDL_malloc.c:1523
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
GLuint64 GLenum GLint fd
Definition: gl2ext.h:1508
size_t mmap_threshold
Definition: SDL_malloc.c:2102
static void init_top ( mstate  m,
mchunkptr  p,
size_t  psize 
)
static

Definition at line 3316 of file SDL_malloc.c.

References align_offset, chunk2mem, chunk_plus_offset, mparams, PINUSE_BIT, TOP_FOOT_SIZE, and malloc_params::trim_threshold.

Referenced by add_segment(), sys_alloc(), and sys_trim().

3317 {
3318  /* Ensure alignment */
3319  size_t offset = align_offset(chunk2mem(p));
3320  p = (mchunkptr) ((char *) p + offset);
3321  psize -= offset;
3322 
3323  m->top = p;
3324  m->topsize = psize;
3325  p->head = psize | PINUSE_BIT;
3326  /* set size of fake trailing chunk holding overhead space only once */
3327  chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
3328  m->trim_check = mparams.trim_threshold; /* reset on each update */
3329 }
GLfloat GLfloat p
const GLfloat * m
GLintptr offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
size_t trim_threshold
Definition: SDL_malloc.c:2103
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
#define align_offset(A)
Definition: SDL_malloc.c:1338
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
static struct mallinfo internal_mallinfo ( mstate  m)
static

Definition at line 2905 of file SDL_malloc.c.

References align_as_chunk, mallinfo::arena, check_malloc_state, chunksize, cinuse, FENCEPOST_HEAD, mallinfo::fordblks, mallinfo::hblkhd, is_initialized, mallinfo::keepcost, next_chunk, mallinfo::ordblks, POSTACTION, PREACTION, segment_holds, SIZE_T_ONE, TOP_FOOT_SIZE, mallinfo::uordblks, and mallinfo::usmblks.

Referenced by dlmallinfo().

2906 {
2907  struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2908  if (!PREACTION(m)) {
2910  if (is_initialized(m)) {
2911  size_t nfree = SIZE_T_ONE; /* top always free */
2912  size_t mfree = m->topsize + TOP_FOOT_SIZE;
2913  size_t sum = mfree;
2914  msegmentptr s = &m->seg;
2915  while (s != 0) {
2916  mchunkptr q = align_as_chunk(s->base);
2917  while (segment_holds(s, q) &&
2918  q != m->top && q->head != FENCEPOST_HEAD) {
2919  size_t sz = chunksize(q);
2920  sum += sz;
2921  if (!cinuse(q)) {
2922  mfree += sz;
2923  ++nfree;
2924  }
2925  q = next_chunk(q);
2926  }
2927  s = s->next;
2928  }
2929 
2930  nm.arena = sum;
2931  nm.ordblks = nfree;
2932  nm.hblkhd = m->footprint - sum;
2933  nm.usmblks = m->max_footprint;
2934  nm.uordblks = m->footprint - mfree;
2935  nm.fordblks = mfree;
2936  nm.keepcost = m->topsize;
2937  }
2938 
2939  POSTACTION(m);
2940  }
2941  return nm;
2942 }
#define next_chunk(p)
Definition: SDL_malloc.c:1766
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
MALLINFO_FIELD_TYPE arena
Definition: SDL_malloc.c:690
GLdouble s
Definition: SDL_opengl.h:2063
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2087
#define cinuse(p)
Definition: SDL_malloc.c:1754
const GLfloat * m
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
#define is_initialized(M)
Definition: SDL_malloc.c:2113
MALLINFO_FIELD_TYPE ordblks
Definition: SDL_malloc.c:691
MALLINFO_FIELD_TYPE fordblks
Definition: SDL_malloc.c:698
#define align_as_chunk(A)
Definition: SDL_malloc.c:1721
#define PREACTION(M)
Definition: SDL_malloc.c:2206
#define check_malloc_state(M)
Definition: SDL_malloc.c:2259
MALLINFO_FIELD_TYPE keepcost
Definition: SDL_malloc.c:699
#define segment_holds(S, A)
Definition: SDL_malloc.c:2149
MALLINFO_FIELD_TYPE hblkhd
Definition: SDL_malloc.c:694
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
MALLINFO_FIELD_TYPE uordblks
Definition: SDL_malloc.c:697
MALLINFO_FIELD_TYPE usmblks
Definition: SDL_malloc.c:695
static void internal_malloc_stats ( mstate  m)
static

Definition at line 2946 of file SDL_malloc.c.

References align_as_chunk, check_malloc_state, chunksize, cinuse, FENCEPOST_HEAD, is_initialized, next_chunk, POSTACTION, PREACTION, segment_holds, and TOP_FOOT_SIZE.

Referenced by dlmalloc_stats().

2947 {
2948  if (!PREACTION(m)) {
2949 #ifndef LACKS_STDIO_H
2950  size_t maxfp = 0;
2951 #endif
2952  size_t fp = 0;
2953  size_t used = 0;
2955  if (is_initialized(m)) {
2956  msegmentptr s = &m->seg;
2957 #ifndef LACKS_STDIO_H
2958  maxfp = m->max_footprint;
2959 #endif
2960  fp = m->footprint;
2961  used = fp - (m->topsize + TOP_FOOT_SIZE);
2962 
2963  while (s != 0) {
2964  mchunkptr q = align_as_chunk(s->base);
2965  while (segment_holds(s, q) &&
2966  q != m->top && q->head != FENCEPOST_HEAD) {
2967  if (!cinuse(q))
2968  used -= chunksize(q);
2969  q = next_chunk(q);
2970  }
2971  s = s->next;
2972  }
2973  }
2974 #ifndef LACKS_STDIO_H
2975  fprintf(stderr, "max system bytes = %10lu\n",
2976  (unsigned long) (maxfp));
2977  fprintf(stderr, "system bytes = %10lu\n", (unsigned long) (fp));
2978  fprintf(stderr, "in use bytes = %10lu\n", (unsigned long) (used));
2979 #endif
2980 
2981  POSTACTION(m);
2982  }
2983 }
#define next_chunk(p)
Definition: SDL_malloc.c:1766
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
GLdouble s
Definition: SDL_opengl.h:2063
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2087
#define cinuse(p)
Definition: SDL_malloc.c:1754
const GLfloat * m
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
#define is_initialized(M)
Definition: SDL_malloc.c:2113
#define align_as_chunk(A)
Definition: SDL_malloc.c:1721
#define PREACTION(M)
Definition: SDL_malloc.c:2206
#define check_malloc_state(M)
Definition: SDL_malloc.c:2259
#define segment_holds(S, A)
Definition: SDL_malloc.c:2149
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
static void* internal_memalign ( mstate  m,
size_t  alignment,
size_t  bytes 
)
static

Definition at line 3959 of file SDL_malloc.c.

References assert, check_inuse_chunk, chunk2mem, CHUNK_OVERHEAD, chunk_plus_offset, chunksize, CINUSE_BIT, internal_free, internal_malloc, is_mmapped, MALLOC_ALIGNMENT, MALLOC_FAILURE_ACTION, MAX_REQUEST, mem2chunk, MIN_CHUNK_SIZE, POSTACTION, PREACTION, request2size, set_inuse, and SIZE_T_ONE.

Referenced by dlmemalign().

3960 {
3961  if (alignment <= MALLOC_ALIGNMENT) /* Can just use malloc */
3962  return internal_malloc(m, bytes);
3963  if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */
3964  alignment = MIN_CHUNK_SIZE;
3965  if ((alignment & (alignment - SIZE_T_ONE)) != 0) { /* Ensure a power of 2 */
3966  size_t a = MALLOC_ALIGNMENT << 1;
3967  while (a < alignment)
3968  a <<= 1;
3969  alignment = a;
3970  }
3971 
3972  if (bytes >= MAX_REQUEST - alignment) {
3973  if (m != 0) { /* Test isn't needed but avoids compiler warning */
3975  }
3976  } else {
3977  size_t nb = request2size(bytes);
3978  size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD;
3979  char *mem = (char *) internal_malloc(m, req);
3980  if (mem != 0) {
3981  void *leader = 0;
3982  void *trailer = 0;
3983  mchunkptr p = mem2chunk(mem);
3984 
3985  if (PREACTION(m))
3986  return 0;
3987  if ((((size_t) (mem)) % alignment) != 0) { /* misaligned */
3988  /*
3989  Find an aligned spot inside chunk. Since we need to give
3990  back leading space in a chunk of at least MIN_CHUNK_SIZE, if
3991  the first calculation places us at a spot with less than
3992  MIN_CHUNK_SIZE leader, we can move to the next aligned spot.
3993  We've allocated enough total room so that this is always
3994  possible.
3995  */
3996  char *br = (char *) mem2chunk((size_t) (((size_t) (mem +
3997  alignment -
3998  SIZE_T_ONE))
3999  & -alignment));
4000  char *pos =
4001  ((size_t) (br - (char *) (p)) >=
4002  MIN_CHUNK_SIZE) ? br : br + alignment;
4003  mchunkptr newp = (mchunkptr) pos;
4004  size_t leadsize = pos - (char *) (p);
4005  size_t newsize = chunksize(p) - leadsize;
4006 
4007  if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */
4008  newp->prev_foot = p->prev_foot + leadsize;
4009  newp->head = (newsize | CINUSE_BIT);
4010  } else { /* Otherwise, give back leader, use the rest */
4011  set_inuse(m, newp, newsize);
4012  set_inuse(m, p, leadsize);
4013  leader = chunk2mem(p);
4014  }
4015  p = newp;
4016  }
4017 
4018  /* Give back spare room at the end */
4019  if (!is_mmapped(p)) {
4020  size_t size = chunksize(p);
4021  if (size > nb + MIN_CHUNK_SIZE) {
4022  size_t remainder_size = size - nb;
4023  mchunkptr remainder = chunk_plus_offset(p, nb);
4024  set_inuse(m, p, nb);
4025  set_inuse(m, remainder, remainder_size);
4026  trailer = chunk2mem(remainder);
4027  }
4028  }
4029 
4030  assert(chunksize(p) >= nb);
4031  assert((((size_t) (chunk2mem(p))) % alignment) == 0);
4032  check_inuse_chunk(m, p);
4033  POSTACTION(m);
4034  if (leader != 0) {
4035  internal_free(m, leader);
4036  }
4037  if (trailer != 0) {
4038  internal_free(m, trailer);
4039  }
4040  return chunk2mem(p);
4041  }
4042  }
4043  return 0;
4044 }
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
#define request2size(req)
Definition: SDL_malloc.c:1732
#define MALLOC_FAILURE_ACTION
Definition: SDL_malloc.c:522
GLfloat GLfloat p
const GLfloat * m
#define assert(x)
Definition: SDL_malloc.c:1240
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define CHUNK_OVERHEAD
Definition: SDL_malloc.c:1705
unsigned int size_t
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2256
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
#define set_inuse(M, p, s)
Definition: SDL_malloc.c:2469
#define MALLOC_ALIGNMENT
Definition: SDL_malloc.c:552
GLsizeiptr size
#define PREACTION(M)
Definition: SDL_malloc.c:2206
#define MAX_REQUEST
Definition: SDL_malloc.c:1724
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
#define internal_free(m, mem)
Definition: SDL_malloc.c:3229
#define chunksize(p)
Definition: SDL_malloc.c:1756
GLboolean GLboolean GLboolean GLboolean a
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
#define internal_malloc(m, b)
Definition: SDL_malloc.c:3228
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
#define is_mmapped(p)
Definition: SDL_malloc.c:1784
static void* internal_realloc ( mstate  m,
void oldmem,
size_t  bytes 
)
static

Definition at line 3889 of file SDL_malloc.c.

References check_inuse_chunk, chunk2mem, chunk_plus_offset, chunksize, internal_free, internal_malloc, is_mmapped, MALLOC_FAILURE_ACTION, MAX_REQUEST, mem2chunk, memcpy, MIN_CHUNK_SIZE, mmap_resize(), ok_address, ok_cinuse, ok_next, ok_pinuse, overhead_for, PINUSE_BIT, POSTACTION, PREACTION, request2size, RTCHECK, set_inuse, and USAGE_ERROR_ACTION.

Referenced by dlrealloc().

3890 {
3891  if (bytes >= MAX_REQUEST) {
3893  return 0;
3894  }
3895  if (!PREACTION(m)) {
3896  mchunkptr oldp = mem2chunk(oldmem);
3897  size_t oldsize = chunksize(oldp);
3898  mchunkptr next = chunk_plus_offset(oldp, oldsize);
3899  mchunkptr newp = 0;
3900  void *extra = 0;
3901 
3902  /* Try to either shrink or extend into top. Else malloc-copy-free */
3903 
3904  if (RTCHECK(ok_address(m, oldp) && ok_cinuse(oldp) &&
3905  ok_next(oldp, next) && ok_pinuse(next))) {
3906  size_t nb = request2size(bytes);
3907  if (is_mmapped(oldp))
3908  newp = mmap_resize(m, oldp, nb);
3909  else if (oldsize >= nb) { /* already big enough */
3910  size_t rsize = oldsize - nb;
3911  newp = oldp;
3912  if (rsize >= MIN_CHUNK_SIZE) {
3913  mchunkptr remainder = chunk_plus_offset(newp, nb);
3914  set_inuse(m, newp, nb);
3915  set_inuse(m, remainder, rsize);
3916  extra = chunk2mem(remainder);
3917  }
3918  } else if (next == m->top && oldsize + m->topsize > nb) {
3919  /* Expand into top */
3920  size_t newsize = oldsize + m->topsize;
3921  size_t newtopsize = newsize - nb;
3922  mchunkptr newtop = chunk_plus_offset(oldp, nb);
3923  set_inuse(m, oldp, nb);
3924  newtop->head = newtopsize | PINUSE_BIT;
3925  m->top = newtop;
3926  m->topsize = newtopsize;
3927  newp = oldp;
3928  }
3929  } else {
3930  USAGE_ERROR_ACTION(m, oldmem);
3931  POSTACTION(m);
3932  return 0;
3933  }
3934 
3935  POSTACTION(m);
3936 
3937  if (newp != 0) {
3938  if (extra != 0) {
3939  internal_free(m, extra);
3940  }
3941  check_inuse_chunk(m, newp);
3942  return chunk2mem(newp);
3943  } else {
3944  void *newmem = internal_malloc(m, bytes);
3945  if (newmem != 0) {
3946  size_t oc = oldsize - overhead_for(oldp);
3947  memcpy(newmem, oldmem, (oc < bytes) ? oc : bytes);
3948  internal_free(m, oldmem);
3949  }
3950  return newmem;
3951  }
3952  }
3953  return 0;
3954 }
#define USAGE_ERROR_ACTION(m, p)
Definition: SDL_malloc.c:2246
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
#define request2size(req)
Definition: SDL_malloc.c:1732
#define ok_cinuse(p)
Definition: SDL_malloc.c:2432
#define MALLOC_FAILURE_ACTION
Definition: SDL_malloc.c:522
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
const GLfloat * m
#define ok_pinuse(p)
Definition: SDL_malloc.c:2434
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb)
Definition: SDL_malloc.c:3277
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2256
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
#define set_inuse(M, p, s)
Definition: SDL_malloc.c:2469
#define ok_next(p, n)
Definition: SDL_malloc.c:2430
#define PREACTION(M)
Definition: SDL_malloc.c:2206
#define memcpy
Definition: SDL_malloc.c:640
#define MAX_REQUEST
Definition: SDL_malloc.c:1724
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
#define internal_free(m, mem)
Definition: SDL_malloc.c:3229
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define overhead_for(p)
Definition: SDL_malloc.c:1788
#define internal_malloc(m, b)
Definition: SDL_malloc.c:3228
#define ok_address(M, a)
Definition: SDL_malloc.c:2428
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
#define is_mmapped(p)
Definition: SDL_malloc.c:1784
static void* mmap_alloc ( mstate  m,
size_t  nb 
)
static

Definition at line 3247 of file SDL_malloc.c.

References align_offset, assert, check_mmapped_chunk, chunk2mem, CHUNK_ALIGN_MASK, chunk_plus_offset, CINUSE_BIT, CMFAIL, DIRECT_MMAP, FENCEPOST_HEAD, granularity_align, is_aligned, IS_MMAPPED_BIT, mark_inuse_foot, MMAP_FOOT_PAD, sbinptr::prev_foot, SIX_SIZE_T_SIZES, and SIZE_T_SIZE.

Referenced by sys_alloc().

3248 {
3249  size_t mmsize =
3251  if (mmsize > nb) { /* Check for wrap around 0 */
3252  char *mm = (char *) (DIRECT_MMAP(mmsize));
3253  if (mm != CMFAIL) {
3254  size_t offset = align_offset(chunk2mem(mm));
3255  size_t psize = mmsize - offset - MMAP_FOOT_PAD;
3256  mchunkptr p = (mchunkptr) (mm + offset);
3257  p->prev_foot = offset | IS_MMAPPED_BIT;
3258  (p)->head = (psize | CINUSE_BIT);
3259  mark_inuse_foot(m, p, psize);
3260  chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;
3261  chunk_plus_offset(p, psize + SIZE_T_SIZE)->head = 0;
3262 
3263  if (mm < m->least_addr)
3264  m->least_addr = mm;
3265  if ((m->footprint += mmsize) > m->max_footprint)
3266  m->max_footprint = m->footprint;
3268  check_mmapped_chunk(m, p);
3269  return chunk2mem(p);
3270  }
3271  }
3272  return 0;
3273 }
#define DIRECT_MMAP(s)
Definition: SDL_malloc.c:1431
#define mark_inuse_foot(M, p, s)
Definition: SDL_malloc.c:2466
GLfloat GLfloat p
const GLfloat * m
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
#define IS_MMAPPED_BIT
Definition: SDL_malloc.c:1363
#define SIX_SIZE_T_SIZES
Definition: SDL_malloc.c:1328
GLintptr offset
#define assert(x)
Definition: SDL_malloc.c:1240
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define CMFAIL
Definition: SDL_malloc.c:1353
#define CHUNK_ALIGN_MASK
Definition: SDL_malloc.c:1332
#define is_aligned(A)
Definition: SDL_malloc.c:1335
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
#define check_mmapped_chunk(M, P)
Definition: SDL_malloc.c:2258
#define MMAP_FOOT_PAD
Definition: SDL_malloc.c:1711
SDL_EventEntry * head
Definition: SDL_events.c:81
#define align_offset(A)
Definition: SDL_malloc.c:1338
#define granularity_align(S)
Definition: SDL_malloc.c:2140
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
static mchunkptr mmap_resize ( mstate  m,
mchunkptr  oldp,
size_t  nb 
)
static

Definition at line 3277 of file SDL_malloc.c.

References CALL_MREMAP, check_mmapped_chunk, CHUNK_ALIGN_MASK, chunk_plus_offset, chunksize, CINUSE_BIT, CMFAIL, cp, FENCEPOST_HEAD, malloc_params::granularity, granularity_align, IS_MMAPPED_BIT, is_small, mark_inuse_foot, MMAP_FOOT_PAD, mparams, SIX_SIZE_T_SIZES, and SIZE_T_SIZE.

Referenced by internal_realloc().

3278 {
3279  size_t oldsize = chunksize(oldp);
3280  if (is_small(nb)) /* Can't shrink mmap regions below small size */
3281  return 0;
3282  /* Keep old chunk if big enough but not too big */
3283  if (oldsize >= nb + SIZE_T_SIZE &&
3284  (oldsize - nb) <= (mparams.granularity << 1))
3285  return oldp;
3286  else {
3287  size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT;
3288  size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD;
3289  size_t newmmsize = granularity_align(nb + SIX_SIZE_T_SIZES +
3291  char *cp = (char *) CALL_MREMAP((char *) oldp - offset,
3292  oldmmsize, newmmsize, 1);
3293  if (cp != CMFAIL) {
3294  mchunkptr newp = (mchunkptr) (cp + offset);
3295  size_t psize = newmmsize - offset - MMAP_FOOT_PAD;
3296  newp->head = (psize | CINUSE_BIT);
3297  mark_inuse_foot(m, newp, psize);
3298  chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;
3299  chunk_plus_offset(newp, psize + SIZE_T_SIZE)->head = 0;
3300 
3301  if (cp < m->least_addr)
3302  m->least_addr = cp;
3303  if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint)
3304  m->max_footprint = m->footprint;
3305  check_mmapped_chunk(m, newp);
3306  return newp;
3307  }
3308  }
3309  return 0;
3310 }
#define mark_inuse_foot(M, p, s)
Definition: SDL_malloc.c:2466
const GLfloat * m
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
#define IS_MMAPPED_BIT
Definition: SDL_malloc.c:1363
#define SIX_SIZE_T_SIZES
Definition: SDL_malloc.c:1328
GLintptr offset
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define CMFAIL
Definition: SDL_malloc.c:1353
#define CHUNK_ALIGN_MASK
Definition: SDL_malloc.c:1332
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
cp
Definition: e_pow.c:96
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
#define is_small(s)
Definition: SDL_malloc.c:2286
size_t granularity
Definition: SDL_malloc.c:2101
#define CALL_MREMAP(addr, osz, nsz, mv)
Definition: SDL_malloc.c:1438
#define check_mmapped_chunk(M, P)
Definition: SDL_malloc.c:2258
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define MMAP_FOOT_PAD
Definition: SDL_malloc.c:1711
#define granularity_align(S)
Definition: SDL_malloc.c:2140
static void* prepend_alloc ( mstate  m,
char *  newbase,
char *  oldbase,
size_t  nb 
)
static

Definition at line 3366 of file SDL_malloc.c.

References align_as_chunk, assert, check_free_chunk, check_malloced_chunk, check_top_chunk, chunk2mem, chunk_plus_offset, chunksize, cinuse, insert_chunk, MIN_CHUNK_SIZE, pinuse, PINUSE_BIT, set_free_with_pinuse, set_size_and_pinuse_of_free_chunk, set_size_and_pinuse_of_inuse_chunk, and unlink_chunk.

Referenced by sys_alloc().

3367 {
3368  mchunkptr p = align_as_chunk(newbase);
3369  mchunkptr oldfirst = align_as_chunk(oldbase);
3370  size_t psize = (char *) oldfirst - (char *) p;
3371  mchunkptr q = chunk_plus_offset(p, nb);
3372  size_t qsize = psize - nb;
3374 
3375  assert((char *) oldfirst > (char *) q);
3376  assert(pinuse(oldfirst));
3377  assert(qsize >= MIN_CHUNK_SIZE);
3378 
3379  /* consolidate remainder with first chunk of old base */
3380  if (oldfirst == m->top) {
3381  size_t tsize = m->topsize += qsize;
3382  m->top = q;
3383  q->head = tsize | PINUSE_BIT;
3384  check_top_chunk(m, q);
3385  } else if (oldfirst == m->dv) {
3386  size_t dsize = m->dvsize += qsize;
3387  m->dv = q;
3389  } else {
3390  if (!cinuse(oldfirst)) {
3391  size_t nsize = chunksize(oldfirst);
3392  unlink_chunk(m, oldfirst, nsize);
3393  oldfirst = chunk_plus_offset(oldfirst, nsize);
3394  qsize += nsize;
3395  }
3396  set_free_with_pinuse(q, qsize, oldfirst);
3397  insert_chunk(m, q, qsize);
3398  check_free_chunk(m, q);
3399  }
3400 
3401  check_malloced_chunk(m, chunk2mem(p), nb);
3402  return chunk2mem(p);
3403 }
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3207
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2087
#define cinuse(p)
Definition: SDL_malloc.c:1754
GLfloat GLfloat p
const GLfloat * m
#define set_free_with_pinuse(p, s, n)
Definition: SDL_malloc.c:1781
#define assert(x)
Definition: SDL_malloc.c:1240
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
#define align_as_chunk(A)
Definition: SDL_malloc.c:1721
#define unlink_chunk(M, P, S)
Definition: SDL_malloc.c:3211
#define check_malloced_chunk(M, P, N)
Definition: SDL_malloc.c:2257
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
#define pinuse(p)
Definition: SDL_malloc.c:1755
#define check_free_chunk(M, P)
Definition: SDL_malloc.c:2255
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
static size_t release_unused_segments ( mstate  m)
static

Definition at line 3665 of file SDL_malloc.c.

References align_as_chunk, assert, msegmentptr::base, CALL_MUNMAP, chunksize, cinuse, insert_large_chunk, is_extern_segment, is_mmapped_segment, msegmentptr::next, segment_holds, TOP_FOOT_SIZE, and unlink_large_chunk.

Referenced by sys_trim().

3666 {
3667  size_t released = 0;
3668  msegmentptr pred = &m->seg;
3669  msegmentptr sp = pred->next;
3670  while (sp != 0) {
3671  char *base = sp->base;
3672  size_t size = sp->size;
3673  msegmentptr next = sp->next;
3674  if (is_mmapped_segment(sp) && !is_extern_segment(sp)) {
3675  mchunkptr p = align_as_chunk(base);
3676  size_t psize = chunksize(p);
3677  /* Can unmap if first chunk holds entire segment and not pinned */
3678  if (!cinuse(p)
3679  && (char *) p + psize >= base + size - TOP_FOOT_SIZE) {
3680  tchunkptr tp = (tchunkptr) p;
3681  assert(segment_holds(sp, (char *) sp));
3682  if (p == m->dv) {
3683  m->dv = 0;
3684  m->dvsize = 0;
3685  } else {
3686  unlink_large_chunk(m, tp);
3687  }
3688  if (CALL_MUNMAP(base, size) == 0) {
3689  released += size;
3690  m->footprint -= size;
3691  /* unlink obsoleted record */
3692  sp = pred;
3693  sp->next = next;
3694  } else { /* back out if cannot unmap */
3695  insert_large_chunk(m, tp, psize);
3696  }
3697  }
3698  }
3699  pred = sp;
3700  sp = next;
3701  }
3702  return released;
3703 }
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3134
#define cinuse(p)
Definition: SDL_malloc.c:1754
GLfloat GLfloat p
const GLfloat * m
#define assert(x)
Definition: SDL_malloc.c:1240
#define CALL_MUNMAP(a, s)
Definition: SDL_malloc.c:1430
#define align_as_chunk(A)
Definition: SDL_malloc.c:1721
GLsizeiptr size
#define insert_large_chunk(M, X, S)
Definition: SDL_malloc.c:3066
#define segment_holds(S, A)
Definition: SDL_malloc.c:2149
#define chunksize(p)
Definition: SDL_malloc.c:1756
#define is_mmapped_segment(S)
Definition: SDL_malloc.c:1974
#define is_extern_segment(S)
Definition: SDL_malloc.c:1975
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
static msegmentptr segment_holding ( mstate  m,
char *  addr 
)
static

Definition at line 2154 of file SDL_malloc.c.

Referenced by add_segment(), sys_alloc(), and sys_trim().

2155 {
2156  msegmentptr sp = &m->seg;
2157  for (;;) {
2158  if (addr >= sp->base && addr < sp->base + sp->size)
2159  return sp;
2160  if ((sp = sp->next) == 0)
2161  return 0;
2162  }
2163 }
const GLfloat * m
GLenum const void * addr
static void* sys_alloc ( mstate  m,
size_t  nb 
)
static

Definition at line 3465 of file SDL_malloc.c.

References ACQUIRE_MORECORE_LOCK, add_segment(), CALL_MMAP, CALL_MORECORE, check_malloced_chunk, check_top_chunk, chunk2mem, chunk_plus_offset, CMFAIL, disable_contiguous, granularity_align, HALF_MAX_SIZE_T, HAVE_MMAP, HAVE_MORECORE, init_bins(), init_mparams(), init_top(), is_extern_segment, is_global, is_initialized, IS_MMAPPED_BIT, is_page_aligned, malloc_params::magic, MALLOC_ALIGNMENT, MALLOC_FAILURE_ACTION, mem2chunk, mmap_alloc(), malloc_params::mmap_threshold, MORECORE_CONTIGUOUS, mparams, msegmentptr::next, next_chunk, page_align, PINUSE_BIT, prepend_alloc(), RELEASE_MORECORE_LOCK, segment_holding(), segment_holds, set_size_and_pinuse_of_inuse_chunk, msegmentptr::size, SIZE_T_ONE, TOP_FOOT_SIZE, use_mmap, and use_noncontiguous.

Referenced by dlmalloc().

3466 {
3467  char *tbase = CMFAIL;
3468  size_t tsize = 0;
3469  flag_t mmap_flag = 0;
3470 
3471  init_mparams();
3472 
3473  /* Directly map large chunks */
3474  if (use_mmap(m) && nb >= mparams.mmap_threshold) {
3475  void *mem = mmap_alloc(m, nb);
3476  if (mem != 0)
3477  return mem;
3478  }
3479 
3480  /*
3481  Try getting memory in any of three ways (in most-preferred to
3482  least-preferred order):
3483  1. A call to MORECORE that can normally contiguously extend memory.
3484  (disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or
3485  or main space is mmapped or a previous contiguous call failed)
3486  2. A call to MMAP new space (disabled if not HAVE_MMAP).
3487  Note that under the default settings, if MORECORE is unable to
3488  fulfill a request, and HAVE_MMAP is true, then mmap is
3489  used as a noncontiguous system allocator. This is a useful backup
3490  strategy for systems with holes in address spaces -- in this case
3491  sbrk cannot contiguously expand the heap, but mmap may be able to
3492  find space.
3493  3. A call to MORECORE that cannot usually contiguously extend memory.
3494  (disabled if not HAVE_MORECORE)
3495  */
3496 
3498  char *br = CMFAIL;
3499  msegmentptr ss =
3500  (m->top == 0) ? 0 : segment_holding(m, (char *) m->top);
3501  size_t asize = 0;
3503 
3504  if (ss == 0) { /* First time through or recovery */
3505  char *base = (char *) CALL_MORECORE(0);
3506  if (base != CMFAIL) {
3507  asize =
3509  SIZE_T_ONE);
3510  /* Adjust to end on a page boundary */
3511  if (!is_page_aligned(base))
3512  asize += (page_align((size_t) base) - (size_t) base);
3513  /* Can't call MORECORE if size is negative when treated as signed */
3514  if (asize < HALF_MAX_SIZE_T &&
3515  (br = (char *) (CALL_MORECORE(asize))) == base) {
3516  tbase = base;
3517  tsize = asize;
3518  }
3519  }
3520  } else {
3521  /* Subtract out existing available top space from MORECORE request. */
3522  asize =
3523  granularity_align(nb - m->topsize + TOP_FOOT_SIZE +
3525  /* Use mem here only if it did continuously extend old space */
3526  if (asize < HALF_MAX_SIZE_T &&
3527  (br =
3528  (char *) (CALL_MORECORE(asize))) == ss->base + ss->size) {
3529  tbase = br;
3530  tsize = asize;
3531  }
3532  }
3533 
3534  if (tbase == CMFAIL) { /* Cope with partial failure */
3535  if (br != CMFAIL) { /* Try to use/extend the space we did get */
3536  if (asize < HALF_MAX_SIZE_T &&
3537  asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) {
3538  size_t esize =
3541  asize);
3542  if (esize < HALF_MAX_SIZE_T) {
3543  char *end = (char *) CALL_MORECORE(esize);
3544  if (end != CMFAIL)
3545  asize += esize;
3546  else { /* Can't use; try to release */
3547  end = (char *) CALL_MORECORE(-asize);
3548  br = CMFAIL;
3549  }
3550  }
3551  }
3552  }
3553  if (br != CMFAIL) { /* Use the space we did get */
3554  tbase = br;
3555  tsize = asize;
3556  } else
3557  disable_contiguous(m); /* Don't try contiguous path in the future */
3558  }
3559 
3561  }
3562 
3563  if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */
3564  size_t req = nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE;
3565  size_t rsize = granularity_align(req);
3566  if (rsize > nb) { /* Fail if wraps around zero */
3567  char *mp = (char *) (CALL_MMAP(rsize));
3568  if (mp != CMFAIL) {
3569  tbase = mp;
3570  tsize = rsize;
3571  mmap_flag = IS_MMAPPED_BIT;
3572  }
3573  }
3574  }
3575 
3576  if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */
3577  size_t asize =
3579  SIZE_T_ONE);
3580  if (asize < HALF_MAX_SIZE_T) {
3581  char *br = CMFAIL;
3582  char *end = CMFAIL;
3584  br = (char *) (CALL_MORECORE(asize));
3585  end = (char *) (CALL_MORECORE(0));
3587  if (br != CMFAIL && end != CMFAIL && br < end) {
3588  size_t ssize = end - br;
3589  if (ssize > nb + TOP_FOOT_SIZE) {
3590  tbase = br;
3591  tsize = ssize;
3592  }
3593  }
3594  }
3595  }
3596 
3597  if (tbase != CMFAIL) {
3598 
3599  if ((m->footprint += tsize) > m->max_footprint)
3600  m->max_footprint = m->footprint;
3601 
3602  if (!is_initialized(m)) { /* first-time initialization */
3603  m->seg.base = m->least_addr = tbase;
3604  m->seg.size = tsize;
3605  m->seg.sflags = mmap_flag;
3606  m->magic = mparams.magic;
3607  init_bins(m);
3608  if (is_global(m))
3609  init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
3610  else {
3611  /* Offset top by embedded malloc_state */
3612  mchunkptr mn = next_chunk(mem2chunk(m));
3613  init_top(m, mn,
3614  (size_t) ((tbase + tsize) - (char *) mn) -
3615  TOP_FOOT_SIZE);
3616  }
3617  }
3618 
3619  else {
3620  /* Try to merge with an existing segment */
3621  msegmentptr sp = &m->seg;
3622  while (sp != 0 && tbase != sp->base + sp->size)
3623  sp = sp->next;
3624  if (sp != 0 && !is_extern_segment(sp) && (sp->sflags & IS_MMAPPED_BIT) == mmap_flag && segment_holds(sp, m->top)) { /* append */
3625  sp->size += tsize;
3626  init_top(m, m->top, m->topsize + tsize);
3627  } else {
3628  if (tbase < m->least_addr)
3629  m->least_addr = tbase;
3630  sp = &m->seg;
3631  while (sp != 0 && sp->base != tbase + tsize)
3632  sp = sp->next;
3633  if (sp != 0 &&
3634  !is_extern_segment(sp) &&
3635  (sp->sflags & IS_MMAPPED_BIT) == mmap_flag) {
3636  char *oldbase = sp->base;
3637  sp->base = tbase;
3638  sp->size += tsize;
3639  return prepend_alloc(m, tbase, oldbase, nb);
3640  } else
3641  add_segment(m, tbase, tsize, mmap_flag);
3642  }
3643  }
3644 
3645  if (nb < m->topsize) { /* Allocate from new or extended top space */
3646  size_t rsize = m->topsize -= nb;
3647  mchunkptr p = m->top;
3648  mchunkptr r = m->top = chunk_plus_offset(p, nb);
3649  r->head = rsize | PINUSE_BIT;
3651  check_top_chunk(m, m->top);
3652  check_malloced_chunk(m, chunk2mem(p), nb);
3653  return chunk2mem(p);
3654  }
3655  }
3656 
3658  return 0;
3659 }
#define next_chunk(p)
Definition: SDL_malloc.c:1766
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
#define HAVE_MMAP
Definition: SDL_malloc.c:512
unsigned int flag_t
Definition: SDL_malloc.c:1696
#define MALLOC_FAILURE_ACTION
Definition: SDL_malloc.c:522
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLfloat GLfloat p
#define disable_contiguous(M)
Definition: SDL_malloc.c:2128
const GLfloat * m
#define is_initialized(M)
Definition: SDL_malloc.c:2113
#define IS_MMAPPED_BIT
Definition: SDL_malloc.c:1363
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define CMFAIL
Definition: SDL_malloc.c:1353
#define ACQUIRE_MORECORE_LOCK()
Definition: SDL_malloc.c:1533
#define CALL_MORECORE(S)
Definition: SDL_malloc.c:1444
unsigned int size_t
#define use_noncontiguous(M)
Definition: SDL_malloc.c:2127
static void init_bins(mstate m)
Definition: SDL_malloc.c:3333
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
#define MORECORE_CONTIGUOUS
Definition: SDL_malloc.c:596
#define MALLOC_ALIGNMENT
Definition: SDL_malloc.c:552
#define is_global(M)
Definition: SDL_malloc.c:2112
#define page_align(S)
Definition: SDL_malloc.c:2136
#define CALL_MMAP(s)
Definition: SDL_malloc.c:1429
static void init_top(mstate m, mchunkptr p, size_t psize)
Definition: SDL_malloc.c:3316
#define HALF_MAX_SIZE_T
Definition: SDL_malloc.c:1329
#define HAVE_MORECORE
Definition: SDL_malloc.c:513
#define check_malloced_chunk(M, P, N)
Definition: SDL_malloc.c:2257
static void * prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb)
Definition: SDL_malloc.c:3366
#define segment_holds(S, A)
Definition: SDL_malloc.c:2149
static int init_mparams(void)
Definition: SDL_malloc.c:2512
static void add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped)
Definition: SDL_malloc.c:3408
#define RELEASE_MORECORE_LOCK()
Definition: SDL_malloc.c:1534
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
#define use_mmap(M)
Definition: SDL_malloc.c:2123
static msegmentptr segment_holding(mstate m, char *addr)
Definition: SDL_malloc.c:2154
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
#define is_extern_segment(S)
Definition: SDL_malloc.c:1975
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
#define granularity_align(S)
Definition: SDL_malloc.c:2140
static void * mmap_alloc(mstate m, size_t nb)
Definition: SDL_malloc.c:3247
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
#define is_page_aligned(S)
Definition: SDL_malloc.c:2143
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
size_t mmap_threshold
Definition: SDL_malloc.c:2102
static int sys_trim ( mstate  m,
size_t  pad 
)
static

Definition at line 3706 of file SDL_malloc.c.

References ACQUIRE_MORECORE_LOCK, CALL_MORECORE, CALL_MREMAP, CALL_MUNMAP, check_top_chunk, CMFAIL, malloc_params::granularity, HALF_MAX_SIZE_T, has_segment_link(), HAVE_MMAP, HAVE_MORECORE, init_top(), is_extern_segment, is_initialized, is_mmapped_segment, MAX_REQUEST, MAX_SIZE_T, MFAIL, mparams, RELEASE_MORECORE_LOCK, release_unused_segments(), segment_holding(), SIZE_T_ONE, and TOP_FOOT_SIZE.

Referenced by dlfree(), and dlmalloc_trim().

3707 {
3708  size_t released = 0;
3709  if (pad < MAX_REQUEST && is_initialized(m)) {
3710  pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */
3711 
3712  if (m->topsize > pad) {
3713  /* Shrink top space in granularity-size units, keeping at least one */
3714  size_t unit = mparams.granularity;
3715  size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit -
3716  SIZE_T_ONE) * unit;
3717  msegmentptr sp = segment_holding(m, (char *) m->top);
3718 
3719  if (!is_extern_segment(sp)) {
3720  if (is_mmapped_segment(sp)) {
3721  if (HAVE_MMAP && sp->size >= extra && !has_segment_link(m, sp)) { /* can't shrink if pinned */
3722  size_t newsize = sp->size - extra;
3723  /* Prefer mremap, fall back to munmap */
3724  if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) !=
3725  MFAIL)
3726  || (CALL_MUNMAP(sp->base + newsize, extra) == 0)) {
3727  released = extra;
3728  }
3729  }
3730  } else if (HAVE_MORECORE) {
3731  if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */
3732  extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit;
3734  {
3735  /* Make sure end of memory is where we last set it. */
3736  char *old_br = (char *) (CALL_MORECORE(0));
3737  if (old_br == sp->base + sp->size) {
3738  char *rel_br = (char *) (CALL_MORECORE(-extra));
3739  char *new_br = (char *) (CALL_MORECORE(0));
3740  if (rel_br != CMFAIL && new_br < old_br)
3741  released = old_br - new_br;
3742  }
3743  }
3745  }
3746  }
3747 
3748  if (released != 0) {
3749  sp->size -= released;
3750  m->footprint -= released;
3751  init_top(m, m->top, m->topsize - released);
3752  check_top_chunk(m, m->top);
3753  }
3754  }
3755 
3756  /* Unmap any unused mmapped segments */
3757  if (HAVE_MMAP)
3758  released += release_unused_segments(m);
3759 
3760  /* On failure, disable autotrim to avoid repeated failed future calls */
3761  if (released == 0)
3762  m->trim_check = MAX_SIZE_T;
3763  }
3764 
3765  return (released != 0) ? 1 : 0;
3766 }
#define HAVE_MMAP
Definition: SDL_malloc.c:512
static int has_segment_link(mstate m, msegmentptr ss)
Definition: SDL_malloc.c:2167
const GLfloat * m
#define is_initialized(M)
Definition: SDL_malloc.c:2113
#define CALL_MUNMAP(a, s)
Definition: SDL_malloc.c:1430
#define CMFAIL
Definition: SDL_malloc.c:1353
#define ACQUIRE_MORECORE_LOCK()
Definition: SDL_malloc.c:1533
#define CALL_MORECORE(S)
Definition: SDL_malloc.c:1444
#define MFAIL
Definition: SDL_malloc.c:1352
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
#define MAX_SIZE_T
Definition: SDL_malloc.c:539
static void init_top(mstate m, mchunkptr p, size_t psize)
Definition: SDL_malloc.c:3316
#define HALF_MAX_SIZE_T
Definition: SDL_malloc.c:1329
#define HAVE_MORECORE
Definition: SDL_malloc.c:513
size_t granularity
Definition: SDL_malloc.c:2101
static size_t release_unused_segments(mstate m)
Definition: SDL_malloc.c:3665
#define RELEASE_MORECORE_LOCK()
Definition: SDL_malloc.c:1534
#define MAX_REQUEST
Definition: SDL_malloc.c:1724
#define CALL_MREMAP(addr, osz, nsz, mv)
Definition: SDL_malloc.c:1438
static msegmentptr segment_holding(mstate m, char *addr)
Definition: SDL_malloc.c:2154
#define is_mmapped_segment(S)
Definition: SDL_malloc.c:1974
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
#define is_extern_segment(S)
Definition: SDL_malloc.c:1975
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260
static void* tmalloc_large ( mstate  m,
size_t  nb 
)
static

Definition at line 3772 of file SDL_malloc.c.

References assert, chunk2mem, chunk_plus_offset, chunksize, compute_bit2idx, compute_tree_index, CORRUPTION_ERROR_ACTION, i, idx2bit, insert_chunk, least_bit, left_bits, leftmost_child, leftshift_for_tree_index, MIN_CHUNK_SIZE, ok_address, ok_next, RTCHECK, set_inuse_and_pinuse, set_size_and_pinuse_of_free_chunk, set_size_and_pinuse_of_inuse_chunk, SIZE_T_BITSIZE, SIZE_T_ONE, treebin_at, and unlink_large_chunk.

Referenced by dlmalloc().

3773 {
3774  tchunkptr v = 0;
3775  size_t rsize = -nb; /* Unsigned negation */
3776  tchunkptr t;
3777  bindex_t idx;
3778  compute_tree_index(nb, idx);
3779 
3780  if ((t = *treebin_at(m, idx)) != 0) {
3781  /* Traverse tree for this bin looking for node with size == nb */
3782  size_t sizebits = nb << leftshift_for_tree_index(idx);
3783  tchunkptr rst = 0; /* The deepest untaken right subtree */
3784  for (;;) {
3785  tchunkptr rt;
3786  size_t trem = chunksize(t) - nb;
3787  if (trem < rsize) {
3788  v = t;
3789  if ((rsize = trem) == 0)
3790  break;
3791  }
3792  rt = t->child[1];
3793  t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1];
3794  if (rt != 0 && rt != t)
3795  rst = rt;
3796  if (t == 0) {
3797  t = rst; /* set t to least subtree holding sizes > nb */
3798  break;
3799  }
3800  sizebits <<= 1;
3801  }
3802  }
3803 
3804  if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */
3805  binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap;
3806  if (leftbits != 0) {
3807  bindex_t i;
3808  binmap_t leastbit = least_bit(leftbits);
3809  compute_bit2idx(leastbit, i);
3810  t = *treebin_at(m, i);
3811  }
3812  }
3813 
3814  while (t != 0) { /* find smallest of tree or subtree */
3815  size_t trem = chunksize(t) - nb;
3816  if (trem < rsize) {
3817  rsize = trem;
3818  v = t;
3819  }
3820  t = leftmost_child(t);
3821  }
3822 
3823  /* If dv is a better fit, return 0 so malloc will use it */
3824  if (v != 0 && rsize < (size_t) (m->dvsize - nb)) {
3825  if (RTCHECK(ok_address(m, v))) { /* split */
3826  mchunkptr r = chunk_plus_offset(v, nb);
3827  assert(chunksize(v) == rsize + nb);
3828  if (RTCHECK(ok_next(v, r))) {
3829  unlink_large_chunk(m, v);
3830  if (rsize < MIN_CHUNK_SIZE)
3831  set_inuse_and_pinuse(m, v, (rsize + nb));
3832  else {
3835  insert_chunk(m, r, rsize);
3836  }
3837  return chunk2mem(v);
3838  }
3839  }
3841  }
3842  return 0;
3843 }
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3134
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
size_t bindex_t
Definition: SDL_malloc.c:1694
#define compute_tree_index(S, I)
Definition: SDL_malloc.c:2311
const GLdouble * v
Definition: SDL_opengl.h:2064
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3207
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
const GLfloat * m
#define compute_bit2idx(X, I)
Definition: SDL_malloc.c:2374
#define assert(x)
Definition: SDL_malloc.c:1240
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define leftmost_child(t)
Definition: SDL_malloc.c:1907
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2242
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
#define idx2bit(i)
Definition: SDL_malloc.c:2348
#define ok_next(p, n)
Definition: SDL_malloc.c:2430
#define leftshift_for_tree_index(i)
Definition: SDL_malloc.c:2335
#define SIZE_T_BITSIZE
Definition: SDL_malloc.c:1319
#define treebin_at(M, i)
Definition: SDL_malloc.c:2293
#define left_bits(x)
Definition: SDL_malloc.c:2392
#define chunksize(p)
Definition: SDL_malloc.c:1756
unsigned int binmap_t
Definition: SDL_malloc.c:1695
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
#define ok_address(M, a)
Definition: SDL_malloc.c:2428
#define least_bit(x)
Definition: SDL_malloc.c:2389
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
#define set_inuse_and_pinuse(M, p, s)
Definition: SDL_malloc.c:2474
static void* tmalloc_small ( mstate  m,
size_t  nb 
)
static

Definition at line 3847 of file SDL_malloc.c.

References assert, chunk2mem, chunk_plus_offset, chunksize, compute_bit2idx, CORRUPTION_ERROR_ACTION, i, least_bit, leftmost_child, MIN_CHUNK_SIZE, ok_address, ok_next, replace_dv, RTCHECK, set_inuse_and_pinuse, set_size_and_pinuse_of_free_chunk, set_size_and_pinuse_of_inuse_chunk, treebin_at, and unlink_large_chunk.

Referenced by dlmalloc().

3848 {
3849  tchunkptr t, v;
3850  size_t rsize;
3851  bindex_t i;
3852  binmap_t leastbit = least_bit(m->treemap);
3853  compute_bit2idx(leastbit, i);
3854 
3855  v = t = *treebin_at(m, i);
3856  rsize = chunksize(t) - nb;
3857 
3858  while ((t = leftmost_child(t)) != 0) {
3859  size_t trem = chunksize(t) - nb;
3860  if (trem < rsize) {
3861  rsize = trem;
3862  v = t;
3863  }
3864  }
3865 
3866  if (RTCHECK(ok_address(m, v))) {
3867  mchunkptr r = chunk_plus_offset(v, nb);
3868  assert(chunksize(v) == rsize + nb);
3869  if (RTCHECK(ok_next(v, r))) {
3870  unlink_large_chunk(m, v);
3871  if (rsize < MIN_CHUNK_SIZE)
3872  set_inuse_and_pinuse(m, v, (rsize + nb));
3873  else {
3876  replace_dv(m, r, rsize);
3877  }
3878  return chunk2mem(v);
3879  }
3880  }
3881 
3883  return 0;
3884 }
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3134
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
size_t bindex_t
Definition: SDL_malloc.c:1694
const GLdouble * v
Definition: SDL_opengl.h:2064
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
#define replace_dv(M, P, S)
Definition: SDL_malloc.c:3052
const GLfloat * m
#define compute_bit2idx(X, I)
Definition: SDL_malloc.c:2374
#define assert(x)
Definition: SDL_malloc.c:1240
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
#define leftmost_child(t)
Definition: SDL_malloc.c:1907
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2242
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
#define ok_next(p, n)
Definition: SDL_malloc.c:2430
#define treebin_at(M, i)
Definition: SDL_malloc.c:2293
#define chunksize(p)
Definition: SDL_malloc.c:1756
unsigned int binmap_t
Definition: SDL_malloc.c:1695
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
#define ok_address(M, a)
Definition: SDL_malloc.c:2428
#define least_bit(x)
Definition: SDL_malloc.c:2389
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
#define set_inuse_and_pinuse(M, p, s)
Definition: SDL_malloc.c:2474
static int win32_acquire_lock ( MLOCK_T sl)
static

Definition at line 1494 of file SDL_malloc.c.

1495 {
1496  for (;;) {
1497 #ifdef InterlockedCompareExchangePointer
1498  if (!InterlockedCompareExchange(sl, 1, 0))
1499  return 0;
1500 #else /* Use older void* version */
1501  if (!InterlockedCompareExchange((void **) sl, (void *) 1, (void *) 0))
1502  return 0;
1503 #endif /* InterlockedCompareExchangePointer */
1504  Sleep(0);
1505  }
1506 }
static void win32_release_lock ( MLOCK_T sl)
static

Definition at line 1509 of file SDL_malloc.c.

1510 {
1511  InterlockedExchange(sl, 0);
1512 }
static void* win32direct_mmap ( size_t  size)
static

Definition at line 1402 of file SDL_malloc.c.

References MFAIL.

1403 {
1404  void *ptr = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN,
1405  PAGE_READWRITE);
1406  return (ptr != 0) ? ptr : MFAIL;
1407 }
#define MFAIL
Definition: SDL_malloc.c:1352
GLsizeiptr size
static void* win32mmap ( size_t  size)
static

Definition at line 1393 of file SDL_malloc.c.

References MFAIL.

1394 {
1395  void *ptr =
1396  VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
1397  return (ptr != 0) ? ptr : MFAIL;
1398 }
#define MFAIL
Definition: SDL_malloc.c:1352
GLsizeiptr size
static int win32munmap ( void ptr,
size_t  size 
)
static

Definition at line 1411 of file SDL_malloc.c.

1412 {
1413  MEMORY_BASIC_INFORMATION minfo;
1414  char *cptr = ptr;
1415  while (size) {
1416  if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)
1417  return -1;
1418  if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||
1419  minfo.State != MEM_COMMIT || minfo.RegionSize > size)
1420  return -1;
1421  if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)
1422  return -1;
1423  cptr += minfo.RegionSize;
1424  size -= minfo.RegionSize;
1425  }
1426  return 0;
1427 }
GLsizeiptr size

Variable Documentation

struct malloc_state _gm_
static

Definition at line 2110 of file SDL_malloc.c.

MLOCK_T magic_init_mutex
static

Definition at line 1520 of file SDL_malloc.c.

struct malloc_params mparams
static