[compiler-rt] 8ac0847 - [NFC][ASAN] Remove redundant fields of AsanThread
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue May 30 18:33:06 PDT 2023
Author: Vitaly Buka
Date: 2023-05-30T18:25:51-07:00
New Revision: 8ac084728daf5b666624621562afb6d63cc01ae3
URL: https://github.com/llvm/llvm-project/commit/8ac084728daf5b666624621562afb6d63cc01ae3
DIFF: https://github.com/llvm/llvm-project/commit/8ac084728daf5b666624621562afb6d63cc01ae3.diff
LOG: [NFC][ASAN] Remove redundant fields of AsanThread
Added:
Modified:
compiler-rt/lib/asan/asan_interceptors.cpp
compiler-rt/lib/asan/asan_thread.cpp
compiler-rt/lib/asan/asan_thread.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 7aedefe81f95..086b23ca1a64 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -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;
}
@@ -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;
{
diff --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp
index f718adf5e1f7..5d0c134808b8 100644
--- a/compiler-rt/lib/asan/asan_thread.cpp
+++ b/compiler-rt/lib/asan/asan_thread.cpp
@@ -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);
@@ -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
@@ -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;
}
diff --git a/compiler-rt/lib/asan/asan_thread.h b/compiler-rt/lib/asan/asan_thread.h
index c131dd40d864..b6b7705f7876 100644
--- a/compiler-rt/lib/asan/asan_thread.h
+++ b/compiler-rt/lib/asan/asan_thread.h
@@ -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();
@@ -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.
@@ -148,8 +145,6 @@ class AsanThread {
StackBounds GetStackBounds() const;
AsanThreadContext *context_;
- thread_callback_t start_routine_;
- void *arg_;
uptr stack_top_;
uptr stack_bottom_;
More information about the llvm-commits
mailing list