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

Go to the source code of this file.

## Data Structures

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

## Macros

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

## Typedefs

typedef size_t | bindex_t
typedef unsigned int | binmap_t
typedef unsigned int | flag_t

## Functions

void * | dlmalloc (size_t)
void | dlfree (void *)
void * | dlcalloc (size_t, size_t)
void * | dlrealloc (void *, size_t)
void * | dlmemalign (size_t, size_t)
void * | dlvalloc (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 **)
void * | dlpvalloc (size_t)
int | dlmalloc_trim (size_t)
size_t | dlmalloc_usable_size (void *)
void | dlmalloc_stats (void)
static void * | win32mmap (size_t size)
static void * | win32direct_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 void * | mmap_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 void * | prepend_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 void * | sys_alloc (mstate m, size_t nb)
static size_t | release_unused_segments (mstate m)
static int | sys_trim (mstate m, size_t pad)
static void * | tmalloc_large (mstate m, size_t nb)
static void * | tmalloc_small (mstate m, size_t nb)
static void * | internal_realloc (mstate m, void *oldmem, size_t bytes)
static void * | internal_memalign (mstate m, size_t alignment, size_t bytes)
static void ** | ialloc (mstate m, size_t n_elements, size_t *sizes, int opts, void *chunks[])
void ** | dlindependent_calloc (size_t n_elements, size_t elem_size, void *chunks[])
void ** | dlindependent_comalloc (size_t n_elements, size_t sizes[], void *chunks[])

## Variables

static MLOCK_T | magic_init_mutex
static struct malloc_params | mparams
static struct malloc_state | _gm_

## Macro Definition Documentation

#define ABORT

Definition at line 61 of file SDL_malloc.c.

Referenced by init_mparams().

#define ABORT_ON_ASSERT_FAILURE 1

Definition at line 561 of file SDL_malloc.c.

#define ACQUIRE_LOCK | ( |  | l | ) | win32_acquire_lock(l)

Definition at line 1515 of file SDL_malloc.c.

#define ACQUIRE_MAGIC_INIT_LOCK | ( |  | ) | ACQUIRE_LOCK(&magic_init_mutex);

Definition at line 1538 of file SDL_malloc.c.

Referenced by init_mparams().

#define ACQUIRE_MORECORE_LOCK | ( |  | ) |

Definition at line 1533 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

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

Definition at line 1721 of file SDL_malloc.c.

Referenced by change_mparam(), dlmallopt(), internal_mallinfo(), internal_malloc_stats(), prepend_alloc(), and release_unused_segments().

#define align_offset | ( |  | A | ) |

Value:
((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\
((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
CHUNK_ALIGN_MASK
#define CHUNK_ALIGN_MASK
Definition: SDL_malloc.c:1332
size_t
unsigned int size_t
Definition: SDL_config_windows.h:67
MALLOC_ALIGNMENT
#define MALLOC_ALIGNMENT
Definition: SDL_malloc.c:552

Definition at line 1338 of file SDL_malloc.c.

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

#define assert | ( |  | x | ) |

Definition at line 1240 of file SDL_malloc.c.

Referenced by add_segment(), change_mparam(), dlmalloc(), dlmallopt(), ialloc(), internal_memalign(), mmap_alloc(), prepend_alloc(), release_unused_segments(), tmalloc_large(), and tmalloc_small().

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

Definition at line 2331 of file SDL_malloc.c.

#define CALL_MMAP | ( |  | s | ) | win32mmap(s)

Definition at line 1429 of file SDL_malloc.c.

Referenced by dlmallopt(), and sys_alloc().

#define CALL_MORECORE | ( |  | S | ) | MFAIL

Definition at line 1444 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

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

Definition at line 1438 of file SDL_malloc.c.

Referenced by mmap_resize(), and sys_trim().

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

Definition at line 1430 of file SDL_malloc.c.

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

#define calloc SDL_calloc

Definition at line 642 of file SDL_malloc.c.

Referenced by decode_edid().

#define calloc_must_clear | ( |  | p | ) | (1)

Definition at line 1795 of file SDL_malloc.c.

Referenced by dlcalloc(), and dlmallopt().

#define check_free_chunk | ( |  | M,
|  |  | P
| ) |  |

Definition at line 2255 of file SDL_malloc.c.

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

#define check_inuse_chunk | ( |  | M,
|  |  | P
| ) |  |

Definition at line 2256 of file SDL_malloc.c.

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

#define check_malloc_state | ( |  | M | ) |

Definition at line 2259 of file SDL_malloc.c.

Referenced by internal_mallinfo(), and internal_malloc_stats().

#define check_malloced_chunk | ( |  | M,
|  |  | P,
|  |  | N
| ) |  |

Definition at line 2257 of file SDL_malloc.c.

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

#define check_mmapped_chunk | ( |  | M,
|  |  | P
| ) |  |

Definition at line 2258 of file SDL_malloc.c.

Referenced by mmap_alloc(), and mmap_resize().

#define check_top_chunk | ( |  | M,
|  |  | P
| ) |  |

Definition at line 2260 of file SDL_malloc.c.

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

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

Definition at line 1718 of file SDL_malloc.c.

Referenced by add_segment(), change_mparam(), dlmalloc(), dlmallopt(), ialloc(), init_top(), internal_memalign(), internal_realloc(), mmap_alloc(), prepend_alloc(), sys_alloc(), tmalloc_large(), and tmalloc_small().

#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE)

Definition at line 1332 of file SDL_malloc.c.

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

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

Definition at line 1763 of file SDL_malloc.c.

Referenced by dlfree(), and dlmallopt().

#define CHUNK_OVERHEAD (SIZE_T_SIZE)

Definition at line 1705 of file SDL_malloc.c.

Referenced by ialloc(), and internal_memalign().

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

Definition at line 1762 of file SDL_malloc.c.

Referenced by add_segment(), change_mparam(), dlfree(), dlmalloc(), dlmallopt(), ialloc(), init_top(), internal_memalign(), internal_realloc(), mmap_alloc(), mmap_resize(), prepend_alloc(), sys_alloc(), tmalloc_large(), and tmalloc_small().

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

Definition at line 1756 of file SDL_malloc.c.

Referenced by change_mparam(), dlfree(), dlmalloc(), dlmalloc_usable_size(), dlmallopt(), ialloc(), internal_mallinfo(), internal_malloc_stats(), internal_memalign(), internal_realloc(), mmap_resize(), prepend_alloc(), release_unused_segments(), tmalloc_large(), and tmalloc_small().

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

Definition at line 1754 of file SDL_malloc.c.

Referenced by change_mparam(), dlfree(), dlmalloc_usable_size(), dlmallopt(), internal_mallinfo(), internal_malloc_stats(), prepend_alloc(), and release_unused_segments().

#define CINUSE_BIT (SIZE_T_TWO)

Definition at line 1747 of file SDL_malloc.c.

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

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

Definition at line 1759 of file SDL_malloc.c.

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

Definition at line 1758 of file SDL_malloc.c.

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

Definition at line 2352 of file SDL_malloc.c.

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

Definition at line 2356 of file SDL_malloc.c.

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

Definition at line 1353 of file SDL_malloc.c.

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

#define compute_bit2idx | ( |  | X,
|  |  | I
| ) |  |

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

Definition at line 2374 of file SDL_malloc.c.

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

#define compute_tree_index | ( |  | S,
|  |  | I
| ) |  |

Value:
{\
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));\
}\
}
TREEBIN_SHIFT
#define TREEBIN_SHIFT
Definition: SDL_malloc.c:2060
size_t
unsigned int size_t
Definition: SDL_config_windows.h:67
NTREEBINS
#define NTREEBINS
Definition: SDL_malloc.c:2057
I
#define I(x, y, z)
Definition: SDL_test_md5.c:76

Definition at line 2311 of file SDL_malloc.c.

Referenced by change_mparam(), and tmalloc_large().

#define CORRUPTION_ERROR_ACTION | ( |  | m | ) | ABORT

Definition at line 2242 of file SDL_malloc.c.

Referenced by tmalloc_large(), and tmalloc_small().

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

Definition at line 609 of file SDL_malloc.c.

Referenced by init_mparams().

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

Definition at line 621 of file SDL_malloc.c.

Referenced by init_mparams().

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

Definition at line 614 of file SDL_malloc.c.

Referenced by init_mparams().

#define DIRECT_MMAP | ( |  | s | ) | win32direct_mmap(s)

Definition at line 1431 of file SDL_malloc.c.

Referenced by mmap_alloc().

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

Definition at line 2128 of file SDL_malloc.c.

Referenced by dlmallopt(), and sys_alloc().

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

Definition at line 2121 of file SDL_malloc.c.

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

Definition at line 2125 of file SDL_malloc.c.

Referenced by ialloc().

#define dlcalloc calloc

Definition at line 715 of file SDL_malloc.c.

#define dlfree free

Definition at line 716 of file SDL_malloc.c.

Referenced by dlrealloc().

#define dlindependent_calloc independent_calloc

Definition at line 729 of file SDL_malloc.c.

#define dlindependent_comalloc independent_comalloc

Definition at line 730 of file SDL_malloc.c.

#define dlmallinfo mallinfo

Definition at line 722 of file SDL_malloc.c.

#define dlmalloc malloc

Definition at line 717 of file SDL_malloc.c.

Referenced by dlcalloc(), and dlrealloc().

#define dlmalloc_footprint malloc_footprint

Definition at line 727 of file SDL_malloc.c.

#define dlmalloc_max_footprint malloc_max_footprint

Definition at line 728 of file SDL_malloc.c.

void dlmalloc_stats malloc_stats

Definition at line 725 of file SDL_malloc.c.

#define dlmalloc_trim malloc_trim

Definition at line 724 of file SDL_malloc.c.

#define dlmalloc_usable_size malloc_usable_size

Definition at line 726 of file SDL_malloc.c.

#define dlmallopt mallopt

Definition at line 723 of file SDL_malloc.c.

#define dlmemalign memalign

Definition at line 718 of file SDL_malloc.c.

Referenced by dlpvalloc(), and dlvalloc().

#define dlpvalloc pvalloc

Definition at line 721 of file SDL_malloc.c.

#define dlrealloc realloc

Definition at line 719 of file SDL_malloc.c.

#define dlvalloc valloc

Definition at line 720 of file SDL_malloc.c.

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

Definition at line 2120 of file SDL_malloc.c.

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

Definition at line 2124 of file SDL_malloc.c.

Referenced by ialloc().

#define EXTERN_BIT (8U)

Definition at line 1451 of file SDL_malloc.c.

Referenced by dlmallopt().

#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE)

Definition at line 1751 of file SDL_malloc.c.

Referenced by add_segment(), change_mparam(), internal_mallinfo(), internal_malloc_stats(), mmap_alloc(), and mmap_resize().

#define fm gm

Referenced by dlfree(), and dlmallopt().

#define FOOTERS 0

Definition at line 555 of file SDL_malloc.c.

#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2)

Definition at line 1327 of file SDL_malloc.c.

Referenced by add_segment().

#define free SDL_free

Definition at line 644 of file SDL_malloc.c.

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

Definition at line 1773 of file SDL_malloc.c.

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

Definition at line 2204 of file SDL_malloc.c.

#define gm (&_gm_)

Definition at line 2111 of file SDL_malloc.c.

Referenced by dlindependent_calloc(), dlindependent_comalloc(), dlmallinfo(), dlmalloc(), dlmalloc_footprint(), dlmalloc_max_footprint(), dlmalloc_stats(), dlmalloc_trim(), dlmemalign(), dlrealloc(), and init_mparams().

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

Definition at line 2140 of file SDL_malloc.c.

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

#define HALF_MAX_SIZE_T (MAX_SIZE_T / 2U)

Definition at line 1329 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define HAVE_MMAP 1

Definition at line 512 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define HAVE_MORECORE 0

Definition at line 513 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define HAVE_MREMAP 0

Definition at line 582 of file SDL_malloc.c.

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

Definition at line 2348 of file SDL_malloc.c.

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

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

Definition at line 1514 of file SDL_malloc.c.

Referenced by dlmallopt(), and init_mparams().

#define INSECURE 0

Definition at line 570 of file SDL_malloc.c.

#define insert_chunk | ( |  | M,
|  |  | P,
|  |  | S
| ) |  |

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

Definition at line 3203 of file SDL_malloc.c.

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

#define insert_large_chunk | ( |  | M,
|  |  | X,
|  |  | S
| ) |  |

Definition at line 3062 of file SDL_malloc.c.

Referenced by release_unused_segments().

#define insert_small_chunk | ( |  | M,
|  |  | P,
|  |  | S
| ) |  |

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;\
}
bindex_t
size_t bindex_t
Definition: SDL_malloc.c:1694
RTCHECK
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
smallbin_at
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
assert
#define assert(x)
Definition: SDL_malloc.c:1240
CORRUPTION_ERROR_ACTION
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2242
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
I
#define I(x, y, z)
Definition: SDL_test_md5.c:76
small_index
#define small_index(s)
Definition: SDL_malloc.c:2287
F
#define F(x, y, z)
Definition: SDL_test_md5.c:73
smallmap_is_marked
#define smallmap_is_marked(M, i)
Definition: SDL_malloc.c:2353
mark_smallmap
#define mark_smallmap(M, i)
Definition: SDL_malloc.c:2351
ok_address
#define ok_address(M, a)
Definition: SDL_malloc.c:2428

Definition at line 2991 of file SDL_malloc.c.

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

Definition at line 3225 of file SDL_malloc.c.

Referenced by internal_memalign(), and internal_realloc().

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

Definition at line 3224 of file SDL_malloc.c.

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

#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT)

Definition at line 1748 of file SDL_malloc.c.

Referenced by dlfree(), and dlmallopt().

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

Definition at line 1335 of file SDL_malloc.c.

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

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

Definition at line 1975 of file SDL_malloc.c.

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

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

Definition at line 2112 of file SDL_malloc.c.

Referenced by sys_alloc().

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

Definition at line 2145 of file SDL_malloc.c.

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

Definition at line 2113 of file SDL_malloc.c.

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

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

