Skip to content

Commit

Permalink
[NFC][ASAN] Remove redundant fields of AsanThread
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybuka committed May 31, 2023
1 parent bce889c commit 8ac0847
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
7 changes: 3 additions & 4 deletions compiler-rt/lib/asan/asan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
SetCurrentThread(t);
auto self = GetThreadSelf();
auto args = asanThreadArgRetval().GetArgs(self);
thread_return_t retval = t->ThreadStart(GetTid());
thread_return_t retval =
t->ThreadStart(GetTid(), args.routine, args.arg_retval);
asanThreadArgRetval().Finish(self, retval);
CHECK_EQ(args.arg_retval, t->get_arg());
return retval;
}

Expand All @@ -197,8 +197,7 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
}();

u32 current_tid = GetCurrentTidOrInvalid();
AsanThread *t =
AsanThread::Create(start_routine, arg, current_tid, &stack, detached);
AsanThread *t = AsanThread::Create(current_tid, &stack, detached);

int result;
{
Expand Down
18 changes: 8 additions & 10 deletions compiler-rt/lib/asan/asan_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,11 @@ AsanThreadContext *GetThreadContextByTidLocked(u32 tid) {

// AsanThread implementation.

AsanThread *AsanThread::Create(thread_callback_t start_routine, void *arg,
u32 parent_tid, StackTrace *stack,
AsanThread *AsanThread::Create(u32 parent_tid, StackTrace *stack,
bool detached) {
uptr PageSize = GetPageSizeCached();
uptr size = RoundUpTo(sizeof(AsanThread), PageSize);
AsanThread *thread = (AsanThread *)MmapOrDie(size, __func__);
thread->start_routine_ = start_routine;
thread->arg_ = arg;
AsanThreadContext::CreateThreadContextArgs args = {thread, stack};
asanThreadRegistry().CreateThread(0, detached, parent_tid, &args);

Expand Down Expand Up @@ -273,22 +270,23 @@ void AsanThread::Init(const InitOptions *options) {
// asan_fuchsia.c definies CreateMainThread and SetThreadStackAndTls.
#if !SANITIZER_FUCHSIA

thread_return_t AsanThread::ThreadStart(tid_t os_id) {
thread_return_t AsanThread::ThreadStart(tid_t os_id, void *(*routine)(void *),
void *arg) {
Init();
asanThreadRegistry().StartThread(tid(), os_id, ThreadType::Regular, nullptr);

if (common_flags()->use_sigaltstack)
SetAlternateSignalStack();

if (!start_routine_) {
if (!routine) {
// start_routine_ == 0 if we're on the main thread or on one of the
// OS X libdispatch worker threads. But nobody is supposed to call
// ThreadStart() for the worker threads.
CHECK_EQ(tid(), 0);
CHECK_EQ(tid(), kMainTid);
return 0;
}

thread_return_t res = start_routine_(arg_);
thread_return_t res = (*routine)(arg);

// On POSIX systems we defer this to the TSD destructor. LSan will consider
// the thread's memory as non-live from the moment we call Destroy(), even
Expand All @@ -303,10 +301,10 @@ thread_return_t AsanThread::ThreadStart(tid_t os_id) {

AsanThread *CreateMainThread() {
AsanThread *main_thread = AsanThread::Create(
/* start_routine */ nullptr, /* arg */ nullptr, /* parent_tid */ kMainTid,
/* parent_tid */ kMainTid,
/* stack */ nullptr, /* detached */ true);
SetCurrentThread(main_thread);
main_thread->ThreadStart(internal_getpid());
main_thread->ThreadStart(internal_getpid(), nullptr, nullptr);
return main_thread;
}

Expand Down
9 changes: 2 additions & 7 deletions compiler-rt/lib/asan/asan_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ COMPILER_CHECK(sizeof(AsanThreadContext) <= 256);
// AsanThread are stored in TSD and destroyed when the thread dies.
class AsanThread {
public:
static AsanThread *Create(thread_callback_t start_routine, void *arg,
u32 parent_tid, StackTrace *stack, bool detached);
static AsanThread *Create(u32 parent_tid, StackTrace *stack, bool detached);
static void TSDDtor(void *tsd);
void Destroy();

struct InitOptions;
void Init(const InitOptions *options = nullptr);

thread_return_t ThreadStart(tid_t os_id);
thread_return_t ThreadStart(tid_t os_id, void *(*routine)(void *), void *arg);

uptr stack_top();
uptr stack_bottom();
Expand Down Expand Up @@ -130,8 +129,6 @@ class AsanThread {

void *extra_spill_area() { return &extra_spill_area_; }

void *get_arg() const { return arg_; }

private:
// NOTE: There is no AsanThread constructor. It is allocated
// via mmap() and *must* be valid in zero-initialized state.
Expand All @@ -148,8 +145,6 @@ class AsanThread {
StackBounds GetStackBounds() const;

AsanThreadContext *context_;
thread_callback_t start_routine_;
void *arg_;

uptr stack_top_;
uptr stack_bottom_;
Expand Down

0 comments on commit 8ac0847

Please sign in to comment.