silk.platform.wasi.component.
Memory and polling operations shared by WASI Preview 2 providers.
Details#
These types use the wasm32 canonical ABI. Imported lists use the same allocator as Silk and their owners release the allocation. Pollable owners release their resource exactly once.
Import as wasi_component with import silk.platform.wasi.component as wasi_component.
Public declarations: 6.
ResultArea#
pub extern "C" struct ResultAreaAn aligned, initialized result area for canonical results up to 128 bytes.
address#
pub fn address<T>(value: &mut T) -> u32Returns the wasm32 address of a live value. The caller keeps the value alive through the call.
byte#
pub unsafe fn byte<T>(value: &T, offset: usize) -> u8Reads a byte of an initialized foreign record. offset must be inside its storage.
Implementation ResultArea#
impl ResultAreaAssociated function make#
pub fn make() -> ResultAreaMakes a zeroed canonical result area, aligned to eight bytes.
Method byte#
pub fn byte(self: &Self, offset: usize) -> u8Reads one initialized byte. offset must be below 128.
Method word16#
pub fn word16(self: &Self, offset: usize) -> u16Reads one little-endian 16-bit integer. offset must be at most 126.
Method word32#
pub fn word32(self: &Self, offset: usize) -> u32Reads one little-endian 32-bit integer. offset must be at most 124.
Method word64#
pub fn word64(self: &Self, offset: usize) -> u64Reads one little-endian 64-bit integer. offset must be at most 120.
Pollable#
pub struct PollableAn owned WASI pollable. Drop releases the resource; it must precede its parent resource.
expired#
pub effect fn expired(deadline: &Option<Instant>) -> bool ? &mut MonotonicClockWhether an optional absolute deadline has expired on the supplied monotonic clock.
Implementation Pollable#
impl PollableAssociated function take#
pub unsafe fn take(handle: u32) -> PollableTakes ownership of a live pollable handle. The caller must surrender its previous owner.
Method wait#
pub effect fn wait(self: &Self, deadline: &Option<Instant>) -> bool ? &mut MonotonicClockWaits for readiness, returning false when the deadline on the supplied clock expires. With no deadline the host blocks directly. With a deadline readiness is checked at most one millisecond apart, using the supplied clock for both time and waiting.
Implementation Drop for Pollable#
impl Drop for PollableOperation drop#
fn drop(self: &mut Self) -> ()StreamResult#
pub extern "C" struct StreamResultAn owned canonical result<list<u8>, stream-error>, initialized before a stream read.
Drop releases the returned buffer or error resource. Read fields only through its methods.
Implementation StreamResult#
impl StreamResultAssociated function make#
pub fn make() -> StreamResultInitializes storage for a host read. Pass its address as the indirect return argument.
Method succeeded#
pub fn succeeded(self: &Self) -> boolWhether the host returned bytes rather than a stream error.
Method count#
pub fn count(self: &Self) -> usizeThe byte count of a successful result. Call only after succeeded returns true.
Method ended#
pub fn ended(self: &Self) -> boolWhether the host reported that the stream ended.
Method copyTo#
pub fn copyTo(self: &Self, output: &mut [u8]) -> usizeCopies the returned bytes into output. The host result must be a successful read of at
most output.length bytes; an invalid host count traps before memory is accessed.
Implementation Drop for StreamResult#
impl Drop for StreamResultOperation drop#
fn drop(self: &mut Self) -> ()Category: Native platform.
Profiles: wasm32-wasip2.