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

Side by Side Diff: src/compiler/x64/code-generator-x64.cc

Issue 2500443004: [wasm] OOB traps: build protected instruction list during codegen (Closed)
Patch Set: Code review feedback Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/code-generator.h" 5 #include "src/compiler/code-generator.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/compilation-info.h" 9 #include "src/compilation-info.h"
10 #include "src/compiler/code-generator-impl.h" 10 #include "src/compiler/code-generator-impl.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 Register const object_; 263 Register const object_;
264 Operand const operand_; 264 Operand const operand_;
265 Register const value_; 265 Register const value_;
266 Register const scratch0_; 266 Register const scratch0_;
267 Register const scratch1_; 267 Register const scratch1_;
268 RecordWriteMode const mode_; 268 RecordWriteMode const mode_;
269 }; 269 };
270 270
271 class WasmOutOfLineTrap final : public OutOfLineCode { 271 class WasmOutOfLineTrap final : public OutOfLineCode {
272 public: 272 public:
273 WasmOutOfLineTrap(CodeGenerator* gen, Address pc, bool frame_elided, 273 WasmOutOfLineTrap(CodeGenerator* gen, int pc, bool frame_elided,
274 Register context, int32_t position) 274 Register context, int32_t position)
275 : OutOfLineCode(gen), 275 : OutOfLineCode(gen),
276 gen_(gen),
276 pc_(pc), 277 pc_(pc),
277 frame_elided_(frame_elided), 278 frame_elided_(frame_elided),
278 context_(context), 279 context_(context),
279 position_(position) {} 280 position_(position) {}
280 281
282 // TODO(eholk): Refactor this method to take the code generator as a
283 // parameter.
281 void Generate() final { 284 void Generate() final {
282 // TODO(eholk): record pc_ and the current pc in a table so that 285 int current_pc = __ pc_offset();
283 // the signal handler can find it. 286
284 USE(pc_); 287 gen_->AddProtectedInstruction(pc_, current_pc);
285 288
286 if (frame_elided_) { 289 if (frame_elided_) {
287 __ EnterFrame(StackFrame::WASM); 290 __ EnterFrame(StackFrame::WASM);
288 } 291 }
289 292
290 wasm::TrapReason trap_id = wasm::kTrapMemOutOfBounds; 293 wasm::TrapReason trap_id = wasm::kTrapMemOutOfBounds;
291 int trap_reason = wasm::WasmOpcodes::TrapReasonToMessageId(trap_id); 294 int trap_reason = wasm::WasmOpcodes::TrapReasonToMessageId(trap_id);
292 __ Push(Smi::FromInt(trap_reason)); 295 __ Push(Smi::FromInt(trap_reason));
293 __ Push(Smi::FromInt(position_)); 296 __ Push(Smi::FromInt(position_));
294 __ Move(rsi, context_); 297 __ Move(rsi, context_);
295 __ CallRuntime(Runtime::kThrowWasmError); 298 __ CallRuntime(Runtime::kThrowWasmError);
296 } 299 }
297 300
298 private: 301 private:
299 Address pc_; 302 CodeGenerator* gen_;
303 int pc_;
300 bool frame_elided_; 304 bool frame_elided_;
301 Register context_; 305 Register context_;
302 int32_t position_; 306 int32_t position_;
303 }; 307 };
304 308
305 } // namespace 309 } // namespace
306 310
307 311
308 #define ASSEMBLE_UNOP(asm_instr) \ 312 #define ASSEMBLE_UNOP(asm_instr) \
309 do { \ 313 do { \
(...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 case kX64Movl: 1894 case kX64Movl:
1891 case kX64TrapMovl: 1895 case kX64TrapMovl:
1892 if (instr->HasOutput()) { 1896 if (instr->HasOutput()) {
1893 if (instr->addressing_mode() == kMode_None) { 1897 if (instr->addressing_mode() == kMode_None) {
1894 if (instr->InputAt(0)->IsRegister()) { 1898 if (instr->InputAt(0)->IsRegister()) {
1895 __ movl(i.OutputRegister(), i.InputRegister(0)); 1899 __ movl(i.OutputRegister(), i.InputRegister(0));
1896 } else { 1900 } else {
1897 __ movl(i.OutputRegister(), i.InputOperand(0)); 1901 __ movl(i.OutputRegister(), i.InputOperand(0));
1898 } 1902 }
1899 } else { 1903 } else {
1900 Address pc = __ pc(); 1904 int pc = __ pc_offset();
1901 __ movl(i.OutputRegister(), i.MemoryOperand()); 1905 __ movl(i.OutputRegister(), i.MemoryOperand());
1902 1906
1903 if (arch_opcode == kX64TrapMovl) { 1907 if (arch_opcode == kX64TrapMovl) {
1904 bool frame_elided = !frame_access_state()->has_frame(); 1908 bool frame_elided = !frame_access_state()->has_frame();
1905 new (zone()) WasmOutOfLineTrap(this, pc, frame_elided, 1909 new (zone()) WasmOutOfLineTrap(this, pc, frame_elided,
1906 i.InputRegister(2), i.InputInt32(3)); 1910 i.InputRegister(2), i.InputInt32(3));
1907 } 1911 }
1908 } 1912 }
1909 __ AssertZeroExtended(i.OutputRegister()); 1913 __ AssertZeroExtended(i.OutputRegister());
1910 } else { 1914 } else {
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
2777 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; 2781 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
2778 __ Nop(padding_size); 2782 __ Nop(padding_size);
2779 } 2783 }
2780 } 2784 }
2781 2785
2782 #undef __ 2786 #undef __
2783 2787
2784 } // namespace compiler 2788 } // namespace compiler
2785 } // namespace internal 2789 } // namespace internal
2786 } // namespace v8 2790 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698