mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-01-15 17:48:00 +08:00
fix asan with MI_GUARDED
This commit is contained in:
parent
d57cb0765d
commit
b8dc09e3d2
@ -123,6 +123,9 @@ static mi_decl_noinline void* mi_heap_malloc_zero_aligned_at_overalloc(mi_heap_t
|
|||||||
|
|
||||||
if (p != aligned_p) {
|
if (p != aligned_p) {
|
||||||
mi_track_align(p,aligned_p,adjust,mi_usable_size(aligned_p));
|
mi_track_align(p,aligned_p,adjust,mi_usable_size(aligned_p));
|
||||||
|
#if MI_GUARDED
|
||||||
|
mi_track_mem_defined(p, sizeof(mi_block_t));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return aligned_p;
|
return aligned_p;
|
||||||
}
|
}
|
||||||
|
@ -640,8 +640,9 @@ static void* mi_block_ptr_set_guarded(mi_block_t* block, size_t obj_size) {
|
|||||||
// give up to place it right in front of the guard page if the offset is too large for unalignment
|
// give up to place it right in front of the guard page if the offset is too large for unalignment
|
||||||
offset = MI_BLOCK_ALIGNMENT_MAX;
|
offset = MI_BLOCK_ALIGNMENT_MAX;
|
||||||
}
|
}
|
||||||
void* p = (uint8_t*)block + offset;
|
void* p = (uint8_t*)block + offset;
|
||||||
mi_track_align(block, p, offset, obj_size);
|
mi_track_align(block, p, offset, obj_size);
|
||||||
|
mi_track_mem_defined(block, sizeof(mi_block_t));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,7 +662,7 @@ mi_decl_restrict void* _mi_heap_malloc_guarded(mi_heap_t* heap, size_t size, boo
|
|||||||
void* const p = mi_block_ptr_set_guarded(block, obj_size);
|
void* const p = mi_block_ptr_set_guarded(block, obj_size);
|
||||||
|
|
||||||
// stats
|
// stats
|
||||||
mi_track_malloc(p, size, zero);
|
mi_track_malloc(p, size, zero);
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
if (!mi_heap_is_initialized(heap)) { heap = mi_prim_get_default_heap(); }
|
if (!mi_heap_is_initialized(heap)) { heap = mi_prim_get_default_heap(); }
|
||||||
#if MI_STAT>1
|
#if MI_STAT>1
|
||||||
|
2
src/os.c
2
src/os.c
@ -273,7 +273,9 @@ static void* mi_os_prim_alloc_aligned(size_t size, size_t alignment, bool commit
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// if not aligned, free it, overallocate, and unmap around it
|
// if not aligned, free it, overallocate, and unmap around it
|
||||||
|
#if !MI_TRACK_ASAN
|
||||||
_mi_warning_message("unable to allocate aligned OS memory directly, fall back to over-allocation (size: 0x%zx bytes, address: %p, alignment: 0x%zx, commit: %d)\n", size, p, alignment, commit);
|
_mi_warning_message("unable to allocate aligned OS memory directly, fall back to over-allocation (size: 0x%zx bytes, address: %p, alignment: 0x%zx, commit: %d)\n", size, p, alignment, commit);
|
||||||
|
#endif
|
||||||
mi_os_prim_free(p, size, commit, stats);
|
mi_os_prim_free(p, size, commit, stats);
|
||||||
if (size >= (SIZE_MAX - alignment)) return NULL; // overflow
|
if (size >= (SIZE_MAX - alignment)) return NULL; // overflow
|
||||||
const size_t over_size = size + alignment;
|
const size_t over_size = size + alignment;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user