mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Add block size support for tracked_malloc (#11856)
This does still deviate from USE_ZEND_ALLOC=0 in that we're not rounding up the size of the allocation to fixed sizes. Doing so would suppress some out-of-bounds errors checked by ASAN. Rounding up the size in _zend_mm_block_size would not be good either as it would break code like memset(ptr, 0 _zend_mm_block_size(ptr)).
This commit is contained in:
@@ -2401,6 +2401,18 @@ void* ZEND_FASTCALL _zend_mm_realloc2(zend_mm_heap *heap, void *ptr, size_t size
|
||||
|
||||
ZEND_API size_t ZEND_FASTCALL _zend_mm_block_size(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
|
||||
{
|
||||
#if ZEND_MM_CUSTOM
|
||||
if (UNEXPECTED(heap->use_custom_heap)) {
|
||||
if (heap->custom_heap.std._malloc == tracked_malloc) {
|
||||
zend_ulong h = ((uintptr_t) ptr) >> ZEND_MM_ALIGNMENT_LOG2;
|
||||
zval *size_zv = zend_hash_index_find(heap->tracked_allocs, h);
|
||||
if (size_zv) {
|
||||
return Z_LVAL_P(size_zv);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return zend_mm_size(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
|
||||
}
|
||||
|
||||
@@ -2636,12 +2648,7 @@ ZEND_API void* ZEND_FASTCALL _erealloc2(void *ptr, size_t size, size_t copy_size
|
||||
|
||||
ZEND_API size_t ZEND_FASTCALL _zend_mem_block_size(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
|
||||
{
|
||||
#if ZEND_MM_CUSTOM
|
||||
if (UNEXPECTED(AG(mm_heap)->use_custom_heap)) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return zend_mm_size(AG(mm_heap), ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
|
||||
return _zend_mm_block_size(AG(mm_heap), ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
|
||||
}
|
||||
|
||||
ZEND_API void* ZEND_FASTCALL _safe_emalloc(size_t nmemb, size_t size, size_t offset ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
|
||||
|
||||
Reference in New Issue
Block a user