diff options
| author | Peter Collingbourne <peter@pcc.me.uk> | 2013-10-24 06:23:39 +0000 |
|---|---|---|
| committer | Peter Collingbourne <peter@pcc.me.uk> | 2013-10-24 06:23:39 +0000 |
| commit | 53177247698bfba075f2d5b255a447fc3ced6976 (patch) | |
| tree | 570b148c39fdbe22b2e984e270778b73637d6e7f | |
| parent | a412f485298901a6cbf9d5d7489e834efebc9483 (diff) | |
| download | compiler-rt-53177247698bfba075f2d5b255a447fc3ced6976.tar.gz compiler-rt-53177247698bfba075f2d5b255a447fc3ced6976.tar.bz2 compiler-rt-53177247698bfba075f2d5b255a447fc3ced6976.tar.xz | |
Introduce an operator new for LowLevelAllocator, and convert most users to it.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193308 91177308-0d34-0410-b5e6-96231b3b80d8
| -rw-r--r-- | lib/asan/asan_globals.cc | 6 | ||||
| -rw-r--r-- | lib/asan/asan_thread.cc | 3 | ||||
| -rw-r--r-- | lib/sanitizer_common/sanitizer_common.h | 5 | ||||
| -rw-r--r-- | lib/sanitizer_common/sanitizer_internal_defs.h | 18 | ||||
| -rw-r--r-- | lib/sanitizer_common/sanitizer_placement_new.h | 10 | ||||
| -rw-r--r-- | lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc | 3 |
6 files changed, 22 insertions, 23 deletions
diff --git a/lib/asan/asan_globals.cc b/lib/asan/asan_globals.cc index 3c3d620c..81699676 100644 --- a/lib/asan/asan_globals.cc +++ b/lib/asan/asan_globals.cc @@ -94,15 +94,13 @@ static void RegisterGlobal(const Global *g) { CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); if (flags()->poison_heap) PoisonRedZones(*g); - ListOfGlobals *l = - (ListOfGlobals*)allocator_for_globals.Allocate(sizeof(ListOfGlobals)); + ListOfGlobals *l = new(allocator_for_globals) ListOfGlobals; l->g = g; l->next = list_of_all_globals; list_of_all_globals = l; if (g->has_dynamic_init) { if (dynamic_init_globals == 0) { - void *mem = allocator_for_globals.Allocate(sizeof(VectorOfGlobals)); - dynamic_init_globals = new(mem) + dynamic_init_globals = new(allocator_for_globals) VectorOfGlobals(kDynamicInitGlobalsInitialCapacity); } DynInitGlobal dyn_global = { *g, false }; diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc index 00d62c0e..11167e98 100644 --- a/lib/asan/asan_thread.cc +++ b/lib/asan/asan_thread.cc @@ -48,8 +48,7 @@ static LowLevelAllocator allocator_for_thread_context; static ThreadContextBase *GetAsanThreadContext(u32 tid) { BlockingMutexLock lock(&mu_for_thread_context); - void *mem = allocator_for_thread_context.Allocate(sizeof(AsanThreadContext)); - return new(mem) AsanThreadContext(tid); + return new(allocator_for_thread_context) AsanThreadContext(tid); } ThreadRegistry &asanThreadRegistry() { diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h index 87f3b48f..31c22362 100644 --- a/lib/sanitizer_common/sanitizer_common.h +++ b/lib/sanitizer_common/sanitizer_common.h @@ -450,4 +450,9 @@ const uptr kPthreadDestructorIterations = 0; typedef void (*RangeIteratorCallback)(uptr begin, uptr end, void *arg); } // namespace __sanitizer +inline void *operator new(__sanitizer::operator_new_size_type size, + __sanitizer::LowLevelAllocator &alloc) { + return alloc.Allocate(size); +} + #endif // SANITIZER_COMMON_H diff --git a/lib/sanitizer_common/sanitizer_internal_defs.h b/lib/sanitizer_common/sanitizer_internal_defs.h index 1087f819..189614c3 100644 --- a/lib/sanitizer_common/sanitizer_internal_defs.h +++ b/lib/sanitizer_common/sanitizer_internal_defs.h @@ -34,6 +34,12 @@ # define SANITIZER_SUPPORTS_WEAK_HOOKS 0 #endif +#if __LP64__ || defined(_WIN64) +# define SANITIZER_WORDSIZE 64 +#else +# define SANITIZER_WORDSIZE 32 +#endif + // GCC does not understand __has_feature #if !defined(__has_feature) # define __has_feature(x) 0 @@ -79,6 +85,12 @@ typedef u64 OFF_T; typedef uptr OFF_T; #endif typedef u64 OFF64_T; + +#if (SANITIZER_WORDSIZE == 64) || SANITIZER_MAC +typedef uptr operator_new_size_type; +#else +typedef u32 operator_new_size_type; +#endif } // namespace __sanitizer extern "C" { @@ -167,12 +179,6 @@ typedef void* thread_return_t; #endif // _WIN32 typedef thread_return_t (THREAD_CALLING_CONV *thread_callback_t)(void* arg); -#if __LP64__ || defined(_WIN64) -# define SANITIZER_WORDSIZE 64 -#else -# define SANITIZER_WORDSIZE 32 -#endif - // NOTE: Functions below must be defined in each run-time. namespace __sanitizer { void NORETURN Die(); diff --git a/lib/sanitizer_common/sanitizer_placement_new.h b/lib/sanitizer_common/sanitizer_placement_new.h index a42301ae..8904d104 100644 --- a/lib/sanitizer_common/sanitizer_placement_new.h +++ b/lib/sanitizer_common/sanitizer_placement_new.h @@ -18,15 +18,7 @@ #include "sanitizer_internal_defs.h" -namespace __sanitizer { -#if (SANITIZER_WORDSIZE == 64) || SANITIZER_MAC -typedef uptr operator_new_ptr_type; -#else -typedef u32 operator_new_ptr_type; -#endif -} // namespace __sanitizer - -inline void *operator new(__sanitizer::operator_new_ptr_type sz, void *p) { +inline void *operator new(__sanitizer::operator_new_size_type sz, void *p) { return p; } diff --git a/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc b/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc index e080403f..ddc8dba5 100644 --- a/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc +++ b/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc @@ -23,8 +23,7 @@ static LowLevelAllocator tctx_allocator; template<typename TCTX> static ThreadContextBase *GetThreadContext(u32 tid) { BlockingMutexLock l(&tctx_allocator_lock); - void *mem = tctx_allocator.Allocate(sizeof(TCTX)); - return new(mem) TCTX(tid); + return new(tctx_allocator) TCTX(tid); } static const u32 kMaxRegistryThreads = 1000; |
