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

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

Issue 2174123002: [wasm] Add support for multiple indirect function tables (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix GC issue Created 4 years, 4 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/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-interpreter.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 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/wasm/module-decoder.h" 5 #include "src/wasm/module-decoder.h"
6 6
7 #include "src/base/functional.h" 7 #include "src/base/functional.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/macro-assembler.h" 9 #include "src/macro-assembler.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 static_cast<int>(pc_ - start_)); 250 static_cast<int>(pc_ - start_));
251 module->data_segments.push_back({0, // dest_addr 251 module->data_segments.push_back({0, // dest_addr
252 0, // source_offset 252 0, // source_offset
253 0, // source_size 253 0, // source_size
254 false}); // init 254 false}); // init
255 WasmDataSegment* segment = &module->data_segments.back(); 255 WasmDataSegment* segment = &module->data_segments.back();
256 DecodeDataSegmentInModule(module, segment); 256 DecodeDataSegmentInModule(module, segment);
257 } 257 }
258 break; 258 break;
259 } 259 }
260 case WasmSection::Code::FunctionTablePad: {
261 if (!FLAG_wasm_jit_prototype) {
262 error("FunctionTablePad section without jiting enabled");
263 }
264 // An indirect function table requires functions first.
265 module->indirect_table_size = consume_u32v("indirect entry count");
266 if (module->indirect_table_size > 0 &&
267 module->indirect_table_size < module->function_table.size()) {
268 error("more predefined indirect entries than table can hold");
269 }
270 break;
271 }
272 case WasmSection::Code::FunctionTable: { 260 case WasmSection::Code::FunctionTable: {
273 // An indirect function table requires functions first. 261 // An indirect function table requires functions first.
274 CheckForFunctions(module, section); 262 CheckForFunctions(module, section);
275 uint32_t function_table_count = consume_u32v("function table count"); 263 // Assume only one table for now.
276 module->function_table.reserve(SafeReserve(function_table_count)); 264 static const uint32_t kSupportedTableCount = 1;
265 module->function_tables.reserve(SafeReserve(kSupportedTableCount));
277 // Decode function table. 266 // Decode function table.
278 for (uint32_t i = 0; i < function_table_count; ++i) { 267 for (uint32_t i = 0; i < kSupportedTableCount; ++i) {
279 if (failed()) break; 268 if (failed()) break;
280 TRACE("DecodeFunctionTable[%d] module+%d\n", i, 269 TRACE("DecodeFunctionTable[%d] module+%d\n", i,
281 static_cast<int>(pc_ - start_)); 270 static_cast<int>(pc_ - start_));
282 uint16_t index = consume_u32v(); 271 module->function_tables.push_back({0, 0, std::vector<uint16_t>()});
283 if (index >= module->functions.size()) { 272 DecodeFunctionTableInModule(module, &module->function_tables[i]);
284 error(pc_ - 2, "invalid function index");
285 break;
286 }
287 module->function_table.push_back(index);
288 }
289 if (module->indirect_table_size > 0 &&
290 module->indirect_table_size < module->function_table.size()) {
291 error("more predefined indirect entries than table can hold");
292 } 273 }
293 break; 274 break;
294 } 275 }
295 case WasmSection::Code::StartFunction: { 276 case WasmSection::Code::StartFunction: {
296 // Declares a start function for a module. 277 // Declares a start function for a module.
297 CheckForFunctions(module, section); 278 CheckForFunctions(module, section);
298 if (module->start_function_index >= 0) { 279 if (module->start_function_index >= 0) {
299 error("start function already declared"); 280 error("start function already declared");
300 break; 281 break;
301 } 282 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 WasmModule::kPageSize * (module ? module->min_mem_pages 494 WasmModule::kPageSize * (module ? module->min_mem_pages
514 : WasmModule::kMaxMemPages); 495 : WasmModule::kMaxMemPages);
515 if (!IsWithinLimit(memory_limit, segment->dest_addr, 496 if (!IsWithinLimit(memory_limit, segment->dest_addr,
516 segment->source_size)) { 497 segment->source_size)) {
517 error(start, "segment out of bounds of memory"); 498 error(start, "segment out of bounds of memory");
518 } 499 }
519 500
520 consume_bytes(segment->source_size); 501 consume_bytes(segment->source_size);
521 } 502 }
522 503
504 // Decodes a single function table inside a module starting at {pc_}.
505 void DecodeFunctionTableInModule(WasmModule* module,
506 WasmIndirectFunctionTable* table) {
507 table->size = consume_u32v("function table entry count");
508 table->max_size = FLAG_wasm_jit_prototype ? consume_u32v() : table->size;
509
510 if ((!FLAG_wasm_jit_prototype && table->max_size != table->size) ||
511 (FLAG_wasm_jit_prototype && table->max_size < table->size)) {
512 error("invalid table maximum size");
513 }
514
515 for (uint32_t i = 0; i < table->size; ++i) {
516 uint16_t index = consume_u32v();
517 if (index >= module->functions.size()) {
518 error(pc_ - sizeof(index), "invalid function index");
519 break;
520 }
521 table->values.push_back(index);
522 }
523 }
524
523 // Calculate individual global offsets and total size of globals table. 525 // Calculate individual global offsets and total size of globals table.
524 void CalculateGlobalsOffsets(WasmModule* module) { 526 void CalculateGlobalsOffsets(WasmModule* module) {
525 uint32_t offset = 0; 527 uint32_t offset = 0;
526 if (module->globals.size() == 0) { 528 if (module->globals.size() == 0) {
527 module->globals_size = 0; 529 module->globals_size = 0;
528 return; 530 return;
529 } 531 }
530 for (WasmGlobal& global : module->globals) { 532 for (WasmGlobal& global : module->globals) {
531 byte size = 533 byte size =
532 WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(global.type)); 534 WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(global.type));
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 decoder.consume_bytes(size); 810 decoder.consume_bytes(size);
809 } 811 }
810 if (decoder.more()) decoder.error("unexpected additional bytes"); 812 if (decoder.more()) decoder.error("unexpected additional bytes");
811 813
812 return decoder.toResult(std::move(table)); 814 return decoder.toResult(std::move(table));
813 } 815 }
814 816
815 } // namespace wasm 817 } // namespace wasm
816 } // namespace internal 818 } // namespace internal
817 } // namespace v8 819 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698