tsan: make cur_thread_init return cur_thread

Whenever we call cur_thread_init, we call cur_thread on the next line.
So make cur_thread_init return the current thread directly.
Makes code a bit shorter, does not affect codegen.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D110384
This commit is contained in:
Dmitry Vyukov 2021-09-24 06:57:37 +02:00
parent f4f9ad0f5d
commit a0ed71ff29
5 changed files with 13 additions and 23 deletions

View File

@ -32,16 +32,14 @@ LibIgnore *libignore();
#if !SANITIZER_GO
inline bool in_symbolizer() {
cur_thread_init();
return UNLIKELY(cur_thread()->in_symbolizer);
return UNLIKELY(cur_thread_init()->in_symbolizer);
}
#endif
} // namespace __tsan
#define SCOPED_INTERCEPTOR_RAW(func, ...) \
cur_thread_init(); \
ThreadState *thr = cur_thread(); \
ThreadState *thr = cur_thread_init(); \
const uptr caller_pc = GET_CALLER_PC(); \
ScopedInterceptor si(thr, #func, caller_pc); \
const uptr pc = GET_CURRENT_PC(); \

View File

@ -153,7 +153,7 @@ const int SIG_SETMASK = 2;
#endif
#define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED \
(cur_thread_init(), !cur_thread()->is_inited)
(!cur_thread_init()->is_inited)
namespace __tsan {
struct SignalDesc {
@ -531,10 +531,7 @@ static void LongJmp(ThreadState *thr, uptr *env) {
}
// FIXME: put everything below into a common extern "C" block?
extern "C" void __tsan_setjmp(uptr sp) {
cur_thread_init();
SetJmp(cur_thread(), sp);
}
extern "C" void __tsan_setjmp(uptr sp) { SetJmp(cur_thread_init(), sp); }
#if SANITIZER_MAC
TSAN_INTERCEPTOR(int, setjmp, void *env);
@ -973,8 +970,7 @@ extern "C" void *__tsan_thread_start_func(void *arg) {
void* (*callback)(void *arg) = p->callback;
void *param = p->param;
{
cur_thread_init();
ThreadState *thr = cur_thread();
ThreadState *thr = cur_thread_init();
// Thread-local state is not initialized yet.
ScopedIgnoreInterceptors ignore;
#if !SANITIZER_MAC && !SANITIZER_NETBSD && !SANITIZER_FREEBSD
@ -2061,8 +2057,7 @@ static bool is_sync_signal(ThreadSignalContext *sctx, int sig) {
}
void sighandler(int sig, __sanitizer_siginfo *info, void *ctx) {
cur_thread_init();
ThreadState *thr = cur_thread();
ThreadState *thr = cur_thread_init();
ThreadSignalContext *sctx = SigCtx(thr);
if (sig < 0 || sig >= kSigCount) {
VPrintf(1, "ThreadSanitizer: ignoring signal %d\n", sig);

View File

@ -20,10 +20,7 @@
using namespace __tsan;
void __tsan_init() {
cur_thread_init();
Initialize(cur_thread());
}
void __tsan_init() { Initialize(cur_thread_init()); }
void __tsan_flush_memory() {
FlushShadowMemory();

View File

@ -196,8 +196,7 @@ static void *BackgroundThread(void *arg) {
// We don't use ScopedIgnoreInterceptors, because we want ignores to be
// enabled even when the thread function exits (e.g. during pthread thread
// shutdown code).
cur_thread_init();
cur_thread()->ignore_interceptors++;
cur_thread_init()->ignore_interceptors++;
const u64 kMs2Ns = 1000 * 1000;
const u64 start = NanoTime();

View File

@ -230,23 +230,24 @@ struct ThreadState {
ThreadState *cur_thread();
void set_cur_thread(ThreadState *thr);
void cur_thread_finalize();
inline void cur_thread_init() { }
#else
inline ThreadState *cur_thread_init() { return cur_thread(); }
# else
__attribute__((tls_model("initial-exec")))
extern THREADLOCAL char cur_thread_placeholder[];
inline ThreadState *cur_thread() {
return reinterpret_cast<ThreadState *>(cur_thread_placeholder)->current;
}
inline void cur_thread_init() {
inline ThreadState *cur_thread_init() {
ThreadState *thr = reinterpret_cast<ThreadState *>(cur_thread_placeholder);
if (UNLIKELY(!thr->current))
thr->current = thr;
return thr->current;
}
inline void set_cur_thread(ThreadState *thr) {
reinterpret_cast<ThreadState *>(cur_thread_placeholder)->current = thr;
}
inline void cur_thread_finalize() { }
#endif // SANITIZER_MAC || SANITIZER_ANDROID
# endif // SANITIZER_MAC || SANITIZER_ANDROID
#endif // SANITIZER_GO
class ThreadContext final : public ThreadContextBase {