1 //===--- rtsan_stack.cpp - Realtime Sanitizer -------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 //===----------------------------------------------------------------------===// 10 11 #include "rtsan_stack.h" 12 13 #include <sanitizer_common/sanitizer_flags.h> 14 #include <sanitizer_common/sanitizer_stacktrace.h> 15 16 using namespace __sanitizer; 17 using namespace __rtsan; 18 19 // We must define our own implementation of this method for our runtime. 20 // This one is just copied from UBSan. 21 namespace __sanitizer { 22 void BufferedStackTrace::UnwindImpl(uptr pc, uptr bp, void *context, 23 bool request_fast, u32 max_depth) { 24 uptr top = 0; 25 uptr bottom = 0; 26 GetThreadStackTopAndBottom(false, &top, &bottom); 27 bool fast = StackTrace::WillUseFastUnwind(request_fast); 28 Unwind(max_depth, pc, bp, context, top, bottom, fast); 29 } 30 } // namespace __sanitizer 31 32 static void SetGlobalStackTraceFormat() { 33 SetCommonFlagsDefaults(); 34 CommonFlags cf; 35 cf.CopyFrom(*common_flags()); 36 cf.stack_trace_format = "DEFAULT"; 37 cf.external_symbolizer_path = GetEnv("RTSAN_SYMBOLIZER_PATH"); 38 OverrideCommonFlags(cf); 39 } 40 41 void __rtsan::PrintStackTrace() { 42 43 BufferedStackTrace stack{}; 44 45 GET_CURRENT_PC_BP; 46 stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal); 47 48 SetGlobalStackTraceFormat(); 49 stack.Print(); 50 } 51