Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions
zend_alloc.h File Reference
#include <stdio.h>
#include "../TSRM/TSRM.h"
#include "zend.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _zend_leak_info
struct  _zend_mm_segment
struct  _zend_mm_mem_handlers
struct  _zend_mm_storage

Defines

#define ZEND_MM_ALIGNMENT_MASK   ~(ZEND_MM_ALIGNMENT-1)
#define ZEND_MM_ALIGNED_SIZE(size)   (((size) + ZEND_MM_ALIGNMENT - 1) & ZEND_MM_ALIGNMENT_MASK)
#define emalloc(size)   _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define safe_emalloc(nmemb, size, offset)   _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define efree(ptr)   _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define ecalloc(nmemb, size)   _ecalloc((nmemb), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define erealloc(ptr, size)   _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define safe_erealloc(ptr, nmemb, size, offset)   _safe_erealloc((ptr), (nmemb), (size), (offset) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define erealloc_recoverable(ptr, size)   _erealloc((ptr), (size), 1 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define estrdup(s)   _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define estrndup(s, length)   _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define zend_mem_block_size(ptr)   _zend_mem_block_size((ptr) TSRMLS_CC ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define emalloc_rel(size)   _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define safe_emalloc_rel(nmemb, size, offset)   _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define efree_rel(ptr)   _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define ecalloc_rel(nmemb, size)   _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define erealloc_rel(ptr, size)   _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define erealloc_recoverable_rel(ptr, size)   _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define safe_erealloc_rel(ptr, nmemb, size, offset)   _safe_erealloc((ptr), (nmemb), (size), (offset) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define estrdup_rel(s)   _estrdup((s) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define estrndup_rel(s, length)   _estrndup((s), (length) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define zend_mem_block_size_rel(ptr)   _zend_mem_block_size((ptr) TSRMLS_CC ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define pemalloc(size, persistent)   ((persistent)?__zend_malloc(size):emalloc(size))
#define safe_pemalloc(nmemb, size, offset, persistent)   ((persistent)?_safe_malloc(nmemb, size, offset):safe_emalloc(nmemb, size, offset))
#define pefree(ptr, persistent)   ((persistent)?free(ptr):efree(ptr))
#define pecalloc(nmemb, size, persistent)   ((persistent)?__zend_calloc((nmemb), (size)):ecalloc((nmemb), (size)))
#define perealloc(ptr, size, persistent)   ((persistent)?__zend_realloc((ptr), (size)):erealloc((ptr), (size)))
#define safe_perealloc(ptr, nmemb, size, offset, persistent)   ((persistent)?_safe_realloc((ptr), (nmemb), (size), (offset)):safe_erealloc((ptr), (nmemb), (size), (offset)))
#define perealloc_recoverable(ptr, size, persistent)   ((persistent)?__zend_realloc((ptr), (size)):erealloc_recoverable((ptr), (size)))
#define pestrdup(s, persistent)   ((persistent)?strdup(s):estrdup(s))
#define pestrndup(s, length, persistent)   ((persistent)?zend_strndup((s),(length)):estrndup((s),(length)))
#define pemalloc_rel(size, persistent)   ((persistent)?__zend_malloc(size):emalloc_rel(size))
#define pefree_rel(ptr, persistent)   ((persistent)?free(ptr):efree_rel(ptr))
#define pecalloc_rel(nmemb, size, persistent)   ((persistent)?__zend_calloc((nmemb), (size)):ecalloc_rel((nmemb), (size)))
#define perealloc_rel(ptr, size, persistent)   ((persistent)?__zend_realloc((ptr), (size)):erealloc_rel((ptr), (size)))
#define perealloc_recoverable_rel(ptr, size, persistent)   ((persistent)?__zend_realloc((ptr), (size)):erealloc_recoverable_rel((ptr), (size)))
#define pestrdup_rel(s, persistent)   ((persistent)?strdup(s):estrdup_rel(s))
#define safe_estrdup(ptr)   ((ptr)?(estrdup(ptr)):STR_EMPTY_ALLOC())
#define safe_estrndup(ptr, len)   ((ptr)?(estrndup((ptr), (len))):STR_EMPTY_ALLOC())
#define mem_block_check(type, ptr, silent)
#define full_mem_check(silent)
#define ZEND_FAST_ALLOC(p, type, fc_type)   (p) = (type *) emalloc(sizeof(type))
#define ZEND_FAST_FREE(p, fc_type)   efree(p)
#define ZEND_FAST_ALLOC_REL(p, type, fc_type)   (p) = (type *) emalloc_rel(sizeof(type))
#define ZEND_FAST_FREE_REL(p, fc_type)   efree_rel(p)
#define ALLOC_ZVAL(z)   ZEND_FAST_ALLOC(z, zval, ZVAL_CACHE_LIST)
#define FREE_ZVAL(z)   ZEND_FAST_FREE(z, ZVAL_CACHE_LIST)
#define ALLOC_ZVAL_REL(z)   ZEND_FAST_ALLOC_REL(z, zval, ZVAL_CACHE_LIST)
#define FREE_ZVAL_REL(z)   ZEND_FAST_FREE_REL(z, ZVAL_CACHE_LIST)
#define ALLOC_HASHTABLE(ht)   ZEND_FAST_ALLOC(ht, HashTable, HASHTABLE_CACHE_LIST)
#define FREE_HASHTABLE(ht)   ZEND_FAST_FREE(ht, HASHTABLE_CACHE_LIST)
#define ALLOC_HASHTABLE_REL(ht)   ZEND_FAST_ALLOC_REL(ht, HashTable, HASHTABLE_CACHE_LIST)
#define FREE_HASHTABLE_REL(ht)   ZEND_FAST_FREE_REL(ht, HASHTABLE_CACHE_LIST)
#define zend_mm_alloc(heap, size)   _zend_mm_alloc((heap), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define zend_mm_free(heap, p)   _zend_mm_free((heap), (p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define zend_mm_realloc(heap, p, size)   _zend_mm_realloc((heap), (p), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define zend_mm_block_size(heap, p)   _zend_mm_block_size((heap), (p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
#define zend_mm_alloc_rel(heap, size)   _zend_mm_alloc((heap), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define zend_mm_free_rel(heap, p)   _zend_mm_free((heap), (p) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define zend_mm_realloc_rel(heap, p, size)   _zend_mm_realloc((heap), (p), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define zend_mm_block_size_rel(heap, p)   _zend_mm_block_size((heap), (p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Typedefs

