SDL  2.0
SDL_malloc.c File Reference
#include "../SDL_internal.h"
#include "SDL_stdinc.h"
#include "SDL_atomic.h"
#include "SDL_error.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 USE_DL_PREFIX
 
#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 M_TRIM_THRESHOLD   (-1)
 
#define M_GRANULARITY   (-2)
 
#define M_MMAP_THRESHOLD   (-3)
 
#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
 
#define real_malloc   dlmalloc
 
#define real_calloc   dlcalloc
 
#define real_realloc   dlrealloc
 
#define real_free   dlfree
 

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[])
 
void SDL_GetMemoryFunctions (SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
 Get the current set of SDL memory functions. More...
 
int SDL_SetMemoryFunctions (SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
 Replace SDL's memory allocation functions with a custom set. More...
 
int SDL_GetNumAllocations (void)
 Get the number of outstanding (unfreed) allocations. More...
 
voidSDL_malloc (size_t size)
 
voidSDL_calloc (size_t nmemb, size_t size)
 
voidSDL_realloc (void *ptr, size_t size)
 
void SDL_free (void *ptr)
 

Variables

static MLOCK_T magic_init_mutex
 
static struct malloc_params mparams
 
static struct malloc_state _gm_
 
struct {
   SDL_malloc_func   malloc_func
 
   SDL_calloc_func   calloc_func
 
   SDL_realloc_func   realloc_func
 
   SDL_free_func   free_func
 
   SDL_atomic_t   num_allocations
 
s_mem
 

Macro Definition Documentation

◆ ABORT

#define ABORT

Definition at line 39 of file SDL_malloc.c.

◆ ABORT_ON_ASSERT_FAILURE

#define ABORT_ON_ASSERT_FAILURE   1

Definition at line 548 of file SDL_malloc.c.

◆ ACQUIRE_LOCK

#define ACQUIRE_LOCK (   l)    win32_acquire_lock(l)

Definition at line 1548 of file SDL_malloc.c.

◆ ACQUIRE_MAGIC_INIT_LOCK

#define ACQUIRE_MAGIC_INIT_LOCK ( )    ACQUIRE_LOCK(&magic_init_mutex);

Definition at line 1571 of file SDL_malloc.c.

◆ ACQUIRE_MORECORE_LOCK

#define ACQUIRE_MORECORE_LOCK ( )

Definition at line 1566 of file SDL_malloc.c.

◆ align_as_chunk

#define align_as_chunk (   A)    (mchunkptr)((A) + align_offset(chunk2mem(A)))

Definition at line 1754 of file SDL_malloc.c.

◆ align_offset

#define align_offset (   A)
Value:

Definition at line 1325 of file SDL_malloc.c.

◆ assert

#define assert (   x)

Definition at line 1227 of file SDL_malloc.c.

◆ bit_for_tree_index

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

Definition at line 2364 of file SDL_malloc.c.

◆ CALL_MMAP

#define CALL_MMAP (   s)    win32mmap(s)

Definition at line 1452 of file SDL_malloc.c.

◆ CALL_MORECORE

#define CALL_MORECORE (   S)    MFAIL

Definition at line 1467 of file SDL_malloc.c.

◆ CALL_MREMAP

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

Definition at line 1461 of file SDL_malloc.c.

◆ CALL_MUNMAP

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

Definition at line 1453 of file SDL_malloc.c.

◆ calloc_must_clear

#define calloc_must_clear (   p)    (1)

Definition at line 1828 of file SDL_malloc.c.

◆ check_free_chunk

#define check_free_chunk (   M,
 
)

Definition at line 2288 of file SDL_malloc.c.

◆ check_inuse_chunk

#define check_inuse_chunk (   M,
 
)

Definition at line 2289 of file SDL_malloc.c.

◆ check_malloc_state

#define check_malloc_state (   M)

Definition at line 2292 of file SDL_malloc.c.

◆ check_malloced_chunk

#define check_malloced_chunk (   M,
  P,
 
)

Definition at line 2290 of file SDL_malloc.c.

◆ check_mmapped_chunk

#define check_mmapped_chunk (   M,
 
)

Definition at line 2291 of file SDL_malloc.c.

◆ check_top_chunk

#define check_top_chunk (   M,
 
)

Definition at line 2293 of file SDL_malloc.c.

◆ chunk2mem

#define chunk2mem (   p)    ((void*)((char*)(p) + TWO_SIZE_T_SIZES))

Definition at line 1751 of file SDL_malloc.c.

◆ CHUNK_ALIGN_MASK

#define CHUNK_ALIGN_MASK   (MALLOC_ALIGNMENT - SIZE_T_ONE)

Definition at line 1319 of file SDL_malloc.c.

◆ chunk_minus_offset

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

Definition at line 1796 of file SDL_malloc.c.

◆ CHUNK_OVERHEAD

#define CHUNK_OVERHEAD   (SIZE_T_SIZE)

Definition at line 1738 of file SDL_malloc.c.

◆ chunk_plus_offset

#define chunk_plus_offset (   p,
  s 
)    ((mchunkptr)(((char*)(p)) + (s)))

Definition at line 1795 of file SDL_malloc.c.

◆ chunksize

#define chunksize (   p)    ((p)->head & ~(INUSE_BITS))

Definition at line 1789 of file SDL_malloc.c.

◆ cinuse

#define cinuse (   p)    ((p)->head & CINUSE_BIT)

Definition at line 1787 of file SDL_malloc.c.

◆ CINUSE_BIT

#define CINUSE_BIT   (SIZE_T_TWO)

Definition at line 1780 of file SDL_malloc.c.

◆ clear_cinuse

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

Definition at line 1792 of file SDL_malloc.c.

◆ clear_pinuse

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

Definition at line 1791 of file SDL_malloc.c.

◆ clear_smallmap

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

Definition at line 2385 of file SDL_malloc.c.

◆ clear_treemap

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

Definition at line 2389 of file SDL_malloc.c.

◆ CMFAIL

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

Definition at line 1340 of file SDL_malloc.c.

◆ compute_bit2idx

#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);\
}

Definition at line 2407 of file SDL_malloc.c.

◆ compute_tree_index

#define compute_tree_index (   S,
  I 
)
Value:
{\
size_t X = S >> TREEBIN_SHIFT;\
if (X == 0)\
I = 0;\
else if (X > 0xFFFF)\
I = NTREEBINS-1;\
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));\
}\
}

Definition at line 2344 of file SDL_malloc.c.

◆ CORRUPTION_ERROR_ACTION

#define CORRUPTION_ERROR_ACTION (   m)    ABORT

Definition at line 2275 of file SDL_malloc.c.

◆ DEFAULT_GRANULARITY

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

Definition at line 596 of file SDL_malloc.c.

◆ DEFAULT_MMAP_THRESHOLD

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

Definition at line 608 of file SDL_malloc.c.

◆ DEFAULT_TRIM_THRESHOLD

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

Definition at line 601 of file SDL_malloc.c.

◆ DIRECT_MMAP

#define DIRECT_MMAP (   s)    win32direct_mmap(s)

Definition at line 1454 of file SDL_malloc.c.

◆ disable_contiguous

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

Definition at line 2161 of file SDL_malloc.c.

◆ disable_lock

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

Definition at line 2154 of file SDL_malloc.c.

◆ disable_mmap

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

Definition at line 2158 of file SDL_malloc.c.

◆ enable_lock

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

Definition at line 2153 of file SDL_malloc.c.

◆ enable_mmap

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

Definition at line 2157 of file SDL_malloc.c.

◆ EXTERN_BIT

#define EXTERN_BIT   (8U)

Definition at line 1474 of file SDL_malloc.c.

◆ FENCEPOST_HEAD

#define FENCEPOST_HEAD   (INUSE_BITS|SIZE_T_SIZE)

Definition at line 1784 of file SDL_malloc.c.

◆ fm

#define fm   gm

◆ FOOTERS

#define FOOTERS   0

Definition at line 542 of file SDL_malloc.c.

◆ FOUR_SIZE_T_SIZES

#define FOUR_SIZE_T_SIZES   (SIZE_T_SIZE<<2)

Definition at line 1314 of file SDL_malloc.c.

◆ get_foot

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

Definition at line 1806 of file SDL_malloc.c.

◆ GLOBALLY_INITIALIZE

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

Definition at line 2237 of file SDL_malloc.c.

◆ gm

#define gm   (&_gm_)

Definition at line 2144 of file SDL_malloc.c.

◆ granularity_align

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

Definition at line 2173 of file SDL_malloc.c.

◆ HALF_MAX_SIZE_T

#define HALF_MAX_SIZE_T   (MAX_SIZE_T / 2U)

Definition at line 1316 of file SDL_malloc.c.

◆ HAVE_MMAP

#define HAVE_MMAP   1

Definition at line 491 of file SDL_malloc.c.

◆ HAVE_MORECORE

#define HAVE_MORECORE   0

Definition at line 492 of file SDL_malloc.c.

◆ HAVE_MREMAP

#define HAVE_MREMAP   0

Definition at line 569 of file SDL_malloc.c.

◆ idx2bit

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

Definition at line 2381 of file SDL_malloc.c.

◆ INITIAL_LOCK

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

Definition at line 1547 of file SDL_malloc.c.

◆ INSECURE

#define INSECURE   0

Definition at line 557 of file SDL_malloc.c.

◆ insert_chunk

#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); }

Definition at line 3245 of file SDL_malloc.c.

◆ insert_large_chunk

#define insert_large_chunk (   M,
  X,
 
)

Definition at line 3104 of file SDL_malloc.c.

◆ insert_small_chunk

#define insert_small_chunk (   M,
  P,
 
)
Value:
{\
bindex_t I = small_index(S);\
mchunkptr B = smallbin_at(M, I);\
mchunkptr F = B;\
assert(S >= MIN_CHUNK_SIZE);\
if (!smallmap_is_marked(M, I))\
mark_smallmap(M, I);\
else if (RTCHECK(ok_address(M, B->fd)))\
F = B->fd;\
else {\
CORRUPTION_ERROR_ACTION(M);\
}\
B->fd = P;\
F->bk = P;\
P->fd = F;\
P->bk = B;\
}

Definition at line 3033 of file SDL_malloc.c.

◆ internal_free

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

Definition at line 3267 of file SDL_malloc.c.

◆ internal_malloc

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

Definition at line 3266 of file SDL_malloc.c.

◆ INUSE_BITS

#define INUSE_BITS   (PINUSE_BIT|CINUSE_BIT)

Definition at line 1781 of file SDL_malloc.c.

◆ is_aligned

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

Definition at line 1322 of file SDL_malloc.c.

◆ is_extern_segment

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

Definition at line 2008 of file SDL_malloc.c.

◆ is_global

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

Definition at line 2145 of file SDL_malloc.c.

◆ is_granularity_aligned

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

Definition at line 2178 of file SDL_malloc.c.

◆ is_initialized

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

Definition at line 2146 of file SDL_malloc.c.

◆ is_mmapped

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

Definition at line 1817 of file SDL_malloc.c.

◆ IS_MMAPPED_BIT

#define IS_MMAPPED_BIT   (SIZE_T_ONE)

Definition at line 1350 of file SDL_malloc.c.

◆ is_mmapped_segment

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

Definition at line 2007 of file SDL_malloc.c.

◆ is_page_aligned

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

Definition at line 2176 of file SDL_malloc.c.

◆ is_small

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

Definition at line 2319 of file SDL_malloc.c.

◆ LACKS_ERRNO_H

#define LACKS_ERRNO_H

Definition at line 499 of file SDL_malloc.c.

◆ LACKS_FCNTL_H

#define LACKS_FCNTL_H

Definition at line 500 of file SDL_malloc.c.

◆ LACKS_STDIO_H

#define LACKS_STDIO_H

Definition at line 35 of file SDL_malloc.c.

◆ LACKS_STDLIB_H

#define LACKS_STDLIB_H

Definition at line 38 of file SDL_malloc.c.

◆ LACKS_STRING_H [1/2]

#define LACKS_STRING_H

Definition at line 496 of file SDL_malloc.c.

◆ LACKS_STRING_H [2/2]

#define LACKS_STRING_H

Definition at line 496 of file SDL_malloc.c.

◆ LACKS_STRINGS_H [1/2]

#define LACKS_STRINGS_H

Definition at line 497 of file SDL_malloc.c.

◆ LACKS_STRINGS_H [2/2]

#define LACKS_STRINGS_H

Definition at line 497 of file SDL_malloc.c.

◆ LACKS_SYS_MMAN_H

#define LACKS_SYS_MMAN_H

Definition at line 495 of file SDL_malloc.c.

◆ LACKS_SYS_PARAM_H

#define LACKS_SYS_PARAM_H

Definition at line 494 of file SDL_malloc.c.

◆ LACKS_SYS_TYPES_H [1/2]

#define LACKS_SYS_TYPES_H

Definition at line 498 of file SDL_malloc.c.

◆ LACKS_SYS_TYPES_H [2/2]

#define LACKS_SYS_TYPES_H

Definition at line 498 of file SDL_malloc.c.

◆ LACKS_UNISTD_H

#define LACKS_UNISTD_H

Definition at line 493 of file SDL_malloc.c.

◆ least_bit

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

Definition at line 2422 of file SDL_malloc.c.

◆ left_bits

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

Definition at line 2425 of file SDL_malloc.c.

◆ leftmost_child

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

Definition at line 1940 of file SDL_malloc.c.

◆ leftshift_for_tree_index

