Only use __float128 in test if available
[official-gcc.git] / libsanitizer / ubsan / ubsan_signals_standalone.cc
blob5e77c60b1dbb53e0d8c1d954f99bc54182941b3b
1 //=-- ubsan_signals_standalone.cc
2 //------------------------------------------------===//
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
11 // Installs signal handlers and related interceptors for UBSan standalone.
13 //===----------------------------------------------------------------------===//
15 #include "ubsan_platform.h"
16 #include "sanitizer_common/sanitizer_platform.h"
17 #if CAN_SANITIZE_UB
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
33 namespace __ubsan {
34 void InitializeDeadlySignals() {}
37 #else
39 #define COMMON_INTERCEPT_FUNCTION(name) INTERCEPT_FUNCTION(name)
40 #include "sanitizer_common/sanitizer_signal_interceptors.inc"
42 namespace __ubsan {
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() {
57 if (is_initialized)
58 return;
59 is_initialized = true;
60 InitializeSignalInterceptors();
61 InstallDeadlySignalHandlers(&UBsanOnDeadlySignal);
64 } // namespace __ubsan
66 #endif
68 #endif // CAN_SANITIZE_UB