Definition at line 1784 of file SDL_malloc.c.

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

#define IS_MMAPPED_BIT (SIZE_T_ONE)

Definition at line 1363 of file SDL_malloc.c.

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

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

Definition at line 1974 of file SDL_malloc.c.

Referenced by release_unused_segments(), and sys_trim().

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

Definition at line 2143 of file SDL_malloc.c.

Referenced by sys_alloc().

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

Definition at line 2286 of file SDL_malloc.c.

Referenced by change_mparam(), and mmap_resize().

#define LACKS_ERRNO_H

Definition at line 520 of file SDL_malloc.c.

#define LACKS_FCNTL_H

Definition at line 521 of file SDL_malloc.c.

#define LACKS_STDIO_H

Definition at line 57 of file SDL_malloc.c.

#define LACKS_STDLIB_H

Definition at line 60 of file SDL_malloc.c.

#define LACKS_STRING_H

Definition at line 517 of file SDL_malloc.c.

#define LACKS_STRING_H

Definition at line 517 of file SDL_malloc.c.

#define LACKS_STRINGS_H

Definition at line 518 of file SDL_malloc.c.

#define LACKS_STRINGS_H

Definition at line 518 of file SDL_malloc.c.

#define LACKS_SYS_MMAN_H

Definition at line 516 of file SDL_malloc.c.

#define LACKS_SYS_PARAM_H

Definition at line 515 of file SDL_malloc.c.

#define LACKS_SYS_TYPES_H

Definition at line 519 of file SDL_malloc.c.

#define LACKS_SYS_TYPES_H

Definition at line 519 of file SDL_malloc.c.

#define LACKS_UNISTD_H

Definition at line 514 of file SDL_malloc.c.

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

Definition at line 2389 of file SDL_malloc.c.

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

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

Definition at line 2392 of file SDL_malloc.c.

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

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

Definition at line 1907 of file SDL_malloc.c.

Referenced by tmalloc_large(), and tmalloc_small().

#define leftshift_for_tree_index | ( |  | i | ) |

Value:
((i == NTREEBINS-1)? 0 : \
((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2)))
TREEBIN_SHIFT
#define TREEBIN_SHIFT
Definition: SDL_malloc.c:2060
NTREEBINS
#define NTREEBINS
Definition: SDL_malloc.c:2057
SIZE_T_BITSIZE
#define SIZE_T_BITSIZE
Definition: SDL_malloc.c:1319
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:42
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324

Definition at line 2335 of file SDL_malloc.c.

Referenced by change_mparam(), and tmalloc_large().

#define M_GRANULARITY (-2)

Definition at line 654 of file SDL_malloc.c.

Referenced by change_mparam().

#define M_MMAP_THRESHOLD (-3)

Definition at line 655 of file SDL_malloc.c.

Referenced by change_mparam().

#define M_TRIM_THRESHOLD (-1)

Definition at line 653 of file SDL_malloc.c.

Referenced by change_mparam().

#define MALLINFO_FIELD_TYPE size_t

Definition at line 636 of file SDL_malloc.c.

#define malloc SDL_malloc

Definition at line 641 of file SDL_malloc.c.

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

#define MALLOC_ALIGNMENT ((size_t)8U)

Definition at line 552 of file SDL_malloc.c.

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

#define MALLOC_FAILURE_ACTION

Definition at line 522 of file SDL_malloc.c.

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

#define mark_inuse_foot | ( |  | M,
|  |  | p,
|  |  | s
| ) |  |

Definition at line 2466 of file SDL_malloc.c.

Referenced by mmap_alloc(), and mmap_resize().

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

Definition at line 2351 of file SDL_malloc.c.

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

Definition at line 2355 of file SDL_malloc.c.

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

Definition at line 1724 of file SDL_malloc.c.

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

#define MAX_SIZE_T (~(size_t)0)

Definition at line 539 of file SDL_malloc.c.

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

#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)

Definition at line 2063 of file SDL_malloc.c.

Referenced by dlmalloc(), and dlmallopt().

#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE)

Definition at line 2062 of file SDL_malloc.c.

#define MCHUNK_SIZE (sizeof(mchunk))

Definition at line 1700 of file SDL_malloc.c.

Referenced by init_mparams().

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

Definition at line 1719 of file SDL_malloc.c.

Referenced by change_mparam(), dlcalloc(), dlfree(), dlmalloc_usable_size(), dlmallopt(), dlrealloc(), ialloc(), internal_memalign(), internal_realloc(), and sys_alloc().

#define memcpy SDL_memcpy

Definition at line 640 of file SDL_malloc.c.

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

#define memset SDL_memset

Definition at line 639 of file SDL_malloc.c.

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

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

Definition at line 1352 of file SDL_malloc.c.

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

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

Definition at line 1714 of file SDL_malloc.c.

Referenced by add_segment(), change_mparam(), dlmalloc(), dlmallopt(), init_mparams(), internal_memalign(), internal_realloc(), prepend_alloc(), tmalloc_large(), and tmalloc_small().

#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT)

Definition at line 2061 of file SDL_malloc.c.

Referenced by change_mparam().

#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)

Definition at line 1725 of file SDL_malloc.c.

Referenced by dlmalloc(), and dlmallopt().

#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE))

Definition at line 2289 of file SDL_malloc.c.

#define minsize_for_tree_index | ( |  | i | ) |

Value:
((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \
(((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1)))
TREEBIN_SHIFT
#define TREEBIN_SHIFT
Definition: SDL_malloc.c:2060
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:42
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324

Definition at line 2340 of file SDL_malloc.c.

Referenced by change_mparam().

#define MLOCK_T long

Definition at line 1492 of file SDL_malloc.c.

#define MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES)

Definition at line 1709 of file SDL_malloc.c.

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

Definition at line 523 of file SDL_malloc.c.

#define MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES)

Definition at line 1711 of file SDL_malloc.c.

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

#define MORECORE_CONTIGUOUS 0

Definition at line 596 of file SDL_malloc.c.

Referenced by sys_alloc().

#define MSPACES 0

Definition at line 548 of file SDL_malloc.c.

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

Definition at line 1766 of file SDL_malloc.c.

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

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

Definition at line 1770 of file SDL_malloc.c.

Referenced by change_mparam().

#define NO_MALLINFO 0

Definition at line 633 of file SDL_malloc.c.

#define NSMALLBINS (32U)

Definition at line 2056 of file SDL_malloc.c.

Referenced by change_mparam(), and init_bins().

#define NTREEBINS (32U)

Definition at line 2057 of file SDL_malloc.c.

Referenced by change_mparam(), and init_bins().

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

Definition at line 2428 of file SDL_malloc.c.

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

#define ok_cinuse | ( |  | p | ) | cinuse(p)

Definition at line 2432 of file SDL_malloc.c.

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

#define ok_magic | ( |  | M | ) | (1)

Definition at line 2447 of file SDL_malloc.c.

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

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

Definition at line 2430 of file SDL_malloc.c.

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

#define ok_pinuse | ( |  | p | ) | pinuse(p)

Definition at line 2434 of file SDL_malloc.c.

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

#define ONLY_MSPACES 0

Definition at line 542 of file SDL_malloc.c.

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

Definition at line 1788 of file SDL_malloc.c.

Referenced by dlmalloc_usable_size(), and internal_realloc().

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

Definition at line 1728 of file SDL_malloc.c.

Referenced by add_segment(), dlmalloc(), and dlmallopt().

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

Definition at line 2136 of file SDL_malloc.c.

Referenced by sys_alloc().

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

Definition at line 1755 of file SDL_malloc.c.

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

#define PINUSE_BIT (SIZE_T_ONE)

Definition at line 1746 of file SDL_malloc.c.

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

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

Definition at line 2207 of file SDL_malloc.c.

Referenced by dlfree(), dlmalloc(), dlmalloc_trim(), dlmallopt(), ialloc(), internal_mallinfo(), internal_malloc_stats(), internal_memalign(), and internal_realloc().

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

Definition at line 2206 of file SDL_malloc.c.

Referenced by dlfree(), dlmalloc(), dlmalloc_trim(), dlmallopt(), ialloc(), internal_mallinfo(), internal_malloc_stats(), internal_memalign(), and internal_realloc().

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

Definition at line 1767 of file SDL_malloc.c.

Referenced by change_mparam().

#define PROCEED_ON_ERROR 0

Definition at line 564 of file SDL_malloc.c.

#define realloc SDL_realloc

Definition at line 643 of file SDL_malloc.c.

#define RELEASE_LOCK | ( |  | l | ) | win32_release_lock(l)

Definition at line 1516 of file SDL_malloc.c.

#define RELEASE_MAGIC_INIT_LOCK | ( |  | ) | RELEASE_LOCK(&magic_init_mutex);

Definition at line 1539 of file SDL_malloc.c.

Referenced by init_mparams().

#define RELEASE_MORECORE_LOCK | ( |  | ) |

Definition at line 1534 of file SDL_malloc.c.

Referenced by sys_alloc(), and sys_trim().

#define replace_dv | ( |  | M,
|  |  | P,
|  |  | S
| ) |  |

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;\
}
assert
#define assert(x)
Definition: SDL_malloc.c:1240
size_t
unsigned int size_t
Definition: SDL_config_windows.h:67
insert_small_chunk
#define insert_small_chunk(M, P, S)
Definition: SDL_malloc.c:2991
is_small
#define is_small(s)
Definition: SDL_malloc.c:2286

Definition at line 3048 of file SDL_malloc.c.

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

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

Definition at line 1732 of file SDL_malloc.c.

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

#define RTCHECK | ( |  | e | ) | (e)

Definition at line 2456 of file SDL_malloc.c.

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

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

Definition at line 2395 of file SDL_malloc.c.

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

Definition at line 2149 of file SDL_malloc.c.

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

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

Definition at line 1774 of file SDL_malloc.c.

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

Definition at line 1781 of file SDL_malloc.c.

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

#define set_inuse | ( |  | M,
|  |  | p,
|  |  | s
| ) |  |

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

Definition at line 2469 of file SDL_malloc.c.

Referenced by internal_memalign(), and internal_realloc().

#define set_inuse_and_pinuse | ( |  | M,
|  |  | p,
|  |  | s
| ) |  |

Value:
((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\
((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)
s
GLdouble s
Definition: SDL_opengl.h:2056
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
CINUSE_BIT
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
head
SDL_EventEntry * head
Definition: SDL_events.c:79
PINUSE_BIT
#define PINUSE_BIT
Definition: SDL_malloc.c:1746

Definition at line 2474 of file SDL_malloc.c.

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

#define set_lock | ( |  | M,
|  |  | L
| ) |  |

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

Definition at line 2130 of file SDL_malloc.c.

Referenced by dlmallopt().

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

Definition at line 1777 of file SDL_malloc.c.

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

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

Definition at line 2479 of file SDL_malloc.c.

Referenced by add_segment(), dlmalloc(), dlmallopt(), ialloc(), prepend_alloc(), sys_alloc(), tmalloc_large(), and tmalloc_small().

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

Definition at line 2179 of file SDL_malloc.c.

Referenced by dlfree(), and dlmallopt().

#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES)

Definition at line 1328 of file SDL_malloc.c.

Referenced by mmap_alloc(), and mmap_resize().

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

Definition at line 1319 of file SDL_malloc.c.

Referenced by change_mparam(), and tmalloc_large().

#define SIZE_T_ONE ((size_t)1)

Definition at line 1324 of file SDL_malloc.c.

Referenced by change_mparam(), dlpvalloc(), init_mparams(), internal_mallinfo(), internal_memalign(), sys_alloc(), sys_trim(), and tmalloc_large().

#define SIZE_T_SIZE (sizeof(size_t))

Definition at line 1318 of file SDL_malloc.c.

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

#define SIZE_T_TWO ((size_t)2)

Definition at line 1325 of file SDL_malloc.c.

#define SIZE_T_ZERO ((size_t)0)

Definition at line 1323 of file SDL_malloc.c.

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

Definition at line 2287 of file SDL_malloc.c.

Referenced by change_mparam(), dlmalloc(), and dlmallopt().

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

Definition at line 2288 of file SDL_malloc.c.

Referenced by dlmalloc(), and dlmallopt().

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

Definition at line 2292 of file SDL_malloc.c.

Referenced by change_mparam(), dlmalloc(), dlmallopt(), and init_bins().

#define SMALLBIN_SHIFT (3U)

Definition at line 2058 of file SDL_malloc.c.

#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT)

Definition at line 2059 of file SDL_malloc.c.

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

Definition at line 2353 of file SDL_malloc.c.

Referenced by change_mparam().

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

Definition at line 2189 of file SDL_malloc.c.

Referenced by add_segment(), change_mparam(), dlmallopt(), init_top(), internal_mallinfo(), internal_malloc_stats(), release_unused_segments(), sys_alloc(), and sys_trim().

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

Definition at line 2293 of file SDL_malloc.c.

Referenced by change_mparam(), init_bins(), tmalloc_large(), and tmalloc_small().

#define TREEBIN_SHIFT (8U)

Definition at line 2060 of file SDL_malloc.c.

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

Definition at line 2357 of file SDL_malloc.c.

Referenced by change_mparam().

#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1)

Definition at line 1326 of file SDL_malloc.c.

#define unlink_chunk | ( |  | M,
|  |  | P,
|  |  | S
| ) |  |

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

Definition at line 3207 of file SDL_malloc.c.

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

#define unlink_first_small_chunk | ( |  | M,
|  |  | B,
|  |  | P,
|  |  | I
| ) |  |

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

Definition at line 3030 of file SDL_malloc.c.

Referenced by dlmalloc(), and dlmallopt().

#define unlink_large_chunk | ( |  | M,
|  |  | X
| ) |  |

Definition at line 3130 of file SDL_malloc.c.

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

