Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Unified Diff: src/compiler/wasm-compiler.cc

Issue 2371833007: [wasm] Initial signal handler (Closed)
Patch Set: Make sure guard pages get set up when resizing from 0 to more than 0 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/api.cc ('k') | src/compiler/x64/code-generator-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/wasm-compiler.cc
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc
index 5660b71c173ef9d54272956c681f99b51ea0d9c0..e275b532edd7a5db5fb8b7e7bb039af5d3dfddde 100644
--- a/src/compiler/wasm-compiler.cc
+++ b/src/compiler/wasm-compiler.cc
@@ -111,13 +111,6 @@ Node* BuildCallToRuntime(Runtime::FunctionId f, JSGraph* jsgraph,
} // namespace
-// TODO(eholk): Support trap handlers on other platforms.
-#if V8_TARGET_ARCH_X64 && V8_OS_LINUX
-const bool kTrapHandlerSupported = true;
-#else
-const bool kTrapHandlerSupported = false;
-#endif
-
// A helper that handles building graph fragments for trapping.
// To avoid generating a ton of redundant code that just calls the runtime
// to trap, we generate a per-trap-reason block of code that all trap sites
@@ -2807,6 +2800,15 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
args[pos++] = wasm_param;
}
+ // Set the ThreadInWasm flag before we do the actual call.
+ if (trap_handler::UseTrapHandler()) {
+ // TODO(eholk): Set the flag directly without a runtime call. We should be
+ // able to store directly to a location in the isolate (later TLS) that sets
+ // the g_thread_in_wasm_code flag.
+ BuildCallToRuntime(Runtime::kSetThreadInWasm, jsgraph(), nullptr, 0,
+ effect_, *control_);
+ }
+
args[pos++] = *effect_;
args[pos++] = *control_;
@@ -2816,6 +2818,16 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), count, args);
*effect_ = call;
+
+ // Clear the ThreadInWasmFlag
+ if (trap_handler::UseTrapHandler()) {
+ // TODO(eholk): Set the flag directly without a runtime call. We should be
+ // able to store directly to a location in the isolate (later TLS) that sets
+ // the g_thread_in_wasm_code flag.
+ BuildCallToRuntime(Runtime::kClearThreadInWasm, jsgraph(), nullptr, 0,
+ effect_, *control_);
+ }
+
Node* retval = call;
Node* jsval = ToJS(
retval, sig->return_count() == 0 ? wasm::kWasmStmt : sig->GetReturn());
@@ -2862,6 +2874,11 @@ void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target,
Node* call;
bool direct_call = false;
+ if (trap_handler::UseTrapHandler()) {
+ BuildCallToRuntime(Runtime::kClearThreadInWasm, jsgraph(), nullptr, 0,
+ effect_, *control_);
+ }
+
if (target->IsJSFunction()) {
Handle<JSFunction> function = Handle<JSFunction>::cast(target);
if (function->shared()->internal_formal_parameter_count() == wasm_count) {
@@ -2926,6 +2943,11 @@ void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target,
*effect_ = call;
SetSourcePosition(call, 0);
+ if (trap_handler::UseTrapHandler()) {
+ BuildCallToRuntime(Runtime::kSetThreadInWasm, jsgraph(), nullptr, 0,
+ effect_, *control_);
+ }
+
// Convert the return value back.
Node* i32_zero = jsgraph()->Int32Constant(0);
Node* val = sig->return_count() == 0
@@ -3195,7 +3217,7 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
Node* load;
// WASM semantics throw on OOB. Introduce explicit bounds check.
- if (!FLAG_wasm_trap_handler || !kTrapHandlerSupported) {
+ if (!FLAG_wasm_trap_handler || !V8_TRAP_HANDLER_SUPPORTED) {
BoundsCheckMem(memtype, index, offset, position);
}
bool aligned = static_cast<int>(alignment) >=
@@ -3203,7 +3225,7 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
if (aligned ||
jsgraph()->machine()->UnalignedLoadSupported(memtype, alignment)) {
- if (FLAG_wasm_trap_handler && kTrapHandlerSupported) {
+ if (FLAG_wasm_trap_handler && V8_TRAP_HANDLER_SUPPORTED) {
DCHECK(FLAG_wasm_guard_pages);
Node* position_node = jsgraph()->Int32Constant(position);
load = graph()->NewNode(jsgraph()->machine()->ProtectedLoad(memtype),
@@ -3215,7 +3237,7 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
}
} else {
// TODO(eholk): Support unaligned loads with trap handlers.
- DCHECK(!FLAG_wasm_trap_handler || !kTrapHandlerSupported);
+ DCHECK(!FLAG_wasm_trap_handler || !V8_TRAP_HANDLER_SUPPORTED);
load = graph()->NewNode(jsgraph()->machine()->UnalignedLoad(memtype),
MemBuffer(offset), index, *effect_, *control_);
}
@@ -3249,7 +3271,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
Node* store;
// WASM semantics throw on OOB. Introduce explicit bounds check.
- if (!FLAG_wasm_trap_handler || !kTrapHandlerSupported) {
+ if (!FLAG_wasm_trap_handler || !V8_TRAP_HANDLER_SUPPORTED) {
BoundsCheckMem(memtype, index, offset, position);
}
StoreRepresentation rep(memtype.representation(), kNoWriteBarrier);
@@ -3263,7 +3285,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
if (aligned ||
jsgraph()->machine()->UnalignedStoreSupported(memtype, alignment)) {
- if (FLAG_wasm_trap_handler && kTrapHandlerSupported) {
+ if (FLAG_wasm_trap_handler && V8_TRAP_HANDLER_SUPPORTED) {
Node* position_node = jsgraph()->Int32Constant(position);
store = graph()->NewNode(
jsgraph()->machine()->ProtectedStore(memtype.representation()),
@@ -3276,7 +3298,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
}
} else {
// TODO(eholk): Support unaligned stores with trap handlers.
- DCHECK(!FLAG_wasm_trap_handler || !kTrapHandlerSupported);
+ DCHECK(!FLAG_wasm_trap_handler || !V8_TRAP_HANDLER_SUPPORTED);
UnalignedStoreRepresentation rep(memtype.representation());
store =
graph()->NewNode(jsgraph()->machine()->UnalignedStore(rep),
« no previous file with comments | « src/api.cc ('k') | src/compiler/x64/code-generator-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698