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 dlmallopt(), and 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(), dlmallopt(), 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(), and dlmallopt().

#define check_free_chunk (   M,
 
)

Definition at line 2255 of file SDL_malloc.c.

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

#define check_inuse_chunk (   M,
 
)

Definition at line 2256 of file SDL_malloc.c.

Referenced by dlfree(), dlmallopt(), 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(), dlmallopt(), 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(), dlmallopt(), 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(), change_mparam(), 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(), and dlmallopt().

#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_BIT   (SIZE_T_TWO)

Definition at line 1747 of file SDL_malloc.c.

Referenced by change_mparam(), dlmallopt(), 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 dlmallopt(), 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(), dlmallopt(), 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 change_mparam(), and 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 dlmallopt(), and 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.

Referenced by dlmallopt().

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

Referenced by dlfree(), and dlmallopt().

#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 dlmallopt(), 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(), dlmallopt(), and tmalloc_large().

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

Definition at line 1514 of file SDL_malloc.c.

Referenced by dlmallopt(), and 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:2991
#define is_small(s)
Definition: SDL_malloc.c:2286
#define insert_large_chunk(M, X, S)
Definition: SDL_malloc.c:3062

Definition at line 3203 of file SDL_malloc.c.

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

#define insert_large_chunk (   M,
  X,
 
)

Definition at line 3062 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 2991 of file SDL_malloc.c.

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

Definition at line 3225 of file SDL_malloc.c.

Referenced by internal_memalign(), and internal_realloc().

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

Definition at line 3224 of file SDL_malloc.c.

Referenced by dlmallopt(), 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(), and dlmallopt().

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

Definition at line 1335 of file SDL_malloc.c.

Referenced by add_segment(), change_mparam(), 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)
#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 change_mparam(), ialloc(), internal_memalign(), and internal_realloc().

#define IS_MMAPPED_BIT   (SIZE_T_ONE)

Definition at line 1363 of file SDL_malloc.c.

Referenced by change_mparam(), dlfree(), dlmallopt(), 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 change_mparam(), and 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(), dlmallopt(), 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(), dlmallopt(), 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
#define NTREEBINS
Definition: SDL_malloc.c:2057
#define SIZE_T_BITSIZE
Definition: SDL_malloc.c:1319
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:42
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324

Definition at line 2335 of file SDL_malloc.c.

Referenced by change_mparam(), and 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(), 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(), dlmallopt(), 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(), dlmallopt(), 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(), and dlmallopt().

#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(), SDL_memcpy(), and SDL_tolower().

#define memset   SDL_memset

Definition at line 639 of file SDL_malloc.c.

Referenced by dlcalloc(), dlmallopt(), 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.

Referenced by change_mparam().

#define MIN_REQUEST   (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)

Definition at line 1725 of file SDL_malloc.c.

Referenced by dlmalloc(), and dlmallopt().

#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:42
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324

Definition at line 2340 of file SDL_malloc.c.

Referenced by change_mparam().

#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 change_mparam(), dlfree(), dlmallopt(), 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)))
#define next_pinuse (   p)    ((next_chunk(p)->head) & PINUSE_BIT)

Definition at line 1770 of file SDL_malloc.c.

Referenced by change_mparam().

#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 change_mparam(), and init_bins().

#define NTREEBINS   (32U)

Definition at line 2057 of file SDL_malloc.c.

Referenced by change_mparam(), and init_bins().

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

Definition at line 2432 of file SDL_malloc.c.

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

#define ok_magic (   M)    (1)

Definition at line 2447 of file SDL_malloc.c.

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

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

Definition at line 2430 of file SDL_malloc.c.

Referenced by dlfree(), dlmallopt(), 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(), dlmallopt(), 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(), dlmalloc(), and dlmallopt().

#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 change_mparam(), dlfree(), dlmallopt(), and prepend_alloc().

#define PINUSE_BIT   (SIZE_T_ONE)
#define POSTACTION (   M)    { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); }
#define prev_chunk (   p)    ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) ))

Definition at line 1767 of file SDL_malloc.c.

Referenced by change_mparam().

#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:2991
#define is_small(s)
Definition: SDL_malloc.c:2286

Definition at line 3048 of file SDL_malloc.c.

Referenced by dlmalloc(), dlmallopt(), 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(), dlmallopt(), 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(), dlmallopt(), 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:2056
GLfloat GLfloat p
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
SDL_EventEntry * head
Definition: SDL_events.c:79
#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:2056
GLfloat GLfloat p
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
SDL_EventEntry * head
Definition: SDL_events.c:79
#define PINUSE_BIT
Definition: SDL_malloc.c:1746

Definition at line 2474 of file SDL_malloc.c.

Referenced by dlmalloc(), dlmallopt(), 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.

Referenced by dlmallopt().

#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(), dlmallopt(), 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(), and dlmallopt().

#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 change_mparam(), and tmalloc_large().

#define SIZE_T_ONE   ((size_t)1)
#define SIZE_T_SIZE   (sizeof(size_t))
#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 change_mparam(), dlmalloc(), and dlmallopt().

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

Definition at line 2288 of file SDL_malloc.c.

Referenced by dlmalloc(), and dlmallopt().

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

