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

Side by Side Diff: src/wasm/wasm-interpreter.cc

Issue 2285643002: [wasm] Validate the alignment of load and store instructions. (Closed)
Patch Set: Add alignment and maximum alignment information to the error message. Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « src/wasm/ast-decoder.cc ('k') | test/unittests/wasm/ast-decoder-unittest.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/wasm/wasm-interpreter.h" 5 #include "src/wasm/wasm-interpreter.h"
6 6
7 #include "src/utils.h" 7 #include "src/utils.h"
8 #include "src/wasm/ast-decoder.h" 8 #include "src/wasm/ast-decoder.h"
9 #include "src/wasm/decoder.h" 9 #include "src/wasm/decoder.h"
10 #include "src/wasm/wasm-external-refs.h" 10 #include "src/wasm/wasm-external-refs.h"
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 } else { 1437 } else {
1438 UNREACHABLE(); 1438 UNREACHABLE();
1439 } 1439 }
1440 Push(pc, val); 1440 Push(pc, val);
1441 len = 1 + operand.length; 1441 len = 1 + operand.length;
1442 break; 1442 break;
1443 } 1443 }
1444 1444
1445 #define LOAD_CASE(name, ctype, mtype) \ 1445 #define LOAD_CASE(name, ctype, mtype) \
1446 case kExpr##name: { \ 1446 case kExpr##name: { \
1447 MemoryAccessOperand operand(&decoder, code->at(pc)); \ 1447 MemoryAccessOperand operand(&decoder, code->at(pc), sizeof(ctype)); \
1448 uint32_t index = Pop().to<uint32_t>(); \ 1448 uint32_t index = Pop().to<uint32_t>(); \
1449 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ 1449 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \
1450 if (operand.offset > effective_mem_size || \ 1450 if (operand.offset > effective_mem_size || \
1451 index > (effective_mem_size - operand.offset)) { \ 1451 index > (effective_mem_size - operand.offset)) { \
1452 return DoTrap(kTrapMemOutOfBounds, pc); \ 1452 return DoTrap(kTrapMemOutOfBounds, pc); \
1453 } \ 1453 } \
1454 byte* addr = instance()->mem_start + operand.offset + index; \ 1454 byte* addr = instance()->mem_start + operand.offset + index; \
1455 WasmVal result(static_cast<ctype>(ReadLittleEndianValue<mtype>(addr))); \ 1455 WasmVal result(static_cast<ctype>(ReadLittleEndianValue<mtype>(addr))); \
1456 Push(pc, result); \ 1456 Push(pc, result); \
1457 len = 1 + operand.length; \ 1457 len = 1 + operand.length; \
(...skipping 11 matching lines...) Expand all
1469 LOAD_CASE(I64LoadMem32S, int64_t, int32_t); 1469 LOAD_CASE(I64LoadMem32S, int64_t, int32_t);
1470 LOAD_CASE(I64LoadMem32U, int64_t, uint32_t); 1470 LOAD_CASE(I64LoadMem32U, int64_t, uint32_t);
1471 LOAD_CASE(I32LoadMem, int32_t, int32_t); 1471 LOAD_CASE(I32LoadMem, int32_t, int32_t);
1472 LOAD_CASE(I64LoadMem, int64_t, int64_t); 1472 LOAD_CASE(I64LoadMem, int64_t, int64_t);
1473 LOAD_CASE(F32LoadMem, float, float); 1473 LOAD_CASE(F32LoadMem, float, float);
1474 LOAD_CASE(F64LoadMem, double, double); 1474 LOAD_CASE(F64LoadMem, double, double);
1475 #undef LOAD_CASE 1475 #undef LOAD_CASE
1476 1476
1477 #define STORE_CASE(name, ctype, mtype) \ 1477 #define STORE_CASE(name, ctype, mtype) \
1478 case kExpr##name: { \ 1478 case kExpr##name: { \
1479 MemoryAccessOperand operand(&decoder, code->at(pc)); \ 1479 MemoryAccessOperand operand(&decoder, code->at(pc), sizeof(ctype)); \
1480 WasmVal val = Pop(); \ 1480 WasmVal val = Pop(); \
1481 uint32_t index = Pop().to<uint32_t>(); \ 1481 uint32_t index = Pop().to<uint32_t>(); \
1482 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ 1482 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \
1483 if (operand.offset > effective_mem_size || \ 1483 if (operand.offset > effective_mem_size || \
1484 index > (effective_mem_size - operand.offset)) { \ 1484 index > (effective_mem_size - operand.offset)) { \
1485 return DoTrap(kTrapMemOutOfBounds, pc); \ 1485 return DoTrap(kTrapMemOutOfBounds, pc); \
1486 } \ 1486 } \
1487 byte* addr = instance()->mem_start + operand.offset + index; \ 1487 byte* addr = instance()->mem_start + operand.offset + index; \
1488 WriteLittleEndianValue<mtype>(addr, static_cast<mtype>(val.to<ctype>())); \ 1488 WriteLittleEndianValue<mtype>(addr, static_cast<mtype>(val.to<ctype>())); \
1489 Push(pc, val); \ 1489 Push(pc, val); \
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 1804
1805 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( 1805 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting(
1806 Zone* zone, const byte* start, const byte* end) { 1806 Zone* zone, const byte* start, const byte* end) {
1807 ControlTransfers targets(zone, 0, start, end); 1807 ControlTransfers targets(zone, 0, start, end);
1808 return targets.map_; 1808 return targets.map_;
1809 } 1809 }
1810 1810
1811 } // namespace wasm 1811 } // namespace wasm
1812 } // namespace internal 1812 } // namespace internal
1813 } // namespace v8 1813 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/ast-decoder.cc ('k') | test/unittests/wasm/ast-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698