@@ -10,9 +10,6 @@ use std::sync::atomic::Ordering::Relaxed;
1010#[ cfg( feature = "debug_stats" ) ]
1111use crate :: allocation:: { ALLOCATION_PROFILING_COUNT , ALLOCATION_PROFILING_SIZE } ;
1212
13- type ZendHeapPrepareFn = unsafe fn ( heap : * mut zend:: _zend_mm_heap ) -> c_int ;
14- type ZendHeapRestoreFn = unsafe fn ( heap : * mut zend:: _zend_mm_heap , custom_heap : c_int ) ;
15-
1613#[ derive( Copy , Clone ) ]
1714struct ZendMMState {
1815 /// The heap installed in ZendMM at the time we install our custom
@@ -30,7 +27,6 @@ struct ZendMMState {
3027 prev_custom_mm_gc : Option < zend:: VmMmCustomGcFn > ,
3128 /// The engine's previous custom shutdown function, if there is one.
3229 prev_custom_mm_shutdown : Option < zend:: VmMmCustomShutdownFn > ,
33- prepare_restore_zend_heap : ( ZendHeapPrepareFn , ZendHeapRestoreFn ) ,
3430 /// Safety: this function pointer is only allowed to point to
3531 /// `alloc_prof_prev_alloc()` when at the same time the
3632 /// `ZEND_MM_STATE.prev_custom_mm_alloc` is initialised to a valid function
@@ -75,7 +71,6 @@ impl ZendMMState {
7571 prev_custom_mm_free : None ,
7672 prev_custom_mm_gc : None ,
7773 prev_custom_mm_shutdown : None ,
78- prepare_restore_zend_heap : ( prepare_zend_heap, restore_zend_heap) ,
7974 alloc : super :: alloc_prof_panic_alloc,
8075 realloc : super :: alloc_prof_panic_realloc,
8176 free : super :: alloc_prof_panic_free,
@@ -193,15 +188,12 @@ pub fn alloc_prof_rinit() {
193188 zend_mm_state. realloc = alloc_prof_prev_realloc;
194189 zend_mm_state. gc = alloc_prof_prev_gc;
195190 zend_mm_state. shutdown = alloc_prof_prev_shutdown;
196- zend_mm_state. prepare_restore_zend_heap =
197- ( prepare_zend_heap_none, restore_zend_heap_none) ;
198191 } else {
199192 zend_mm_state. alloc = alloc_prof_orig_alloc;
200193 zend_mm_state. free = alloc_prof_orig_free;
201194 zend_mm_state. realloc = alloc_prof_orig_realloc;
202195 zend_mm_state. gc = alloc_prof_orig_gc;
203196 zend_mm_state. shutdown = alloc_prof_orig_shutdown;
204- zend_mm_state. prepare_restore_zend_heap = ( prepare_zend_heap, restore_zend_heap) ;
205197
206198 // Reset previous handlers to None. There might be a chaotic neighbor that
207199 // registered custom handlers in an earlier request, but it doesn't do so for this
@@ -334,17 +326,11 @@ unsafe fn prepare_zend_heap(heap: *mut zend::_zend_mm_heap) -> c_int {
334326 custom_heap
335327}
336328
337- fn prepare_zend_heap_none ( _heap : * mut zend:: _zend_mm_heap ) -> c_int {
338- 0
339- }
340-
341329/// Restore the ZendMM heap's `use_custom_heap` flag, see `prepare_zend_heap` for details
342330unsafe fn restore_zend_heap ( heap : * mut zend:: _zend_mm_heap , custom_heap : c_int ) {
343331 ptr:: write ( heap as * mut c_int , custom_heap) ;
344332}
345333
346- fn restore_zend_heap_none ( _heap : * mut zend:: _zend_mm_heap , _custom_heap : c_int ) { }
347-
348334unsafe extern "C" fn alloc_prof_malloc ( len : size_t ) -> * mut c_void {
349335 #[ cfg( feature = "debug_stats" ) ]
350336 ALLOCATION_PROFILING_COUNT . fetch_add ( 1 , Relaxed ) ;
@@ -450,10 +436,9 @@ unsafe fn alloc_prof_prev_gc() -> size_t {
450436
451437unsafe fn alloc_prof_orig_gc ( ) -> size_t {
452438 let heap = tls_zend_mm_state_get ! ( heap) . unwrap ( ) ;
453- let ( prepare, restore) = tls_zend_mm_state_get ! ( prepare_restore_zend_heap) ;
454- let custom_heap = prepare ( heap) ;
439+ let custom_heap = prepare_zend_heap ( heap) ;
455440 let size = zend:: zend_mm_gc ( heap) ;
456- restore ( heap, custom_heap) ;
441+ restore_zend_heap ( heap, custom_heap) ;
457442 size
458443}
459444
@@ -471,10 +456,9 @@ unsafe fn alloc_prof_prev_shutdown(full: bool, silent: bool) {
471456
472457unsafe fn alloc_prof_orig_shutdown ( full : bool , silent : bool ) {
473458 let heap = tls_zend_mm_state_get ! ( heap) . unwrap_unchecked ( ) ;
474- let ( prepare, restore) = tls_zend_mm_state_get ! ( prepare_restore_zend_heap) ;
475- let custom_heap = prepare ( heap) ;
459+ let custom_heap = prepare_zend_heap ( heap) ;
476460 zend:: zend_mm_shutdown ( heap, full, silent) ;
477- restore ( heap, custom_heap) ;
461+ restore_zend_heap ( heap, custom_heap) ;
478462}
479463
480464/// safe wrapper for `zend::is_zend_mm()`.
0 commit comments