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/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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 error(pos, pos, | 71 error(pos, pos, |
72 "expected version %02x %02x %02x %02x, " | 72 "expected version %02x %02x %02x %02x, " |
73 "found %02x %02x %02x %02x", | 73 "found %02x %02x %02x %02x", |
74 BYTES(kWasmVersion), BYTES(magic_version)); | 74 BYTES(kWasmVersion), BYTES(magic_version)); |
75 return toResult(module); | 75 return toResult(module); |
76 } | 76 } |
77 | 77 |
78 // Decode the module sections. | 78 // Decode the module sections. |
79 while (pc_ < limit_) { | 79 while (pc_ < limit_) { |
80 TRACE("DecodeSection\n"); | 80 TRACE("DecodeSection\n"); |
81 WasmSectionDeclCode section = | 81 uint8_t section_u8 = consume_u8("section"); |
82 static_cast<WasmSectionDeclCode>(consume_u8("section")); | 82 |
| 83 if (section_u8 >= kMaxModuleSectionCode) { |
| 84 // Skip unknown section. |
| 85 int length; |
| 86 uint32_t section_bytes = consume_u32v(&length, "section size"); |
| 87 consume_bytes(section_bytes); |
| 88 continue; |
| 89 } |
| 90 |
83 // Each section should appear at most once. | 91 // Each section should appear at most once. |
84 if (section < kMaxModuleSectionCode) { | 92 auto section = static_cast<WasmSectionDeclCode>(section_u8); |
85 CheckForPreviousSection(sections, section, false); | 93 CheckForPreviousSection(sections, section, false); |
86 sections[section] = true; | 94 sections[section] = true; |
87 } | |
88 | 95 |
89 switch (section) { | 96 switch (section) { |
90 case kDeclEnd: | 97 case kDeclEnd: |
91 // Terminate section decoding. | 98 // Terminate section decoding. |
92 limit_ = pc_; | 99 limit_ = pc_; |
93 break; | 100 break; |
94 case kDeclMemory: | 101 case kDeclMemory: |
95 int length; | 102 int length; |
96 module->min_mem_pages = consume_u32v(&length, "min memory"); | 103 module->min_mem_pages = consume_u32v(&length, "min memory"); |
97 module->max_mem_pages = consume_u32v(&length, "max memory"); | 104 module->max_mem_pages = consume_u32v(&length, "max memory"); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 if (exp->func_index >= module->functions.size()) { | 279 if (exp->func_index >= module->functions.size()) { |
273 error(sigpos, sigpos, | 280 error(sigpos, sigpos, |
274 "function index %u out of bounds (%d functions)", | 281 "function index %u out of bounds (%d functions)", |
275 exp->func_index, | 282 exp->func_index, |
276 static_cast<int>(module->functions.size())); | 283 static_cast<int>(module->functions.size())); |
277 } | 284 } |
278 exp->name_offset = consume_string("export name"); | 285 exp->name_offset = consume_string("export name"); |
279 } | 286 } |
280 break; | 287 break; |
281 } | 288 } |
282 case kDeclWLL: { | 289 case kMaxModuleSectionCode: |
283 // Reserved for experimentation by the Web Low-level Language project | 290 UNREACHABLE(); // Already skipped unknown sections. |
284 // which is augmenting the binary encoding with source code meta | |
285 // information. This section does not affect the semantics of the code | |
286 // and can be ignored by the runtime. https://github.com/JSStats/wll | |
287 int length = 0; | |
288 uint32_t section_size = consume_u32v(&length, "section size"); | |
289 if (pc_ + section_size > limit_ || pc_ + section_size < pc_) { | |
290 error(pc_ - length, "invalid section size"); | |
291 break; | |
292 } | |
293 pc_ += section_size; | |
294 break; | |
295 } | |
296 default: | |
297 error(pc_ - 1, nullptr, "unrecognized section 0x%02x", section); | |
298 break; | |
299 } | 291 } |
300 } | 292 } |
301 | 293 |
302 return toResult(module); | 294 return toResult(module); |
303 } | 295 } |
304 | 296 |
305 uint32_t SafeReserve(uint32_t count) { | 297 uint32_t SafeReserve(uint32_t count) { |
306 // Avoid OOM by only reserving up to a certain size. | 298 // Avoid OOM by only reserving up to a certain size. |
307 const uint32_t kMaxReserve = 20000; | 299 const uint32_t kMaxReserve = 20000; |
308 return count < kMaxReserve ? count : kMaxReserve; | 300 return count < kMaxReserve ? count : kMaxReserve; |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 if (function_start > function_end) return FunctionError("start > end"); | 644 if (function_start > function_end) return FunctionError("start > end"); |
653 if (size > kMaxFunctionSize) | 645 if (size > kMaxFunctionSize) |
654 return FunctionError("size > maximum function size"); | 646 return FunctionError("size > maximum function size"); |
655 WasmFunction* function = new WasmFunction(); | 647 WasmFunction* function = new WasmFunction(); |
656 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); | 648 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); |
657 return decoder.DecodeSingleFunction(module_env, function); | 649 return decoder.DecodeSingleFunction(module_env, function); |
658 } | 650 } |
659 } // namespace wasm | 651 } // namespace wasm |
660 } // namespace internal | 652 } // namespace internal |
661 } // namespace v8 | 653 } // namespace v8 |
OLD | NEW |