@@ -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 );
@@ -3138,6 +3151,18 @@ ZEND_API void zend_mm_set_custom_handlers(zend_mm_heap *heap,
3138
3151
void (* _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3139
3152
void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ))
3140
3153
{
3154
+ #if ZEND_MM_CUSTOM
3155
+ zend_mm_set_custom_handlers_ex (heap , _malloc , _free , _realloc , NULL , NULL );
3156
+ #endif
3157
+ }
3158
+
3159
+ ZEND_API void zend_mm_set_custom_handlers_ex (zend_mm_heap * heap ,
3160
+ void * (* _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3161
+ void (* _free )(void * 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 ))
3165
+ {
3141
3166
#if ZEND_MM_CUSTOM
3142
3167
zend_mm_heap * _heap = (zend_mm_heap * )heap ;
3143
3168
@@ -3148,14 +3173,28 @@ 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
- void * (* * _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3157
- 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 ))
3183
+ void * (* * _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3184
+ void (* * _free )(void * 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
+ {
3187
+ #if ZEND_MM_CUSTOM
3188
+ zend_mm_get_custom_handlers_ex (heap , _malloc , _free , _realloc , NULL , NULL );
3189
+ #endif
3190
+ }
3191
+
3192
+ ZEND_API void zend_mm_get_custom_handlers_ex (zend_mm_heap * heap ,
3193
+ void * (* * _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3194
+ void (* * _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3195
+ void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3196
+ size_t (* * _gc )(void ),
3197
+ void (* * _shutdown )(bool , bool ))
3159
3198
{
3160
3199
#if ZEND_MM_CUSTOM
3161
3200
zend_mm_heap * _heap = (zend_mm_heap * )heap ;
@@ -3164,15 +3203,29 @@ ZEND_API void zend_mm_get_custom_handlers(zend_mm_heap *heap,
3164
3203
* _malloc = _heap -> custom_heap ._malloc ;
3165
3204
* _free = _heap -> custom_heap ._free ;
3166
3205
* _realloc = _heap -> custom_heap ._realloc ;
3206
+ if (_gc != NULL ) {
3207
+ * _gc = _heap -> custom_heap ._gc ;
3208
+ }
3209
+ if (_shutdown != NULL ) {
3210
+ * _shutdown = _heap -> custom_heap ._shutdown ;
3211
+ }
3167
3212
} else {
3168
3213
* _malloc = NULL ;
3169
3214
* _free = NULL ;
3170
3215
* _realloc = NULL ;
3216
+ if (_gc != NULL ) {
3217
+ * _gc = NULL ;
3218
+ }
3219
+ if (_shutdown != NULL ) {
3220
+ * _shutdown = NULL ;
3221
+ }
3171
3222
}
3172
3223
#else
3173
3224
* _malloc = NULL ;
3174
3225
* _free = NULL ;
3175
3226
* _realloc = NULL ;
3227
+ * _gc = NULL ;
3228
+ * _shutdown = NULL ;
3176
3229
#endif
3177
3230
}
3178
3231
0 commit comments