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" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 v8::internal::HandleScope scope(i_isolate); | 134 v8::internal::HandleScope scope(i_isolate); |
135 | 135 |
136 ErrorThrower interpreter_thrower(i_isolate, "Interpreter"); | 136 ErrorThrower interpreter_thrower(i_isolate, "Interpreter"); |
137 std::unique_ptr<const WasmModule> module(testing::DecodeWasmModuleForTesting( | 137 std::unique_ptr<const WasmModule> module(testing::DecodeWasmModuleForTesting( |
138 i_isolate, &interpreter_thrower, buffer.begin(), buffer.end(), | 138 i_isolate, &interpreter_thrower, buffer.begin(), buffer.end(), |
139 v8::internal::wasm::ModuleOrigin::kWasmOrigin, true)); | 139 v8::internal::wasm::ModuleOrigin::kWasmOrigin, true)); |
140 | 140 |
141 if (module == nullptr) { | 141 if (module == nullptr) { |
142 return 0; | 142 return 0; |
143 } | 143 } |
| 144 ModuleWireBytes wire_bytes(buffer.begin(), buffer.end()); |
144 int32_t result_interpreted; | 145 int32_t result_interpreted; |
145 bool possible_nondeterminism = false; | 146 bool possible_nondeterminism = false; |
146 { | 147 { |
147 result_interpreted = testing::InterpretWasmModule( | 148 result_interpreted = testing::InterpretWasmModule( |
148 i_isolate, &interpreter_thrower, module.get(), 0, interpreter_args, | 149 i_isolate, &interpreter_thrower, module.get(), wire_bytes, 0, |
149 &possible_nondeterminism); | 150 interpreter_args, &possible_nondeterminism); |
150 } | 151 } |
151 | 152 |
152 ErrorThrower compiler_thrower(i_isolate, "Compiler"); | 153 ErrorThrower compiler_thrower(i_isolate, "Compiler"); |
153 v8::internal::Handle<v8::internal::JSObject> instance = | 154 v8::internal::Handle<v8::internal::JSObject> instance = |
154 testing::InstantiateModuleForTesting(i_isolate, &compiler_thrower, | 155 testing::InstantiateModuleForTesting(i_isolate, &compiler_thrower, |
155 module.get()); | 156 module.get(), wire_bytes); |
156 | 157 |
157 if (!interpreter_thrower.error()) { | 158 if (!interpreter_thrower.error()) { |
158 CHECK(!instance.is_null()); | 159 CHECK(!instance.is_null()); |
159 } else { | 160 } else { |
160 return 0; | 161 return 0; |
161 } | 162 } |
162 int32_t result_compiled; | 163 int32_t result_compiled; |
163 { | 164 { |
164 result_compiled = testing::CallWasmFunctionForTesting( | 165 result_compiled = testing::CallWasmFunctionForTesting( |
165 i_isolate, instance, &compiler_thrower, "main", argc, compiled_args, | 166 i_isolate, instance, &compiler_thrower, "main", argc, compiled_args, |
166 v8::internal::wasm::ModuleOrigin::kWasmOrigin); | 167 v8::internal::wasm::ModuleOrigin::kWasmOrigin); |
167 } | 168 } |
168 if (result_interpreted == bit_cast<int32_t>(0xdeadbeef)) { | 169 if (result_interpreted == bit_cast<int32_t>(0xdeadbeef)) { |
169 CHECK(i_isolate->has_pending_exception()); | 170 CHECK(i_isolate->has_pending_exception()); |
170 i_isolate->clear_pending_exception(); | 171 i_isolate->clear_pending_exception(); |
171 } else { | 172 } else { |
172 // The WebAssembly spec allows the sign bit of NaN to be non-deterministic. | 173 // The WebAssembly spec allows the sign bit of NaN to be non-deterministic. |
173 // This sign bit may cause result_interpreted to be different than | 174 // This sign bit may cause result_interpreted to be different than |
174 // result_compiled. Therefore we do not check the equality of the results | 175 // result_compiled. Therefore we do not check the equality of the results |
175 // if the execution may have produced a NaN at some point. | 176 // if the execution may have produced a NaN at some point. |
176 if (!possible_nondeterminism && (result_interpreted != result_compiled)) { | 177 if (!possible_nondeterminism && (result_interpreted != result_compiled)) { |
177 V8_Fatal(__FILE__, __LINE__, "WasmCodeFuzzerHash=%x", | 178 V8_Fatal(__FILE__, __LINE__, "WasmCodeFuzzerHash=%x", |
178 v8::internal::StringHasher::HashSequentialString( | 179 v8::internal::StringHasher::HashSequentialString( |
179 data, static_cast<int>(size), WASM_CODE_FUZZER_HASH_SEED)); | 180 data, static_cast<int>(size), WASM_CODE_FUZZER_HASH_SEED)); |
180 } | 181 } |
181 } | 182 } |
182 return 0; | 183 return 0; |
183 } | 184 } |
OLD | NEW |