[PATCH] D39473: [sanitizers] Add init function to set alignment of low level allocator
Walter Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 20 17:01:46 PST 2017
This revision was automatically updated to reflect the committed changes.
waltl marked an inline comment as done.
Closed by commit rL318717: [sanitizers] Add init function to set alignment of low level allocator (authored by waltl).
Changed prior to commit:
https://reviews.llvm.org/D39473?vs=123633&id=123693#toc
Repository:
rL LLVM
https://reviews.llvm.org/D39473
Files:
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
Index: compiler-rt/trunk/lib/asan/asan_rtl.cc
===================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc
@@ -407,6 +407,7 @@
MaybeReexec();
// Setup internal allocator callback.
+ SetLowLevelAllocateMinAlignment(SHADOW_GRANULARITY);
SetLowLevelAllocateCallback(OnLowLevelAllocate);
InitializeAsanInterceptors();
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc
@@ -178,11 +178,13 @@
}
// LowLevelAllocator
+constexpr uptr kLowLevelAllocatorDefaultAlignment = 8;
+static uptr low_level_alloc_min_alignment = kLowLevelAllocatorDefaultAlignment;
static LowLevelAllocateCallback low_level_alloc_callback;
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_ =
@@ -199,6 +201,11 @@
return res;
}
+void SetLowLevelAllocateMinAlignment(uptr alignment) {
+ CHECK(IsPowerOfTwo(alignment));
+ low_level_alloc_min_alignment = Max(alignment, low_level_alloc_min_alignment);
+}
+
void SetLowLevelAllocateCallback(LowLevelAllocateCallback callback) {
low_level_alloc_callback = callback;
}
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
@@ -206,6 +206,8 @@
char *allocated_end_;
char *allocated_current_;
};
+// Set the min alignment of LowLevelAllocator to at least alignment.
+void SetLowLevelAllocateMinAlignment(uptr alignment);
typedef void (*LowLevelAllocateCallback)(uptr ptr, uptr size);
// Allows to register tool-specific callbacks for LowLevelAllocator.
// Passing NULL removes the callback.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39473.123693.patch
Type: text/x-patch
Size: 2217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171121/b36aca85/attachment.bin>
More information about the llvm-commits
mailing list