#define unlink_small_chunk | ( |  | M,
|  |  | P,
|  |  | S
| ) |  |

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);\
}\
}
bindex_t
size_t bindex_t
Definition: SDL_malloc.c:1694
clear_smallmap
#define clear_smallmap(M, i)
Definition: SDL_malloc.c:2352
RTCHECK
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
smallbin_at
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
assert
#define assert(x)
Definition: SDL_malloc.c:1240
CORRUPTION_ERROR_ACTION
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2242
small_index2size
#define small_index2size(i)
Definition: SDL_malloc.c:2288
I
#define I(x, y, z)
Definition: SDL_test_md5.c:76
small_index
#define small_index(s)
Definition: SDL_malloc.c:2287
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
F
#define F(x, y, z)
Definition: SDL_test_md5.c:73
ok_address
#define ok_address(M, a)
Definition: SDL_malloc.c:2428

Definition at line 3010 of file SDL_malloc.c.

#define USAGE_ERROR_ACTION | ( |  | m,
|  |  | p
| ) |  | ABORT

Definition at line 2246 of file SDL_malloc.c.

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

#define USE_BUILTIN_FFS 0

Definition at line 627 of file SDL_malloc.c.

#define USE_DEV_RANDOM 0

Definition at line 630 of file SDL_malloc.c.

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

Definition at line 2119 of file SDL_malloc.c.

#define USE_LOCK_BIT (2U)

Definition at line 1523 of file SDL_malloc.c.

Referenced by init_mparams().

#define USE_LOCKS 1

Definition at line 62 of file SDL_malloc.c.

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

Definition at line 2123 of file SDL_malloc.c.

Referenced by change_mparam(), ialloc(), and sys_alloc().

#define USE_MMAP_BIT (SIZE_T_ONE)

Definition at line 1364 of file SDL_malloc.c.

Referenced by init_mparams().

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

Definition at line 2127 of file SDL_malloc.c.

Referenced by sys_alloc().

#define USE_NONCONTIGUOUS_BIT (4U)

Definition at line 1448 of file SDL_malloc.c.

Referenced by init_mparams().

#define WIN32 1

Definition at line 506 of file SDL_malloc.c.

#define WIN32_LEAN_AND_MEAN

Definition at line 510 of file SDL_malloc.c.

## Typedef Documentation

typedef size_t bindex_t

Definition at line 1694 of file SDL_malloc.c.

typedef unsigned int binmap_t

Definition at line 1695 of file SDL_malloc.c.

typedef unsigned int flag_t

Definition at line 1696 of file SDL_malloc.c.

## Function Documentation

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

static

Definition at line 3404 of file SDL_malloc.c.

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

Referenced by sys_alloc().

{
/* Determine locations and sizes of segment, fenceposts, old top */
char *old_top = (char *) m->top;
msegmentptr oldsp = segment_holding(m, old_top);
char *old_end = oldsp->base + oldsp->size;
size_t ssize = pad_request(sizeof(struct malloc_segment));
char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
size_t offset = align_offset(chunk2mem(rawsp));
char *asp = rawsp + offset;
char *csp = (asp < (old_top + MIN_CHUNK_SIZE)) ? old_top : asp;
mchunkptr sp = (mchunkptr) csp;
msegmentptr ss = (msegmentptr) (chunk2mem(sp));
mchunkptr tnext = chunk_plus_offset(sp, ssize);
mchunkptr p = tnext;
int nfences = 0;
/* reset top to new space */
init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
/* Set up segment record */
assert(is_aligned(ss));
set_size_and_pinuse_of_inuse_chunk(m, sp, ssize);
*ss = m->seg; /* Push current record */
m->seg.base = tbase;
m->seg.size = tsize;
m->seg.sflags = mmapped;
m->seg.next = ss;
/* Insert trailing fenceposts */
for (;;) {
mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);
p->head = FENCEPOST_HEAD;
++nfences;
if ((char *) (&(nextp->head)) < old_end)
p = nextp;
else
break;
}
assert(nfences >= 2);
/* Insert the rest of old top into a bin as an ordinary free chunk */
if (csp != old_top) {
mchunkptr q = (mchunkptr) old_top;
size_t psize = csp - old_top;
mchunkptr tn = chunk_plus_offset(q, psize);
set_free_with_pinuse(q, psize, tn);
insert_chunk(m, q, psize);
}
check_top_chunk(m, m->top);
}
insert_chunk
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3203
q
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2080
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
FENCEPOST_HEAD
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
set_free_with_pinuse
#define set_free_with_pinuse(p, s, n)
Definition: SDL_malloc.c:1781
assert
#define assert(x)
Definition: SDL_malloc.c:1240
SIZE_T_SIZE
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
FOUR_SIZE_T_SIZES
#define FOUR_SIZE_T_SIZES
Definition: SDL_malloc.c:1327
CHUNK_ALIGN_MASK
#define CHUNK_ALIGN_MASK
Definition: SDL_malloc.c:1332
malloc_segment
Definition: SDL_malloc.c:1966
is_aligned
#define is_aligned(A)
Definition: SDL_malloc.c:1335
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
init_top
static void init_top(mstate m, mchunkptr p, size_t psize)
Definition: SDL_malloc.c:3312
offset
GLintptr offset
Definition: SDL_opengl_glext.h:538
segment_holding
static msegmentptr segment_holding(mstate m, char *addr)
Definition: SDL_malloc.c:2154
pad_request
#define pad_request(req)
Definition: SDL_malloc.c:1728
align_offset
#define align_offset(A)
Definition: SDL_malloc.c:1338
TOP_FOOT_SIZE
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
check_top_chunk
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260
set_size_and_pinuse_of_inuse_chunk
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479

static int change_mparam | ( | int | param_number,
|  | int | value
| ) |  |

static

Definition at line 2590 of file SDL_malloc.c.

References align_as_chunk, assert, sbinptr::bk, chunk2mem, CHUNK_ALIGN_MASK, chunk_plus_offset, chunksize, cinuse, CINUSE_BIT, compute_tree_index, FENCEPOST_HEAD, mstate::footprint, malloc_params::granularity, head, i, init_mparams(), is_aligned, is_initialized, is_mmapped, IS_MMAPPED_BIT, is_small, leftshift_for_tree_index, M_GRANULARITY, M_MMAP_THRESHOLD, M_TRIM_THRESHOLD, mem2chunk, MIN_CHUNK_SIZE, MIN_LARGE_SIZE, minsize_for_tree_index, MMAP_FOOT_PAD, malloc_params::mmap_threshold, mparams, next_chunk, next_pinuse, NSMALLBINS, NTREEBINS, ok_address, malloc_params::page_size, pinuse, PINUSE_BIT, prev_chunk, segment_holding(), segment_holds, SIZE_T_BITSIZE, SIZE_T_ONE, SIZE_T_SIZE, small_index, smallbin_at, smallmap_is_marked, TOP_FOOT_SIZE, treebin_at, treemap_is_marked, malloc_params::trim_threshold, and use_mmap.

Referenced by dlmallopt().

{
size_t val = (size_t) value;
init_mparams();
switch (param_number) {
case M_TRIM_THRESHOLD:
mparams.trim_threshold = val;
return 1;
case M_GRANULARITY:
if (val >= mparams.page_size && ((val & (val - 1)) == 0)) {
mparams.granularity = val;
return 1;
} else
return 0;
case M_MMAP_THRESHOLD:
mparams.mmap_threshold = val;
return 1;
default:
return 0;
}
}
M_MMAP_THRESHOLD
#define M_MMAP_THRESHOLD
Definition: SDL_malloc.c:655
M_GRANULARITY
#define M_GRANULARITY
Definition: SDL_malloc.c:654
size_t
unsigned int size_t
Definition: SDL_config_windows.h:67
val
GLuint GLfloat * val
Definition: SDL_opengl_glext.h:1492
malloc_params::trim_threshold
size_t trim_threshold
Definition: SDL_malloc.c:2103
malloc_params::page_size
size_t page_size
Definition: SDL_malloc.c:2100
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
mparams
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
M_TRIM_THRESHOLD
#define M_TRIM_THRESHOLD
Definition: SDL_malloc.c:653
malloc_params::granularity
size_t granularity
Definition: SDL_malloc.c:2101
init_mparams
static int init_mparams(void)
Definition: SDL_malloc.c:2512
malloc_params::mmap_threshold
size_t mmap_threshold
Definition: SDL_malloc.c:2102

void * dlcalloc | ( | size_t | n_elements,
|  | size_t | elem_size
| ) |  |

Definition at line 4402 of file SDL_malloc.c.

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

{
void *mem;
size_t req = 0;
if (n_elements != 0) {
req = n_elements * elem_size;
if (((n_elements | elem_size) & ~(size_t) 0xffff) &&
(req / n_elements != elem_size))
req = MAX_SIZE_T; /* force downstream failure on overflow */
}
mem = dlmalloc(req);
if (mem != 0 && calloc_must_clear(mem2chunk(mem)))
memset(mem, 0, req);
return mem;
}
memset
#define memset
Definition: SDL_malloc.c:639
MAX_SIZE_T
#define MAX_SIZE_T
Definition: SDL_malloc.c:539
dlmalloc
#define dlmalloc
Definition: SDL_malloc.c:717
mem2chunk
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
calloc_must_clear
#define calloc_must_clear(p)
Definition: SDL_malloc.c:1795

void dlfree | ( | void * | mem | ) |

Definition at line 4305 of file SDL_malloc.c.

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

{
/*
Consolidate freed chunks with preceeding or succeeding bordering
free chunks, if they exist, and then place in a bin. Intermixed
with special cases for top, dv, mmapped chunks, and usage errors.
*/
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
#if FOOTERS
mstate fm = get_mstate_for(p);
if (!ok_magic(fm)) {
USAGE_ERROR_ACTION(fm, p);
return;
}
#else /* FOOTERS */
#define fm gm
#endif /* FOOTERS */
if (!PREACTION(fm)) {
check_inuse_chunk(fm, p);
if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) {
size_t psize = chunksize(p);
mchunkptr next = chunk_plus_offset(p, psize);
if (!pinuse(p)) {
size_t prevsize = p->prev_foot;
if ((prevsize & IS_MMAPPED_BIT) != 0) {
prevsize &= ~IS_MMAPPED_BIT;
psize += prevsize + MMAP_FOOT_PAD;
if (CALL_MUNMAP((char *) p - prevsize, psize) == 0)
fm->footprint -= psize;
goto postaction;
} else {
mchunkptr prev = chunk_minus_offset(p, prevsize);
psize += prevsize;
p = prev;
if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */
if (p != fm->dv) {
unlink_chunk(fm, p, prevsize);
} else if ((next->head & INUSE_BITS) ==
INUSE_BITS) {
fm->dvsize = psize;
set_free_with_pinuse(p, psize, next);
goto postaction;
}
} else
goto erroraction;
}
}
if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) {
if (!cinuse(next)) { /* consolidate forward */
if (next == fm->top) {
size_t tsize = fm->topsize += psize;
fm->top = p;
p->head = tsize | PINUSE_BIT;
if (p == fm->dv) {
fm->dv = 0;
fm->dvsize = 0;
}
if (should_trim(fm, tsize))
sys_trim(fm, 0);
goto postaction;
} else if (next == fm->dv) {
size_t dsize = fm->dvsize += psize;
fm->dv = p;
set_size_and_pinuse_of_free_chunk(p, dsize);
goto postaction;
} else {
size_t nsize = chunksize(next);
psize += nsize;
unlink_chunk(fm, next, nsize);
set_size_and_pinuse_of_free_chunk(p, psize);
if (p == fm->dv) {
fm->dvsize = psize;
goto postaction;
}
}
} else
set_free_with_pinuse(p, psize, next);
insert_chunk(fm, p, psize);
check_free_chunk(fm, p);
goto postaction;
}
}
erroraction:
USAGE_ERROR_ACTION(fm, p);
postaction:
POSTACTION(fm);
}
}
#if !FOOTERS
#undef fm
#endif /* FOOTERS */
}
USAGE_ERROR_ACTION
#define USAGE_ERROR_ACTION(m, p)
Definition: SDL_malloc.c:2246
POSTACTION
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
fm
#define fm
ok_cinuse
#define ok_cinuse(p)
Definition: SDL_malloc.c:2432
insert_chunk
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3203
cinuse
#define cinuse(p)
Definition: SDL_malloc.c:1754
RTCHECK
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
set_free_with_pinuse
#define set_free_with_pinuse(p, s, n)
Definition: SDL_malloc.c:1781
IS_MMAPPED_BIT
#define IS_MMAPPED_BIT
Definition: SDL_malloc.c:1363
ok_pinuse
#define ok_pinuse(p)
Definition: SDL_malloc.c:2434
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
CALL_MUNMAP
#define CALL_MUNMAP(a, s)
Definition: SDL_malloc.c:1430
INUSE_BITS
#define INUSE_BITS
Definition: SDL_malloc.c:1748
sys_trim
static int sys_trim(mstate m, size_t pad)
Definition: SDL_malloc.c:3702
check_inuse_chunk
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2256
unlink_chunk
#define unlink_chunk(M, P, S)
Definition: SDL_malloc.c:3207
ok_next
#define ok_next(p, n)
Definition: SDL_malloc.c:2430
chunk_minus_offset
#define chunk_minus_offset(p, s)
Definition: SDL_malloc.c:1763
should_trim
#define should_trim(M, s)
Definition: SDL_malloc.c:2179
PREACTION
#define PREACTION(M)
Definition: SDL_malloc.c:2206
mem2chunk
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
MMAP_FOOT_PAD
#define MMAP_FOOT_PAD
Definition: SDL_malloc.c:1711
set_size_and_pinuse_of_free_chunk
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
pinuse
#define pinuse(p)
Definition: SDL_malloc.c:1755
check_free_chunk
#define check_free_chunk(M, P)
Definition: SDL_malloc.c:2255
ok_address
#define ok_address(M, a)
Definition: SDL_malloc.c:2428
PINUSE_BIT
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
ok_magic
#define ok_magic(M)
Definition: SDL_malloc.c:2447

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

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

Definition at line 4450 of file SDL_malloc.c.

References gm, and ialloc().

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

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

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

Definition at line 4457 of file SDL_malloc.c.

References gm, and ialloc().

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

struct mallinfo dlmallinfo | ( | void |  | ) |

Definition at line 4506 of file SDL_malloc.c.

References gm, and internal_mallinfo().

