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..bb656253a69e5f09393387dfeabdb29ee97da50f 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,40 @@ class OutOfLineRecordWrite final : public OutOfLineCode { |
RecordWriteMode const mode_; |
}; |
+class WasmOutOfLineTrap final : public OutOfLineCode { |
+ public: |
+ WasmOutOfLineTrap(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 { |
+ // TODO(eholk): record pc_ and the current pc in a table so that |
+ // the signal handler can find it. |
+ (void)pc_; |
Mircea Trofin
2016/09/02 04:05:45
you could do USE(pc_);
Eric Holk
2016/09/02 20:05:32
Done.
|
+ |
+ if (needs_frame_) { |
+ __ EnterFrame(StackFrame::WASM); |
+ } |
+ |
+ auto trap_id = wasm::kTrapMemOutOfBounds; |
Mircea Trofin
2016/09/02 04:05:45
please no auto. Same below.
Eric Holk
2016/09/02 20:05:32
Done.
|
+ 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 +1884,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 +1893,14 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
__ movl(i.OutputRegister(), i.InputOperand(0)); |
} |
} else { |
+ auto pc = __ GetPC(); |
Mircea Trofin
2016/09/02 04:05:45
no auto.
Eric Holk
2016/09/02 20:05:32
Done.
|
__ movl(i.OutputRegister(), i.MemoryOperand()); |
+ |
+ if (arch_opcode == kX64TrapMovl) { |
+ const auto needs_frame = !frame_access_state()->has_frame(); |
Mircea Trofin
2016/09/02 04:05:45
no auto
Eric Holk
2016/09/02 20:05:32
Done.
|
+ new (zone()) WasmOutOfLineTrap(this, pc, needs_frame, |
+ i.InputRegister(2), i.InputInt32(3)); |
+ } |
} |
__ AssertZeroExtended(i.OutputRegister()); |
} else { |