@@ -368,12 +368,18 @@ unsafe extern "C" fn alloc_profiling_malloc(len: size_t) -> *mut c_void {
368
368
ptr
369
369
}
370
370
371
+ /// Safety: this function pointer is only allowed to point to `allocation_profiling_prev_alloc()`
372
+ /// when at the same time the `ZEND_MM_STATE.prev_custom_mm_alloc` is initialised to a valid
373
+ /// function pointer, otherwise there will be dragons.
371
374
static mut ALLOCATION_PROFILING_ALLOC : unsafe fn ( size_t ) -> * mut c_void =
372
375
allocation_profiling_orig_alloc;
373
376
374
377
unsafe fn allocation_profiling_prev_alloc ( len : size_t ) -> * mut c_void {
375
378
ZEND_MM_STATE . with ( |cell| {
376
379
let zend_mm_state = cell. get ( ) ;
380
+ // Safety: `ALLOCATION_PROFILING_ALLOC` will be initialised in
381
+ // `allocation_profiling_rinit()` and only point to this function when
382
+ // `prev_custom_mm_alloc` is also initialised
377
383
let prev = ( * zend_mm_state) . prev_custom_mm_alloc . unwrap ( ) ;
378
384
prev ( len)
379
385
} )
@@ -395,11 +401,17 @@ unsafe extern "C" fn alloc_profiling_free(ptr: *mut c_void) {
395
401
ALLOCATION_PROFILING_FREE ( ptr) ;
396
402
}
397
403
404
+ /// Safety: this function pointer is only allowed to point to `allocation_profiling_prev_free()`
405
+ /// when at the same time the `ZEND_MM_STATE.prev_custom_mm_free` is initialised to a valid
406
+ /// function pointer, otherwise there will be dragons.
398
407
static mut ALLOCATION_PROFILING_FREE : unsafe fn ( * mut c_void ) = allocation_profiling_orig_free;
399
408
400
409
unsafe fn allocation_profiling_prev_free ( ptr : * mut c_void ) {
401
410
ZEND_MM_STATE . with ( |cell| {
402
411
let zend_mm_state = cell. get ( ) ;
412
+ // Safety: `ALLOCATION_PROFILING_FREE` will be initialised in
413
+ // `allocation_profiling_free()` and only point to this function when
414
+ // `prev_custom_mm_free` is also initialised
403
415
let prev = ( * zend_mm_state) . prev_custom_mm_free . unwrap ( ) ;
404
416
prev ( ptr)
405
417
} )
@@ -430,12 +442,18 @@ unsafe extern "C" fn alloc_profiling_realloc(prev_ptr: *mut c_void, len: size_t)
430
442
ptr
431
443
}
432
444
445
+ /// Safety: this function pointer is only allowed to point to `allocation_profiling_prev_realloc()`
446
+ /// when at the same time the `ZEND_MM_STATE.prev_custom_mm_realloc` is initialised to a valid
447
+ /// function pointer, otherwise there will be dragons.
433
448
static mut ALLOCATION_PROFILING_REALLOC : unsafe fn ( * mut c_void , size_t ) -> * mut c_void =
434
449
allocation_profiling_orig_realloc;
435
450
436
451
unsafe fn allocation_profiling_prev_realloc ( prev_ptr : * mut c_void , len : size_t ) -> * mut c_void {
437
452
ZEND_MM_STATE . with ( |cell| {
438
453
let zend_mm_state = cell. get ( ) ;
454
+ // Safety: `ALLOCATION_PROFILING_REALLOC` will be initialised in
455
+ // `allocation_profiling_realloc()` and only point to this function when
456
+ // `prev_custom_mm_realloc` is also initialised
439
457
let prev = ( * zend_mm_state) . prev_custom_mm_realloc . unwrap ( ) ;
440
458
prev ( prev_ptr, len)
441
459
} )
0 commit comments