#define leftshift_for_tree_index (   i)
Value:
((i == NTREEBINS-1)? 0 : \
((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2)))

Definition at line 2368 of file SDL_malloc.c.

◆ M_GRANULARITY

#define M_GRANULARITY   (-2)

Definition at line 641 of file SDL_malloc.c.

◆ M_MMAP_THRESHOLD

#define M_MMAP_THRESHOLD   (-3)

Definition at line 642 of file SDL_malloc.c.

◆ M_TRIM_THRESHOLD

#define M_TRIM_THRESHOLD   (-1)

Definition at line 640 of file SDL_malloc.c.

◆ MALLINFO_FIELD_TYPE

#define MALLINFO_FIELD_TYPE   size_t

Definition at line 623 of file SDL_malloc.c.

◆ MALLOC_ALIGNMENT

#define MALLOC_ALIGNMENT   ((size_t)8U)

Definition at line 539 of file SDL_malloc.c.

◆ MALLOC_FAILURE_ACTION

#define MALLOC_FAILURE_ACTION

Definition at line 501 of file SDL_malloc.c.

◆ mark_inuse_foot

#define mark_inuse_foot (   M,
  p,
  s 
)

Definition at line 2499 of file SDL_malloc.c.

◆ mark_smallmap

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

Definition at line 2384 of file SDL_malloc.c.

◆ mark_treemap

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

Definition at line 2388 of file SDL_malloc.c.

◆ MAX_REQUEST

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

Definition at line 1757 of file SDL_malloc.c.

◆ MAX_SIZE_T

#define MAX_SIZE_T   (~(size_t)0)

Definition at line 526 of file SDL_malloc.c.

◆ MAX_SMALL_REQUEST

#define MAX_SMALL_REQUEST   (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)

Definition at line 2096 of file SDL_malloc.c.

◆ MAX_SMALL_SIZE

#define MAX_SMALL_SIZE   (MIN_LARGE_SIZE - SIZE_T_ONE)

Definition at line 2095 of file SDL_malloc.c.

◆ MCHUNK_SIZE

#define MCHUNK_SIZE   (sizeof(mchunk))

Definition at line 1733 of file SDL_malloc.c.

◆ mem2chunk

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

Definition at line 1752 of file SDL_malloc.c.

◆ memcpy

#define memcpy   SDL_memcpy

Definition at line 630 of file SDL_malloc.c.

◆ memset

#define memset   SDL_memset

Definition at line 627 of file SDL_malloc.c.

◆ MFAIL

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

Definition at line 1339 of file SDL_malloc.c.

◆ MIN_CHUNK_SIZE

#define MIN_CHUNK_SIZE   ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)

Definition at line 1747 of file SDL_malloc.c.

◆ MIN_LARGE_SIZE

#define MIN_LARGE_SIZE   (SIZE_T_ONE << TREEBIN_SHIFT)

Definition at line 2094 of file SDL_malloc.c.

◆ MIN_REQUEST

#define MIN_REQUEST   (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)

Definition at line 1758 of file SDL_malloc.c.

◆ MIN_SMALL_INDEX

#define MIN_SMALL_INDEX   (small_index(MIN_CHUNK_SIZE))

Definition at line 2322 of file SDL_malloc.c.

◆ minsize_for_tree_index

#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)))

Definition at line 2373 of file SDL_malloc.c.

◆ MLOCK_T

#define MLOCK_T   long

Definition at line 1525 of file SDL_malloc.c.

◆ MMAP_CHUNK_OVERHEAD

#define MMAP_CHUNK_OVERHEAD   (TWO_SIZE_T_SIZES)

Definition at line 1742 of file SDL_malloc.c.

◆ MMAP_CLEARS

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

Definition at line 502 of file SDL_malloc.c.

◆ MMAP_FOOT_PAD

#define MMAP_FOOT_PAD   (FOUR_SIZE_T_SIZES)

Definition at line 1744 of file SDL_malloc.c.

◆ MORECORE_CONTIGUOUS

#define MORECORE_CONTIGUOUS   0

Definition at line 583 of file SDL_malloc.c.

◆ MSPACES

#define MSPACES   0

Definition at line 535 of file SDL_malloc.c.

◆ next_chunk

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

Definition at line 1799 of file SDL_malloc.c.

◆ next_pinuse

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

Definition at line 1803 of file SDL_malloc.c.

◆ NO_MALLINFO

#define NO_MALLINFO   0

Definition at line 620 of file SDL_malloc.c.

◆ NSMALLBINS

#define NSMALLBINS   (32U)

Definition at line 2089 of file SDL_malloc.c.

◆ NTREEBINS

#define NTREEBINS   (32U)

Definition at line 2090 of file SDL_malloc.c.

◆ ok_address

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

Definition at line 2461 of file SDL_malloc.c.

◆ ok_cinuse

#define ok_cinuse (   p)    cinuse(p)

Definition at line 2465 of file SDL_malloc.c.

◆ ok_magic

#define ok_magic (   M)    (1)

Definition at line 2480 of file SDL_malloc.c.

◆ ok_next

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

Definition at line 2463 of file SDL_malloc.c.

◆ ok_pinuse

#define ok_pinuse (   p)    pinuse(p)

Definition at line 2467 of file SDL_malloc.c.

◆ ONLY_MSPACES

#define ONLY_MSPACES   0

Definition at line 529 of file SDL_malloc.c.

◆ overhead_for

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

Definition at line 1821 of file SDL_malloc.c.

◆ pad_request

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

Definition at line 1761 of file SDL_malloc.c.

◆ page_align

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

Definition at line 2169 of file SDL_malloc.c.

◆ pinuse

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

Definition at line 1788 of file SDL_malloc.c.

◆ PINUSE_BIT

#define PINUSE_BIT   (SIZE_T_ONE)

Definition at line 1779 of file SDL_malloc.c.

◆ POSTACTION

#define POSTACTION (   M)    { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); }

Definition at line 2240 of file SDL_malloc.c.

◆ PREACTION

#define PREACTION (   M)    ((GLOBALLY_INITIALIZE() || use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0)

Definition at line 2239 of file SDL_malloc.c.

◆ prev_chunk

#define prev_chunk (   p)    ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) ))

Definition at line 1800 of file SDL_malloc.c.

◆ PROCEED_ON_ERROR

#define PROCEED_ON_ERROR   0

Definition at line 551 of file SDL_malloc.c.

◆ real_calloc

#define real_calloc   dlcalloc

Definition at line 5313 of file SDL_malloc.c.

◆ real_free

#define real_free   dlfree

Definition at line 5315 of file SDL_malloc.c.

◆ real_malloc

#define real_malloc   dlmalloc

Definition at line 5312 of file SDL_malloc.c.

◆ real_realloc

#define real_realloc   dlrealloc

Definition at line 5314 of file SDL_malloc.c.

◆ RELEASE_LOCK

#define RELEASE_LOCK (   l)    win32_release_lock(l)

Definition at line 1549 of file SDL_malloc.c.

◆ RELEASE_MAGIC_INIT_LOCK

#define RELEASE_MAGIC_INIT_LOCK ( )    RELEASE_LOCK(&magic_init_mutex);

Definition at line 1572 of file SDL_malloc.c.

◆ RELEASE_MORECORE_LOCK

#define RELEASE_MORECORE_LOCK ( )

Definition at line 1567 of file SDL_malloc.c.

◆ replace_dv

#define replace_dv (   M,
  P,
 
)
Value:
{\
size_t DVS = M->dvsize;\
if (DVS != 0) {\
mchunkptr DV = M->dv;\
assert(is_small(DVS));\
insert_small_chunk(M, DV, DVS);\
}\
M->dvsize = S;\
M->dv = P;\
}

Definition at line 3090 of file SDL_malloc.c.

◆ request2size

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

Definition at line 1765 of file SDL_malloc.c.

◆ RTCHECK

#define RTCHECK (   e)    (e)

Definition at line 2489 of file SDL_malloc.c.

◆ same_or_left_bits

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

Definition at line 2428 of file SDL_malloc.c.

◆ segment_holds

#define segment_holds (   S,
 
)    ((char*)(A) >= S->base && (char*)(A) < S->base + S->size)

Definition at line 2182 of file SDL_malloc.c.

◆ set_foot

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

Definition at line 1807 of file SDL_malloc.c.

◆ set_free_with_pinuse

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

Definition at line 1814 of file SDL_malloc.c.

◆ set_inuse

#define set_inuse (   M,
  p,
  s 
)
Value:
((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\
((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)

Definition at line 2502 of file SDL_malloc.c.

◆ set_inuse_and_pinuse

#define set_inuse_and_pinuse (   M,
  p,
  s 
)
Value:
((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)

Definition at line 2507 of file SDL_malloc.c.

◆ set_lock

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

Definition at line 2163 of file SDL_malloc.c.

◆ set_size_and_pinuse_of_free_chunk

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

Definition at line 1810 of file SDL_malloc.c.

◆ set_size_and_pinuse_of_inuse_chunk

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

Definition at line 2512 of file SDL_malloc.c.

◆ should_trim

#define should_trim (   M,
  s 
)    ((s) > (M)->trim_check)

Definition at line 2212 of file SDL_malloc.c.

◆ SIX_SIZE_T_SIZES

#define SIX_SIZE_T_SIZES   (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES)

Definition at line 1315 of file SDL_malloc.c.

◆ SIZE_T_BITSIZE

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

Definition at line 1306 of file SDL_malloc.c.

◆ SIZE_T_ONE

#define SIZE_T_ONE   ((size_t)1)

Definition at line 1311 of file SDL_malloc.c.

◆ SIZE_T_SIZE

#define SIZE_T_SIZE   (sizeof(size_t))

Definition at line 1305 of file SDL_malloc.c.

◆ SIZE_T_TWO

#define SIZE_T_TWO   ((size_t)2)

Definition at line 1312 of file SDL_malloc.c.

◆ SIZE_T_ZERO

#define SIZE_T_ZERO   ((size_t)0)

Definition at line 1310 of file SDL_malloc.c.

◆ small_index

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

Definition at line 2320 of file SDL_malloc.c.

◆ small_index2size

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

Definition at line 2321 of file SDL_malloc.c.

◆ smallbin_at

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

Definition at line 2325 of file SDL_malloc.c.

◆ SMALLBIN_SHIFT

#define SMALLBIN_SHIFT   (3U)

Definition at line 2091 of file SDL_malloc.c.

◆ SMALLBIN_WIDTH

#define SMALLBIN_WIDTH   (SIZE_T_ONE << SMALLBIN_SHIFT)

Definition at line 2092 of file SDL_malloc.c.

◆ smallmap_is_marked

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

Definition at line 2386 of file SDL_malloc.c.

◆ TOP_FOOT_SIZE

#define TOP_FOOT_SIZE   (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)

Definition at line 2222 of file SDL_malloc.c.

◆ treebin_at

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

Definition at line 2326 of file SDL_malloc.c.

◆ TREEBIN_SHIFT

#define TREEBIN_SHIFT   (8U)

Definition at line 2093 of file SDL_malloc.c.

◆ treemap_is_marked

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

Definition at line 2390 of file SDL_malloc.c.

◆ TWO_SIZE_T_SIZES

#define TWO_SIZE_T_SIZES   (SIZE_T_SIZE<<1)

Definition at line 1313 of file SDL_malloc.c.

◆ unlink_chunk

#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); }

Definition at line 3249 of file SDL_malloc.c.

◆ unlink_first_small_chunk

#define unlink_first_small_chunk (   M,
  B,
  P,
  I 
)
Value:
{\
mchunkptr F = P->fd;\
assert(P != B);\
assert(P != F);\
assert(chunksize(P) == small_index2size(I));\
if (B == F)\
clear_smallmap(M, I);\
else if (RTCHECK(ok_address(M, F))) {\
B->fd = F;\
F->bk = B;\
}\
else {\
CORRUPTION_ERROR_ACTION(M);\
}\
}

Definition at line 3072 of file SDL_malloc.c.

◆ unlink_large_chunk

#define unlink_large_chunk (   M,
 
)

Definition at line 3172 of file SDL_malloc.c.

◆ unlink_small_chunk

#define unlink_small_chunk (   M,
  P,
 
)
Value:
{\
mchunkptr F = P->fd;\
mchunkptr B = P->bk;\
bindex_t I = small_index(S);\
assert(P != B);\
assert(P != F);\
assert(chunksize(P) == small_index2size(I));\
if (F == B)\
clear_smallmap(M, I);\
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 {\
CORRUPTION_ERROR_ACTION(M);\
}\
}

Definition at line 3052 of file SDL_malloc.c.

◆ USAGE_ERROR_ACTION

#define USAGE_ERROR_ACTION (   m,
  p 
)    ABORT

Definition at line 2279 of file SDL_malloc.c.

◆ USE_BUILTIN_FFS

#define USE_BUILTIN_FFS   0

Definition at line 614 of file SDL_malloc.c.

◆ USE_DEV_RANDOM

#define USE_DEV_RANDOM   0

Definition at line 617 of file SDL_malloc.c.

◆ USE_DL_PREFIX

#define USE_DL_PREFIX

Definition at line 41 of file SDL_malloc.c.

◆ use_lock

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

Definition at line 2152 of file SDL_malloc.c.

◆ USE_LOCK_BIT

#define USE_LOCK_BIT   (2U)

Definition at line 1556 of file SDL_malloc.c.

◆ USE_LOCKS

#define USE_LOCKS   1

Definition at line 40 of file SDL_malloc.c.

