#ifndef V8_TRAP_HANDLER_TRAP_HANDLER_H_
#define V8_TRAP_HANDLER_TRAP_HANDLER_H_
#include <stdint.h>
#include <stdlib.h>
#include <atomic>
#include "include/v8config.h"
#include "src/base/immediate-crash.h"
namespace v8 {
namespace internal {
namespace trap_handler {
#if V8_HOST_ARCH_X64 && V8_TARGET_ARCH_X64 && \
((V8_OS_LINUX && !V8_OS_ANDROID) || V8_OS_WIN || V8_OS_DARWIN || \
V8_OS_FREEBSD)
#define V8_TRAP_HANDLER_SUPPORTED …
#elif V8_TARGET_ARCH_ARM64 && V8_HOST_ARCH_ARM64 && \
(V8_OS_DARWIN || (V8_OS_LINUX && !V8_OS_ANDROID))
#define V8_TRAP_HANDLER_SUPPORTED …
#elif V8_TARGET_ARCH_ARM64 && V8_HOST_ARCH_X64 && \
(V8_OS_LINUX || V8_OS_DARWIN || V8_OS_WIN) && \
(!defined(_MSC_VER) || defined(__clang__))
#define V8_TRAP_HANDLER_VIA_SIMULATOR
#define V8_TRAP_HANDLER_SUPPORTED …
#elif V8_TARGET_ARCH_LOONG64 && V8_HOST_ARCH_LOONG64 && V8_OS_LINUX
#define V8_TRAP_HANDLER_SUPPORTED …
#elif V8_TARGET_ARCH_LOONG64 && V8_HOST_ARCH_X64 && V8_OS_LINUX
#define V8_TRAP_HANDLER_VIA_SIMULATOR
#define V8_TRAP_HANDLER_SUPPORTED …
#elif V8_TARGET_ARCH_RISCV64 && V8_HOST_ARCH_RISCV64 && V8_OS_LINUX && \
!V8_OS_ANDROID
#define V8_TRAP_HANDLER_SUPPORTED …
#elif V8_TARGET_ARCH_RISCV64 && V8_HOST_ARCH_X64 && V8_OS_LINUX
#define V8_TRAP_HANDLER_VIA_SIMULATOR
#define V8_TRAP_HANDLER_SUPPORTED …
#else
#define V8_TRAP_HANDLER_SUPPORTED …
#endif
#if V8_OS_ANDROID && V8_TRAP_HANDLER_SUPPORTED
#error "The V8 trap handler should not be enabled on Android"
#endif
#if defined(BUILDING_V8_SHARED_PRIVATE) && defined(V8_OS_WIN)
#define TH_EXPORT_PRIVATE …
#elif defined(BUILDING_V8_SHARED_PRIVATE)
#define TH_EXPORT_PRIVATE …
#elif defined(USING_V8_SHARED_PRIVATE) && defined(V8_OS_WIN)
#define TH_EXPORT_PRIVATE …
#else
#define TH_EXPORT_PRIVATE
#endif
#define TH_CHECK(condition) …
#ifdef DEBUG
#define TH_DCHECK(condition) …
#else
#define TH_DCHECK …
#endif
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define TH_DISABLE_ASAN …
#else
#define TH_DISABLE_ASAN
#endif
#else
#define TH_DISABLE_ASAN
#endif
struct ProtectedInstructionData { … };
const int kInvalidIndex = …;
int TH_EXPORT_PRIVATE RegisterHandlerData(
uintptr_t base, size_t size, size_t num_protected_instructions,
const ProtectedInstructionData* protected_instructions);
void TH_EXPORT_PRIVATE ReleaseHandlerData(int index);
void TH_EXPORT_PRIVATE SetV8SandboxBaseAndSize(uintptr_t base, size_t size);
TH_EXPORT_PRIVATE extern bool g_is_trap_handler_enabled;
TH_EXPORT_PRIVATE extern std::atomic<bool> g_can_enable_trap_handler;
TH_EXPORT_PRIVATE bool EnableTrapHandler(bool use_v8_handler);
TH_EXPORT_PRIVATE void SetLandingPad(uintptr_t landing_pad);
inline bool IsTrapHandlerEnabled() { … }
#if defined(V8_OS_AIX)
extern __thread int g_thread_in_wasm_code;
#else
extern thread_local int g_thread_in_wasm_code;
#endif
V8_NOINLINE TH_EXPORT_PRIVATE int* GetThreadInWasmThreadLocalAddress();
TH_DISABLE_ASAN inline bool IsThreadInWasm() { … }
inline void SetThreadInWasm() { … }
inline void ClearThreadInWasm() { … }
bool RegisterDefaultTrapHandler();
TH_EXPORT_PRIVATE void RemoveTrapHandler();
TH_EXPORT_PRIVATE size_t GetRecoveredTrapCount();
}
}
}
#endif