Index: src/compiler/x64/code-generator-x64.cc |
diff --git a/src/compiler/x64/code-generator-x64.cc b/src/compiler/x64/code-generator-x64.cc |
index 4c2f6e80dfb78459a22684bf2c7ab9168ca14188..af2d963dc5c35410dfbc183df17762621b1902f5 100644 |
--- a/src/compiler/x64/code-generator-x64.cc |
+++ b/src/compiler/x64/code-generator-x64.cc |
@@ -9,6 +9,7 @@ |
#include "src/compiler/gap-resolver.h" |
#include "src/compiler/node-matchers.h" |
#include "src/compiler/osr.h" |
+#include "src/wasm/wasm-module.h" |
#include "src/x64/assembler-x64.h" |
#include "src/x64/macro-assembler-x64.h" |
@@ -260,6 +261,45 @@ class OutOfLineRecordWrite final : public OutOfLineCode { |
RecordWriteMode const mode_; |
}; |
+class OutOfLineTrap final : public OutOfLineCode { |
+ public: |
+ OutOfLineTrap(CodeGenerator* gen, Address pc, bool needs_frame, |
+ Register context, int32_t position) |
+ : OutOfLineCode(gen), |
+ pc_(pc), |
+ needs_frame_(needs_frame), |
+ context_(context), |
+ position_(position) {} |
+ |
+ void Generate() final { |
+ const auto landing = __ GetPC(); |
+ |
+ // Save the location of this OOL code so the trap handler can find it. |
+ const auto offset = |
+ reinterpret_cast<intptr_t>(landing) - reinterpret_cast<intptr_t>(pc_); |
+ RelocInfo rinfo(isolate(), pc_, RelocInfo::WASM_TRAP_LANDING, offset, NULL); |
+ __ RecordRelocInfo(&rinfo); |
+ |
+ if (needs_frame_) { |
+ __ EnterFrame(StackFrame::WASM); |
+ } |
+ |
+ // TODO(eholk): plumb these two arguments from wasm-compiler.cc |
+ auto trap_id = wasm::kTrapMemOutOfBounds; |
+ auto trap_reason = wasm::WasmOpcodes::TrapReasonToMessageId(trap_id); |
+ __ Push(Smi::FromInt(trap_reason)); |
+ __ Push(Smi::FromInt(position_)); |
+ __ Move(rsi, context_); |
+ __ CallRuntime(Runtime::kThrowWasmError); |
+ } |
+ |
+ private: |
+ Address pc_; |
+ bool needs_frame_; |
+ Register context_; |
+ int32_t position_; |
+}; |
+ |
} // namespace |
@@ -1849,6 +1889,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
break; |
} |
case kX64Movl: |
+ case kX64TrapMovl: |
if (instr->HasOutput()) { |
if (instr->addressing_mode() == kMode_None) { |
if (instr->InputAt(0)->IsRegister()) { |
@@ -1857,7 +1898,14 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
__ movl(i.OutputRegister(), i.InputOperand(0)); |
} |
} else { |
+ auto pc = __ GetPC(); |
__ movl(i.OutputRegister(), i.MemoryOperand()); |
+ |
+ if (arch_opcode == kX64TrapMovl) { |
+ const auto needs_frame = !frame_access_state()->has_frame(); |
+ new (zone()) OutOfLineTrap(this, pc, needs_frame, |
+ i.InputRegister(2), i.InputInt32(3)); |
+ } |
} |
__ AssertZeroExtended(i.OutputRegister()); |
} else { |