| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 menv.module = module; | 104 menv.module = module; |
| 105 menv.instance = nullptr; | 105 menv.instance = nullptr; |
| 106 menv.asm_js = asm_js_; | 106 menv.asm_js = asm_js_; |
| 107 // Decode functions. | 107 // Decode functions. |
| 108 for (uint32_t i = 0; i < functions_count; i++) { | 108 for (uint32_t i = 0; i < functions_count; i++) { |
| 109 if (failed()) break; | 109 if (failed()) break; |
| 110 TRACE("DecodeFunction[%d] module+%d\n", i, | 110 TRACE("DecodeFunction[%d] module+%d\n", i, |
| 111 static_cast<int>(pc_ - start_)); | 111 static_cast<int>(pc_ - start_)); |
| 112 | 112 |
| 113 module->functions->push_back( | 113 module->functions->push_back( |
| 114 {nullptr, 0, 0, 0, 0, 0, 0, false, false}); | 114 {nullptr, i, 0, 0, 0, 0, 0, 0, false, false}); |
| 115 WasmFunction* function = &module->functions->back(); | 115 WasmFunction* function = &module->functions->back(); |
| 116 DecodeFunctionInModule(module, function, false); | 116 DecodeFunctionInModule(module, function, false); |
| 117 } | 117 } |
| 118 if (ok() && verify_functions) { | 118 if (ok() && verify_functions) { |
| 119 for (uint32_t i = 0; i < functions_count; i++) { | 119 for (uint32_t i = 0; i < functions_count; i++) { |
| 120 if (failed()) break; | 120 if (failed()) break; |
| 121 WasmFunction* function = &module->functions->at(i); | 121 WasmFunction* function = &module->functions->at(i); |
| 122 if (!function->external) { | 122 if (!function->external) { |
| 123 VerifyFunctionBody(i, &menv, function); | 123 VerifyFunctionBody(i, &menv, function); |
| 124 if (result_.failed()) | 124 if (result_.failed()) |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 if (!IsWithinLimit(memory_limit, segment->dest_addr, | 393 if (!IsWithinLimit(memory_limit, segment->dest_addr, |
| 394 segment->source_size)) { | 394 segment->source_size)) { |
| 395 error(pc_ - sizeof(uint32_t), "segment out of bounds of memory"); | 395 error(pc_ - sizeof(uint32_t), "segment out of bounds of memory"); |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 // Verifies the body (code) of a given function. | 399 // Verifies the body (code) of a given function. |
| 400 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv, | 400 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv, |
| 401 WasmFunction* function) { | 401 WasmFunction* function) { |
| 402 if (FLAG_trace_wasm_decode_time) { | 402 if (FLAG_trace_wasm_decode_time) { |
| 403 // TODO(titzer): clean me up a bit. | |
| 404 OFStream os(stdout); | 403 OFStream os(stdout); |
| 405 os << "Verifying WASM function:"; | 404 os << "Verifying WASM function " << WasmFunctionName(function, menv) |
| 406 if (function->name_offset > 0) { | 405 << std::endl; |
| 407 os << menv->module->GetName(function->name_offset); | |
| 408 } | |
| 409 os << std::endl; | 406 os << std::endl; |
| 410 } | 407 } |
| 411 FunctionEnv fenv; | 408 FunctionEnv fenv; |
| 412 fenv.module = menv; | 409 fenv.module = menv; |
| 413 fenv.sig = function->sig; | 410 fenv.sig = function->sig; |
| 414 fenv.local_i32_count = function->local_i32_count; | 411 fenv.local_i32_count = function->local_i32_count; |
| 415 fenv.local_i64_count = function->local_i64_count; | 412 fenv.local_i64_count = function->local_i64_count; |
| 416 fenv.local_f32_count = function->local_f32_count; | 413 fenv.local_f32_count = function->local_f32_count; |
| 417 fenv.local_f64_count = function->local_f64_count; | 414 fenv.local_f64_count = function->local_f64_count; |
| 418 fenv.SumLocals(); | 415 fenv.SumLocals(); |
| 419 | 416 |
| 420 TreeResult result = | 417 TreeResult result = |
| 421 VerifyWasmCode(&fenv, start_, start_ + function->code_start_offset, | 418 VerifyWasmCode(&fenv, start_, start_ + function->code_start_offset, |
| 422 start_ + function->code_end_offset); | 419 start_ + function->code_end_offset); |
| 423 if (result.failed()) { | 420 if (result.failed()) { |
| 424 // Wrap the error message from the function decoder. | 421 // Wrap the error message from the function decoder. |
| 425 std::ostringstream str; | 422 std::ostringstream str; |
| 426 str << "in function #" << func_num << ": "; | 423 str << "in function " << WasmFunctionName(function, menv) << ": "; |
| 427 // TODO(titzer): add function name for the user? | |
| 428 str << result; | 424 str << result; |
| 429 std::string strval = str.str(); | 425 std::string strval = str.str(); |
| 430 const char* raw = strval.c_str(); | 426 const char* raw = strval.c_str(); |
| 431 size_t len = strlen(raw); | 427 size_t len = strlen(raw); |
| 432 char* buffer = new char[len]; | 428 char* buffer = new char[len]; |
| 433 strncpy(buffer, raw, len); | 429 strncpy(buffer, raw, len); |
| 434 buffer[len - 1] = 0; | 430 buffer[len - 1] = 0; |
| 435 | 431 |
| 436 // Copy error code and location. | 432 // Copy error code and location. |
| 437 result_.CopyFrom(result); | 433 result_.CopyFrom(result); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 if (function_start > function_end) return FunctionError("start > end"); | 576 if (function_start > function_end) return FunctionError("start > end"); |
| 581 if (size > kMaxFunctionSize) | 577 if (size > kMaxFunctionSize) |
| 582 return FunctionError("size > maximum function size"); | 578 return FunctionError("size > maximum function size"); |
| 583 WasmFunction* function = new WasmFunction(); | 579 WasmFunction* function = new WasmFunction(); |
| 584 ModuleDecoder decoder(zone, function_start, function_end, false); | 580 ModuleDecoder decoder(zone, function_start, function_end, false); |
| 585 return decoder.DecodeSingleFunction(module_env, function); | 581 return decoder.DecodeSingleFunction(module_env, function); |
| 586 } | 582 } |
| 587 } // namespace wasm | 583 } // namespace wasm |
| 588 } // namespace internal | 584 } // namespace internal |
| 589 } // namespace v8 | 585 } // namespace v8 |
| OLD | NEW |