◆ use_mmap

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

Definition at line 2156 of file SDL_malloc.c.

◆ USE_MMAP_BIT

#define USE_MMAP_BIT   (SIZE_T_ONE)

Definition at line 1351 of file SDL_malloc.c.

◆ use_noncontiguous

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

Definition at line 2160 of file SDL_malloc.c.

◆ USE_NONCONTIGUOUS_BIT

#define USE_NONCONTIGUOUS_BIT   (4U)

Definition at line 1471 of file SDL_malloc.c.

◆ WIN32

#define WIN32   1

Definition at line 485 of file SDL_malloc.c.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 489 of file SDL_malloc.c.

Typedef Documentation

◆ bindex_t

typedef size_t bindex_t

Definition at line 1727 of file SDL_malloc.c.

◆ binmap_t

typedef unsigned int binmap_t

Definition at line 1728 of file SDL_malloc.c.

◆ flag_t

typedef unsigned int flag_t

Definition at line 1729 of file SDL_malloc.c.

Function Documentation

◆ add_segment()

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

Definition at line 3446 of file SDL_malloc.c.

3447 {
3448  /* Determine locations and sizes of segment, fenceposts, old top */
3449  char *old_top = (char *) m->top;
3450  msegmentptr oldsp = segment_holding(m, old_top);
3451  char *old_end = oldsp->base + oldsp->size;
3452  size_t ssize = pad_request(sizeof(struct malloc_segment));
3453  char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
3454  size_t offset = align_offset(chunk2mem(rawsp));
3455  char *asp = rawsp + offset;
3456  char *csp = (asp < (old_top + MIN_CHUNK_SIZE)) ? old_top : asp;
3457  mchunkptr sp = (mchunkptr) csp;
3458  msegmentptr ss = (msegmentptr) (chunk2mem(sp));
3459  mchunkptr tnext = chunk_plus_offset(sp, ssize);
3460  mchunkptr p = tnext;
3461  int nfences = 0;
3462 
3463  /* reset top to new space */
3464  init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
3465 
3466  /* Set up segment record */
3467  assert(is_aligned(ss));
3469  *ss = m->seg; /* Push current record */
3470  m->seg.base = tbase;
3471  m->seg.size = tsize;
3472  m->seg.sflags = mmapped;
3473  m->seg.next = ss;
3474 
3475  /* Insert trailing fenceposts */
3476  for (;;) {
3477  mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);
3478  p->head = FENCEPOST_HEAD;
3479  ++nfences;
3480  if ((char *) (&(nextp->head)) < old_end)
3481  p = nextp;
3482  else
3483  break;
3484  }
3485  assert(nfences >= 2);
3486 
3487  /* Insert the rest of old top into a bin as an ordinary free chunk */
3488  if (csp != old_top) {
3489  mchunkptr q = (mchunkptr) old_top;
3490  size_t psize = csp - old_top;
3491  mchunkptr tn = chunk_plus_offset(q, psize);
3492  set_free_with_pinuse(q, psize, tn);
3493  insert_chunk(m, q, psize);
3494  }
3495 
3496  check_top_chunk(m, m->top);
3497 }

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().

◆ change_mparam()

static int change_mparam ( int  param_number,
int  value 
)
static

Definition at line 2628 of file SDL_malloc.c.

2629 {
2630  size_t val = (size_t) value;
2631  init_mparams();
2632  switch (param_number) {
2633  case M_TRIM_THRESHOLD:
2635  return 1;
2636  case M_GRANULARITY:
2637  if (val >= mparams.page_size && ((val & (val - 1)) == 0)) {
2639  return 1;
2640  } else
2641  return 0;
2642  case M_MMAP_THRESHOLD:
2644  return 1;
2645  default:
2646  return 0;
2647  }
2648 }

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

Referenced by dlmallopt().

◆ dlcalloc()

void * dlcalloc ( size_t  n_elements,
size_t  elem_size 
)

Definition at line 4444 of file SDL_malloc.c.

4445 {
4446  void *mem;
4447  size_t req = 0;
4448  if (n_elements != 0) {
4449  req = n_elements * elem_size;
4450  if (((n_elements | elem_size) & ~(size_t) 0xffff) &&
4451  (req / n_elements != elem_size))
4452  req = MAX_SIZE_T; /* force downstream failure on overflow */
4453  }
4454  mem = dlmalloc(req);
4455  if (mem != 0 && calloc_must_clear(mem2chunk(mem)))
4456  memset(mem, 0, req);
4457  return mem;
4458 }

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

◆ dlfree()

void dlfree ( void mem)

Definition at line 4347 of file SDL_malloc.c.

4348 {
4349  /*
4350  Consolidate freed chunks with preceeding or succeeding bordering
4351  free chunks, if they exist, and then place in a bin. Intermixed
4352  with special cases for top, dv, mmapped chunks, and usage errors.
4353  */
4354 
4355  if (mem != 0) {
4356  mchunkptr p = mem2chunk(mem);
4357 #if FOOTERS
4358  mstate fm = get_mstate_for(p);
4359  if (!ok_magic(fm)) {
4361  return;
4362  }
4363 #else /* FOOTERS */
4364 #define fm gm
4365 #endif /* FOOTERS */
4366  if (!PREACTION(fm)) {
4368  if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) {
4369  size_t psize = chunksize(p);
4370  mchunkptr next = chunk_plus_offset(p, psize);
4371  if (!pinuse(p)) {
4372  size_t prevsize = p->prev_foot;
4373  if ((prevsize & IS_MMAPPED_BIT) != 0) {
4374  prevsize &= ~IS_MMAPPED_BIT;
4375  psize += prevsize + MMAP_FOOT_PAD;
4376  if (CALL_MUNMAP((char *) p - prevsize, psize) == 0)
4377  fm->footprint -= psize;
4378  goto postaction;
4379  } else {
4380  mchunkptr prev = chunk_minus_offset(p, prevsize);
4381  psize += prevsize;
4382  p = prev;
4383  if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */
4384  if (p != fm->dv) {
4385  unlink_chunk(fm, p, prevsize);
4386  } else if ((next->head & INUSE_BITS) ==
4387  INUSE_BITS) {
4388  fm->dvsize = psize;
4389  set_free_with_pinuse(p, psize, next);
4390  goto postaction;
4391  }
4392  } else
4393  goto erroraction;
4394  }
4395  }
4396 
4397  if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) {
4398  if (!cinuse(next)) { /* consolidate forward */
4399  if (next == fm->top) {
4400  size_t tsize = fm->topsize += psize;
4401  fm->top = p;
4402  p->head = tsize | PINUSE_BIT;
4403  if (p == fm->dv) {
4404  fm->dv = 0;
4405  fm->dvsize = 0;
4406  }
4407  if (should_trim(fm, tsize))
4408  sys_trim(fm, 0);
4409  goto postaction;
4410  } else if (next == fm->dv) {
4411  size_t dsize = fm->dvsize += psize;
4412  fm->dv = p;
4414  goto postaction;
4415  } else {
4416  size_t nsize = chunksize(next);
4417  psize += nsize;
4418  unlink_chunk(fm, next, nsize);
4420  if (p == fm->dv) {
4421  fm->dvsize = psize;
4422  goto postaction;
4423  }
4424  }
4425  } else
4426  set_free_with_pinuse(p, psize, next);
4427  insert_chunk(fm, p, psize);
4428  check_free_chunk(fm, p);
4429  goto postaction;
4430  }
4431  }
4432  erroraction:
4434  postaction:
4435  POSTACTION(fm);
4436  }
4437  }
4438 #if !FOOTERS
4439 #undef fm
4440 #endif /* FOOTERS */
4441 }

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.

Referenced by dlrealloc().

◆ dlindependent_calloc() [1/2]

void** dlindependent_calloc ( size_t  n_elements,
size_t  elem_size,
void chunks[] 
)

Definition at line 4492 of file SDL_malloc.c.

4493 {
4494  size_t sz = elem_size; /* serves as 1-element array */
4495  return ialloc(gm, n_elements, &sz, 3, chunks);
4496 }

References gm, and ialloc().

◆ dlindependent_calloc() [2/2]

void** dlindependent_calloc ( size_t  ,
size_t  ,
void **   
)

◆ dlindependent_comalloc() [1/2]

void** dlindependent_comalloc ( size_t  n_elements,
size_t  sizes[],
void chunks[] 
)

Definition at line 4499 of file SDL_malloc.c.

4500 {
4501  return ialloc(gm, n_elements, sizes, 0, chunks);
4502 }

References gm, and ialloc().

◆ dlindependent_comalloc() [2/2]

void** dlindependent_comalloc ( size_t  ,
size_t ,
void **   
)

◆ dlmallinfo()

struct mallinfo dlmallinfo ( void  )

Definition at line 4548 of file SDL_malloc.c.

4549 {
4550  return internal_mallinfo(gm);
4551 }

References gm, and internal_mallinfo().

◆ dlmalloc()

void * dlmalloc ( size_t  bytes)

Definition at line 4213 of file SDL_malloc.c.

4214 {
4215  /*
4216  Basic algorithm:
4217  If a small request (< 256 bytes minus per-chunk overhead):
4218  1. If one exists, use a remainderless chunk in associated smallbin.
4219  (Remainderless means that there are too few excess bytes to
4220  represent as a chunk.)
4221  2. If it is big enough, use the dv chunk, which is normally the
4222  chunk adjacent to the one used for the most recent small request.
4223  3. If one exists, split the smallest available chunk in a bin,
4224  saving remainder in dv.
4225  4. If it is big enough, use the top chunk.
4226  5. If available, get memory from system and use it
4227  Otherwise, for a large request:
4228  1. Find the smallest available binned chunk that fits, and use it
4229  if it is better fitting than dv chunk, splitting if necessary.
4230  2. If better fitting than any binned chunk, use the dv chunk.
4231  3. If it is big enough, use the top chunk.
4232  4. If request size >= mmap threshold, try to directly mmap this chunk.
4233  5. If available, get memory from system and use it
4234 
4235  The ugly goto's here ensure that postaction occurs along all paths.
4236  */
4237 
4238  if (!PREACTION(gm)) {
4239  void *mem;
4240  size_t nb;
4241  if (bytes <= MAX_SMALL_REQUEST) {
4242  bindex_t idx;
4243  binmap_t smallbits;
4244  nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes);
4245  idx = small_index(nb);
4246  smallbits = gm->smallmap >> idx;
4247 
4248  if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */
4249  mchunkptr b, p;
4250  idx += ~smallbits & 1; /* Uses next bin if idx empty */
4251  b = smallbin_at(gm, idx);
4252  p = b->fd;
4253  assert(chunksize(p) == small_index2size(idx));
4254  unlink_first_small_chunk(gm, b, p, idx);
4256  mem = chunk2mem(p);
4257  check_malloced_chunk(gm, mem, nb);
4258  goto postaction;
4259  }
4260 
4261  else if (nb > gm->dvsize) {
4262  if (smallbits != 0) { /* Use chunk in next nonempty smallbin */
4263  mchunkptr b, p, r;
4264  size_t rsize;
4265  bindex_t i;
4266  binmap_t leftbits =
4267  (smallbits << idx) & left_bits(idx2bit(idx));
4268  binmap_t leastbit = least_bit(leftbits);
4269  compute_bit2idx(leastbit, i);
4270  b = smallbin_at(gm, i);
4271  p = b->fd;
4274  rsize = small_index2size(i) - nb;
4275  /* Fit here cannot be remainderless if 4byte sizes */
4276  if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE)
4278  else {
4280  r = chunk_plus_offset(p, nb);
4282  replace_dv(gm, r, rsize);
4283  }
4284  mem = chunk2mem(p);
4285  check_malloced_chunk(gm, mem, nb);
4286  goto postaction;
4287  }
4288 
4289  else if (gm->treemap != 0
4290  && (mem = tmalloc_small(gm, nb)) != 0) {
4291  check_malloced_chunk(gm, mem, nb);
4292  goto postaction;
4293  }
4294  }
4295  } else if (bytes >= MAX_REQUEST)
4296  nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */
4297  else {
4298  nb = pad_request(bytes);
4299  if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) {
4300  check_malloced_chunk(gm, mem, nb);
4301  goto postaction;
4302  }
4303  }
4304 
4305  if (nb <= gm->dvsize) {
4306  size_t rsize = gm->dvsize - nb;
4307  mchunkptr p = gm->dv;
4308  if (rsize >= MIN_CHUNK_SIZE) { /* split dv */
4309  mchunkptr r = gm->dv = chunk_plus_offset(p, nb);
4310  gm->dvsize = rsize;
4313  } else { /* exhaust dv */
4314  size_t dvs = gm->dvsize;
4315  gm->dvsize = 0;
4316  gm->dv = 0;
4317  set_inuse_and_pinuse(gm, p, dvs);
4318  }
4319  mem = chunk2mem(p);
4320  check_malloced_chunk(gm, mem, nb);
4321  goto postaction;
4322  }
4323 
4324  else if (nb < gm->topsize) { /* Split top */
4325  size_t rsize = gm->topsize -= nb;
4326  mchunkptr p = gm->top;
4327  mchunkptr r = gm->top = chunk_plus_offset(p, nb);
4328  r->head = rsize | PINUSE_BIT;
4330  mem = chunk2mem(p);
4331  check_top_chunk(gm, gm->top);
4332  check_malloced_chunk(gm, mem, nb);
4333  goto postaction;
4334  }
4335 
4336  mem = sys_alloc(gm, nb);
4337 
4338  postaction:
4339  POSTACTION(gm);
4340  return mem;
4341  }
4342 
4343  return 0;
4344 }

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.

