]> granicus.if.org Git - php/commitdiff
Provide is_zend_ptr() function to check if a pointer lays in Zend MM heap.
authorDmitry Stogov <dmitry@zend.com>
Wed, 12 Dec 2018 10:02:28 +0000 (13:02 +0300)
committerDmitry Stogov <dmitry@zend.com>
Wed, 12 Dec 2018 10:02:28 +0000 (13:02 +0300)
Zend/zend_alloc.c
Zend/zend_alloc.h

index eee64c3872c959a1185efa6a556aaf5b5b006a9d..7043939db18edeb6e199916be5ca3dbe31569bc7 100644 (file)
@@ -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
 
index b3986ab9618446249c7e40ea42dd757b051708b1..0fa20cad34ae180d50ab2d61217017b20aa51026 100644 (file)
@@ -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);