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 13 matching lines...) Expand all Loading... |
24 } while (false) | 24 } while (false) |
25 #else | 25 #else |
26 #define TRACE(...) | 26 #define TRACE(...) |
27 #endif | 27 #endif |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const char* kNameString = "name"; | 31 const char* kNameString = "name"; |
32 const size_t kNameStringLength = 4; | 32 const size_t kNameStringLength = 4; |
33 | 33 |
| 34 static const uint32_t kMaxTableSize = 1 << 28; |
| 35 |
34 LocalType TypeOf(const WasmModule* module, const WasmInitExpr& expr) { | 36 LocalType TypeOf(const WasmModule* module, const WasmInitExpr& expr) { |
35 switch (expr.kind) { | 37 switch (expr.kind) { |
36 case WasmInitExpr::kNone: | 38 case WasmInitExpr::kNone: |
37 return kAstStmt; | 39 return kAstStmt; |
38 case WasmInitExpr::kGlobalIndex: | 40 case WasmInitExpr::kGlobalIndex: |
39 return expr.val.global_index < module->globals.size() | 41 return expr.val.global_index < module->globals.size() |
40 ? module->globals[expr.val.global_index].type | 42 ? module->globals[expr.val.global_index].type |
41 : kAstStmt; | 43 : kAstStmt; |
42 case WasmInitExpr::kI32Const: | 44 case WasmInitExpr::kI32Const: |
43 return kAstI32; | 45 return kAstI32; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 break; | 308 break; |
307 } | 309 } |
308 case kExternalTable: { | 310 case kExternalTable: { |
309 // ===== Imported table ========================================== | 311 // ===== Imported table ========================================== |
310 import->index = | 312 import->index = |
311 static_cast<uint32_t>(module->function_tables.size()); | 313 static_cast<uint32_t>(module->function_tables.size()); |
312 module->function_tables.push_back( | 314 module->function_tables.push_back( |
313 {0, 0, std::vector<int32_t>(), true, false, SignatureMap()}); | 315 {0, 0, std::vector<int32_t>(), true, false, SignatureMap()}); |
314 expect_u8("element type", 0x20); | 316 expect_u8("element type", 0x20); |
315 WasmIndirectFunctionTable* table = &module->function_tables.back(); | 317 WasmIndirectFunctionTable* table = &module->function_tables.back(); |
316 consume_resizable_limits("element count", "elements", kMaxUInt32, | 318 consume_resizable_limits("element count", "elements", kMaxTableSize, |
317 &table->size, &table->max_size); | 319 &table->size, &table->max_size); |
318 break; | 320 break; |
319 } | 321 } |
320 case kExternalMemory: { | 322 case kExternalMemory: { |
321 // ===== Imported memory ========================================= | 323 // ===== Imported memory ========================================= |
322 consume_resizable_limits( | 324 consume_resizable_limits( |
323 "memory", "pages", WasmModule::kMaxLegalPages, | 325 "memory", "pages", WasmModule::kMaxLegalPages, |
324 &module->min_mem_pages, &module->max_mem_pages); | 326 &module->min_mem_pages, &module->max_mem_pages); |
325 break; | 327 break; |
326 } | 328 } |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 table.push_back(std::move(func_asm_offsets)); | 1212 table.push_back(std::move(func_asm_offsets)); |
1211 } | 1213 } |
1212 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1214 if (decoder.more()) decoder.error("unexpected additional bytes"); |
1213 | 1215 |
1214 return decoder.toResult(std::move(table)); | 1216 return decoder.toResult(std::move(table)); |
1215 } | 1217 } |
1216 | 1218 |
1217 } // namespace wasm | 1219 } // namespace wasm |
1218 } // namespace internal | 1220 } // namespace internal |
1219 } // namespace v8 | 1221 } // namespace v8 |
OLD | NEW |