Skip to content

Commit 86c67e3

Browse files
remove tls prepare access
1 parent 176f194 commit 86c67e3

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
@@ -67,7 +63,6 @@ impl ZendMMState {
6763
prev_custom_mm_free: None,
6864
prev_custom_mm_gc: None,
6965
prev_custom_mm_shutdown: None,
70-
prepare_restore_zend_heap: (prepare_zend_heap, restore_zend_heap),
7166
alloc: super::alloc_prof_panic_alloc,
7267
realloc: super::alloc_prof_panic_realloc,
7368
free: super::alloc_prof_panic_free,
@@ -185,15 +180,12 @@ pub fn alloc_prof_rinit() {
185180
zend_mm_state.realloc = alloc_prof_prev_realloc;
186181
zend_mm_state.gc = alloc_prof_prev_gc;
187182
zend_mm_state.shutdown = alloc_prof_prev_shutdown;
188-
zend_mm_state.prepare_restore_zend_heap =
189-
(prepare_zend_heap_none, restore_zend_heap_none);
190183
} else {
191184
zend_mm_state.alloc = alloc_prof_orig_alloc;
192185
zend_mm_state.free = alloc_prof_orig_free;
193186
zend_mm_state.realloc = alloc_prof_orig_realloc;
194187
zend_mm_state.gc = alloc_prof_orig_gc;
195188
zend_mm_state.shutdown = alloc_prof_orig_shutdown;
196-
zend_mm_state.prepare_restore_zend_heap = (prepare_zend_heap, restore_zend_heap);
197189

198190
// Reset previous handlers to None. There might be a chaotic neighbor that
199191
// registered custom handlers in an earlier request, but it doesn't do so for this
@@ -326,17 +318,11 @@ unsafe fn prepare_zend_heap(heap: *mut zend::_zend_mm_heap) -> c_int {
326318
custom_heap
327319
}
328320

329-
fn prepare_zend_heap_none(_heap: *mut zend::_zend_mm_heap) -> c_int {
330-
0
331-
}
332-
333321
/// Restore the ZendMM heap's `use_custom_heap` flag, see `prepare_zend_heap` for details
334322
unsafe fn restore_zend_heap(heap: *mut zend::_zend_mm_heap, custom_heap: c_int) {
335323
ptr::write(heap as *mut c_int, custom_heap);
336324
}
337325

338-
fn restore_zend_heap_none(_heap: *mut zend::_zend_mm_heap, _custom_heap: c_int) {}
339-
340326
unsafe extern "C" fn alloc_prof_malloc(len: size_t) -> *mut c_void {
341327
#[cfg(feature = "debug_stats")]
342328
ALLOCATION_PROFILING_COUNT.fetch_add(1, Relaxed);
@@ -446,10 +432,9 @@ unsafe fn alloc_prof_prev_gc() -> size_t {
446432

447433
unsafe fn alloc_prof_orig_gc() -> size_t {
448434
let heap = tls_zend_mm_state_get!(heap).unwrap();
449-
let (prepare, restore) = tls_zend_mm_state_get!(prepare_restore_zend_heap);
450-
let custom_heap = prepare(heap);
435+
let custom_heap = prepare_zend_heap(heap);
451436
let size = zend::zend_mm_gc(heap);
452-
restore(heap, custom_heap);
437+
restore_zend_heap(heap, custom_heap);
453438
size
454439
}
455440

@@ -467,10 +452,9 @@ unsafe fn alloc_prof_prev_shutdown(full: bool, silent: bool) {
467452

468453
unsafe fn alloc_prof_orig_shutdown(full: bool, silent: bool) {
469454
let heap = tls_zend_mm_state_get!(heap).unwrap_unchecked();
470-
let (prepare, restore) = tls_zend_mm_state_get!(prepare_restore_zend_heap);
471-
let custom_heap = prepare(heap);
455+
let custom_heap = prepare_zend_heap(heap);
472456
zend::zend_mm_shutdown(heap, full, silent);
473-
restore(heap, custom_heap);
457+
restore_zend_heap(heap, custom_heap);
474458
}
475459

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

0 commit comments

Comments
 (0)