1999-04-07 18:10:10 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 17:33:29 +00:00
|
|
|
| Copyright (c) 1998-2004 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-04-07 18:10:10 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 15:16:21 +00:00
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
1999-07-16 14:58:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2001-12-11 15:16:21 +00:00
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
1999-07-16 14:58:16 +00:00
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
1999-04-07 18:10:10 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2003-02-01 01:49:15 +00:00
|
|
|
/* $Id$ */
|
1999-07-16 14:58:16 +00:00
|
|
|
|
2000-07-03 00:55:36 +00:00
|
|
|
#ifndef ZEND_ALLOC_H
|
|
|
|
#define ZEND_ALLOC_H
|
1999-04-07 18:10:10 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2000-11-18 02:43:23 +00:00
|
|
|
#include "../TSRM/TSRM.h"
|
1999-09-05 19:03:35 +00:00
|
|
|
#include "zend_globals_macros.h"
|
|
|
|
|
2002-06-24 07:22:25 +00:00
|
|
|
#include "zend_mm.h"
|
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
#define MEM_BLOCK_START_MAGIC 0x7312F8DCL
|
2001-04-29 13:06:00 +00:00
|
|
|
#define MEM_BLOCK_END_MAGIC 0x2A8FCC84L
|
1999-04-07 18:10:10 +00:00
|
|
|
#define MEM_BLOCK_FREED_MAGIC 0x99954317L
|
|
|
|
#define MEM_BLOCK_CACHED_MAGIC 0xFB8277DCL
|
|
|
|
|
1999-12-26 20:45:42 +00:00
|
|
|
typedef struct _zend_mem_header {
|
1999-04-07 18:10:10 +00:00
|
|
|
#if ZEND_DEBUG
|
|
|
|
long magic;
|
|
|
|
char *filename;
|
|
|
|
uint lineno;
|
1999-06-26 11:48:22 +00:00
|
|
|
int reported;
|
1999-08-28 10:18:54 +00:00
|
|
|
char *orig_filename;
|
|
|
|
uint orig_lineno;
|
2000-11-18 02:43:23 +00:00
|
|
|
# ifdef ZTS
|
|
|
|
THREAD_T thread_id;
|
|
|
|
# endif
|
1999-04-07 18:10:10 +00:00
|
|
|
#endif
|
2004-05-25 10:09:46 +00:00
|
|
|
#if ZEND_DEBUG || !defined(ZEND_MM)
|
1999-12-26 20:45:42 +00:00
|
|
|
struct _zend_mem_header *pNext;
|
|
|
|
struct _zend_mem_header *pLast;
|
2002-06-24 07:22:25 +00:00
|
|
|
#endif
|
2004-07-15 22:59:54 +00:00
|
|
|
unsigned int size;
|
1999-12-26 20:45:42 +00:00
|
|
|
} zend_mem_header;
|
1999-04-07 18:10:10 +00:00
|
|
|
|
1999-05-22 16:10:51 +00:00
|
|
|
typedef union _align_test {
|
1999-04-07 18:10:10 +00:00
|
|
|
void *ptr;
|
|
|
|
double dbl;
|
|
|
|
long lng;
|
|
|
|
} align_test;
|
|
|
|
|
2000-06-22 18:33:09 +00:00
|
|
|
#define MAX_CACHED_MEMORY 11
|
|
|
|
#define MAX_CACHED_ENTRIES 256
|
|
|
|
#define PRE_INIT_CACHE_ENTRIES 32
|
|
|
|
|
2003-08-28 14:53:02 +00:00
|
|
|
#if ZEND_GCC_VERSION >= 2000
|
2003-08-28 05:50:15 +00:00
|
|
|
# define PLATFORM_ALIGNMENT (__alignof__ (align_test))
|
2000-01-29 09:14:22 +00:00
|
|
|
#else
|
2003-08-28 05:50:15 +00:00
|
|
|
# define PLATFORM_ALIGNMENT (sizeof(align_test))
|
2003-08-28 06:17:05 +00:00
|
|
|
#endif
|
|
|
|
|
2001-04-29 13:00:46 +00:00
|
|
|
#define MEM_HEADER_PADDING (((PLATFORM_ALIGNMENT-sizeof(zend_mem_header))%PLATFORM_ALIGNMENT+PLATFORM_ALIGNMENT)%PLATFORM_ALIGNMENT)
|
1999-04-07 18:10:10 +00:00
|
|
|
|
|
|
|
|
1999-04-23 03:32:33 +00:00
|
|
|
BEGIN_EXTERN_C()
|
|
|
|
|
2003-08-28 05:50:15 +00:00
|
|
|
ZEND_API char *zend_strndup(const char *s, unsigned int length) ZEND_ATTRIBUTE_MALLOC;
|
2000-10-29 22:40:01 +00:00
|
|
|
|
2003-08-28 05:50:15 +00:00
|
|
|
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;
|
2004-07-20 21:55:57 +00:00
|
|
|
ZEND_API void *_safe_malloc(size_t nmemb, size_t size, size_t offset) ZEND_ATTRIBUTE_MALLOC;
|
1999-08-28 10:18:54 +00:00
|
|
|
ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
|
2003-08-28 05:50:15 +00:00
|
|
|
ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC;
|
1999-08-28 10:18:54 +00:00
|
|
|
ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
|
2003-08-28 05:50:15 +00:00
|
|
|
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;
|
1999-08-27 19:17:19 +00:00
|
|
|
|
|
|
|
/* Standard wrapper macros */
|
1999-08-28 10:18:54 +00:00
|
|
|
#define emalloc(size) _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
2003-04-24 03:35:06 +00:00
|
|
|
#define safe_emalloc(nmemb, size, offset) _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
1999-08-28 10:18:54 +00:00
|
|
|
#define efree(ptr) _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
2001-08-11 15:56:40 +00:00
|
|
|
#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 erealloc_recoverable(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
1999-08-28 10:18:54 +00:00
|
|
|
#define estrdup(s) _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
2001-08-11 15:56:40 +00:00
|
|
|
#define estrndup(s, length) _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
1999-08-27 19:17:19 +00:00
|
|
|
|
|
|
|
/* Relay wrapper macros */
|
1999-08-28 10:18:54 +00:00
|
|
|
#define emalloc_rel(size) _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
2003-04-24 03:35:06 +00:00
|
|
|
#define safe_emalloc_rel(nmemb, size, offset) _safe_emalloc((nmemb), (size), (offset) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
1999-08-28 10:18:54 +00:00
|
|
|
#define efree_rel(ptr) _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
2002-04-28 06:24:15 +00:00
|
|
|
#define ecalloc_rel(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
|
1999-08-28 10:18:54 +00:00
|
|
|
#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 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)
|
1999-08-27 19:17:19 +00:00
|
|
|
|
|
|
|
/* Selective persistent/non persistent allocation macros */
|
2001-08-11 15:56:40 +00:00
|
|
|
#define pemalloc(size, persistent) ((persistent)?malloc(size):emalloc(size))
|
2004-07-20 21:55:57 +00:00
|
|
|
#define safe_pemalloc(nmemb, size, offset, persistent) ((persistent)?_safe_malloc(nmemb, size, offset):safe_emalloc(nmemb, size, offset))
|
2001-08-11 15:56:40 +00:00
|
|
|
#define pefree(ptr, persistent) ((persistent)?free(ptr):efree(ptr))
|
|
|
|
#define pecalloc(nmemb, size, persistent) ((persistent)?calloc((nmemb), (size)):ecalloc((nmemb), (size)))
|
|
|
|
#define perealloc(ptr, size, persistent) ((persistent)?realloc((ptr), (size)):erealloc((ptr), (size)))
|
|
|
|
#define perealloc_recoverable(ptr, size, persistent) ((persistent)?realloc((ptr), (size)):erealloc_recoverable((ptr), (size)))
|
|
|
|
#define pestrdup(s, persistent) ((persistent)?strdup(s):estrdup(s))
|
1999-04-07 18:10:10 +00:00
|
|
|
|
2003-08-18 21:17:26 +00:00
|
|
|
#define pemalloc_rel(size, persistent) ((persistent)?malloc(size):emalloc_rel(size))
|
|
|
|
#define pefree_rel(ptr, persistent) ((persistent)?free(ptr):efree_rel(ptr))
|
|
|
|
#define pecalloc_rel(nmemb, size, persistent) ((persistent)?calloc((nmemb), (size)):ecalloc_rel((nmemb), (size)))
|
|
|
|
#define perealloc_rel(ptr, size, persistent) ((persistent)?realloc((ptr), (size)):erealloc_rel((ptr), (size)))
|
|
|
|
#define perealloc_recoverable_rel(ptr, size, persistent) ((persistent)?realloc((ptr), (size)):erealloc_recoverable_rel((ptr), (size)))
|
|
|
|
#define pestrdup_rel(s, persistent) ((persistent)?strdup(s):estrdup_rel(s))
|
|
|
|
|
2004-07-19 07:19:50 +00:00
|
|
|
#define safe_estrdup(ptr) ((ptr)?(estrdup(ptr)):STR_EMPTY_ALLOC())
|
|
|
|
#define safe_estrndup(ptr, len) ((ptr)?(estrndup((ptr), (len))):STR_EMPTY_ALLOC())
|
1999-04-07 18:10:10 +00:00
|
|
|
|
1999-04-10 16:24:28 +00:00
|
|
|
ZEND_API int zend_set_memory_limit(unsigned int memory_limit);
|
1999-04-10 14:44:35 +00:00
|
|
|
|
2001-07-28 10:51:54 +00:00
|
|
|
ZEND_API void start_memory_manager(TSRMLS_D);
|
2004-05-25 08:33:11 +00:00
|
|
|
ZEND_API void shutdown_memory_manager(int silent, int full_shutdown TSRMLS_DC);
|
1999-04-07 18:10:10 +00:00
|
|
|
|
|
|
|
#if ZEND_DEBUG
|
1999-08-28 10:18:54 +00:00
|
|
|
ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
|
|
|
|
ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
|
1999-12-01 22:55:20 +00:00
|
|
|
void zend_debug_alloc_output(char *format, ...);
|
1999-08-28 10:18:54 +00:00
|
|
|
#define mem_block_check(ptr, silent) _mem_block_check(ptr, silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
|
|
|
#define full_mem_check(silent) _full_mem_check(silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
|
1999-04-07 18:10:10 +00:00
|
|
|
#else
|
|
|
|
#define mem_block_check(type, ptr, silent)
|
|
|
|
#define full_mem_check(silent)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-04-23 03:32:33 +00:00
|
|
|
END_EXTERN_C()
|
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
2003-02-01 01:49:15 +00:00
|
|
|
* indent-tabs-mode: t
|
1999-04-07 18:10:10 +00:00
|
|
|
* End:
|
|
|
|
*/
|