blob: 2c91db8ca3974841a2314b86a97b6d259c9e0d9c [file] [log] [blame]
//=-- ubsan_signals_standalone.cpp ----------------------------------------===//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// Installs signal handlers and related interceptors for UBSan standalone.
#include "ubsan_platform.h"
#include "sanitizer_common/sanitizer_platform.h"
#include "interception/interception.h"
#include "sanitizer_common/sanitizer_stacktrace.h"
#include "ubsan_diag.h"
#include "ubsan_init.h"
// 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 method.
namespace __ubsan {
void InitializeDeadlySignals() {}
#include "sanitizer_common/"
// TODO(yln): Temporary workaround. Will be removed.
void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth,
uptr pc, uptr bp, void *context, bool fast);
namespace __ubsan {
static void OnStackUnwind(const SignalContext &sig, const void *,
BufferedStackTrace *stack) {
ubsan_GetStackTrace(stack, kStackTraceMax,
StackTrace::GetNextInstructionPc(sig.pc), sig.bp,
sig.context, common_flags()->fast_unwind_on_fatal);
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)
is_initialized = true;
} // namespace __ubsan