chromium/v8/src/trap-handler/handler-inside-posix.cc

// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// PLEASE READ BEFORE CHANGING THIS FILE!
//
// This file implements the out of bounds signal handler for
// WebAssembly. Signal handlers are notoriously difficult to get
// right, and getting it wrong can lead to security
// vulnerabilities. In order to minimize this risk, here are some
// rules to follow.
//
// 1. Do not introduce any new external dependencies. This file needs
//    to be self contained so it is easy to audit everything that a
//    signal handler might do.
//
// 2. Any changes must be reviewed by someone from the crash reporting
//    or security team. See OWNERS for suggested reviewers.
//
// For more information, see https://goo.gl/yMeyUY.
//
// This file contains most of the code that actually runs in a signal handler
// context. Some additional code is used both inside and outside the signal
// handler. This code can be found in handler-shared.cc.

#include "src/trap-handler/handler-inside-posix.h"

#include <signal.h>

#if defined(V8_OS_LINUX) || defined(V8_OS_FREEBSD)
#include <ucontext.h>
#elif V8_OS_DARWIN
#include <sys/ucontext.h>
#endif

#include <stddef.h>
#include <stdlib.h>

#include "src/trap-handler/trap-handler-internal.h"
#include "src/trap-handler/trap-handler.h"

#ifdef V8_TRAP_HANDLER_VIA_SIMULATOR
#include "src/trap-handler/trap-handler-simulator.h"
#endif

namespace v8 {
namespace internal {
namespace trap_handler {

#if V8_TRAP_HANDLER_SUPPORTED

#if V8_OS_LINUX && V8_HOST_ARCH_ARM64
#define CONTEXT_REG
#elif V8_OS_LINUX && (V8_HOST_ARCH_LOONG64 || V8_HOST_ARCH_RISCV64)
#define CONTEXT_REG
#elif V8_OS_LINUX
#define CONTEXT_REG(reg, REG)
#elif V8_OS_DARWIN && V8_HOST_ARCH_ARM64
#define CONTEXT_REG
#elif V8_OS_DARWIN
#define CONTEXT_REG
#elif V8_OS_FREEBSD
#define CONTEXT_REG
#else
#error "Unsupported platform."
#endif

#if V8_OS_LINUX && V8_HOST_ARCH_ARM64
#define CONTEXT_PC
#elif V8_OS_DARWIN && V8_HOST_ARCH_ARM64
#define CONTEXT_PC
#elif V8_OS_LINUX && V8_HOST_ARCH_LOONG64
#define CONTEXT_PC
#elif V8_OS_LINUX && V8_HOST_ARCH_RISCV64
#define CONTEXT_PC
#endif

bool IsKernelGeneratedSignal(siginfo_t* info) {}

class UnmaskOobSignalScope {};

#ifdef V8_TRAP_HANDLER_VIA_SIMULATOR
// This is the address where we continue on a failed "ProbeMemory". It's defined
// in "handler-outside-simulator.cc".
extern char probe_memory_continuation[]
#if V8_OS_DARWIN
    asm("_v8_simulator_probe_memory_continuation");
#else
    asm("v8_simulator_probe_memory_continuation");
#endif
#endif  // V8_TRAP_HANDLER_VIA_SIMULATOR

bool TryHandleSignal(int signum, siginfo_t* info, void* context) {}

void HandleSignal(int signum, siginfo_t* info, void* context) {}

#endif

}  // namespace trap_handler
}  // namespace internal
}  // namespace v8