Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions crates/cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl wasmtime_environ::Compiler for Compiler {
// The way that stack overflow is handled here is by adding a prologue
// check to all functions for how much native stack is remaining. The
// `VMContext` pointer is the first argument to all functions, and the
// first field of this structure is `*const VMRuntimeLimits` and the
// first field of this structure is `*const VMStoreContext` and the
// first field of that is the stack limit. Note that the stack limit in
// this case means "if the stack pointer goes below this, trap". Each
// function which consumes stack space or isn't a leaf function starts
Expand Down Expand Up @@ -255,7 +255,7 @@ impl wasmtime_environ::Compiler for Compiler {
});
let stack_limit = context.func.create_global_value(ir::GlobalValueData::Load {
base: interrupts_ptr,
offset: i32::from(func_env.offsets.ptr.vmruntime_limits_stack_limit()).into(),
offset: i32::from(func_env.offsets.ptr.vmstore_context_stack_limit()).into(),
global_type: isa.pointer_type(),
flags: MemFlags::trusted(),
});
Expand Down Expand Up @@ -393,13 +393,13 @@ impl wasmtime_environ::Compiler for Compiler {
wasmtime_environ::VMCONTEXT_MAGIC,
);
let ptr = isa.pointer_bytes();
let limits = builder.ins().load(
let vm_store_context = builder.ins().load(
pointer_type,
MemFlags::trusted(),
caller_vmctx,
i32::from(ptr.vmcontext_runtime_limits()),
i32::from(ptr.vmcontext_store_context()),
);
save_last_wasm_exit_fp_and_pc(&mut builder, pointer_type, &ptr, limits);
save_last_wasm_exit_fp_and_pc(&mut builder, pointer_type, &ptr, vm_store_context);

// Spill all wasm arguments to the stack in `ValRaw` slots.
let (args_base, args_len) =
Expand Down Expand Up @@ -592,13 +592,13 @@ impl wasmtime_environ::Compiler for Compiler {
// additionally perform the "routine of the exit trampoline" of saving
// fp/pc/etc.
debug_assert_vmctx_kind(isa, &mut builder, vmctx, wasmtime_environ::VMCONTEXT_MAGIC);
let limits = builder.ins().load(
let vm_store_context = builder.ins().load(
pointer_type,
MemFlags::trusted(),
vmctx,
ptr_size.vmcontext_runtime_limits(),
ptr_size.vmcontext_store_context(),
);
save_last_wasm_exit_fp_and_pc(&mut builder, pointer_type, &ptr_size, limits);
save_last_wasm_exit_fp_and_pc(&mut builder, pointer_type, &ptr_size, vm_store_context);

// Now it's time to delegate to the actual builtin. Forward all our own
// arguments to the libcall itself.
Expand Down Expand Up @@ -1157,24 +1157,24 @@ fn save_last_wasm_entry_fp(
builder: &mut FunctionBuilder,
pointer_type: ir::Type,
ptr_size: &impl PtrSize,
vm_runtime_limits_offset: u32,
vm_store_context_offset: u32,
vmctx: Value,
) {
// First we need to get the `VMRuntimeLimits`.
let limits = builder.ins().load(
// First we need to get the `VMStoreContext`.
let vm_store_context = builder.ins().load(
pointer_type,
MemFlags::trusted(),
vmctx,
i32::try_from(vm_runtime_limits_offset).unwrap(),
i32::try_from(vm_store_context_offset).unwrap(),
);

// Then store our current stack pointer into the appropriate slot.
let fp = builder.ins().get_frame_pointer(pointer_type);
builder.ins().store(
MemFlags::trusted(),
fp,
limits,
ptr_size.vmruntime_limits_last_wasm_entry_fp(),
vm_store_context,
ptr_size.vmstore_context_last_wasm_entry_fp(),
);
}

Expand All @@ -1201,14 +1201,14 @@ fn save_last_wasm_exit_fp_and_pc(
MemFlags::trusted(),
wasm_fp,
limits,
ptr.vmruntime_limits_last_wasm_exit_fp(),
ptr.vmstore_context_last_wasm_exit_fp(),
);
// Finally save the Wasm return address to the limits.
let wasm_pc = builder.ins().get_return_address(pointer_type);
builder.ins().store(
MemFlags::trusted(),
wasm_pc,
limits,
ptr.vmruntime_limits_last_wasm_exit_pc(),
ptr.vmstore_context_last_wasm_exit_pc(),
);
}
6 changes: 3 additions & 3 deletions crates/cranelift/src/compiler/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,17 +856,17 @@ impl ComponentCompiler for Compiler {
wasmtime_environ::component::VMCOMPONENT_MAGIC,
);
if let Abi::Wasm = abi {
let limits = c.builder.ins().load(
let vm_store_context = c.builder.ins().load(
pointer_type,
MemFlags::trusted(),
vmctx,
i32::try_from(c.offsets.limits()).unwrap(),
i32::try_from(c.offsets.vm_store_context()).unwrap(),
);
super::save_last_wasm_exit_fp_and_pc(
&mut c.builder,
pointer_type,
&c.offsets.ptr,
limits,
vm_store_context,
);
}

Expand Down
57 changes: 27 additions & 30 deletions crates/cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ pub struct FuncEnvironment<'module_environment> {
/// A function-local variable which stores the cached value of the amount of
/// fuel remaining to execute. If used this is modified frequently so it's
/// stored locally as a variable instead of always referenced from the field
/// in `*const VMRuntimeLimits`
/// in `*const VMStoreContext`
fuel_var: cranelift_frontend::Variable,

/// A function-local variable which caches the value of `*const
/// VMRuntimeLimits` for this function's vmctx argument. This pointer is stored
/// VMStoreContext` for this function's vmctx argument. This pointer is stored
/// in the vmctx itself, but never changes for the lifetime of the function,
/// so if we load it up front we can continue to use it throughout.
vmruntime_limits_ptr: ir::Value,
vmstore_context_ptr: ir::Value,

/// A cached epoch deadline value, when performing epoch-based
/// interruption. Loaded from `VMRuntimeLimits` and reloaded after
/// interruption. Loaded from `VMStoreContext` and reloaded after
/// any yield.
epoch_deadline_var: cranelift_frontend::Variable,

Expand Down Expand Up @@ -199,7 +199,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
fuel_var: Variable::new(0),
epoch_deadline_var: Variable::new(0),
epoch_ptr_var: Variable::new(0),
vmruntime_limits_ptr: ir::Value::reserved_value(),
vmstore_context_ptr: ir::Value::reserved_value(),

// Start with at least one fuel being consumed because even empty
// functions should consume at least some fuel.
Expand Down Expand Up @@ -304,17 +304,17 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
}
}

fn declare_vmruntime_limits_ptr(&mut self, builder: &mut FunctionBuilder<'_>) {
// We load the `*const VMRuntimeLimits` value stored within vmctx at the
fn declare_vmstore_context_ptr(&mut self, builder: &mut FunctionBuilder<'_>) {
// We load the `*const VMStoreContext` value stored within vmctx at the
// head of the function and reuse the same value across the entire
// function. This is possible since we know that the pointer never
// changes for the lifetime of the function.
let pointer_type = self.pointer_type();
let vmctx = self.vmctx(builder.func);
let base = builder.ins().global_value(pointer_type, vmctx);
let offset = i32::from(self.offsets.ptr.vmctx_runtime_limits());
debug_assert!(self.vmruntime_limits_ptr.is_reserved_value());
self.vmruntime_limits_ptr =
debug_assert!(self.vmstore_context_ptr.is_reserved_value());
self.vmstore_context_ptr =
builder
.ins()
.load(pointer_type, ir::MemFlags::trusted(), base, offset);
Expand All @@ -324,7 +324,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
// On function entry we load the amount of fuel into a function-local
// `self.fuel_var` to make fuel modifications fast locally. This cache
// is then periodically flushed to the Store-defined location in
// `VMRuntimeLimits` later.
// `VMStoreContext` later.
builder.declare_var(self.fuel_var, ir::types::I64);
self.fuel_load_into_var(builder);
self.fuel_check(builder);
Expand Down Expand Up @@ -372,13 +372,13 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
match op {
// Exiting a function (via a return or unreachable) or otherwise
// entering a different function (via a call) means that we need to
// update the fuel consumption in `VMRuntimeLimits` because we're
// update the fuel consumption in `VMStoreContext` because we're
// about to move control out of this function itself and the fuel
// may need to be read.
//
// Before this we need to update the fuel counter from our own cost
// leading up to this function call, and then we can store
// `self.fuel_var` into `VMRuntimeLimits`.
// `self.fuel_var` into `VMStoreContext`.
Operator::Unreachable
| Operator::Return
| Operator::CallIndirect { .. }
Expand Down Expand Up @@ -463,7 +463,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
builder.def_var(self.fuel_var, fuel);
}

/// Loads the fuel consumption value from `VMRuntimeLimits` into `self.fuel_var`
/// Loads the fuel consumption value from `VMStoreContext` into `self.fuel_var`
fn fuel_load_into_var(&mut self, builder: &mut FunctionBuilder<'_>) {
let (addr, offset) = self.fuel_addr_offset();
let fuel = builder
Expand All @@ -473,7 +473,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
}

/// Stores the fuel consumption value from `self.fuel_var` into
/// `VMRuntimeLimits`.
/// `VMStoreContext`.
fn fuel_save_from_var(&mut self, builder: &mut FunctionBuilder<'_>) {
let (addr, offset) = self.fuel_addr_offset();
let fuel_consumed = builder.use_var(self.fuel_var);
Expand All @@ -483,12 +483,12 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
}

/// Returns the `(address, offset)` of the fuel consumption within
/// `VMRuntimeLimits`, used to perform loads/stores later.
/// `VMStoreContext`, used to perform loads/stores later.
fn fuel_addr_offset(&mut self) -> (ir::Value, ir::immediates::Offset32) {
debug_assert!(!self.vmruntime_limits_ptr.is_reserved_value());
debug_assert!(!self.vmstore_context_ptr.is_reserved_value());
(
self.vmruntime_limits_ptr,
i32::from(self.offsets.ptr.vmruntime_limits_fuel_consumed()).into(),
self.vmstore_context_ptr,
i32::from(self.offsets.ptr.vmstore_context_fuel_consumed()).into(),
)
}

Expand Down Expand Up @@ -672,15 +672,12 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
// We keep the deadline cached in a register to speed the checks
// in the common case (between epoch ticks) but we want to do a
// precise check here by reloading the cache first.
let deadline =
builder.ins().load(
ir::types::I64,
ir::MemFlags::trusted(),
self.vmruntime_limits_ptr,
ir::immediates::Offset32::new(
self.offsets.ptr.vmruntime_limits_epoch_deadline() as i32
),
);
let deadline = builder.ins().load(
ir::types::I64,
ir::MemFlags::trusted(),
self.vmstore_context_ptr,
ir::immediates::Offset32::new(self.offsets.ptr.vmstore_context_epoch_deadline() as i32),
);
builder.def_var(self.epoch_deadline_var, deadline);
self.epoch_check_cached(builder, cur_epoch_value, continuation_block);

Expand Down Expand Up @@ -3088,10 +3085,10 @@ impl FuncEnvironment<'_> {
self.conditionally_trap(builder, overflow, ir::TrapCode::STACK_OVERFLOW);
}

// If the `vmruntime_limits_ptr` variable will get used then we initialize
// it here.
// If the `vmstore_context_ptr` variable will get used then we
// initialize it here.
if self.tunables.consume_fuel || self.tunables.epoch_interruption {
self.declare_vmruntime_limits_ptr(builder);
self.declare_vmstore_context_ptr(builder);
}
// Additionally we initialize `fuel_var` if it will get used.
if self.tunables.consume_fuel {
Expand Down
2 changes: 1 addition & 1 deletion crates/environ/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ macro_rules! foreach_builtin_function {
// Wasm code, so that it doesn't need to make a libcall to go from
// id to `VMFuncRef`. That will be a little tricky: it will also
// require updating the pointer to the slab in the `VMContext` (or
// `VMRuntimeLimits` or wherever we put it) when the slab is
// `VMStoreContext` or wherever we put it) when the slab is
// resized.
#[cfg(feature = "gc")]
get_interned_func_ref(
Expand Down
14 changes: 7 additions & 7 deletions crates/environ/src/component/vmcomponent_offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// struct VMComponentContext {
// magic: u32,
// builtins: &'static VMComponentBuiltins,
// limits: *const VMRuntimeLimits,
// limits: *const VMStoreContext,
// flags: [VMGlobalDefinition; component.num_runtime_component_instances],
// trampoline_func_refs: [VMFuncRef; component.num_trampolines],
// lowerings: [VMLowering; component.num_lowerings],
Expand Down Expand Up @@ -61,7 +61,7 @@ pub struct VMComponentOffsets<P> {
// precalculated offsets of various member fields
magic: u32,
builtins: u32,
limits: u32,
vm_store_context: u32,
flags: u32,
trampoline_func_refs: u32,
lowerings: u32,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl<P: PtrSize> VMComponentOffsets<P> {
num_resources: component.num_resources,
magic: 0,
builtins: 0,
limits: 0,
vm_store_context: 0,
flags: 0,
trampoline_func_refs: 0,
lowerings: 0,
Expand Down Expand Up @@ -138,7 +138,7 @@ impl<P: PtrSize> VMComponentOffsets<P> {
size(magic) = 4u32,
align(u32::from(ret.ptr.size())),
size(builtins) = ret.ptr.size(),
size(limits) = ret.ptr.size(),
size(vm_store_context) = ret.ptr.size(),
align(16),
size(flags) = cmul(ret.num_runtime_component_instances, ret.ptr.size_of_vmglobal_definition()),
align(u32::from(ret.ptr.size())),
Expand Down Expand Up @@ -186,10 +186,10 @@ impl<P: PtrSize> VMComponentOffsets<P> {
self.flags + index.as_u32() * u32::from(self.ptr.size_of_vmglobal_definition())
}

/// The offset of the `limits` field.
/// The offset of the `vm_store_context` field.
#[inline]
pub fn limits(&self) -> u32 {
self.limits
pub fn vm_store_context(&self) -> u32 {
self.vm_store_context
}

/// The offset of the `trampoline_func_refs` field.
Expand Down
Loading