blob: 59d01295c2b0ad19c01e6a53ce4140f2d495bc30 [file] [log] [blame]
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// For wasm::FunctionSig.
#include "src/wasm/value-type.h"
// For wasm::AddressType.
#include "src/wasm/wasm-module.h"
@useParentTypeChecker
type PodArrayOfWasmValueType extends ByteArray
constexpr 'PodArray<wasm::ValueType>';
@useParentTypeChecker
type ManagedWasmNativeModule extends Foreign
constexpr 'Managed<wasm::NativeModule>';
@useParentTypeChecker
type TrustedManagedWasmJSFunctionOffheapData extends TrustedForeign
constexpr 'TrustedManaged<WasmJSFunctionData::OffheapData>';
type RawFunctionSigPtr extends RawPtr constexpr 'const wasm::CanonicalSig*';
extern enum AddressType extends uint8 constexpr 'wasm::AddressType' {
kI32,
kI64
}
type WasmCodePointer = uint32;
// Trusted instance data, exposed via WasmInstanceObject::trusted_data.
extern class WasmTrustedInstanceData extends ExposedTrustedObject;
extern class WasmInstanceObject extends JSObject {
trusted_data: TrustedPointer<WasmTrustedInstanceData>;
module_object: WasmModuleObject;
exports_object: JSObject;
}
// The WasmImportData is passed to non-wasm imports in place of the
// WasmTrustedInstanceData. It is used in import wrappers (wasm-to-*) to load
// needed information, and is used during wrapper tiering to know which
// call site to patch (see the `call_origin` field).
extern class WasmImportData extends TrustedObject {
// The instance data is used to load memory start/size for fast API calls, and
// for tier-up of wasm-to-js wrappers.
// Use the '.instance_data' macro to read this from torque code.
protected_instance_data: ProtectedPointer<WasmTrustedInstanceData>;
// `call_origin` records which place to patch on wrapper tier-up:
// - WasmInternalFunction: a func ref
// - WasmDispatchTable: a table; the slot is in the {bit_field}.
protected_call_origin:
ProtectedPointer<WasmInternalFunction|WasmDispatchTable>;
native_context: NativeContext;
callable: JSReceiver|Undefined;
wrapper_budget: Smi;
// The signature is needed for the generic wasm-to-js wrapper.
sig: RawFunctionSigPtr;
// See BitFields defined in the C++ class for details.
bit_field: uint32;
@if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
}
extern operator '.instance_data' macro LoadInstanceDataFromWasmImportData(
WasmImportData): WasmTrustedInstanceData|Smi;
class WasmFastApiCallData extends HeapObject {
signature: HeapObject;
callback_data: Object;
cached_map: Weak<Map>|Null;
}
// This is the representation that is used internally by wasm to represent
// function references. It is "exposed" via the WasmFuncRef.
extern class WasmInternalFunction extends ExposedTrustedObject {
// This is the implicit first argument that must be passed along in the
// "instance" register when calling the given function. It is either the
// target instance data (for wasm functions), or a WasmImportData object (for
// non-wasm imports). For imported functions, this value equals the respective
// entry in the module's dispatch_table_for_imports.
// Torque code should use the '.implicit_arg' macro to access the value.
protected_implicit_arg:
ProtectedPointer<WasmTrustedInstanceData|WasmImportData>;
// The external (JS) representation of this function reference.
external: JSFunction|Undefined;
// For exported Wasm functions: the function index in the defining module;
// {protected_implicit_arg} is the {WasmTrustedInstanceData} corresponding
// to this module.
// For imported JS functions: the function index in the importing module;
// {protected_implicit_arg} is a {WasmImportData} describing this module.
// For WasmJSFunctions and WasmCapiFunctions: -1.
function_index: Smi;
// The call target, stored as a WasmCodePointer in this trusted object.
raw_call_target: WasmCodePointer;
@if(WASM_CODE_POINTER_NEEDS_PADDING) optional_padding: uint32;
@ifnot(WASM_CODE_POINTER_NEEDS_PADDING) optional_padding: void;
}
extern operator '.implicit_arg' macro LoadImplicitArgFromWasmInternalFunction(
WasmInternalFunction): WasmTrustedInstanceData|WasmImportData;
// WasmFuncRef is the type of function references. They are stored on-heap and
// link to a WasmInternalFunction which contains the actual information.
extern class WasmFuncRef extends HeapObject {
// Note: Torque code uses the '.internal' macro below to access the reference.
trusted_internal: TrustedPointer<WasmInternalFunction>;
}
extern operator '.internal' macro LoadWasmInternalFunctionFromFuncRef(
WasmFuncRef): WasmInternalFunction;
// Exposed via SharedFunctionInfo::trusted_function_data.
extern class WasmFunctionData extends ExposedTrustedObject {
// Used for calling this function from JavaScript.
wrapper_code: TrustedPointer<Code>;
// The function reference for this function object. This is used when
// converting a JS function back to the wasm-side func ref.
func_ref: WasmFuncRef;
// Encode the {promising} and {suspending} flags in a single smi.
js_promise_flags: Smi;
// Trusted-to-trusted pointer, to ensure that the pair of WasmFunctionData
// and WasmInternalFunction remains in an overall consistent state.
protected_internal: ProtectedPointer<WasmInternalFunction>;
}
extern operator '.internal' macro LoadWasmInternalFunctionFromFunctionData(
WasmFunctionData): WasmInternalFunction;
extern class WasmExportedFunctionData extends WasmFunctionData {
// This is the instance that exported the function (which in case of
// imported and re-exported functions is different from the instance
// where the function is defined).
protected_instance_data: ProtectedPointer<WasmTrustedInstanceData>;
function_index: Smi;
// Contains a Smi; boxed so that generated code can update the value.
wrapper_budget: Cell;
canonical_type_index: Smi;
// {packed_args_size} and {c_wrapper_code} are for fast calling from C++.
// The contract is that they are lazily populated, and either both will be
// present or neither.
packed_args_size: Smi;
c_wrapper_code: TrustedPointer<Code>;
sig: RawFunctionSigPtr;
}
extern operator '.instance_data' macro
LoadWasmTrustedInstanceDataFromWasmExportedFunctionData(
WasmExportedFunctionData): WasmTrustedInstanceData;
extern class WasmJSFunctionData extends WasmFunctionData {
canonical_sig_index: Smi;
protected_offheap_data:
ProtectedPointer<TrustedManagedWasmJSFunctionOffheapData>;
}
extern class WasmCapiFunctionData extends WasmFunctionData {
// TODO(jkummerow): Move {canonical_sig_index} into {WasmFunctionData}.
canonical_sig_index: Smi;
embedder_data: Foreign; // Managed<wasm::FuncData>
sig: RawFunctionSigPtr;
}
extern class WasmResumeData extends HeapObject {
suspender: WasmSuspenderObject;
on_resume: Smi; // See wasm::OnResume enum.
}
extern class WasmContinuationObject extends HeapObject {
parent: WasmContinuationObject|Undefined;
stack: ExternalPointer;
}
extern class WasmSuspenderObject extends HeapObject {
continuation: WasmContinuationObject|Undefined;
parent: WasmSuspenderObject|Undefined;
promise: JSPromise;
resume: JSObject|Undefined;
reject: JSObject|Undefined;
}
extern class WasmExceptionTag extends Struct {
// Note that this index is only useful for debugging purposes and it is not
// unique across modules. The GC however does not allow objects without at
// least one field, hence this also serves as a padding field for now.
index: Smi;
}
extern class WasmExceptionPackage extends JSObject;
extern class WasmModuleObject extends JSObject {
managed_native_module: ManagedWasmNativeModule;
script: Script;
}
extern class WasmDispatchTable extends ExposedTrustedObject;
extern class WasmTableObject extends JSObject {
// The entries array is at least as big as {current_length()}, but might be
// bigger to make future growth more efficient.
// If this is a function table, each element is either
// - a WasmFuncRef (Wasm function added from Wasm),
// - a WasmExportedFunction (exported Wasm function added from JS),
// - a WasmJSFunction (WebAssembly.Function created from JS), or
// - a Tuple2 (placeholder for lazy initialization), holding a
// WasmInstanceObject and Smi for the function index.
entries: FixedArray;
current_length: Smi;
// The declared maximum. Undefined if no maximum was declared.
// If {address_type == kI32} this stores a Smi or HeapNumber, otherwise a
// BigInt. Note that the value can in any case be bigger than
// {wasm::kV8MaxWasmTableSize}.
maximum_length: Smi|HeapNumber|BigInt|Undefined;
// Stores a (module-specific!) ValueType's {raw_bits()} describing the type
// of this table. Used for spec-level type checks and debugging.
// For sandbox-related checks, use WasmDispatchTable::table_type instead!
raw_type: Smi;
// This field is not set if the table is not a function table.
trusted_dispatch_table: TrustedPointer<WasmDispatchTable>;
// The instance in which this WasmTableObject is defined.
// This field is not set if the table is defined outside any Wasm module,
// i.e., through the JS API (WebAssembly.Table).
trusted_data: TrustedPointer<WasmTrustedInstanceData>;
address_type: AddressType;
// TODO(clemensb): Support fixed-sized arrays in torque.
padding_for_address_type_0: uint8;
padding_for_address_type_1: uint16;
@if(TAGGED_SIZE_8_BYTES) padding_for_address_type_2: uint32;
}
extern class WasmMemoryObject extends JSObject {
array_buffer: JSArrayBuffer;
maximum_pages: Smi;
instances: WeakArrayList;
address_type: AddressType;
// TODO(clemensb): Support fixed-sized arrays in torque.
padding_for_address_type_0: uint8;
padding_for_address_type_1: uint16;
@if(TAGGED_SIZE_8_BYTES) padding_for_address_type_2: uint32;
}
extern class WasmMemoryMapDescriptor extends JSObject {
// TODO(ahaas): Don't store the file descriptor here directly, but store it
// in an array in the isolate, and only store an index into that array here.
// An attacker could otherwise change the file descriptor here and thereby
// access an arbitrary file descriptor.
memory: Weak<WasmMemoryObject>;
file_descriptor: int32;
// TODO(339678654,ahaas): Support memory64.
offset: uint32;
size: uint32;
@if(TAGGED_SIZE_8_BYTES) padding: uint32;
}
extern class WasmGlobalObject extends JSObject {
// The instance in which this WasmGlobalObject is defined.
// This field is not set if the global is defined outside any Wasm module,
// i.e., through the JS API (WebAssembly.Global).
trusted_data: TrustedPointer<WasmTrustedInstanceData>;
untagged_buffer: JSArrayBuffer|Undefined;
tagged_buffer: FixedArray|Undefined;
offset: Smi;
raw_type: Smi;
// TODO(14034): If we encode mutability in raw_type, turn this into a boolean
// accessor.
is_mutable: Smi;
}
extern class WasmTagObject extends JSObject {
serialized_signature: PodArrayOfWasmValueType;
tag: HeapObject;
canonical_type_index: Smi;
trusted_data: TrustedPointer<WasmTrustedInstanceData>;
}
type WasmExportedFunction extends JSFunction;
extern class AsmWasmData extends Struct {
managed_native_module: ManagedWasmNativeModule;
uses_bitset: HeapNumber;
}
extern class WasmTypeInfo extends HeapObject {
canonical_type: uint32;
canonical_element_type: uint32; // Only for WasmArrays.
const supertypes_length: Smi;
supertypes[supertypes_length]: Object;
}
// WasmObject corresponds to data ref types which are WasmStruct and WasmArray.
@abstract
extern class WasmObject extends JSReceiver {}
@highestInstanceTypeWithinParentClassRange
extern class WasmStruct extends WasmObject {}
@lowestInstanceTypeWithinParentClassRange
extern class WasmArray extends WasmObject {
length: uint32;
@if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
@ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
}
class WasmStringViewIter extends HeapObject {
string: String;
offset: uint32; // Index into string.
@if(TAGGED_SIZE_8_BYTES) optional_padding: uint32;
@ifnot(TAGGED_SIZE_8_BYTES) optional_padding: void;
}
extern class WasmNull extends HeapObject {}
extern macro WasmNullConstant(): WasmNull;
const kWasmNull: WasmNull = WasmNullConstant();
extern class WasmSuspendingObject extends JSObject {
callable: JSReceiver;
}