Referenced by dlcalloc(), and dlrealloc().

◆ dlmalloc_footprint()

size_t dlmalloc_footprint ( void  )

Definition at line 4535 of file SDL_malloc.c.

4536 {
4537  return gm->footprint;
4538 }

References gm.

◆ dlmalloc_max_footprint()

size_t dlmalloc_max_footprint ( void  )

Definition at line 4541 of file SDL_malloc.c.

4542 {
4543  return gm->max_footprint;
4544 }

References gm.

◆ dlmalloc_stats()

void dlmalloc_stats ( void  )

Definition at line 4555 of file SDL_malloc.c.

4556 {
4558 }

References gm, and internal_malloc_stats().

◆ dlmalloc_trim()

int dlmalloc_trim ( size_t  pad)

Definition at line 4524 of file SDL_malloc.c.

4525 {
4526  int result = 0;
4527  if (!PREACTION(gm)) {
4528  result = sys_trim(gm, pad);
4529  POSTACTION(gm);
4530  }
4531  return result;
4532 }

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

◆ dlmalloc_usable_size()

size_t dlmalloc_usable_size ( void mem)

Definition at line 4561 of file SDL_malloc.c.

4562 {
4563  if (mem != 0) {
4564  mchunkptr p = mem2chunk(mem);
4565  if (cinuse(p))
4566  return chunksize(p) - overhead_for(p);
4567  }
4568  return 0;
4569 }

References chunksize, cinuse, mem2chunk, and overhead_for.

◆ dlmallopt()

int dlmallopt ( int  param_number,
int  value 
)

Definition at line 4572 of file SDL_malloc.c.

4573 {
4574  return change_mparam(param_number, value);
4575 }

References change_mparam().

◆ dlmemalign()

void * dlmemalign ( size_t  alignment,
size_t  bytes 
)

Definition at line 4486 of file SDL_malloc.c.

4487 {
4488  return internal_memalign(gm, alignment, bytes);
4489 }

References gm, and internal_memalign().

Referenced by dlpvalloc(), and dlvalloc().

◆ dlpvalloc()

void * dlpvalloc ( size_t  bytes)

Definition at line 4514 of file SDL_malloc.c.

4515 {
4516  size_t pagesz;
4517  init_mparams();
4518  pagesz = mparams.page_size;
4519  return dlmemalign(pagesz,
4520  (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE));
4521 }

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

◆ dlrealloc()

void * dlrealloc ( void oldmem,
size_t  bytes 
)

Definition at line 4461 of file SDL_malloc.c.

4462 {
4463  if (oldmem == 0)
4464  return dlmalloc(bytes);
4465 #ifdef REALLOC_ZERO_BYTES_FREES
4466  if (bytes == 0) {
4467  dlfree(oldmem);
4468  return 0;
4469  }
4470 #endif /* REALLOC_ZERO_BYTES_FREES */
4471  else {
4472 #if ! FOOTERS
4473  mstate m = gm;
4474 #else /* FOOTERS */
4475  mstate m = get_mstate_for(mem2chunk(oldmem));
4476  if (!ok_magic(m)) {
4477  USAGE_ERROR_ACTION(m, oldmem);
4478  return 0;
4479  }
4480 #endif /* FOOTERS */
4481  return internal_realloc(m, oldmem, bytes);
4482  }
4483 }

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

◆ dlvalloc()

void * dlvalloc ( size_t  bytes)

Definition at line 4505 of file SDL_malloc.c.

4506 {
4507  size_t pagesz;
4508  init_mparams();
4509  pagesz = mparams.page_size;
4510  return dlmemalign(pagesz, bytes);
4511 }

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

◆ has_segment_link()

static int has_segment_link ( mstate  m,
msegmentptr  ss 
)
static

Definition at line 2200 of file SDL_malloc.c.

2201 {
2202  msegmentptr sp = &m->seg;
2203  for (;;) {
2204  if ((char *) sp >= ss->base && (char *) sp < ss->base + ss->size)
2205  return 1;
2206  if ((sp = sp->next) == 0)
2207  return 0;
2208  }
2209 }

Referenced by sys_trim().

◆ ialloc()

static void** ialloc ( mstate  m,
size_t  n_elements,
size_t sizes,
int  opts,
void chunks[] 
)
static

Definition at line 4087 of file SDL_malloc.c.

4088 {
4089  /*
4090  This provides common support for independent_X routines, handling
4091  all of the combinations that can result.
4092 
4093  The opts arg has:
4094  bit 0 set if all elements are same size (using sizes[0])
4095  bit 1 set if elements should be zeroed
4096  */
4097 
4098  size_t element_size; /* chunksize of each element, if all same */
4099  size_t contents_size; /* total size of elements */
4100  size_t array_size; /* request size of pointer array */
4101  void *mem; /* malloced aggregate space */
4102  mchunkptr p; /* corresponding chunk */
4103  size_t remainder_size; /* remaining bytes while splitting */
4104  void **marray; /* either "chunks" or malloced ptr array */
4105  mchunkptr array_chunk; /* chunk for malloced ptr array */
4106  flag_t was_enabled; /* to disable mmap */
4107  size_t size;
4108  size_t i;
4109 
4110  /* compute array length, if needed */
4111  if (chunks != 0) {
4112  if (n_elements == 0)
4113  return chunks; /* nothing to do */
4114  marray = chunks;
4115  array_size = 0;
4116  } else {
4117  /* if empty req, must still return chunk representing empty array */
4118  if (n_elements == 0)
4119  return (void **) internal_malloc(m, 0);
4120  marray = 0;
4121  array_size = request2size(n_elements * (sizeof(void *)));
4122  }
4123 
4124  /* compute total element size */
4125  if (opts & 0x1) { /* all-same-size */
4126  element_size = request2size(*sizes);
4127  contents_size = n_elements * element_size;
4128  } else { /* add up all the sizes */
4129  element_size = 0;
4130  contents_size = 0;
4131  for (i = 0; i != n_elements; ++i)
4132  contents_size += request2size(sizes[i]);
4133  }
4134 
4135  size = contents_size + array_size;
4136 
4137  /*
4138  Allocate the aggregate chunk. First disable direct-mmapping so
4139  malloc won't use it, since we would not be able to later
4140  free/realloc space internal to a segregated mmap region.
4141  */
4142  was_enabled = use_mmap(m);
4143  disable_mmap(m);
4145  if (was_enabled)
4146  enable_mmap(m);
4147  if (mem == 0)
4148  return 0;
4149 
4150  if (PREACTION(m))
4151  return 0;
4152  p = mem2chunk(mem);
4153  remainder_size = chunksize(p);
4154 
4155  assert(!is_mmapped(p));
4156 
4157  if (opts & 0x2) { /* optionally clear the elements */
4158  memset((size_t *) mem, 0, remainder_size - SIZE_T_SIZE - array_size);
4159  }
4160 
4161  /* If not provided, allocate the pointer array as final part of chunk */
4162  if (marray == 0) {
4163  size_t array_chunk_size;
4164  array_chunk = chunk_plus_offset(p, contents_size);
4165  array_chunk_size = remainder_size - contents_size;
4166  marray = (void **) (chunk2mem(array_chunk));
4167  set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size);
4168  remainder_size = contents_size;
4169  }
4170 
4171  /* split out elements */
4172  for (i = 0;; ++i) {
4173  marray[i] = chunk2mem(p);
4174  if (i != n_elements - 1) {
4175  if (element_size != 0)
4176  size = element_size;
4177  else
4178  size = request2size(sizes[i]);
4179  remainder_size -= size;
4181  p = chunk_plus_offset(p, size);
4182  } else { /* the final element absorbs any overallocation slop */
4183  set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size);
4184  break;
4185  }
4186  }
4187 
4188 #if DEBUG
4189  if (marray != chunks) {
4190  /* final element must have exactly exhausted chunk */
4191  if (element_size != 0) {
4192  assert(remainder_size == element_size);
4193  } else {
4194  assert(remainder_size == request2size(sizes[i]));
4195  }
4196  check_inuse_chunk(m, mem2chunk(marray));
4197  }
4198  for (i = 0; i != n_elements; ++i)
4199  check_inuse_chunk(m, mem2chunk(marray[i]));
4200 
4201 #endif /* DEBUG */
4202 
4203  POSTACTION(m);
4204  return marray;
4205 }

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

Referenced by dlindependent_calloc(), and dlindependent_comalloc().

◆ init_bins()

static void init_bins ( mstate  m)
static

Definition at line 3371 of file SDL_malloc.c.

3372 {
3373  /* Establish circular links for smallbins */
3374  bindex_t i;
3375  for (i = 0; i < NSMALLBINS; ++i) {
3376  sbinptr bin = smallbin_at(m, i);
3377  bin->fd = bin->bk = bin;
3378  }
3379 }

References i, NSMALLBINS, and smallbin_at.

Referenced by sys_alloc().

◆ init_mparams()

static int init_mparams ( void  )
static

Definition at line 2545 of file SDL_malloc.c.

2546 {
2547  if (mparams.page_size == 0) {
2548  size_t s;
2549 
2552 #if MORECORE_CONTIGUOUS
2554 #else /* MORECORE_CONTIGUOUS */
2557 #endif /* MORECORE_CONTIGUOUS */
2558 
2559 #if (FOOTERS && !INSECURE)
2560  {
2561 #if USE_DEV_RANDOM
2562  int fd;
2563  unsigned char buf[sizeof(size_t)];
2564  /* Try to use /dev/urandom, else fall back on using time */
2565  if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 &&
2566  read(fd, buf, sizeof(buf)) == sizeof(buf)) {
2567  s = *((size_t *) buf);
2568  close(fd);
2569  } else
2570 #endif /* USE_DEV_RANDOM */
2571  s = (size_t) (time(0) ^ (size_t) 0x55555555U);
2572 
2573  s |= (size_t) 8U; /* ensure nonzero */
2574  s &= ~(size_t) 7U; /* improve chances of fault for bad values */
2575 
2576  }
2577 #else /* (FOOTERS && !INSECURE) */
2578  s = (size_t) 0x58585858U;
2579 #endif /* (FOOTERS && !INSECURE) */
2581  if (mparams.magic == 0) {
2582  mparams.magic = s;
2583  /* Set up lock for main malloc area */
2584  INITIAL_LOCK(&gm->mutex);
2585  gm->mflags = mparams.default_mflags;
2586  }
2588 
2589 #if !defined(WIN32) && !defined(__OS2__)
2590  mparams.page_size = malloc_getpagesize;
2593 #elif defined (__OS2__)
2594  /* if low-memory is used, os2munmap() would break
2595  if it were anything other than 64k */
2596  mparams.page_size = 4096u;
2597  mparams.granularity = 65536u;
2598 #else /* WIN32 */
2599  {
2600  SYSTEM_INFO system_info;
2601  GetSystemInfo(&system_info);
2602  mparams.page_size = system_info.dwPageSize;
2603  mparams.granularity = system_info.dwAllocationGranularity;
2604  }
2605 #endif /* WIN32 */
2606 
2607  /* Sanity-check configuration:
2608  size_t must be unsigned and as wide as pointer type.
2609  ints must be at least 4 bytes.
2610  alignment must be at least 8.
2611  Alignment, min chunk size, and page size must all be powers of 2.
2612  */
2613  if ((sizeof(size_t) != sizeof(char *)) ||
2614  (MAX_SIZE_T < MIN_CHUNK_SIZE) ||
2615  (sizeof(int) < 4) ||
2616  (MALLOC_ALIGNMENT < (size_t) 8U) ||
2617  ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT - SIZE_T_ONE)) != 0) ||
2618  ((MCHUNK_SIZE & (MCHUNK_SIZE - SIZE_T_ONE)) != 0) ||
2620  || ((mparams.page_size & (mparams.page_size - SIZE_T_ONE)) != 0))
2621  ABORT;
2622  }
2623  return 0;
2624 }

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

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

◆ init_top()

static void init_top ( mstate  m,
mchunkptr  p,
size_t  psize 
)
static

Definition at line 3354 of file SDL_malloc.c.

3355 {
3356  /* Ensure alignment */
3357  size_t offset = align_offset(chunk2mem(p));
3358  p = (mchunkptr) ((char *) p + offset);
3359  psize -= offset;
3360 
3361  m->top = p;
3362  m->topsize = psize;
3363  p->head = psize | PINUSE_BIT;
3364  /* set size of fake trailing chunk holding overhead space only once */
3365  chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
3366  m->trim_check = mparams.trim_threshold; /* reset on each update */
3367 }

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

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

◆ internal_mallinfo()

static struct mallinfo internal_mallinfo ( mstate  m)
static

Definition at line 2943 of file SDL_malloc.c.

2944 {
2945  struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2946  if (!PREACTION(m)) {
2948  if (is_initialized(m)) {
2949  size_t nfree = SIZE_T_ONE; /* top always free */
2950  size_t mfree = m->topsize + TOP_FOOT_SIZE;
2951  size_t sum = mfree;
2952  msegmentptr s = &m->seg;
2953  while (s != 0) {
2954  mchunkptr q = align_as_chunk(s->base);
2955  while (segment_holds(s, q) &&
2956  q != m->top && q->head != FENCEPOST_HEAD) {
2957  size_t sz = chunksize(q);
2958  sum += sz;
2959  if (!cinuse(q)) {
2960  mfree += sz;
2961  ++nfree;
2962  }
2963  q = next_chunk(q);
2964  }
2965  s = s->next;
2966  }
2967 
2968  nm.arena = sum;
2969  nm.ordblks = nfree;
2970  nm.hblkhd = m->footprint - sum;
2971  nm.usmblks = m->max_footprint;
2972  nm.uordblks = m->footprint - mfree;
2973  nm.fordblks = mfree;
2974  nm.keepcost = m->topsize;
2975  }
2976 
2977  POSTACTION(m);
2978  }
2979  return nm;
2980 }

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().

