| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 i, // func_index | 169 i, // func_index |
| 170 0, // sig_index | 170 0, // sig_index |
| 171 0, // name_offset | 171 0, // name_offset |
| 172 0, // name_length | 172 0, // name_length |
| 173 0, // code_start_offset | 173 0, // code_start_offset |
| 174 0, // code_end_offset | 174 0, // code_end_offset |
| 175 0, // local_i32_count | 175 0, // local_i32_count |
| 176 0, // local_i64_count | 176 0, // local_i64_count |
| 177 0, // local_f32_count | 177 0, // local_f32_count |
| 178 0, // local_f64_count | 178 0, // local_f64_count |
| 179 false, // exported | 179 false}); // exported |
| 180 false}); // external | |
| 181 WasmFunction* function = &module->functions.back(); | 180 WasmFunction* function = &module->functions.back(); |
| 182 function->sig_index = consume_sig_index(module, &function->sig); | 181 function->sig_index = consume_sig_index(module, &function->sig); |
| 183 } | 182 } |
| 184 break; | 183 break; |
| 185 } | 184 } |
| 186 case WasmSection::Code::FunctionBodies: { | 185 case WasmSection::Code::FunctionBodies: { |
| 187 int length; | 186 int length; |
| 188 const byte* pos = pc_; | 187 const byte* pos = pc_; |
| 189 uint32_t functions_count = consume_u32v(&length, "functions count"); | 188 uint32_t functions_count = consume_u32v(&length, "functions count"); |
| 190 if (functions_count != module->functions.size()) { | 189 if (functions_count != module->functions.size()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 i, // func_index | 227 i, // func_index |
| 229 0, // sig_index | 228 0, // sig_index |
| 230 0, // name_offset | 229 0, // name_offset |
| 231 0, // name_length | 230 0, // name_length |
| 232 0, // code_start_offset | 231 0, // code_start_offset |
| 233 0, // code_end_offset | 232 0, // code_end_offset |
| 234 0, // local_i32_count | 233 0, // local_i32_count |
| 235 0, // local_i64_count | 234 0, // local_i64_count |
| 236 0, // local_f32_count | 235 0, // local_f32_count |
| 237 0, // local_f64_count | 236 0, // local_f64_count |
| 238 false, // exported | 237 false}); // exported |
| 239 false}); // external | |
| 240 WasmFunction* function = &module->functions.back(); | 238 WasmFunction* function = &module->functions.back(); |
| 241 DecodeFunctionInModule(module, function, false); | 239 DecodeFunctionInModule(module, function, false); |
| 242 } | 240 } |
| 243 if (ok() && verify_functions) { | 241 if (ok() && verify_functions) { |
| 244 for (uint32_t i = 0; i < functions_count; i++) { | 242 for (uint32_t i = 0; i < functions_count; i++) { |
| 245 if (failed()) break; | 243 if (failed()) break; |
| 246 WasmFunction* function = &module->functions[i]; | 244 WasmFunction* function = &module->functions[i]; |
| 247 if (!function->external) { | 245 VerifyFunctionBody(i, &menv, function); |
| 248 VerifyFunctionBody(i, &menv, function); | 246 if (result_.failed()) { |
| 249 if (result_.failed()) | 247 error(result_.error_pc, result_.error_msg.get()); |
| 250 error(result_.error_pc, result_.error_msg.get()); | |
| 251 } | 248 } |
| 252 } | 249 } |
| 253 } | 250 } |
| 254 break; | 251 break; |
| 255 } | 252 } |
| 256 case WasmSection::Code::Names: { | 253 case WasmSection::Code::Names: { |
| 257 int length; | 254 int length; |
| 258 const byte* pos = pc_; | 255 const byte* pos = pc_; |
| 259 uint32_t functions_count = consume_u32v(&length, "functions count"); | 256 uint32_t functions_count = consume_u32v(&length, "functions count"); |
| 260 if (functions_count != module->functions.size()) { | 257 if (functions_count != module->functions.size()) { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // Decodes a single anonymous function starting at {start_}. | 464 // Decodes a single anonymous function starting at {start_}. |
| 468 FunctionResult DecodeSingleFunction(ModuleEnv* module_env, | 465 FunctionResult DecodeSingleFunction(ModuleEnv* module_env, |
| 469 WasmFunction* function) { | 466 WasmFunction* function) { |
| 470 pc_ = start_; | 467 pc_ = start_; |
| 471 function->sig = consume_sig(); // read signature | 468 function->sig = consume_sig(); // read signature |
| 472 function->name_offset = 0; // ---- name | 469 function->name_offset = 0; // ---- name |
| 473 function->name_length = 0; // ---- name length | 470 function->name_length = 0; // ---- name length |
| 474 function->code_start_offset = off(pc_); // ---- code start | 471 function->code_start_offset = off(pc_); // ---- code start |
| 475 function->code_end_offset = off(limit_); // ---- code end | 472 function->code_end_offset = off(limit_); // ---- code end |
| 476 function->exported = false; // ---- exported | 473 function->exported = false; // ---- exported |
| 477 function->external = false; // ---- external | |
| 478 | 474 |
| 479 if (ok()) VerifyFunctionBody(0, module_env, function); | 475 if (ok()) VerifyFunctionBody(0, module_env, function); |
| 480 | 476 |
| 481 FunctionResult result; | 477 FunctionResult result; |
| 482 result.CopyFrom(result_); // Copy error code and location. | 478 result.CopyFrom(result_); // Copy error code and location. |
| 483 result.val = function; | 479 result.val = function; |
| 484 return result; | 480 return result; |
| 485 } | 481 } |
| 486 | 482 |
| 487 // Decodes a single function signature at {start}. | 483 // Decodes a single function signature at {start}. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 516 | 512 |
| 517 const byte* sigpos = pc_; | 513 const byte* sigpos = pc_; |
| 518 function->sig_index = consume_u16("signature index"); | 514 function->sig_index = consume_u16("signature index"); |
| 519 | 515 |
| 520 if (function->sig_index >= module->signatures.size()) { | 516 if (function->sig_index >= module->signatures.size()) { |
| 521 return error(sigpos, "invalid signature index"); | 517 return error(sigpos, "invalid signature index"); |
| 522 } else { | 518 } else { |
| 523 function->sig = module->signatures[function->sig_index]; | 519 function->sig = module->signatures[function->sig_index]; |
| 524 } | 520 } |
| 525 | 521 |
| 526 TRACE(" +%d <function attributes:%s%s%s%s%s>\n", | 522 TRACE(" +%d <function attributes:%s%s%s>\n", |
| 527 static_cast<int>(pc_ - start_), | 523 static_cast<int>(pc_ - start_), |
| 528 decl_bits & kDeclFunctionName ? " name" : "", | 524 decl_bits & kDeclFunctionName ? " name" : "", |
| 529 decl_bits & kDeclFunctionImport ? " imported" : "", | |
| 530 decl_bits & kDeclFunctionLocals ? " locals" : "", | 525 decl_bits & kDeclFunctionLocals ? " locals" : "", |
| 531 decl_bits & kDeclFunctionExport ? " exported" : "", | 526 decl_bits & kDeclFunctionExport ? " exported" : ""); |
| 532 (decl_bits & kDeclFunctionImport) == 0 ? " body" : ""); | |
| 533 | 527 |
| 534 function->exported = decl_bits & kDeclFunctionExport; | 528 function->exported = decl_bits & kDeclFunctionExport; |
| 535 | 529 |
| 536 if (decl_bits & kDeclFunctionName) { | 530 if (decl_bits & kDeclFunctionName) { |
| 537 function->name_offset = | 531 function->name_offset = |
| 538 consume_string(&function->name_length, function->exported); | 532 consume_string(&function->name_length, function->exported); |
| 539 } | 533 } |
| 540 | 534 |
| 541 // Imported functions have no locals or body. | |
| 542 if (decl_bits & kDeclFunctionImport) { | |
| 543 function->external = true; | |
| 544 return; | |
| 545 } | |
| 546 | |
| 547 if (decl_bits & kDeclFunctionLocals) { | 535 if (decl_bits & kDeclFunctionLocals) { |
| 548 function->local_i32_count = consume_u16("i32 count"); | 536 function->local_i32_count = consume_u16("i32 count"); |
| 549 function->local_i64_count = consume_u16("i64 count"); | 537 function->local_i64_count = consume_u16("i64 count"); |
| 550 function->local_f32_count = consume_u16("f32 count"); | 538 function->local_f32_count = consume_u16("f32 count"); |
| 551 function->local_f64_count = consume_u16("f64 count"); | 539 function->local_f64_count = consume_u16("f64 count"); |
| 552 } | 540 } |
| 553 | 541 |
| 554 uint16_t size = consume_u16("body size"); | 542 uint16_t size = consume_u16("body size"); |
| 555 if (ok()) { | 543 if (ok()) { |
| 556 if ((pc_ + size) > limit_) { | 544 if ((pc_ + size) > limit_) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 return FunctionError("size > maximum function size"); | 831 return FunctionError("size > maximum function size"); |
| 844 isolate->counters()->wasm_function_size_bytes()->AddSample( | 832 isolate->counters()->wasm_function_size_bytes()->AddSample( |
| 845 static_cast<int>(size)); | 833 static_cast<int>(size)); |
| 846 WasmFunction* function = new WasmFunction(); | 834 WasmFunction* function = new WasmFunction(); |
| 847 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); | 835 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); |
| 848 return decoder.DecodeSingleFunction(module_env, function); | 836 return decoder.DecodeSingleFunction(module_env, function); |
| 849 } | 837 } |
| 850 } // namespace wasm | 838 } // namespace wasm |
| 851 } // namespace internal | 839 } // namespace internal |
| 852 } // namespace v8 | 840 } // namespace v8 |
| OLD | NEW |