diff options
author | Zeev Suraski <zeev@php.net> | 2000-11-18 02:43:23 +0000 |
---|---|---|
committer | Zeev Suraski <zeev@php.net> | 2000-11-18 02:43:23 +0000 |
commit | 9a0b61a6195433a7115b040b47df03ec46f5117d (patch) | |
tree | d7aee9cf0ccf8bc59cd547568806c34b2d2bdeb5 /Zend/zend_alloc.c | |
parent | 1ebdb6fa14ab47c70600c0c6c6c96ff09f161b90 (diff) | |
download | php-git-9a0b61a6195433a7115b040b47df03ec46f5117d.tar.gz |
Add thread-safety debugging information (idea - Dmitri Dmitrienko)
Diffstat (limited to 'Zend/zend_alloc.c')
-rw-r--r-- | Zend/zend_alloc.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 537b8d68ff..dd17fb33ba 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -137,6 +137,9 @@ ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) p->orig_lineno = __zend_orig_lineno; p->magic = MEM_BLOCK_START_MAGIC; p->reported = 0; + /* Setting the thread id should not be necessary, because we fetched this block + * from this thread's cache + */ AG(cache_stats)[CACHE_INDEX][1]++; #endif p->persistent = 0; @@ -177,6 +180,9 @@ ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) p->orig_lineno = __zend_orig_lineno; p->magic = MEM_BLOCK_START_MAGIC; p->reported = 0; +# ifdef ZTS + p->thread_id = tsrm_thread_id(); +# endif *((long *)(((char *) p) + sizeof(zend_mem_header)+SIZE+PLATFORM_PADDING+END_ALIGNMENT(SIZE))) = MEM_BLOCK_END_MAGIC; #endif #if MEMORY_LIMIT @@ -193,6 +199,17 @@ ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) DECLARE_CACHE_VARS ALS_FETCH(); +#ifdef ZTS + if (p->thread_id != tsrm_thread_id()) { +# if ZEND_DEBUG + tsrm_error(TSRM_ERROR_LEVEL_ERROR, "Memory block allocated at %s:(%d) on thread %x freed at %s:(%d) on thread %x, ignoring", + p->filename, p->lineno, p->thread_id, + __zend_filename, __zend_lineno, tsrm_thread_id()); +# endif + return; + } +#endif + CALCULATE_REAL_SIZE_AND_CACHE_INDEX(p->size); #if ZEND_DEBUG if (!_mem_block_check(ptr, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC)) { @@ -253,6 +270,21 @@ ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LIN return _emalloc(size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); } +#ifdef ZTS + if (p->thread_id != tsrm_thread_id()) { + void *new_p; + +# if ZEND_DEBUG + tsrm_error(TSRM_ERROR_LEVEL_ERROR, "Memory block allocated at %s:(%d) on thread %x reallocated at %s:(%d) on thread %x, duplicating", + p->filename, p->lineno, p->thread_id, + __zend_filename, __zend_lineno, tsrm_thread_id()); +# endif + new_p = _emalloc(size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + memcpy(new_p, ptr, p->size); + return new_p; + } +#endif + CALCULATE_REAL_SIZE_AND_CACHE_INDEX(size); HANDLE_BLOCK_INTERRUPTIONS(); |