◆ internal_malloc_stats()

static void internal_malloc_stats ( mstate  m)
static

Definition at line 2984 of file SDL_malloc.c.

2985 {
2986  if (!PREACTION(m)) {
2987 #ifndef LACKS_STDIO_H
2988  size_t maxfp = 0;
2989 #endif
2990  size_t fp = 0;
2991  size_t used = 0;
2993  if (is_initialized(m)) {
2994  msegmentptr s = &m->seg;
2995 #ifndef LACKS_STDIO_H
2996  maxfp = m->max_footprint;
2997 #endif
2998  fp = m->footprint;
2999  used = fp - (m->topsize + TOP_FOOT_SIZE);
3000 
3001  while (s != 0) {
3002  mchunkptr q = align_as_chunk(s->base);
3003  while (segment_holds(s, q) &&
3004  q != m->top && q->head != FENCEPOST_HEAD) {
3005  if (!cinuse(q))
3006  used -= chunksize(q);
3007  q = next_chunk(q);
3008  }
3009  s = s->next;
3010  }
3011  }
3012 #ifndef LACKS_STDIO_H
3013  fprintf(stderr, "max system bytes = %10lu\n",
3014  (unsigned long) (maxfp));
3015  fprintf(stderr, "system bytes = %10lu\n", (unsigned long) (fp));
3016  fprintf(stderr, "in use bytes = %10lu\n", (unsigned long) (used));
3017 #endif
3018 
3019  POSTACTION(m);
3020  }
3021 }

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().

◆ internal_memalign()

static void* internal_memalign ( mstate  m,
size_t  alignment,
size_t  bytes 
)
static

Definition at line 3997 of file SDL_malloc.c.

3998 {
3999  if (alignment <= MALLOC_ALIGNMENT) /* Can just use malloc */
4000  return internal_malloc(m, bytes);
4001  if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */
4002  alignment = MIN_CHUNK_SIZE;
4003  if ((alignment & (alignment - SIZE_T_ONE)) != 0) { /* Ensure a power of 2 */
4004  size_t a = MALLOC_ALIGNMENT << 1;
4005  while (a < alignment)
4006  a <<= 1;
4007  alignment = a;
4008  }
4009 
4010  if (bytes >= MAX_REQUEST - alignment) {
4011  if (m != 0) { /* Test isn't needed but avoids compiler warning */
4013  }
4014  } else {
4015  size_t nb = request2size(bytes);
4016  size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD;
4017  char *mem = (char *) internal_malloc(m, req);
4018  if (mem != 0) {
4019  void *leader = 0;
4020  void *trailer = 0;
4021  mchunkptr p = mem2chunk(mem);
4022 
4023  if (PREACTION(m))
4024  return 0;
4025  if ((((size_t) (mem)) % alignment) != 0) { /* misaligned */
4026  /*
4027  Find an aligned spot inside chunk. Since we need to give
4028  back leading space in a chunk of at least MIN_CHUNK_SIZE, if
4029  the first calculation places us at a spot with less than
4030  MIN_CHUNK_SIZE leader, we can move to the next aligned spot.
4031  We've allocated enough total room so that this is always
4032  possible.
4033  */
4034  char *br = (char *) mem2chunk((size_t) (((size_t) (mem +
4035  alignment -
4036  SIZE_T_ONE))
4037  & -alignment));
4038  char *pos =
4039  ((size_t) (br - (char *) (p)) >=
4040  MIN_CHUNK_SIZE) ? br : br + alignment;
4041  mchunkptr newp = (mchunkptr) pos;
4042  size_t leadsize = pos - (char *) (p);
4043  size_t newsize = chunksize(p) - leadsize;
4044 
4045  if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */
4046  newp->prev_foot = p->prev_foot + leadsize;
4047  newp->head = (newsize | CINUSE_BIT);
4048  } else { /* Otherwise, give back leader, use the rest */
4049  set_inuse(m, newp, newsize);
4050  set_inuse(m, p, leadsize);
4051  leader = chunk2mem(p);
4052  }
4053  p = newp;
4054  }
4055 
4056  /* Give back spare room at the end */
4057  if (!is_mmapped(p)) {
4058  size_t size = chunksize(p);
4059  if (size > nb + MIN_CHUNK_SIZE) {
4060  size_t remainder_size = size - nb;
4061  mchunkptr remainder = chunk_plus_offset(p, nb);
4062  set_inuse(m, p, nb);
4063  set_inuse(m, remainder, remainder_size);
4064  trailer = chunk2mem(remainder);
4065  }
4066  }
4067 
4068  assert(chunksize(p) >= nb);
4069  assert((((size_t) (chunk2mem(p))) % alignment) == 0);
4070  check_inuse_chunk(m, p);
4071  POSTACTION(m);
4072  if (leader != 0) {
4073  internal_free(m, leader);
4074  }
4075  if (trailer != 0) {
4076  internal_free(m, trailer);
4077  }
4078  return chunk2mem(p);
4079  }
4080  }
4081  return 0;
4082 }

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

Referenced by dlmemalign().

◆ internal_realloc()

static void* internal_realloc ( mstate  m,
void oldmem,
size_t  bytes 
)
static

Definition at line 3927 of file SDL_malloc.c.

3928 {
3929  if (bytes >= MAX_REQUEST) {
3931  return 0;
3932  }
3933  if (!PREACTION(m)) {
3934  mchunkptr oldp = mem2chunk(oldmem);
3935  size_t oldsize = chunksize(oldp);
3936  mchunkptr next = chunk_plus_offset(oldp, oldsize);
3937  mchunkptr newp = 0;
3938  void *extra = 0;
3939 
3940  /* Try to either shrink or extend into top. Else malloc-copy-free */
3941 
3942  if (RTCHECK(ok_address(m, oldp) && ok_cinuse(oldp) &&
3943  ok_next(oldp, next) && ok_pinuse(next))) {
3944  size_t nb = request2size(bytes);
3945  if (is_mmapped(oldp))
3946  newp = mmap_resize(m, oldp, nb);
3947  else if (oldsize >= nb) { /* already big enough */
3948  size_t rsize = oldsize - nb;
3949  newp = oldp;
3950  if (rsize >= MIN_CHUNK_SIZE) {
3951  mchunkptr remainder = chunk_plus_offset(newp, nb);
3952  set_inuse(m, newp, nb);
3953  set_inuse(m, remainder, rsize);
3954  extra = chunk2mem(remainder);
3955  }
3956  } else if (next == m->top && oldsize + m->topsize > nb) {
3957  /* Expand into top */
3958  size_t newsize = oldsize + m->topsize;
3959  size_t newtopsize = newsize - nb;
3960  mchunkptr newtop = chunk_plus_offset(oldp, nb);
3961  set_inuse(m, oldp, nb);
3962  newtop->head = newtopsize | PINUSE_BIT;
3963  m->top = newtop;
3964  m->topsize = newtopsize;
3965  newp = oldp;
3966  }
3967  } else {
3968  USAGE_ERROR_ACTION(m, oldmem);
3969  POSTACTION(m);
3970  return 0;
3971  }
3972 
3973  POSTACTION(m);
3974 
3975  if (newp != 0) {
3976  if (extra != 0) {
3977  internal_free(m, extra);
3978  }
3979  check_inuse_chunk(m, newp);
3980  return chunk2mem(newp);
3981  } else {
3982  void *newmem = internal_malloc(m, bytes);
3983  if (newmem != 0) {
3984  size_t oc = oldsize - overhead_for(oldp);
3985  memcpy(newmem, oldmem, (oc < bytes) ? oc : bytes);
3986  internal_free(m, oldmem);
3987  }
3988  return newmem;
3989  }
3990  }
3991  return 0;
3992 }

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

Referenced by dlrealloc().

◆ mmap_alloc()

static void* mmap_alloc ( mstate  m,
size_t  nb 
)
static

Definition at line 3285 of file SDL_malloc.c.

3286 {
3287  size_t mmsize =
3289  if (mmsize > nb) { /* Check for wrap around 0 */
3290  char *mm = (char *) (DIRECT_MMAP(mmsize));
3291  if (mm != CMFAIL) {
3292  size_t offset = align_offset(chunk2mem(mm));
3293  size_t psize = mmsize - offset - MMAP_FOOT_PAD;
3294  mchunkptr p = (mchunkptr) (mm + offset);
3295  p->prev_foot = offset | IS_MMAPPED_BIT;
3296  (p)->head = (psize | CINUSE_BIT);
3297  mark_inuse_foot(m, p, psize);
3298  chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;
3299  chunk_plus_offset(p, psize + SIZE_T_SIZE)->head = 0;
3300 
3301  if (mm < m->least_addr)
3302  m->least_addr = mm;
3303  if ((m->footprint += mmsize) > m->max_footprint)
3304  m->max_footprint = m->footprint;
3307  return chunk2mem(p);
3308  }
3309  }
3310  return 0;
3311 }

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().

◆ mmap_resize()

static mchunkptr mmap_resize ( mstate  m,
mchunkptr  oldp,
size_t  nb 
)
static

Definition at line 3315 of file SDL_malloc.c.

3316 {
3317  size_t oldsize = chunksize(oldp);
3318  if (is_small(nb)) /* Can't shrink mmap regions below small size */
3319  return 0;
3320  /* Keep old chunk if big enough but not too big */
3321  if (oldsize >= nb + SIZE_T_SIZE &&
3322  (oldsize - nb) <= (mparams.granularity << 1))
3323  return oldp;
3324  else {
3325  size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT;
3326  size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD;
3327  size_t newmmsize = granularity_align(nb + SIX_SIZE_T_SIZES +
3329  char *cp = (char *) CALL_MREMAP((char *) oldp - offset,
3330  oldmmsize, newmmsize, 1);
3331  if (cp != CMFAIL) {
3332  mchunkptr newp = (mchunkptr) (cp + offset);
3333  size_t psize = newmmsize - offset - MMAP_FOOT_PAD;
3334  newp->head = (psize | CINUSE_BIT);
3335  mark_inuse_foot(m, newp, psize);
3336  chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;
3337  chunk_plus_offset(newp, psize + SIZE_T_SIZE)->head = 0;
3338 
3339  if (cp < m->least_addr)
3340  m->least_addr = cp;
3341  if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint)
3342  m->max_footprint = m->footprint;
3343  check_mmapped_chunk(m, newp);
3344  return newp;
3345  }
3346  }
3347  return 0;
3348 }

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().

◆ prepend_alloc()

static void* prepend_alloc ( mstate  m,
char *  newbase,
char *  oldbase,
size_t  nb 
)
static

Definition at line 3404 of file SDL_malloc.c.

3405 {
3406  mchunkptr p = align_as_chunk(newbase);
3407  mchunkptr oldfirst = align_as_chunk(oldbase);
3408  size_t psize = (char *) oldfirst - (char *) p;
3409  mchunkptr q = chunk_plus_offset(p, nb);
3410  size_t qsize = psize - nb;
3412 
3413  assert((char *) oldfirst > (char *) q);
3414  assert(pinuse(oldfirst));
3415  assert(qsize >= MIN_CHUNK_SIZE);
3416 
3417  /* consolidate remainder with first chunk of old base */
3418  if (oldfirst == m->top) {
3419  size_t tsize = m->topsize += qsize;
3420  m->top = q;
3421  q->head = tsize | PINUSE_BIT;
3422  check_top_chunk(m, q);
3423  } else if (oldfirst == m->dv) {
3424  size_t dsize = m->dvsize += qsize;
3425  m->dv = q;
3427  } else {
3428  if (!cinuse(oldfirst)) {
3429  size_t nsize = chunksize(oldfirst);
3430  unlink_chunk(m, oldfirst, nsize);
3431  oldfirst = chunk_plus_offset(oldfirst, nsize);
3432  qsize += nsize;
3433  }
3434  set_free_with_pinuse(q, qsize, oldfirst);
3435  insert_chunk(m, q, qsize);
3436  check_free_chunk(m, q);
3437  }
3438 
3440  return chunk2mem(p);
3441 }

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().

◆ release_unused_segments()

static size_t release_unused_segments ( mstate  m)
static

Definition at line 3703 of file SDL_malloc.c.

3704 {
3705  size_t released = 0;
3706  msegmentptr pred = &m->seg;
3707  msegmentptr sp = pred->next;
3708  while (sp != 0) {
3709  char *base = sp->base;
3710  size_t size = sp->size;
3711  msegmentptr next = sp->next;
3712  if (is_mmapped_segment(sp) && !is_extern_segment(sp)) {
3713  mchunkptr p = align_as_chunk(base);
3714  size_t psize = chunksize(p);
3715  /* Can unmap if first chunk holds entire segment and not pinned */
3716  if (!cinuse(p)
3717  && (char *) p + psize >= base + size - TOP_FOOT_SIZE) {
3718  tchunkptr tp = (tchunkptr) p;
3719  assert(segment_holds(sp, (char *) sp));
3720  if (p == m->dv) {
3721  m->dv = 0;
3722  m->dvsize = 0;
3723  } else {
3724  unlink_large_chunk(m, tp);
3725  }
3726  if (CALL_MUNMAP(base, size) == 0) {
3727  released += size;
3728  m->footprint -= size;
3729  /* unlink obsoleted record */
3730  sp = pred;
3731  sp->next = next;
3732  } else { /* back out if cannot unmap */
3733  insert_large_chunk(m, tp, psize);
3734  }
3735  }
3736  }
3737  pred = sp;
3738  sp = next;
3739  }
3740  return released;
3741 }

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().

