OLD | NEW |
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/flags.h" | 9 #include "src/flags.h" |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 if (table_index != 0) { | 533 if (table_index != 0) { |
534 error(pos, pos, "illegal table index %u != 0", table_index); | 534 error(pos, pos, "illegal table index %u != 0", table_index); |
535 } | 535 } |
536 WasmIndirectFunctionTable* table = nullptr; | 536 WasmIndirectFunctionTable* table = nullptr; |
537 if (table_index >= module->function_tables.size()) { | 537 if (table_index >= module->function_tables.size()) { |
538 error(pos, pos, "out of bounds table index %u", table_index); | 538 error(pos, pos, "out of bounds table index %u", table_index); |
539 } else { | 539 } else { |
540 table = &module->function_tables[table_index]; | 540 table = &module->function_tables[table_index]; |
541 } | 541 } |
542 WasmInitExpr offset = consume_init_expr(module, kAstI32); | 542 WasmInitExpr offset = consume_init_expr(module, kAstI32); |
543 uint32_t num_elem = consume_u32v("number of elements"); | 543 uint32_t num_elem = |
| 544 consume_count("number of elements", kV8MaxWasmTableEntries); |
544 std::vector<uint32_t> vector; | 545 std::vector<uint32_t> vector; |
545 module->table_inits.push_back({table_index, offset, vector}); | 546 module->table_inits.push_back({table_index, offset, vector}); |
546 WasmTableInit* init = &module->table_inits.back(); | 547 WasmTableInit* init = &module->table_inits.back(); |
547 for (uint32_t j = 0; ok() && j < num_elem; j++) { | 548 for (uint32_t j = 0; ok() && j < num_elem; j++) { |
548 WasmFunction* func = nullptr; | 549 WasmFunction* func = nullptr; |
549 uint32_t index = consume_func_index(module, &func); | 550 uint32_t index = consume_func_index(module, &func); |
550 init->entries.push_back(index); | 551 init->entries.push_back(index); |
551 if (table && index < module->functions.size()) { | 552 if (table && index < module->functions.size()) { |
552 // Canonicalize signature indices during decoding. | 553 // Canonicalize signature indices during decoding. |
553 // TODO(titzer): suboptimal, redundant when verifying only. | |
554 table->map.FindOrInsert(module->functions[index].sig); | 554 table->map.FindOrInsert(module->functions[index].sig); |
555 } | 555 } |
556 } | 556 } |
557 } | 557 } |
558 | 558 |
559 section_iter.advance(); | 559 section_iter.advance(); |
560 } | 560 } |
561 | 561 |
562 // ===== Code section ==================================================== | 562 // ===== Code section ==================================================== |
563 if (section_iter.section_code() == kCodeSectionCode) { | 563 if (section_iter.section_code() == kCodeSectionCode) { |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 table.push_back(std::move(func_asm_offsets)); | 1224 table.push_back(std::move(func_asm_offsets)); |
1225 } | 1225 } |
1226 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1226 if (decoder.more()) decoder.error("unexpected additional bytes"); |
1227 | 1227 |
1228 return decoder.toResult(std::move(table)); | 1228 return decoder.toResult(std::move(table)); |
1229 } | 1229 } |
1230 | 1230 |
1231 } // namespace wasm | 1231 } // namespace wasm |
1232 } // namespace internal | 1232 } // namespace internal |
1233 } // namespace v8 | 1233 } // namespace v8 |
OLD | NEW |