{
return internal_mallinfo(gm);
}
gm
#define gm
Definition: SDL_malloc.c:2111
internal_mallinfo
static struct mallinfo internal_mallinfo(mstate m)
Definition: SDL_malloc.c:2905

void * dlmalloc | ( | size_t | bytes | ) |

Definition at line 4171 of file SDL_malloc.c.

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

{
/*
Basic algorithm:
If a small request (< 256 bytes minus per-chunk overhead):
1. If one exists, use a remainderless chunk in associated smallbin.
(Remainderless means that there are too few excess bytes to
represent as a chunk.)
2. If it is big enough, use the dv chunk, which is normally the
chunk adjacent to the one used for the most recent small request.
3. If one exists, split the smallest available chunk in a bin,
saving remainder in dv.
4. If it is big enough, use the top chunk.
5. If available, get memory from system and use it
Otherwise, for a large request:
1. Find the smallest available binned chunk that fits, and use it
if it is better fitting than dv chunk, splitting if necessary.
2. If better fitting than any binned chunk, use the dv chunk.
3. If it is big enough, use the top chunk.
4. If request size >= mmap threshold, try to directly mmap this chunk.
5. If available, get memory from system and use it
The ugly goto's here ensure that postaction occurs along all paths.
*/
if (!PREACTION(gm)) {
void *mem;
size_t nb;
if (bytes <= MAX_SMALL_REQUEST) {
bindex_t idx;
binmap_t smallbits;
nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes);
idx = small_index(nb);
smallbits = gm->smallmap >> idx;
if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */
mchunkptr b, p;
idx += ~smallbits & 1; /* Uses next bin if idx empty */
b = smallbin_at(gm, idx);
p = b->fd;
assert(chunksize(p) == small_index2size(idx));
unlink_first_small_chunk(gm, b, p, idx);
set_inuse_and_pinuse(gm, p, small_index2size(idx));
mem = chunk2mem(p);
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
else if (nb > gm->dvsize) {
if (smallbits != 0) { /* Use chunk in next nonempty smallbin */
mchunkptr b, p, r;
size_t rsize;
bindex_t i;
binmap_t leftbits =
(smallbits << idx) & left_bits(idx2bit(idx));
binmap_t leastbit = least_bit(leftbits);
compute_bit2idx(leastbit, i);
b = smallbin_at(gm, i);
p = b->fd;
assert(chunksize(p) == small_index2size(i));
unlink_first_small_chunk(gm, b, p, i);
rsize = small_index2size(i) - nb;
/* Fit here cannot be remainderless if 4byte sizes */
if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE)
set_inuse_and_pinuse(gm, p, small_index2size(i));
else {
set_size_and_pinuse_of_inuse_chunk(gm, p, nb);
r = chunk_plus_offset(p, nb);
set_size_and_pinuse_of_free_chunk(r, rsize);
replace_dv(gm, r, rsize);
}
mem = chunk2mem(p);
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
else if (gm->treemap != 0
&& (mem = tmalloc_small(gm, nb)) != 0) {
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
}
} else if (bytes >= MAX_REQUEST)
nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */
else {
nb = pad_request(bytes);
if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) {
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
}
if (nb <= gm->dvsize) {
size_t rsize = gm->dvsize - nb;
mchunkptr p = gm->dv;
if (rsize >= MIN_CHUNK_SIZE) { /* split dv */
mchunkptr r = gm->dv = chunk_plus_offset(p, nb);
gm->dvsize = rsize;
set_size_and_pinuse_of_free_chunk(r, rsize);
set_size_and_pinuse_of_inuse_chunk(gm, p, nb);
} else { /* exhaust dv */
size_t dvs = gm->dvsize;
gm->dvsize = 0;
gm->dv = 0;
set_inuse_and_pinuse(gm, p, dvs);
}
mem = chunk2mem(p);
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
else if (nb < gm->topsize) { /* Split top */
size_t rsize = gm->topsize -= nb;
mchunkptr p = gm->top;
mchunkptr r = gm->top = chunk_plus_offset(p, nb);
r->head = rsize | PINUSE_BIT;
set_size_and_pinuse_of_inuse_chunk(gm, p, nb);
mem = chunk2mem(p);
check_top_chunk(gm, gm->top);
check_malloced_chunk(gm, mem, nb);
goto postaction;
}
mem = sys_alloc(gm, nb);
postaction:
POSTACTION(gm);
return mem;
}
return 0;
}
POSTACTION
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
sys_alloc
static void * sys_alloc(mstate m, size_t nb)
Definition: SDL_malloc.c:3461
bindex_t
size_t bindex_t
Definition: SDL_malloc.c:1694
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
tmalloc_large
static void * tmalloc_large(mstate m, size_t nb)
Definition: SDL_malloc.c:3768
smallbin_at
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
replace_dv
#define replace_dv(M, P, S)
Definition: SDL_malloc.c:3048
compute_bit2idx
#define compute_bit2idx(X, I)
Definition: SDL_malloc.c:2374
assert
#define assert(x)
Definition: SDL_malloc.c:1240
SIZE_T_SIZE
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
small_index2size
#define small_index2size(i)
Definition: SDL_malloc.c:2288
MIN_REQUEST
#define MIN_REQUEST
Definition: SDL_malloc.c:1725
unlink_first_small_chunk
#define unlink_first_small_chunk(M, B, P, I)
Definition: SDL_malloc.c:3030
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
gm
#define gm
Definition: SDL_malloc.c:2111
tmalloc_small
static void * tmalloc_small(mstate m, size_t nb)
Definition: SDL_malloc.c:3843
MAX_SIZE_T
#define MAX_SIZE_T
Definition: SDL_malloc.c:539
idx2bit
#define idx2bit(i)
Definition: SDL_malloc.c:2348
MAX_SMALL_REQUEST
#define MAX_SMALL_REQUEST
Definition: SDL_malloc.c:2063
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:42
PREACTION
#define PREACTION(M)
Definition: SDL_malloc.c:2206
check_malloced_chunk
#define check_malloced_chunk(M, P, N)
Definition: SDL_malloc.c:2257
left_bits
#define left_bits(x)
Definition: SDL_malloc.c:2392
MAX_REQUEST
#define MAX_REQUEST
Definition: SDL_malloc.c:1724
small_index
#define small_index(s)
Definition: SDL_malloc.c:2287
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
binmap_t
unsigned int binmap_t
Definition: SDL_malloc.c:1695
pad_request
#define pad_request(req)
Definition: SDL_malloc.c:1728
set_size_and_pinuse_of_free_chunk
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1109
least_bit
#define least_bit(x)
Definition: SDL_malloc.c:2389
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
PINUSE_BIT
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
check_top_chunk
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260
set_size_and_pinuse_of_inuse_chunk
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
set_inuse_and_pinuse
#define set_inuse_and_pinuse(M, p, s)
Definition: SDL_malloc.c:2474

size_t dlmalloc_footprint | ( | void |  | ) |

Definition at line 4493 of file SDL_malloc.c.

References gm.

{
return gm->footprint;
}
gm
#define gm
Definition: SDL_malloc.c:2111

size_t dlmalloc_max_footprint | ( | void |  | ) |

Definition at line 4499 of file SDL_malloc.c.

References gm.

{
return gm->max_footprint;
}
gm
#define gm
Definition: SDL_malloc.c:2111

void dlmalloc_stats | ( | void |  | ) |

Definition at line 4513 of file SDL_malloc.c.

References gm, and internal_malloc_stats().

{
internal_malloc_stats(gm);
}
gm
#define gm
Definition: SDL_malloc.c:2111
internal_malloc_stats
static void internal_malloc_stats(mstate m)
Definition: SDL_malloc.c:2946

int dlmalloc_trim | ( | size_t | pad | ) |

Definition at line 4482 of file SDL_malloc.c.

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

{
int result = 0;
if (!PREACTION(gm)) {
result = sys_trim(gm, pad);
POSTACTION(gm);
}
return result;
}
POSTACTION
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
sys_trim
static int sys_trim(mstate m, size_t pad)
Definition: SDL_malloc.c:3702
gm
#define gm
Definition: SDL_malloc.c:2111
PREACTION
#define PREACTION(M)
Definition: SDL_malloc.c:2206

size_t dlmalloc_usable_size | ( | void * | mem | ) |

Definition at line 4519 of file SDL_malloc.c.

References chunksize, cinuse, mem2chunk, and overhead_for.

{
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
if (cinuse(p))
return chunksize(p) - overhead_for(p);
}
return 0;
}
cinuse
#define cinuse(p)
Definition: SDL_malloc.c:1754
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
mem2chunk
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
overhead_for
#define overhead_for(p)
Definition: SDL_malloc.c:1788

int dlmallopt | ( | int | param_number,
|  | int | value
| ) |  |

Definition at line 4530 of file SDL_malloc.c.

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

{
return change_mparam(param_number, value);
}
change_mparam
static int change_mparam(int param_number, int value)
Definition: SDL_malloc.c:2590
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698

void * dlmemalign | ( | size_t | alignment,
|  | size_t | bytes
| ) |  |

Definition at line 4444 of file SDL_malloc.c.

References gm, and internal_memalign().

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

void * dlpvalloc | ( | size_t | bytes | ) |

Definition at line 4472 of file SDL_malloc.c.

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

{
size_t pagesz;
init_mparams();
pagesz = mparams.page_size;
return dlmemalign(pagesz,
(bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE));
}
dlmemalign
#define dlmemalign
Definition: SDL_malloc.c:718
malloc_params::page_size
size_t page_size
Definition: SDL_malloc.c:2100
mparams
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
init_mparams
static int init_mparams(void)
Definition: SDL_malloc.c:2512
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324

void * dlrealloc | ( | void * | oldmem,
|  | size_t | bytes
| ) |  |

Definition at line 4419 of file SDL_malloc.c.

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

{
if (oldmem == 0)
return dlmalloc(bytes);
#ifdef REALLOC_ZERO_BYTES_FREES
if (bytes == 0) {
dlfree(oldmem);
return 0;
}
#endif /* REALLOC_ZERO_BYTES_FREES */
else {
#if ! FOOTERS
mstate m = gm;
#else /* FOOTERS */
mstate m = get_mstate_for(mem2chunk(oldmem));
if (!ok_magic(m)) {
USAGE_ERROR_ACTION(m, oldmem);
return 0;
}
#endif /* FOOTERS */
return internal_realloc(m, oldmem, bytes);
}
}
USAGE_ERROR_ACTION
#define USAGE_ERROR_ACTION(m, p)
Definition: SDL_malloc.c:2246
internal_realloc
static void * internal_realloc(mstate m, void *oldmem, size_t bytes)
Definition: SDL_malloc.c:3885
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
gm
#define gm
Definition: SDL_malloc.c:2111
dlmalloc
#define dlmalloc
Definition: SDL_malloc.c:717
dlfree
#define dlfree
Definition: SDL_malloc.c:716
mem2chunk
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
ok_magic
#define ok_magic(M)
Definition: SDL_malloc.c:2447

void * dlvalloc | ( | size_t | bytes | ) |

Definition at line 4463 of file SDL_malloc.c.

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

{
size_t pagesz;
init_mparams();
pagesz = mparams.page_size;
return dlmemalign(pagesz, bytes);
}
dlmemalign
#define dlmemalign
Definition: SDL_malloc.c:718
malloc_params::page_size
size_t page_size
Definition: SDL_malloc.c:2100
mparams
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
init_mparams
static int init_mparams(void)
Definition: SDL_malloc.c:2512

static int has_segment_link | ( | mstate | m,
|  | msegmentptr | ss
| ) |  |

static

Definition at line 2167 of file SDL_malloc.c.

Referenced by sys_trim().

{
msegmentptr sp = &m->seg;
for (;;) {
if ((char *) sp >= ss->base && (char *) sp < ss->base + ss->size)
return 1;
if ((sp = sp->next) == 0)
return 0;
}
}
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092

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

static

Definition at line 4045 of file SDL_malloc.c.

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

Referenced by dlindependent_calloc(), dlindependent_comalloc(), and dlmallopt().

{
/*
This provides common support for independent_X routines, handling
all of the combinations that can result.
The opts arg has:
bit 0 set if all elements are same size (using sizes[0])
bit 1 set if elements should be zeroed
*/
size_t element_size; /* chunksize of each element, if all same */
size_t contents_size; /* total size of elements */
size_t array_size; /* request size of pointer array */
void *mem; /* malloced aggregate space */
mchunkptr p; /* corresponding chunk */
size_t remainder_size; /* remaining bytes while splitting */
void **marray; /* either "chunks" or malloced ptr array */
mchunkptr array_chunk; /* chunk for malloced ptr array */
flag_t was_enabled; /* to disable mmap */
size_t size;
size_t i;
/* compute array length, if needed */
if (chunks != 0) {
if (n_elements == 0)
return chunks; /* nothing to do */
marray = chunks;
array_size = 0;
} else {
/* if empty req, must still return chunk representing empty array */
if (n_elements == 0)
return (void **) internal_malloc(m, 0);
marray = 0;
array_size = request2size(n_elements * (sizeof(void *)));
}
/* compute total element size */
if (opts & 0x1) { /* all-same-size */
element_size = request2size(*sizes);
contents_size = n_elements * element_size;
} else { /* add up all the sizes */
element_size = 0;
contents_size = 0;
for (i = 0; i != n_elements; ++i)
contents_size += request2size(sizes[i]);
}
size = contents_size + array_size;
/*
Allocate the aggregate chunk. First disable direct-mmapping so
malloc won't use it, since we would not be able to later
free/realloc space internal to a segregated mmap region.
*/
was_enabled = use_mmap(m);
disable_mmap(m);
mem = internal_malloc(m, size - CHUNK_OVERHEAD);
if (was_enabled)
enable_mmap(m);
if (mem == 0)
return 0;
if (PREACTION(m))
return 0;
p = mem2chunk(mem);
remainder_size = chunksize(p);
assert(!is_mmapped(p));
if (opts & 0x2) { /* optionally clear the elements */
memset((size_t *) mem, 0, remainder_size - SIZE_T_SIZE - array_size);
}
/* If not provided, allocate the pointer array as final part of chunk */
if (marray == 0) {
size_t array_chunk_size;
array_chunk = chunk_plus_offset(p, contents_size);
array_chunk_size = remainder_size - contents_size;
marray = (void **) (chunk2mem(array_chunk));
set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size);
remainder_size = contents_size;
}
/* split out elements */
for (i = 0;; ++i) {
marray[i] = chunk2mem(p);
if (i != n_elements - 1) {
if (element_size != 0)
size = element_size;
else
size = request2size(sizes[i]);
remainder_size -= size;
set_size_and_pinuse_of_inuse_chunk(m, p, size);
p = chunk_plus_offset(p, size);
} else { /* the final element absorbs any overallocation slop */
set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size);
break;
}
}
#if DEBUG
if (marray != chunks) {
/* final element must have exactly exhausted chunk */
if (element_size != 0) {
assert(remainder_size == element_size);
} else {
assert(remainder_size == request2size(sizes[i]));
}
check_inuse_chunk(m, mem2chunk(marray));
}
for (i = 0; i != n_elements; ++i)
check_inuse_chunk(m, mem2chunk(marray[i]));
#endif /* DEBUG */
POSTACTION(m);
return marray;
}
POSTACTION
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
request2size
#define request2size(req)
Definition: SDL_malloc.c:1732
x1
GLuint GLfloat GLfloat GLfloat x1
Definition: SDL_opengl_glext.h:8583
flag_t
unsigned int flag_t
Definition: SDL_malloc.c:1696
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
memset
#define memset
Definition: SDL_malloc.c:639
assert
#define assert(x)
Definition: SDL_malloc.c:1240
SIZE_T_SIZE
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
x2
GLfixed GLfixed x2
Definition: SDL_opengl_glext.h:4583
CHUNK_OVERHEAD
#define CHUNK_OVERHEAD
Definition: SDL_malloc.c:1705
check_inuse_chunk
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2256
sizes
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: SDL_opengl_glext.h:2561
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:42
PREACTION
#define PREACTION(M)
Definition: SDL_malloc.c:2206
enable_mmap
#define enable_mmap(M)
Definition: SDL_malloc.c:2124
mem2chunk
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
use_mmap
#define use_mmap(M)
Definition: SDL_malloc.c:2123
internal_malloc
#define internal_malloc(m, b)
Definition: SDL_malloc.c:3224
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
disable_mmap
#define disable_mmap(M)
Definition: SDL_malloc.c:2125
is_mmapped
#define is_mmapped(p)
Definition: SDL_malloc.c:1784
set_size_and_pinuse_of_inuse_chunk
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479

static void init_bins | ( | mstate | m | ) |

static

Definition at line 3329 of file SDL_malloc.c.

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

Referenced by dlmallopt(), and sys_alloc().

{
/* Establish circular links for smallbins */
bindex_t i;
for (i = 0; i < NSMALLBINS; ++i) {
sbinptr bin = smallbin_at(m, i);
bin->fd = bin->bk = bin;
}
}
bindex_t
size_t bindex_t
Definition: SDL_malloc.c:1694
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
smallbin_at
#define smallbin_at(M, i)
Definition: SDL_malloc.c:2292
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:42
NSMALLBINS
#define NSMALLBINS
Definition: SDL_malloc.c:2056

static int init_mparams | ( | void |  | ) |

static

Definition at line 2512 of file SDL_malloc.c.

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

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

{
if (mparams.page_size == 0) {
size_t s;
mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD;
mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD;
#if MORECORE_CONTIGUOUS
mparams.default_mflags = USE_LOCK_BIT | USE_MMAP_BIT;
#else /* MORECORE_CONTIGUOUS */
mparams.default_mflags =
USE_LOCK_BIT | USE_MMAP_BIT | USE_NONCONTIGUOUS_BIT;
#endif /* MORECORE_CONTIGUOUS */
#if (FOOTERS && !INSECURE)
{
#if USE_DEV_RANDOM
int fd;
unsigned char buf[sizeof(size_t)];
/* Try to use /dev/urandom, else fall back on using time */
if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 &&
read(fd, buf, sizeof(buf)) == sizeof(buf)) {
s = *((size_t *) buf);
close(fd);
} else
#endif /* USE_DEV_RANDOM */
s = (size_t) (time(0) ^ (size_t) 0x55555555U);
s |= (size_t) 8U; /* ensure nonzero */
s &= ~(size_t) 7U; /* improve chances of fault for bad values */
}
#else /* (FOOTERS && !INSECURE) */
s = (size_t) 0x58585858U;
#endif /* (FOOTERS && !INSECURE) */
ACQUIRE_MAGIC_INIT_LOCK();
if (mparams.magic == 0) {
mparams.magic = s;
/* Set up lock for main malloc area */
INITIAL_LOCK(&gm->mutex);
gm->mflags = mparams.default_mflags;
}
RELEASE_MAGIC_INIT_LOCK();
#ifndef WIN32
mparams.page_size = malloc_getpagesize;
mparams.granularity = ((DEFAULT_GRANULARITY != 0) ?
DEFAULT_GRANULARITY : mparams.page_size);
#else /* WIN32 */
{
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
mparams.page_size = system_info.dwPageSize;
mparams.granularity = system_info.dwAllocationGranularity;
}
#endif /* WIN32 */
/* Sanity-check configuration:
size_t must be unsigned and as wide as pointer type.
ints must be at least 4 bytes.
alignment must be at least 8.
Alignment, min chunk size, and page size must all be powers of 2.
*/
if ((sizeof(size_t) != sizeof(char *)) ||
(MAX_SIZE_T < MIN_CHUNK_SIZE) ||
(sizeof(int) < 4) ||
(MALLOC_ALIGNMENT < (size_t) 8U) ||
((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT - SIZE_T_ONE)) != 0) ||
((MCHUNK_SIZE & (MCHUNK_SIZE - SIZE_T_ONE)) != 0) ||
((mparams.granularity & (mparams.granularity - SIZE_T_ONE)) != 0)
|| ((mparams.page_size & (mparams.page_size - SIZE_T_ONE)) != 0))
ABORT;
}
return 0;
}
DEFAULT_MMAP_THRESHOLD
#define DEFAULT_MMAP_THRESHOLD
Definition: SDL_malloc.c:621
INITIAL_LOCK
#define INITIAL_LOCK(l)
Definition: SDL_malloc.c:1514
malloc_params::default_mflags
flag_t default_mflags
Definition: SDL_malloc.c:2104
ACQUIRE_MAGIC_INIT_LOCK
#define ACQUIRE_MAGIC_INIT_LOCK()
Definition: SDL_malloc.c:1538
s
GLdouble s
Definition: SDL_opengl.h:2056
DEFAULT_TRIM_THRESHOLD
#define DEFAULT_TRIM_THRESHOLD
Definition: SDL_malloc.c:614
ABORT
#define ABORT
Definition: SDL_malloc.c:61
MCHUNK_SIZE
#define MCHUNK_SIZE
Definition: SDL_malloc.c:1700
USE_NONCONTIGUOUS_BIT
#define USE_NONCONTIGUOUS_BIT
Definition: SDL_malloc.c:1448
size_t
unsigned int size_t
Definition: SDL_config_windows.h:67
malloc_params::trim_threshold
size_t trim_threshold
Definition: SDL_malloc.c:2103
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
malloc_params::page_size
size_t page_size
Definition: SDL_malloc.c:2100
mparams
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
gm
#define gm
Definition: SDL_malloc.c:2111
USE_MMAP_BIT
#define USE_MMAP_BIT
Definition: SDL_malloc.c:1364
MALLOC_ALIGNMENT
#define MALLOC_ALIGNMENT
Definition: SDL_malloc.c:552
MAX_SIZE_T
#define MAX_SIZE_T
Definition: SDL_malloc.c:539
malloc_params::magic
size_t magic
Definition: SDL_malloc.c:2099
DEFAULT_GRANULARITY
#define DEFAULT_GRANULARITY
Definition: SDL_malloc.c:609
buf
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: SDL_opengl_glext.h:2480
RELEASE_MAGIC_INIT_LOCK
#define RELEASE_MAGIC_INIT_LOCK()
Definition: SDL_malloc.c:1539
malloc_params::granularity
size_t granularity
Definition: SDL_malloc.c:2101
USE_LOCK_BIT
#define USE_LOCK_BIT
Definition: SDL_malloc.c:1523
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
malloc_params::mmap_threshold
size_t mmap_threshold
Definition: SDL_malloc.c:2102

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

static

Definition at line 3312 of file SDL_malloc.c.

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

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

{
/* Ensure alignment */
size_t offset = align_offset(chunk2mem(p));
p = (mchunkptr) ((char *) p + offset);
psize -= offset;
m->top = p;
m->topsize = psize;
p->head = psize | PINUSE_BIT;
/* set size of fake trailing chunk holding overhead space only once */
chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
m->trim_check = mparams.trim_threshold; /* reset on each update */
}
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
malloc_params::trim_threshold
size_t trim_threshold
Definition: SDL_malloc.c:2103
mparams
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
offset
GLintptr offset
Definition: SDL_opengl_glext.h:538
align_offset
#define align_offset(A)
Definition: SDL_malloc.c:1338
TOP_FOOT_SIZE
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
PINUSE_BIT
#define PINUSE_BIT
Definition: SDL_malloc.c:1746

static struct mallinfo internal_mallinfo | ( | mstate | m | ) |

static

Definition at line 2905 of file SDL_malloc.c.

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

Referenced by dlmallinfo(), and dlmallopt().

{
struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
if (!PREACTION(m)) {
check_malloc_state(m);
if (is_initialized(m)) {
size_t nfree = SIZE_T_ONE; /* top always free */
size_t mfree = m->topsize + TOP_FOOT_SIZE;
size_t sum = mfree;
msegmentptr s = &m->seg;
while (s != 0) {
mchunkptr q = align_as_chunk(s->base);
while (segment_holds(s, q) &&
q != m->top && q->head != FENCEPOST_HEAD) {
size_t sz = chunksize(q);
sum += sz;
if (!cinuse(q)) {
mfree += sz;
++nfree;
}
q = next_chunk(q);
}
s = s->next;
}
nm.arena = sum;
nm.ordblks = nfree;
nm.hblkhd = m->footprint - sum;
nm.usmblks = m->max_footprint;
nm.uordblks = m->footprint - mfree;
nm.fordblks = mfree;
nm.keepcost = m->topsize;
}
POSTACTION(m);
}
return nm;
}
next_chunk
#define next_chunk(p)
Definition: SDL_malloc.c:1766
POSTACTION
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
mallinfo::arena
MALLINFO_FIELD_TYPE arena
Definition: SDL_malloc.c:690
s
GLdouble s
Definition: SDL_opengl.h:2056
q
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2080
cinuse
#define cinuse(p)
Definition: SDL_malloc.c:1754
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
FENCEPOST_HEAD
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
is_initialized
#define is_initialized(M)
Definition: SDL_malloc.c:2113
mallinfo::ordblks
MALLINFO_FIELD_TYPE ordblks
Definition: SDL_malloc.c:691
mallinfo::fordblks
MALLINFO_FIELD_TYPE fordblks
Definition: SDL_malloc.c:698
align_as_chunk
#define align_as_chunk(A)
Definition: SDL_malloc.c:1721
PREACTION
#define PREACTION(M)
Definition: SDL_malloc.c:2206
check_malloc_state
#define check_malloc_state(M)
Definition: SDL_malloc.c:2259
mallinfo::keepcost
MALLINFO_FIELD_TYPE keepcost
Definition: SDL_malloc.c:699
segment_holds
#define segment_holds(S, A)
Definition: SDL_malloc.c:2149
mallinfo::hblkhd
MALLINFO_FIELD_TYPE hblkhd
Definition: SDL_malloc.c:694
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
mallinfo
Definition: SDL_malloc.c:688
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
TOP_FOOT_SIZE
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
mallinfo::uordblks
MALLINFO_FIELD_TYPE uordblks
Definition: SDL_malloc.c:697
mallinfo::usmblks
MALLINFO_FIELD_TYPE usmblks
Definition: SDL_malloc.c:695

static void internal_malloc_stats | ( | mstate | m | ) |

static

Definition at line 2946 of file SDL_malloc.c.

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

Referenced by dlmalloc_stats(), and dlmallopt().

{
if (!PREACTION(m)) {
size_t maxfp = 0;
size_t fp = 0;
size_t used = 0;
check_malloc_state(m);
if (is_initialized(m)) {
msegmentptr s = &m->seg;
maxfp = m->max_footprint;
fp = m->footprint;
used = fp - (m->topsize + TOP_FOOT_SIZE);
while (s != 0) {
mchunkptr q = align_as_chunk(s->base);
while (segment_holds(s, q) &&
q != m->top && q->head != FENCEPOST_HEAD) {
if (!cinuse(q))
used -= chunksize(q);
q = next_chunk(q);
}
s = s->next;
}
}
#ifndef LACKS_STDIO_H
fprintf(stderr, "max system bytes = %10lu\n",
(unsigned long) (maxfp));
fprintf(stderr, "system bytes = %10lu\n", (unsigned long) (fp));
fprintf(stderr, "in use bytes = %10lu\n", (unsigned long) (used));
#endif
POSTACTION(m);
}
}
next_chunk
#define next_chunk(p)
Definition: SDL_malloc.c:1766
POSTACTION
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
s
GLdouble s
Definition: SDL_opengl.h:2056
q
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2080
cinuse
#define cinuse(p)
Definition: SDL_malloc.c:1754
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
FENCEPOST_HEAD
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
is_initialized
#define is_initialized(M)
Definition: SDL_malloc.c:2113
align_as_chunk
#define align_as_chunk(A)
Definition: SDL_malloc.c:1721
PREACTION
#define PREACTION(M)
Definition: SDL_malloc.c:2206
check_malloc_state
#define check_malloc_state(M)
Definition: SDL_malloc.c:2259
segment_holds
#define segment_holds(S, A)
Definition: SDL_malloc.c:2149
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
TOP_FOOT_SIZE
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189

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

static

Definition at line 3955 of file SDL_malloc.c.

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

