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