mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Add thread-safety debugging information (idea - Dmitri Dmitrienko)
This commit is contained in:
parent
1ebdb6fa14
commit
9a0b61a619
2 changed files with 36 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../TSRM/TSRM.h"
|
||||
#include "zend_globals_macros.h"
|
||||
|
||||
#define MEM_BLOCK_START_MAGIC 0x7312F8DCL
|
||||
|
@ -38,6 +39,9 @@ typedef struct _zend_mem_header {
|
|||
int reported;
|
||||
char *orig_filename;
|
||||
uint orig_lineno;
|
||||
# ifdef ZTS
|
||||
THREAD_T thread_id;
|
||||
# endif
|
||||
#endif
|
||||
struct _zend_mem_header *pNext;
|
||||
struct _zend_mem_header *pLast;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue