@@ -272,6 +272,8 @@ struct _zend_mm_heap {
272
272
void * (* _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
273
273
void (* _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
274
274
void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
275
+ size_t (* _gc )(void );
276
+ void (* _shutdown )(bool full , bool silent );
275
277
} custom_heap ;
276
278
HashTable * tracked_allocs ;
277
279
#endif
@@ -1961,6 +1963,10 @@ ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
1961
1963
1962
1964
#if ZEND_MM_CUSTOM
1963
1965
if (heap -> use_custom_heap ) {
1966
+ size_t (* gc )(void ) = heap -> custom_heap ._gc ;
1967
+ if (gc ) {
1968
+ return gc ();
1969
+ }
1964
1970
return 0 ;
1965
1971
}
1966
1972
#endif
@@ -2255,10 +2261,10 @@ static void zend_mm_check_leaks(zend_mm_heap *heap)
2255
2261
2256
2262
#if ZEND_MM_CUSTOM
2257
2263
static void * tracked_malloc (size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
2258
- static void tracked_free_all (void );
2264
+ static void tracked_free_all (zend_mm_heap * heap );
2259
2265
#endif
2260
2266
2261
- void zend_mm_shutdown (zend_mm_heap * heap , bool full , bool silent )
2267
+ ZEND_API void zend_mm_shutdown (zend_mm_heap * heap , bool full , bool silent )
2262
2268
{
2263
2269
zend_mm_chunk * p ;
2264
2270
zend_mm_huge_list * list ;
@@ -2267,7 +2273,7 @@ void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
2267
2273
if (heap -> use_custom_heap ) {
2268
2274
if (heap -> custom_heap ._malloc == tracked_malloc ) {
2269
2275
if (silent ) {
2270
- tracked_free_all ();
2276
+ tracked_free_all (heap );
2271
2277
}
2272
2278
zend_hash_clean (heap -> tracked_allocs );
2273
2279
if (full ) {
@@ -2279,9 +2285,16 @@ void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
2279
2285
heap -> size = 0 ;
2280
2286
}
2281
2287
2288
+ void (* shutdown )(bool , bool ) = heap -> custom_heap ._shutdown ;
2289
+
2282
2290
if (full ) {
2283
2291
heap -> custom_heap ._free (heap ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC );
2284
2292
}
2293
+
2294
+ if (shutdown ) {
2295
+ shutdown (full , silent );
2296
+ }
2297
+
2285
2298
return ;
2286
2299
}
2287
2300
#endif
@@ -2854,8 +2867,8 @@ static void *tracked_realloc(void *ptr, size_t new_size ZEND_FILE_LINE_DC ZEND_F
2854
2867
return ptr ;
2855
2868
}
2856
2869
2857
- static void tracked_free_all (void ) {
2858
- HashTable * tracked_allocs = AG ( mm_heap ) -> tracked_allocs ;
2870
+ static void tracked_free_all (zend_mm_heap * heap ) {
2871
+ HashTable * tracked_allocs = heap -> tracked_allocs ;
2859
2872
zend_ulong h ;
2860
2873
ZEND_HASH_FOREACH_NUM_KEY (tracked_allocs , h ) {
2861
2874
void * ptr = (void * ) (uintptr_t ) (h << ZEND_MM_ALIGNMENT_LOG2 );
@@ -2939,6 +2952,16 @@ ZEND_API zend_mm_heap *zend_mm_get_heap(void)
2939
2952
return AG (mm_heap );
2940
2953
}
2941
2954
2955
+ ZEND_API zend_mm_heap * zend_mm_heap_create (void )
2956
+ {
2957
+ return zend_mm_init ();
2958
+ }
2959
+
2960
+ ZEND_API void zend_mm_heap_free (zend_mm_heap * heap )
2961
+ {
2962
+ zend_mm_chunk_free (heap , heap -> main_chunk , ZEND_MM_CHUNK_SIZE );
2963
+ }
2964
+
2942
2965
ZEND_API bool zend_mm_is_custom_heap (zend_mm_heap * new_heap )
2943
2966
{
2944
2967
#if ZEND_MM_CUSTOM
@@ -2951,7 +2974,9 @@ ZEND_API bool zend_mm_is_custom_heap(zend_mm_heap *new_heap)
2951
2974
ZEND_API void zend_mm_set_custom_handlers (zend_mm_heap * heap ,
2952
2975
void * (* _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
2953
2976
void (* _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
2954
- void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ))
2977
+ void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
2978
+ size_t (* _gc )(void ),
2979
+ void (* _shutdown )(bool , bool ))
2955
2980
{
2956
2981
#if ZEND_MM_CUSTOM
2957
2982
zend_mm_heap * _heap = (zend_mm_heap * )heap ;
@@ -2963,14 +2988,18 @@ ZEND_API void zend_mm_set_custom_handlers(zend_mm_heap *heap,
2963
2988
_heap -> custom_heap ._malloc = _malloc ;
2964
2989
_heap -> custom_heap ._free = _free ;
2965
2990
_heap -> custom_heap ._realloc = _realloc ;
2991
+ _heap -> custom_heap ._gc = _gc ;
2992
+ _heap -> custom_heap ._shutdown = _shutdown ;
2966
2993
}
2967
2994
#endif
2968
2995
}
2969
2996
2970
2997
ZEND_API void zend_mm_get_custom_handlers (zend_mm_heap * heap ,
2971
2998
void * (* * _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
2972
2999
void (* * _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
2973
- void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ))
3000
+ void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3001
+ size_t (* * _gc )(void ),
3002
+ void (* * _shutdown )(bool , bool ))
2974
3003
{
2975
3004
#if ZEND_MM_CUSTOM
2976
3005
zend_mm_heap * _heap = (zend_mm_heap * )heap ;
@@ -2979,15 +3008,29 @@ ZEND_API void zend_mm_get_custom_handlers(zend_mm_heap *heap,
2979
3008
* _malloc = _heap -> custom_heap ._malloc ;
2980
3009
* _free = _heap -> custom_heap ._free ;
2981
3010
* _realloc = _heap -> custom_heap ._realloc ;
3011
+ if (_gc != NULL ) {
3012
+ * _gc = _heap -> custom_heap ._gc ;
3013
+ }
3014
+ if (_shutdown != NULL ) {
3015
+ * _shutdown = _heap -> custom_heap ._shutdown ;
3016
+ }
2982
3017
} else {
2983
3018
* _malloc = NULL ;
2984
3019
* _free = NULL ;
2985
3020
* _realloc = NULL ;
3021
+ if (_gc != NULL ) {
3022
+ * _gc = NULL ;
3023
+ }
3024
+ if (_shutdown != NULL ) {
3025
+ * _shutdown = NULL ;
3026
+ }
2986
3027
}
2987
3028
#else
2988
3029
* _malloc = NULL ;
2989
3030
* _free = NULL ;
2990
3031
* _realloc = NULL ;
3032
+ * _gc = NULL ;
3033
+ * _shutdown = NULL ;
2991
3034
#endif
2992
3035
}
2993
3036
0 commit comments