diff --git a/BUILD.gn b/BUILD.gn index 0761edbe6b..876200f03f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3103,8 +3103,6 @@ v8_header_set("v8_internal_headers") { "src/tracing/trace-event.h", "src/tracing/traced-value.h", "src/tracing/tracing-category-observer.h", - "src/trap-handler/trap-handler-internal.h", - "src/trap-handler/trap-handler.h", "src/utils/address-map.h", "src/utils/allocation.h", "src/utils/bit-vector.h", @@ -3152,6 +3150,8 @@ v8_header_set("v8_internal_headers") { "src/compiler/wasm-compiler.h", "src/debug/debug-wasm-objects-inl.h", "src/debug/debug-wasm-objects.h", + "src/trap-handler/trap-handler-internal.h", + "src/trap-handler/trap-handler.h", "src/wasm/baseline/liftoff-assembler-defs.h", "src/wasm/baseline/liftoff-assembler.h", "src/wasm/baseline/liftoff-compiler.h", @@ -3294,16 +3294,19 @@ v8_header_set("v8_internal_headers") { "src/wasm/baseline/x64/liftoff-assembler-x64.h", ] - # iOS Xcode simulator builds run on an x64 target. iOS and macOS are both - # based on Darwin and thus POSIX-compliant to a similar degree. - if (is_linux || is_chromeos || is_mac || is_ios || target_os == "freebsd") { - sources += [ "src/trap-handler/handler-inside-posix.h" ] - } if (is_win) { - sources += [ - "src/diagnostics/unwinding-info-win64.h", - "src/trap-handler/handler-inside-win.h", - ] + sources += [ "src/diagnostics/unwinding-info-win64.h" ] + } + + if (v8_enable_webassembly) { + # iOS Xcode simulator builds run on an x64 target. iOS and macOS are both + # based on Darwin and thus POSIX-compliant to a similar degree. + if (is_linux || is_chromeos || is_mac || is_ios || + target_os == "freebsd") { + sources += [ "src/trap-handler/handler-inside-posix.h" ] + } else if (is_win) { + sources += [ "src/trap-handler/handler-inside-win.h" ] + } } } else if (v8_current_cpu == "arm") { sources += [ ### gcmole(arch:arm) ### @@ -3348,7 +3351,7 @@ v8_header_set("v8_internal_headers") { if (v8_control_flow_integrity) { sources += [ "src/execution/arm64/pointer-authentication-arm64.h" ] } - if (current_cpu == "arm64" && is_mac) { + if (v8_enable_webassembly && current_cpu == "arm64" && is_mac) { sources += [ "src/trap-handler/handler-inside-posix.h" ] } if (is_win) { @@ -4069,9 +4072,6 @@ v8_source_set("v8_base_without_compiler") { "src/tracing/trace-event.cc", "src/tracing/traced-value.cc", "src/tracing/tracing-category-observer.cc", - "src/trap-handler/handler-inside.cc", - "src/trap-handler/handler-outside.cc", - "src/trap-handler/handler-shared.cc", "src/utils/address-map.cc", "src/utils/allocation.cc", "src/utils/bit-vector.cc", @@ -4098,6 +4098,9 @@ v8_source_set("v8_base_without_compiler") { "src/debug/debug-wasm-objects.cc", "src/runtime/runtime-test-wasm.cc", "src/runtime/runtime-wasm.cc", + "src/trap-handler/handler-inside.cc", + "src/trap-handler/handler-outside.cc", + "src/trap-handler/handler-shared.cc", "src/wasm/baseline/liftoff-assembler.cc", "src/wasm/baseline/liftoff-compiler.cc", "src/wasm/function-body-decoder.cc", @@ -4194,20 +4197,25 @@ v8_source_set("v8_base_without_compiler") { "src/regexp/x64/regexp-macro-assembler-x64.cc", ] - # iOS Xcode simulator builds run on an x64 target. iOS and macOS are both - # based on Darwin and thus POSIX-compliant to a similar degree. - if (is_linux || is_chromeos || is_mac || is_ios || target_os == "freebsd") { - sources += [ - "src/trap-handler/handler-inside-posix.cc", - "src/trap-handler/handler-outside-posix.cc", - ] - } if (is_win) { - sources += [ - "src/diagnostics/unwinding-info-win64.cc", - "src/trap-handler/handler-inside-win.cc", - "src/trap-handler/handler-outside-win.cc", - ] + sources += [ "src/diagnostics/unwinding-info-win64.cc" ] + } + + if (v8_enable_webassembly) { + # iOS Xcode simulator builds run on an x64 target. iOS and macOS are both + # based on Darwin and thus POSIX-compliant to a similar degree. + if (is_linux || is_chromeos || is_mac || is_ios || + target_os == "freebsd") { + sources += [ + "src/trap-handler/handler-inside-posix.cc", + "src/trap-handler/handler-outside-posix.cc", + ] + } else if (is_win) { + sources += [ + "src/trap-handler/handler-inside-win.cc", + "src/trap-handler/handler-outside-win.cc", + ] + } } } else if (v8_current_cpu == "arm") { sources += [ ### gcmole(arch:arm) ### @@ -4251,7 +4259,7 @@ v8_source_set("v8_base_without_compiler") { "src/execution/arm64/simulator-logic-arm64.cc", "src/regexp/arm64/regexp-macro-assembler-arm64.cc", ] - if (current_cpu == "arm64" && is_mac) { + if (v8_enable_webassembly && current_cpu == "arm64" && is_mac) { sources += [ "src/trap-handler/handler-inside-posix.cc", "src/trap-handler/handler-outside-posix.cc", diff --git a/src/api/api.cc b/src/api/api.cc index 44f9693b2a..595eb373a1 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -109,11 +109,11 @@ #include "src/strings/string-hasher.h" #include "src/strings/unicode-inl.h" #include "src/tracing/trace-event.h" -#include "src/trap-handler/trap-handler.h" #include "src/utils/detachable-vector.h" #include "src/utils/version.h" #if V8_ENABLE_WEBASSEMBLY +#include "src/trap-handler/trap-handler.h" #include "src/wasm/streaming-decoder.h" #include "src/wasm/value-type.h" #include "src/wasm/wasm-engine.h" @@ -5862,8 +5862,9 @@ bool TryHandleWebAssemblyTrapPosix(int sig_code, siginfo_t* info, // code rather than the wasm code, so the trap handler cannot find the landing // pad and lets the process crash. Therefore, only enable trap handlers if // the host and target arch are the same. -#if (V8_TARGET_ARCH_X64 && !V8_OS_ANDROID) || \ - (V8_HOST_ARCH_ARM64 && V8_TARGET_ARCH_ARM64 && V8_OS_MACOSX) +#if V8_ENABLE_WEBASSEMBLY && \ + ((V8_TARGET_ARCH_X64 && !V8_OS_ANDROID) || \ + (V8_HOST_ARCH_ARM64 && V8_TARGET_ARCH_ARM64 && V8_OS_MACOSX)) return i::trap_handler::TryHandleSignal(sig_code, info, context); #else return false; @@ -5878,15 +5879,20 @@ bool V8::TryHandleSignal(int signum, void* info, void* context) { #if V8_OS_WIN bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS* exception) { -#if V8_TARGET_ARCH_X64 +#if V8_ENABLE_WEBASSEMBLY && V8_TARGET_ARCH_X64 return i::trap_handler::TryHandleWasmTrap(exception); -#endif +#else return false; +#endif } #endif bool V8::EnableWebAssemblyTrapHandler(bool use_v8_signal_handler) { +#if V8_ENABLE_WEBASSEMBLY return v8::internal::trap_handler::EnableTrapHandler(use_v8_signal_handler); +#else + return false; +#endif } #if defined(V8_OS_WIN) diff --git a/src/execution/isolate.cc b/src/execution/isolate.cc index 7ee373d931..1a3ba3ad4f 100644 --- a/src/execution/isolate.cc +++ b/src/execution/isolate.cc @@ -92,7 +92,6 @@ #include "src/strings/string-stream.h" #include "src/tasks/cancelable-task.h" #include "src/tracing/tracing-category-observer.h" -#include "src/trap-handler/trap-handler.h" #include "src/utils/address-map.h" #include "src/utils/ostreams.h" #include "src/utils/version.h" @@ -103,6 +102,7 @@ #endif // V8_INTL_SUPPORT #if V8_ENABLE_WEBASSEMBLY +#include "src/trap-handler/trap-handler.h" #include "src/wasm/wasm-code-manager.h" #include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-module.h" @@ -1582,8 +1582,8 @@ Handle Isolate::CreateMessageOrAbort( Object Isolate::ThrowInternal(Object raw_exception, MessageLocation* location) { DCHECK(!has_pending_exception()); - DCHECK_IMPLIES(trap_handler::IsTrapHandlerEnabled(), - !trap_handler::IsThreadInWasm()); + IF_WASM(DCHECK_IMPLIES, trap_handler::IsTrapHandlerEnabled(), + !trap_handler::IsThreadInWasm()); HandleScope scope(this); Handle exception(raw_exception, this); @@ -1678,6 +1678,7 @@ Object Isolate::ReThrow(Object exception) { } namespace { +#if V8_ENABLE_WEBASSEMBLY // This scope will set the thread-in-wasm flag after the execution of all // destructors. The thread-in-wasm flag is only set when the scope gets enabled. class SetThreadInWasmFlagScope { @@ -1696,9 +1697,11 @@ class SetThreadInWasmFlagScope { private: bool enabled_ = false; }; +#endif // V8_ENABLE_WEBASSEMBLY } // namespace Object Isolate::UnwindAndFindHandler() { +#if V8_ENABLE_WEBASSEMBLY // Create the {SetThreadInWasmFlagScope} first in this function so that its // destructor gets called after all the other destructors. It is important // that the destructor sets the thread-in-wasm flag after all other @@ -1706,6 +1709,7 @@ Object Isolate::UnwindAndFindHandler() { // Windows, which would invalidate the thread-in-wasm flag when the wasm trap // handler handles such non-wasm exceptions. SetThreadInWasmFlagScope set_thread_in_wasm_flag_scope; +#endif // V8_ENABLE_WEBASSEMBLY Object exception = pending_exception(); auto FoundHandler = [&](Context context, Address instruction_start, diff --git a/src/execution/thread-local-top.cc b/src/execution/thread-local-top.cc index 4af5dc6407..64962c8a84 100644 --- a/src/execution/thread-local-top.cc +++ b/src/execution/thread-local-top.cc @@ -42,8 +42,10 @@ void ThreadLocalTop::Initialize(Isolate* isolate) { Clear(); isolate_ = isolate; thread_id_ = ThreadId::Current(); +#if V8_ENABLE_WEBASSEMBLY thread_in_wasm_flag_address_ = reinterpret_cast
( trap_handler::GetThreadInWasmThreadLocalAddress()); +#endif // V8_ENABLE_WEBASSEMBLY #ifdef USE_SIMULATOR simulator_ = Simulator::current(isolate); #endif diff --git a/src/objects/backing-store.cc b/src/objects/backing-store.cc index a1826a3022..89bb17b03a 100644 --- a/src/objects/backing-store.cc +++ b/src/objects/backing-store.cc @@ -10,9 +10,9 @@ #include "src/execution/isolate.h" #include "src/handles/global-handles.h" #include "src/logging/counters.h" -#include "src/trap-handler/trap-handler.h" #if V8_ENABLE_WEBASSEMBLY +#include "src/trap-handler/trap-handler.h" #include "src/wasm/wasm-constants.h" #include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-limits.h" @@ -349,7 +349,12 @@ std::unique_ptr BackingStore::TryAllocateAndPartiallyCommitMemory( TRACE_BS("BSw:try %zu pages, %zu max\n", initial_pages, maximum_pages); +#if V8_ENABLE_WEBASSEMBLY bool guards = is_wasm_memory && trap_handler::IsTrapHandlerEnabled(); +#else + CHECK(!is_wasm_memory); + bool guards = false; +#endif // V8_ENABLE_WEBASSEMBLY // For accounting purposes, whether a GC was necessary. bool did_retry = false; diff --git a/test/cctest/cctest.cc b/test/cctest/cctest.cc index 3e5b87e863..195ef93291 100644 --- a/test/cctest/cctest.cc +++ b/test/cctest/cctest.cc @@ -341,12 +341,12 @@ int main(int argc, char* argv[]) { v8::V8::Initialize(); v8::V8::InitializeExternalStartupData(argv[0]); -#if V8_ENABLE_WEBASSEMBLY - if (V8_TRAP_HANDLER_SUPPORTED && i::FLAG_wasm_trap_handler) { +#if V8_ENABLE_WEBASSEMBLY && V8_TRAP_HANDLER_SUPPORTED + if (i::FLAG_wasm_trap_handler) { constexpr bool use_default_signal_handler = true; CHECK(v8::V8::EnableWebAssemblyTrapHandler(use_default_signal_handler)); } -#endif // V8_ENABLE_WEBASSEMBLY +#endif // V8_TRAP_HANDLER_SUPPORTED && V8_ENABLE_WEBASSEMBLY CcTest::set_array_buffer_allocator( v8::ArrayBuffer::Allocator::NewDefaultAllocator());