[PATCH] D46467: [asan] Add argument to allow fake stack to be initialized during thread init

Walter Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 4 13:50:56 PDT 2018


waltl created this revision.
waltl added reviewers: vitalybuka, eugenis, alekseyshl.
Herald added a subscriber: kubamracek.

This will be used on RTEMS, where we prefer to allocate the memory up
front, rather than on first use which may be in a context
(i.e. interrupt handler) that is unable to allocate memory.


Repository:
  rL LLVM

https://reviews.llvm.org/D46467

Files:
  compiler-rt/lib/asan/asan_thread.cc
  compiler-rt/lib/asan/asan_thread.h


Index: compiler-rt/lib/asan/asan_thread.h
===================================================================
--- compiler-rt/lib/asan/asan_thread.h
+++ compiler-rt/lib/asan/asan_thread.h
@@ -68,7 +68,7 @@
   void Destroy();
 
   struct InitOptions;
-  void Init(const InitOptions *options = nullptr);
+  void Init(const InitOptions *options = nullptr, bool init_fake_stack = false);
 
   thread_return_t ThreadStart(tid_t os_id,
                               atomic_uintptr_t *signal_thread_is_registered);
Index: compiler-rt/lib/asan/asan_thread.cc
===================================================================
--- compiler-rt/lib/asan/asan_thread.cc
+++ compiler-rt/lib/asan/asan_thread.cc
@@ -222,16 +222,18 @@
   return nullptr;
 }
 
-void AsanThread::Init(const InitOptions *options) {
+void AsanThread::Init(const InitOptions *options, bool init_fake_stack) {
   next_stack_top_ = next_stack_bottom_ = 0;
   atomic_store(&stack_switching_, false, memory_order_release);
-  fake_stack_ = nullptr;  // Will be initialized lazily if needed.
+  fake_stack_ = nullptr;  // Will be initialized below, or lazily if needed.
   CHECK_EQ(this->stack_size(), 0U);
   SetThreadStackAndTls(options);
   CHECK_GT(this->stack_size(), 0U);
   CHECK(AddrIsInMem(stack_bottom_));
   CHECK(AddrIsInMem(stack_top_ - 1));
   ClearShadowForThreadStackAndTLS();
+  if (__asan_option_detect_stack_use_after_return && init_fake_stack)
+    AsyncSignalSafeLazyInitFakeStack();
   int local = 0;
   VReport(1, "T%d: stack [%p,%p) size 0x%zx; local=%p\n", tid(),
           (void *)stack_bottom_, (void *)stack_top_, stack_top_ - stack_bottom_,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46467.145284.patch
Type: text/x-patch
Size: 1631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180504/f2524064/attachment.bin>


More information about the llvm-commits mailing list