xref: /freebsd/contrib/llvm-project/compiler-rt/lib/ubsan/ubsan_diag_standalone.cpp (revision b4e38a41f584ad4391c04b8cfec81f46176b18b0)
1 //===-- ubsan_diag_standalone.cpp -----------------------------------------===//
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 // Diagnostic reporting for the standalone UBSan runtime.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "ubsan_platform.h"
14 #if CAN_SANITIZE_UB
15 #include "ubsan_diag.h"
16 
17 using namespace __ubsan;
18 
19 void __sanitizer::BufferedStackTrace::UnwindImpl(
20     uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) {
21   uptr top = 0;
22   uptr bottom = 0;
23   if (StackTrace::WillUseFastUnwind(request_fast)) {
24     GetThreadStackTopAndBottom(false, &top, &bottom);
25     Unwind(max_depth, pc, bp, nullptr, top, bottom, true);
26   } else
27     Unwind(max_depth, pc, bp, context, 0, 0, false);
28 }
29 
30 extern "C" {
31 SANITIZER_INTERFACE_ATTRIBUTE
32 void __sanitizer_print_stack_trace() {
33   GET_CURRENT_PC_BP;
34   BufferedStackTrace stack;
35   stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal);
36   stack.Print();
37 }
38 } // extern "C"
39 
40 #endif  // CAN_SANITIZE_UB
41