[−][src]Struct lucet_runtime_internals::context::ContextHandle
A wrapper around a Context
, primarily meant for use in test code.
Users of this library interact with contexts implicitly via Instance
values, but for testing
the context code independently, it is helpful to use contexts directly.
Movement of ContextHandle
ContextHandle
keeps a pointer to a Context
rather than keeping all of the data directly as
fields in order to have better control over where that data lives in memory. We always want that
data to be heap-allocated, and to never move once it has been initialized. The ContextHandle
,
by contrast, should be treated like a normal Rust value with no such restrictions.
Until the Unpin
marker trait arrives in stable Rust, it is difficult to enforce this with the
type system alone, so we use a bit of unsafety and (hopefully) clever API design to ensure that
the data cannot be moved.
We create the Context
within a box to allocate it on the heap, then convert it into a raw
pointer to relinquish ownership. When accessing the internal structure via the DerefMut
trait,
data must not be moved out of the Context
with functions like mem::replace
.
Layout
Foreign code accesses the internal
pointer in tests, so it is important that it is the first
member, and that the struct is repr(C)
.
Methods
impl ContextHandle
[src]
pub fn new() -> Self
[src]
Create an all-zeroed ContextHandle
.
pub fn create_and_init(
stack: &mut [u64],
parent: &mut ContextHandle,
fptr: usize,
args: &[Val]
) -> Result<ContextHandle, Error>
[src]
stack: &mut [u64],
parent: &mut ContextHandle,
fptr: usize,
args: &[Val]
) -> Result<ContextHandle, Error>
Methods from Deref<Target = Context>
pub fn clear_retvals(&mut self)
[src]
Clear (zero) return values.
pub fn get_retval_gp(&self, idx: usize) -> u64
[src]
Get the general-purpose return value at index idx
.
If this method is called before the context has returned from its original entrypoint, the
result will be 0
.
pub fn get_retval_fp(&self) -> __m128
[src]
Get the floating point return value.
If this method is called before the context has returned from its original entrypoint, the
result will be 0.0
.
pub fn get_untyped_retval(&self) -> UntypedRetVal
[src]
Get the return value as an UntypedRetVal
.
This combines the 0th general-purpose return value, and the single floating-point return value.
Trait Implementations
impl Drop for ContextHandle
[src]
impl Deref for ContextHandle
[src]
impl DerefMut for ContextHandle
[src]
Auto Trait Implementations
impl !Send for ContextHandle
impl !Sync for ContextHandle
impl Unpin for ContextHandle
impl UnwindSafe for ContextHandle
impl RefUnwindSafe for ContextHandle
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self