[PATCH] D58861: [NFC][Sanitizer] Cleanup ASan's GetStackTrace implementation

Julian Lettner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 2 22:52:47 PST 2019


yln updated this revision to Diff 189068.
yln added a comment.

Put back special case for MIPS.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58861/new/

https://reviews.llvm.org/D58861

Files:
  compiler-rt/lib/asan/asan_stack.cc
  compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h


Index: compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
@@ -134,6 +134,11 @@
   void UnwindSlow(uptr pc, u32 max_depth);
   void UnwindSlow(uptr pc, void *context, u32 max_depth);
 
+  void UnwindSlowWithOptionalContext(uptr pc, void *context, u32 max_depth) {
+    if (context) UnwindSlow(pc, context, max_depth);
+    else         UnwindSlow(pc, max_depth);
+  }
+
   void PopStackFrames(uptr count);
   uptr LocatePcInTrace(uptr pc);
 
Index: compiler-rt/lib/asan/asan_stack.cc
===================================================================
--- compiler-rt/lib/asan/asan_stack.cc
+++ compiler-rt/lib/asan/asan_stack.cc
@@ -31,28 +31,38 @@
 void __sanitizer::BufferedStackTrace::UnwindImpl(
     uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) {
   using namespace __asan;
-#if SANITIZER_WINDOWS
-  Unwind(max_depth, pc, 0, context, 0, 0, false);
-#else
-  AsanThread *t;
   size = 0;
-  if (LIKELY(asan_inited)) {
-    if ((t = GetCurrentThread()) && !t->isUnwinding()) {
-      uptr stack_top = t->stack_top();
-      uptr stack_bottom = t->stack_bottom();
-      ScopedUnwinding unwind_scope(t);
-      if (!SANITIZER_MIPS || IsValidFrame(bp, stack_top, stack_bottom)) {
-        if (StackTrace::WillUseFastUnwind(request_fast))
-          Unwind(max_depth, pc, bp, nullptr, stack_top, stack_bottom, true);
-        else
-          Unwind(max_depth, pc, 0, context, 0, 0, false);
-      }
-    } else if (!t && !request_fast) {
-      /* If GetCurrentThread() has failed, try to do slow unwind anyways. */
-      Unwind(max_depth, pc, bp, context, 0, 0, false);
+  if (UNLIKELY(!asan_inited)) return;
+
+  AsanThread *t = GetCurrentThread();
+  if (t && t->isUnwinding()) return;
+
+  if (!t) {
+#if SANITIZER_CAN_SLOW_UNWIND
+    // TODO(yln): no scope used
+    UnwindSlowWithOptionalContext(pc, context, max_depth);
+#endif
+    return;
+  }
+
+  ScopedUnwinding unwind_scope(t);
+  if (WillUseFastUnwind(request_fast)) {
+    uptr top = t->stack_top();
+    uptr bottom = t->stack_bottom();
+    if (!SANITIZER_MIPS || IsValidFrame(bp, top, bottom)) {
+      UnwindFast(pc, bp, top, bottom, max_depth);
+    } else {
+#if SANITIZER_CAN_SLOW_UNWIND
+      UnwindSlowWithOptionalContext(pc, context, max_depth);
+#endif
     }
+  } else {
+#if SANITIZER_CAN_SLOW_UNWIND
+    UnwindSlowWithOptionalContext(pc, context, max_depth);
+#else
+    UNREACHABLE("Slow unwinding is unsupported");
+#endif
   }
-#endif // SANITIZER_WINDOWS
 }
 
 // ------------------ Interface -------------- {{{1


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58861.189068.patch
Type: text/x-patch
Size: 2714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190303/4467c81d/attachment.bin>


More information about the llvm-commits mailing list