summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-06-06 14:46:38 +0000
committerKostya Serebryany <kcc@google.com>2012-06-06 14:46:38 +0000
commit53b74ac25697fb03569ffe98e309be377899ba92 (patch)
treee7991ef67c4badaea25e6c900f1fc7e6ae256780
parent64166ca86bc2ed3d363233b14d68cb2c1f6e4322 (diff)
downloadbcm5719-llvm-53b74ac25697fb03569ffe98e309be377899ba92.tar.gz
bcm5719-llvm-53b74ac25697fb03569ffe98e309be377899ba92.zip
[asan] start compacting the allocator header, the goal is to make it 16 bytes w/o losing any information
llvm-svn: 158072
-rw-r--r--compiler-rt/lib/asan/asan_allocator.cc22
-rw-r--r--compiler-rt/lib/asan/asan_internal.h1
-rw-r--r--compiler-rt/lib/asan/asan_posix.cc4
-rw-r--r--compiler-rt/lib/asan/asan_win.cc7
4 files changed, 23 insertions, 11 deletions
diff --git a/compiler-rt/lib/asan/asan_allocator.cc b/compiler-rt/lib/asan/asan_allocator.cc
index afa1dc0a8d8..48ed6518d53 100644
--- a/compiler-rt/lib/asan/asan_allocator.cc
+++ b/compiler-rt/lib/asan/asan_allocator.cc
@@ -150,19 +150,19 @@ static u8 *MmapNewPagesAndPoisonShadow(uptr size) {
//
// The magic numbers for the enum values are taken randomly.
enum {
- CHUNK_AVAILABLE = 0x573B,
- CHUNK_ALLOCATED = 0x3204,
- CHUNK_QUARANTINE = 0x1978,
- CHUNK_MEMALIGN = 0xDC68,
+ CHUNK_AVAILABLE = 0x57,
+ CHUNK_ALLOCATED = 0x32,
+ CHUNK_QUARANTINE = 0x19,
+ CHUNK_MEMALIGN = 0xDC,
};
struct ChunkBase {
- u16 chunk_state;
- u8 size_class;
- u32 offset; // User-visible memory starts at this+offset (beg()).
- s32 alloc_tid;
- s32 free_tid;
- uptr used_size; // Size requested by the user.
+ u8 chunk_state;
+ u8 size_class;
+ u32 offset; // User-visible memory starts at this+offset (beg()).
+ s32 alloc_tid;
+ s32 free_tid;
+ uptr used_size; // Size requested by the user.
AsanChunk *next;
uptr beg() { return (uptr)this + offset; }
@@ -708,7 +708,7 @@ static void Deallocate(u8 *ptr, AsanStackTrace *stack) {
AsanChunk *m = PtrToChunk((uptr)ptr);
// Flip the state atomically to avoid race on double-free.
- u16 old_chunk_state = AtomicExchange(&m->chunk_state, CHUNK_QUARANTINE);
+ u8 old_chunk_state = AtomicExchange(&m->chunk_state, CHUNK_QUARANTINE);
if (old_chunk_state == CHUNK_QUARANTINE) {
AsanReport("ERROR: AddressSanitizer attempting double-free on %p:\n", ptr);
diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h
index 63bed97a5ed..48818a1b134 100644
--- a/compiler-rt/lib/asan/asan_internal.h
+++ b/compiler-rt/lib/asan/asan_internal.h
@@ -144,6 +144,7 @@ void InstallSignalHandlers();
uptr GetThreadSelf();
int AtomicInc(int *a);
u16 AtomicExchange(u16 *a, u16 new_val);
+u8 AtomicExchange(u8 *a, u8 new_val);
// Wrapper for TLS/TSD.
void AsanTSDInit(void (*destructor)(void *tsd));
diff --git a/compiler-rt/lib/asan/asan_posix.cc b/compiler-rt/lib/asan/asan_posix.cc
index de715c53a64..1903bc7092c 100644
--- a/compiler-rt/lib/asan/asan_posix.cc
+++ b/compiler-rt/lib/asan/asan_posix.cc
@@ -186,6 +186,10 @@ u16 AtomicExchange(u16 *a, u16 new_val) {
return __sync_lock_test_and_set(a, new_val);
}
+u8 AtomicExchange(u8 *a, u8 new_val) {
+ return __sync_lock_test_and_set(a, new_val);
+}
+
void SortArray(uptr *array, uptr size) {
std::sort(array, array + size);
}
diff --git a/compiler-rt/lib/asan/asan_win.cc b/compiler-rt/lib/asan/asan_win.cc
index 609f3d4322f..8e49edafd8c 100644
--- a/compiler-rt/lib/asan/asan_win.cc
+++ b/compiler-rt/lib/asan/asan_win.cc
@@ -219,6 +219,13 @@ u16 AtomicExchange(u16 *a, u16 new_val) {
return new_val;
}
+u16 AtomicExchange(u16 *a, u16 new_val) {
+ // FIXME: can we do this with a proper xchg intrinsic?
+ u8 t = *a;
+ *a = new_val;
+ return t;
+}
+
const char* AsanGetEnv(const char* name) {
static char env_buffer[32767] = {};
OpenPOWER on IntegriCloud