Definition at line 2292 of file SDL_malloc.c.

Referenced by change_mparam(), dlmalloc(), dlmallopt(), 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.

Referenced by change_mparam().

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

Definition at line 2293 of file SDL_malloc.c.

Referenced by change_mparam(), init_bins(), 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.

Referenced by change_mparam().

#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:3130
#define unlink_small_chunk(M, P, S)
Definition: SDL_malloc.c:3010
#define is_small(s)
Definition: SDL_malloc.c:2286

Definition at line 3207 of file SDL_malloc.c.

Referenced by dlfree(), dlmallopt(), 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 3030 of file SDL_malloc.c.

Referenced by dlmalloc(), and dlmallopt().

#define unlink_large_chunk (   M,
 
)

Definition at line 3130 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 3010 of file SDL_malloc.c.

#define USAGE_ERROR_ACTION (   m,
  p 
)    ABORT

Definition at line 2246 of file SDL_malloc.c.

Referenced by dlfree(), dlmallopt(), 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 change_mparam(), 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 3404 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().

3405 {
3406  /* Determine locations and sizes of segment, fenceposts, old top */
3407  char *old_top = (char *) m->top;
3408  msegmentptr oldsp = segment_holding(m, old_top);
3409  char *old_end = oldsp->base + oldsp->size;
3410  size_t ssize = pad_request(sizeof(struct malloc_segment));
3411  char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
3412  size_t offset = align_offset(chunk2mem(rawsp));
3413  char *asp = rawsp + offset;
3414  char *csp = (asp < (old_top + MIN_CHUNK_SIZE)) ? old_top : asp;
3415  mchunkptr sp = (mchunkptr) csp;
3416  msegmentptr ss = (msegmentptr) (chunk2mem(sp));
3417  mchunkptr tnext = chunk_plus_offset(sp, ssize);
3418  mchunkptr p = tnext;
3419  int nfences = 0;
3420 
3421  /* reset top to new space */
3422  init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
3423 
3424  /* Set up segment record */
3425  assert(is_aligned(ss));
3427  *ss = m->seg; /* Push current record */
3428  m->seg.base = tbase;
3429  m->seg.size = tsize;
3430  m->seg.sflags = mmapped;
3431  m->seg.next = ss;
3432 
3433  /* Insert trailing fenceposts */
3434  for (;;) {
3435  mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);
3436  p->head = FENCEPOST_HEAD;
3437  ++nfences;
3438  if ((char *) (&(nextp->head)) < old_end)
3439  p = nextp;
3440  else
3441  break;
3442  }
3443  assert(nfences >= 2);
3444 
3445  /* Insert the rest of old top into a bin as an ordinary free chunk */
3446  if (csp != old_top) {
3447  mchunkptr q = (mchunkptr) old_top;
3448  size_t psize = csp - old_top;
3449  mchunkptr tn = chunk_plus_offset(q, psize);
3450  set_free_with_pinuse(q, psize, tn);
3451  insert_chunk(m, q, psize);
3452  }
3453 
3454  check_top_chunk(m, m->top);
3455 }
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3203
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2080
const GLfloat * m
GLfloat GLfloat p
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
#define set_free_with_pinuse(p, s, n)
Definition: SDL_malloc.c:1781
#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:3312
GLintptr offset
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 align_as_chunk, assert, sbinptr::bk, chunk2mem, CHUNK_ALIGN_MASK, chunk_plus_offset, chunksize, cinuse, CINUSE_BIT, compute_tree_index, FENCEPOST_HEAD, mstate::footprint, malloc_params::granularity, head, i, init_mparams(), is_aligned, is_initialized, is_mmapped, IS_MMAPPED_BIT, is_small, leftshift_for_tree_index, M_GRANULARITY, M_MMAP_THRESHOLD, M_TRIM_THRESHOLD, mem2chunk, MIN_CHUNK_SIZE, MIN_LARGE_SIZE, minsize_for_tree_index, MMAP_FOOT_PAD, malloc_params::mmap_threshold, mparams, next_chunk, next_pinuse, NSMALLBINS, NTREEBINS, ok_address, malloc_params::page_size, pinuse, PINUSE_BIT, prev_chunk, segment_holding(), segment_holds, SIZE_T_BITSIZE, SIZE_T_ONE, SIZE_T_SIZE, small_index, smallbin_at, smallmap_is_marked, TOP_FOOT_SIZE, treebin_at, treemap_is_marked, malloc_params::trim_threshold, and use_mmap.

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
GLsizei const GLfloat * value
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
#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 4402 of file SDL_malloc.c.

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

4403 {
4404  void *mem;
4405  size_t req = 0;
4406  if (n_elements != 0) {
4407  req = n_elements * elem_size;
4408  if (((n_elements | elem_size) & ~(size_t) 0xffff) &&
4409  (req / n_elements != elem_size))
4410  req = MAX_SIZE_T; /* force downstream failure on overflow */
4411  }
4412  mem = dlmalloc(req);
4413  if (mem != 0 && calloc_must_clear(mem2chunk(mem)))
4414  memset(mem, 0, req);
4415  return mem;
4416 }
#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 4305 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.