typedef struct _zend_leak_info zend_leak_info
typedef struct _zend_mm_heap
typedef struct _zend_mm_storage
typedef struct _zend_mm_segment zend_mm_segment
typedef struct
_zend_mm_mem_handlers 
zend_mm_mem_handlers

Functions

ZEND_API char * zend_strndup (const char *s, unsigned int length) ZEND_ATTRIBUTE_MALLOC
ZEND_API void * _emalloc (size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC
ZEND_API void * _safe_emalloc (size_t nmemb, size_t size, size_t offset ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC
ZEND_API void * _safe_malloc (size_t nmemb, size_t size, size_t offset) ZEND_ATTRIBUTE_MALLOC
ZEND_API void _efree (void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
ZEND_API void * _ecalloc (size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC
ZEND_API void * _erealloc (void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
ZEND_API void * _safe_erealloc (void *ptr, size_t nmemb, size_t size, size_t offset ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
ZEND_API void * _safe_realloc (void *ptr, size_t nmemb, size_t size, size_t offset)
ZEND_API char * _estrdup (const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC
ZEND_API char * _estrndup (const char *s, unsigned int length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC
ZEND_API size_t _zend_mem_block_size (void *ptr TSRMLS_DC ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
static void * __zend_malloc (size_t len)
static void * __zend_calloc (size_t nmemb, size_t len)
static void * __zend_realloc (void *p, size_t len)
ZEND_API int zend_set_memory_limit (size_t memory_limit)
ZEND_API void start_memory_manager (TSRMLS_D)
ZEND_API void shutdown_memory_manager (int silent, int full_shutdown TSRMLS_DC)
ZEND_API int is_zend_mm (TSRMLS_D)
ZEND_API size_t zend_memory_usage (int real_usage TSRMLS_DC)
ZEND_API size_t zend_memory_peak_usage (int real_usage TSRMLS_DC)
ZEND_API zend_mm_heap * zend_mm_startup (void)
ZEND_API void zend_mm_shutdown (zend_mm_heap *heap, int full_shutdown, int silent TSRMLS_DC)
ZEND_API void * _zend_mm_alloc (zend_mm_heap *heap, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC
ZEND_API void _zend_mm_free (zend_mm_heap *heap, void *p ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
ZEND_API void * _zend_mm_realloc (zend_mm_heap *heap, void *p, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
ZEND_API size_t _zend_mm_block_size (zend_mm_heap *heap, void *p ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
ZEND_API zend_mm_heap * zend_mm_startup_ex (const zend_mm_mem_handlers *handlers, size_t block_size, size_t reserve_size, int internal, void *params)
ZEND_API zend_mm_heap * zend_mm_set_heap (zend_mm_heap *new_heap TSRMLS_DC)
ZEND_API zend_mm_storage * zend_mm_get_storage (zend_mm_heap *heap)
ZEND_API void zend_mm_set_custom_handlers (zend_mm_heap *heap, void *(*_malloc)(size_t), void(*_free)(void *), void *(*_realloc)(void *, size_t))

Class Documentation

struct _zend_leak_info

Definition at line 44 of file zend_alloc.h.

Class Members
void * addr
char * filename
uint lineno
char * orig_filename
uint orig_lineno
size_t size
struct _zend_mm_segment

Definition at line 227 of file zend_alloc.h.

Collaboration diagram for _zend_mm_segment:
Class Members
struct _zend_mm_segment * next_segment
size_t size
struct _zend_mm_storage

Definition at line 242 of file zend_alloc.h.

Collaboration diagram for _zend_mm_storage:
Class Members
void * data
const zend_mm_mem_handlers * handlers

Define Documentation

#define ALLOC_HASHTABLE (   ht)    ZEND_FAST_ALLOC(ht, HashTable, HASHTABLE_CACHE_LIST)

Definition at line 192 of file zend_alloc.h.

#define ALLOC_HASHTABLE_REL (   ht)    ZEND_FAST_ALLOC_REL(ht, HashTable, HASHTABLE_CACHE_LIST)

Definition at line 198 of file zend_alloc.h.

#define ALLOC_ZVAL (   z)    ZEND_FAST_ALLOC(z, zval, ZVAL_CACHE_LIST)

Definition at line 179 of file zend_alloc.h.

#define ALLOC_ZVAL_REL (   z)    ZEND_FAST_ALLOC_REL(z, zval, ZVAL_CACHE_LIST)

Definition at line 185 of file zend_alloc.h.

#define ecalloc (   nmemb,
  size 
)    _ecalloc((nmemb), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 73 of file zend_alloc.h.

#define ecalloc_rel (   nmemb,
  size 
)    _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

Definition at line 85 of file zend_alloc.h.

Definition at line 72 of file zend_alloc.h.

Definition at line 84 of file zend_alloc.h.

#define emalloc (   size)    _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 70 of file zend_alloc.h.

Definition at line 82 of file zend_alloc.h.

#define erealloc (   ptr,
  size 
)    _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 74 of file zend_alloc.h.

#define erealloc_recoverable (   ptr,
  size 
)    _erealloc((ptr), (size), 1 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 76 of file zend_alloc.h.

#define erealloc_recoverable_rel (   ptr,
  size 
)    _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

Definition at line 87 of file zend_alloc.h.

#define erealloc_rel (   ptr,
  size 
)    _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

Definition at line 86 of file zend_alloc.h.

Definition at line 77 of file zend_alloc.h.

Definition at line 89 of file zend_alloc.h.

#define estrndup (   s,
  length 
)    _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 78 of file zend_alloc.h.

#define estrndup_rel (   s,
  length 
)    _estrndup((s), (length) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

Definition at line 90 of file zend_alloc.h.

#define FREE_HASHTABLE (   ht)    ZEND_FAST_FREE(ht, HASHTABLE_CACHE_LIST)

Definition at line 195 of file zend_alloc.h.

#define FREE_HASHTABLE_REL (   ht)    ZEND_FAST_FREE_REL(ht, HASHTABLE_CACHE_LIST)

Definition at line 201 of file zend_alloc.h.

#define FREE_ZVAL (   z)    ZEND_FAST_FREE(z, ZVAL_CACHE_LIST)

Definition at line 182 of file zend_alloc.h.

#define FREE_ZVAL_REL (   z)    ZEND_FAST_FREE_REL(z, ZVAL_CACHE_LIST)

Definition at line 188 of file zend_alloc.h.

#define full_mem_check (   silent)

Definition at line 156 of file zend_alloc.h.

#define mem_block_check (   type,
  ptr,
  silent 
)

Definition at line 155 of file zend_alloc.h.

#define pecalloc (   nmemb,
  size,
  persistent 
)    ((persistent)?__zend_calloc((nmemb), (size)):ecalloc((nmemb), (size)))

Definition at line 125 of file zend_alloc.h.

#define pecalloc_rel (   nmemb,
  size,
  persistent 
)    ((persistent)?__zend_calloc((nmemb), (size)):ecalloc_rel((nmemb), (size)))

Definition at line 134 of file zend_alloc.h.

#define pefree (   ptr,
  persistent 
)    ((persistent)?free(ptr):efree(ptr))

Definition at line 124 of file zend_alloc.h.

#define pefree_rel (   ptr,
  persistent 
)    ((persistent)?free(ptr):efree_rel(ptr))

Definition at line 133 of file zend_alloc.h.

#define pemalloc (   size,
  persistent 
)    ((persistent)?__zend_malloc(size):emalloc(size))

Definition at line 122 of file zend_alloc.h.

#define pemalloc_rel (   size,
  persistent 
)    ((persistent)?__zend_malloc(size):emalloc_rel(size))

Definition at line 132 of file zend_alloc.h.

#define perealloc (   ptr,
  size,
  persistent 
)    ((persistent)?__zend_realloc((ptr), (size)):erealloc((ptr), (size)))

