Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #ifndef WASM_FUZZER_COMMON_H_
6 : #define WASM_FUZZER_COMMON_H_
7 :
8 : #include <stddef.h>
9 : #include <stdint.h>
10 :
11 : #include "src/wasm/module-decoder.h"
12 : #include "src/wasm/wasm-interpreter.h"
13 : #include "src/wasm/wasm-module-builder.h"
14 :
15 : namespace v8 {
16 : namespace internal {
17 : namespace wasm {
18 : namespace fuzzer {
19 :
20 : // First instantiates and interprets the "main" function within module_object if
21 : // possible. If the interpretation finishes within kMaxSteps steps,
22 : // module_object is instantiated again and the compiled "main" function is
23 : // executed.
24 : void InterpretAndExecuteModule(Isolate* isolate,
25 : Handle<WasmModuleObject> module_object);
26 :
27 : void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
28 : bool compiles);
29 :
30 2 : class WasmExecutionFuzzer {
31 : public:
32 2 : virtual ~WasmExecutionFuzzer() = default;
33 : void FuzzWasmModule(Vector<const uint8_t> data, bool require_valid = false);
34 :
35 2 : virtual size_t max_input_size() const { return 512; }
36 :
37 : protected:
38 : virtual bool GenerateModule(
39 : Isolate* isolate, Zone* zone, Vector<const uint8_t> data,
40 : ZoneBuffer& buffer, int32_t& num_args,
41 : std::unique_ptr<WasmValue[]>& interpreter_args,
42 : std::unique_ptr<Handle<Object>[]>& compiler_args) = 0;
43 : };
44 :
45 : } // namespace fuzzer
46 : } // namespace wasm
47 : } // namespace internal
48 : } // namespace v8
49 : #endif // WASM_FUZZER_COMMON_H_
|