forked from OSchip/llvm-project
Introduce an operator new for LowLevelAllocator, and convert most users to it.
llvm-svn: 193308
This commit is contained in:
parent
d04d096ecf
commit
50cb32e614
|
@ -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 };
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue