summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-06-07 09:15:48 +0000
committerKostya Serebryany <kcc@google.com>2012-06-07 09:15:48 +0000
commit0334fc8564e91d5ebd495066bb263af36331fe61 (patch)
tree802a12c32337e7ba60ad22b17c0f13b7bb5242eb /lib
parent6e0c3a447307091ff5340c302f828ea9632709ca (diff)
downloadcompiler-rt-0334fc8564e91d5ebd495066bb263af36331fe61.tar.gz
[asan] slow 16-byte redzones (still experimental)
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158143 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/asan/asan_allocator.cc14
-rw-r--r--lib/asan/asan_rtl.cc4
2 files changed, 8 insertions, 10 deletions
diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cc
index 19f147f42..349bb5086 100644
--- a/lib/asan/asan_allocator.cc
+++ b/lib/asan/asan_allocator.cc
@@ -174,29 +174,27 @@ struct ChunkBase {
// Typically the beginning of the user-accessible memory is 'this'+REDZONE
// and is also aligned by REDZONE. However, if the memory is allocated
// by memalign, the alignment might be higher and the user-accessible memory
- // starts at the first properly aligned address after the end of 'this'.
- uptr Beg() {
- return RoundUpTo((uptr)this + sizeof(ChunkBase), 1 << alignment_log);
- }
+ // starts at the first properly aligned address after 'this'.
+ uptr Beg() { return RoundUpTo((uptr)this + 1, 1 << alignment_log); }
uptr Size() { return SizeClassToSize(size_class); }
u8 SizeClass() { return size_class; }
};
struct AsanChunk: public ChunkBase {
u32 *compressed_alloc_stack() {
- CHECK(REDZONE >= sizeof(ChunkBase));
return (u32*)((uptr)this + sizeof(ChunkBase));
}
u32 *compressed_free_stack() {
- CHECK(REDZONE >= sizeof(ChunkBase));
- return (u32*)((uptr)this + REDZONE);
+ return (u32*)((uptr)this + Max(REDZONE, (uptr)sizeof(ChunkBase)));
}
// The left redzone after the ChunkBase is given to the alloc stack trace.
uptr compressed_alloc_stack_size() {
+ if (REDZONE < sizeof(ChunkBase)) return 0;
return (REDZONE - sizeof(ChunkBase)) / sizeof(u32);
}
uptr compressed_free_stack_size() {
+ if (REDZONE < sizeof(ChunkBase)) return 0;
return (REDZONE) / sizeof(u32);
}
@@ -680,7 +678,7 @@ static u8 *Allocate(uptr alignment, uptr size, AsanStackTrace *stack) {
m->next = 0;
CHECK(m->Size() == size_to_allocate);
uptr addr = (uptr)m + REDZONE;
- CHECK(addr == (uptr)m->compressed_free_stack());
+ CHECK(addr <= (uptr)m->compressed_free_stack());
if (alignment > REDZONE && (addr & (alignment - 1))) {
addr = RoundUpTo(addr, alignment);
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index 96078ebd3..4aa5fc5fc 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -445,8 +445,8 @@ static void ParseAsanOptions(const char *options) {
IntFlagValue(options, "verbosity=", &FLAG_v);
IntFlagValue(options, "redzone=", (s64*)&FLAG_redzone);
- CHECK(FLAG_redzone >= 32);
- CHECK((FLAG_redzone & (FLAG_redzone - 1)) == 0);
+ CHECK(FLAG_redzone >= 16);
+ CHECK(IsPowerOfTwo(FLAG_redzone));
IntFlagValue(options, "quarantine_size=", (s64*)&FLAG_quarantine_size);
IntFlagValue(options, "atexit=", &FLAG_atexit);