[hwasan] Do not memset allocation if it comes from the secondary allocator

The secondary allocator calls mmap which should return zero-inited pages, so we
don't need to explicitly memset it with zeros. This is similar to what asan's
calloc does.

Differential Revision: https://reviews.llvm.org/D149285
This commit is contained in:
Leonard Chan
2023-04-26 21:48:37 +00:00
parent d94fe97280
commit 82e5994c8d

View File

@@ -213,7 +213,10 @@ static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment,
ReportOutOfMemory(size, stack);
}
if (zeroise) {
internal_memset(allocated, 0, size);
// The secondary allocator mmaps memory, which should be zero-inited so we
// don't need to explicitly clear it.
if (allocator.FromPrimary(allocated))
internal_memset(allocated, 0, size);
} else if (flags()->max_malloc_fill_size > 0) {
uptr fill_size = Min(size, (uptr)flags()->max_malloc_fill_size);
internal_memset(allocated, flags()->malloc_fill_byte, fill_size);