Referenced by dlmallopt(), and dlmemalign().

{
if (alignment <= MALLOC_ALIGNMENT) /* Can just use malloc */
return internal_malloc(m, bytes);
if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */
alignment = MIN_CHUNK_SIZE;
if ((alignment & (alignment - SIZE_T_ONE)) != 0) { /* Ensure a power of 2 */
size_t a = MALLOC_ALIGNMENT << 1;
while (a < alignment)
a <<= 1;
alignment = a;
}
if (bytes >= MAX_REQUEST - alignment) {
if (m != 0) { /* Test isn't needed but avoids compiler warning */
MALLOC_FAILURE_ACTION;
}
} else {
size_t nb = request2size(bytes);
size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD;
char *mem = (char *) internal_malloc(m, req);
if (mem != 0) {
void *leader = 0;
void *trailer = 0;
mchunkptr p = mem2chunk(mem);
if (PREACTION(m))
return 0;
if ((((size_t) (mem)) % alignment) != 0) { /* misaligned */
/*
Find an aligned spot inside chunk. Since we need to give
back leading space in a chunk of at least MIN_CHUNK_SIZE, if
the first calculation places us at a spot with less than
MIN_CHUNK_SIZE leader, we can move to the next aligned spot.
We've allocated enough total room so that this is always
possible.
*/
char *br = (char *) mem2chunk((size_t) (((size_t) (mem +
alignment -
SIZE_T_ONE))
& -alignment));
char *pos =
((size_t) (br - (char *) (p)) >=
MIN_CHUNK_SIZE) ? br : br + alignment;
mchunkptr newp = (mchunkptr) pos;
size_t leadsize = pos - (char *) (p);
size_t newsize = chunksize(p) - leadsize;
if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */
newp->prev_foot = p->prev_foot + leadsize;
newp->head = (newsize | CINUSE_BIT);
} else { /* Otherwise, give back leader, use the rest */
set_inuse(m, newp, newsize);
set_inuse(m, p, leadsize);
leader = chunk2mem(p);
}
p = newp;
}
/* Give back spare room at the end */
if (!is_mmapped(p)) {
size_t size = chunksize(p);
if (size > nb + MIN_CHUNK_SIZE) {
size_t remainder_size = size - nb;
mchunkptr remainder = chunk_plus_offset(p, nb);
set_inuse(m, p, nb);
set_inuse(m, remainder, remainder_size);
trailer = chunk2mem(remainder);
}
}
assert(chunksize(p) >= nb);
assert((((size_t) (chunk2mem(p))) % alignment) == 0);
check_inuse_chunk(m, p);
POSTACTION(m);
if (leader != 0) {
internal_free(m, leader);
}
if (trailer != 0) {
internal_free(m, trailer);
}
return chunk2mem(p);
}
}
return 0;
}
POSTACTION
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
request2size
#define request2size(req)
Definition: SDL_malloc.c:1732
MALLOC_FAILURE_ACTION
#define MALLOC_FAILURE_ACTION
Definition: SDL_malloc.c:522
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
assert
#define assert(x)
Definition: SDL_malloc.c:1240
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
CHUNK_OVERHEAD
#define CHUNK_OVERHEAD
Definition: SDL_malloc.c:1705
size_t
unsigned int size_t
Definition: SDL_config_windows.h:67
check_inuse_chunk
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2256
CINUSE_BIT
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
set_inuse
#define set_inuse(M, p, s)
Definition: SDL_malloc.c:2469
MALLOC_ALIGNMENT
#define MALLOC_ALIGNMENT
Definition: SDL_malloc.c:552
PREACTION
#define PREACTION(M)
Definition: SDL_malloc.c:2206
MAX_REQUEST
#define MAX_REQUEST
Definition: SDL_malloc.c:1724
mem2chunk
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
internal_free
#define internal_free(m, mem)
Definition: SDL_malloc.c:3225
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1109
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
internal_malloc
#define internal_malloc(m, b)
Definition: SDL_malloc.c:3224
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
is_mmapped
#define is_mmapped(p)
Definition: SDL_malloc.c:1784

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

static

Definition at line 3885 of file SDL_malloc.c.

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

Referenced by dlmallopt(), and dlrealloc().

{
if (bytes >= MAX_REQUEST) {
MALLOC_FAILURE_ACTION;
return 0;
}
if (!PREACTION(m)) {
mchunkptr oldp = mem2chunk(oldmem);
size_t oldsize = chunksize(oldp);
mchunkptr next = chunk_plus_offset(oldp, oldsize);
mchunkptr newp = 0;
void *extra = 0;
/* Try to either shrink or extend into top. Else malloc-copy-free */
if (RTCHECK(ok_address(m, oldp) && ok_cinuse(oldp) &&
ok_next(oldp, next) && ok_pinuse(next))) {
size_t nb = request2size(bytes);
if (is_mmapped(oldp))
newp = mmap_resize(m, oldp, nb);
else if (oldsize >= nb) { /* already big enough */
size_t rsize = oldsize - nb;
newp = oldp;
if (rsize >= MIN_CHUNK_SIZE) {
mchunkptr remainder = chunk_plus_offset(newp, nb);
set_inuse(m, newp, nb);
set_inuse(m, remainder, rsize);
extra = chunk2mem(remainder);
}
} else if (next == m->top && oldsize + m->topsize > nb) {
/* Expand into top */
size_t newsize = oldsize + m->topsize;
size_t newtopsize = newsize - nb;
mchunkptr newtop = chunk_plus_offset(oldp, nb);
set_inuse(m, oldp, nb);
newtop->head = newtopsize | PINUSE_BIT;
m->top = newtop;
m->topsize = newtopsize;
newp = oldp;
}
} else {
USAGE_ERROR_ACTION(m, oldmem);
POSTACTION(m);
return 0;
}
POSTACTION(m);
if (newp != 0) {
if (extra != 0) {
internal_free(m, extra);
}
check_inuse_chunk(m, newp);
return chunk2mem(newp);
} else {
void *newmem = internal_malloc(m, bytes);
if (newmem != 0) {
size_t oc = oldsize - overhead_for(oldp);
memcpy(newmem, oldmem, (oc < bytes) ? oc : bytes);
internal_free(m, oldmem);
}
return newmem;
}
}
return 0;
}
USAGE_ERROR_ACTION
#define USAGE_ERROR_ACTION(m, p)
Definition: SDL_malloc.c:2246
POSTACTION
#define POSTACTION(M)
Definition: SDL_malloc.c:2207
request2size
#define request2size(req)
Definition: SDL_malloc.c:1732
ok_cinuse
#define ok_cinuse(p)
Definition: SDL_malloc.c:2432
MALLOC_FAILURE_ACTION
#define MALLOC_FAILURE_ACTION
Definition: SDL_malloc.c:522
RTCHECK
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
ok_pinuse
#define ok_pinuse(p)
Definition: SDL_malloc.c:2434
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
mmap_resize
static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb)
Definition: SDL_malloc.c:3273
check_inuse_chunk
#define check_inuse_chunk(M, P)
Definition: SDL_malloc.c:2256
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
set_inuse
#define set_inuse(M, p, s)
Definition: SDL_malloc.c:2469
ok_next
#define ok_next(p, n)
Definition: SDL_malloc.c:2430
PREACTION
#define PREACTION(M)
Definition: SDL_malloc.c:2206
memcpy
#define memcpy
Definition: SDL_malloc.c:640
MAX_REQUEST
#define MAX_REQUEST
Definition: SDL_malloc.c:1724
mem2chunk
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
internal_free
#define internal_free(m, mem)
Definition: SDL_malloc.c:3225
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
overhead_for
#define overhead_for(p)
Definition: SDL_malloc.c:1788
internal_malloc
#define internal_malloc(m, b)
Definition: SDL_malloc.c:3224
ok_address
#define ok_address(M, a)
Definition: SDL_malloc.c:2428
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
PINUSE_BIT
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
is_mmapped
#define is_mmapped(p)
Definition: SDL_malloc.c:1784

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

static

Definition at line 3243 of file SDL_malloc.c.

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

Referenced by sys_alloc().

{
size_t mmsize =
granularity_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
if (mmsize > nb) { /* Check for wrap around 0 */
char *mm = (char *) (DIRECT_MMAP(mmsize));
if (mm != CMFAIL) {
size_t offset = align_offset(chunk2mem(mm));
size_t psize = mmsize - offset - MMAP_FOOT_PAD;
mchunkptr p = (mchunkptr) (mm + offset);
p->prev_foot = offset | IS_MMAPPED_BIT;
(p)->head = (psize | CINUSE_BIT);
mark_inuse_foot(m, p, psize);
chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;
chunk_plus_offset(p, psize + SIZE_T_SIZE)->head = 0;
if (mm < m->least_addr)
m->least_addr = mm;
if ((m->footprint += mmsize) > m->max_footprint)
m->max_footprint = m->footprint;
assert(is_aligned(chunk2mem(p)));
check_mmapped_chunk(m, p);
return chunk2mem(p);
}
}
return 0;
}
DIRECT_MMAP
#define DIRECT_MMAP(s)
Definition: SDL_malloc.c:1431
mark_inuse_foot
#define mark_inuse_foot(M, p, s)
Definition: SDL_malloc.c:2466
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
FENCEPOST_HEAD
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
IS_MMAPPED_BIT
#define IS_MMAPPED_BIT
Definition: SDL_malloc.c:1363
SIX_SIZE_T_SIZES
#define SIX_SIZE_T_SIZES
Definition: SDL_malloc.c:1328
assert
#define assert(x)
Definition: SDL_malloc.c:1240
SIZE_T_SIZE
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
CMFAIL
#define CMFAIL
Definition: SDL_malloc.c:1353
CHUNK_ALIGN_MASK
#define CHUNK_ALIGN_MASK
Definition: SDL_malloc.c:1332
is_aligned
#define is_aligned(A)
Definition: SDL_malloc.c:1335
CINUSE_BIT
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
offset
GLintptr offset
Definition: SDL_opengl_glext.h:538
check_mmapped_chunk
#define check_mmapped_chunk(M, P)
Definition: SDL_malloc.c:2258
MMAP_FOOT_PAD
#define MMAP_FOOT_PAD
Definition: SDL_malloc.c:1711
head
SDL_EventEntry * head
Definition: SDL_events.c:79
align_offset
#define align_offset(A)
Definition: SDL_malloc.c:1338
granularity_align
#define granularity_align(S)
Definition: SDL_malloc.c:2140
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718

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

static

Definition at line 3273 of file SDL_malloc.c.

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

Referenced by internal_realloc().

{
size_t oldsize = chunksize(oldp);
if (is_small(nb)) /* Can't shrink mmap regions below small size */
return 0;
/* Keep old chunk if big enough but not too big */
if (oldsize >= nb + SIZE_T_SIZE &&
(oldsize - nb) <= (mparams.granularity << 1))
return oldp;
else {
size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT;
size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD;
size_t newmmsize = granularity_align(nb + SIX_SIZE_T_SIZES +
CHUNK_ALIGN_MASK);
char *cp = (char *) CALL_MREMAP((char *) oldp - offset,
oldmmsize, newmmsize, 1);
if (cp != CMFAIL) {
mchunkptr newp = (mchunkptr) (cp + offset);
size_t psize = newmmsize - offset - MMAP_FOOT_PAD;
newp->head = (psize | CINUSE_BIT);
mark_inuse_foot(m, newp, psize);
chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;
chunk_plus_offset(newp, psize + SIZE_T_SIZE)->head = 0;
if (cp < m->least_addr)
m->least_addr = cp;
if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint)
m->max_footprint = m->footprint;
check_mmapped_chunk(m, newp);
return newp;
}
}
return 0;
}
mark_inuse_foot
#define mark_inuse_foot(M, p, s)
Definition: SDL_malloc.c:2466
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
FENCEPOST_HEAD
#define FENCEPOST_HEAD
Definition: SDL_malloc.c:1751
IS_MMAPPED_BIT
#define IS_MMAPPED_BIT
Definition: SDL_malloc.c:1363
SIX_SIZE_T_SIZES
#define SIX_SIZE_T_SIZES
Definition: SDL_malloc.c:1328
SIZE_T_SIZE
#define SIZE_T_SIZE
Definition: SDL_malloc.c:1318
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
CMFAIL
#define CMFAIL
Definition: SDL_malloc.c:1353
CHUNK_ALIGN_MASK
#define CHUNK_ALIGN_MASK
Definition: SDL_malloc.c:1332
CINUSE_BIT
#define CINUSE_BIT
Definition: SDL_malloc.c:1747
cp
cp
Definition: e_pow.c:96
mparams
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
is_small
#define is_small(s)
Definition: SDL_malloc.c:2286
offset
GLintptr offset
Definition: SDL_opengl_glext.h:538
malloc_params::granularity
size_t granularity
Definition: SDL_malloc.c:2101
CALL_MREMAP
#define CALL_MREMAP(addr, osz, nsz, mv)
Definition: SDL_malloc.c:1438
check_mmapped_chunk
#define check_mmapped_chunk(M, P)
Definition: SDL_malloc.c:2258
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
MMAP_FOOT_PAD
#define MMAP_FOOT_PAD
Definition: SDL_malloc.c:1711
granularity_align
#define granularity_align(S)
Definition: SDL_malloc.c:2140

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

static

Definition at line 3362 of file SDL_malloc.c.

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

Referenced by sys_alloc().

