2017-05-08 09:22:54 +00:00
|
|
|
// 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.
|
|
|
|
|
2017-11-06 12:21:06 +00:00
|
|
|
#ifndef WASM_FUZZER_COMMON_H_
|
|
|
|
#define WASM_FUZZER_COMMON_H_
|
2017-05-08 09:22:54 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2020-06-23 07:48:53 +00:00
|
|
|
|
2019-09-13 16:11:40 +00:00
|
|
|
#include <memory>
|
2017-05-08 09:22:54 +00:00
|
|
|
|
|
|
|
#include "src/wasm/module-decoder.h"
|
|
|
|
#include "src/wasm/wasm-module-builder.h"
|
|
|
|
|
2022-12-05 11:59:26 +00:00
|
|
|
namespace v8::internal::wasm::fuzzer {
|
|
|
|
|
|
|
|
// A default value for {max_executed_instructions} in {ExecuteAgainstReference}.
|
2022-12-06 15:38:21 +00:00
|
|
|
#ifdef USE_SIMULATOR
|
|
|
|
constexpr int kDefaultMaxFuzzerExecutedInstructions = 16'000;
|
|
|
|
#else
|
|
|
|
constexpr int kDefaultMaxFuzzerExecutedInstructions = 1'000'000;
|
|
|
|
#endif
|
2022-12-05 11:59:26 +00:00
|
|
|
|
|
|
|
// First creates a reference module fully compiled with Liftoff, with
|
|
|
|
// instrumentation to stop after a given number of steps and to record any
|
|
|
|
// nondeterminism while executing. If execution finishes within {max_steps},
|
|
|
|
// {module_object} is instantiated, its "main" function is executed, and the
|
|
|
|
// result is compared against the reference execution. If non-determinism was
|
|
|
|
// detected during the reference execution, the result is allowed to differ.
|
|
|
|
void ExecuteAgainstReference(Isolate* isolate,
|
|
|
|
Handle<WasmModuleObject> module_object,
|
|
|
|
int32_t max_executed_instructions);
|
2017-05-08 09:22:54 +00:00
|
|
|
|
2018-06-21 12:09:36 +00:00
|
|
|
void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
|
|
|
|
bool compiles);
|
|
|
|
|
2022-11-16 17:01:23 +00:00
|
|
|
// On the first call, enables all staged wasm features and experimental features
|
|
|
|
// that are ready for fuzzing. All subsequent calls are no-ops. This avoids race
|
|
|
|
// conditions with threads reading the flags. Fuzzers are executed in their own
|
|
|
|
// process anyway, so this should not interfere with anything.
|
|
|
|
void EnableExperimentalWasmFeatures(v8::Isolate* isolate);
|
2020-10-05 14:50:59 +00:00
|
|
|
|
2017-05-08 09:22:54 +00:00
|
|
|
class WasmExecutionFuzzer {
|
|
|
|
public:
|
2018-09-13 10:07:40 +00:00
|
|
|
virtual ~WasmExecutionFuzzer() = default;
|
2021-06-17 15:43:55 +00:00
|
|
|
void FuzzWasmModule(base::Vector<const uint8_t> data,
|
|
|
|
bool require_valid = false);
|
2017-05-08 09:22:54 +00:00
|
|
|
|
2018-10-25 14:24:01 +00:00
|
|
|
virtual size_t max_input_size() const { return 512; }
|
|
|
|
|
2017-05-08 09:22:54 +00:00
|
|
|
protected:
|
2021-07-05 14:08:41 +00:00
|
|
|
virtual bool GenerateModule(Isolate* isolate, Zone* zone,
|
|
|
|
base::Vector<const uint8_t> data,
|
2022-12-05 11:59:26 +00:00
|
|
|
ZoneBuffer* buffer) = 0;
|
2017-05-08 09:22:54 +00:00
|
|
|
};
|
|
|
|
|
2022-12-05 11:59:26 +00:00
|
|
|
} // namespace v8::internal::wasm::fuzzer
|
2017-11-06 12:21:06 +00:00
|
|
|
#endif // WASM_FUZZER_COMMON_H_
|