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
12
#include "
src/wasm/wasm-code-manager.h
"
13
#include "
src/wasm/wasm-objects.h
"
14
15
namespace
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.
20
class
V8_EXPORT_PRIVATE
WasmSerializer
{
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
:
48
NativeModule
*
native_module_
;
49
// The {WasmCodeRefScope} keeps the pointers in {code_table_} alive.
50
WasmCodeRefScope
code_ref_scope_
;
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.
57
bool
IsSupportedVersion
(
base::Vector<const uint8_t>
data,
58
WasmEnabledFeatures
enabled_features);
59
60
// Deserializes the given data to create a Wasm module object.
61
V8_EXPORT_PRIVATE
MaybeDirectHandle<WasmModuleObject>
DeserializeNativeModule
(
62
Isolate
*,
base::Vector<const uint8_t>
data,
63
base::Vector<const uint8_t>
wire_bytes,
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_
v8::base::Vector
Definition
zone-list.h:15
v8::internal::Isolate
Definition
isolate.h:586
v8::internal::MaybeDirectHandle
Definition
maybe-handles.h:241
v8::internal::wasm::CompileTimeImports
Definition
wasm-features.h:149
v8::internal::wasm::NativeModule
Definition
wasm-code-manager.h:579
v8::internal::wasm::WasmCodeRefScope
Definition
wasm-code-manager.h:1231
v8::internal::wasm::WasmEnabledFeatures
Definition
wasm-features.h:54
v8::internal::wasm::WasmSerializer
Definition
wasm-serialization.h:20
v8::internal::wasm::WasmSerializer::code_ref_scope_
WasmCodeRefScope code_ref_scope_
Definition
wasm-serialization.h:50
v8::internal::wasm::WasmSerializer::code_table_
std::vector< WasmCode * > code_table_
Definition
wasm-serialization.h:51
v8::internal::wasm::WasmSerializer::native_module_
NativeModule * native_module_
Definition
wasm-serialization.h:48
v8::internal::wasm::WasmSerializer::import_statuses_
std::vector< WellKnownImport > import_statuses_
Definition
wasm-serialization.h:52
v8::internal::wasm
Definition
asm-parser.cc:24
v8::internal::wasm::DeserializeNativeModule
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)
Definition
wasm-serialization.cc:1088
v8::internal::wasm::IsSupportedVersion
bool IsSupportedVersion(base::Vector< const uint8_t > header, WasmEnabledFeatures enabled_features)
Definition
wasm-serialization.cc:1078
v8::internal::kUInt32Size
constexpr int kUInt32Size
Definition
globals.h:403
V8_EXPORT_PRIVATE
#define V8_EXPORT_PRIVATE
Definition
macros.h:460
wasm-code-manager.h
wasm-objects.h
src
wasm
wasm-serialization.h
Generated on Sun Apr 6 2025 21:08:58 for v8 by
1.12.0