silk.platform.wasi.preview1.
The WASI Preview 1 canonical ABI, also used inside Preview 2 command components.
When to use#
Use these unsafe calls to implement a WASI provider. Applications use the portable service interfaces.
Details#
Functions return a WASI errno: zero means success. Pointer arguments use the Preview 1 memory layouts. Calls do not retain pointers. The host controls descriptor rights and available resources. Preview 2 builds translate these calls through the WASI command adapter.
Import as wasi with import silk.platform.wasi.preview1 as wasi.
Public declarations: 53.
IoVector#
pub extern "C" struct IoVectorThe Preview 1 IoVector memory record, with the canonical ABI layout.
Field base#
pub base: ?[*]mut u8The writable buffer.
Field length#
pub length: u32The buffer capacity in bytes.
ConstIoVector#
pub extern "C" struct ConstIoVectorThe Preview 1 ConstIoVector memory record, with the canonical ABI layout.
Field base#
pub base: ?[*]const u8The readable buffer.
Field length#
pub length: u32The buffer length in bytes.
FdStat#
pub extern "C" struct FdStatThe Preview 1 FdStat memory record, with the canonical ABI layout.
Field kind#
pub kind: u8The WASI file type.
Field flags#
pub flags: u16The descriptor flags.
Field rights#
pub rights: u64The descriptor rights.
Field inheriting#
pub inheriting: u64The rights available to child descriptors.
FileStat#
pub extern "C" struct FileStatThe Preview 1 FileStat memory record, with the canonical ABI layout.
Field device#
pub device: u64The device identifier.
Field inode#
pub inode: u64The inode identifier.
Field kind#
pub kind: u8The WASI file type.
Field links#
pub links: u64The link count.
Field size#
pub size: u64The file size in bytes.
Field access#
pub access: u64The access time in nanoseconds.
Field modified#
pub modified: u64The modification time in nanoseconds.
Field changed#
pub changed: u64The status-change time in nanoseconds.
Prestat#
pub extern "C" struct PrestatThe Preview 1 Prestat memory record, with the canonical ABI layout.
Field kind#
pub kind: u8The preopen type; zero identifies a directory.
Field length#
pub length: u32The preopened directory name length in bytes.
Subscription#
pub extern "C" struct SubscriptionThe Preview 1 Subscription memory record, with the canonical ABI layout.
Field userdata#
pub userdata: u64The caller identifier returned with the event.
Field kind#
pub kind: u8The event type; zero selects a clock.
Field reserved#
pub reserved: [u8; 7]Reserved bytes; initialize to zero.
Field clock#
pub clock: u32The clock identifier for a clock subscription.
Field timeout#
pub timeout: u64The clock deadline or duration, in nanoseconds.
Field precision#
pub precision: u64The permitted clock tolerance, in nanoseconds.
Field flags#
pub flags: u16The clock flags; one selects an absolute deadline.
Event#
pub extern "C" struct EventThe Preview 1 Event memory record, with the canonical ABI layout.
Field userdata#
pub userdata: u64The caller identifier from the subscription.
Field error#
pub error: u16The WASI errno for this event.
Field kind#
pub kind: u8The event type.
Field bytes#
pub bytes: u64The readable or writable byte count for a descriptor event.
Field flags#
pub flags: u16The descriptor event flags.
args_get#
pub unsafe extern "C" fn args_get(
argv: ?[*]mut ?[*]mut u8,
buffer: ?[*]mut u8
) -> u32 as "silk_wasi_args_get"Calls WASI args_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
args_sizes_get#
pub unsafe extern "C" fn args_sizes_get(
count: *mut u32,
size: *mut u32
) -> u32 as "silk_wasi_args_sizes_get"Calls WASI args_sizes_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
environ_get#
pub unsafe extern "C" fn environ_get(
environ: ?[*]mut ?[*]mut u8,
buffer: ?[*]mut u8
) -> u32 as "silk_wasi_environ_get"Calls WASI environ_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
environ_sizes_get#
pub unsafe extern "C" fn environ_sizes_get(
count: *mut u32,
size: *mut u32
) -> u32 as "silk_wasi_environ_sizes_get"Calls WASI environ_sizes_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
clock_res_get#
pub unsafe extern "C" fn clock_res_get(
clock: u32,
resolution: *mut u64
) -> u32 as "silk_wasi_clock_res_get"Calls WASI clock_res_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
clock_time_get#
pub unsafe extern "C" fn clock_time_get(
clock: u32,
precision: u64,
time: *mut u64
) -> u32 as "silk_wasi_clock_time_get"Calls WASI clock_time_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_advise#
pub unsafe extern "C" fn fd_advise(
fd: u32,
offset: u64,
length: u64,
advice: u32
) -> u32 as "silk_wasi_fd_advise"Calls WASI fd_advise with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_allocate#
pub unsafe extern "C" fn fd_allocate(
fd: u32,
offset: u64,
length: u64
) -> u32 as "silk_wasi_fd_allocate"Calls WASI fd_allocate with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_close#
pub unsafe extern "C" fn fd_close(fd: u32) -> u32 as "silk_wasi_fd_close"Calls WASI fd_close with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_datasync#
pub unsafe extern "C" fn fd_datasync(fd: u32) -> u32 as "silk_wasi_fd_datasync"Calls WASI fd_datasync with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_fdstat_get#
pub unsafe extern "C" fn fd_fdstat_get(
fd: u32,
stat: *mut FdStat
) -> u32 as "silk_wasi_fd_fdstat_get"Calls WASI fd_fdstat_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_fdstat_set_flags#
pub unsafe extern "C" fn fd_fdstat_set_flags(
fd: u32,
flags: u32
) -> u32 as "silk_wasi_fd_fdstat_set_flags"Calls WASI fd_fdstat_set_flags with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_fdstat_set_rights#
pub unsafe extern "C" fn fd_fdstat_set_rights(
fd: u32,
base: u64,
inheriting: u64
) -> u32 as "silk_wasi_fd_fdstat_set_rights"Calls WASI fd_fdstat_set_rights with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_filestat_get#
pub unsafe extern "C" fn fd_filestat_get(
fd: u32,
stat: *mut FileStat
) -> u32 as "silk_wasi_fd_filestat_get"Calls WASI fd_filestat_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_filestat_set_size#
pub unsafe extern "C" fn fd_filestat_set_size(
fd: u32,
size: u64
) -> u32 as "silk_wasi_fd_filestat_set_size"Calls WASI fd_filestat_set_size with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_filestat_set_times#
pub unsafe extern "C" fn fd_filestat_set_times(
fd: u32,
access: u64,
modified: u64,
flags: u32
) -> u32 as "silk_wasi_fd_filestat_set_times"Calls WASI fd_filestat_set_times with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_pread#
pub unsafe extern "C" fn fd_pread(
fd: u32,
vectors: ?[*]const IoVector,
count: u32,
offset: u64,
read: *mut u32
) -> u32 as "silk_wasi_fd_pread"Calls WASI fd_pread with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_prestat_get#
pub unsafe extern "C" fn fd_prestat_get(
fd: u32,
stat: *mut Prestat
) -> u32 as "silk_wasi_fd_prestat_get"Calls WASI fd_prestat_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_prestat_dir_name#
pub unsafe extern "C" fn fd_prestat_dir_name(
fd: u32,
path: ?[*]mut u8,
length: u32
) -> u32 as "silk_wasi_fd_prestat_dir_name"Calls WASI fd_prestat_dir_name with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_pwrite#
pub unsafe extern "C" fn fd_pwrite(
fd: u32,
vectors: ?[*]const ConstIoVector,
count: u32,
offset: u64,
written: *mut u32
) -> u32 as "silk_wasi_fd_pwrite"Calls WASI fd_pwrite with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_read#
pub unsafe extern "C" fn fd_read(
fd: u32,
vectors: ?[*]const IoVector,
count: u32,
read: *mut u32
) -> u32 as "silk_wasi_fd_read"Calls WASI fd_read with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_readdir#
pub unsafe extern "C" fn fd_readdir(
fd: u32,
buffer: ?[*]mut u8,
length: u32,
cookie: u64,
used: *mut u32
) -> u32 as "silk_wasi_fd_readdir"Calls WASI fd_readdir with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_renumber#
pub unsafe extern "C" fn fd_renumber(from: u32, to: u32) -> u32 as "silk_wasi_fd_renumber"Calls WASI fd_renumber with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_seek#
pub unsafe extern "C" fn fd_seek(
fd: u32,
offset: i64,
whence: u32,
position: *mut u64
) -> u32 as "silk_wasi_fd_seek"Calls WASI fd_seek with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_sync#
pub unsafe extern "C" fn fd_sync(fd: u32) -> u32 as "silk_wasi_fd_sync"Calls WASI fd_sync with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_tell#
pub unsafe extern "C" fn fd_tell(
fd: u32,
position: *mut u64
) -> u32 as "silk_wasi_fd_tell"Calls WASI fd_tell with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
fd_write#
pub unsafe extern "C" fn fd_write(
fd: u32,
vectors: ?[*]const ConstIoVector,
count: u32,
written: *mut u32
) -> u32 as "silk_wasi_fd_write"Calls WASI fd_write with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_create_directory#
pub unsafe extern "C" fn path_create_directory(
fd: u32,
path: ?[*]const u8,
length: u32
) -> u32 as "silk_wasi_path_create_directory"Calls WASI path_create_directory with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_filestat_get#
pub unsafe extern "C" fn path_filestat_get(
fd: u32,
flags: u32,
path: ?[*]const u8,
length: u32,
stat: *mut FileStat
) -> u32 as "silk_wasi_path_filestat_get"Calls WASI path_filestat_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_filestat_set_times#
pub unsafe extern "C" fn path_filestat_set_times(
fd: u32,
lookup: u32,
path: ?[*]const u8,
length: u32,
access: u64,
modified: u64,
flags: u32
) -> u32 as "silk_wasi_path_filestat_set_times"Calls WASI path_filestat_set_times with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_link#
pub unsafe extern "C" fn path_link(
oldfd: u32,
flags: u32,
oldpath: ?[*]const u8,
oldlength: u32,
newfd: u32,
newpath: ?[*]const u8,
newlength: u32
) -> u32 as "silk_wasi_path_link"Calls WASI path_link with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_open#
pub unsafe extern "C" fn path_open(
fd: u32,
lookup: u32,
path: ?[*]const u8,
length: u32,
flags: u32,
rights: u64,
inheriting: u64,
descriptorFlags: u32,
opened: *mut u32
) -> u32 as "silk_wasi_path_open"Calls WASI path_open with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_readlink#
pub unsafe extern "C" fn path_readlink(
fd: u32,
path: ?[*]const u8,
length: u32,
buffer: ?[*]mut u8,
capacity: u32,
used: *mut u32
) -> u32 as "silk_wasi_path_readlink"Calls WASI path_readlink with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_remove_directory#
pub unsafe extern "C" fn path_remove_directory(
fd: u32,
path: ?[*]const u8,
length: u32
) -> u32 as "silk_wasi_path_remove_directory"Calls WASI path_remove_directory with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_rename#
pub unsafe extern "C" fn path_rename(
oldfd: u32,
oldpath: ?[*]const u8,
oldlength: u32,
newfd: u32,
newpath: ?[*]const u8,
newlength: u32
) -> u32 as "silk_wasi_path_rename"Calls WASI path_rename with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_symlink#
pub unsafe extern "C" fn path_symlink(
oldpath: ?[*]const u8,
oldlength: u32,
fd: u32,
newpath: ?[*]const u8,
newlength: u32
) -> u32 as "silk_wasi_path_symlink"Calls WASI path_symlink with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
path_unlink_file#
pub unsafe extern "C" fn path_unlink_file(
fd: u32,
path: ?[*]const u8,
length: u32
) -> u32 as "silk_wasi_path_unlink_file"Calls WASI path_unlink_file with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
poll_oneoff#
pub unsafe extern "C" fn poll_oneoff(
subscriptions: ?[*]const Subscription,
events: ?[*]mut Event,
count: u32,
received: *mut u32
) -> u32 as "silk_wasi_poll_oneoff"Calls WASI poll_oneoff with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
proc_exit#
pub unsafe extern "C" fn proc_exit(code: u32) -> () as "silk_wasi_proc_exit"Calls WASI proc_exit with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call. This call terminates the process without resource cleanup.
proc_raise#
pub unsafe extern "C" fn proc_raise(signal: u32) -> u32 as "silk_wasi_proc_raise"Calls WASI proc_raise with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
random_get#
pub unsafe extern "C" fn random_get(
buffer: ?[*]mut u8,
length: u32
) -> u32 as "silk_wasi_random_get"Calls WASI random_get with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
sched_yield#
pub unsafe extern "C" fn sched_yield() -> u32 as "silk_wasi_sched_yield"Calls WASI sched_yield with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
sock_accept#
pub unsafe extern "C" fn sock_accept(
fd: u32,
flags: u32,
accepted: *mut u32
) -> u32 as "silk_wasi_sock_accept"Calls WASI sock_accept with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
sock_recv#
pub unsafe extern "C" fn sock_recv(
fd: u32,
vectors: ?[*]const IoVector,
count: u32,
flags: u32,
received: *mut u32,
resultFlags: *mut u16
) -> u32 as "silk_wasi_sock_recv"Calls WASI sock_recv with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
sock_send#
pub unsafe extern "C" fn sock_send(
fd: u32,
vectors: ?[*]const ConstIoVector,
count: u32,
flags: u32,
sent: *mut u32
) -> u32 as "silk_wasi_sock_send"Calls WASI sock_send with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
sock_shutdown#
pub unsafe extern "C" fn sock_shutdown(fd: u32, how: u32) -> u32 as "silk_wasi_sock_shutdown"Calls WASI sock_shutdown with the Preview 1 ABI.
Gotchas#
All pointers must address the buffers and structures that the WASI specification requires for this call.
Category: Native platform.
Profiles: wasm32-wasip1, wasm32-wasip2.