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

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: Removing spurious changes 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
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 void EmitOOLTrapIfNeeded(Zone* zone, CodeGenerator* codegen, 309 void EmitOOLTrapIfNeeded(Zone* zone, CodeGenerator* codegen,
306 InstructionCode opcode, X64OperandConverter& i, 310 InstructionCode opcode, X64OperandConverter& i,
307 Address pc) { 311 int pc) {
308 X64MemoryProtection protection = 312 X64MemoryProtection protection =
309 static_cast<X64MemoryProtection>(MiscField::decode(opcode)); 313 static_cast<X64MemoryProtection>(MiscField::decode(opcode));
310 if (protection == X64MemoryProtection::kProtected) { 314 if (protection == X64MemoryProtection::kProtected) {
311 bool frame_elided = !codegen->frame_access_state()->has_frame(); 315 bool frame_elided = !codegen->frame_access_state()->has_frame();
312 new (zone) WasmOutOfLineTrap(codegen, pc, frame_elided, i.InputRegister(2), 316 new (zone) WasmOutOfLineTrap(codegen, pc, frame_elided, i.InputRegister(2),
313 i.InputInt32(3)); 317 i.InputInt32(3));
314 } 318 }
315 } 319 }
316 } // namespace 320 } // namespace
317 321
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 i.InputOperand(0)); 1847 i.InputOperand(0));
1844 } 1848 }
1845 break; 1849 break;
1846 } 1850 }
1847 case kSSEFloat64SilenceNaN: 1851 case kSSEFloat64SilenceNaN:
1848 __ Xorpd(kScratchDoubleReg, kScratchDoubleReg); 1852 __ Xorpd(kScratchDoubleReg, kScratchDoubleReg);
1849 __ Subsd(i.InputDoubleRegister(0), kScratchDoubleReg); 1853 __ Subsd(i.InputDoubleRegister(0), kScratchDoubleReg);
1850 break; 1854 break;
1851 case kX64Movsxbl: 1855 case kX64Movsxbl:
1852 ASSEMBLE_MOVX(movsxbl); 1856 ASSEMBLE_MOVX(movsxbl);
1853 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1857 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1854 __ AssertZeroExtended(i.OutputRegister()); 1858 __ AssertZeroExtended(i.OutputRegister());
1855 break; 1859 break;
1856 case kX64Movzxbl: 1860 case kX64Movzxbl:
1857 ASSEMBLE_MOVX(movzxbl); 1861 ASSEMBLE_MOVX(movzxbl);
1858 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1862 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1859 __ AssertZeroExtended(i.OutputRegister()); 1863 __ AssertZeroExtended(i.OutputRegister());
1860 break; 1864 break;
1861 case kX64Movsxbq: 1865 case kX64Movsxbq:
1862 ASSEMBLE_MOVX(movsxbq); 1866 ASSEMBLE_MOVX(movsxbq);
1863 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1867 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1864 break; 1868 break;
1865 case kX64Movzxbq: 1869 case kX64Movzxbq:
1866 ASSEMBLE_MOVX(movzxbq); 1870 ASSEMBLE_MOVX(movzxbq);
1867 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1871 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1868 __ AssertZeroExtended(i.OutputRegister()); 1872 __ AssertZeroExtended(i.OutputRegister());
1869 break; 1873 break;
1870 case kX64Movb: { 1874 case kX64Movb: {
1871 size_t index = 0; 1875 size_t index = 0;
1872 Operand operand = i.MemoryOperand(&index); 1876 Operand operand = i.MemoryOperand(&index);
1873 if (HasImmediateInput(instr, index)) { 1877 if (HasImmediateInput(instr, index)) {
1874 __ movb(operand, Immediate(i.InputInt8(index))); 1878 __ movb(operand, Immediate(i.InputInt8(index)));
1875 } else { 1879 } else {
1876 __ movb(operand, i.InputRegister(index)); 1880 __ movb(operand, i.InputRegister(index));
1877 } 1881 }
1878 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1882 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1879 break; 1883 break;
1880 } 1884 }
1881 case kX64Movsxwl: 1885 case kX64Movsxwl:
1882 ASSEMBLE_MOVX(movsxwl); 1886 ASSEMBLE_MOVX(movsxwl);
1883 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1887 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1884 __ AssertZeroExtended(i.OutputRegister()); 1888 __ AssertZeroExtended(i.OutputRegister());
1885 break; 1889 break;
1886 case kX64Movzxwl: 1890 case kX64Movzxwl:
1887 ASSEMBLE_MOVX(movzxwl); 1891 ASSEMBLE_MOVX(movzxwl);
1888 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1892 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1889 __ AssertZeroExtended(i.OutputRegister()); 1893 __ AssertZeroExtended(i.OutputRegister());
1890 break; 1894 break;
1891 case kX64Movsxwq: 1895 case kX64Movsxwq:
1892 ASSEMBLE_MOVX(movsxwq); 1896 ASSEMBLE_MOVX(movsxwq);
1893 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1897 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1894 break; 1898 break;
1895 case kX64Movzxwq: 1899 case kX64Movzxwq:
1896 ASSEMBLE_MOVX(movzxwq); 1900 ASSEMBLE_MOVX(movzxwq);
1897 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1901 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1898 __ AssertZeroExtended(i.OutputRegister()); 1902 __ AssertZeroExtended(i.OutputRegister());
1899 break; 1903 break;
1900 case kX64Movw: { 1904 case kX64Movw: {
1901 size_t index = 0; 1905 size_t index = 0;
1902 Operand operand = i.MemoryOperand(&index); 1906 Operand operand = i.MemoryOperand(&index);
1903 if (HasImmediateInput(instr, index)) { 1907 if (HasImmediateInput(instr, index)) {
1904 __ movw(operand, Immediate(i.InputInt16(index))); 1908 __ movw(operand, Immediate(i.InputInt16(index)));
1905 } else { 1909 } else {
1906 __ movw(operand, i.InputRegister(index)); 1910 __ movw(operand, i.InputRegister(index));
1907 } 1911 }
1908 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1912 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1909 break; 1913 break;
1910 } 1914 }
1911 case kX64Movl: 1915 case kX64Movl:
1912 if (instr->HasOutput()) { 1916 if (instr->HasOutput()) {
1913 if (instr->addressing_mode() == kMode_None) { 1917 if (instr->addressing_mode() == kMode_None) {
1914 if (instr->InputAt(0)->IsRegister()) { 1918 if (instr->InputAt(0)->IsRegister()) {
1915 __ movl(i.OutputRegister(), i.InputRegister(0)); 1919 __ movl(i.OutputRegister(), i.InputRegister(0));
1916 } else { 1920 } else {
1917 __ movl(i.OutputRegister(), i.InputOperand(0)); 1921 __ movl(i.OutputRegister(), i.InputOperand(0));
1918 } 1922 }
1919 } else { 1923 } else {
1920 __ movl(i.OutputRegister(), i.MemoryOperand()); 1924 __ movl(i.OutputRegister(), i.MemoryOperand());
1921 } 1925 }
1922 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1926 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1923 __ AssertZeroExtended(i.OutputRegister()); 1927 __ AssertZeroExtended(i.OutputRegister());
1924 } else { 1928 } else {
1925 size_t index = 0; 1929 size_t index = 0;
1926 Operand operand = i.MemoryOperand(&index); 1930 Operand operand = i.MemoryOperand(&index);
1927 if (HasImmediateInput(instr, index)) { 1931 if (HasImmediateInput(instr, index)) {
1928 __ movl(operand, i.InputImmediate(index)); 1932 __ movl(operand, i.InputImmediate(index));
1929 } else { 1933 } else {
1930 __ movl(operand, i.InputRegister(index)); 1934 __ movl(operand, i.InputRegister(index));
1931 } 1935 }
1932 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1936 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1933 } 1937 }
1934 break; 1938 break;
1935 case kX64Movsxlq: 1939 case kX64Movsxlq:
1936 ASSEMBLE_MOVX(movsxlq); 1940 ASSEMBLE_MOVX(movsxlq);
1937 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1941 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1938 break; 1942 break;
1939 case kX64Movq: 1943 case kX64Movq:
1940 if (instr->HasOutput()) { 1944 if (instr->HasOutput()) {
1941 __ movq(i.OutputRegister(), i.MemoryOperand()); 1945 __ movq(i.OutputRegister(), i.MemoryOperand());
1942 } else { 1946 } else {
1943 size_t index = 0; 1947 size_t index = 0;
1944 Operand operand = i.MemoryOperand(&index); 1948 Operand operand = i.MemoryOperand(&index);
1945 if (HasImmediateInput(instr, index)) { 1949 if (HasImmediateInput(instr, index)) {
1946 __ movq(operand, i.InputImmediate(index)); 1950 __ movq(operand, i.InputImmediate(index));
1947 } else { 1951 } else {
1948 __ movq(operand, i.InputRegister(index)); 1952 __ movq(operand, i.InputRegister(index));
1949 } 1953 }
1950 } 1954 }
1951 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1955 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1952 break; 1956 break;
1953 case kX64Movss: 1957 case kX64Movss:
1954 if (instr->HasOutput()) { 1958 if (instr->HasOutput()) {
1955 __ movss(i.OutputDoubleRegister(), i.MemoryOperand()); 1959 __ movss(i.OutputDoubleRegister(), i.MemoryOperand());
1956 } else { 1960 } else {
1957 size_t index = 0; 1961 size_t index = 0;
1958 Operand operand = i.MemoryOperand(&index); 1962 Operand operand = i.MemoryOperand(&index);
1959 __ movss(operand, i.InputDoubleRegister(index)); 1963 __ movss(operand, i.InputDoubleRegister(index));
1960 } 1964 }
1961 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1965 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1962 break; 1966 break;
1963 case kX64Movsd: 1967 case kX64Movsd:
1964 if (instr->HasOutput()) { 1968 if (instr->HasOutput()) {
1965 __ Movsd(i.OutputDoubleRegister(), i.MemoryOperand()); 1969 __ Movsd(i.OutputDoubleRegister(), i.MemoryOperand());
1966 } else { 1970 } else {
1967 size_t index = 0; 1971 size_t index = 0;
1968 Operand operand = i.MemoryOperand(&index); 1972 Operand operand = i.MemoryOperand(&index);
1969 __ Movsd(operand, i.InputDoubleRegister(index)); 1973 __ Movsd(operand, i.InputDoubleRegister(index));
1970 } 1974 }
1971 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc()); 1975 EmitOOLTrapIfNeeded(zone(), this, opcode, i, __ pc_offset());
1972 break; 1976 break;
1973 case kX64BitcastFI: 1977 case kX64BitcastFI:
1974 if (instr->InputAt(0)->IsFPStackSlot()) { 1978 if (instr->InputAt(0)->IsFPStackSlot()) {
1975 __ movl(i.OutputRegister(), i.InputOperand(0)); 1979 __ movl(i.OutputRegister(), i.InputOperand(0));
1976 } else { 1980 } else {
1977 __ Movd(i.OutputRegister(), i.InputDoubleRegister(0)); 1981 __ Movd(i.OutputRegister(), i.InputDoubleRegister(0));
1978 } 1982 }
1979 break; 1983 break;
1980 case kX64BitcastDL: 1984 case kX64BitcastDL:
1981 if (instr->InputAt(0)->IsFPStackSlot()) { 1985 if (instr->InputAt(0)->IsFPStackSlot()) {
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
2796 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; 2800 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
2797 __ Nop(padding_size); 2801 __ Nop(padding_size);
2798 } 2802 }
2799 } 2803 }
2800 2804
2801 #undef __ 2805 #undef __
2802 2806
2803 } // namespace compiler 2807 } // namespace compiler
2804 } // namespace internal 2808 } // namespace internal
2805 } // namespace v8 2809 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698