1 //=-- ubsan_signals_standalone.cc
2 //------------------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 // Installs signal handlers and related interceptors for UBSan standalone.
13 //===----------------------------------------------------------------------===//
15 #include "ubsan_platform.h"
16 #include "sanitizer_common/sanitizer_platform.h"
18 #include "interception/interception.h"
19 #include "sanitizer_common/sanitizer_stacktrace.h"
20 #include "ubsan_diag.h"
21 #include "ubsan_init.h"
23 // Interception of signals breaks too many things on Android.
24 // * It requires that ubsan is the first dependency of the main executable for
25 // the interceptors to work correctly. This complicates deployment, as it
26 // prevents us from enabling ubsan on random platform modules independently.
27 // * For this to work with ART VM, ubsan signal handler has to be set after the
28 // debuggerd handler, but before the ART handler.
29 // * Interceptors don't work at all when ubsan runtime is loaded late, ex. when
30 // it is part of an APK that does not use wrap.sh method.
31 #if SANITIZER_FUCHSIA || SANITIZER_ANDROID
34 void InitializeDeadlySignals() {}
39 #define COMMON_INTERCEPT_FUNCTION(name) INTERCEPT_FUNCTION(name)
40 #include "sanitizer_common/sanitizer_signal_interceptors.inc"
44 static void OnStackUnwind(const SignalContext
&sig
, const void *,
45 BufferedStackTrace
*stack
) {
46 GetStackTrace(stack
, kStackTraceMax
, sig
.pc
, sig
.bp
, sig
.context
,
47 common_flags()->fast_unwind_on_fatal
);
50 static void UBsanOnDeadlySignal(int signo
, void *siginfo
, void *context
) {
51 HandleDeadlySignal(siginfo
, context
, GetTid(), &OnStackUnwind
, nullptr);
54 static bool is_initialized
= false;
56 void InitializeDeadlySignals() {
59 is_initialized
= true;
60 InitializeSignalInterceptors();
61 InstallDeadlySignalHandlers(&UBsanOnDeadlySignal
);
64 } // namespace __ubsan
68 #endif // CAN_SANITIZE_UB