Skip to content

Commit 4e8b1eb

Browse files
remove tls prepare access
1 parent cd32fc9 commit 4e8b1eb

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

profiling/src/allocation/allocation_ge84.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ use std::sync::atomic::Ordering::Relaxed;
1010
#[cfg(feature = "debug_stats")]
1111
use 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)]
1714
struct 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
342330
unsafe 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-
348334
unsafe 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);
@@ -454,10 +440,9 @@ unsafe fn alloc_prof_prev_gc() -> size_t {
454440

455441
unsafe fn alloc_prof_orig_gc() -> size_t {
456442
let heap = tls_zend_mm_state_get!(heap).unwrap();
457-
let (prepare, restore) = tls_zend_mm_state_get!(prepare_restore_zend_heap);
458-
let custom_heap = prepare(heap);
443+
let custom_heap = prepare_zend_heap(heap);
459444
let size = zend::zend_mm_gc(heap);
460-
restore(heap, custom_heap);
445+
restore_zend_heap(heap, custom_heap);
461446
size
462447
}
463448

@@ -475,10 +460,9 @@ unsafe fn alloc_prof_prev_shutdown(full: bool, silent: bool) {
475460

476461
unsafe fn alloc_prof_orig_shutdown(full: bool, silent: bool) {
477462
let heap = tls_zend_mm_state_get!(heap).unwrap_unchecked();
478-
let (prepare, restore) = tls_zend_mm_state_get!(prepare_restore_zend_heap);
479-
let custom_heap = prepare(heap);
463+
let custom_heap = prepare_zend_heap(heap);
480464
zend::zend_mm_shutdown(heap, full, silent);
481-
restore(heap, custom_heap);
465+
restore_zend_heap(heap, custom_heap);
482466
}
483467

484468
/// safe wrapper for `zend::is_zend_mm()`.

0 commit comments

Comments
 (0)