[asan] do not use new/delete for the internal thread structure

llvm-svn: 147674
This commit is contained in:
Kostya Serebryany 2012-01-06 19:44:11 +00:00
parent 667a074be0
commit 3f4b9bb4a0
5 changed files with 20 additions and 20 deletions

View File

@ -28,8 +28,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <new>
namespace __asan {
extern dispatch_async_f_f real_dispatch_async_f;
@ -190,9 +188,8 @@ void asan_dispatch_call_block_and_release(void *block) {
// It's incorrect to assert that the current thread is not dying: at least
// the callbacks from dispatch_sync() are sometimes called after the TSD is
// destroyed.
t = (AsanThread*)asan_malloc(sizeof(AsanThread), &stack);
new(t) AsanThread(context->parent_tid,
/*start_routine*/NULL, /*arg*/NULL, &stack);
AsanThread *t = AsanThread::Create(context->parent_tid, NULL, NULL);
asanThreadRegistry().RegisterThread(t, context->parent_tid, &stack);
t->Init();
asanThreadRegistry().SetCurrent(t);
}

View File

@ -396,11 +396,11 @@ __attribute__((visibility("default")))
int WRAP(pthread_create)(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg) {
GET_STACK_TRACE_HERE(kStackTraceMax, /*fast_unwind*/false);
AsanThread *t = (AsanThread*)asan_malloc(sizeof(AsanThread), &stack);
AsanThread *curr_thread = asanThreadRegistry().GetCurrent();
CHECK(curr_thread || asanThreadRegistry().IsCurrentThreadDying());
new(t) AsanThread(asanThreadRegistry().GetCurrentTidOrMinusOne(),
start_routine, arg, &stack);
int current_tid = asanThreadRegistry().GetCurrentTidOrMinusOne();
AsanThread *t = AsanThread::Create(current_tid, start_routine, arg);
asanThreadRegistry().RegisterThread(t, current_tid, &stack);
return real_pthread_create(thread, attr, asan_thread_start, t);
}

View File

@ -15,7 +15,6 @@
#include "asan_interceptors.h"
#include "asan_procmaps.h"
#include "asan_thread.h"
#include "asan_thread_registry.h"
#include "asan_mapping.h"
#include <pthread.h>
@ -29,20 +28,23 @@ AsanThread::AsanThread(LinkerInitialized x)
malloc_storage_(x),
stats_(x) { }
AsanThread::AsanThread(int parent_tid, void *(*start_routine) (void *),
void *arg, AsanStackTrace *stack)
: start_routine_(start_routine),
arg_(arg) {
asanThreadRegistry().RegisterThread(this, parent_tid, stack);
AsanThread *AsanThread::Create(int parent_tid, void *(*start_routine) (void *),
void *arg) {
size_t size = RoundUpTo(sizeof(AsanThread), kPageSize);
AsanThread *res = (AsanThread*)AsanMmapSomewhereOrDie(size, __FUNCTION__);
res->start_routine_ = start_routine;
res->arg_ = arg;
return res;
}
AsanThread::~AsanThread() {
asanThreadRegistry().UnregisterThread(this);
void AsanThread::Destroy() {
fake_stack().Cleanup();
// We also clear the shadow on thread destruction because
// some code may still be executing in later TSD destructors
// and we don't want it to have any poisoned stack.
ClearShadowForThreadStack();
size_t size = RoundUpTo(sizeof(AsanThread), kPageSize);
AsanUnmapOrDie(this, size);
}
void AsanThread::ClearShadowForThreadStack() {

View File

@ -62,9 +62,9 @@ class AsanThreadSummary {
class AsanThread {
public:
explicit AsanThread(LinkerInitialized); // for T0.
AsanThread(int parent_tid, void *(*start_routine) (void *),
void *arg, AsanStackTrace *stack);
~AsanThread();
static AsanThread *Create(int parent_tid, void *(*start_routine) (void *),
void *arg);
void Destroy();
void Init(); // Should be called from the thread itself.
void *ThreadStart();

View File

@ -51,7 +51,8 @@ static void DestroyAsanTsd(void *tsd) {
// The pointer is valid.
AsanThread *t = (AsanThread*)tsd;
if (t != asanThreadRegistry().GetMain()) {
delete t;
asanThreadRegistry().UnregisterThread(t);
t->Destroy();
}
iter = 1;
} else {