2017-09-23 10:47:11 +08:00
|
|
|
//=-- ubsan_signals_standalone.cc
|
|
|
|
//------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-09-23 10:47:11 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Installs signal handlers and related interceptors for UBSan standalone.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ubsan_platform.h"
|
2018-01-23 03:26:01 +08:00
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
2017-09-23 10:47:11 +08:00
|
|
|
#if CAN_SANITIZE_UB
|
|
|
|
#include "interception/interception.h"
|
|
|
|
#include "sanitizer_common/sanitizer_stacktrace.h"
|
|
|
|
#include "ubsan_diag.h"
|
|
|
|
#include "ubsan_init.h"
|
|
|
|
|
2018-01-23 03:26:01 +08:00
|
|
|
// Interception of signals breaks too many things on Android.
|
|
|
|
// * It requires that ubsan is the first dependency of the main executable for
|
|
|
|
// the interceptors to work correctly. This complicates deployment, as it
|
|
|
|
// prevents us from enabling ubsan on random platform modules independently.
|
|
|
|
// * For this to work with ART VM, ubsan signal handler has to be set after the
|
|
|
|
// debuggerd handler, but before the ART handler.
|
|
|
|
// * Interceptors don't work at all when ubsan runtime is loaded late, ex. when
|
|
|
|
// it is part of an APK that does not use wrap.sh method.
|
|
|
|
#if SANITIZER_FUCHSIA || SANITIZER_ANDROID
|
|
|
|
|
|
|
|
namespace __ubsan {
|
|
|
|
void InitializeDeadlySignals() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-09-23 10:47:11 +08:00
|
|
|
#define COMMON_INTERCEPT_FUNCTION(name) INTERCEPT_FUNCTION(name)
|
|
|
|
#include "sanitizer_common/sanitizer_signal_interceptors.inc"
|
|
|
|
|
2019-03-01 02:42:14 +08:00
|
|
|
// TODO(yln): Temporary workaround. Will be removed.
|
|
|
|
void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth,
|
|
|
|
uptr pc, uptr bp, void *context, bool fast);
|
|
|
|
|
2017-09-23 10:47:11 +08:00
|
|
|
namespace __ubsan {
|
|
|
|
|
|
|
|
static void OnStackUnwind(const SignalContext &sig, const void *,
|
|
|
|
BufferedStackTrace *stack) {
|
2019-03-01 02:42:14 +08:00
|
|
|
ubsan_GetStackTrace(stack, kStackTraceMax, sig.pc, sig.bp, sig.context,
|
2017-11-09 15:53:06 +08:00
|
|
|
common_flags()->fast_unwind_on_fatal);
|
2017-09-23 10:47:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void UBsanOnDeadlySignal(int signo, void *siginfo, void *context) {
|
|
|
|
HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_initialized = false;
|
|
|
|
|
|
|
|
void InitializeDeadlySignals() {
|
|
|
|
if (is_initialized)
|
|
|
|
return;
|
|
|
|
is_initialized = true;
|
|
|
|
InitializeSignalInterceptors();
|
|
|
|
InstallDeadlySignalHandlers(&UBsanOnDeadlySignal);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __ubsan
|
|
|
|
|
2018-01-23 03:26:01 +08:00
|
|
|
#endif
|
|
|
|
|
2017-09-23 10:47:11 +08:00
|
|
|
#endif // CAN_SANITIZE_UB
|