@@ -334,6 +334,8 @@ struct _zend_mm_heap {
334
334
void * (* _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
335
335
void (* _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
336
336
void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
337
+ size_t (* _gc )(void );
338
+ void (* _shutdown )(bool full , bool silent );
337
339
} custom_heap ;
338
340
HashTable * tracked_allocs ;
339
341
#endif
@@ -2119,6 +2121,10 @@ ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
2119
2121
2120
2122
#if ZEND_MM_CUSTOM
2121
2123
if (heap -> use_custom_heap ) {
2124
+ size_t (* gc )(void ) = heap -> custom_heap ._gc ;
2125
+ if (gc ) {
2126
+ return gc ();
2127
+ }
2122
2128
return 0 ;
2123
2129
}
2124
2130
#endif
@@ -2421,10 +2427,10 @@ static void zend_mm_check_leaks(zend_mm_heap *heap)
2421
2427
2422
2428
#if ZEND_MM_CUSTOM
2423
2429
static void * tracked_malloc (size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
2424
- static void tracked_free_all (void );
2430
+ static void tracked_free_all (zend_mm_heap * heap );
2425
2431
#endif
2426
2432
2427
- void zend_mm_shutdown (zend_mm_heap * heap , bool full , bool silent )
2433
+ ZEND_API void zend_mm_shutdown (zend_mm_heap * heap , bool full , bool silent )
2428
2434
{
2429
2435
zend_mm_chunk * p ;
2430
2436
zend_mm_huge_list * list ;
@@ -2433,7 +2439,7 @@ void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
2433
2439
if (heap -> use_custom_heap ) {
2434
2440
if (heap -> custom_heap ._malloc == tracked_malloc ) {
2435
2441
if (silent ) {
2436
- tracked_free_all ();
2442
+ tracked_free_all (heap );
2437
2443
}
2438
2444
zend_hash_clean (heap -> tracked_allocs );
2439
2445
if (full ) {
@@ -2445,9 +2451,16 @@ void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
2445
2451
heap -> size = 0 ;
2446
2452
}
2447
2453
2454
+ void (* shutdown )(bool , bool ) = heap -> custom_heap ._shutdown ;
2455
+
2448
2456
if (full ) {
2449
2457
heap -> custom_heap ._free (heap ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC );
2450
2458
}
2459
+
2460
+ if (shutdown ) {
2461
+ shutdown (full , silent );
2462
+ }
2463
+
2451
2464
return ;
2452
2465
}
2453
2466
#endif
@@ -3039,8 +3052,8 @@ static void *tracked_realloc(void *ptr, size_t new_size ZEND_FILE_LINE_DC ZEND_F
3039
3052
return ptr ;
3040
3053
}
3041
3054
3042
- static void tracked_free_all (void ) {
3043
- HashTable * tracked_allocs = AG ( mm_heap ) -> tracked_allocs ;
3055
+ static void tracked_free_all (zend_mm_heap * heap ) {
3056
+ HashTable * tracked_allocs = heap -> tracked_allocs ;
3044
3057
zend_ulong h ;
3045
3058
ZEND_HASH_FOREACH_NUM_KEY (tracked_allocs , h ) {
3046
3059
void * ptr = (void * ) (uintptr_t ) (h << ZEND_MM_ALIGNMENT_LOG2 );
@@ -3124,6 +3137,16 @@ ZEND_API zend_mm_heap *zend_mm_get_heap(void)
3124
3137
return AG (mm_heap );
3125
3138
}
3126
3139
3140
+ ZEND_API zend_mm_heap * zend_mm_heap_create (void )
3141
+ {
3142
+ return zend_mm_init ();
3143
+ }
3144
+
3145
+ ZEND_API void zend_mm_heap_free (zend_mm_heap * heap )
3146
+ {
3147
+ zend_mm_chunk_free (heap , heap -> main_chunk , ZEND_MM_CHUNK_SIZE );
3148
+ }
3149
+
3127
3150
ZEND_API bool zend_mm_is_custom_heap (zend_mm_heap * new_heap )
3128
3151
{
3129
3152
#if ZEND_MM_CUSTOM
@@ -3136,7 +3159,9 @@ ZEND_API bool zend_mm_is_custom_heap(zend_mm_heap *new_heap)
3136
3159
ZEND_API void zend_mm_set_custom_handlers (zend_mm_heap * heap ,
3137
3160
void * (* _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3138
3161
void (* _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3139
- void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ))
3162
+ void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3163
+ size_t (* _gc )(void ),
3164
+ void (* _shutdown )(bool , bool ))
3140
3165
{
3141
3166
#if ZEND_MM_CUSTOM
3142
3167
zend_mm_heap * _heap = (zend_mm_heap * )heap ;
@@ -3148,14 +3173,18 @@ ZEND_API void zend_mm_set_custom_handlers(zend_mm_heap *heap,
3148
3173
_heap -> custom_heap ._malloc = _malloc ;
3149
3174
_heap -> custom_heap ._free = _free ;
3150
3175
_heap -> custom_heap ._realloc = _realloc ;
3176
+ _heap -> custom_heap ._gc = _gc ;
3177
+ _heap -> custom_heap ._shutdown = _shutdown ;
3151
3178
}
3152
3179
#endif
3153
3180
}
3154
3181
3155
3182
ZEND_API void zend_mm_get_custom_handlers (zend_mm_heap * heap ,
3156
3183
void * (* * _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3157
3184
void (* * _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3158
- void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ))
3185
+ void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3186
+ size_t (* * _gc )(void ),
3187
+ void (* * _shutdown )(bool , bool ))
3159
3188
{
3160
3189
#if ZEND_MM_CUSTOM
3161
3190
zend_mm_heap * _heap = (zend_mm_heap * )heap ;
@@ -3164,15 +3193,29 @@ ZEND_API void zend_mm_get_custom_handlers(zend_mm_heap *heap,
3164
3193
* _malloc = _heap -> custom_heap ._malloc ;
3165
3194
* _free = _heap -> custom_heap ._free ;
3166
3195
* _realloc = _heap -> custom_heap ._realloc ;
3196
+ if (_gc != NULL ) {
3197
+ * _gc = _heap -> custom_heap ._gc ;
3198
+ }
3199
+ if (_shutdown != NULL ) {
3200
+ * _shutdown = _heap -> custom_heap ._shutdown ;
3201
+ }
3167
3202
} else {
3168
3203
* _malloc = NULL ;
3169
3204
* _free = NULL ;
3170
3205
* _realloc = NULL ;
3206
+ if (_gc != NULL ) {
3207
+ * _gc = NULL ;
3208
+ }
3209
+ if (_shutdown != NULL ) {
3210
+ * _shutdown = NULL ;
3211
+ }
3171
3212
}
3172
3213
#else
3173
3214
* _malloc = NULL ;
3174
3215
* _free = NULL ;
3175
3216
* _realloc = NULL ;
3217
+ * _gc = NULL ;
3218
+ * _shutdown = NULL ;
3176
3219
#endif
3177
3220
}
3178
3221
0 commit comments