Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "include/v8.h" | 8 #include "include/v8.h" |
| 9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
| 10 #include "src/wasm/encoder.h" | 10 #include "src/wasm/encoder.h" |
| 11 #include "src/wasm/wasm-interpreter.h" | |
| 11 #include "src/wasm/wasm-js.h" | 12 #include "src/wasm/wasm-js.h" |
| 12 #include "src/wasm/wasm-module.h" | 13 #include "src/wasm/wasm-module.h" |
| 13 #include "test/cctest/wasm/test-signatures.h" | 14 #include "test/cctest/wasm/test-signatures.h" |
| 15 #include "test/cctest/wasm/wasm-module-runner.h" | |
| 14 #include "test/fuzzer/fuzzer-support.h" | 16 #include "test/fuzzer/fuzzer-support.h" |
| 15 | 17 |
| 16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 17 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); | 19 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); |
| 18 v8::Isolate* isolate = support->GetIsolate(); | 20 v8::Isolate* isolate = support->GetIsolate(); |
| 19 v8::internal::Isolate* i_isolate = | 21 v8::internal::Isolate* i_isolate = |
| 20 reinterpret_cast<v8::internal::Isolate*>(isolate); | 22 reinterpret_cast<v8::internal::Isolate*>(isolate); |
| 21 | 23 |
| 22 // Clear any pending exceptions from a prior run. | 24 // Clear any pending exceptions from a prior run. |
| 23 if (i_isolate->has_pending_exception()) { | 25 if (i_isolate->has_pending_exception()) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 41 f->SetSignature(sigs.i_iii()); | 43 f->SetSignature(sigs.i_iii()); |
| 42 f->EmitCode(data, static_cast<uint32_t>(size)); | 44 f->EmitCode(data, static_cast<uint32_t>(size)); |
| 43 f->SetExported(); | 45 f->SetExported(); |
| 44 f->SetName("main", 4); | 46 f->SetName("main", 4); |
| 45 | 47 |
| 46 v8::internal::wasm::ZoneBuffer buffer(&zone); | 48 v8::internal::wasm::ZoneBuffer buffer(&zone); |
| 47 builder.WriteTo(buffer); | 49 builder.WriteTo(buffer); |
| 48 | 50 |
| 49 v8::internal::WasmJs::InstallWasmFunctionMap(i_isolate, | 51 v8::internal::WasmJs::InstallWasmFunctionMap(i_isolate, |
| 50 i_isolate->native_context()); | 52 i_isolate->native_context()); |
| 51 v8::internal::wasm::testing::CompileAndRunWasmModule( | 53 |
| 52 i_isolate, buffer.begin(), buffer.end(), false); | 54 v8::internal::HandleScope scope(i_isolate); |
| 55 | |
| 56 v8::internal::wasm::ErrorThrower interpreter_thrower(i_isolate, | |
|
titzer
2016/09/12 11:46:21
Nit: use a "using v8::internal::wasm" to shorten t
| |
| 57 "Interpreter"); | |
| 58 std::unique_ptr<const v8::internal::wasm::WasmModule> module( | |
| 59 v8::internal::wasm::testing::DecodeWasmModuleForTesting( | |
| 60 i_isolate, &zone, interpreter_thrower, buffer.begin(), buffer.end(), | |
| 61 v8::internal::wasm::kWasmOrigin)); | |
| 62 | |
| 63 if (module == nullptr) { | |
| 64 return 0; | |
| 65 } | |
| 66 int32_t result_interpreted; | |
| 67 { | |
| 68 v8::internal::wasm::WasmVal args[] = {v8::internal::wasm::WasmVal(1), | |
| 69 v8::internal::wasm::WasmVal(2), | |
| 70 v8::internal::wasm::WasmVal(3)}; | |
| 71 result_interpreted = v8::internal::wasm::testing::InterpretWasmModule( | |
| 72 i_isolate, interpreter_thrower, module.get(), 0, args); | |
| 73 } | |
| 74 | |
| 75 v8::internal::wasm::ErrorThrower compiler_thrower(i_isolate, "Compiler"); | |
| 76 v8::internal::Handle<v8::internal::JSObject> instance = | |
| 77 v8::internal::wasm::testing::InstantiateModuleForTesting( | |
| 78 i_isolate, compiler_thrower, module.get()); | |
| 79 | |
| 80 if (!interpreter_thrower.error()) { | |
| 81 CHECK(!instance.is_null()); | |
| 82 } else { | |
| 83 return 0; | |
| 84 } | |
| 85 int32_t result_compiled; | |
| 86 { | |
| 87 v8::internal::Handle<v8::internal::Object> arguments[] = { | |
| 88 v8::internal::handle(v8::internal::Smi::FromInt(1), i_isolate)}; | |
| 89 result_compiled = v8::internal::wasm::testing::CallWasmFunctionForTesting( | |
| 90 i_isolate, instance, compiler_thrower, "main", arraysize(arguments), | |
| 91 arguments, false); | |
| 92 } | |
| 93 if (result_interpreted == 0xdeadbeef) { | |
| 94 CHECK(i_isolate->has_pending_exception()); | |
| 95 i_isolate->clear_pending_exception(); | |
| 96 } else { | |
| 97 CHECK_EQ(result_interpreted, result_compiled); | |
| 98 } | |
| 53 return 0; | 99 return 0; |
| 54 } | 100 } |
| OLD | NEW |