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

Side by Side Diff: src/wasm/module-decoder.cc

Issue 1776923005: [Wasm] Move data segment data inline to the data segment section (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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/encoder.cc ('k') | test/mjsunit/wasm/wasm-module-builder.js » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/macro-assembler.h" 5 #include "src/macro-assembler.h"
6 #include "src/objects.h" 6 #include "src/objects.h"
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/wasm/decoder.h" 9 #include "src/wasm/decoder.h"
10 #include "src/wasm/module-decoder.h" 10 #include "src/wasm/module-decoder.h"
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 438 }
439 439
440 bool IsWithinLimit(uint32_t limit, uint32_t offset, uint32_t size) { 440 bool IsWithinLimit(uint32_t limit, uint32_t offset, uint32_t size) {
441 if (offset > limit) return false; 441 if (offset > limit) return false;
442 if ((offset + size) < offset) return false; // overflow 442 if ((offset + size) < offset) return false; // overflow
443 return (offset + size) <= limit; 443 return (offset + size) <= limit;
444 } 444 }
445 445
446 // Decodes a single data segment entry inside a module starting at {pc_}. 446 // Decodes a single data segment entry inside a module starting at {pc_}.
447 void DecodeDataSegmentInModule(WasmModule* module, WasmDataSegment* segment) { 447 void DecodeDataSegmentInModule(WasmModule* module, WasmDataSegment* segment) {
448 segment->dest_addr = consume_u32("destination"); 448 const byte* start = pc_;
449 segment->source_offset = consume_offset("source offset"); 449 int length;
450 segment->source_size = consume_u32("source size"); 450 segment->dest_addr = consume_u32v(&length, "destination");
451 segment->init = consume_u8("init"); 451 segment->source_size = consume_u32v(&length, "source size");
452 segment->source_offset = static_cast<uint32_t>(pc_ - start_);
453 segment->init = true;
452 454
453 // Validate the data is in the module. 455 // Validate the data is in the module.
454 uint32_t module_limit = static_cast<uint32_t>(limit_ - start_); 456 uint32_t module_limit = static_cast<uint32_t>(limit_ - start_);
455 if (!IsWithinLimit(module_limit, segment->source_offset, 457 if (!IsWithinLimit(module_limit, segment->source_offset,
456 segment->source_size)) { 458 segment->source_size)) {
457 error(pc_ - sizeof(uint32_t), "segment out of bounds of module"); 459 error(start, "segment out of bounds of module");
458 } 460 }
459 461
460 // Validate that the segment will fit into the (minimum) memory. 462 // Validate that the segment will fit into the (minimum) memory.
461 uint32_t memory_limit = 463 uint32_t memory_limit =
462 WasmModule::kPageSize * (module ? module->min_mem_pages 464 WasmModule::kPageSize * (module ? module->min_mem_pages
463 : WasmModule::kMaxMemPages); 465 : WasmModule::kMaxMemPages);
464 if (!IsWithinLimit(memory_limit, segment->dest_addr, 466 if (!IsWithinLimit(memory_limit, segment->dest_addr,
465 segment->source_size)) { 467 segment->source_size)) {
466 error(pc_ - sizeof(uint32_t), "segment out of bounds of memory"); 468 error(start, "segment out of bounds of memory");
467 } 469 }
470
471 consume_bytes(segment->source_size);
468 } 472 }
469 473
470 // Verifies the body (code) of a given function. 474 // Verifies the body (code) of a given function.
471 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv, 475 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv,
472 WasmFunction* function) { 476 WasmFunction* function) {
473 if (FLAG_trace_wasm_decode_time) { 477 if (FLAG_trace_wasm_decode_time) {
474 OFStream os(stdout); 478 OFStream os(stdout);
475 os << "Verifying WASM function " << WasmFunctionName(function, menv) 479 os << "Verifying WASM function " << WasmFunctionName(function, menv)
476 << std::endl; 480 << std::endl;
477 os << std::endl; 481 os << std::endl;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 if (function_start > function_end) return FunctionError("start > end"); 646 if (function_start > function_end) return FunctionError("start > end");
643 if (size > kMaxFunctionSize) 647 if (size > kMaxFunctionSize)
644 return FunctionError("size > maximum function size"); 648 return FunctionError("size > maximum function size");
645 WasmFunction* function = new WasmFunction(); 649 WasmFunction* function = new WasmFunction();
646 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); 650 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin);
647 return decoder.DecodeSingleFunction(module_env, function); 651 return decoder.DecodeSingleFunction(module_env, function);
648 } 652 }
649 } // namespace wasm 653 } // namespace wasm
650 } // namespace internal 654 } // namespace internal
651 } // namespace v8 655 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/encoder.cc ('k') | test/mjsunit/wasm/wasm-module-builder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698