Definition at line 126 of file zend_alloc.h.

#define perealloc_recoverable (   ptr,
  size,
  persistent 
)    ((persistent)?__zend_realloc((ptr), (size)):erealloc_recoverable((ptr), (size)))

Definition at line 128 of file zend_alloc.h.

#define perealloc_recoverable_rel (   ptr,
  size,
  persistent 
)    ((persistent)?__zend_realloc((ptr), (size)):erealloc_recoverable_rel((ptr), (size)))

Definition at line 136 of file zend_alloc.h.

#define perealloc_rel (   ptr,
  size,
  persistent 
)    ((persistent)?__zend_realloc((ptr), (size)):erealloc_rel((ptr), (size)))

Definition at line 135 of file zend_alloc.h.

#define pestrdup (   s,
  persistent 
)    ((persistent)?strdup(s):estrdup(s))

Definition at line 129 of file zend_alloc.h.

#define pestrdup_rel (   s,
  persistent 
)    ((persistent)?strdup(s):estrdup_rel(s))

Definition at line 137 of file zend_alloc.h.

#define pestrndup (   s,
  length,
  persistent 
)    ((persistent)?zend_strndup((s),(length)):estrndup((s),(length)))

Definition at line 130 of file zend_alloc.h.

#define safe_emalloc (   nmemb,
  size,
  offset 
)    _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 71 of file zend_alloc.h.

