Save exit Wasm FP and PC in component-to-host trampolines (#4601)

* Wasmtime: Add a pointer to `VMRuntimeLimits` in component contexts

* Save exit Wasm FP and PC in component-to-host trampolines

Fixes #4535

* Add comment about why we deref the trampoline's FP

* Update some tests to use new `vmruntime_limits_*` methods
This commit is contained in:
Nick Fitzgerald
2022-08-04 08:27:30 -07:00
committed by GitHub
parent f69acd6187
commit 70ce288dc7
16 changed files with 206 additions and 149 deletions

View File

@@ -3,6 +3,7 @@
// struct VMComponentContext {
// magic: u32,
// store: *mut dyn Store,
// limits: *const VMRuntimeLimits,
// flags: [VMGlobalDefinition; component.num_runtime_component_instances],
// lowering_anyfuncs: [VMCallerCheckedAnyfunc; component.num_lowerings],
// always_trap_anyfuncs: [VMCallerCheckedAnyfunc; component.num_always_trap],
@@ -60,6 +61,7 @@ pub struct VMComponentOffsets<P> {
// precalculated offsets of various member fields
magic: u32,
store: u32,
limits: u32,
flags: u32,
lowering_anyfuncs: u32,
always_trap_anyfuncs: u32,
@@ -93,6 +95,7 @@ impl<P: PtrSize> VMComponentOffsets<P> {
num_always_trap: component.num_always_trap,
magic: 0,
store: 0,
limits: 0,
flags: 0,
lowering_anyfuncs: 0,
always_trap_anyfuncs: 0,
@@ -131,6 +134,7 @@ impl<P: PtrSize> VMComponentOffsets<P> {
size(magic) = 4u32,
align(u32::from(ret.ptr.size())),
size(store) = cmul(2, ret.ptr.size()),
size(limits) = 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())),
@@ -177,6 +181,12 @@ impl<P: PtrSize> VMComponentOffsets<P> {
self.store
}
/// The offset of the `limits` field.
#[inline]
pub fn limits(&self) -> u32 {
self.limits
}
/// The offset of the `lowering_anyfuncs` field.
#[inline]
pub fn lowering_anyfuncs(&self) -> u32 {

View File

@@ -135,6 +135,39 @@ pub trait PtrSize {
fn size_of_vmglobal_definition(&self) -> u8 {
16
}
/// Return the offset of the `stack_limit` field of `VMRuntimeLimits`
#[inline]
fn vmruntime_limits_stack_limit(&self) -> u8 {
0
}
/// Return the offset of the `fuel_consumed` field of `VMRuntimeLimits`
#[inline]
fn vmruntime_limits_fuel_consumed(&self) -> u8 {
self.size()
}
/// Return the offset of the `epoch_deadline` field of `VMRuntimeLimits`
#[inline]
fn vmruntime_limits_epoch_deadline(&self) -> u8 {
self.vmruntime_limits_fuel_consumed() + 8 // `stack_limit` is a pointer; `fuel_consumed` is an `i64`
}
/// Return the offset of the `last_wasm_exit_fp` field of `VMRuntimeLimits`.
fn vmruntime_limits_last_wasm_exit_fp(&self) -> u8 {
self.vmruntime_limits_epoch_deadline() + 8
}
/// Return the offset of the `last_wasm_exit_pc` field of `VMRuntimeLimits`.
fn vmruntime_limits_last_wasm_exit_pc(&self) -> u8 {
self.vmruntime_limits_last_wasm_exit_fp() + self.size()
}
/// Return the offset of the `last_enty_sp` field of `VMRuntimeLimits`.
fn vmruntime_limits_last_wasm_entry_sp(&self) -> u8 {
self.vmruntime_limits_last_wasm_exit_pc() + self.size()
}
}
/// Type representing the size of a pointer for the current compilation host
@@ -545,42 +578,6 @@ impl<P: PtrSize> VMOffsets<P> {
}
}
/// Offsets for `VMRuntimeLimits`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the offset of the `stack_limit` field of `VMRuntimeLimits`
#[inline]
pub fn vmruntime_limits_stack_limit(&self) -> u8 {
0
}
/// Return the offset of the `fuel_consumed` field of `VMRuntimeLimits`
#[inline]
pub fn vmruntime_limits_fuel_consumed(&self) -> u8 {
self.pointer_size()
}
/// Return the offset of the `epoch_deadline` field of `VMRuntimeLimits`
#[inline]
pub fn vmruntime_limits_epoch_deadline(&self) -> u8 {
self.vmruntime_limits_fuel_consumed() + 8 // `stack_limit` is a pointer; `fuel_consumed` is an `i64`
}
/// Return the offset of the `last_wasm_exit_fp` field of `VMRuntimeLimits`.
pub fn vmruntime_limits_last_wasm_exit_fp(&self) -> u8 {
self.vmruntime_limits_epoch_deadline() + 8
}
/// Return the offset of the `last_wasm_exit_pc` field of `VMRuntimeLimits`.
pub fn vmruntime_limits_last_wasm_exit_pc(&self) -> u8 {
self.vmruntime_limits_last_wasm_exit_fp() + self.pointer_size()
}
/// Return the offset of the `last_enty_sp` field of `VMRuntimeLimits`.
pub fn vmruntime_limits_last_wasm_entry_sp(&self) -> u8 {
self.vmruntime_limits_last_wasm_exit_pc() + self.pointer_size()
}
}
/// Offsets for `VMContext`.
impl<P: PtrSize> VMOffsets<P> {
/// Return the offset to the `magic` value in this `VMContext`.