Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions bazel/external/wee8.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 1. Fix linking with unbundled toolchain on macOS.
# 2. Increase VSZ limit to 64 TiB (allows us to start up to 6,553 VMs).
# 3. Fix building and linking with MSAN.
# TODO(PiotrSikora): remove when not needed anymore (most likely in v9.2 branch):
# 4. Fix "thread_in_wasm flag was not set" crash in debug builds (https://chromium-review.googlesource.com/c/v8/v8/+/2817598, https://chromium-review.googlesource.com/c/v8/v8/+/2867468).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes listed are part of the diff below. LGTM!

--- wee8/build/toolchain/gcc_toolchain.gni
+++ wee8/build/toolchain/gcc_toolchain.gni
@@ -348,6 +348,8 @@ template("gcc_toolchain") {
Expand Down Expand Up @@ -67,3 +69,80 @@
# Pass the same C/C++ flags to the objective C/C++ compiler.
cflags_objc += cflags_c
cflags_objcc += cflags_cc
--- wee8/src/execution/isolate.cc
+++ wee8/src/execution/isolate.cc
@@ -1672,10 +1672,36 @@ Object Isolate::ReThrow(Object exception) {
return ReadOnlyRoots(heap()).exception();
}

+namespace {
+// 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 {
+ public:
+ SetThreadInWasmFlagScope() {
+ DCHECK_IMPLIES(trap_handler::IsTrapHandlerEnabled(),
+ !trap_handler::IsThreadInWasm());
+ }
+
+ ~SetThreadInWasmFlagScope() {
+ if (enabled_) trap_handler::SetThreadInWasm();
+ }
+
+ void Enable() { enabled_ = true; }
+
+ private:
+ bool enabled_ = false;
+};
+} // namespace
+
Object Isolate::UnwindAndFindHandler() {
+ // 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
+ // destructors. The other destructors may cause exceptions, e.g. ASan on
+ // 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;
Object exception = pending_exception();
- DCHECK_IMPLIES(trap_handler::IsTrapHandlerEnabled(),
- !trap_handler::IsThreadInWasm());

auto FoundHandler = [&](Context context, Address instruction_start,
intptr_t handler_offset,
@@ -1768,9 +1794,10 @@ Object Isolate::UnwindAndFindHandler() {
StandardFrameConstants::kFixedFrameSizeAboveFp -
wasm_code->stack_slots() * kSystemPointerSize;

- // This is going to be handled by Wasm, so we need to set the TLS flag.
- trap_handler::SetThreadInWasm();
-
+ // This is going to be handled by WebAssembly, so we need to set the TLS
+ // flag. The {SetThreadInWasmFlagScope} will set the flag after all
+ // destructors have been executed.
+ set_thread_in_wasm_flag_scope.Enable();
return FoundHandler(Context(), wasm_code->instruction_start(), offset,
wasm_code->constant_pool(), return_sp, frame->fp());
}
--- wee8/src/compiler/wasm-compiler.cc
+++ wee8/src/compiler/wasm-compiler.cc
@@ -7030,6 +7030,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {

BuildModifyThreadInWasmFlag(true);

+ Node* old_effect = effect();
Node* exception_branch = graph()->NewNode(
mcgraph()->common()->Branch(BranchHint::kTrue),
gasm_->WordEqual(return_value, mcgraph()->IntPtrConstant(0)),
@@ -7046,9 +7047,8 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
gasm_->Call(call_descriptor, call_target, return_value);
TerminateThrow(effect(), control());

- SetEffectControl(
- return_value,
- graph()->NewNode(mcgraph()->common()->IfTrue(), exception_branch));
+ SetEffectControl(old_effect, graph()->NewNode(mcgraph()->common()->IfTrue(),
+ exception_branch));
DCHECK_LT(sig_->return_count(), wasm::kV8MaxWasmFunctionMultiReturns);
size_t return_count = sig_->return_count();
if (return_count == 0) {