// Copyright 2016 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "test/fuzzer/wasm-fuzzer-common.h" #include #include "include/v8.h" #include "src/execution/isolate.h" #include "src/objects/objects-inl.h" #include "src/utils/ostreams.h" #include "src/wasm/baseline/liftoff-compiler.h" #include "src/wasm/module-instantiate.h" #include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-feature-flags.h" #include "src/wasm/wasm-module-builder.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-objects-inl.h" #include "src/zone/accounting-allocator.h" #include "src/zone/zone.h" #include "test/common/wasm/flag-utils.h" #include "test/common/wasm/wasm-module-runner.h" #include "test/fuzzer/fuzzer-support.h" namespace v8 { namespace internal { namespace wasm { namespace fuzzer { // Compile a baseline module. We pass a pointer to a max step counter and a // nondeterminsm flag that are updated during execution by Liftoff. Handle CompileReferenceModule(Zone* zone, Isolate* isolate, ModuleWireBytes wire_bytes, ErrorThrower* thrower, int32_t* max_steps, int32_t* nondeterminism) { // Create the native module. std::shared_ptr native_module; constexpr bool kNoVerifyFunctions = false; auto enabled_features = i::wasm::WasmFeatures::FromIsolate(isolate); ModuleResult module_res = DecodeWasmModule( enabled_features, wire_bytes.start(), wire_bytes.end(), kNoVerifyFunctions, ModuleOrigin::kWasmOrigin, isolate->counters(), isolate->metrics_recorder(), v8::metrics::Recorder::ContextId::Empty(), DecodingMethod::kSync, GetWasmEngine()->allocator()); CHECK(module_res.ok()); std::shared_ptr module = module_res.value(); CHECK_NOT_NULL(module); native_module = GetWasmEngine()->NewNativeModule(isolate, enabled_features, module, 0); native_module->SetWireBytes( base::OwnedVector::Of(wire_bytes.module_bytes())); // Compile all functions with Liftoff. WasmCodeRefScope code_ref_scope; auto env = native_module->CreateCompilationEnv(); for (size_t i = module->num_imported_functions; i < module->functions.size(); ++i) { auto& func = module->functions[i]; base::Vector func_code = wire_bytes.GetFunctionBytes(&func); WasmFeatures unused_detected_features; FunctionBody func_body(func.sig, func.code.offset(), func_code.begin(), func_code.end()); auto result = ExecuteLiftoffCompilation( &env, func_body, func.func_index, kForDebugging, isolate->counters(), &unused_detected_features, {}, nullptr, 0, max_steps, nondeterminism); native_module->PublishCode( native_module->AddCompiledCode(std::move(result))); } // Create the module object. constexpr base::Vector kNoSourceUrl; Handle