Skip to content

Commit

Permalink
[NFC][asan] Split AsanThread::ThreadStart
Browse files Browse the repository at this point in the history
Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D156290
  • Loading branch information
vitalybuka committed Jul 26, 2023
1 parent 011cc6d commit 4e1b55a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
3 changes: 2 additions & 1 deletion compiler-rt/lib/asan/asan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ 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());
t->ThreadStart(GetTid());
thread_return_t retval = t->RunThread();
asanThreadArgRetval().Finish(self, retval);
CHECK_EQ(args.arg_retval, t->get_arg());
return retval;
Expand Down
14 changes: 3 additions & 11 deletions compiler-rt/lib/asan/asan_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,16 @@ 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) {
void AsanThread::ThreadStart(tid_t os_id) {
Init();
asanThreadRegistry().StartThread(tid(), os_id, ThreadType::Regular, nullptr);

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

if (!start_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);
return 0;
}

return start_routine_(arg_);
}

thread_return_t AsanThread::RunThread() { return start_routine_(arg_); }

AsanThread *CreateMainThread() {
AsanThread *main_thread = AsanThread::Create(
/* start_routine */ nullptr, /* arg */ nullptr, /* parent_tid */ kMainTid,
Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/lib/asan/asan_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class AsanThread {
struct InitOptions;
void Init(const InitOptions *options = nullptr);

thread_return_t ThreadStart(tid_t os_id);
void ThreadStart(tid_t os_id);
thread_return_t RunThread();

uptr stack_top();
uptr stack_bottom();
Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/lib/asan/asan_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ INTERCEPTOR(int, _except_handler4, void *a, void *b, void *c, void *d) {
static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
AsanThread *t = (AsanThread *)arg;
SetCurrentThread(t);
auto res = t->ThreadStart(GetTid());
t->ThreadStart(GetTid());
auto res = t->RunThread();
t->Destroy(); // POSIX calls this from TSD destructor.
return res;
}
Expand Down

0 comments on commit 4e1b55a

Please sign in to comment.