◆ SDL_calloc()

void* SDL_calloc ( size_t  nmemb,
size_t  size 
)

Definition at line 5394 of file SDL_malloc.c.

5395 {
5396  void *mem;
5397 
5398  if (!nmemb || !size) {
5399  nmemb = 1;
5400  size = 1;
5401  }
5402 
5403  mem = s_mem.calloc_func(nmemb, size);
5404  if (mem) {
5405  SDL_AtomicIncRef(&s_mem.num_allocations);
5406  }
5407  return mem;
5408 }

References s_mem, and SDL_AtomicIncRef.

◆ SDL_free()

void SDL_free ( void ptr)

Definition at line 5425 of file SDL_malloc.c.

5426 {
5427  if (!ptr) {
5428  return;
5429  }
5430 
5431  s_mem.free_func(ptr);
5432  (void)SDL_AtomicDecRef(&s_mem.num_allocations);
5433 }

References s_mem, SDL_AtomicDecRef, and void.

◆ SDL_GetMemoryFunctions()

void SDL_GetMemoryFunctions ( SDL_malloc_func malloc_func,
SDL_calloc_func calloc_func,
SDL_realloc_func realloc_func,
SDL_free_func free_func 
)

Get the current set of SDL memory functions.

Definition at line 5330 of file SDL_malloc.c.

5334 {
5335  if (malloc_func) {
5336  *malloc_func = s_mem.malloc_func;
5337  }
5338  if (calloc_func) {
5339  *calloc_func = s_mem.calloc_func;
5340  }
5341  if (realloc_func) {
5342  *realloc_func = s_mem.realloc_func;
5343  }
5344  if (free_func) {
5345  *free_func = s_mem.free_func;
5346  }
5347 }

References calloc_func, free_func, malloc_func, realloc_func, and s_mem.

◆ SDL_GetNumAllocations()

int SDL_GetNumAllocations ( void  )

Get the number of outstanding (unfreed) allocations.

Definition at line 5374 of file SDL_malloc.c.

5375 {
5376  return SDL_AtomicGet(&s_mem.num_allocations);
5377 }

References s_mem, and SDL_AtomicGet.

◆ SDL_malloc()

void* SDL_malloc ( size_t  size)

Definition at line 5379 of file SDL_malloc.c.

5380 {
5381  void *mem;
5382 
5383  if (!size) {
5384  size = 1;
5385  }
5386 
5387  mem = s_mem.malloc_func(size);
5388  if (mem) {
5389  SDL_AtomicIncRef(&s_mem.num_allocations);
5390  }
5391  return mem;
5392 }

References s_mem, and SDL_AtomicIncRef.

◆ SDL_realloc()

void* SDL_realloc ( void ptr,
size_t  size 
)

Definition at line 5410 of file SDL_malloc.c.

5411 {
5412  void *mem;
5413 
5414  if (!ptr && !size) {
5415  size = 1;
5416  }
5417 
5418  mem = s_mem.realloc_func(ptr, size);
5419  if (mem && !ptr) {
5420  SDL_AtomicIncRef(&s_mem.num_allocations);
5421  }
5422  return mem;
5423 }

References s_mem, and SDL_AtomicIncRef.

◆ SDL_SetMemoryFunctions()

int SDL_SetMemoryFunctions ( SDL_malloc_func  malloc_func,
SDL_calloc_func  calloc_func,
SDL_realloc_func  realloc_func,
SDL_free_func  free_func 
)

Replace SDL's memory allocation functions with a custom set.

Note
If you are replacing SDL's memory functions, you should call SDL_GetNumAllocations() and be very careful if it returns non-zero. That means that your free function will be called with memory allocated by the previous memory allocation functions.

Definition at line 5349 of file SDL_malloc.c.

5353 {
5354  if (!malloc_func) {
5355  return SDL_InvalidParamError("malloc_func");
5356  }
5357  if (!calloc_func) {
5358  return SDL_InvalidParamError("calloc_func");
5359  }
5360  if (!realloc_func) {
5361  return SDL_InvalidParamError("realloc_func");
5362  }
5363  if (!free_func) {
5364  return SDL_InvalidParamError("free_func");
5365  }
5366 
5367  s_mem.malloc_func = malloc_func;
5368  s_mem.calloc_func = calloc_func;
5369  s_mem.realloc_func = realloc_func;
5370  s_mem.free_func = free_func;
5371  return 0;
5372 }

References calloc_func, free_func, malloc_func, realloc_func, s_mem, and SDL_InvalidParamError.

◆ segment_holding()

static msegmentptr segment_holding ( mstate  m,
char *  addr 
)
static

Definition at line 2187 of file SDL_malloc.c.

2188 {
2189  msegmentptr sp = &m->seg;
2190  for (;;) {
2191  if (addr >= sp->base && addr < sp->base + sp->size)
2192  return sp;
2193  if ((sp = sp->next) == 0)
2194  return 0;
2195  }
2196 }

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

◆ sys_alloc()

static void* sys_alloc ( mstate  m,
size_t  nb 
)
static

Definition at line 3503 of file SDL_malloc.c.

3504 {
3505  char *tbase = CMFAIL;
3506  size_t tsize = 0;
3507  flag_t mmap_flag = 0;
3508 
3509  init_mparams();
3510 
3511  /* Directly map large chunks */
3512  if (use_mmap(m) && nb >= mparams.mmap_threshold) {
3513  void *mem = mmap_alloc(m, nb);
3514  if (mem != 0)
3515  return mem;
3516  }
3517 
3518  /*
3519  Try getting memory in any of three ways (in most-preferred to
3520  least-preferred order):
3521  1. A call to MORECORE that can normally contiguously extend memory.
3522  (disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or
3523  or main space is mmapped or a previous contiguous call failed)
3524  2. A call to MMAP new space (disabled if not HAVE_MMAP).
3525  Note that under the default settings, if MORECORE is unable to
3526  fulfill a request, and HAVE_MMAP is true, then mmap is
3527  used as a noncontiguous system allocator. This is a useful backup
3528  strategy for systems with holes in address spaces -- in this case
3529  sbrk cannot contiguously expand the heap, but mmap may be able to
3530  find space.
3531  3. A call to MORECORE that cannot usually contiguously extend memory.
3532  (disabled if not HAVE_MORECORE)
3533  */
3534 
3536  char *br = CMFAIL;
3537  msegmentptr ss =
3538  (m->top == 0) ? 0 : segment_holding(m, (char *) m->top);
3539  size_t asize = 0;
3541 
3542  if (ss == 0) { /* First time through or recovery */
3543  char *base = (char *) CALL_MORECORE(0);
3544  if (base != CMFAIL) {
3545  asize =
3547  SIZE_T_ONE);
3548  /* Adjust to end on a page boundary */
3549  if (!is_page_aligned(base))
3550  asize += (page_align((size_t) base) - (size_t) base);
3551  /* Can't call MORECORE if size is negative when treated as signed */
3552  if (asize < HALF_MAX_SIZE_T &&
3553  (br = (char *) (CALL_MORECORE(asize))) == base) {
3554  tbase = base;
3555  tsize = asize;
3556  }
3557  }
3558  } else {
3559  /* Subtract out existing available top space from MORECORE request. */
3560  asize =
3561  granularity_align(nb - m->topsize + TOP_FOOT_SIZE +
3563  /* Use mem here only if it did continuously extend old space */
3564  if (asize < HALF_MAX_SIZE_T &&
3565  (br =
3566  (char *) (CALL_MORECORE(asize))) == ss->base + ss->size) {
3567  tbase = br;
3568  tsize = asize;
3569  }
3570  }
3571 
3572  if (tbase == CMFAIL) { /* Cope with partial failure */
3573  if (br != CMFAIL) { /* Try to use/extend the space we did get */
3574  if (asize < HALF_MAX_SIZE_T &&
3575  asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) {
3576  size_t esize =
3579  asize);
3580  if (esize < HALF_MAX_SIZE_T) {
3581  char *end = (char *) CALL_MORECORE(esize);
3582  if (end != CMFAIL)
3583  asize += esize;
3584  else { /* Can't use; try to release */
3585  end = (char *) CALL_MORECORE(-asize);
3586  br = CMFAIL;
3587  }
3588  }
3589  }
3590  }
3591  if (br != CMFAIL) { /* Use the space we did get */
3592  tbase = br;
3593  tsize = asize;
3594  } else
3595  disable_contiguous(m); /* Don't try contiguous path in the future */
3596  }
3597 
3599  }
3600 
3601  if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */
3602  size_t req = nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE;
3603  size_t rsize = granularity_align(req);
3604  if (rsize > nb) { /* Fail if wraps around zero */
3605  char *mp = (char *) (CALL_MMAP(rsize));
3606  if (mp != CMFAIL) {
3607  tbase = mp;
3608  tsize = rsize;
3609  mmap_flag = IS_MMAPPED_BIT;
3610  }
3611  }
3612  }
3613 
3614  if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */
3615  size_t asize =
3617  SIZE_T_ONE);
3618  if (asize < HALF_MAX_SIZE_T) {
3619  char *br = CMFAIL;
3620  char *end = CMFAIL;
3622  br = (char *) (CALL_MORECORE(asize));
3623  end = (char *) (CALL_MORECORE(0));
3625  if (br != CMFAIL && end != CMFAIL && br < end) {
3626  size_t ssize = end - br;
3627  if (ssize > nb + TOP_FOOT_SIZE) {
3628  tbase = br;
3629  tsize = ssize;
3630  }
3631  }
3632  }
3633  }
3634 
3635  if (tbase != CMFAIL) {
3636 
3637  if ((m->footprint += tsize) > m->max_footprint)
3638  m->max_footprint = m->footprint;
3639 
3640  if (!is_initialized(m)) { /* first-time initialization */
3641  m->seg.base = m->least_addr = tbase;
3642  m->seg.size = tsize;
3643  m->seg.sflags = mmap_flag;
3644  m->magic = mparams.magic;
3645  init_bins(m);
3646  if (is_global(m))
3647  init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
3648  else {
3649  /* Offset top by embedded malloc_state */
3650  mchunkptr mn = next_chunk(mem2chunk(m));
3651  init_top(m, mn,
3652  (size_t) ((tbase + tsize) - (char *) mn) -
3653  TOP_FOOT_SIZE);
3654  }
3655  }
3656 
3657  else {
3658  /* Try to merge with an existing segment */
3659  msegmentptr sp = &m->seg;
3660  while (sp != 0 && tbase != sp->base + sp->size)
3661  sp = sp->next;
3662  if (sp != 0 && !is_extern_segment(sp) && (sp->sflags & IS_MMAPPED_BIT) == mmap_flag && segment_holds(sp, m->top)) { /* append */
3663  sp->size += tsize;
3664  init_top(m, m->top, m->topsize + tsize);
3665  } else {
3666  if (tbase < m->least_addr)
3667  m->least_addr = tbase;
3668  sp = &m->seg;
3669  while (sp != 0 && sp->base != tbase + tsize)
3670  sp = sp->next;
3671  if (sp != 0 &&
3672  !is_extern_segment(sp) &&
3673  (sp->sflags & IS_MMAPPED_BIT) == mmap_flag) {
3674  char *oldbase = sp->base;
3675  sp->base = tbase;
3676  sp->size += tsize;
3677  return prepend_alloc(m, tbase, oldbase, nb);
3678  } else
3679  add_segment(m, tbase, tsize, mmap_flag);
3680  }
3681  }
3682 
3683  if (nb < m->topsize) { /* Allocate from new or extended top space */
3684  size_t rsize = m->topsize -= nb;
3685  mchunkptr p = m->top;
3686  mchunkptr r = m->top = chunk_plus_offset(p, nb);
3687  r->head = rsize | PINUSE_BIT;
3689  check_top_chunk(m, m->top);
3691  return chunk2mem(p);
3692  }
3693  }
3694 
3696  return 0;
3697 }

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().

◆ sys_trim()

static int sys_trim ( mstate  m,
size_t  pad 
)
static

Definition at line 3744 of file SDL_malloc.c.

