[trap-handler] Rename ProbeMemory

The "ProbeMemory" functions starts showing up on stack traces for random
illegal memory accesses hit by the arm64 simulator (see e.g.
https://crbug.com/1408957 or https://crbug.com/1409124).
Thus specify an explicit symbol name that will make it easier to see
that this is a v8-internal symbol related to the simulator.

R=mseaborn@chromium.org

Change-Id: If5753170cfee399aa59b11cfcd82314589990192
Cq-Include-Trybots: luci.v8.try:v8_mac_arm64_sim_rel
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4200630
Reviewed-by: Mark Mentovai <mark@chromium.org>
Reviewed-by: Mark Seaborn <mseaborn@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#85641}
This commit is contained in:
Clemens Backes 2023-02-03 07:44:31 +01:00 committed by V8 LUCI CQ
parent 8f93980acc
commit a6966097a0
4 changed files with 34 additions and 22 deletions

View File

@ -91,7 +91,12 @@ 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 "C" char v8_probe_memory_continuation[];
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) {
@ -149,7 +154,7 @@ bool TryHandleSignal(int signum, siginfo_t* info, void* context) {
auto* return_reg = CONTEXT_REG(rax, RAX);
*return_reg = landing_pad;
// Continue at the memory probing continuation.
*context_ip = reinterpret_cast<uintptr_t>(&v8_probe_memory_continuation);
*context_ip = reinterpret_cast<uintptr_t>(&probe_memory_continuation);
#else
if (!TryFindLandingPad(fault_addr, &landing_pad)) return false;

View File

@ -58,7 +58,8 @@ struct TEB {
#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 "C" char v8_probe_memory_continuation[];
extern char probe_memory_continuation[] asm(
"v8_simulator_probe_memory_continuation");
#endif // V8_TRAP_HANDLER_VIA_SIMULATOR
bool TryHandleWasmTrap(EXCEPTION_POINTERS* exception) {
@ -112,7 +113,7 @@ bool TryHandleWasmTrap(EXCEPTION_POINTERS* exception) {
exception->ContextRecord->Rax = landing_pad;
// Continue at the memory probing continuation.
exception->ContextRecord->Rip =
reinterpret_cast<uintptr_t>(&v8_probe_memory_continuation);
reinterpret_cast<uintptr_t>(&probe_memory_continuation);
#else
if (!TryFindLandingPad(fault_addr, &landing_pad)) return false;

View File

@ -14,29 +14,29 @@
#define SYMBOL(name) #name
#endif // !V8_OS_DARWIN
// Define the ProbeMemory function declared in trap-handler-simulators.h.
asm(
".globl " SYMBOL(ProbeMemory) " \n"
SYMBOL(ProbeMemory) ": \n"
// Define the v8::internal::trap_handler::ProbeMemory function declared in
// trap-handler-simulators.h.
asm(".globl " SYMBOL(v8_internal_simulator_ProbeMemory) " \n"
SYMBOL(v8_internal_simulator_ProbeMemory) ": \n"
// First parameter (address) passed in %rdi on Linux/Mac, and %rcx on Windows.
// The second parameter (pc) is unused here. It is read by the trap handler
// instead.
#if V8_OS_WIN
" movb (%rcx), %al \n"
" movb (%rcx), %al \n"
#else
" movb (%rdi), %al \n"
" movb (%rdi), %al \n"
#endif // V8_OS_WIN
// Return 0 on success.
" xorl %eax, %eax \n"
" xorl %eax, %eax \n"
// Place an additional "ret" here instead of falling through to the one
// below, because (some) toolchain(s) on Mac set ".subsections_via_symbols",
// which can cause the "ret" below to be placed elsewhere. An alternative
// prevention would be to add ".alt_entry" (see
// https://reviews.llvm.org/D79926), but just adding a "ret" is simpler.
" ret \n"
".globl " SYMBOL(v8_probe_memory_continuation) "\n"
SYMBOL(v8_probe_memory_continuation) ": \n"
" ret \n"
".globl " SYMBOL(v8_simulator_probe_memory_continuation) " \n"
SYMBOL(v8_simulator_probe_memory_continuation) ": \n"
// If the trap handler continues here, it wrote the landing pad in %rax.
" ret \n");
" ret \n");
#endif

View File

@ -7,6 +7,8 @@
#include <cstdint>
#include "include/v8config.h"
// This header defines the ProbeMemory function to be used by simulators to
// trigger a signal at a defined location, before doing an actual memory access.
@ -16,9 +18,7 @@
#error "Do only include this file on simulator builds on x64."
#endif
namespace v8 {
namespace internal {
namespace trap_handler {
namespace v8::internal::trap_handler {
// Probe a memory address by doing a 1-byte read from the given address. If the
// address is not readable, this will cause a trap as usual, but the trap
@ -28,10 +28,16 @@ namespace trap_handler {
// is not registered as a protected instruction, the signal will be propagated
// as usual.
// If the read at {address} succeeds, this function returns {0} instead.
extern "C" uintptr_t ProbeMemory(uintptr_t address, uintptr_t pc);
uintptr_t ProbeMemory(uintptr_t address, uintptr_t pc)
// Specify an explicit symbol name (defined in
// handler-outside-simulator.cc). Just {extern "C"} would produce
// "ProbeMemory", but we want something more expressive on stack traces.
#if V8_OS_DARWIN
asm("_v8_internal_simulator_ProbeMemory");
#else
asm("v8_internal_simulator_ProbeMemory");
#endif
} // namespace trap_handler
} // namespace internal
} // namespace v8
} // namespace v8::internal::trap_handler
#endif // V8_TRAP_HANDLER_TRAP_HANDLER_SIMULATOR_H_