v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
module-instantiate.h
Go to the documentation of this file.
1// Copyright 2019 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_MODULE_INSTANTIATE_H_
6#define V8_WASM_MODULE_INSTANTIATE_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 <stdint.h>
13
14#include <optional>
15
18#include "src/wasm/wasm-value.h"
20
21namespace v8 {
22namespace internal {
23
24class FixedArray;
25class JSArrayBuffer;
26class WasmFunctionData;
27class WasmModuleObject;
28class WasmInstanceObject;
30class Zone;
31
32namespace wasm {
33class ErrorThrower;
34enum Suspend : int { kSuspend, kNoSuspend };
35// kStressSwitch: switch to a secondary stack, but without the JSPI semantics:
36// do not handle async imports and do not return a Promise. For testing only.
38struct WasmModule;
39
40// Calls to Wasm imports are handled in several different ways, depending on the
41// type of the target function/callable and whether the signature matches the
42// argument arity.
43// TODO(jkummerow): Merge kJSFunctionArity{Match,Mismatch}, we don't really
44// need the distinction any more.
45enum class ImportCallKind : uint8_t {
46 kLinkError, // static Wasm->Wasm type error
47 kRuntimeTypeError, // runtime Wasm->JS type error
48 kWasmToCapi, // fast Wasm->C-API call
49 kWasmToJSFastApi, // fast Wasm->JS Fast API C call
50 kWasmToWasm, // fast Wasm->Wasm call
51 kJSFunctionArityMatch, // fast Wasm->JS call
52 kJSFunctionArityMismatch, // Wasm->JS, needs adapter frame
53 // For everything else, there's the call builtin.
55};
56
59
60// Resolves which import call wrapper is required for the given JS callable.
61// Provides the kind of wrapper needed, the ultimate target callable, and the
62// suspender object if applicable. Note that some callables (e.g. a
63// {WasmExportedFunction} or {WasmJSFunction}) just wrap another target, which
64// is why the ultimate target is provided as well.
66 public:
67 // TODO(clemensb): We should only need one of {sig} and {expected_sig_id};
68 // currently we can't efficiently translate between them.
70 DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
71 int func_index, DirectHandle<JSReceiver> callable,
72 const wasm::CanonicalSig* sig, CanonicalTypeIndex expected_sig_id,
73 WellKnownImport preknown_import);
74
75 ImportCallKind kind() const { return kind_; }
77 Suspend suspend() const { return suspend_; }
79 // Avoid reading function data from the result of `callable()`, because it
80 // might have been corrupted in the meantime (in a compromised sandbox).
81 // Instead, use this cached copy.
85
86 private:
89
91 DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
92 int func_index, const wasm::CanonicalSig* expected_sig,
93 CanonicalTypeIndex expected_canonical_type_index,
94 WellKnownImport preknown_import);
95
101};
102
104 Isolate* isolate, ErrorThrower* thrower,
105 DirectHandle<WasmModuleObject> module_object,
108
109// Initializes a segment at index {segment_index} of the segment array of
110// {instance}. If successful, returns the empty {Optional}, otherwise an
111// {Optional} that contains the error message. Exits early if the segment is
112// already initialized.
113std::optional<MessageTemplate> InitializeElementSegment(
114 Zone* zone, Isolate* isolate,
115 DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
116 DirectHandle<WasmTrustedInstanceData> shared_trusted_instance_data,
117 uint32_t segment_index);
118
120 Isolate* isolate, const WasmModule* module, ModuleTypeIndex type_index,
121 DirectHandle<FixedArray> maybe_shared_maps);
122
123// Wrapper information required for graph building.
131
132} // namespace wasm
133} // namespace internal
134} // namespace v8
135
136#endif // V8_WASM_MODULE_INSTANTIATE_H_
friend Zone
Definition asm-types.cc:195
DirectHandle< WasmFunctionData > trusted_function_data_
DirectHandle< WasmFunctionData > trusted_function_data() const
DirectHandle< JSReceiver > callable() const
ImportCallKind ComputeKind(DirectHandle< WasmTrustedInstanceData > trusted_instance_data, int func_index, const wasm::CanonicalSig *expected_sig, CanonicalTypeIndex expected_canonical_type_index, WellKnownImport preknown_import)
void SetCallable(Isolate *isolate, Tagged< JSReceiver > callable)
V8_EXPORT_PRIVATE ResolvedWasmImport(DirectHandle< WasmTrustedInstanceData > trusted_instance_data, int func_index, DirectHandle< JSReceiver > callable, const wasm::CanonicalSig *sig, CanonicalTypeIndex expected_sig_id, WellKnownImport preknown_import)
std::optional< MessageTemplate > InitializeElementSegment(Zone *zone, Isolate *isolate, DirectHandle< WasmTrustedInstanceData > trusted_instance_data, DirectHandle< WasmTrustedInstanceData > shared_trusted_instance_data, uint32_t segment_index)
constexpr ImportCallKind kDefaultImportCallKind
MaybeDirectHandle< WasmInstanceObject > InstantiateToInstanceObject(Isolate *isolate, ErrorThrower *thrower, DirectHandle< WasmModuleObject > module_object, MaybeDirectHandle< JSReceiver > imports, MaybeDirectHandle< JSArrayBuffer > memory_buffer)
void CreateMapForType(Isolate *isolate, const WasmModule *module, ModuleTypeIndex type_index, DirectHandle< FixedArray > maybe_shared_maps)
kWasmInternalFunctionIndirectPointerTag WasmTrustedInstanceData
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
Definition c-api.cc:87
#define V8_EXPORT_PRIVATE
Definition macros.h:460