4306 {
4307  /*
4308  Consolidate freed chunks with preceeding or succeeding bordering
4309  free chunks, if they exist, and then place in a bin. Intermixed
4310  with special cases for top, dv, mmapped chunks, and usage errors.
4311  */
4312 
4313  if (mem != 0) {
4314  mchunkptr p = mem2chunk(mem);
4315 #if FOOTERS
4316  mstate fm = get_mstate_for(p);
4317  if (!ok_magic(fm)) {
4318  USAGE_ERROR_ACTION(fm, p);
4319  return;
4320  }
4321 #else /* FOOTERS */
4322 #define fm gm
4323 #endif /* FOOTERS */
4324  if (!PREACTION(fm)) {
4325  check_inuse_chunk(fm, p);
4326  if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) {
4327  size_t psize = chunksize(p);
4328  mchunkptr next = chunk_plus_offset(p, psize);
4329  if (!pinuse(p)) {
4330  size_t prevsize = p->prev_foot;
4331  if ((prevsize & IS_MMAPPED_BIT) != 0) {
4332  prevsize &= ~IS_MMAPPED_BIT;
4333  psize += prevsize + MMAP_FOOT_PAD;
4334  if (CALL_MUNMAP((char *) p - prevsize, psize) == 0)
4335  fm->footprint -= psize;
4336  goto postaction;
4337  } else {
4338  mchunkptr prev = chunk_minus_offset(p, prevsize);
4339  psize += prevsize;
4340  p = prev;
4341  if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */
4342  if (p != fm->dv) {
4343  unlink_chunk(fm, p, prevsize);
4344  } else if ((next->head & INUSE_BITS) ==
4345  INUSE_BITS) {
4346  fm->dvsize = psize;
4347  set_free_with_pinuse(p, psize, next);
4348  goto postaction;
4349  }
4350  } else
4351  goto erroraction;
4352  }
4353  }
4354 
4355  if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) {
4356  if (!cinuse(next)) { /* consolidate forward */
4357  if (next == fm->top) {
4358  size_t tsize = fm->topsize += psize;
4359  fm->top = p;
4360  p->head = tsize | PINUSE_BIT;
4361  if (p == fm->dv) {
4362  fm->dv = 0;
4363  fm->dvsize = 0;
4364  }
4365  if (should_trim(fm, tsize))
4366  sys_trim(fm, 0);
4367  goto postaction;
4368  } else if (next == fm->dv) {
4369  size_t dsize = fm->dvsize += psize;
4370  fm->dv = p;
4372  goto postaction;
4373  } else {
4374  size_t nsize = chunksize(next);
4375  psize += nsize;
4376  unlink_chunk(fm, next, nsize);
4378  if (p == fm->dv) {
4379  fm->dvsize = psize;
4380  goto postaction;
4381  }
4382  }
4383  } else
4384  set_free_with_pinuse(p, psize, next);
4385  insert_chunk(fm, p, psize);
4386  check_free_chunk(fm, p);
4387  goto postaction;
4388  }
4389  }
4390  erroraction:
4391  USAGE_ERROR_ACTION(fm, p);
4392  postaction:
4393  POSTACTION(fm);
4394  }
4395  }
4396 #if !FOOTERS
4397 #undef fm
4398 #endif /* FOOTERS */
4399 }
#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:3203
#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:3702
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2256
#define unlink_chunk(M, P, S)
Definition: SDL_malloc.c:3207
#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 4450 of file SDL_malloc.c.

References gm, and ialloc().

4451 {
4452  size_t sz = elem_size; /* serves as 1-element array */
4453  return ialloc(gm, n_elements, &sz, 3, chunks);
4454 }
static void ** ialloc(mstate m, size_t n_elements, size_t *sizes, int opts, void *chunks[])
Definition: SDL_malloc.c:4045
#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 4457 of file SDL_malloc.c.

References gm, and ialloc().

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

Definition at line 4506 of file SDL_malloc.c.

References gm, and internal_mallinfo().

4507 {
4508  return internal_mallinfo(gm);
4509 }
#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 4171 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.

4172 {
4173  /*
4174  Basic algorithm:
4175  If a small request (< 256 bytes minus per-chunk overhead):
4176  1. If one exists, use a remainderless chunk in associated smallbin.
4177  (Remainderless means that there are too few excess bytes to
4178  represent as a chunk.)
4179  2. If it is big enough, use the dv chunk, which is normally the
4180  chunk adjacent to the one used for the most recent small request.
4181  3. If one exists, split the smallest available chunk in a bin,
4182  saving remainder in dv.
4183  4. If it is big enough, use the top chunk.
4184  5. If available, get memory from system and use it
4185  Otherwise, for a large request:
4186  1. Find the smallest available binned chunk that fits, and use it
4187  if it is better fitting than dv chunk, splitting if necessary.
4188  2. If better fitting than any binned chunk, use the dv chunk.
4189  3. If it is big enough, use the top chunk.
4190  4. If request size >= mmap threshold, try to directly mmap this chunk.
4191  5. If available, get memory from system and use it
4192 
4193  The ugly goto's here ensure that postaction occurs along all paths.
4194  */
4195 
4196  if (!PREACTION(gm)) {
4197  void *mem;
4198  size_t nb;
4199  if (bytes <= MAX_SMALL_REQUEST) {
4200  bindex_t idx;
4201  binmap_t smallbits;
4202  nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes);
4203  idx = small_index(nb);
4204  smallbits = gm->smallmap >> idx;
4205 
4206  if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */
4207  mchunkptr b, p;
4208  idx += ~smallbits & 1; /* Uses next bin if idx empty */
4209  b = smallbin_at(gm, idx);
4210  p = b->fd;
4211  assert(chunksize(p) == small_index2size(idx));
4212  unlink_first_small_chunk(gm, b, p, idx);
4214  mem = chunk2mem(p);
4215  check_malloced_chunk(gm, mem, nb);
4216  goto postaction;
4217  }
4218 
4219  else if (nb > gm->dvsize) {
4220  if (smallbits != 0) { /* Use chunk in next nonempty smallbin */
4221  mchunkptr b, p, r;
4222  size_t rsize;
4223  bindex_t i;
4224  binmap_t leftbits =
4225  (smallbits << idx) & left_bits(idx2bit(idx));
4226  binmap_t leastbit = least_bit(leftbits);
4227  compute_bit2idx(leastbit, i);
4228  b = smallbin_at(gm, i);
4229  p = b->fd;
4230  assert(chunksize(p) == small_index2size(i));
4231  unlink_first_small_chunk(gm, b, p, i);
4232  rsize = small_index2size(i) - nb;
4233  /* Fit here cannot be remainderless if 4byte sizes */
4234  if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE)
4236  else {
4238  r = chunk_plus_offset(p, nb);
4240  replace_dv(gm, r, rsize);
4241  }
4242  mem = chunk2mem(p);
4243  check_malloced_chunk(gm, mem, nb);
4244  goto postaction;
4245  }
4246 
4247  else if (gm->treemap != 0
4248  && (mem = tmalloc_small(gm, nb)) != 0) {
4249  check_malloced_chunk(gm, mem, nb);
4250  goto postaction;
4251  }
4252  }
4253  } else if (bytes >= MAX_REQUEST)
4254  nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */
4255  else {
4256  nb = pad_request(bytes);
4257  if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) {
4258  check_malloced_chunk(gm, mem, nb);
4259  goto postaction;
4260  }
4261  }
4262 
4263  if (nb <= gm->dvsize) {
4264  size_t rsize = gm->dvsize - nb;
4265  mchunkptr p = gm->dv;
4266  if (rsize >= MIN_CHUNK_SIZE) { /* split dv */
4267  mchunkptr r = gm->dv = chunk_plus_offset(p, nb);
4268  gm->dvsize = rsize;
4271  } else { /* exhaust dv */
4272  size_t dvs = gm->dvsize;
4273  gm->dvsize = 0;
4274  gm->dv = 0;
4275  set_inuse_and_pinuse(gm, p, dvs);
4276  }
4277  mem = chunk2mem(p);
4278  check_malloced_chunk(gm, mem, nb);
4279  goto postaction;
4280  }
4281 
4282  else if (nb < gm->topsize) { /* Split top */
4283  size_t rsize = gm->topsize -= nb;
4284  mchunkptr p = gm->top;
4285  mchunkptr r = gm->top = chunk_plus_offset(p, nb);
4286  r->head = rsize | PINUSE_BIT;
4288  mem = chunk2mem(p);
4289  check_top_chunk(gm, gm->top);
4290  check_malloced_chunk(gm, mem, nb);
4291  goto postaction;
4292  }
4293 
4294  mem = sys_alloc(gm, nb);
4295 
4296  postaction:
4297  POSTACTION(gm);
4298  return mem;
4299  }
4300 
4301  return 0;
4302 }
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
static void * sys_alloc(mstate m, size_t nb)
Definition: SDL_malloc.c:3461
size_t bindex_t
Definition: SDL_malloc.c:1694
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
static void * tmalloc_large(mstate m, size_t nb)
Definition: SDL_malloc.c:3768
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
GLfloat GLfloat p
#define replace_dv(M, P, S)
Definition: SDL_malloc.c:3048
#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
#define MIN_REQUEST
Definition: SDL_malloc.c:1725
#define unlink_first_small_chunk(M, B, P, I)
Definition: SDL_malloc.c:3030
#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:3843
#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
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:42
#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 4493 of file SDL_malloc.c.

References gm.

4494 {
4495  return gm->footprint;
4496 }
#define gm
Definition: SDL_malloc.c:2111
size_t dlmalloc_max_footprint ( void  )

Definition at line 4499 of file SDL_malloc.c.

References gm.

4500 {
4501  return gm->max_footprint;
4502 }
#define gm
Definition: SDL_malloc.c:2111
void dlmalloc_stats ( void  )

Definition at line 4513 of file SDL_malloc.c.

References gm, and internal_malloc_stats().

4514 {
4516 }
#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 4482 of file SDL_malloc.c.

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

4483 {
4484  int result = 0;
4485  if (!PREACTION(gm)) {
4486  result = sys_trim(gm, pad);
4487  POSTACTION(gm);
4488  }
4489  return result;
4490 }
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
GLuint64EXT * result
static int sys_trim(mstate m, size_t pad)
Definition: SDL_malloc.c:3702
#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 4519 of file SDL_malloc.c.

References chunksize, cinuse, mem2chunk, and overhead_for.

4520 {
4521  if (mem != 0) {
4522  mchunkptr p = mem2chunk(mem);
4523  if (cinuse(p))
4524  return chunksize(p) - overhead_for(p);
4525  }
4526  return 0;
4527 }
#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 4530 of file SDL_malloc.c.

References align_as_chunk, assert, msegmentptr::base, CALL_MMAP, CALL_MUNMAP, calloc_must_clear, change_mparam(), check_free_chunk, check_inuse_chunk, check_malloced_chunk, check_top_chunk, chunk2mem, chunk_minus_offset, chunk_plus_offset, chunksize, cinuse, CINUSE_BIT, CMFAIL, compute_bit2idx, malloc_params::default_mflags, disable_contiguous, EXTERN_BIT, fm, mstate::footprint, malloc_params::granularity, granularity_align, i, ialloc(), idx2bit, init_bins(), init_mparams(), init_top(), INITIAL_LOCK, insert_chunk, internal_mallinfo(), internal_malloc, internal_malloc_stats(), internal_memalign(), internal_realloc(), INUSE_BITS, IS_MMAPPED_BIT, least_bit, left_bits, malloc_params::magic, mstate::max_footprint, MAX_REQUEST, MAX_SIZE_T, MAX_SMALL_REQUEST, mem2chunk, memset, MIN_CHUNK_SIZE, MIN_REQUEST, MMAP_FOOT_PAD, mparams, next_chunk, ok_address, ok_cinuse, ok_magic, ok_next, ok_pinuse, pad_request, malloc_params::page_size, pinuse, PINUSE_BIT, POSTACTION, PREACTION, replace_dv, RTCHECK, set_free_with_pinuse, set_inuse_and_pinuse, set_lock, set_size_and_pinuse_of_free_chunk, set_size_and_pinuse_of_inuse_chunk, should_trim, SIZE_T_SIZE, small_index, small_index2size, smallbin_at, sys_alloc(), sys_trim(), tmalloc_large(), tmalloc_small(), TOP_FOOT_SIZE, unlink_chunk, unlink_first_small_chunk, and USAGE_ERROR_ACTION.

4531 {
4532  return change_mparam(param_number, value);
4533 }
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 4444 of file SDL_malloc.c.

References gm, and internal_memalign().

4445 {
4446  return internal_memalign(gm, alignment, bytes);
4447 }
#define gm
Definition: SDL_malloc.c:2111
static void * internal_memalign(mstate m, size_t alignment, size_t bytes)
Definition: SDL_malloc.c:3955
void * dlpvalloc ( size_t  bytes)

Definition at line 4472 of file SDL_malloc.c.

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

4473 {
4474  size_t pagesz;
4475  init_mparams();
4476  pagesz = mparams.page_size;
4477  return dlmemalign(pagesz,
4478  (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE));
4479 }
#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 4419 of file SDL_malloc.c.

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

4420 {
4421  if (oldmem == 0)
4422  return dlmalloc(bytes);
4423 #ifdef REALLOC_ZERO_BYTES_FREES
4424  if (bytes == 0) {
4425  dlfree(oldmem);
4426  return 0;
4427  }
4428 #endif /* REALLOC_ZERO_BYTES_FREES */
4429  else {
4430 #if ! FOOTERS
4431  mstate m = gm;
4432 #else /* FOOTERS */
4433  mstate m = get_mstate_for(mem2chunk(oldmem));
4434  if (!ok_magic(m)) {
4435  USAGE_ERROR_ACTION(m, oldmem);
4436  return 0;
4437  }
4438 #endif /* FOOTERS */
4439  return internal_realloc(m, oldmem, bytes);
4440  }
4441 }
#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:3885
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 4463 of file SDL_malloc.c.

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

4464 {
4465  size_t pagesz;
4466  init_mparams();
4467  pagesz = mparams.page_size;
4468  return dlmemalign(pagesz, bytes);
4469 }
#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 4045 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(), dlindependent_comalloc(), and dlmallopt().

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

References i, NSMALLBINS, NTREEBINS, smallbin_at, and treebin_at.

Referenced by dlmallopt(), and sys_alloc().

3330 {
3331  /* Establish circular links for smallbins */
3332  bindex_t i;
3333  for (i = 0; i < NSMALLBINS; ++i) {
3334  sbinptr bin = smallbin_at(m, i);
3335  bin->fd = bin->bk = bin;
3336  }
3337 }
size_t bindex_t
Definition: SDL_malloc.c:1694
const GLfloat * m
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
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:42
#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(), dlmallopt(), 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:2056
#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
size_t mmap_threshold
Definition: SDL_malloc.c:2102
static void init_top ( mstate  m,
mchunkptr  p,
size_t  psize 
)
static

Definition at line 3312 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(), dlmallopt(), sys_alloc(), and sys_trim().

3313 {
3314  /* Ensure alignment */
3315  size_t offset = align_offset(chunk2mem(p));
3316  p = (mchunkptr) ((char *) p + offset);
3317  psize -= offset;
3318 
3319  m->top = p;
3320  m->topsize = psize;
3321  p->head = psize | PINUSE_BIT;
3322  /* set size of fake trailing chunk holding overhead space only once */
3323  chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
3324  m->trim_check = mparams.trim_threshold; /* reset on each update */
3325 }
const GLfloat * m
GLfloat GLfloat p
#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
GLintptr offset
#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(), and dlmallopt().

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:2056
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2080
#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(), and dlmallopt().

2947 {
2948  if (!PREACTION(m)) {
2949  size_t maxfp = 0;
2950  size_t fp = 0;
2951  size_t used = 0;
2953  if (is_initialized(m)) {
2954  msegmentptr s = &m->seg;
2955  maxfp = m->max_footprint;
2956  fp = m->footprint;
2957  used = fp - (m->topsize + TOP_FOOT_SIZE);
2958 
2959  while (s != 0) {
2960  mchunkptr q = align_as_chunk(s->base);
2961  while (segment_holds(s, q) &&
2962  q != m->top && q->head != FENCEPOST_HEAD) {
2963  if (!cinuse(q))
2964  used -= chunksize(q);
2965  q = next_chunk(q);
2966  }
2967  s = s->next;
2968  }
2969  }
2970 #ifndef LACKS_STDIO_H
2971  fprintf(stderr, "max system bytes = %10lu\n",
2972  (unsigned long) (maxfp));
2973  fprintf(stderr, "system bytes = %10lu\n", (unsigned long) (fp));
2974  fprintf(stderr, "in use bytes = %10lu\n", (unsigned long) (used));
2975 #endif
2976 
2977  POSTACTION(m);
2978  }
2979 }
#define next_chunk(p)
Definition: SDL_malloc.c:1766
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
GLdouble s
Definition: SDL_opengl.h:2056
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2080
#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 3955 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 dlmallopt(), and dlmemalign().

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

3886 {
3887  if (bytes >= MAX_REQUEST) {
3889  return 0;
3890  }
3891  if (!PREACTION(m)) {
3892  mchunkptr oldp = mem2chunk(oldmem);
3893  size_t oldsize = chunksize(oldp);
3894  mchunkptr next = chunk_plus_offset(oldp, oldsize);
3895  mchunkptr newp = 0;
3896  void *extra = 0;
3897 
3898  /* Try to either shrink or extend into top. Else malloc-copy-free */
3899 
3900  if (RTCHECK(ok_address(m, oldp) && ok_cinuse(oldp) &&
3901  ok_next(oldp, next) && ok_pinuse(next))) {
3902  size_t nb = request2size(bytes);
3903  if (is_mmapped(oldp))
3904  newp = mmap_resize(m, oldp, nb);
3905  else if (oldsize >= nb) { /* already big enough */
3906  size_t rsize = oldsize - nb;
3907  newp = oldp;
3908  if (rsize >= MIN_CHUNK_SIZE) {
3909  mchunkptr remainder = chunk_plus_offset(newp, nb);
3910  set_inuse(m, newp, nb);
3911  set_inuse(m, remainder, rsize);
3912  extra = chunk2mem(remainder);
3913  }
3914  } else if (next == m->top && oldsize + m->topsize > nb) {
3915  /* Expand into top */
3916  size_t newsize = oldsize + m->topsize;
3917  size_t newtopsize = newsize - nb;
3918  mchunkptr newtop = chunk_plus_offset(oldp, nb);
3919  set_inuse(m, oldp, nb);
3920  newtop->head = newtopsize | PINUSE_BIT;
3921  m->top = newtop;
3922  m->topsize = newtopsize;
3923  newp = oldp;
3924  }
3925  } else {
3926  USAGE_ERROR_ACTION(m, oldmem);
3927  POSTACTION(m);
3928  return 0;
3929  }
3930 
3931  POSTACTION(m);
3932 
3933  if (newp != 0) {
3934  if (extra != 0) {
3935  internal_free(m, extra);
3936  }
3937  check_inuse_chunk(m, newp);
3938  return chunk2mem(newp);
3939  } else {
3940  void *newmem = internal_malloc(m, bytes);
3941  if (newmem != 0) {
3942  size_t oc = oldsize - overhead_for(oldp);
3943  memcpy(newmem, oldmem, (oc < bytes) ? oc : bytes);
3944  internal_free(m, oldmem);
3945  }
3946  return newmem;
3947  }
3948  }
3949  return 0;
3950 }
#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:3273
#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:3225
#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:3224
#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 3243 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, head, 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().

3244 {
3245  size_t mmsize =
3247  if (mmsize > nb) { /* Check for wrap around 0 */
3248  char *mm = (char *) (DIRECT_MMAP(mmsize));
3249  if (mm != CMFAIL) {
3250  size_t offset = align_offset(chunk2mem(mm));
3251  size_t psize = mmsize - offset - MMAP_FOOT_PAD;
3252  mchunkptr p = (mchunkptr) (mm + offset);
3253  p->prev_foot = offset | IS_MMAPPED_BIT;
3254  (p)->head = (psize | CINUSE_BIT);
3255  mark_inuse_foot(m, p, psize);
3256  chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;
3257  chunk_plus_offset(p, psize + SIZE_T_SIZE)->head = 0;
3258 
3259  if (mm < m->least_addr)
3260  m->least_addr = mm;
3261  if ((m->footprint += mmsize) > m->max_footprint)
3262  m->max_footprint = m->footprint;
3264  check_mmapped_chunk(m, p);
3265  return chunk2mem(p);
3266  }
3267  }
3268  return 0;
3269 }
#define DIRECT_MMAP(s)
Definition: SDL_malloc.c:1431
#define mark_inuse_foot(M, p, s)
Definition: SDL_malloc.c:2466
const GLfloat * m
GLfloat GLfloat p
#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
#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
GLintptr offset
#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:79
#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 3273 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().

3274 {
3275  size_t oldsize = chunksize(oldp);
3276  if (is_small(nb)) /* Can't shrink mmap regions below small size */
3277  return 0;
3278  /* Keep old chunk if big enough but not too big */
3279  if (oldsize >= nb + SIZE_T_SIZE &&
3280  (oldsize - nb) <= (mparams.granularity << 1))
3281  return oldp;
3282  else {
3283  size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT;
3284  size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD;
3285  size_t newmmsize = granularity_align(nb + SIX_SIZE_T_SIZES +
3287  char *cp = (char *) CALL_MREMAP((char *) oldp - offset,
3288  oldmmsize, newmmsize, 1);
3289  if (cp != CMFAIL) {
3290  mchunkptr newp = (mchunkptr) (cp + offset);
3291  size_t psize = newmmsize - offset - MMAP_FOOT_PAD;
3292  newp->head = (psize | CINUSE_BIT);
3293  mark_inuse_foot(m, newp, psize);
3294  chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;
3295  chunk_plus_offset(newp, psize + SIZE_T_SIZE)->head = 0;
3296 
3297  if (cp < m->least_addr)
3298  m->least_addr = cp;
3299  if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint)
3300  m->max_footprint = m->footprint;
3301  check_mmapped_chunk(m, newp);
3302  return newp;
3303  }
3304  }
3305  return 0;
3306 }
#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
#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
GLintptr offset
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 3362 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().

3363 {
3364  mchunkptr p = align_as_chunk(newbase);
3365  mchunkptr oldfirst = align_as_chunk(oldbase);
3366  size_t psize = (char *) oldfirst - (char *) p;
3367  mchunkptr q = chunk_plus_offset(p, nb);
3368  size_t qsize = psize - nb;
3370 
3371  assert((char *) oldfirst > (char *) q);
3372  assert(pinuse(oldfirst));
3373  assert(qsize >= MIN_CHUNK_SIZE);
3374 
3375  /* consolidate remainder with first chunk of old base */
3376  if (oldfirst == m->top) {
3377  size_t tsize = m->topsize += qsize;
3378  m->top = q;
3379  q->head = tsize | PINUSE_BIT;
3380  check_top_chunk(m, q);
3381  } else if (oldfirst == m->dv) {
3382  size_t dsize = m->dvsize += qsize;
3383  m->dv = q;
3385  } else {
3386  if (!cinuse(oldfirst)) {
3387  size_t nsize = chunksize(oldfirst);
3388  unlink_chunk(m, oldfirst, nsize);
3389  oldfirst = chunk_plus_offset(oldfirst, nsize);
3390  qsize += nsize;
3391  }
3392  set_free_with_pinuse(q, qsize, oldfirst);
3393  insert_chunk(m, q, qsize);
3394  check_free_chunk(m, q);
3395  }
3396 
3397  check_malloced_chunk(m, chunk2mem(p), nb);
3398  return chunk2mem(p);
3399 }
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3203
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2080
#define cinuse(p)
Definition: SDL_malloc.c:1754
const GLfloat * m
GLfloat GLfloat p
#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:3207
#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 3661 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().

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

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

3703 {
3704  size_t released = 0;
3705  if (pad < MAX_REQUEST && is_initialized(m)) {
3706  pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */
3707 
3708  if (m->topsize > pad) {
3709  /* Shrink top space in granularity-size units, keeping at least one */
3710  size_t unit = mparams.granularity;
3711  size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit -
3712  SIZE_T_ONE) * unit;
3713  msegmentptr sp = segment_holding(m, (char *) m->top);
3714 
3715  if (!is_extern_segment(sp)) {
3716  if (is_mmapped_segment(sp)) {
3717  if (HAVE_MMAP && sp->size >= extra && !has_segment_link(m, sp)) { /* can't shrink if pinned */
3718  size_t newsize = sp->size - extra;
3719  /* Prefer mremap, fall back to munmap */
3720  if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) !=
3721  MFAIL)
3722  || (CALL_MUNMAP(sp->base + newsize, extra) == 0)) {
3723  released = extra;
3724  }
3725  }
3726  } else if (HAVE_MORECORE) {
3727  if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */
3728  extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit;
3730  {
3731  /* Make sure end of memory is where we last set it. */
3732  char *old_br = (char *) (CALL_MORECORE(0));
3733  if (old_br == sp->base + sp->size) {
3734  char *rel_br = (char *) (CALL_MORECORE(-extra));
3735  char *new_br = (char *) (CALL_MORECORE(0));
3736  if (rel_br != CMFAIL && new_br < old_br)
3737  released = old_br - new_br;
3738  }
3739  }
3741  }
3742  }
3743 
3744  if (released != 0) {
3745  sp->size -= released;
3746  m->footprint -= released;
3747  init_top(m, m->top, m->topsize - released);
3748  check_top_chunk(m, m->top);
3749  }
3750  }
3751 
3752  /* Unmap any unused mmapped segments */
3753  if (HAVE_MMAP)
3754  released += release_unused_segments(m);
3755 
3756  /* On failure, disable autotrim to avoid repeated failed future calls */
3757  if (released == 0)
3758  m->trim_check = MAX_SIZE_T;
3759  }
3760 
3761  return (released != 0) ? 1 : 0;
3762 }
#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:3312
#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:3661
#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 3768 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(), and dlmallopt().

