forked from OSchip/llvm-project
tsan: move shadow stack into ThreadState
Currently the shadow stack is located in the trace memory mapping. The new tsan runtime will remove the trace memory mapping. Move the shadow stack into ThreadState as a preparation step. Reviewed By: melver Differential Revision: https://reviews.llvm.org/D110519
This commit is contained in:
parent
e2b46e336b
commit
ed7f3f5bc9
|
@ -145,6 +145,16 @@ ThreadState::ThreadState(Context *ctx, Tid tid, int unique_id, u64 epoch,
|
|||
last_sleep_clock(tid)
|
||||
#endif
|
||||
{
|
||||
#if !SANITIZER_GO
|
||||
shadow_stack_pos = shadow_stack;
|
||||
shadow_stack_end = shadow_stack + kShadowStackSize;
|
||||
#else
|
||||
// Setup dynamic shadow stack.
|
||||
const int kInitStackSize = 8;
|
||||
shadow_stack = (uptr *)Alloc(kInitStackSize * sizeof(uptr));
|
||||
shadow_stack_pos = shadow_stack;
|
||||
shadow_stack_end = shadow_stack + kInitStackSize;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !SANITIZER_GO
|
||||
|
|
|
@ -159,10 +159,12 @@ struct ThreadState {
|
|||
#if !SANITIZER_GO
|
||||
IgnoreSet mop_ignore_set;
|
||||
IgnoreSet sync_ignore_set;
|
||||
#endif
|
||||
// C/C++ uses fixed size shadow stack embed into Trace.
|
||||
// C/C++ uses fixed size shadow stack.
|
||||
uptr shadow_stack[kShadowStackSize];
|
||||
#else
|
||||
// Go uses malloc-allocated shadow stack with dynamic size.
|
||||
uptr *shadow_stack;
|
||||
#endif
|
||||
uptr *shadow_stack_end;
|
||||
uptr *shadow_stack_pos;
|
||||
RawShadow *racy_shadow_addr;
|
||||
|
|
|
@ -190,17 +190,6 @@ void ThreadContext::OnStarted(void *arg) {
|
|||
new (thr)
|
||||
ThreadState(ctx, tid, unique_id, epoch0, reuse_count, args->stk_addr,
|
||||
args->stk_size, args->tls_addr, args->tls_size);
|
||||
#if !SANITIZER_GO
|
||||
thr->shadow_stack = &ThreadTrace(thr->tid)->shadow_stack[0];
|
||||
thr->shadow_stack_pos = thr->shadow_stack;
|
||||
thr->shadow_stack_end = thr->shadow_stack + kShadowStackSize;
|
||||
#else
|
||||
// Setup dynamic shadow stack.
|
||||
const int kInitStackSize = 8;
|
||||
thr->shadow_stack = (uptr *)Alloc(kInitStackSize * sizeof(uptr));
|
||||
thr->shadow_stack_pos = thr->shadow_stack;
|
||||
thr->shadow_stack_end = thr->shadow_stack + kInitStackSize;
|
||||
#endif
|
||||
if (common_flags()->detect_deadlocks)
|
||||
thr->dd_lt = ctx->dd->CreateLogicalThread(unique_id);
|
||||
thr->fast_state.SetHistorySize(flags()->history_size);
|
||||
|
|
|
@ -19,10 +19,6 @@ namespace __tsan {
|
|||
template <typename StackTraceTy>
|
||||
static void TestStackTrace(StackTraceTy *trace) {
|
||||
ThreadState thr(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
uptr stack[128];
|
||||
thr.shadow_stack = &stack[0];
|
||||
thr.shadow_stack_pos = &stack[0];
|
||||
thr.shadow_stack_end = &stack[128];
|
||||
|
||||
ObtainCurrentStack(&thr, 0, trace);
|
||||
EXPECT_EQ(0U, trace->size);
|
||||
|
@ -48,13 +44,8 @@ static void TestStackTrace(StackTraceTy *trace) {
|
|||
template<typename StackTraceTy>
|
||||
static void TestTrim(StackTraceTy *trace) {
|
||||
ThreadState thr(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
const uptr kShadowStackSize = 2 * kStackTraceMax;
|
||||
uptr stack[kShadowStackSize];
|
||||
thr.shadow_stack = &stack[0];
|
||||
thr.shadow_stack_pos = &stack[0];
|
||||
thr.shadow_stack_end = &stack[kShadowStackSize];
|
||||
|
||||
for (uptr i = 0; i < kShadowStackSize; ++i)
|
||||
for (uptr i = 0; i < 2 * kStackTraceMax; ++i)
|
||||
*thr.shadow_stack_pos++ = 100 + i;
|
||||
|
||||
ObtainCurrentStack(&thr, 0, trace);
|
||||
|
|
Loading…
Reference in New Issue