v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
random-module-generation.h
Go to the documentation of this file.
1// Copyright 2024 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 V8_WASM_FUZZING_RANDOM_MODULE_GENERATION_H_
6#define V8_WASM_FUZZING_RANDOM_MODULE_GENERATION_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
12#include "src/base/enum-set.h"
14#include "src/base/logging.h"
15#include "src/base/vector.h"
16
17namespace v8::internal {
18class Zone;
19}
20
22
23#ifdef V8_WASM_RANDOM_FUZZERS
24// Defines what expressions should be generated by the fuzzer besides the MVP
25// ones.
26enum WasmModuleGenerationOption { kGenerateSIMD, kGenerateWasmGC };
27
28struct WasmModuleGenerationOptions
29 : public base::EnumSet<WasmModuleGenerationOption> {
30 bool generate_simd() const { return contains(kGenerateSIMD); }
31 bool generate_wasm_gc() const { return contains(kGenerateWasmGC); }
32
33 static constexpr WasmModuleGenerationOptions MVP() { return {{}}; }
34 static constexpr WasmModuleGenerationOptions All() {
35 return {{kGenerateSIMD, kGenerateWasmGC}};
36 }
37};
38
39// Generate a valid Wasm module based on the given input bytes.
40// Returns an empty buffer on failure, valid module wire bytes otherwise.
41// The bytes will be allocated in the zone.
42// Defined in random-module-generation.cc.
44 Zone*, WasmModuleGenerationOptions, base::Vector<const uint8_t> data);
45
47 Zone*, base::Vector<const uint8_t> data, size_t* count);
48
50 Zone*, base::Vector<const uint8_t> data, std::vector<std::string>& callees,
51 std::vector<std::string>& inlinees);
52#endif
53
54} // namespace v8::internal::wasm::fuzzing
55
56#endif // V8_WASM_FUZZING_RANDOM_MODULE_GENERATION_H_
friend Zone
Definition asm-types.cc:195
bool contains(const C &container, const T &element)
base::Vector< uint8_t > GenerateRandomWasmModule(Zone *zone, WasmModuleGenerationOptions options, base::Vector< const uint8_t > data)
base::Vector< uint8_t > GenerateWasmModuleForInitExpressions(Zone *zone, base::Vector< const uint8_t > data, size_t *count)
base::Vector< uint8_t > GenerateWasmModuleForDeopt(Zone *zone, base::Vector< const uint8_t > data, std::vector< std::string > &callees, std::vector< std::string > &inlinees)
#define V8_EXPORT_PRIVATE
Definition macros.h:460