Skip to content

Commit cee178f

Browse files
paolosevMSFTV8 LUCI CQ
authored andcommitted
[wasm] Enable trap handling on ARM64 Windows
Improve the speed of Wasm on Windows/ARM64 by enabling bounds-checking via trap-handling. Change-Id: I85a6cb59d8482d19f409515e26e641d333bf7b90 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5824747 Commit-Queue: Paolo Severini <[email protected]> Reviewed-by: Mark Mentovai <[email protected]> Reviewed-by: Andreas Haas <[email protected]> Cr-Commit-Position: refs/heads/main@{#96606}
1 parent aef0dd0 commit cee178f

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

BUILD.gn

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6071,15 +6071,14 @@ v8_source_set("v8_base_without_compiler") {
60716071
"src/regexp/arm64/regexp-macro-assembler-arm64.cc",
60726072
]
60736073
if (v8_enable_webassembly) {
6074-
# Trap handling is enabled on arm64 Mac and Linux and in simulators on
6075-
# x64 on Linux, Mac, and Windows.
6074+
# Trap handling is enabled on arm64 and x64, on Linux, Mac and Windows.
60766075
if ((current_cpu == "arm64" && (is_linux || is_chromeos || is_apple)) ||
60776076
(current_cpu == "x64" && (is_linux || is_chromeos || is_mac))) {
60786077
sources += [
60796078
"src/trap-handler/handler-inside-posix.cc",
60806079
"src/trap-handler/handler-outside-posix.cc",
60816080
]
6082-
} else if (current_cpu == "x64" && is_win) {
6081+
} else if ((current_cpu == "arm64" || current_cpu == "x64") && is_win) {
60836082
sources += [
60846083
"src/trap-handler/handler-inside-win.cc",
60856084
"src/trap-handler/handler-outside-win.cc",

src/trap-handler/handler-inside-win.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,16 @@ bool TryHandleWasmTrap(EXCEPTION_POINTERS* exception) {
119119

120120
TH_DCHECK(gLandingPad != 0);
121121
// Tell the caller to return to the landing pad.
122+
#if V8_HOST_ARCH_X64
122123
exception->ContextRecord->Rip = gLandingPad;
123124
exception->ContextRecord->R10 = fault_addr;
124-
#endif
125+
#elif V8_HOST_ARCH_ARM64
126+
exception->ContextRecord->Pc = gLandingPad;
127+
exception->ContextRecord->X16 = fault_addr;
128+
#else
129+
#error Unsupported architecture
130+
#endif // V8_HOST_ARCH_X64
131+
#endif // V8_TRAP_HANDLER_VIA_SIMULATOR
125132
// We will return to wasm code, so restore the g_thread_in_wasm_code flag.
126133
g_thread_in_wasm_code = true;
127134
return true;

src/trap-handler/trap-handler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ namespace trap_handler {
2222
((V8_OS_LINUX && !V8_OS_ANDROID) || V8_OS_WIN || V8_OS_DARWIN || \
2323
V8_OS_FREEBSD)
2424
#define V8_TRAP_HANDLER_SUPPORTED true
25-
// Arm64 (non-simulator) on Mac and Linux.
25+
// Arm64 (non-simulator) on Linux, Windows, MacOS.
2626
#elif V8_TARGET_ARCH_ARM64 && V8_HOST_ARCH_ARM64 && \
27-
(V8_OS_DARWIN || (V8_OS_LINUX && !V8_OS_ANDROID))
27+
((V8_OS_LINUX && !V8_OS_ANDROID) || V8_OS_WIN || V8_OS_DARWIN)
2828
#define V8_TRAP_HANDLER_SUPPORTED true
2929
// Arm64 simulator on x64 on Linux, Mac, or Windows.
3030
//

test/unittests/wasm/trap-handler-native-unittest.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
#if V8_TRAP_HANDLER_SUPPORTED
3737

38-
#if V8_HOST_ARCH_ARM64 && (!V8_OS_LINUX && !V8_OS_DARWIN)
38+
#if V8_HOST_ARCH_ARM64 && (!V8_OS_LINUX && !V8_OS_DARWIN && !V8_OS_WIN)
3939
#error Unsupported platform
4040
#endif
4141

@@ -247,7 +247,13 @@ class TrapHandlerTest : public TestWithIsolate,
247247
RemoveVectoredExceptionHandler(g_registered_handler);
248248
g_registered_handler = nullptr;
249249
g_test_handler_executed = true;
250+
#if V8_HOST_ARCH_X64
250251
exception->ContextRecord->Rip = g_recovery_address;
252+
#elif V8_HOST_ARCH_ARM64
253+
exception->ContextRecord->Pc = g_recovery_address;
254+
#else
255+
#error Unsupported architecture
256+
#endif // V8_HOST_ARCH_X64
251257
return EXCEPTION_CONTINUE_EXECUTION;
252258
}
253259
#endif

0 commit comments

Comments
 (0)