diff options
-rw-r--r-- | Zend/zend_alloc.c | 34 | ||||
-rw-r--r-- | Zend/zend_alloc.h | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index eee64c3872..7043939db1 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -2376,6 +2376,40 @@ ZEND_API int is_zend_mm(void) #endif } +ZEND_API int is_zend_ptr(const void *ptr) +{ +#if ZEND_MM_CUSTOM + if (AG(mm_heap)->use_custom_heap) { + return 0; + } +#endif + + if (AG(mm_heap)->main_chunk) { + zend_mm_chunk *chunk = AG(mm_heap)->main_chunk; + + do { + if (ptr >= (void*)chunk + && ptr < (void*)((char*)chunk + ZEND_MM_CHUNK_SIZE)) { + return 1; + } + chunk = chunk->next; + } while (chunk != AG(mm_heap)->main_chunk); + } + + if (AG(mm_heap)->huge_list) { + zend_mm_huge_list *block = AG(mm_heap)->huge_list; + + do { + if (ptr >= (void*)block + && ptr < (void*)((char*)block + block->size)) { + return 1; + } + block = block->next; + } while (block != AG(mm_heap)->huge_list); + } + return 0; +} + #if !ZEND_DEBUG && defined(HAVE_BUILTIN_CONSTANT_P) #undef _emalloc diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h index b3986ab961..0fa20cad34 100644 --- a/Zend/zend_alloc.h +++ b/Zend/zend_alloc.h @@ -224,6 +224,7 @@ ZEND_API int zend_set_memory_limit(size_t memory_limit); ZEND_API void start_memory_manager(void); ZEND_API void shutdown_memory_manager(int silent, int full_shutdown); ZEND_API int is_zend_mm(void); +ZEND_API int is_zend_ptr(const void *ptr); ZEND_API size_t zend_memory_usage(int real_usage); ZEND_API size_t zend_memory_peak_usage(int real_usage); |