3769 {
3770  tchunkptr v = 0;
3771  size_t rsize = -nb; /* Unsigned negation */
3772  tchunkptr t;
3773  bindex_t idx;
3774  compute_tree_index(nb, idx);
3775 
3776  if ((t = *treebin_at(m, idx)) != 0) {
3777  /* Traverse tree for this bin looking for node with size == nb */
3778  size_t sizebits = nb << leftshift_for_tree_index(idx);
3779  tchunkptr rst = 0; /* The deepest untaken right subtree */
3780  for (;;) {
3781  tchunkptr rt;
3782  size_t trem = chunksize(t) - nb;
3783  if (trem < rsize) {
3784  v = t;
3785  if ((rsize = trem) == 0)
3786  break;
3787  }
3788  rt = t->child[1];
3789  t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1];
3790  if (rt != 0 && rt != t)
3791  rst = rt;
3792  if (t == 0) {
3793  t = rst; /* set t to least subtree holding sizes > nb */
3794  break;
3795  }
3796  sizebits <<= 1;
3797  }
3798  }
3799 
3800  if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */
3801  binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap;
3802  if (leftbits != 0) {
3803  bindex_t i;
3804  binmap_t leastbit = least_bit(leftbits);
3805  compute_bit2idx(leastbit, i);
3806  t = *treebin_at(m, i);
3807  }
3808  }
3809 
3810  while (t != 0) { /* find smallest of tree or subtree */
3811  size_t trem = chunksize(t) - nb;
3812  if (trem < rsize) {
3813  rsize = trem;
3814  v = t;
3815  }
3816  t = leftmost_child(t);
3817  }
3818 
3819  /* If dv is a better fit, return 0 so malloc will use it */
3820  if (v != 0 && rsize < (size_t) (m->dvsize - nb)) {
3821  if (RTCHECK(ok_address(m, v))) { /* split */
3822  mchunkptr r = chunk_plus_offset(v, nb);
3823  assert(chunksize(v) == rsize + nb);
3824  if (RTCHECK(ok_next(v, r))) {
3825  unlink_large_chunk(m, v);
3826  if (rsize < MIN_CHUNK_SIZE)
3827  set_inuse_and_pinuse(m, v, (rsize + nb));
3828  else {
3831  insert_chunk(m, r, rsize);
3832  }
3833  return chunk2mem(v);
3834  }
3835  }
3837  }
3838  return 0;
3839 }
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3130
size_t bindex_t
Definition: SDL_malloc.c:1694
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
#define compute_tree_index(S, I)
Definition: SDL_malloc.c:2311
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3203
#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
const GLdouble * v
Definition: SDL_opengl.h:2057
#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
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:42
#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:2064
#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 3843 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(), and dlmallopt().

3844 {
3845  tchunkptr t, v;
3846  size_t rsize;
3847  bindex_t i;
3848  binmap_t leastbit = least_bit(m->treemap);
3849  compute_bit2idx(leastbit, i);
3850 
3851  v = t = *treebin_at(m, i);
3852  rsize = chunksize(t) - nb;
3853 
3854  while ((t = leftmost_child(t)) != 0) {
3855  size_t trem = chunksize(t) - nb;
3856  if (trem < rsize) {
3857  rsize = trem;
3858  v = t;
3859  }
3860  }
3861 
3862  if (RTCHECK(ok_address(m, v))) {
3863  mchunkptr r = chunk_plus_offset(v, nb);
3864  assert(chunksize(v) == rsize + nb);
3865  if (RTCHECK(ok_next(v, r))) {
3866  unlink_large_chunk(m, v);
3867  if (rsize < MIN_CHUNK_SIZE)
3868  set_inuse_and_pinuse(m, v, (rsize + nb));
3869  else {
3872  replace_dv(m, r, rsize);
3873  }
3874  return chunk2mem(v);
3875  }
3876  }
3877 
3879  return 0;
3880 }
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3130
size_t bindex_t
Definition: SDL_malloc.c:1694
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
const GLfloat * m
#define replace_dv(M, P, S)
Definition: SDL_malloc.c:3048
#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
const GLdouble * v
Definition: SDL_opengl.h:2057
#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
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:42
#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:2064
#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 }
GLsizeiptr size
#define MFAIL
Definition: SDL_malloc.c:1352
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 }
GLsizeiptr size
#define MFAIL
Definition: SDL_malloc.c:1352
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