{
mchunkptr p = align_as_chunk(newbase);
mchunkptr oldfirst = align_as_chunk(oldbase);
size_t psize = (char *) oldfirst - (char *) p;
mchunkptr q = chunk_plus_offset(p, nb);
size_t qsize = psize - nb;
set_size_and_pinuse_of_inuse_chunk(m, p, nb);
assert((char *) oldfirst > (char *) q);
assert(pinuse(oldfirst));
assert(qsize >= MIN_CHUNK_SIZE);
/* consolidate remainder with first chunk of old base */
if (oldfirst == m->top) {
size_t tsize = m->topsize += qsize;
m->top = q;
q->head = tsize | PINUSE_BIT;
check_top_chunk(m, q);
} else if (oldfirst == m->dv) {
size_t dsize = m->dvsize += qsize;
m->dv = q;
set_size_and_pinuse_of_free_chunk(q, dsize);
} else {
if (!cinuse(oldfirst)) {
size_t nsize = chunksize(oldfirst);
unlink_chunk(m, oldfirst, nsize);
oldfirst = chunk_plus_offset(oldfirst, nsize);
qsize += nsize;
}
set_free_with_pinuse(q, qsize, oldfirst);
insert_chunk(m, q, qsize);
check_free_chunk(m, q);
}
check_malloced_chunk(m, chunk2mem(p), nb);
return chunk2mem(p);
}
insert_chunk
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3203
q
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2080
cinuse
#define cinuse(p)
Definition: SDL_malloc.c:1754
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
set_free_with_pinuse
#define set_free_with_pinuse(p, s, n)
Definition: SDL_malloc.c:1781
assert
#define assert(x)
Definition: SDL_malloc.c:1240
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
align_as_chunk
#define align_as_chunk(A)
Definition: SDL_malloc.c:1721
unlink_chunk
#define unlink_chunk(M, P, S)
Definition: SDL_malloc.c:3207
check_malloced_chunk
#define check_malloced_chunk(M, P, N)
Definition: SDL_malloc.c:2257
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
set_size_and_pinuse_of_free_chunk
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
pinuse
#define pinuse(p)
Definition: SDL_malloc.c:1755
check_free_chunk
#define check_free_chunk(M, P)
Definition: SDL_malloc.c:2255
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
PINUSE_BIT
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
check_top_chunk
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260
set_size_and_pinuse_of_inuse_chunk
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479

static size_t release_unused_segments | ( | mstate | m | ) |

static

Definition at line 3661 of file SDL_malloc.c.

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

Referenced by sys_trim().

{
size_t released = 0;
msegmentptr pred = &m->seg;
msegmentptr sp = pred->next;
while (sp != 0) {
char *base = sp->base;
size_t size = sp->size;
msegmentptr next = sp->next;
if (is_mmapped_segment(sp) && !is_extern_segment(sp)) {
mchunkptr p = align_as_chunk(base);
size_t psize = chunksize(p);
/* Can unmap if first chunk holds entire segment and not pinned */
if (!cinuse(p)
&& (char *) p + psize >= base + size - TOP_FOOT_SIZE) {
tchunkptr tp = (tchunkptr) p;
assert(segment_holds(sp, (char *) sp));
if (p == m->dv) {
m->dv = 0;
m->dvsize = 0;
} else {
unlink_large_chunk(m, tp);
}
if (CALL_MUNMAP(base, size) == 0) {
released += size;
m->footprint -= size;
/* unlink obsoleted record */
sp = pred;
sp->next = next;
} else { /* back out if cannot unmap */
insert_large_chunk(m, tp, psize);
}
}
}
pred = sp;
sp = next;
}
return released;
}
unlink_large_chunk
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3130
cinuse
#define cinuse(p)
Definition: SDL_malloc.c:1754
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
assert
#define assert(x)
Definition: SDL_malloc.c:1240
CALL_MUNMAP
#define CALL_MUNMAP(a, s)
Definition: SDL_malloc.c:1430
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
align_as_chunk
#define align_as_chunk(A)
Definition: SDL_malloc.c:1721
insert_large_chunk
#define insert_large_chunk(M, X, S)
Definition: SDL_malloc.c:3062
segment_holds
#define segment_holds(S, A)
Definition: SDL_malloc.c:2149
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
is_mmapped_segment
#define is_mmapped_segment(S)
Definition: SDL_malloc.c:1974
is_extern_segment
#define is_extern_segment(S)
Definition: SDL_malloc.c:1975
TOP_FOOT_SIZE
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189

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

static

Definition at line 2154 of file SDL_malloc.c.

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

{
msegmentptr sp = &m->seg;
for (;;) {
if (addr >= sp->base && addr < sp->base + sp->size)
return sp;
if ((sp = sp->next) == 0)
return 0;
}
}
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
addr
GLenum const void * addr
Definition: SDL_opengl_glext.h:7945

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

static

Definition at line 3461 of file SDL_malloc.c.

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

Referenced by dlmalloc(), and dlmallopt().

{
char *tbase = CMFAIL;
size_t tsize = 0;
flag_t mmap_flag = 0;
init_mparams();
/* Directly map large chunks */
if (use_mmap(m) && nb >= mparams.mmap_threshold) {
void *mem = mmap_alloc(m, nb);
if (mem != 0)
return mem;
}
/*
Try getting memory in any of three ways (in most-preferred to
least-preferred order):
1. A call to MORECORE that can normally contiguously extend memory.
(disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or
or main space is mmapped or a previous contiguous call failed)
2. A call to MMAP new space (disabled if not HAVE_MMAP).
Note that under the default settings, if MORECORE is unable to
fulfill a request, and HAVE_MMAP is true, then mmap is
used as a noncontiguous system allocator. This is a useful backup
strategy for systems with holes in address spaces -- in this case
sbrk cannot contiguously expand the heap, but mmap may be able to
find space.
3. A call to MORECORE that cannot usually contiguously extend memory.
(disabled if not HAVE_MORECORE)
*/
if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) {
char *br = CMFAIL;
msegmentptr ss =
(m->top == 0) ? 0 : segment_holding(m, (char *) m->top);
size_t asize = 0;
ACQUIRE_MORECORE_LOCK();
if (ss == 0) { /* First time through or recovery */
char *base = (char *) CALL_MORECORE(0);
if (base != CMFAIL) {
asize =
granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT +
SIZE_T_ONE);
/* Adjust to end on a page boundary */
if (!is_page_aligned(base))
asize += (page_align((size_t) base) - (size_t) base);
/* Can't call MORECORE if size is negative when treated as signed */
if (asize < HALF_MAX_SIZE_T &&
(br = (char *) (CALL_MORECORE(asize))) == base) {
tbase = base;
tsize = asize;
}
}
} else {
/* Subtract out existing available top space from MORECORE request. */
asize =
granularity_align(nb - m->topsize + TOP_FOOT_SIZE +
MALLOC_ALIGNMENT + SIZE_T_ONE);
/* Use mem here only if it did continuously extend old space */
if (asize < HALF_MAX_SIZE_T &&
(br =
(char *) (CALL_MORECORE(asize))) == ss->base + ss->size) {
tbase = br;
tsize = asize;
}
}
if (tbase == CMFAIL) { /* Cope with partial failure */
if (br != CMFAIL) { /* Try to use/extend the space we did get */
if (asize < HALF_MAX_SIZE_T &&
asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) {
size_t esize =
granularity_align(nb + TOP_FOOT_SIZE +
MALLOC_ALIGNMENT + SIZE_T_ONE -
asize);
if (esize < HALF_MAX_SIZE_T) {
char *end = (char *) CALL_MORECORE(esize);
if (end != CMFAIL)
asize += esize;
else { /* Can't use; try to release */
end = (char *) CALL_MORECORE(-asize);
br = CMFAIL;
}
}
}
}
if (br != CMFAIL) { /* Use the space we did get */
tbase = br;
tsize = asize;
} else
disable_contiguous(m); /* Don't try contiguous path in the future */
}
RELEASE_MORECORE_LOCK();
}
if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */
size_t req = nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE;
size_t rsize = granularity_align(req);
if (rsize > nb) { /* Fail if wraps around zero */
char *mp = (char *) (CALL_MMAP(rsize));
if (mp != CMFAIL) {
tbase = mp;
tsize = rsize;
mmap_flag = IS_MMAPPED_BIT;
}
}
}
if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */
size_t asize =
granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT +
SIZE_T_ONE);
if (asize < HALF_MAX_SIZE_T) {
char *br = CMFAIL;
char *end = CMFAIL;
ACQUIRE_MORECORE_LOCK();
br = (char *) (CALL_MORECORE(asize));
end = (char *) (CALL_MORECORE(0));
RELEASE_MORECORE_LOCK();
if (br != CMFAIL && end != CMFAIL && br < end) {
size_t ssize = end - br;
if (ssize > nb + TOP_FOOT_SIZE) {
tbase = br;
tsize = ssize;
}
}
}
}
if (tbase != CMFAIL) {
if ((m->footprint += tsize) > m->max_footprint)
m->max_footprint = m->footprint;
if (!is_initialized(m)) { /* first-time initialization */
m->seg.base = m->least_addr = tbase;
m->seg.size = tsize;
m->seg.sflags = mmap_flag;
m->magic = mparams.magic;
init_bins(m);
if (is_global(m))
init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
else {
/* Offset top by embedded malloc_state */
mchunkptr mn = next_chunk(mem2chunk(m));
init_top(m, mn,
(size_t) ((tbase + tsize) - (char *) mn) -
TOP_FOOT_SIZE);
}
}
else {
/* Try to merge with an existing segment */
msegmentptr sp = &m->seg;
while (sp != 0 && tbase != sp->base + sp->size)
sp = sp->next;
if (sp != 0 && !is_extern_segment(sp) && (sp->sflags & IS_MMAPPED_BIT) == mmap_flag && segment_holds(sp, m->top)) { /* append */
sp->size += tsize;
init_top(m, m->top, m->topsize + tsize);
} else {
if (tbase < m->least_addr)
m->least_addr = tbase;
sp = &m->seg;
while (sp != 0 && sp->base != tbase + tsize)
sp = sp->next;
if (sp != 0 &&
!is_extern_segment(sp) &&
(sp->sflags & IS_MMAPPED_BIT) == mmap_flag) {
char *oldbase = sp->base;
sp->base = tbase;
sp->size += tsize;
return prepend_alloc(m, tbase, oldbase, nb);
} else
add_segment(m, tbase, tsize, mmap_flag);
}
}
if (nb < m->topsize) { /* Allocate from new or extended top space */
size_t rsize = m->topsize -= nb;
mchunkptr p = m->top;
mchunkptr r = m->top = chunk_plus_offset(p, nb);
r->head = rsize | PINUSE_BIT;
set_size_and_pinuse_of_inuse_chunk(m, p, nb);
check_top_chunk(m, m->top);
check_malloced_chunk(m, chunk2mem(p), nb);
return chunk2mem(p);
}
}
MALLOC_FAILURE_ACTION;
return 0;
}
next_chunk
#define next_chunk(p)
Definition: SDL_malloc.c:1766
HAVE_MMAP
#define HAVE_MMAP
Definition: SDL_malloc.c:512
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
flag_t
unsigned int flag_t
Definition: SDL_malloc.c:1696
MALLOC_FAILURE_ACTION
#define MALLOC_FAILURE_ACTION
Definition: SDL_malloc.c:522
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
end
GLuint GLuint end
Definition: SDL_opengl.h:1564
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
disable_contiguous
#define disable_contiguous(M)
Definition: SDL_malloc.c:2128
is_initialized
#define is_initialized(M)
Definition: SDL_malloc.c:2113
IS_MMAPPED_BIT
#define IS_MMAPPED_BIT
Definition: SDL_malloc.c:1363
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
CMFAIL
#define CMFAIL
Definition: SDL_malloc.c:1353
ACQUIRE_MORECORE_LOCK
#define ACQUIRE_MORECORE_LOCK()
Definition: SDL_malloc.c:1533
CALL_MORECORE
#define CALL_MORECORE(S)
Definition: SDL_malloc.c:1444
size_t
unsigned int size_t
Definition: SDL_config_windows.h:67
use_noncontiguous
#define use_noncontiguous(M)
Definition: SDL_malloc.c:2127
init_bins
static void init_bins(mstate m)
Definition: SDL_malloc.c:3329
mparams
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
MORECORE_CONTIGUOUS
#define MORECORE_CONTIGUOUS
Definition: SDL_malloc.c:596
MALLOC_ALIGNMENT
#define MALLOC_ALIGNMENT
Definition: SDL_malloc.c:552
is_global
#define is_global(M)
Definition: SDL_malloc.c:2112
malloc_params::magic
size_t magic
Definition: SDL_malloc.c:2099
page_align
#define page_align(S)
Definition: SDL_malloc.c:2136
CALL_MMAP
#define CALL_MMAP(s)
Definition: SDL_malloc.c:1429
init_top
static void init_top(mstate m, mchunkptr p, size_t psize)
Definition: SDL_malloc.c:3312
HALF_MAX_SIZE_T
#define HALF_MAX_SIZE_T
Definition: SDL_malloc.c:1329
HAVE_MORECORE
#define HAVE_MORECORE
Definition: SDL_malloc.c:513
check_malloced_chunk
#define check_malloced_chunk(M, P, N)
Definition: SDL_malloc.c:2257
prepend_alloc
static void * prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb)
Definition: SDL_malloc.c:3362
segment_holds
#define segment_holds(S, A)
Definition: SDL_malloc.c:2149
init_mparams
static int init_mparams(void)
Definition: SDL_malloc.c:2512
add_segment
static void add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped)
Definition: SDL_malloc.c:3404
RELEASE_MORECORE_LOCK
#define RELEASE_MORECORE_LOCK()
Definition: SDL_malloc.c:1534
mem2chunk
#define mem2chunk(mem)
Definition: SDL_malloc.c:1719
use_mmap
#define use_mmap(M)
Definition: SDL_malloc.c:2123
segment_holding
static msegmentptr segment_holding(mstate m, char *addr)
Definition: SDL_malloc.c:2154
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
is_extern_segment
#define is_extern_segment(S)
Definition: SDL_malloc.c:1975
TOP_FOOT_SIZE
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
granularity_align
#define granularity_align(S)
Definition: SDL_malloc.c:2140
mmap_alloc
static void * mmap_alloc(mstate m, size_t nb)
Definition: SDL_malloc.c:3243
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
PINUSE_BIT
#define PINUSE_BIT
Definition: SDL_malloc.c:1746
is_page_aligned
#define is_page_aligned(S)
Definition: SDL_malloc.c:2143
check_top_chunk
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260
set_size_and_pinuse_of_inuse_chunk
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
malloc_params::mmap_threshold
size_t mmap_threshold
Definition: SDL_malloc.c:2102

