[PATCH] D39473: [sanitizers] Increase alignment of low level allocator

Walter Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 07:06:41 PST 2017


waltl updated this revision to Diff 123586.
waltl added a comment.

Add SetLowLevelAllocateMinAlignment


https://reviews.llvm.org/D39473

Files:
  compiler-rt/lib/asan/asan_rtl.cc
  compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
  compiler-rt/lib/sanitizer_common/sanitizer_common.h


Index: compiler-rt/lib/sanitizer_common/sanitizer_common.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -209,6 +209,7 @@
 // Allows to register tool-specific callbacks for LowLevelAllocator.
 // Passing NULL removes the callback.
 void SetLowLevelAllocateCallback(LowLevelAllocateCallback callback);
+void SetLowLevelAllocateMinAlignment(uptr alignment);
 
 // IO
 void CatastrophicErrorWrite(const char *buffer, uptr length);
Index: compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
+++ compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc
@@ -179,10 +179,11 @@
 
 // LowLevelAllocator
 static LowLevelAllocateCallback low_level_alloc_callback;
+static uptr low_level_alloc_min_alignment = 8;
 
 void *LowLevelAllocator::Allocate(uptr size) {
   // Align allocation size.
-  size = RoundUpTo(size, 8);
+  size = RoundUpTo(size, low_level_alloc_min_alignment);
   if (allocated_end_ - allocated_current_ < (sptr)size) {
     uptr size_to_allocate = Max(size, GetPageSizeCached());
     allocated_current_ =
@@ -203,6 +204,12 @@
   low_level_alloc_callback = callback;
 }
 
+void SetLowLevelAllocateMinAlignment(uptr alignment) {
+  CHECK(IsPowerOfTwo(alignment));
+  if (low_level_alloc_min_alignment < alignment)
+    low_level_alloc_min_alignment = alignment;
+}
+
 static atomic_uint8_t allocator_out_of_memory = {0};
 static atomic_uint8_t allocator_may_return_null = {0};
 
Index: compiler-rt/lib/asan/asan_rtl.cc
===================================================================
--- compiler-rt/lib/asan/asan_rtl.cc
+++ compiler-rt/lib/asan/asan_rtl.cc
@@ -408,6 +408,7 @@
 
   // Setup internal allocator callback.
   SetLowLevelAllocateCallback(OnLowLevelAllocate);
+  SetLowLevelAllocateMinAlignment(SHADOW_GRANULARITY);
 
   InitializeAsanInterceptors();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39473.123586.patch
Type: text/x-patch
Size: 2044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171120/e1e179ee/attachment.bin>


More information about the llvm-commits mailing list