[compiler-rt] [compiler-rt][nsan] Update UnwindImpl following msan's example (PR #107313)
Alexander Shaposhnikov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 14:21:06 PDT 2024
https://github.com/alexander-shaposhnikov created https://github.com/llvm/llvm-project/pull/107313
Implement __sanitizer::BufferedStackTrace::UnwindImpl following msan.
>From 1c0558e8d19529ee28b9b0731f494aade8d48004 Mon Sep 17 00:00:00 2001
From: Alexander Shaposhnikov <ashaposhnikov at google.com>
Date: Wed, 4 Sep 2024 21:13:47 +0000
Subject: [PATCH] [compiler-rt][nsan] Update
__sanitizer::BufferedStackTrace::UnwindImpl following msan's example
---
compiler-rt/lib/nsan/nsan.cpp | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/compiler-rt/lib/nsan/nsan.cpp b/compiler-rt/lib/nsan/nsan.cpp
index 4be9c673bd4e00..c2e7690e12ab10 100644
--- a/compiler-rt/lib/nsan/nsan.cpp
+++ b/compiler-rt/lib/nsan/nsan.cpp
@@ -195,12 +195,19 @@ template <typename T> T max(T a, T b) { return a < b ? b : a; }
} // end anonymous namespace
-void __sanitizer::BufferedStackTrace::UnwindImpl(uptr pc, uptr bp,
- void *context,
- bool request_fast,
- u32 max_depth) {
- using namespace __nsan;
- return Unwind(max_depth, pc, bp, context, 0, 0, false);
+void __sanitizer::BufferedStackTrace::UnwindImpl(
+ uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) {
+ using namespace __msan;
+ NsanThread *t = GetCurrentThread();
+ if (!t || !StackTrace::WillUseFastUnwind(request_fast)) {
+ // Block reports from our interceptors during _Unwind_Backtrace.
+ return Unwind(max_depth, pc, bp, context, t ? t->stack_top() : 0,
+ t ? t->stack_bottom() : 0, false);
+ }
+ if (StackTrace::WillUseFastUnwind(request_fast))
+ Unwind(max_depth, pc, bp, nullptr, t->stack_top(), t->stack_bottom(), true);
+ else
+ Unwind(max_depth, pc, 0, context, 0, 0, false);
}
extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_print_accumulated_stats() {
More information about the llvm-commits
mailing list