static int sys_trim | ( | mstate | m,
|  | size_t | pad
| ) |  |

static

Definition at line 3702 of file SDL_malloc.c.

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

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

{
size_t released = 0;
if (pad < MAX_REQUEST && is_initialized(m)) {
pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */
if (m->topsize > pad) {
/* Shrink top space in granularity-size units, keeping at least one */
size_t unit = mparams.granularity;
size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit -
SIZE_T_ONE) * unit;
msegmentptr sp = segment_holding(m, (char *) m->top);
if (!is_extern_segment(sp)) {
if (is_mmapped_segment(sp)) {
if (HAVE_MMAP && sp->size >= extra && !has_segment_link(m, sp)) { /* can't shrink if pinned */
size_t newsize = sp->size - extra;
/* Prefer mremap, fall back to munmap */
if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) !=
MFAIL)
|| (CALL_MUNMAP(sp->base + newsize, extra) == 0)) {
released = extra;
}
}
} else if (HAVE_MORECORE) {
if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */
extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit;
ACQUIRE_MORECORE_LOCK();
{
/* Make sure end of memory is where we last set it. */
char *old_br = (char *) (CALL_MORECORE(0));
if (old_br == sp->base + sp->size) {
char *rel_br = (char *) (CALL_MORECORE(-extra));
char *new_br = (char *) (CALL_MORECORE(0));
if (rel_br != CMFAIL && new_br < old_br)
released = old_br - new_br;
}
}
RELEASE_MORECORE_LOCK();
}
}
if (released != 0) {
sp->size -= released;
m->footprint -= released;
init_top(m, m->top, m->topsize - released);
check_top_chunk(m, m->top);
}
}
/* Unmap any unused mmapped segments */
if (HAVE_MMAP)
released += release_unused_segments(m);
/* On failure, disable autotrim to avoid repeated failed future calls */
if (released == 0)
m->trim_check = MAX_SIZE_T;
}
return (released != 0) ? 1 : 0;
}
HAVE_MMAP
#define HAVE_MMAP
Definition: SDL_malloc.c:512
has_segment_link
static int has_segment_link(mstate m, msegmentptr ss)
Definition: SDL_malloc.c:2167
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
is_initialized
#define is_initialized(M)
Definition: SDL_malloc.c:2113
CALL_MUNMAP
#define CALL_MUNMAP(a, s)
Definition: SDL_malloc.c:1430
CMFAIL
#define CMFAIL
Definition: SDL_malloc.c:1353
ACQUIRE_MORECORE_LOCK
#define ACQUIRE_MORECORE_LOCK()
Definition: SDL_malloc.c:1533
CALL_MORECORE
#define CALL_MORECORE(S)
Definition: SDL_malloc.c:1444
MFAIL
#define MFAIL
Definition: SDL_malloc.c:1352
mparams
static struct malloc_params mparams
Definition: SDL_malloc.c:2107
MAX_SIZE_T
#define MAX_SIZE_T
Definition: SDL_malloc.c:539
init_top
static void init_top(mstate m, mchunkptr p, size_t psize)
Definition: SDL_malloc.c:3312
HALF_MAX_SIZE_T
#define HALF_MAX_SIZE_T
Definition: SDL_malloc.c:1329
HAVE_MORECORE
#define HAVE_MORECORE
Definition: SDL_malloc.c:513
malloc_params::granularity
size_t granularity
Definition: SDL_malloc.c:2101
release_unused_segments
static size_t release_unused_segments(mstate m)
Definition: SDL_malloc.c:3661
RELEASE_MORECORE_LOCK
#define RELEASE_MORECORE_LOCK()
Definition: SDL_malloc.c:1534
MAX_REQUEST
#define MAX_REQUEST
Definition: SDL_malloc.c:1724
CALL_MREMAP
#define CALL_MREMAP(addr, osz, nsz, mv)
Definition: SDL_malloc.c:1438
segment_holding
static msegmentptr segment_holding(mstate m, char *addr)
Definition: SDL_malloc.c:2154
is_mmapped_segment
#define is_mmapped_segment(S)
Definition: SDL_malloc.c:1974
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
is_extern_segment
#define is_extern_segment(S)
Definition: SDL_malloc.c:1975
TOP_FOOT_SIZE
#define TOP_FOOT_SIZE
Definition: SDL_malloc.c:2189
check_top_chunk
#define check_top_chunk(M, P)
Definition: SDL_malloc.c:2260

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

static

Definition at line 3768 of file SDL_malloc.c.

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

Referenced by dlmalloc(), and dlmallopt().

{
tchunkptr v = 0;
size_t rsize = -nb; /* Unsigned negation */
tchunkptr t;
bindex_t idx;
compute_tree_index(nb, idx);
if ((t = *treebin_at(m, idx)) != 0) {
/* Traverse tree for this bin looking for node with size == nb */
size_t sizebits = nb << leftshift_for_tree_index(idx);
tchunkptr rst = 0; /* The deepest untaken right subtree */
for (;;) {
tchunkptr rt;
size_t trem = chunksize(t) - nb;
if (trem < rsize) {
v = t;
if ((rsize = trem) == 0)
break;
}
rt = t->child[1];
t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1];
if (rt != 0 && rt != t)
rst = rt;
if (t == 0) {
t = rst; /* set t to least subtree holding sizes > nb */
break;
}
sizebits <<= 1;
}
}
if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */
binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap;
if (leftbits != 0) {
bindex_t i;
binmap_t leastbit = least_bit(leftbits);
compute_bit2idx(leastbit, i);
t = *treebin_at(m, i);
}
}
while (t != 0) { /* find smallest of tree or subtree */
size_t trem = chunksize(t) - nb;
if (trem < rsize) {
rsize = trem;
v = t;
}
t = leftmost_child(t);
}
/* If dv is a better fit, return 0 so malloc will use it */
if (v != 0 && rsize < (size_t) (m->dvsize - nb)) {
if (RTCHECK(ok_address(m, v))) { /* split */
mchunkptr r = chunk_plus_offset(v, nb);
assert(chunksize(v) == rsize + nb);
if (RTCHECK(ok_next(v, r))) {
unlink_large_chunk(m, v);
if (rsize < MIN_CHUNK_SIZE)
set_inuse_and_pinuse(m, v, (rsize + nb));
else {
set_size_and_pinuse_of_inuse_chunk(m, v, nb);
set_size_and_pinuse_of_free_chunk(r, rsize);
insert_chunk(m, r, rsize);
}
return chunk2mem(v);
}
}
CORRUPTION_ERROR_ACTION(m);
}
return 0;
}
unlink_large_chunk
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3130
bindex_t
size_t bindex_t
Definition: SDL_malloc.c:1694
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
compute_tree_index
#define compute_tree_index(S, I)
Definition: SDL_malloc.c:2311
insert_chunk
#define insert_chunk(M, P, S)
Definition: SDL_malloc.c:3203
RTCHECK
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
compute_bit2idx
#define compute_bit2idx(X, I)
Definition: SDL_malloc.c:2374
assert
#define assert(x)
Definition: SDL_malloc.c:1240
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
leftmost_child
#define leftmost_child(t)
Definition: SDL_malloc.c:1907
CORRUPTION_ERROR_ACTION
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2242
v
const GLdouble * v
Definition: SDL_opengl.h:2057
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
idx2bit
#define idx2bit(i)
Definition: SDL_malloc.c:2348
ok_next
#define ok_next(p, n)
Definition: SDL_malloc.c:2430
leftshift_for_tree_index
#define leftshift_for_tree_index(i)
Definition: SDL_malloc.c:2335
SIZE_T_BITSIZE
#define SIZE_T_BITSIZE
Definition: SDL_malloc.c:1319
treebin_at
#define treebin_at(M, i)
Definition: SDL_malloc.c:2293
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:42
left_bits
#define left_bits(x)
Definition: SDL_malloc.c:2392
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
binmap_t
unsigned int binmap_t
Definition: SDL_malloc.c:1695
set_size_and_pinuse_of_free_chunk
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
SIZE_T_ONE
#define SIZE_T_ONE
Definition: SDL_malloc.c:1324
ok_address
#define ok_address(M, a)
Definition: SDL_malloc.c:2428
least_bit
#define least_bit(x)
Definition: SDL_malloc.c:2389
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
t
GLdouble GLdouble t
Definition: SDL_opengl.h:2064
set_size_and_pinuse_of_inuse_chunk
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
set_inuse_and_pinuse
#define set_inuse_and_pinuse(M, p, s)
Definition: SDL_malloc.c:2474

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

static

Definition at line 3843 of file SDL_malloc.c.

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

Referenced by dlmalloc(), and dlmallopt().

{
tchunkptr t, v;
size_t rsize;
bindex_t i;
binmap_t leastbit = least_bit(m->treemap);
compute_bit2idx(leastbit, i);
v = t = *treebin_at(m, i);
rsize = chunksize(t) - nb;
while ((t = leftmost_child(t)) != 0) {
size_t trem = chunksize(t) - nb;
if (trem < rsize) {
rsize = trem;
v = t;
}
}
if (RTCHECK(ok_address(m, v))) {
mchunkptr r = chunk_plus_offset(v, nb);
assert(chunksize(v) == rsize + nb);
if (RTCHECK(ok_next(v, r))) {
unlink_large_chunk(m, v);
if (rsize < MIN_CHUNK_SIZE)
set_inuse_and_pinuse(m, v, (rsize + nb));
else {
set_size_and_pinuse_of_inuse_chunk(m, v, nb);
set_size_and_pinuse_of_free_chunk(r, rsize);
replace_dv(m, r, rsize);
}
return chunk2mem(v);
}
}
CORRUPTION_ERROR_ACTION(m);
return 0;
}
unlink_large_chunk
#define unlink_large_chunk(M, X)
Definition: SDL_malloc.c:3130
bindex_t
size_t bindex_t
Definition: SDL_malloc.c:1694
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
RTCHECK
#define RTCHECK(e)
Definition: SDL_malloc.c:2456
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
replace_dv
#define replace_dv(M, P, S)
Definition: SDL_malloc.c:3048
compute_bit2idx
#define compute_bit2idx(X, I)
Definition: SDL_malloc.c:2374
assert
#define assert(x)
Definition: SDL_malloc.c:1240
chunk_plus_offset
#define chunk_plus_offset(p, s)
Definition: SDL_malloc.c:1762
leftmost_child
#define leftmost_child(t)
Definition: SDL_malloc.c:1907
CORRUPTION_ERROR_ACTION
#define CORRUPTION_ERROR_ACTION(m)
Definition: SDL_malloc.c:2242
v
const GLdouble * v
Definition: SDL_opengl.h:2057
MIN_CHUNK_SIZE
#define MIN_CHUNK_SIZE
Definition: SDL_malloc.c:1714
ok_next
#define ok_next(p, n)
Definition: SDL_malloc.c:2430
treebin_at
#define treebin_at(M, i)
Definition: SDL_malloc.c:2293
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:42
chunksize
#define chunksize(p)
Definition: SDL_malloc.c:1756
binmap_t
unsigned int binmap_t
Definition: SDL_malloc.c:1695
set_size_and_pinuse_of_free_chunk
#define set_size_and_pinuse_of_free_chunk(p, s)
Definition: SDL_malloc.c:1777
ok_address
#define ok_address(M, a)
Definition: SDL_malloc.c:2428
least_bit
#define least_bit(x)
Definition: SDL_malloc.c:2389
chunk2mem
#define chunk2mem(p)
Definition: SDL_malloc.c:1718
t
GLdouble GLdouble t
Definition: SDL_opengl.h:2064
set_size_and_pinuse_of_inuse_chunk
#define set_size_and_pinuse_of_inuse_chunk(M, p, s)
Definition: SDL_malloc.c:2479
set_inuse_and_pinuse
#define set_inuse_and_pinuse(M, p, s)
Definition: SDL_malloc.c:2474

static int win32_acquire_lock | ( | MLOCK_T * | sl | ) |

static

Definition at line 1494 of file SDL_malloc.c.

{
for (;;) {
#ifdef InterlockedCompareExchangePointer
if (!InterlockedCompareExchange(sl, 1, 0))
return 0;
#else /* Use older void* version */
if (!InterlockedCompareExchange((void **) sl, (void *) 1, (void *) 0))
return 0;
#endif /* InterlockedCompareExchangePointer */
Sleep(0);
}
}

static void win32_release_lock | ( | MLOCK_T * | sl | ) |

static

Definition at line 1509 of file SDL_malloc.c.

{
InterlockedExchange(sl, 0);
}

static void* win32direct_mmap | ( | size_t | size | ) |

static

Definition at line 1402 of file SDL_malloc.c.

References MFAIL.

{
void *ptr = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN,
PAGE_READWRITE);
return (ptr != 0) ? ptr : MFAIL;
}
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
MFAIL
#define MFAIL
Definition: SDL_malloc.c:1352

static void* win32mmap | ( | size_t | size | ) |

static

Definition at line 1393 of file SDL_malloc.c.

References MFAIL.

{
void *ptr =
VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
return (ptr != 0) ? ptr : MFAIL;
}
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
MFAIL
#define MFAIL
Definition: SDL_malloc.c:1352

static int win32munmap | ( | void * | ptr,
|  | size_t | size
| ) |  |

static

Definition at line 1411 of file SDL_malloc.c.

{
MEMORY_BASIC_INFORMATION minfo;
char *cptr = ptr;
while (size) {
if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)
return -1;
if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||
minfo.State != MEM_COMMIT || minfo.RegionSize > size)
return -1;
if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)
return -1;
cptr += minfo.RegionSize;
size -= minfo.RegionSize;
}
return 0;
}
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537

## Variable Documentation

struct malloc_state _gm_

static

Definition at line 2110 of file SDL_malloc.c.

MLOCK_T magic_init_mutex

static

Definition at line 1520 of file SDL_malloc.c.

struct malloc_params mparams

static

Definition at line 2107 of file SDL_malloc.c.

Referenced by change_mparam(), dlmallopt(), dlpvalloc(), dlvalloc(), init_mparams(), init_top(), mmap_resize(), sys_alloc(), and sys_trim().