#define safe_emalloc_rel (   nmemb,
  size,
  offset 
)    _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

Definition at line 83 of file zend_alloc.h.

#define safe_erealloc (   ptr,
  nmemb,
  size,
  offset 
)    _safe_erealloc((ptr), (nmemb), (size), (offset) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 75 of file zend_alloc.h.

#define safe_erealloc_rel (   ptr,
  nmemb,
  size,
  offset 
)    _safe_erealloc((ptr), (nmemb), (size), (offset) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

Definition at line 88 of file zend_alloc.h.

#define safe_estrdup (   ptr)    ((ptr)?(estrdup(ptr)):STR_EMPTY_ALLOC())

Definition at line 139 of file zend_alloc.h.

#define safe_estrndup (   ptr,
  len 
)    ((ptr)?(estrndup((ptr), (len))):STR_EMPTY_ALLOC())

Definition at line 140 of file zend_alloc.h.

#define safe_pemalloc (   nmemb,
  size,
  offset,
  persistent 
)    ((persistent)?_safe_malloc(nmemb, size, offset):safe_emalloc(nmemb, size, offset))

Definition at line 123 of file zend_alloc.h.

#define safe_perealloc (   ptr,
  nmemb,
  size,
  offset,
  persistent 
)    ((persistent)?_safe_realloc((ptr), (nmemb), (size), (offset)):safe_erealloc((ptr), (nmemb), (size), (offset)))

Definition at line 127 of file zend_alloc.h.

#define ZEND_FAST_ALLOC (   p,
  type,
  fc_type 
)    (p) = (type *) emalloc(sizeof(type))

Definition at line 166 of file zend_alloc.h.

#define ZEND_FAST_ALLOC_REL (   p,
  type,
  fc_type 
)    (p) = (type *) emalloc_rel(sizeof(type))

Definition at line 172 of file zend_alloc.h.

#define ZEND_FAST_FREE (   p,
  fc_type 
)    efree(p)

Definition at line 169 of file zend_alloc.h.

#define ZEND_FAST_FREE_REL (   p,
  fc_type 
)    efree_rel(p)

Definition at line 175 of file zend_alloc.h.

Definition at line 79 of file zend_alloc.h.

Definition at line 91 of file zend_alloc.h.

#define ZEND_MM_ALIGNED_SIZE (   size)    (((size) + ZEND_MM_ALIGNMENT - 1) & ZEND_MM_ALIGNMENT_MASK)

Definition at line 42 of file zend_alloc.h.

#define ZEND_MM_ALIGNMENT_MASK   ~(ZEND_MM_ALIGNMENT-1)

Definition at line 40 of file zend_alloc.h.

