@@ -514,6 +514,71 @@ static void stderr_last_error(char *msg)
514
514
}
515
515
#endif
516
516
517
+ static void _zend_mm_set_custom_handlers_ex (zend_mm_heap * heap ,
518
+ void * (* _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
519
+ void (* _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
520
+ void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
521
+ size_t (* _gc )(void ),
522
+ void (* _shutdown )(bool , bool ))
523
+ {
524
+ #if ZEND_MM_CUSTOM
525
+ zend_mm_heap * _heap = (zend_mm_heap * )heap ;
526
+
527
+ if (!_malloc && !_free && !_realloc ) {
528
+ _heap -> use_custom_heap = ZEND_MM_CUSTOM_HEAP_NONE ;
529
+ } else {
530
+ _heap -> use_custom_heap = ZEND_MM_CUSTOM_HEAP_STD ;
531
+ _heap -> custom_heap ._malloc = _malloc ;
532
+ _heap -> custom_heap ._free = _free ;
533
+ _heap -> custom_heap ._realloc = _realloc ;
534
+ _heap -> custom_heap ._gc = _gc ;
535
+ _heap -> custom_heap ._shutdown = _shutdown ;
536
+ }
537
+ #endif
538
+ }
539
+
540
+
541
+ static void _zend_mm_get_custom_handlers_ex (zend_mm_heap * heap ,
542
+ void * (* * _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
543
+ void (* * _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
544
+ void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
545
+ size_t (* * _gc )(void ),
546
+ void (* * _shutdown )(bool , bool ))
547
+ {
548
+ #if ZEND_MM_CUSTOM
549
+ zend_mm_heap * _heap = (zend_mm_heap * )heap ;
550
+
551
+ if (heap -> use_custom_heap ) {
552
+ * _malloc = _heap -> custom_heap ._malloc ;
553
+ * _free = _heap -> custom_heap ._free ;
554
+ * _realloc = _heap -> custom_heap ._realloc ;
555
+ if (_gc != NULL ) {
556
+ * _gc = _heap -> custom_heap ._gc ;
557
+ }
558
+ if (_shutdown != NULL ) {
559
+ * _shutdown = _heap -> custom_heap ._shutdown ;
560
+ }
561
+ } else {
562
+ * _malloc = NULL ;
563
+ * _free = NULL ;
564
+ * _realloc = NULL ;
565
+ if (_gc != NULL ) {
566
+ * _gc = NULL ;
567
+ }
568
+ if (_shutdown != NULL ) {
569
+ * _shutdown = NULL ;
570
+ }
571
+ }
572
+ #else
573
+ * _malloc = NULL ;
574
+ * _free = NULL ;
575
+ * _realloc = NULL ;
576
+ * _gc = NULL ;
577
+ * _shutdown = NULL ;
578
+ #endif
579
+ }
580
+
581
+
517
582
/*****************/
518
583
/* OS Allocation */
519
584
/*****************/
@@ -3509,6 +3574,7 @@ static void* poison_realloc(void *ptr, size_t size ZEND_FILE_LINE_DC ZEND_FILE_L
3509
3574
oldsize -= sizeof (zend_mm_debug_info );
3510
3575
#endif
3511
3576
3577
+ ZEND_MM_UNPOISON (ptr , MIN (oldsize , size ));
3512
3578
memcpy (new , ptr , MIN (oldsize , size ));
3513
3579
poison_free (ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
3514
3580
}
@@ -3526,12 +3592,12 @@ static size_t poison_gc(void)
3526
3592
size_t (* _gc )(void );
3527
3593
void (* _shutdown )(bool , bool );
3528
3594
3529
- zend_mm_get_custom_handlers_ex (heap , & _malloc , & _free , & _realloc , & _gc , & _shutdown );
3530
- zend_mm_set_custom_handlers_ex (heap , NULL , NULL , NULL , NULL , NULL );
3595
+ _zend_mm_get_custom_handlers_ex (heap , & _malloc , & _free , & _realloc , & _gc , & _shutdown );
3596
+ _zend_mm_set_custom_handlers_ex (heap , NULL , NULL , NULL , NULL , NULL );
3531
3597
3532
3598
size_t collected = _zend_mm_gc (heap );
3533
3599
3534
- zend_mm_set_custom_handlers_ex (heap , _malloc , _free , _realloc , _gc , _shutdown );
3600
+ _zend_mm_set_custom_handlers_ex (heap , _malloc , _free , _realloc , _gc , _shutdown );
3535
3601
3536
3602
return collected ;
3537
3603
}
@@ -3546,17 +3612,18 @@ static void poison_shutdown(bool full, bool silent)
3546
3612
size_t (* _gc )(void );
3547
3613
void (* _shutdown )(bool , bool );
3548
3614
3549
- zend_mm_get_custom_handlers_ex (heap , & _malloc , & _free , & _realloc , & _gc , & _shutdown );
3550
- zend_mm_set_custom_handlers_ex (heap , NULL , NULL , NULL , NULL , NULL );
3615
+ _zend_mm_get_custom_handlers_ex (heap , & _malloc , & _free , & _realloc , & _gc , & _shutdown );
3616
+ _zend_mm_set_custom_handlers_ex (heap , NULL , NULL , NULL , NULL , NULL );
3551
3617
3552
3618
if (heap -> debug .check_freelists_on_shutdown ) {
3553
3619
zend_mm_check_freelists (heap );
3554
3620
}
3555
3621
3556
3622
zend_mm_shutdown (heap , full , silent );
3623
+ ZEND_MM_UNPOISON_HEAP (heap );
3557
3624
3558
3625
if (!full ) {
3559
- zend_mm_set_custom_handlers_ex (heap , _malloc , _free , _realloc , _gc , _shutdown );
3626
+ _zend_mm_set_custom_handlers_ex (heap , _malloc , _free , _realloc , _gc , _shutdown );
3560
3627
}
3561
3628
}
3562
3629
@@ -3637,7 +3704,7 @@ static void poison_enable(zend_mm_heap *heap, char *parameters)
3637
3704
tmp ++ ;
3638
3705
}
3639
3706
3640
- zend_mm_set_custom_handlers_ex (heap , poison_malloc , poison_free ,
3707
+ _zend_mm_set_custom_handlers_ex (heap , poison_malloc , poison_free ,
3641
3708
poison_realloc , poison_gc , poison_shutdown );
3642
3709
}
3643
3710
#endif
@@ -3737,95 +3804,51 @@ ZEND_API bool zend_mm_is_custom_heap(zend_mm_heap *new_heap)
3737
3804
#endif
3738
3805
}
3739
3806
3740
- ZEND_API void zend_mm_set_custom_handlers (zend_mm_heap * heap ,
3807
+ ZEND_API void zend_mm_set_custom_handlers_ex (zend_mm_heap * heap ,
3741
3808
void * (* _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3742
3809
void (* _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3743
- void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ))
3810
+ void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3811
+ size_t (* _gc )(void ),
3812
+ void (* _shutdown )(bool , bool ))
3744
3813
{
3745
- #if ZEND_MM_CUSTOM
3746
3814
ZEND_MM_UNPOISON_HEAP (heap );
3747
- zend_mm_set_custom_handlers_ex (heap , _malloc , _free , _realloc , NULL , NULL );
3748
- ZEND_MM_POISON_HEAP (heap );
3749
- #endif
3815
+ _zend_mm_set_custom_handlers_ex (heap , _malloc , _free , _realloc , _gc , _shutdown );
3816
+ ZEND_MM_UNPOISON_HEAP (heap );
3750
3817
}
3751
3818
3752
- ZEND_API void zend_mm_set_custom_handlers_ex (zend_mm_heap * heap ,
3819
+ ZEND_API void zend_mm_set_custom_handlers (zend_mm_heap * heap ,
3753
3820
void * (* _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3754
3821
void (* _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3755
- void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3756
- size_t (* _gc )(void ),
3757
- void (* _shutdown )(bool , bool ))
3822
+ void * (* _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ))
3758
3823
{
3759
3824
#if ZEND_MM_CUSTOM
3760
3825
ZEND_MM_UNPOISON_HEAP (heap );
3761
- zend_mm_heap * _heap = (zend_mm_heap * )heap ;
3762
-
3763
- if (!_malloc && !_free && !_realloc ) {
3764
- _heap -> use_custom_heap = ZEND_MM_CUSTOM_HEAP_NONE ;
3765
- } else {
3766
- _heap -> use_custom_heap = ZEND_MM_CUSTOM_HEAP_STD ;
3767
- _heap -> custom_heap ._malloc = _malloc ;
3768
- _heap -> custom_heap ._free = _free ;
3769
- _heap -> custom_heap ._realloc = _realloc ;
3770
- _heap -> custom_heap ._gc = _gc ;
3771
- _heap -> custom_heap ._shutdown = _shutdown ;
3772
- }
3826
+ _zend_mm_set_custom_handlers_ex (heap , _malloc , _free , _realloc , NULL , NULL );
3773
3827
ZEND_MM_POISON_HEAP (heap );
3774
3828
#endif
3775
3829
}
3776
3830
3777
- ZEND_API void zend_mm_get_custom_handlers (zend_mm_heap * heap ,
3831
+ ZEND_API void zend_mm_get_custom_handlers_ex (zend_mm_heap * heap ,
3778
3832
void * (* * _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3779
3833
void (* * _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3780
- void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ))
3834
+ void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3835
+ size_t (* * _gc )(void ),
3836
+ void (* * _shutdown )(bool , bool ))
3781
3837
{
3782
- #if ZEND_MM_CUSTOM
3783
3838
ZEND_MM_UNPOISON_HEAP (heap );
3784
- zend_mm_get_custom_handlers_ex (heap , _malloc , _free , _realloc , NULL , NULL );
3839
+ _zend_mm_get_custom_handlers_ex (heap , _malloc , _free , _realloc , _gc , _shutdown );
3785
3840
ZEND_MM_POISON_HEAP (heap );
3786
- #endif
3787
3841
}
3788
3842
3789
- ZEND_API void zend_mm_get_custom_handlers_ex (zend_mm_heap * heap ,
3843
+ ZEND_API void zend_mm_get_custom_handlers (zend_mm_heap * heap ,
3790
3844
void * (* * _malloc )(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3791
3845
void (* * _free )(void * ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3792
- void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ),
3793
- size_t (* * _gc )(void ),
3794
- void (* * _shutdown )(bool , bool ))
3846
+ void * (* * _realloc )(void * , size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ))
3795
3847
{
3796
3848
#if ZEND_MM_CUSTOM
3797
3849
ZEND_MM_UNPOISON_HEAP (heap );
3798
-
3799
- zend_mm_heap * _heap = (zend_mm_heap * )heap ;
3800
-
3801
- if (heap -> use_custom_heap ) {
3802
- * _malloc = _heap -> custom_heap ._malloc ;
3803
- * _free = _heap -> custom_heap ._free ;
3804
- * _realloc = _heap -> custom_heap ._realloc ;
3805
- if (_gc != NULL ) {
3806
- * _gc = _heap -> custom_heap ._gc ;
3807
- }
3808
- if (_shutdown != NULL ) {
3809
- * _shutdown = _heap -> custom_heap ._shutdown ;
3810
- }
3811
- } else {
3812
- * _malloc = NULL ;
3813
- * _free = NULL ;
3814
- * _realloc = NULL ;
3815
- if (_gc != NULL ) {
3816
- * _gc = NULL ;
3817
- }
3818
- if (_shutdown != NULL ) {
3819
- * _shutdown = NULL ;
3820
- }
3821
- }
3850
+ _zend_mm_get_custom_handlers_ex (heap , _malloc , _free , _realloc , NULL , NULL );
3822
3851
ZEND_MM_POISON_HEAP (heap );
3823
- #else
3824
- * _malloc = NULL ;
3825
- * _free = NULL ;
3826
- * _realloc = NULL ;
3827
- * _gc = NULL ;
3828
- * _shutdown = NULL ;
3829
3852
#endif
3830
3853
}
3831
3854
0 commit comments