3745 {
3746  size_t released = 0;
3747  if (pad < MAX_REQUEST && is_initialized(m)) {
3748  pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */
3749 
3750  if (m->topsize > pad) {
3751  /* Shrink top space in granularity-size units, keeping at least one */
3752  size_t unit = mparams.granularity;
3753  size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit -
3754  SIZE_T_ONE) * unit;
3755  msegmentptr sp = segment_holding(m, (char *) m->top);
3756 
3757  if (!is_extern_segment(sp)) {
3758  if (is_mmapped_segment(sp)) {
3759  if (HAVE_MMAP && sp->size >= extra && !has_segment_link(m, sp)) { /* can't shrink if pinned */
3760  size_t newsize = sp->size - extra;
3761  /* Prefer mremap, fall back to munmap */
3762  if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) !=
3763  MFAIL)
3764  || (CALL_MUNMAP(sp->base + newsize, extra) == 0)) {
3765  released = extra;
3766  }
3767  }
3768  } else if (HAVE_MORECORE) {
3769  if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */
3770  extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit;
3772  {
3773  /* Make sure end of memory is where we last set it. */
3774  char *old_br = (char *) (CALL_MORECORE(0));
3775  if (old_br == sp->base + sp->size) {
3776  char *rel_br = (char *) (CALL_MORECORE(-extra));
3777  char *new_br = (char *) (CALL_MORECORE(0));
3778  if (rel_br != CMFAIL && new_br < old_br)
3779  released = old_br - new_br;
3780  }
3781  }
3783  }
3784  }
3785 
3786  if (released != 0) {
3787  sp->size -= released;
3788  m->footprint -= released;
3789  init_top(m, m->top, m->topsize - released);
3790  check_top_chunk(m, m->top);
3791  }
3792  }
3793 
3794  /* Unmap any unused mmapped segments */
3795  if (HAVE_MMAP)
3796  released += release_unused_segments(m);
3797 
3798  /* On failure, disable autotrim to avoid repeated failed future calls */
3799  if (released == 0)
3800  m->trim_check = MAX_SIZE_T;
3801  }
3802 
3803  return (released != 0) ? 1 : 0;
3804 }

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

Referenced by dlfree(), and dlmalloc_trim().

◆ tmalloc_large()

static void* tmalloc_large ( mstate  m,
size_t  nb 
)
static

Definition at line 3810 of file SDL_malloc.c.

3811 {
3812  tchunkptr v = 0;
3813  size_t rsize = -nb; /* Unsigned negation */
3814  tchunkptr t;
3815  bindex_t idx;
3816  compute_tree_index(nb, idx);
3817 
3818  if ((t = *treebin_at(m, idx)) != 0) {
3819  /* Traverse tree for this bin looking for node with size == nb */
3820  size_t sizebits = nb << leftshift_for_tree_index(idx);
3821  tchunkptr rst = 0; /* The deepest untaken right subtree */
3822  for (;;) {
3823  tchunkptr rt;
3824  size_t trem = chunksize(t) - nb;
3825  if (trem < rsize) {
3826  v = t;
3827  if ((rsize = trem) == 0)
3828  break;
3829  }
3830  rt = t->child[1];
3831  t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1];
3832  if (rt != 0 && rt != t)
3833  rst = rt;
3834  if (t == 0) {
3835  t = rst; /* set t to least subtree holding sizes > nb */
3836  break;
3837  }
3838  sizebits <<= 1;
3839  }
3840  }
3841 
3842  if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */
3843  binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap;
3844  if (leftbits != 0) {
3845  bindex_t i;
3846  binmap_t leastbit = least_bit(leftbits);
3847  compute_bit2idx(leastbit, i);
3848  t = *treebin_at(m, i);
3849  }
3850  }
3851 
3852  while (t != 0) { /* find smallest of tree or subtree */
3853  size_t trem = chunksize(t) - nb;
3854  if (trem < rsize) {
3855  rsize = trem;
3856  v = t;
3857  }
3858  t = leftmost_child(t);
3859  }
3860 
3861  /* If dv is a better fit, return 0 so malloc will use it */
3862  if (v != 0 && rsize < (size_t) (m->dvsize - nb)) {
3863  if (RTCHECK(ok_address(m, v))) { /* split */
3864  mchunkptr r = chunk_plus_offset(v, nb);
3865  assert(chunksize(v) == rsize + nb);
3866  if (RTCHECK(ok_next(v, r))) {
3868  if (rsize < MIN_CHUNK_SIZE)
3869  set_inuse_and_pinuse(m, v, (rsize + nb));
3870  else {
3873  insert_chunk(m, r, rsize);
3874  }
3875  return chunk2mem(v);
3876  }
3877  }
3879  }
3880  return 0;
3881 }

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().

◆ tmalloc_small()

static void* tmalloc_small ( mstate  m,
size_t  nb 
)
static

Definition at line 3885 of file SDL_malloc.c.

3886 {
3887  tchunkptr t, v;
3888  size_t rsize;
3889  bindex_t i;
3890  binmap_t leastbit = least_bit(m->treemap);
3891  compute_bit2idx(leastbit, i);
3892 
3893  v = t = *treebin_at(m, i);
3894  rsize = chunksize(t) - nb;
3895 
3896  while ((t = leftmost_child(t)) != 0) {
3897  size_t trem = chunksize(t) - nb;
3898  if (trem < rsize) {
3899  rsize = trem;
3900  v = t;
3901  }
3902  }
3903 
3904  if (RTCHECK(ok_address(m, v))) {
3905  mchunkptr r = chunk_plus_offset(v, nb);
3906  assert(chunksize(v) == rsize + nb);
3907  if (RTCHECK(ok_next(v, r))) {
3909  if (rsize < MIN_CHUNK_SIZE)
3910  set_inuse_and_pinuse(m, v, (rsize + nb));
3911  else {
3914  replace_dv(m, r, rsize);
3915  }
3916  return chunk2mem(v);
3917  }
3918  }
3919 
3921  return 0;
3922 }

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().

◆ win32_acquire_lock()

static int win32_acquire_lock ( MLOCK_T sl)
static

Definition at line 1527 of file SDL_malloc.c.

1528 {
1529  for (;;) {
1530 #ifdef InterlockedCompareExchangePointer
1531  if (!InterlockedCompareExchange(sl, 1, 0))
1532  return 0;
1533 #else /* Use older void* version */
1534  if (!InterlockedCompareExchange((void **) sl, (void *) 1, (void *) 0))
1535  return 0;
1536 #endif /* InterlockedCompareExchangePointer */
1537  Sleep(0);
1538  }
1539 }

◆ win32_release_lock()

static void win32_release_lock ( MLOCK_T sl)
static

Definition at line 1542 of file SDL_malloc.c.

1543 {
1544  InterlockedExchange(sl, 0);
1545 }

◆ win32direct_mmap()

static void* win32direct_mmap ( size_t  size)
static

Definition at line 1425 of file SDL_malloc.c.

1426 {
1427  void *ptr = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN,
1428  PAGE_READWRITE);
1429  return (ptr != 0) ? ptr : MFAIL;
1430 }

References MFAIL.

◆ win32mmap()

static void* win32mmap ( size_t  size)
static

Definition at line 1416 of file SDL_malloc.c.

1417 {
1418  void *ptr =
1419  VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
1420  return (ptr != 0) ? ptr : MFAIL;
1421 }

References MFAIL.

◆ win32munmap()

static int win32munmap ( void ptr,
size_t  size 
)
static

Definition at line 1434 of file SDL_malloc.c.

1435 {
1436  MEMORY_BASIC_INFORMATION minfo;
1437  char *cptr = ptr;
1438  while (size) {
1439  if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)
1440  return -1;
1441  if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||
1442  minfo.State != MEM_COMMIT || minfo.RegionSize > size)
1443  return -1;
1444  if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)
1445  return -1;
1446  cptr += minfo.RegionSize;
1447  size -= minfo.RegionSize;
1448  }
1449  return 0;
1450 }

Variable Documentation

◆ _gm_

struct malloc_state _gm_
static

Definition at line 2143 of file SDL_malloc.c.

◆ calloc_func

SDL_calloc_func calloc_func

Definition at line 5322 of file SDL_malloc.c.

Referenced by SDL_GetMemoryFunctions(), and SDL_SetMemoryFunctions().

◆ free_func

SDL_free_func free_func

Definition at line 5324 of file SDL_malloc.c.

Referenced by SDL_GetMemoryFunctions(), and SDL_SetMemoryFunctions().

◆ magic_init_mutex

MLOCK_T magic_init_mutex
static

Definition at line 1553 of file SDL_malloc.c.

◆ malloc_func

SDL_malloc_func malloc_func

Definition at line 5321 of file SDL_malloc.c.

Referenced by SDL_GetMemoryFunctions(), and SDL_SetMemoryFunctions().

◆ mparams

struct malloc_params mparams
static

◆ num_allocations

SDL_atomic_t num_allocations

Definition at line 5325 of file SDL_malloc.c.

◆ realloc_func

SDL_realloc_func realloc_func

Definition at line 5323 of file SDL_malloc.c.

Referenced by SDL_GetMemoryFunctions(), and SDL_SetMemoryFunctions().

◆ s_mem

compute_tree_index
#define compute_tree_index(S, I)
Definition: SDL_malloc.c:2344
mallinfo::fordblks
MALLINFO_FIELD_TYPE fordblks
Definition: SDL_malloc.c:685
segment_holding
static msegmentptr segment_holding(mstate m, char *addr)
Definition: SDL_malloc.c:2187
MFAIL
#define MFAIL
Definition: SDL_malloc.c:1339
use_mmap
#define use_mmap(M)
Definition: SDL_malloc.c:2156
set_free_with_pinuse
#define set_free_with_pinuse(p, s, n)
Definition: SDL_malloc.c:1814
offset
GLintptr offset
Definition: SDL_opengl_glext.h:538
s_mem
static struct @37 s_mem
time
EGLSurface EGLnsecsANDROID time
Definition: eglext.h:518
treebin_at
#define treebin_at(M, i)
Definition: SDL_malloc.c:2326
dlmalloc
void * dlmalloc(size_t)
Definition: SDL_malloc.c:4213
CALL_MUNMAP
#define CALL_MUNMAP(a, s)
Definition: SDL_malloc.c:1453
calloc_func
SDL_calloc_func calloc_func
Definition: SDL_malloc.c:5322
has_segment_link
static int has_segment_link(mstate m, msegmentptr ss)
Definition: SDL_malloc.c:2200
insert_chunk
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3245
end
GLuint GLuint end
Definition: SDL_opengl.h:1571
request2size
#define request2size(req)
Definition: SDL_malloc.c:1765
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1751
check_top_chunk
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2293
CORRUPTION_ERROR_ACTION
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2275
real_realloc
#define real_realloc
Definition: SDL_malloc.c:5314
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1109
malloc_params::magic
size_t magic
Definition: SDL_malloc.c:2132
dlmemalign
void * dlmemalign(size_t, size_t)
Definition: SDL_malloc.c:4486
binmap_t
unsigned int binmap_t
Definition: SDL_malloc.c:1728
malloc_func
SDL_malloc_func malloc_func
Definition: SDL_malloc.c:5321
MORECORE_CONTIGUOUS
#define MORECORE_CONTIGUOUS
Definition: SDL_malloc.c:583
is_mmapped
#define is_mmapped(p)
Definition: SDL_malloc.c:1817
gm
#define gm
Definition: SDL_malloc.c:2144
is_extern_segment
#define is_extern_segment(S)
Definition: SDL_malloc.c:2008
cp
static const double cp
Definition: e_pow.c:96
INUSE_BITS
#define INUSE_BITS
Definition: SDL_malloc.c:1781
CHUNK_ALIGN_MASK
#define CHUNK_ALIGN_MASK
Definition: SDL_malloc.c:1319
calloc_must_clear
#define calloc_must_clear(p)
Definition: SDL_malloc.c:1828
assert
#define assert(x)
Definition: SDL_malloc.c:1227
q
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2087
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
real_malloc
#define real_malloc
Definition: SDL_malloc.c:5312
granularity_align
#define granularity_align(S)
Definition: SDL_malloc.c:2173
unlink_large_chunk
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3172
SDL_InvalidParamError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
SIX_SIZE_T_SIZES
#define SIX_SIZE_T_SIZES
Definition: SDL_malloc.c:1315
SDL_AtomicIncRef
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
Definition: SDL_atomic.h:252
MAX_SIZE_T
#define MAX_SIZE_T
Definition: SDL_malloc.c:526
malloc_params::trim_threshold
size_t trim_threshold
Definition: SDL_malloc.c:2136
change_mparam
static int change_mparam(int param_number, int value)
Definition: SDL_malloc.c:2628
real_calloc
#define real_calloc
Definition: SDL_malloc.c:5313
IS_MMAPPED_BIT
#define IS_MMAPPED_BIT
Definition: SDL_malloc.c:1350
left_bits
#define left_bits(x)
Definition: SDL_malloc.c:2425
MAX_SMALL_REQUEST
#define MAX_SMALL_REQUEST
Definition: SDL_malloc.c:2096
page_align
#define page_align(S)
Definition: SDL_malloc.c:2169
segment_holds
#define segment_holds(S, A)
Definition: SDL_malloc.c:2182
sys_trim
static int sys_trim(mstate m, size_t pad)
Definition: SDL_malloc.c:3744
malloc_params::page_size
size_t page_size
Definition: SDL_malloc.c:2133
CMFAIL
#define CMFAIL
Definition: SDL_malloc.c:1340
x1
GLuint GLfloat GLfloat GLfloat x1
Definition: SDL_opengl_glext.h:8583
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1109
v
const GLdouble * v
Definition: SDL_opengl.h:2064
init_bins
static void init_bins(mstate m)
Definition: SDL_malloc.c:3371
memcpy
#define memcpy
Definition: SDL_malloc.c:630
release_unused_segments
static size_t release_unused_segments(mstate m)
Definition: SDL_malloc.c:3703
check_free_chunk
#define check_free_chunk(M, P)
Definition: SDL_malloc.c:2288
RTCHECK
#define RTCHECK(e)
Definition: SDL_malloc.c:2489
RELEASE_MAGIC_INIT_LOCK
#define RELEASE_MAGIC_INIT_LOCK()
Definition: SDL_malloc.c:1572
next_chunk
#define next_chunk(p)
Definition: SDL_malloc.c:1799
malloc_segment
Definition: SDL_malloc.c:1999
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
NTREEBINS
#define NTREEBINS
Definition: SDL_malloc.c:2090
mem2chunk
#define mem2chunk(mem)
Definition: SDL_malloc.c:1752
pinuse
#define pinuse(p)
Definition: SDL_malloc.c:1788
CINUSE_BIT
#define CINUSE_BIT
Definition: SDL_malloc.c:1780
USE_NONCONTIGUOUS_BIT
#define USE_NONCONTIGUOUS_BIT
Definition: SDL_malloc.c:1471
fm
#define fm
overhead_for
#define overhead_for(p)
Definition: SDL_malloc.c:1821
SDL_AtomicDecRef
#define SDL_AtomicDecRef(a)
Decrement an atomic variable used as a reference count.
Definition: SDL_atomic.h:262
tmalloc_large
static void * tmalloc_large(mstate m, size_t nb)
Definition: SDL_malloc.c:3810
set_size_and_pinuse_of_free_chunk
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1810
USAGE_ERROR_ACTION
#define USAGE_ERROR_ACTION(m, p)
Definition: SDL_malloc.c:2279
unlink_first_small_chunk
#define unlink_first_small_chunk(M, B, P, I)
Definition: SDL_malloc.c:3072
flag_t
unsigned int flag_t
Definition: SDL_malloc.c:1729
PINUSE_BIT
#define PINUSE_BIT
Definition: SDL_malloc.c:1779
insert_small_chunk
#define insert_small_chunk(M, P, S)
Definition: SDL_malloc.c:3033
ABORT
#define ABORT
Definition: SDL_malloc.c:39
MALLOC_ALIGNMENT
#define MALLOC_ALIGNMENT
Definition: SDL_malloc.c:539
buf
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: SDL_opengl_glext.h:2480
set_size_and_pinuse_of_inuse_chunk
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2512
is_small
#define is_small(s)
Definition: SDL_malloc.c:2319
HAVE_MMAP
#define HAVE_MMAP
Definition: SDL_malloc.c:491
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
add_segment
static void add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped)
Definition: SDL_malloc.c:3446
NSMALLBINS
#define NSMALLBINS
Definition: SDL_malloc.c:2089
FOUR_SIZE_T_SIZES
#define FOUR_SIZE_T_SIZES
Definition: SDL_malloc.c:1314
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1789
unlink_chunk
#define unlink_chunk(M, P, S)
Definition: SDL_malloc.c:3249
check_malloc_state
#define check_malloc_state(M)
Definition: SDL_malloc.c:2292
init_top
static void init_top(mstate m, mchunkptr p, size_t psize)
Definition: SDL_malloc.c:3354
internal_realloc
static void * internal_realloc(mstate m, void *oldmem, size_t bytes)
Definition: SDL_malloc.c:3927
check_mmapped_chunk
#define check_mmapped_chunk(M, P)
Definition: SDL_malloc.c:2291
t
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
init_mparams
static int init_mparams(void)
Definition: SDL_malloc.c:2545
enable_mmap
#define enable_mmap(M)
Definition: SDL_malloc.c:2157
mallinfo::hblkhd
MALLINFO_FIELD_TYPE hblkhd
Definition: SDL_malloc.c:681
sys_alloc
static void * sys_alloc(mstate m, size_t nb)
Definition: SDL_malloc.c:3503
MMAP_FOOT_PAD
#define MMAP_FOOT_PAD
Definition: SDL_malloc.c:1744
bindex_t
size_t bindex_t
Definition: SDL_malloc.c:1727
check_inuse_chunk
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2289
SIZE_T_BITSIZE
#define SIZE_T_BITSIZE
Definition: SDL_malloc.c:1306
free_func
SDL_free_func free_func
Definition: SDL_malloc.c:5324
DEFAULT_MMAP_THRESHOLD
#define DEFAULT_MMAP_THRESHOLD
Definition: SDL_malloc.c:608
I
#define I(x, y, z)
Definition: SDL_test_md5.c:76
mallinfo::ordblks
MALLINFO_FIELD_TYPE ordblks
Definition: SDL_malloc.c:678
insert_large_chunk
#define insert_large_chunk(M, X, S)
Definition: SDL_malloc.c:3104
head
SDL_EventEntry * head
Definition: SDL_events.c:80
pad_request
#define pad_request(req)
Definition: SDL_malloc.c:1761
set_inuse_and_pinuse
#define set_inuse_and_pinuse(M, p, s)
Definition: SDL_malloc.c:2507
addr
GLenum const void * addr
Definition: SDL_opengl_glext.h:7945
set_inuse
#define set_inuse(M, p, s)
Definition: SDL_malloc.c:2502
chunk_minus_offset
#define chunk_minus_offset(p, s)
Definition: SDL_malloc.c:1796
mallinfo::uordblks
MALLINFO_FIELD_TYPE uordblks
Definition: SDL_malloc.c:684
is_global
#define is_global(M)
Definition: SDL_malloc.c:2145
F
#define F(x, y, z)
Definition: SDL_test_md5.c:73
small_index
#define small_index(s)
Definition: SDL_malloc.c:2320
HALF_MAX_SIZE_T
#define HALF_MAX_SIZE_T
Definition: SDL_malloc.c:1316
malloc_params::default_mflags
flag_t default_mflags
Definition: SDL_malloc.c:2137
mallinfo::usmblks
MALLINFO_FIELD_TYPE usmblks
Definition: SDL_malloc.c:682
disable_contiguous
#define disable_contiguous(M)
Definition: SDL_malloc.c:2161
M_GRANULARITY
#define M_GRANULARITY
Definition: SDL_malloc.c:641
ok_address
#define ok_address(M, a)
Definition: SDL_malloc.c:2461
ok_pinuse
#define ok_pinuse(p)
Definition: SDL_malloc.c:2467
internal_free
#define internal_free(m, mem)
Definition: SDL_malloc.c:3267
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
tmalloc_small
static void * tmalloc_small(mstate m, size_t nb)
Definition: SDL_malloc.c:3885
sizes
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: SDL_opengl_glext.h:2561
ok_magic
#define ok_magic(M)
Definition: SDL_malloc.c:2480
mmap_resize
static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb)
Definition: SDL_malloc.c:3315
internal_malloc_stats
static void internal_malloc_stats(mstate m)
Definition: SDL_malloc.c:2984
DEFAULT_TRIM_THRESHOLD
#define DEFAULT_TRIM_THRESHOLD
Definition: SDL_malloc.c:601
least_bit
#define least_bit(x)
Definition: SDL_malloc.c:2422
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
use_noncontiguous
#define use_noncontiguous(M)
Definition: SDL_malloc.c:2160
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1747
idx2bit
#define idx2bit(i)
Definition: SDL_malloc.c:2381
cinuse
#define cinuse(p)
Definition: SDL_malloc.c:1787
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1795
is_initialized
#define is_initialized(M)
Definition: SDL_malloc.c:2146
memset
#define memset
Definition: SDL_malloc.c:627
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
mparams
static struct malloc_params mparams
Definition: SDL_malloc.c:2140
val
GLuint GLfloat * val
Definition: SDL_opengl_glext.h:1492
x2
GLfixed GLfixed x2
Definition: SDL_opengl_glext.h:4583
check_malloced_chunk
#define check_malloced_chunk(M, P, N)
Definition: SDL_malloc.c:2290
leftmost_child
#define leftmost_child(t)
Definition: SDL_malloc.c:1940
should_trim
#define should_trim(M, s)
Definition: SDL_malloc.c:2212
unlink_small_chunk
#define unlink_small_chunk(M, P, S)
Definition: SDL_malloc.c:3052
PREACTION
#define PREACTION(M)
Definition: SDL_malloc.c:2239
s
GLdouble s
Definition: SDL_opengl.h:2063
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1311
ialloc
static void ** ialloc(mstate m, size_t n_elements, size_t *sizes, int opts, void *chunks[])
Definition: SDL_malloc.c:4087
ACQUIRE_MORECORE_LOCK
#define ACQUIRE_MORECORE_LOCK()
Definition: SDL_malloc.c:1566
ACQUIRE_MAGIC_INIT_LOCK
#define ACQUIRE_MAGIC_INIT_LOCK()
Definition: SDL_malloc.c:1571
DIRECT_MMAP
#define DIRECT_MMAP(s)
Definition: SDL_malloc.c:1454
internal_mallinfo
static struct mallinfo internal_mallinfo(mstate m)
Definition: SDL_malloc.c:2943
MAX_REQUEST
#define MAX_REQUEST
Definition: SDL_malloc.c:1757
replace_dv
#define replace_dv(M, P, S)
Definition: SDL_malloc.c:3090
MCHUNK_SIZE
#define MCHUNK_SIZE
Definition: SDL_malloc.c:1733
M_TRIM_THRESHOLD
#define M_TRIM_THRESHOLD
Definition: SDL_malloc.c:640
internal_malloc
#define internal_malloc(m, b)
Definition: SDL_malloc.c:3266
is_aligned
#define is_aligned(A)
Definition: SDL_malloc.c:1322
mallinfo::arena
MALLINFO_FIELD_TYPE arena
Definition: SDL_malloc.c:677
small_index2size
#define small_index2size(i)
Definition: SDL_malloc.c:2321
smallbin_at
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2325
realloc_func
SDL_realloc_func realloc_func
Definition: SDL_malloc.c:5323
mallinfo::keepcost
MALLINFO_FIELD_TYPE keepcost
Definition: SDL_malloc.c:686
CALL_MMAP
#define CALL_MMAP(s)
Definition: SDL_malloc.c:1452
MALLOC_FAILURE_ACTION
#define MALLOC_FAILURE_ACTION
Definition: SDL_malloc.c:501
size_t
unsigned int size_t
Definition: SDL_config_windows.h:68
HAVE_MORECORE
#define HAVE_MORECORE
Definition: SDL_malloc.c:492
malloc_params::mmap_threshold
size_t mmap_threshold
Definition: SDL_malloc.c:2135
USE_LOCK_BIT
#define USE_LOCK_BIT
Definition: SDL_malloc.c:1556
internal_memalign
static void * internal_memalign(mstate m, size_t alignment, size_t bytes)
Definition: SDL_malloc.c:3997
is_mmapped_segment
#define is_mmapped_segment(S)
Definition: SDL_malloc.c:2007
mark_inuse_foot
#define mark_inuse_foot(M, p, s)
Definition: SDL_malloc.c:2499
dlfree
void dlfree(void *)
Definition: SDL_malloc.c:4347
align_as_chunk
#define align_as_chunk(A)
Definition: SDL_malloc.c:1754
INITIAL_LOCK
#define INITIAL_LOCK(l)
Definition: SDL_malloc.c:1547
malloc_params::granularity
size_t granularity
Definition: SDL_malloc.c:2134
RELEASE_MORECORE_LOCK
#define RELEASE_MORECORE_LOCK()
Definition: SDL_malloc.c:1567
align_offset
#define align_offset(A)
Definition: SDL_malloc.c:1325
SDL_AtomicGet
#define SDL_AtomicGet
Definition: SDL_dynapi_overrides.h:68
compute_bit2idx
#define compute_bit2idx(X, I)
Definition: SDL_malloc.c:2407
fd
GLuint64 GLenum GLint fd
Definition: gl2ext.h:1508
void
const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char const char const SDL_SCANF_FORMAT_STRING char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Definition: SDL_dynapi_procs.h:89
POSTACTION
#define POSTACTION(M)
Definition: SDL_malloc.c:2240
ok_cinuse
#define ok_cinuse(p)
Definition: SDL_malloc.c:2465
prepend_alloc
static void * prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb)
Definition: SDL_malloc.c:3404
ok_next
#define ok_next(p, n)
Definition: SDL_malloc.c:2463
leftshift_for_tree_index
#define leftshift_for_tree_index(i)
Definition: SDL_malloc.c:2368
real_free
#define real_free
Definition: SDL_malloc.c:5315
disable_mmap
#define disable_mmap(M)
Definition: SDL_malloc.c:2158
TREEBIN_SHIFT
#define TREEBIN_SHIFT
Definition: SDL_malloc.c:2093
mallinfo
Definition: SDL_malloc.c:675
mmap_alloc
static void * mmap_alloc(mstate m, size_t nb)
Definition: SDL_malloc.c:3285
FENCEPOST_HEAD
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1784
M_MMAP_THRESHOLD
#define M_MMAP_THRESHOLD
Definition: SDL_malloc.c:642
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
TOP_FOOT_SIZE
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2222
CHUNK_OVERHEAD
#define CHUNK_OVERHEAD
Definition: SDL_malloc.c:1738
CALL_MREMAP
#define CALL_MREMAP(addr, osz, nsz, mv)
Definition: SDL_malloc.c:1461
SIZE_T_SIZE
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1305
CALL_MORECORE
#define CALL_MORECORE(S)
Definition: SDL_malloc.c:1467
DEFAULT_GRANULARITY
#define DEFAULT_GRANULARITY
Definition: SDL_malloc.c:596
MIN_REQUEST
#define MIN_REQUEST
Definition: SDL_malloc.c:1758
is_page_aligned
#define is_page_aligned(S)
Definition: SDL_malloc.c:2176
smallmap_is_marked
#define smallmap_is_marked(M, i)
Definition: SDL_malloc.c:2386
USE_MMAP_BIT
#define USE_MMAP_BIT
Definition: SDL_malloc.c:1351