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/objects.h" | 10 #include "src/objects.h" |
11 #include "src/ostreams.h" | 11 #include "src/ostreams.h" |
12 #include "src/wasm/wasm-interpreter.h" | 12 #include "src/wasm/wasm-interpreter.h" |
13 #include "src/wasm/wasm-module-builder.h" | 13 #include "src/wasm/wasm-module-builder.h" |
14 #include "src/wasm/wasm-module.h" | 14 #include "src/wasm/wasm-module.h" |
15 #include "test/common/wasm/test-signatures.h" | 15 #include "test/common/wasm/test-signatures.h" |
16 #include "test/common/wasm/wasm-module-runner.h" | 16 #include "test/common/wasm/wasm-module-runner.h" |
17 #include "test/fuzzer/fuzzer-support.h" | 17 #include "test/fuzzer/fuzzer-support.h" |
18 | 18 |
19 #define WASM_CODE_FUZZER_HASH_SEED 83 | 19 #define WASM_CODE_FUZZER_HASH_SEED 83 |
20 | 20 |
21 using namespace v8::internal::wasm; | 21 using namespace v8::internal::wasm; |
22 | 22 |
23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
24 // Save the flag so that we can change it and restore it later. | 24 // Save the flag so that we can change it and restore it later. |
25 bool generate_test = v8::internal::FLAG_wasm_code_fuzzer_gen_test; | 25 bool generate_test = v8::internal::FLAG_wasm_code_fuzzer_gen_test; |
26 if (generate_test) { | 26 if (generate_test) { |
27 v8::internal::OFStream os(stdout); | 27 v8::internal::OFStream os(stdout); |
28 | 28 |
29 os << "// Copyright 2016 the V8 project authors. All rights reserved." | 29 os << "// Copyright 2017 the V8 project authors. All rights reserved." |
30 << std::endl; | 30 << std::endl; |
31 os << "// Use of this source code is governed by a BSD-style license that " | 31 os << "// Use of this source code is governed by a BSD-style license that " |
32 "can be" | 32 "can be" |
33 << std::endl; | 33 << std::endl; |
34 os << "// found in the LICENSE file." << std::endl; | 34 os << "// found in the LICENSE file." << std::endl; |
35 os << std::endl; | 35 os << std::endl; |
36 os << "// Flags: --expose-wasm" << std::endl; | |
37 os << std::endl; | |
38 os << "load(\"test/mjsunit/wasm/wasm-constants.js\");" << std::endl; | 36 os << "load(\"test/mjsunit/wasm/wasm-constants.js\");" << std::endl; |
39 os << "load(\"test/mjsunit/wasm/wasm-module-builder.js\");" << std::endl; | 37 os << "load(\"test/mjsunit/wasm/wasm-module-builder.js\");" << std::endl; |
40 os << std::endl; | 38 os << std::endl; |
41 os << "(function() {" << std::endl; | 39 os << "(function() {" << std::endl; |
42 os << " var builder = new WasmModuleBuilder();" << std::endl; | 40 os << " var builder = new WasmModuleBuilder();" << std::endl; |
| 41 os << " builder.addMemory(32, 32, false);" << std::endl; |
43 os << " builder.addFunction(\"test\", kSig_i_iii)" << std::endl; | 42 os << " builder.addFunction(\"test\", kSig_i_iii)" << std::endl; |
44 os << " .addBody([" << std::endl; | 43 os << " .addBodyWithEnd([" << std::endl; |
45 } | 44 } |
46 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); | 45 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); |
47 v8::Isolate* isolate = support->GetIsolate(); | 46 v8::Isolate* isolate = support->GetIsolate(); |
48 v8::internal::Isolate* i_isolate = | 47 v8::internal::Isolate* i_isolate = |
49 reinterpret_cast<v8::internal::Isolate*>(isolate); | 48 reinterpret_cast<v8::internal::Isolate*>(isolate); |
50 | 49 |
51 // Clear any pending exceptions from a prior run. | 50 // Clear any pending exceptions from a prior run. |
52 if (i_isolate->has_pending_exception()) { | 51 if (i_isolate->has_pending_exception()) { |
53 i_isolate->clear_pending_exception(); | 52 i_isolate->clear_pending_exception(); |
54 } | 53 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // result_compiled. Therefore we do not check the equality of the results | 145 // result_compiled. Therefore we do not check the equality of the results |
147 // if the execution may have produced a NaN at some point. | 146 // if the execution may have produced a NaN at some point. |
148 if (!possible_nondeterminism && (result_interpreted != result_compiled)) { | 147 if (!possible_nondeterminism && (result_interpreted != result_compiled)) { |
149 V8_Fatal(__FILE__, __LINE__, "WasmCodeFuzzerHash=%x", | 148 V8_Fatal(__FILE__, __LINE__, "WasmCodeFuzzerHash=%x", |
150 v8::internal::StringHasher::HashSequentialString( | 149 v8::internal::StringHasher::HashSequentialString( |
151 data, static_cast<int>(size), WASM_CODE_FUZZER_HASH_SEED)); | 150 data, static_cast<int>(size), WASM_CODE_FUZZER_HASH_SEED)); |
152 } | 151 } |
153 } | 152 } |
154 return 0; | 153 return 0; |
155 } | 154 } |
OLD | NEW |