Struct wasmer_runtime_fl::WasmPtr [−][src]
Expand description
A zero-cost type that represents a pointer to something in Wasm linear memory.
This type can be used directly in the host function arguments:
pub fn host_import(ctx: &mut Ctx, ptr: WasmPtr<u32>) { let memory = ctx.memory(0); let derefed_ptr = ptr.deref(memory).expect("pointer in bounds"); let inner_val: u32 = derefed_ptr.get(); println!("Got {} from Wasm memory address 0x{:X}", inner_val, ptr.offset()); // update the value being pointed to derefed_ptr.set(inner_val + 1); }
Implementations
Methods relevant to all types of WasmPtr
.
Methods for WasmPtr
s to data that can be dereferenced, namely to types
that implement ValueType
, meaning that they’re valid for all possible
bit patterns.
Dereference the WasmPtr
getting access to a &Cell<T>
allowing for
reading and mutating of the inner value.
This method is unsound if used with unsynchronized shared memory. If you’re unsure what that means, it likely does not apply to you. This invariant will be enforced in the future.
Mutably dereference this WasmPtr
getting a &mut Cell<T>
allowing for
direct access to a &mut T
.
Safety
- This method does not do any aliasing checks: it’s possible to create
&mut T
that point to the same memory. You should ensure that you have exclusive access to Wasm linear memory before calling this method.
Methods for WasmPtr
s to arrays of data that can be dereferenced, namely to
types that implement ValueType
, meaning that they’re valid for all
possible bit patterns.
Dereference the WasmPtr
getting access to a &[Cell<T>]
allowing for
reading and mutating of the inner values.
This method is unsound if used with unsynchronized shared memory. If you’re unsure what that means, it likely does not apply to you. This invariant will be enforced in the future.
Mutably dereference this WasmPtr
getting a &mut [Cell<T>]
allowing for
direct access to a &mut [T]
.
Safety
- This method does not do any aliasing checks: it’s possible to create
&mut T
that point to the same memory. You should ensure that you have exclusive access to Wasm linear memory before calling this method.
Get a UTF-8 string from the WasmPtr
with the given length.
Note that this method returns a reference to Wasm linear memory. The
underlying data can be mutated if the Wasm is allowed to execute or
an aliasing WasmPtr
is used to mutate memory.
Get a UTF-8 string from the WasmPtr
, where the string is nul-terminated.
Note that this does not account for UTF-8 strings that contain nul themselves,
[get_utf8_string
] has to be used for those.
Also note that this method returns a reference to Wasm linear memory. The
underlying data can be mutated if the Wasm is allowed to execute or
an aliasing WasmPtr
is used to mutate memory.
Trait Implementations
Convert self to Native
type.
Convert from given Native
type to self.
Auto Trait Implementations
impl<T, Ty> RefUnwindSafe for WasmPtr<T, Ty> where
T: RefUnwindSafe,
Ty: RefUnwindSafe,
impl<T, Ty> UnwindSafe for WasmPtr<T, Ty> where
T: UnwindSafe,
Ty: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
type Output = T
type Output = T
Should always be Self
type Error = Infallible
type Error = Infallible
The error type for this trait.
Get returns or error result.
Construct Self
based on an array of returned values.
Generates an empty array that will hold the returned values of the WebAssembly function. Read more
Transforms C values into Rust values.
Transforms Rust values into C values.
Get types of the current values.
pub unsafe fn call<Rets>(
self,
f: NonNull<Func>,
wasm: Wasm,
ctx: *mut Ctx
) -> Result<Rets, RuntimeError> where
Rets: WasmTypeList,
pub unsafe fn call<Rets>(
self,
f: NonNull<Func>,
wasm: Wasm,
ctx: *mut Ctx
) -> Result<Rets, RuntimeError> where
Rets: WasmTypeList,
This method is used to distribute the values onto a function,
e.g. (1, 2).call(func, …)
. This form is unlikely to be used
directly in the code, see the Func::call
implementation. Read more