| 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 error(pc_ - 1, nullptr, "required %s section missing", name); | 339 error(pc_ - 1, nullptr, "required %s section missing", name); |
| 340 } else { | 340 } else { |
| 341 error(pc_ - 1, nullptr, "%s section already present", name); | 341 error(pc_ - 1, nullptr, "%s section already present", name); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Decodes a single anonymous function starting at {start_}. | 345 // Decodes a single anonymous function starting at {start_}. |
| 346 FunctionResult DecodeSingleFunction(ModuleEnv* module_env, | 346 FunctionResult DecodeSingleFunction(ModuleEnv* module_env, |
| 347 WasmFunction* function) { | 347 WasmFunction* function) { |
| 348 pc_ = start_; | 348 pc_ = start_; |
| 349 function->sig = consume_sig(); // read signature | 349 function->sig = consume_sig(); // read signature |
| 350 function->name_offset = 0; // ---- name | 350 function->name_offset = 0; // ---- name |
| 351 function->code_start_offset = off(pc_ + 8); // ---- code start | 351 function->code_start_offset = off(pc_); // ---- code start |
| 352 function->code_end_offset = off(limit_); // ---- code end | 352 function->code_end_offset = off(limit_); // ---- code end |
| 353 function->local_i32_count = consume_u16(); // read u16 | |
| 354 function->local_i64_count = consume_u16(); // read u16 | |
| 355 function->local_f32_count = consume_u16(); // read u16 | |
| 356 function->local_f64_count = consume_u16(); // read u16 | |
| 357 function->exported = false; // ---- exported | 353 function->exported = false; // ---- exported |
| 358 function->external = false; // ---- external | 354 function->external = false; // ---- external |
| 359 | 355 |
| 360 if (ok()) VerifyFunctionBody(0, module_env, function); | 356 if (ok()) VerifyFunctionBody(0, module_env, function); |
| 361 | 357 |
| 362 FunctionResult result; | 358 FunctionResult result; |
| 363 result.CopyFrom(result_); // Copy error code and location. | 359 result.CopyFrom(result_); // Copy error code and location. |
| 364 result.val = function; | 360 result.val = function; |
| 365 return result; | 361 return result; |
| 366 } | 362 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 469 |
| 474 // Verifies the body (code) of a given function. | 470 // Verifies the body (code) of a given function. |
| 475 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv, | 471 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv, |
| 476 WasmFunction* function) { | 472 WasmFunction* function) { |
| 477 if (FLAG_trace_wasm_decode_time) { | 473 if (FLAG_trace_wasm_decode_time) { |
| 478 OFStream os(stdout); | 474 OFStream os(stdout); |
| 479 os << "Verifying WASM function " << WasmFunctionName(function, menv) | 475 os << "Verifying WASM function " << WasmFunctionName(function, menv) |
| 480 << std::endl; | 476 << std::endl; |
| 481 os << std::endl; | 477 os << std::endl; |
| 482 } | 478 } |
| 483 FunctionEnv fenv; | 479 FunctionBody body = {menv, function->sig, start_, |
| 484 fenv.module = menv; | 480 start_ + function->code_start_offset, |
| 485 fenv.sig = function->sig; | 481 start_ + function->code_end_offset}; |
| 486 fenv.local_i32_count = function->local_i32_count; | 482 TreeResult result = VerifyWasmCode(body); |
| 487 fenv.local_i64_count = function->local_i64_count; | |
| 488 fenv.local_f32_count = function->local_f32_count; | |
| 489 fenv.local_f64_count = function->local_f64_count; | |
| 490 fenv.SumLocals(); | |
| 491 | |
| 492 TreeResult result = | |
| 493 VerifyWasmCode(&fenv, start_, start_ + function->code_start_offset, | |
| 494 start_ + function->code_end_offset); | |
| 495 if (result.failed()) { | 483 if (result.failed()) { |
| 496 // Wrap the error message from the function decoder. | 484 // Wrap the error message from the function decoder. |
| 497 std::ostringstream str; | 485 std::ostringstream str; |
| 498 str << "in function " << WasmFunctionName(function, menv) << ": "; | 486 str << "in function " << WasmFunctionName(function, menv) << ": "; |
| 499 str << result; | 487 str << result; |
| 500 std::string strval = str.str(); | 488 std::string strval = str.str(); |
| 501 const char* raw = strval.c_str(); | 489 const char* raw = strval.c_str(); |
| 502 size_t len = strlen(raw); | 490 size_t len = strlen(raw); |
| 503 char* buffer = new char[len]; | 491 char* buffer = new char[len]; |
| 504 strncpy(buffer, raw, len); | 492 strncpy(buffer, raw, len); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 if (function_start > function_end) return FunctionError("start > end"); | 638 if (function_start > function_end) return FunctionError("start > end"); |
| 651 if (size > kMaxFunctionSize) | 639 if (size > kMaxFunctionSize) |
| 652 return FunctionError("size > maximum function size"); | 640 return FunctionError("size > maximum function size"); |
| 653 WasmFunction* function = new WasmFunction(); | 641 WasmFunction* function = new WasmFunction(); |
| 654 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); | 642 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); |
| 655 return decoder.DecodeSingleFunction(module_env, function); | 643 return decoder.DecodeSingleFunction(module_env, function); |
| 656 } | 644 } |
| 657 } // namespace wasm | 645 } // namespace wasm |
| 658 } // namespace internal | 646 } // namespace internal |
| 659 } // namespace v8 | 647 } // namespace v8 |
| OLD | NEW |