[compiler-rt] r193308 - Introduce an operator new for LowLevelAllocator, and convert most users to it.
Peter Collingbourne
peter at pcc.me.uk
Wed Oct 23 23:23:39 PDT 2013
Author: pcc
Date: Thu Oct 24 01:23:39 2013
New Revision: 193308
URL: http://llvm.org/viewvc/llvm-project?rev=193308&view=rev
Log:
Introduce an operator new for LowLevelAllocator, and convert most users to it.
Modified:
compiler-rt/trunk/lib/asan/asan_globals.cc
compiler-rt/trunk/lib/asan/asan_thread.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_placement_new.h
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc
Modified: compiler-rt/trunk/lib/asan/asan_globals.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_globals.cc?rev=193308&r1=193307&r2=193308&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_globals.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_globals.cc Thu Oct 24 01:23:39 2013
@@ -94,15 +94,13 @@ static void RegisterGlobal(const Global
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 };
Modified: compiler-rt/trunk/lib/asan/asan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.cc?rev=193308&r1=193307&r2=193308&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.cc Thu Oct 24 01:23:39 2013
@@ -48,8 +48,7 @@ static LowLevelAllocator allocator_for_t
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() {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=193308&r1=193307&r2=193308&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Thu Oct 24 01:23:39 2013
@@ -450,4 +450,9 @@ const uptr kPthreadDestructorIterations
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
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=193308&r1=193307&r2=193308&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Thu Oct 24 01:23:39 2013
@@ -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();
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_placement_new.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_placement_new.h?rev=193308&r1=193307&r2=193308&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_placement_new.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_placement_new.h Thu Oct 24 01:23:39 2013
@@ -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;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc?rev=193308&r1=193307&r2=193308&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc Thu Oct 24 01:23:39 2013
@@ -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;
More information about the llvm-commits
mailing list