Skip to content

Commit 328f696

Browse files
authored
Revert "[sanitizer] Fix partially initialized static TLS range (#108685)"
This reverts commit b7c9ebe.
1 parent 50d15e6 commit 328f696

File tree

16 files changed

+120
-86
lines changed

16 files changed

+120
-86
lines changed

compiler-rt/lib/asan/asan_posix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ bool PlatformUnpoisonStacks() {
5959

6060
// Since we're on the signal alternate stack, we cannot find the DEFAULT
6161
// stack bottom using a local variable.
62-
uptr stack_begin, stack_end, tls_begin, tls_end;
63-
GetThreadStackAndTls(/*main=*/false, &stack_begin, &stack_end, &tls_begin,
64-
&tls_end);
65-
UnpoisonStack(stack_begin, stack_end, "default");
62+
uptr default_bottom, tls_addr, tls_size, stack_size;
63+
GetThreadStackAndTls(/*main=*/false, &default_bottom, &stack_size, &tls_addr,
64+
&tls_size);
65+
UnpoisonStack(default_bottom, default_bottom + stack_size, "default");
6666
return true;
6767
}
6868

compiler-rt/lib/asan/asan_rtl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,10 @@ static void UnpoisonDefaultStack() {
580580
} else {
581581
CHECK(!SANITIZER_FUCHSIA);
582582
// If we haven't seen this thread, try asking the OS for stack bounds.
583-
uptr tls_begin, tls_end;
584-
GetThreadStackAndTls(/*main=*/false, &bottom, &top, &tls_begin, &tls_end);
583+
uptr tls_addr, tls_size, stack_size;
584+
GetThreadStackAndTls(/*main=*/false, &bottom, &stack_size, &tls_addr,
585+
&tls_size);
586+
top = bottom + stack_size;
585587
}
586588

587589
UnpoisonStack(bottom, top, "default");

compiler-rt/lib/asan/asan_thread.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,13 @@ AsanThread *CreateMainThread() {
306306
// OS-specific implementations that need more information passed through.
307307
void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
308308
DCHECK_EQ(options, nullptr);
309-
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_top_,
310-
&tls_begin_, &tls_end_);
311-
stack_top_ = RoundDownTo(stack_top_, ASAN_SHADOW_GRANULARITY);
309+
uptr tls_size = 0;
310+
uptr stack_size = 0;
311+
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_size,
312+
&tls_begin_, &tls_size);
313+
stack_top_ = RoundDownTo(stack_bottom_ + stack_size, ASAN_SHADOW_GRANULARITY);
312314
stack_bottom_ = RoundDownTo(stack_bottom_, ASAN_SHADOW_GRANULARITY);
315+
tls_end_ = tls_begin_ + tls_size;
313316
dtls_ = DTLS_Get();
314317

315318
if (stack_top_ != stack_bottom_) {

compiler-rt/lib/dfsan/dfsan_thread.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ DFsanThread *DFsanThread::Create(thread_callback_t start_routine, void *arg,
2121
}
2222

2323
void DFsanThread::SetThreadStackAndTls() {
24-
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_.top, &tls_begin_,
25-
&tls_end_);
24+
uptr tls_size = 0;
25+
uptr stack_size = 0;
26+
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_size, &tls_begin_,
27+
&tls_size);
28+
stack_.top = stack_.bottom + stack_size;
29+
tls_end_ = tls_begin_ + tls_size;
30+
2631
int local;
2732
CHECK(AddrIsInStack((uptr)&local));
2833
}

compiler-rt/lib/hwasan/hwasan_linux.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,12 @@ void HwasanOnDeadlySignal(int signo, void *info, void *context) {
499499
}
500500

501501
void Thread::InitStackAndTls(const InitState *) {
502-
GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_top_, &tls_begin_,
503-
&tls_end_);
502+
uptr tls_size;
503+
uptr stack_size;
504+
GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
505+
&tls_size);
506+
stack_top_ = stack_bottom_ + stack_size;
507+
tls_end_ = tls_begin_ + tls_size;
504508
}
505509

506510
uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {

compiler-rt/lib/lsan/lsan_posix.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ void ThreadContext::OnStarted(void *arg) {
5050

5151
void ThreadStart(u32 tid, tid_t os_id, ThreadType thread_type) {
5252
OnStartedArgs args;
53-
GetThreadStackAndTls(tid == kMainTid, &args.stack_begin, &args.stack_end,
54-
&args.tls_begin, &args.tls_end);
53+
uptr stack_size = 0;
54+
uptr tls_size = 0;
55+
GetThreadStackAndTls(tid == kMainTid, &args.stack_begin, &stack_size,
56+
&args.tls_begin, &tls_size);
57+
args.stack_end = args.stack_begin + stack_size;
58+
args.tls_end = args.tls_begin + tls_size;
5559
GetAllocatorCacheRange(&args.cache_begin, &args.cache_end);
5660
args.dtls = DTLS_Get();
5761
ThreadContextLsanBase::ThreadStart(tid, os_id, thread_type, &args);

compiler-rt/lib/memprof/memprof_thread.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ MemprofThread *CreateMainThread() {
168168
// OS-specific implementations that need more information passed through.
169169
void MemprofThread::SetThreadStackAndTls(const InitOptions *options) {
170170
DCHECK_EQ(options, nullptr);
171-
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_top_,
172-
&tls_begin_, &tls_end_);
171+
uptr tls_size = 0;
172+
uptr stack_size = 0;
173+
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_size,
174+
&tls_begin_, &tls_size);
175+
stack_top_ = stack_bottom_ + stack_size;
176+
tls_end_ = tls_begin_ + tls_size;
173177
dtls_ = DTLS_Get();
174178

175179
if (stack_top_ != stack_bottom_) {

compiler-rt/lib/msan/msan_thread.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ MsanThread *MsanThread::Create(thread_callback_t start_routine,
2020
}
2121

2222
void MsanThread::SetThreadStackAndTls() {
23-
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_.top, &tls_begin_,
24-
&tls_end_);
23+
uptr tls_size = 0;
24+
uptr stack_size = 0;
25+
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_size, &tls_begin_,
26+
&tls_size);
27+
stack_.top = stack_.bottom + stack_size;
28+
tls_end_ = tls_begin_ + tls_size;
29+
2530
int local;
2631
CHECK(AddrIsInStack((uptr)&local));
2732
}

compiler-rt/lib/nsan/nsan_thread.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ NsanThread *NsanThread::Create(thread_callback_t start_routine, void *arg) {
2929
}
3030

3131
void NsanThread::SetThreadStackAndTls() {
32-
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_.top, &tls_begin_,
33-
&tls_end_);
32+
uptr tls_size = 0;
33+
uptr stack_size = 0;
34+
GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_size, &tls_begin_,
35+
&tls_size);
36+
stack_.top = stack_.bottom + stack_size;
37+
tls_end_ = tls_begin_ + tls_size;
38+
3439
int local;
3540
CHECK(AddrIsInStack((uptr)&local));
3641
}

compiler-rt/lib/sanitizer_common/sanitizer_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ int TgKill(pid_t pid, tid_t tid, int sig);
8383
uptr GetThreadSelf();
8484
void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
8585
uptr *stack_bottom);
86-
void GetThreadStackAndTls(bool main, uptr *stk_begin, uptr *stk_end,
87-
uptr *tls_begin, uptr *tls_end);
86+
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
87+
uptr *tls_addr, uptr *tls_size);
8888

8989
// Memory management
9090
void *MmapOrDie(uptr size, const char *mem_type, bool raw_report = false);

0 commit comments

Comments
 (0)