[compiler-rt] 82e5994 - [hwasan] Do not memset allocation if it comes from the secondary allocator

Leonard Chan via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 14:50:01 PDT 2023


Author: Leonard Chan
Date: 2023-04-26T21:49:42Z
New Revision: 82e5994c8d72734be813db7ea56af7325b9c9f68

URL: https://github.com/llvm/llvm-project/commit/82e5994c8d72734be813db7ea56af7325b9c9f68
DIFF: https://github.com/llvm/llvm-project/commit/82e5994c8d72734be813db7ea56af7325b9c9f68.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_allocator.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index d3cb5c845725..3bb7594cf731 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -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);


        


More information about the llvm-commits mailing list