#define zend_mm_alloc (   heap,
  size 
)    _zend_mm_alloc((heap), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 214 of file zend_alloc.h.

#define zend_mm_alloc_rel (   heap,
  size 
)    _zend_mm_alloc((heap), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

Definition at line 219 of file zend_alloc.h.

#define zend_mm_block_size (   heap,
 
)    _zend_mm_block_size((heap), (p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 217 of file zend_alloc.h.

Definition at line 222 of file zend_alloc.h.

#define zend_mm_free (   heap,
 
)    _zend_mm_free((heap), (p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 215 of file zend_alloc.h.

#define zend_mm_free_rel (   heap,
 
)    _zend_mm_free((heap), (p) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

Definition at line 220 of file zend_alloc.h.

#define zend_mm_realloc (   heap,
  p,
  size 
)    _zend_mm_realloc((heap), (p), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)

Definition at line 216 of file zend_alloc.h.

#define zend_mm_realloc_rel (   heap,
  p,
  size 
)    _zend_mm_realloc((heap), (p), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

Definition at line 221 of file zend_alloc.h.


Typedef Documentation

typedef struct _zend_mm_heap

Definition at line 205 of file zend_alloc.h.

typedef struct _zend_mm_storage

Definition at line 225 of file zend_alloc.h.


Function Documentation

static void* __zend_calloc ( size_t  nmemb,
size_t  len 
) [inline, static]

Definition at line 103 of file zend_alloc.h.

{
       void *tmp = _safe_malloc(nmemb, len, 0);
       memset(tmp, 0, nmemb * len);
       return tmp;
}

Here is the call graph for this function:

static void* __zend_malloc ( size_t  len) [inline, static]

Definition at line 93 of file zend_alloc.h.

{
       void *tmp = malloc(len);
       if (tmp) {
              return tmp;
       }
       fprintf(stderr, "Out of memory\n");
       exit(1);
}
static void* __zend_realloc ( void *  p,
size_t  len 
) [inline, static]

Definition at line 110 of file zend_alloc.h.

{
       p = realloc(p, len);
       if (p) {
              return p;
       }
       fprintf(stderr, "Out of memory\n");
       exit(1);
}
ZEND_API void* _ecalloc ( size_t  nmemb,
size_t size ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC 
)

Definition at line 2473 of file zend_alloc.c.

{
       void *p;

       p = _safe_emalloc(nmemb, size, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
       if (UNEXPECTED(p == NULL)) {
              return p;
       }
       memset(p, 0, size * nmemb);
       return p;
}

Here is the call graph for this function:

ZEND_API void _efree ( void *ptr ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC)

Definition at line 2353 of file zend_alloc.c.

{
       TSRMLS_FETCH();

       if (UNEXPECTED(!AG(mm_heap)->use_zend_alloc)) {
              AG(mm_heap)->_free(ptr);
              return;
       }
       _zend_mm_free_int(AG(mm_heap), ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}

Here is the call graph for this function:

ZEND_API void* _emalloc ( size_t size ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC)

Definition at line 2343 of file zend_alloc.c.

{
       TSRMLS_FETCH();

       if (UNEXPECTED(!AG(mm_heap)->use_zend_alloc)) {
              return AG(mm_heap)->_malloc(size);
       }
       return _zend_mm_alloc_int(AG(mm_heap), size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API void* _erealloc ( void *  ptr,
size_t  size,
int allow_failure ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC 
)

Definition at line 2364 of file zend_alloc.c.

{
       TSRMLS_FETCH();

       if (UNEXPECTED(!AG(mm_heap)->use_zend_alloc)) {
              return AG(mm_heap)->_realloc(ptr, size);
       }
       return _zend_mm_realloc_int(AG(mm_heap), ptr, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}

Here is the call graph for this function:

ZEND_API char* _estrdup ( const char *s ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC)

Definition at line 2485 of file zend_alloc.c.

{
       int length;
       char *p;

       length = strlen(s)+1;
       p = (char *) _emalloc(length ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
       if (UNEXPECTED(p == NULL)) {
              return p;
       }
       memcpy(p, s, length);
       return p;
}

Here is the call graph for this function:

ZEND_API char* _estrndup ( const char *  s,
unsigned int length ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC 
)

Definition at line 2499 of file zend_alloc.c.

{
       char *p;

       p = (char *) _emalloc(length+1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
       if (UNEXPECTED(p == NULL)) {
              return p;
       }
       memcpy(p, s, length);
       p[length] = 0;
       return p;
}

Here is the call graph for this function:

ZEND_API void* _safe_emalloc ( size_t  nmemb,
size_t  size,
size_t offset ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC 
)

Definition at line 2452 of file zend_alloc.c.

{
       return emalloc_rel(safe_address(nmemb, size, offset));
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API void* _safe_erealloc ( void *  ptr,
size_t  nmemb,
size_t  size,
size_t offset ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC 
)

Definition at line 2462 of file zend_alloc.c.

{
       return erealloc_rel(ptr, safe_address(nmemb, size, offset));
}

Here is the call graph for this function:

ZEND_API void* _safe_malloc ( size_t  nmemb,
size_t  size,
size_t  offset 
)

Definition at line 2457 of file zend_alloc.c.

{
       return pemalloc(safe_address(nmemb, size, offset), 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API void* _safe_realloc ( void *  ptr,
size_t  nmemb,
size_t  size,
size_t  offset 
)

Definition at line 2467 of file zend_alloc.c.

{
       return perealloc(ptr, safe_address(nmemb, size, offset), 1);
}

Here is the call graph for this function:

Definition at line 2374 of file zend_alloc.c.

{
       if (UNEXPECTED(!AG(mm_heap)->use_zend_alloc)) {
              return 0;
       }
       return _zend_mm_block_size(AG(mm_heap), ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}

Here is the call graph for this function:

ZEND_API void* _zend_mm_alloc ( zend_mm_heap *  heap,
size_t size ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC 
)

Definition at line 2291 of file zend_alloc.c.

Here is the call graph for this function:

ZEND_API size_t _zend_mm_block_size ( zend_mm_heap *  heap,
void *p ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC 
)

Definition at line 2306 of file zend_alloc.c.

{
       zend_mm_block *mm_block;

       if (!ZEND_MM_VALID_PTR(p)) {
              return 0;
       }
       mm_block = ZEND_MM_HEADER_OF(p);
       ZEND_MM_CHECK_PROTECTION(mm_block);
#if ZEND_DEBUG || ZEND_MM_HEAP_PROTECTION
       return mm_block->debug.size;
#else
       return ZEND_MM_BLOCK_SIZE(mm_block);
#endif
}

Here is the caller graph for this function:

ZEND_API void _zend_mm_free ( zend_mm_heap *  heap,
void *p ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC 
)

Definition at line 2296 of file zend_alloc.c.

Here is the call graph for this function:

ZEND_API void* _zend_mm_realloc ( zend_mm_heap *  heap,
void *  p,
size_t size ZEND_FILE_LINE_DC  ZEND_FILE_LINE_ORIG_DC 
)

Definition at line 2301 of file zend_alloc.c.

Here is the call graph for this function:

Definition at line 2338 of file zend_alloc.c.

{
       return AG(mm_heap)->use_zend_alloc;
}

Here is the caller graph for this function:

ZEND_API void shutdown_memory_manager ( int  silent,
int full_shutdown  TSRMLS_DC 
)

Definition at line 2560 of file zend_alloc.c.

{
       zend_mm_shutdown(AG(mm_heap), full_shutdown, silent TSRMLS_CC);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2588 of file zend_alloc.c.

{
#ifdef ZTS
       ts_allocate_id(&alloc_globals_id, sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, (ts_allocate_dtor) alloc_globals_dtor);
#else
       alloc_globals_ctor(&alloc_globals);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API size_t zend_memory_peak_usage ( int real_usage  TSRMLS_DC)

Definition at line 2551 of file zend_alloc.c.

{
       if (real_usage) {
              return AG(mm_heap)->real_peak;
       } else {
              return AG(mm_heap)->peak;
       }
}

Here is the caller graph for this function:

ZEND_API size_t zend_memory_usage ( int real_usage  TSRMLS_DC)

Definition at line 2538 of file zend_alloc.c.

{
       if (real_usage) {
              return AG(mm_heap)->real_size;
       } else {
              size_t usage = AG(mm_heap)->size;
#if ZEND_MM_CACHE
              usage -= AG(mm_heap)->cached;
#endif
              return usage;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API zend_mm_storage* zend_mm_get_storage ( zend_mm_heap *  heap)

Definition at line 2606 of file zend_alloc.c.

{
       return heap->storage;
}
ZEND_API void zend_mm_set_custom_handlers ( zend_mm_heap *  heap,
void *(*)(size_t _malloc,
void(*)(void *)  _free,
void *(*)(void *, size_t _realloc 
)

Definition at line 2611 of file zend_alloc.c.

{
       heap->use_zend_alloc = 0;
       heap->_malloc = _malloc;
       heap->_free = _free;
       heap->_realloc = _realloc;
}
ZEND_API zend_mm_heap* zend_mm_set_heap ( zend_mm_heap *new_heap  TSRMLS_DC)

Definition at line 2597 of file zend_alloc.c.

{
       zend_mm_heap *old_heap;

       old_heap = AG(mm_heap);
       AG(mm_heap) = new_heap;
       return old_heap;
}
ZEND_API void zend_mm_shutdown ( zend_mm_heap *  heap,
int  full_shutdown,
int silent  TSRMLS_DC 
)

Definition at line 1574 of file zend_alloc.c.

{
       zend_mm_storage *storage;
       zend_mm_segment *segment;
       zend_mm_segment *prev;
       int internal;

       if (heap->reserve) {
#if ZEND_DEBUG
              if (!silent) {
                     _zend_mm_free_int(heap, heap->reserve ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC);
              }
#endif
              heap->reserve = NULL;
       }

#if ZEND_MM_CACHE_STAT
       if (full_shutdown) {
              FILE *f;

              f = fopen("zend_mm.log", "w");
              if (f) {
                     int i,j;
                     size_t size, true_size, min_size, max_size;
                     int hit = 0, miss = 0;

                     fprintf(f, "\nidx min_size max_size true_size  max_len     hits   misses\n");
                     size = 0;
                     while (1) {
                            true_size = ZEND_MM_TRUE_SIZE(size);
                            if (ZEND_MM_SMALL_SIZE(true_size)) {
                                   min_size = size;
                                   i = ZEND_MM_BUCKET_INDEX(true_size);
                                   size++;
                                   while (1) {
                                          true_size = ZEND_MM_TRUE_SIZE(size);
                                          if (ZEND_MM_SMALL_SIZE(true_size)) {
                                                 j = ZEND_MM_BUCKET_INDEX(true_size);
                                                 if (j > i) {
                                                        max_size = size-1;
                                                        break;
                                                 }
                                          } else {
                                                 max_size = size-1;
                                                 break;
                                          }
                                          size++;
                                   }
                                   hit += heap->cache_stat[i].hit;
                                   miss += heap->cache_stat[i].miss;
                                   fprintf(f, "%2d %8d %8d %9d %8d %8d %8d\n", i, (int)min_size, (int)max_size, ZEND_MM_TRUE_SIZE(max_size), heap->cache_stat[i].max_count, heap->cache_stat[i].hit, heap->cache_stat[i].miss);
                            } else {
                                   break;
                            }
                     }
                     fprintf(f, "                                        %8d %8d\n", hit, miss);
                     fprintf(f, "                                        %8d %8d\n", heap->cache_stat[ZEND_MM_NUM_BUCKETS].hit, heap->cache_stat[ZEND_MM_NUM_BUCKETS].miss);
                     fclose(f);
              }
       }
#endif

#if ZEND_DEBUG
       if (!silent) {
              zend_mm_check_leaks(heap TSRMLS_CC);
       }
#endif

       internal = heap->internal;
       storage = heap->storage;
       segment = heap->segments_list;
       while (segment) {
              prev = segment;
              segment = segment->next_segment;
              ZEND_MM_STORAGE_FREE(prev);
       }
       if (full_shutdown) {
              storage->handlers->dtor(storage);
              if (!internal) {
                     free(heap);
              }
       } else {
              if (heap->compact_size &&
                  heap->real_peak > heap->compact_size) {
                     storage->handlers->compact(storage);
              }
              heap->segments_list = NULL;
              zend_mm_init(heap);
              heap->real_size = 0;
              heap->real_peak = 0;
              heap->size = 0;
              heap->peak = 0;
              if (heap->reserve_size) {
                     heap->reserve = _zend_mm_alloc_int(heap, heap->reserve_size  ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC);
              }
              heap->overflow = 0;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API zend_mm_heap* zend_mm_startup ( void  )

Definition at line 1136 of file zend_alloc.c.

{
       int i;
       size_t seg_size;
       char *mem_type = getenv("ZEND_MM_MEM_TYPE");
       char *tmp;
       const zend_mm_mem_handlers *handlers;
       zend_mm_heap *heap;

       if (mem_type == NULL) {
              i = 0;
       } else {
              for (i = 0; mem_handlers[i].name; i++) {
                     if (strcmp(mem_handlers[i].name, mem_type) == 0) {
                            break;
                     }
              }
              if (!mem_handlers[i].name) {
                     fprintf(stderr, "Wrong or unsupported zend_mm storage type '%s'\n", mem_type);
                     fprintf(stderr, "  supported types:\n");
/* See http://support.microsoft.com/kb/190351 */
#ifdef PHP_WIN32
                     fflush(stderr);
#endif
                     for (i = 0; mem_handlers[i].name; i++) {
                            fprintf(stderr, "    '%s'\n", mem_handlers[i].name);
                     }
/* See http://support.microsoft.com/kb/190351 */
#ifdef PHP_WIN32
                     fflush(stderr);
#endif
                     exit(255);
              }
       }
       handlers = &mem_handlers[i];

       tmp = getenv("ZEND_MM_SEG_SIZE");
       if (tmp) {
              seg_size = zend_atoi(tmp, 0);
              if (zend_mm_low_bit(seg_size) != zend_mm_high_bit(seg_size)) {
                     fprintf(stderr, "ZEND_MM_SEG_SIZE must be a power of two\n");
/* See http://support.microsoft.com/kb/190351 */
#ifdef PHP_WIN32
                     fflush(stderr);
#endif
                     exit(255);
              } else if (seg_size < ZEND_MM_ALIGNED_SEGMENT_SIZE + ZEND_MM_ALIGNED_HEADER_SIZE) {
                     fprintf(stderr, "ZEND_MM_SEG_SIZE is too small\n");
/* See http://support.microsoft.com/kb/190351 */
#ifdef PHP_WIN32
                     fflush(stderr);
#endif
                     exit(255);
              }
       } else {
              seg_size = ZEND_MM_SEG_SIZE;
       }

       heap = zend_mm_startup_ex(handlers, seg_size, ZEND_MM_RESERVE_SIZE, 0, NULL);
       if (heap) {
              tmp = getenv("ZEND_MM_COMPACT");
              if (tmp) {
                     heap->compact_size = zend_atoi(tmp, 0);
              } else {
                     heap->compact_size = 2 * 1024 * 1024;
              }
       }
       return heap;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API zend_mm_heap* zend_mm_startup_ex ( const zend_mm_mem_handlers handlers,
size_t  block_size,
size_t  reserve_size,
int  internal,
void *  params 
)

Definition at line 1016 of file zend_alloc.c.

{
       zend_mm_storage *storage;
       zend_mm_heap    *heap;

#if 0
       int i;

       printf("ZEND_MM_ALIGNMENT=%d\n", ZEND_MM_ALIGNMENT);
       printf("ZEND_MM_ALIGNMENT_LOG2=%d\n", ZEND_MM_ALIGNMENT_LOG2);
       printf("ZEND_MM_MIN_SIZE=%d\n", ZEND_MM_MIN_SIZE);
       printf("ZEND_MM_MAX_SMALL_SIZE=%d\n", ZEND_MM_MAX_SMALL_SIZE);
       printf("ZEND_MM_ALIGNED_HEADER_SIZE=%d\n", ZEND_MM_ALIGNED_HEADER_SIZE);
       printf("ZEND_MM_ALIGNED_FREE_HEADER_SIZE=%d\n", ZEND_MM_ALIGNED_FREE_HEADER_SIZE);
       printf("ZEND_MM_MIN_ALLOC_BLOCK_SIZE=%d\n", ZEND_MM_MIN_ALLOC_BLOCK_SIZE);
       printf("ZEND_MM_ALIGNED_MIN_HEADER_SIZE=%d\n", ZEND_MM_ALIGNED_MIN_HEADER_SIZE);
       printf("ZEND_MM_ALIGNED_SEGMENT_SIZE=%d\n", ZEND_MM_ALIGNED_SEGMENT_SIZE);
       for (i = 0; i < ZEND_MM_MAX_SMALL_SIZE; i++) {
              printf("%3d%c: %3ld %d %2ld\n", i, (i == ZEND_MM_MIN_SIZE?'*':' '), (long)ZEND_MM_TRUE_SIZE(i), ZEND_MM_SMALL_SIZE(ZEND_MM_TRUE_SIZE(i)), (long)ZEND_MM_BUCKET_INDEX(ZEND_MM_TRUE_SIZE(i)));
       }
       exit(0);
#endif

#if ZEND_MM_HEAP_PROTECTION
       if (_mem_block_start_magic == 0) {
              zend_mm_random((unsigned char*)&_mem_block_start_magic, sizeof(_mem_block_start_magic));
       }
       if (_mem_block_end_magic == 0) {
              zend_mm_random((unsigned char*)&_mem_block_end_magic, sizeof(_mem_block_end_magic));
       }
#endif
#if ZEND_MM_COOKIES
       if (_zend_mm_cookie == 0) {
              zend_mm_random((unsigned char*)&_zend_mm_cookie, sizeof(_zend_mm_cookie));
       }
#endif

       if (zend_mm_low_bit(block_size) != zend_mm_high_bit(block_size)) {
              fprintf(stderr, "'block_size' must be a power of two\n");
/* See http://support.microsoft.com/kb/190351 */
#ifdef PHP_WIN32
              fflush(stderr);
#endif
              exit(255);
       }
       storage = handlers->init(params);
       if (!storage) {
              fprintf(stderr, "Cannot initialize zend_mm storage [%s]\n", handlers->name);
/* See http://support.microsoft.com/kb/190351 */
#ifdef PHP_WIN32
              fflush(stderr);
#endif
              exit(255);
       }
       storage->handlers = handlers;

       heap = malloc(sizeof(struct _zend_mm_heap));
       if (heap == NULL) {
              fprintf(stderr, "Cannot allocate heap for zend_mm storage [%s]\n", handlers->name);
#ifdef PHP_WIN32
              fflush(stderr);
#endif
              exit(255);
       }
       heap->storage = storage;
       heap->block_size = block_size;
       heap->compact_size = 0;
       heap->segments_list = NULL;
       zend_mm_init(heap);
# if ZEND_MM_CACHE_STAT
       memset(heap->cache_stat, 0, sizeof(heap->cache_stat));
# endif

       heap->use_zend_alloc = 1;
       heap->real_size = 0;
       heap->overflow = 0;
       heap->real_peak = 0;
       heap->limit = ZEND_MM_LONG_CONST(1)<<(ZEND_MM_NUM_BUCKETS-2);
       heap->size = 0;
       heap->peak = 0;
       heap->internal = internal;
       heap->reserve = NULL;
       heap->reserve_size = reserve_size;
       if (reserve_size > 0) {
              heap->reserve = _zend_mm_alloc_int(heap, reserve_size ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC);
       }
       if (internal) {
              int i;
              zend_mm_free_block *p, *q, *orig;
              zend_mm_heap *mm_heap = _zend_mm_alloc_int(heap, sizeof(zend_mm_heap)  ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC);

              *mm_heap = *heap;

              p = ZEND_MM_SMALL_FREE_BUCKET(mm_heap, 0);
              orig = ZEND_MM_SMALL_FREE_BUCKET(heap, 0);
              for (i = 0; i < ZEND_MM_NUM_BUCKETS; i++) {
                     q = p;
                     while (q->prev_free_block != orig) {
                            q = q->prev_free_block;
                     }
                     q->prev_free_block = p;
                     q = p;
                     while (q->next_free_block != orig) {
                            q = q->next_free_block;
                     }
                     q->next_free_block = p;
                     p = (zend_mm_free_block*)((char*)p + sizeof(zend_mm_free_block*) * 2);
                     orig = (zend_mm_free_block*)((char*)orig + sizeof(zend_mm_free_block*) * 2);
                     if (mm_heap->large_free_buckets[i]) {
                            mm_heap->large_free_buckets[i]->parent = &mm_heap->large_free_buckets[i];
                     }
              }
              mm_heap->rest_buckets[0] = mm_heap->rest_buckets[1] = ZEND_MM_REST_BUCKET(mm_heap);

              free(heap);
              heap = mm_heap;
       }
       return heap;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2529 of file zend_alloc.c.

{
       TSRMLS_FETCH();

       AG(mm_heap)->limit = (memory_limit >= AG(mm_heap)->block_size) ? memory_limit : AG(mm_heap)->block_size;

       return SUCCESS;
}

Here is the caller graph for this function:

ZEND_API char* zend_strndup ( const char *  s,
unsigned int  length 
)

Definition at line 2513 of file zend_alloc.c.

{
       char *p;

       p = (char *) malloc(length+1);
       if (UNEXPECTED(p == NULL)) {
              return p;
       }
       if (length) {
              memcpy(p, s, length);
       }
       p[length] = 0;
       return p;
}

Here is the caller graph for this function: