Chromium Code Reviews| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 module->max_mem_size_log2 = 0; | 49 module->max_mem_size_log2 = 0; |
| 50 module->mem_export = false; | 50 module->mem_export = false; |
| 51 module->mem_external = false; | 51 module->mem_external = false; |
| 52 module->globals = new std::vector<WasmGlobal>(); | 52 module->globals = new std::vector<WasmGlobal>(); |
| 53 module->signatures = new std::vector<FunctionSig*>(); | 53 module->signatures = new std::vector<FunctionSig*>(); |
| 54 module->functions = new std::vector<WasmFunction>(); | 54 module->functions = new std::vector<WasmFunction>(); |
| 55 module->data_segments = new std::vector<WasmDataSegment>(); | 55 module->data_segments = new std::vector<WasmDataSegment>(); |
| 56 module->function_table = new std::vector<uint16_t>(); | 56 module->function_table = new std::vector<uint16_t>(); |
| 57 module->import_table = new std::vector<WasmImport>(); | 57 module->import_table = new std::vector<WasmImport>(); |
| 58 | 58 |
| 59 bool sections[kMaxModuleSectionCode]; | 59 bool sections[kMaxModuleSectionCode] = {false}; |
| 60 memset(sections, 0, sizeof(sections)); | |
| 61 | 60 |
| 62 // Decode the module sections. | 61 // Decode the module sections. |
| 63 while (pc_ < limit_) { | 62 while (pc_ < limit_ && !failed()) { |
| 64 TRACE("DecodeSection\n"); | 63 TRACE("DecodeSection\n"); |
| 65 WasmSectionDeclCode section = | 64 uint8_t section_u8 = consume_u8("section"); |
| 66 static_cast<WasmSectionDeclCode>(consume_u8("section")); | 65 |
| 66 if (section_u8 >= kMaxModuleSectionCode) { | |
| 67 // Skip unknown section. | |
| 68 int length; | |
| 69 for (uint32_t section_bytes = consume_u32v(&length, "globals count"); | |
|
titzer
2016/02/26 22:54:17
s/globals count/section size/
JF
2016/02/26 23:42:41
Done.
| |
| 70 section_bytes; --section_bytes) { | |
| 71 if (failed()) break; | |
| 72 (void)consume_u8("unknown section byte"); | |
|
titzer
2016/02/26 22:54:17
You can just consume the length and then increment
JF
2016/02/26 23:42:41
Done.
| |
| 73 } | |
| 74 continue; | |
| 75 } | |
| 76 | |
| 67 // Each section should appear at most once. | 77 // Each section should appear at most once. |
| 68 if (section < kMaxModuleSectionCode) { | 78 auto section = static_cast<WasmSectionDeclCode>(section_u8); |
| 69 CheckForPreviousSection(sections, section, false); | 79 CheckForPreviousSection(sections, section, false); |
| 70 sections[section] = true; | 80 sections[section] = true; |
| 71 } | |
| 72 | 81 |
| 73 switch (section) { | 82 switch (section) { |
| 74 case kDeclEnd: | 83 case kDeclEnd: |
| 75 // Terminate section decoding. | 84 // Terminate section decoding. |
| 76 limit_ = pc_; | 85 limit_ = pc_; |
| 77 break; | 86 break; |
| 78 case kDeclMemory: | 87 case kDeclMemory: |
| 79 module->min_mem_size_log2 = consume_u8("min memory"); | 88 module->min_mem_size_log2 = consume_u8("min memory"); |
| 80 module->max_mem_size_log2 = consume_u8("max memory"); | 89 module->max_mem_size_log2 = consume_u8("max memory"); |
| 81 module->mem_export = consume_u8("export memory") != 0; | 90 module->mem_export = consume_u8("export memory") != 0; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 error(sigpos, "invalid signature index"); | 236 error(sigpos, "invalid signature index"); |
| 228 } else { | 237 } else { |
| 229 import->sig = module->signatures->at(import->sig_index); | 238 import->sig = module->signatures->at(import->sig_index); |
| 230 } | 239 } |
| 231 import->module_name_offset = consume_string("import module name"); | 240 import->module_name_offset = consume_string("import module name"); |
| 232 import->function_name_offset = | 241 import->function_name_offset = |
| 233 consume_string("import function name"); | 242 consume_string("import function name"); |
| 234 } | 243 } |
| 235 break; | 244 break; |
| 236 } | 245 } |
| 237 case kDeclWLL: { | 246 case kMaxModuleSectionCode: |
| 238 // Reserved for experimentation by the Web Low-level Language project | 247 UNREACHABLE(); // Already skipped unknown sections. |
| 239 // which is augmenting the binary encoding with source code meta | |
| 240 // information. This section does not affect the semantics of the code | |
| 241 // and can be ignored by the runtime. https://github.com/JSStats/wll | |
| 242 int length = 0; | |
| 243 uint32_t section_size = consume_u32v(&length, "section size"); | |
| 244 if (pc_ + section_size > limit_ || pc_ + section_size < pc_) { | |
| 245 error(pc_ - length, "invalid section size"); | |
| 246 break; | |
| 247 } | |
| 248 pc_ += section_size; | |
| 249 break; | |
| 250 } | |
| 251 default: | |
| 252 error(pc_ - 1, nullptr, "unrecognized section 0x%02x", section); | |
| 253 break; | |
| 254 } | 248 } |
| 255 } | 249 } |
| 256 | 250 |
| 257 return toResult(module); | 251 return toResult(module); |
| 258 } | 252 } |
| 259 | 253 |
| 260 uint32_t SafeReserve(uint32_t count) { | 254 uint32_t SafeReserve(uint32_t count) { |
| 261 // Avoid OOM by only reserving up to a certain size. | 255 // Avoid OOM by only reserving up to a certain size. |
| 262 const uint32_t kMaxReserve = 20000; | 256 const uint32_t kMaxReserve = 20000; |
| 263 return count < kMaxReserve ? count : kMaxReserve; | 257 return count < kMaxReserve ? count : kMaxReserve; |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 if (function_start > function_end) return FunctionError("start > end"); | 601 if (function_start > function_end) return FunctionError("start > end"); |
| 608 if (size > kMaxFunctionSize) | 602 if (size > kMaxFunctionSize) |
| 609 return FunctionError("size > maximum function size"); | 603 return FunctionError("size > maximum function size"); |
| 610 WasmFunction* function = new WasmFunction(); | 604 WasmFunction* function = new WasmFunction(); |
| 611 ModuleDecoder decoder(zone, function_start, function_end, false); | 605 ModuleDecoder decoder(zone, function_start, function_end, false); |
| 612 return decoder.DecodeSingleFunction(module_env, function); | 606 return decoder.DecodeSingleFunction(module_env, function); |
| 613 } | 607 } |
| 614 } // namespace wasm | 608 } // namespace wasm |
| 615 } // namespace internal | 609 } // namespace internal |
| 616 } // namespace v8 | 610 } // namespace v8 |
| OLD | NEW |