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/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 static_cast<int>(pc_ - start_)); | 263 static_cast<int>(pc_ - start_)); |
264 module->data_segments.push_back({0, // dest_addr | 264 module->data_segments.push_back({0, // dest_addr |
265 0, // source_offset | 265 0, // source_offset |
266 0, // source_size | 266 0, // source_size |
267 false}); // init | 267 false}); // init |
268 WasmDataSegment* segment = &module->data_segments.back(); | 268 WasmDataSegment* segment = &module->data_segments.back(); |
269 DecodeDataSegmentInModule(module, segment); | 269 DecodeDataSegmentInModule(module, segment); |
270 } | 270 } |
271 break; | 271 break; |
272 } | 272 } |
| 273 case WasmSection::Code::FunctionTablePad: { |
| 274 if (!FLAG_wasm_jit_prototype) { |
| 275 error("FunctionTablePad section without jiting enabled"); |
| 276 } |
| 277 // An indirect function table requires functions first. |
| 278 int length; |
| 279 module->indirect_table_size = |
| 280 consume_u32v(&length, "indirect entry count"); |
| 281 if (module->indirect_table_size > 0 && |
| 282 module->indirect_table_size < module->function_table.size()) { |
| 283 error("more predefined indirect entries than table can hold"); |
| 284 } |
| 285 break; |
| 286 } |
273 case WasmSection::Code::FunctionTable: { | 287 case WasmSection::Code::FunctionTable: { |
274 // An indirect function table requires functions first. | 288 // An indirect function table requires functions first. |
275 CheckForFunctions(module, section); | 289 CheckForFunctions(module, section); |
276 int length; | 290 int length; |
277 uint32_t function_table_count = | 291 uint32_t function_table_count = |
278 consume_u32v(&length, "function table count"); | 292 consume_u32v(&length, "function table count"); |
279 module->function_table.reserve(SafeReserve(function_table_count)); | 293 module->function_table.reserve(SafeReserve(function_table_count)); |
280 // Decode function table. | 294 // Decode function table. |
281 for (uint32_t i = 0; i < function_table_count; i++) { | 295 for (uint32_t i = 0; i < function_table_count; i++) { |
282 if (failed()) break; | 296 if (failed()) break; |
283 TRACE("DecodeFunctionTable[%d] module+%d\n", i, | 297 TRACE("DecodeFunctionTable[%d] module+%d\n", i, |
284 static_cast<int>(pc_ - start_)); | 298 static_cast<int>(pc_ - start_)); |
285 uint16_t index = consume_u32v(&length); | 299 uint16_t index = consume_u32v(&length); |
286 if (index >= module->functions.size()) { | 300 if (index >= module->functions.size()) { |
287 error(pc_ - 2, "invalid function index"); | 301 error(pc_ - 2, "invalid function index"); |
288 break; | 302 break; |
289 } | 303 } |
290 module->function_table.push_back(index); | 304 module->function_table.push_back(index); |
291 } | 305 } |
| 306 if (module->indirect_table_size > 0 && |
| 307 module->indirect_table_size < module->function_table.size()) { |
| 308 error("more predefined indirect entries than table can hold"); |
| 309 } |
292 break; | 310 break; |
293 } | 311 } |
294 case WasmSection::Code::StartFunction: { | 312 case WasmSection::Code::StartFunction: { |
295 // Declares a start function for a module. | 313 // Declares a start function for a module. |
296 CheckForFunctions(module, section); | 314 CheckForFunctions(module, section); |
297 if (module->start_function_index >= 0) { | 315 if (module->start_function_index >= 0) { |
298 error("start function already declared"); | 316 error("start function already declared"); |
299 break; | 317 break; |
300 } | 318 } |
301 WasmFunction* func; | 319 WasmFunction* func; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 it->name_length, pc, last->func_index, it->func_index); | 402 it->name_length, pc, last->func_index, it->func_index); |
385 break; | 403 break; |
386 } | 404 } |
387 } | 405 } |
388 } | 406 } |
389 break; | 407 break; |
390 } | 408 } |
391 case WasmSection::Code::Max: | 409 case WasmSection::Code::Max: |
392 // Skip unknown sections. | 410 // Skip unknown sections. |
393 TRACE("Unknown section: '"); | 411 TRACE("Unknown section: '"); |
394 for (uint32_t i = 0; i != string_length; ++i) { | 412 for (uint32_t i = 0; i != string_length; i++) { |
395 TRACE("%c", *(section_name_start + i)); | 413 TRACE("%c", *(section_name_start + i)); |
396 } | 414 } |
397 TRACE("'\n"); | 415 TRACE("'\n"); |
398 consume_bytes(section_length); | 416 consume_bytes(section_length); |
399 break; | 417 break; |
400 } | 418 } |
401 | 419 |
402 if (pc_ != expected_section_end) { | 420 if (pc_ != expected_section_end) { |
403 const char* diff = pc_ < expected_section_end ? "shorter" : "longer"; | 421 const char* diff = pc_ < expected_section_end ? "shorter" : "longer"; |
404 size_t expected_length = static_cast<size_t>(section_length); | 422 size_t expected_length = static_cast<size_t>(section_length); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 decoder.consume_bytes(size); | 871 decoder.consume_bytes(size); |
854 } | 872 } |
855 if (decoder.more()) decoder.error("unexpected additional bytes"); | 873 if (decoder.more()) decoder.error("unexpected additional bytes"); |
856 | 874 |
857 return decoder.toResult(std::move(table)); | 875 return decoder.toResult(std::move(table)); |
858 } | 876 } |
859 | 877 |
860 } // namespace wasm | 878 } // namespace wasm |
861 } // namespace internal | 879 } // namespace internal |
862 } // namespace v8 | 880 } // namespace v8 |
OLD | NEW |