v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-serialization.h
Go to the documentation of this file.
1// Copyright 2017 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_WASM_SERIALIZATION_H_
6#define V8_WASM_WASM_SERIALIZATION_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
14
15namespace v8::internal::wasm {
16
17// Support for serializing WebAssembly {NativeModule} objects. This class takes
18// a snapshot of the module state at instantiation, and other code that modifies
19// the module after that won't affect the serialized result.
21 public:
22 explicit WasmSerializer(NativeModule* native_module);
23
24 // Measure the required buffer size needed for serialization.
25 size_t GetSerializedNativeModuleSize() const;
26
27 // Serialize the {NativeModule} into the provided {buffer}. Returns true on
28 // success and false if the given buffer it too small for serialization.
29 bool SerializeNativeModule(base::Vector<uint8_t> buffer) const;
30
31 // The data header consists of uint32_t-sized entries (see {WriteVersion}):
32 // [0] magic number
33 // [1] version hash
34 // [2] supported CPU features
35 // [3] flag hash
36 // [4] enabled features (via flags and OT)
37 // ... number of functions
38 // ... serialized functions
39 static constexpr size_t kMagicNumberOffset = 0;
40 static constexpr size_t kVersionHashOffset = kMagicNumberOffset + kUInt32Size;
41 static constexpr size_t kSupportedCPUFeaturesOffset =
42 kVersionHashOffset + kUInt32Size;
43 static constexpr size_t kFlagHashOffset =
44 kSupportedCPUFeaturesOffset + kUInt32Size;
45 static constexpr size_t kHeaderSize = 5 * kUInt32Size;
46
47 private:
49 // The {WasmCodeRefScope} keeps the pointers in {code_table_} alive.
51 std::vector<WasmCode*> code_table_;
52 std::vector<WellKnownImport> import_statuses_;
53};
54
55// Support for deserializing WebAssembly {NativeModule} objects.
56// Checks the version header of the data against the current version.
58 WasmEnabledFeatures enabled_features);
59
60// Deserializes the given data to create a Wasm module object.
64 const CompileTimeImports& compile_imports,
65 base::Vector<const char> source_url);
66
67} // namespace v8::internal::wasm
68
69#endif // V8_WASM_WASM_SERIALIZATION_H_
std::vector< WasmCode * > code_table_
std::vector< WellKnownImport > import_statuses_
MaybeDirectHandle< WasmModuleObject > DeserializeNativeModule(Isolate *isolate, base::Vector< const uint8_t > data, base::Vector< const uint8_t > wire_bytes_vec, const CompileTimeImports &compile_imports, base::Vector< const char > source_url)
bool IsSupportedVersion(base::Vector< const uint8_t > header, WasmEnabledFeatures enabled_features)
constexpr int kUInt32Size
Definition globals.h:403
#define V8_EXPORT_PRIVATE
Definition macros.h:460