Skip to content

Commit a303bd7

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6
1 parent 489a921 commit a303bd7

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

compiler-rt/lib/asan/asan_fake_stack.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -214,35 +214,42 @@ void FakeStack::ForEachFakeFrame(RangeIteratorCallback callback, void *arg) {
214214
#if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA
215215
static THREADLOCAL FakeStack *fake_stack_tls;
216216

217-
FakeStack *GetTLSFakeStack() {
218-
return fake_stack_tls;
219-
}
220-
void SetTLSFakeStack(FakeStack *fs) {
221-
fake_stack_tls = fs;
222-
}
217+
FakeStack* GetTLSFakeStack() { return fake_stack_tls; }
218+
static void SetTLSFakeStack(FakeStack* fs) { fake_stack_tls = fs; }
219+
void ResetTLSFakeStack() { fake_stack_tls = nullptr; }
223220
#else
224-
FakeStack *GetTLSFakeStack() { return 0; }
225-
void SetTLSFakeStack(FakeStack *fs) { }
221+
FakeStack* GetTLSFakeStack() { return 0; }
222+
static void SetTLSFakeStack(FakeStack*) {}
223+
void ResetTLSFakeStack() {}
226224
#endif // (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA
227225

228-
static FakeStack *GetFakeStack() {
229-
AsanThread *t = GetCurrentThread();
230-
if (!t) return nullptr;
226+
static FakeStack* GetFakeStack() {
227+
AsanThread* t = GetCurrentThread();
228+
if (!t)
229+
return nullptr;
231230
return t->get_or_create_fake_stack();
232231
}
233232

234-
static FakeStack *GetFakeStackFast() {
235-
if (FakeStack *fs = GetTLSFakeStack())
233+
static FakeStack* GetFakeStackFast() {
234+
FakeStack* fs = GetTLSFakeStack();
235+
if (LIKELY(fs))
236236
return fs;
237237
if (!__asan_option_detect_stack_use_after_return)
238238
return nullptr;
239-
return GetFakeStack();
239+
fs = GetFakeStack();
240+
if (LIKELY(fs))
241+
SetTLSFakeStack(fs);
242+
return fs;
240243
}
241244

242-
static FakeStack *GetFakeStackFastAlways() {
243-
if (FakeStack *fs = GetTLSFakeStack())
245+
static FakeStack* GetFakeStackFastAlways() {
246+
FakeStack* fs = GetTLSFakeStack();
247+
if (LIKELY(fs))
244248
return fs;
245-
return GetFakeStack();
249+
fs = GetFakeStack();
250+
if (LIKELY(fs))
251+
SetTLSFakeStack(fs);
252+
return fs;
246253
}
247254

248255
static ALWAYS_INLINE uptr OnMalloc(uptr class_id, uptr size) {

compiler-rt/lib/asan/asan_fake_stack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class FakeStack {
196196
};
197197

198198
FakeStack *GetTLSFakeStack();
199-
void SetTLSFakeStack(FakeStack *fs);
199+
void ResetTLSFakeStack();
200200

201201
} // namespace __asan
202202

compiler-rt/lib/asan/asan_thread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void AsanThread::StartSwitchFiber(FakeStack **fake_stack_save, uptr bottom,
163163
if (fake_stack_save)
164164
*fake_stack_save = fake_stack_;
165165
fake_stack_ = nullptr;
166-
SetTLSFakeStack(nullptr);
166+
ResetTLSFakeStack();
167167
// if fake_stack_save is null, the fiber will die, delete the fakestack
168168
if (!fake_stack_save && current_fake_stack)
169169
current_fake_stack->Destroy(this->tid());
@@ -177,8 +177,8 @@ void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save, uptr *bottom_old,
177177
}
178178

179179
if (fake_stack_save) {
180-
SetTLSFakeStack(fake_stack_save);
181180
fake_stack_ = fake_stack_save;
181+
ResetTLSFakeStack();
182182
}
183183

184184
if (bottom_old)
@@ -242,7 +242,7 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
242242
Max(stack_size_log, static_cast<uptr>(flags()->min_uar_stack_size_log));
243243
fake_stack_ = FakeStack::Create(stack_size_log);
244244
DCHECK_EQ(GetCurrentThread(), this);
245-
SetTLSFakeStack(fake_stack_);
245+
ResetTLSFakeStack();
246246
return fake_stack_;
247247
}
248248
return nullptr;

compiler-rt/lib/asan/asan_thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class AsanThread {
104104
if (!fake_stack_) return;
105105
FakeStack *t = fake_stack_;
106106
fake_stack_ = nullptr;
107-
SetTLSFakeStack(nullptr);
107+
ResetTLSFakeStack();
108108
t->Destroy(tid);
109109
}
110110

0 commit comments

Comments
 (0)