@@ -366,9 +366,6 @@ static ZEND_FUNCTION(zend_test_crash)
366
366
php_printf ("%s" , invalid );
367
367
}
368
368
369
- zend_mm_heap * zend_test_heap ;
370
- zend_mm_heap * zend_orig_heap ;
371
-
372
369
static bool has_opline (zend_execute_data * execute_data )
373
370
{
374
371
return execute_data
@@ -383,44 +380,50 @@ void * zend_test_custom_malloc(size_t len)
383
380
if (has_opline (EG (current_execute_data ))) {
384
381
assert (EG (current_execute_data )-> opline -> lineno != (uint32_t )-1 );
385
382
}
386
- return _zend_mm_alloc (zend_orig_heap , len );
383
+ return _zend_mm_alloc (ZT_G ( zend_orig_heap ) , len ZEND_FILE_LINE_EMPTY_CC ZEND_FILE_LINE_EMPTY_CC );
387
384
}
388
385
389
386
void zend_test_custom_free (void * ptr )
390
387
{
391
388
if (has_opline (EG (current_execute_data ))) {
392
389
assert (EG (current_execute_data )-> opline -> lineno != (uint32_t )-1 );
393
390
}
394
- _zend_mm_free (zend_orig_heap , ptr );
391
+ _zend_mm_free (ZT_G ( zend_orig_heap ) , ptr ZEND_FILE_LINE_EMPTY_CC ZEND_FILE_LINE_EMPTY_CC );
395
392
}
396
393
397
394
void * zend_test_custom_realloc (void * ptr , size_t len )
398
395
{
399
396
if (has_opline (EG (current_execute_data ))) {
400
397
assert (EG (current_execute_data )-> opline -> lineno != (uint32_t )-1 );
401
398
}
402
- return _zend_mm_realloc (zend_orig_heap , ptr , len );
399
+ return _zend_mm_realloc (ZT_G ( zend_orig_heap ) , ptr , len ZEND_FILE_LINE_EMPTY_CC ZEND_FILE_LINE_EMPTY_CC );
403
400
}
404
401
405
- static ZEND_FUNCTION ( zend_test_observe_opline_in_zendmm )
402
+ static PHP_INI_MH ( OnUpdateZendTestObserveOplineInZendMM )
406
403
{
407
- zend_test_heap = malloc (4096 );
408
- memset (zend_test_heap , 0 , 4096 );
409
- zend_mm_set_custom_handlers (
410
- zend_test_heap ,
411
- zend_test_custom_malloc ,
412
- zend_test_custom_free ,
413
- zend_test_custom_realloc
414
- );
415
- zend_orig_heap = zend_mm_get_heap ();
416
- zend_mm_set_heap (zend_test_heap );
417
- }
404
+ if (new_value == NULL ) {
405
+ return FAILURE ;
406
+ }
418
407
419
- static ZEND_FUNCTION (zend_test_unobserve_opline_in_zendmm )
420
- {
421
- free (zend_test_heap );
422
- zend_test_heap = NULL ;
423
- zend_mm_set_heap (zend_orig_heap );
408
+ int int_value = zend_ini_parse_bool (new_value );
409
+
410
+ if (int_value == 1 ) {
411
+ ZT_G (zend_test_heap ) = malloc (4096 );
412
+ memset (ZT_G (zend_test_heap ), 0 , 4096 );
413
+ zend_mm_set_custom_handlers (
414
+ ZT_G (zend_test_heap ),
415
+ zend_test_custom_malloc ,
416
+ zend_test_custom_free ,
417
+ zend_test_custom_realloc
418
+ );
419
+ ZT_G (zend_orig_heap ) = zend_mm_get_heap ();
420
+ zend_mm_set_heap (ZT_G (zend_test_heap ));
421
+ } else if (ZT_G (zend_test_heap )) {
422
+ free (ZT_G (zend_test_heap ));
423
+ ZT_G (zend_test_heap ) = NULL ;
424
+ zend_mm_set_heap (ZT_G (zend_orig_heap ));
425
+ }
426
+ return OnUpdateBool (entry , new_value , mh_arg1 , mh_arg2 , mh_arg3 , stage );
424
427
}
425
428
426
429
static ZEND_FUNCTION (zend_test_is_pcre_bundled )
@@ -617,6 +620,7 @@ static ZEND_METHOD(ZendTestChildClassWithMethodWithParameterAttribute, override)
617
620
PHP_INI_BEGIN ()
618
621
STD_PHP_INI_BOOLEAN ("zend_test.replace_zend_execute_ex" , "0" , PHP_INI_SYSTEM , OnUpdateBool , replace_zend_execute_ex , zend_zend_test_globals , zend_test_globals )
619
622
STD_PHP_INI_BOOLEAN ("zend_test.register_passes" , "0" , PHP_INI_SYSTEM , OnUpdateBool , register_passes , zend_zend_test_globals , zend_test_globals )
623
+ STD_PHP_INI_BOOLEAN ("zend_test.observe_opline_in_zendmm" , "0" , PHP_INI_ALL , OnUpdateZendTestObserveOplineInZendMM , observe_opline_in_zendmm , zend_zend_test_globals , zend_test_globals )
620
624
PHP_INI_END ()
621
625
622
626
void (* old_zend_execute_ex )(zend_execute_data * execute_data );
@@ -759,6 +763,13 @@ PHP_RSHUTDOWN_FUNCTION(zend_test)
759
763
zend_weakrefs_hash_del (& ZT_G (global_weakmap ), (zend_object * )(uintptr_t )objptr );
760
764
} ZEND_HASH_FOREACH_END ();
761
765
zend_hash_destroy (& ZT_G (global_weakmap ));
766
+
767
+ if (ZT_G (zend_test_heap )) {
768
+ free (ZT_G (zend_test_heap ));
769
+ ZT_G (zend_test_heap ) = NULL ;
770
+ zend_mm_set_heap (ZT_G (zend_orig_heap ));
771
+ }
772
+
762
773
return SUCCESS ;
763
774
}
764
775
0 commit comments