58
58
#include "zend_multiply.h"
59
59
#include "zend_bitset.h"
60
60
#include "zend_mmap.h"
61
+ #include "zend_portability.h"
61
62
#include <signal.h>
62
63
63
64
#ifdef HAVE_UNISTD_H
@@ -273,11 +274,15 @@ struct _zend_mm_heap {
273
274
void * (* _malloc )(size_t );
274
275
void (* _free )(void * );
275
276
void * (* _realloc )(void * , size_t );
277
+ size_t (* _gc )(void );
278
+ void (* _shutdown )(bool full , bool silent );
276
279
} std ;
277
280
struct {
278
281
void * (* _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
279
282
void (* _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
280
283
void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
284
+ size_t (* _gc )(void ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
285
+ void (* _shutdown )(bool full , bool silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC );
281
286
} debug ;
282
287
} custom_heap ;
283
288
HashTable * tracked_allocs ;
@@ -1968,6 +1973,10 @@ ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
1968
1973
1969
1974
#if ZEND_MM_CUSTOM
1970
1975
if (heap -> use_custom_heap ) {
1976
+ size_t (* gc )(void ) = heap -> custom_heap .std ._gc ;
1977
+ if (gc ) {
1978
+ return gc ();
1979
+ }
1971
1980
return 0 ;
1972
1981
}
1973
1982
#endif
@@ -2265,7 +2274,7 @@ static void *tracked_malloc(size_t size);
2265
2274
static void tracked_free_all (void );
2266
2275
#endif
2267
2276
2268
- void zend_mm_shutdown (zend_mm_heap * heap , bool full , bool silent )
2277
+ ZEND_API void zend_mm_shutdown (zend_mm_heap * heap , bool full , bool silent )
2269
2278
{
2270
2279
zend_mm_chunk * p ;
2271
2280
zend_mm_huge_list * list ;
@@ -2293,6 +2302,10 @@ void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
2293
2302
heap -> custom_heap .std ._free (heap );
2294
2303
}
2295
2304
}
2305
+ void (* shutdown )(bool , bool ) = heap -> custom_heap .std ._shutdown ;
2306
+ if (shutdown ) {
2307
+ shutdown (full , silent );
2308
+ }
2296
2309
return ;
2297
2310
}
2298
2311
#endif
@@ -2980,6 +2993,16 @@ ZEND_API zend_mm_heap *zend_mm_get_heap(void)
2980
2993
return AG (mm_heap );
2981
2994
}
2982
2995
2996
+ ZEND_API zend_mm_heap * zend_mm_heap_create (void )
2997
+ {
2998
+ return zend_mm_init ();
2999
+ }
3000
+
3001
+ ZEND_API void zend_mm_heap_free (zend_mm_heap * heap )
3002
+ {
3003
+ zend_mm_chunk_free (heap , heap -> main_chunk , ZEND_MM_CHUNK_SIZE );
3004
+ }
3005
+
2983
3006
ZEND_API bool zend_mm_is_custom_heap (zend_mm_heap * new_heap )
2984
3007
{
2985
3008
#if ZEND_MM_CUSTOM
@@ -2990,9 +3013,11 @@ ZEND_API bool zend_mm_is_custom_heap(zend_mm_heap *new_heap)
2990
3013
}
2991
3014
2992
3015
ZEND_API void zend_mm_set_custom_handlers (zend_mm_heap * heap ,
2993
- void * (* _malloc )(size_t ),
2994
- void (* _free )(void * ),
2995
- void * (* _realloc )(void * , size_t ))
3016
+ void * (* _malloc )(size_t ),
3017
+ void (* _free )(void * ),
3018
+ void * (* _realloc )(void * , size_t ),
3019
+ size_t (* _gc )(void ),
3020
+ void (* _shutdown )(bool , bool ))
2996
3021
{
2997
3022
#if ZEND_MM_CUSTOM
2998
3023
zend_mm_heap * _heap = (zend_mm_heap * )heap ;
@@ -3004,14 +3029,18 @@ ZEND_API void zend_mm_set_custom_handlers(zend_mm_heap *heap,
3004
3029
_heap -> custom_heap .std ._malloc = _malloc ;
3005
3030
_heap -> custom_heap .std ._free = _free ;
3006
3031
_heap -> custom_heap .std ._realloc = _realloc ;
3032
+ _heap -> custom_heap .std ._gc = _gc ;
3033
+ _heap -> custom_heap .std ._shutdown = _shutdown ;
3007
3034
}
3008
3035
#endif
3009
3036
}
3010
3037
3011
3038
ZEND_API void zend_mm_get_custom_handlers (zend_mm_heap * heap ,
3012
- void * (* * _malloc )(size_t ),
3013
- void (* * _free )(void * ),
3014
- void * (* * _realloc )(void * , size_t ))
3039
+ void * (* * _malloc )(size_t ),
3040
+ void (* * _free )(void * ),
3041
+ void * (* * _realloc )(void * , size_t ),
3042
+ size_t (* * _gc )(void ),
3043
+ void (* * _shutdown )(bool , bool ))
3015
3044
{
3016
3045
#if ZEND_MM_CUSTOM
3017
3046
zend_mm_heap * _heap = (zend_mm_heap * )heap ;
@@ -3020,15 +3049,21 @@ ZEND_API void zend_mm_get_custom_handlers(zend_mm_heap *heap,
3020
3049
* _malloc = _heap -> custom_heap .std ._malloc ;
3021
3050
* _free = _heap -> custom_heap .std ._free ;
3022
3051
* _realloc = _heap -> custom_heap .std ._realloc ;
3052
+ * _gc = _heap -> custom_heap .std ._gc ;
3053
+ * _shutdown = _heap -> custom_heap .std ._shutdown ;
3023
3054
} else {
3024
3055
* _malloc = NULL ;
3025
3056
* _free = NULL ;
3026
3057
* _realloc = NULL ;
3058
+ * _gc = NULL ;
3059
+ * _shutdown = NULL ;
3027
3060
}
3028
3061
#else
3029
3062
* _malloc = NULL ;
3030
3063
* _free = NULL ;
3031
3064
* _realloc = NULL ;
3065
+ * _gc = NULL ;
3066
+ * _shutdown = NULL ;
3032
3067
#endif
3033
3068
}
3034
3069
0 commit comments