跳转到内容
标准库Zig 0.17.0官方原文
源码std/os/wasi.zig

第 1 行

wasi_snapshot_preview1 规范以 witx 格式提供于:

  • 类型名:https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/typenames.witx
  • 模块:https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/wasi_snapshot_preview1.witx 注意,libc API 不放在此文件;WASI libc API 放入 std/c.zig。

std.os.wasi.advice_t

容器

第 85 行

字段

NORMAL = 0
SEQUENTIAL = 1
RANDOM = 2
WILLNEED = 3
DONTNEED = 4
NOREUSE = 5

std.os.wasi.args_get

函数

第 25 行

pub extern "wasi_snapshot_preview1" fn args_get(argv: [*][*:0]u8, argv_buf: [*]u8) errno_t

参数

argv: [*][*:0]u8
argv_buf: [*]u8

std.os.wasi.args_sizes_get

函数

第 26 行

pub extern "wasi_snapshot_preview1" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t

参数

argc: *usize
argv_buf_size: *usize

std.os.wasi.assert

别名

第 7 行

别名目标 std.debug.assert

std.os.wasi.builtin

常量

第 5 行

std.os.wasi.ciovec_t

别名

第 23 行

别名目标 std.posix.iovec_const

std.os.wasi.clock_res_get

函数

第 28 行

pub extern "wasi_snapshot_preview1" fn clock_res_get(clock_id: clockid_t, resolution: *timestamp_t) errno_t

参数

clock_id: clockid_t
resolution: *timestamp_t

std.os.wasi.clock_time_get

函数

第 29 行

pub extern "wasi_snapshot_preview1" fn clock_time_get(clock_id: clockid_t, precision: timestamp_t, timestamp: *timestamp_t) errno_t

参数

clock_id: clockid_t
precision: timestamp_t
timestamp: *timestamp_t

std.os.wasi.clockid_t

容器

第 94 行

字段

REALTIME = 0
MONOTONIC = 1
PROCESS_CPUTIME_ID = 2
THREAD_CPUTIME_ID = 3

std.os.wasi.device_t

类型

第 101 行

std.os.wasi.DIRCOOKIE_START

常量

第 104 行

dircookie_t

std.os.wasi.dircookie_t

类型

第 103 行

std.os.wasi.dirent_t

容器

第 108 行

字段

next: dircookie_t
ino: inode_t
namlen: dirnamlen_t
type: filetype_t

std.os.wasi.dirnamlen_t

类型

第 106 行

std.os.wasi.environ_get

函数

第 31 行

pub extern "wasi_snapshot_preview1" fn environ_get(environ: [*][*:0]u8, environ_buf: [*]u8) errno_t

参数

environ: [*][*:0]u8
environ_buf: [*]u8

std.os.wasi.environ_sizes_get

函数

第 32 行

pub extern "wasi_snapshot_preview1" fn environ_sizes_get(environ_count: *usize, environ_buf_size: *usize) errno_t

参数

environ_count: *usize
environ_buf_size: *usize

std.os.wasi.errno_t

容器

第 115 行

字段

SUCCESS = 0
@"2BIG" = 1
ACCES = 2
ADDRINUSE = 3
ADDRNOTAVAIL = 4
AFNOSUPPORT = 5
AGAIN = 6

此错误码也用于 WOULDBLOCK。

ALREADY = 7
BADF = 8
BADMSG = 9
BUSY = 10
CANCELED = 11
CHILD = 12
CONNABORTED = 13
CONNREFUSED = 14
CONNRESET = 15
DEADLK = 16
DESTADDRREQ = 17
DOM = 18
DQUOT = 19
EXIST = 20
FAULT = 21
FBIG = 22
HOSTUNREACH = 23
IDRM = 24
ILSEQ = 25
INPROGRESS = 26
INTR = 27
INVAL = 28
IO = 29
ISCONN = 30
ISDIR = 31
LOOP = 32
MFILE = 33
MLINK = 34
MSGSIZE = 35
MULTIHOP = 36
NAMETOOLONG = 37
NETDOWN = 38
NETRESET = 39
NETUNREACH = 40
NFILE = 41
NOBUFS = 42
NODEV = 43
NOENT = 44
NOEXEC = 45
NOLCK = 46
NOLINK = 47
NOMEM = 48
NOMSG = 49
NOPROTOOPT = 50
NOSPC = 51
NOSYS = 52
NOTCONN = 53
NOTDIR = 54
NOTEMPTY = 55
NOTRECOVERABLE = 56
NOTSOCK = 57
OPNOTSUPP = 58

这也是用于 NOTSUP 的代码。

NOTTY = 59
NXIO = 60
OVERFLOW = 61
OWNERDEAD = 62
PERM = 63
PIPE = 64
PROTO = 65
PROTONOSUPPORT = 66
PROTOTYPE = 67
RANGE = 68
ROFS = 69
SPIPE = 70
SRCH = 71
STALE = 72
TIMEDOUT = 73
TXTBSY = 74
XDEV = 75
NOTCAPABLE = 76
_

std.os.wasi.EVENT_FD_READWRITE_HANGUP

常量

第 211 行

eventrwflags_t

std.os.wasi.event_t

容器

第 198 行

字段

userdata: userdata_t
@"error": errno_t
type: eventtype_t
fd_readwrite: eventfdreadwrite_t

std.os.wasi.eventfdreadwrite_t

容器

第 205 行

字段

nbytes: filesize_t
flags: eventrwflags_t

std.os.wasi.eventrwflags_t

类型

第 210 行

std.os.wasi.eventtype_t

容器

第 213 行

字段

CLOCK = 0
FD_READ = 1
FD_WRITE = 2

std.os.wasi.exitcode_t

类型

第 219 行

std.os.wasi.fd_advise

函数

第 34 行

pub extern "wasi_snapshot_preview1" fn fd_advise(fd: fd_t, offset: filesize_t, len: filesize_t, advice: advice_t) errno_t

参数

fd: fd_t
offset: filesize_t
len: filesize_t
advice: advice_t

std.os.wasi.fd_allocate

函数

第 35 行

pub extern "wasi_snapshot_preview1" fn fd_allocate(fd: fd_t, offset: filesize_t, len: filesize_t) errno_t

参数

fd: fd_t
offset: filesize_t
len: filesize_t

std.os.wasi.fd_close

函数

第 36 行

pub extern "wasi_snapshot_preview1" fn fd_close(fd: fd_t) errno_t

参数

fd: fd_t

std.os.wasi.fd_datasync

函数

第 37 行

pub extern "wasi_snapshot_preview1" fn fd_datasync(fd: fd_t) errno_t

参数

fd: fd_t

std.os.wasi.fd_fdstat_get

函数

第 48 行

pub extern "wasi_snapshot_preview1" fn fd_fdstat_get(fd: fd_t, buf: *fdstat_t) errno_t

参数

fd: fd_t
buf: *fdstat_t

std.os.wasi.fd_fdstat_set_flags

函数

第 49 行

pub extern "wasi_snapshot_preview1" fn fd_fdstat_set_flags(fd: fd_t, flags: fdflags_t) errno_t

参数

fd: fd_t
flags: fdflags_t

std.os.wasi.fd_fdstat_set_rights

函数

第 50 行

pub extern "wasi_snapshot_preview1" fn fd_fdstat_set_rights(fd: fd_t, fs_rights_base: rights_t, fs_rights_inheriting: rights_t) errno_t

参数

fd: fd_t
fs_rights_base: rights_t
fs_rights_inheriting: rights_t

std.os.wasi.fd_filestat_get

函数

第 52 行

pub extern "wasi_snapshot_preview1" fn fd_filestat_get(fd: fd_t, buf: *filestat_t) errno_t

参数

fd: fd_t
buf: *filestat_t

std.os.wasi.fd_filestat_set_size

函数

第 53 行

pub extern "wasi_snapshot_preview1" fn fd_filestat_set_size(fd: fd_t, st_size: filesize_t) errno_t

参数

fd: fd_t
st_size: filesize_t

std.os.wasi.fd_filestat_set_times

函数

第 54 行

pub extern "wasi_snapshot_preview1" fn fd_filestat_set_times(fd: fd_t, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags_t) errno_t

参数

fd: fd_t
st_atim: timestamp_t
st_mtim: timestamp_t
fstflags: fstflags_t

std.os.wasi.fd_pread

函数

第 38 行

pub extern "wasi_snapshot_preview1" fn fd_pread(fd: fd_t, iovs: [*]const iovec_t, iovs_len: usize, offset: filesize_t, nread: *usize) errno_t

参数

fd: fd_t
iovs: [*]const iovec_t
iovs_len: usize
offset: filesize_t
nread: *usize

std.os.wasi.fd_prestat_dir_name

函数

第 57 行

pub extern "wasi_snapshot_preview1" fn fd_prestat_dir_name(fd: fd_t, path: [*]u8, path_len: usize) errno_t

参数

fd: fd_t
path: [*]u8
path_len: usize

std.os.wasi.fd_prestat_get

函数

第 56 行

pub extern "wasi_snapshot_preview1" fn fd_prestat_get(fd: fd_t, buf: *prestat_t) errno_t

参数

fd: fd_t
buf: *prestat_t

std.os.wasi.fd_pwrite

函数

第 39 行

pub extern "wasi_snapshot_preview1" fn fd_pwrite(fd: fd_t, iovs: [*]const ciovec_t, iovs_len: usize, offset: filesize_t, nwritten: *usize) errno_t

参数

fd: fd_t
iovs: [*]const ciovec_t
iovs_len: usize
offset: filesize_t
nwritten: *usize

std.os.wasi.fd_read

函数

第 40 行

pub extern "wasi_snapshot_preview1" fn fd_read(fd: fd_t, iovs: [*]const iovec_t, iovs_len: usize, nread: *usize) errno_t

参数

fd: fd_t
iovs: [*]const iovec_t
iovs_len: usize
nread: *usize

std.os.wasi.fd_readdir

函数

第 41 行

pub extern "wasi_snapshot_preview1" fn fd_readdir(fd: fd_t, buf: [*]u8, buf_len: usize, cookie: dircookie_t, bufused: *usize) errno_t

参数

fd: fd_t
buf: [*]u8
buf_len: usize
cookie: dircookie_t
bufused: *usize

std.os.wasi.fd_renumber

函数

第 42 行

pub extern "wasi_snapshot_preview1" fn fd_renumber(from: fd_t, to: fd_t) errno_t

参数

from: fd_t
to: fd_t

std.os.wasi.fd_seek

函数

第 43 行

pub extern "wasi_snapshot_preview1" fn fd_seek(fd: fd_t, offset: filedelta_t, whence: whence_t, newoffset: *filesize_t) errno_t

参数

fd: fd_t
offset: filedelta_t
whence: whence_t
newoffset: *filesize_t

std.os.wasi.fd_sync

函数

第 44 行

pub extern "wasi_snapshot_preview1" fn fd_sync(fd: fd_t) errno_t

参数

fd: fd_t

std.os.wasi.fd_t

类型

第 221 行

std.os.wasi.fd_tell

函数

第 45 行

pub extern "wasi_snapshot_preview1" fn fd_tell(fd: fd_t, newoffset: *filesize_t) errno_t

参数

fd: fd_t
newoffset: *filesize_t

std.os.wasi.fd_write

函数

第 46 行

pub extern "wasi_snapshot_preview1" fn fd_write(fd: fd_t, iovs: [*]const ciovec_t, iovs_len: usize, nwritten: *usize) errno_t

参数

fd: fd_t
iovs: [*]const ciovec_t
iovs_len: usize
nwritten: *usize

std.os.wasi.fdflags_t

容器

第 223 行

字段

APPEND: bool = false
DSYNC: bool = false
NONBLOCK: bool = false
RSYNC: bool = false
SYNC: bool = false
_: u11 = 0

std.os.wasi.fdstat_t

容器

第 232 行

字段

fs_filetype: filetype_t
fs_flags: fdflags_t
fs_rights_base: rights_t
fs_rights_inheriting: rights_t

std.os.wasi.filedelta_t

类型

第 239 行

std.os.wasi.filesize_t

类型

第 241 行

std.os.wasi.filestat_t

容器

第 243 行

字段

dev: device_t
ino: inode_t
filetype: filetype_t
nlink: linkcount_t
size: filesize_t
atim: timestamp_t
mtim: timestamp_t
ctim: timestamp_t

std.os.wasi.filetype_t

容器

第 254 行

字段

UNKNOWN
BLOCK_DEVICE
CHARACTER_DEVICE
DIRECTORY
REGULAR_FILE
SOCKET_DGRAM
SOCKET_STREAM
SYMBOLIC_LINK
_

std.os.wasi.fstflags_t

容器

第 266 行

字段

ATIM: bool = false
ATIM_NOW: bool = false
MTIM: bool = false
MTIM_NOW: bool = false
_: u12 = 0

std.os.wasi.inode_t

类型

第 274 行

std.os.wasi.iovec_t

别名

第 22 行

别名目标 std.posix.iovec

std.os.wasi.linkcount_t

类型

第 276 行

std.os.wasi.lookupflags_t

容器

第 278 行

字段

SYMLINK_FOLLOW: bool = false
_: u31 = 0

std.os.wasi.oflags_t

容器

第 283 行

字段

CREAT: bool = false
DIRECTORY: bool = false
EXCL: bool = false
TRUNC: bool = false
_: u12 = 0

std.os.wasi.path_create_directory

函数

第 59 行

pub extern "wasi_snapshot_preview1" fn path_create_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t

参数

fd: fd_t
path: [*]const u8
path_len: usize

std.os.wasi.path_filestat_get

函数

第 60 行

pub extern "wasi_snapshot_preview1" fn path_filestat_get(fd: fd_t, flags: lookupflags_t, path: [*]const u8, path_len: usize, buf: *filestat_t) errno_t

参数

fd: fd_t
flags: lookupflags_t
path: [*]const u8
path_len: usize
buf: *filestat_t

std.os.wasi.path_filestat_set_times

函数

第 61 行

pub extern "wasi_snapshot_preview1" fn path_filestat_set_times(fd: fd_t, flags: lookupflags_t, path: [*]const u8, path_len: usize, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags_t) errno_t

参数

fd: fd_t
flags: lookupflags_t
path: [*]const u8
path_len: usize
st_atim: timestamp_t
st_mtim: timestamp_t
fstflags: fstflags_t

std.os.wasi.path_link

函数

第 62 行

pub extern "wasi_snapshot_preview1" fn path_link(old_fd: fd_t, old_flags: lookupflags_t, old_path: [*]const u8, old_path_len: usize, new_fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t

参数

old_fd: fd_t
old_flags: lookupflags_t
old_path: [*]const u8
old_path_len: usize
new_fd: fd_t
new_path: [*]const u8
new_path_len: usize

std.os.wasi.path_open

函数

第 63 行

pub extern "wasi_snapshot_preview1" fn path_open(dirfd: fd_t, dirflags: lookupflags_t, path: [*]const u8, path_len: usize, oflags: oflags_t, fs_rights_base: rights_t, fs_rights_inheriting: rights_t, fs_flags: fdflags_t, fd: *fd_t) errno_t

参数

dirfd: fd_t
dirflags: lookupflags_t
path: [*]const u8
path_len: usize
oflags: oflags_t
fs_rights_base: rights_t
fs_rights_inheriting: rights_t
fs_flags: fdflags_t
fd: *fd_t

std.os.wasi.path_readlink

函数

第 64 行

pub extern "wasi_snapshot_preview1" fn path_readlink(fd: fd_t, path: [*]const u8, path_len: usize, buf: [*]u8, buf_len: usize, bufused: *usize) errno_t

参数

fd: fd_t
path: [*]const u8
path_len: usize
buf: [*]u8
buf_len: usize
bufused: *usize

std.os.wasi.path_remove_directory

函数

第 65 行

pub extern "wasi_snapshot_preview1" fn path_remove_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t

参数

fd: fd_t
path: [*]const u8
path_len: usize

std.os.wasi.path_rename

函数

第 66 行

pub extern "wasi_snapshot_preview1" fn path_rename(old_fd: fd_t, old_path: [*]const u8, old_path_len: usize, new_fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t

参数

old_fd: fd_t
old_path: [*]const u8
old_path_len: usize
new_fd: fd_t
new_path: [*]const u8
new_path_len: usize

std.os.wasi.path_symlink

函数

第 67 行

pub extern "wasi_snapshot_preview1" fn path_symlink(old_path: [*]const u8, old_path_len: usize, fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t

参数

old_path: [*]const u8
old_path_len: usize
fd: fd_t
new_path: [*]const u8
new_path_len: usize

std.os.wasi.path_unlink_file

函数

第 68 行

pub extern "wasi_snapshot_preview1" fn path_unlink_file(fd: fd_t, path: [*]const u8, path_len: usize) errno_t

参数

fd: fd_t
path: [*]const u8
path_len: usize

std.os.wasi.poll_oneoff

函数

第 70 行

pub extern "wasi_snapshot_preview1" fn poll_oneoff(in: *const subscription_t, out: *event_t, nsubscriptions: usize, nevents: *usize) errno_t

参数

in: *const subscription_t
out: *event_t
nsubscriptions: usize
nevents: *usize

std.os.wasi.preopentype_t

容器

第 291 行

字段

DIR = 0

std.os.wasi.prestat_dir_t

容器

第 300 行

字段

pr_name_len: usize

std.os.wasi.prestat_t

容器

第 295 行

字段

std.os.wasi.prestat_u_t

容器

第 304 行

字段

std.os.wasi.proc_exit

函数

第 72 行

pub extern "wasi_snapshot_preview1" fn proc_exit(rval: exitcode_t) noreturn

参数

rval: exitcode_t

std.os.wasi.random_get

函数

第 74 行

pub extern "wasi_snapshot_preview1" fn random_get(buf: [*]u8, buf_len: usize) errno_t

参数

buf: [*]u8
buf_len: usize

std.os.wasi.riflags_t

类型

第 308 行

std.os.wasi.rights_t

容器

第 318 行

字段

FD_DATASYNC: bool = false

调用 fd_datasync 的权限。若设置了 PATH_OPEN,还包括使用 fdflags_t.dsync 调用 path_open 的权限。

FD_READ: bool = false

调用 fd_read 和 sock_recv 的权限。若设置了 FD_SEEK,还包括调用 fd_pread 的权限。

FD_SEEK: bool = false

调用 fd_seek 的权限。此标志隐含 FD_TELL 权限。

FD_FDSTAT_SET_FLAGS: bool = false

调用 fd_fdstat_set_flags 的权限。

FD_SYNC: bool = false

调用 fd_sync 的权限。若设置了 PATH_OPEN,还包括使用 fdflags_t.RSYNC 和 fdflags_t.DSYNC 调用 path_open 的权限。

FD_TELL: bool = false

以不改变文件偏移的方式调用 fd_seek(即 whence_t.CUR 且偏移为零),或调用 fd_tell 的权限。

FD_WRITE: bool = false

调用 fd_write 和 sock_send 的权限。若设置了 FD_SEEK,还包括调用 fd_pwrite 的权限。

FD_ADVISE: bool = false

调用 fd_advise 的权限。

FD_ALLOCATE: bool = false

调用 fd_allocate 的权限。

PATH_CREATE_DIRECTORY: bool = false

调用 path_create_directory 的权限。

PATH_CREATE_FILE: bool = false

若设置 PATH_OPEN,则拥有使用 oflags_t.CREAT 调用 path_open 的权限。

PATH_LINK_SOURCE: bool = false

以该文件描述符作为源目录调用 path_link 的权限。

PATH_LINK_TARGET: bool = false

以该文件描述符作为目标目录调用 path_link 的权限。

PATH_OPEN: bool = false

调用 path_open 的权限。

FD_READDIR: bool = false

调用 fd_readdir 的权限。

PATH_READLINK: bool = false

调用 path_readlink 的权限。

PATH_RENAME_SOURCE: bool = false

以该文件描述符作为源目录调用 path_rename 的权限。

PATH_RENAME_TARGET: bool = false

以该文件描述符作为目标目录调用 path_rename 的权限。

PATH_FILESTAT_GET: bool = false

调用 path_filestat_get 的权限。

PATH_FILESTAT_SET_SIZE: bool = false

更改文件大小的权限。若设置 PATH_OPEN,则包括 以 oflags_t.TRUNC 调用 path_open 的权限。注意:不存在名为 path_filestat_set_size 的函数。 这遵循 POSIX 仅提供 ftruncate 而不提供 ftruncateat 的设计。 从 API 设计角度看,这样的函数可能有价值,但实际上几乎没有 使用场景,因为为 POSIX 系统编写的代码都不会使用它。此外, 实现该函数需要多次系统调用,性能会更差。

PATH_FILESTAT_SET_TIMES: bool = false

调用 path_filestat_set_times 的权限。

FD_FILESTAT_GET: bool = false

调用 fd_filestat_get 的权限。

FD_FILESTAT_SET_SIZE: bool = false

调用 fd_filestat_set_size 的权限。

FD_FILESTAT_SET_TIMES: bool = false

调用 fd_filestat_set_times 的权限。

PATH_SYMLINK: bool = false

调用 path_symlink 的权限。

PATH_REMOVE_DIRECTORY: bool = false

调用 path_remove_directory 的权限。

PATH_UNLINK_FILE: bool = false

调用 path_unlink_file 的权限。

POLL_FD_READWRITE: bool = false

若设置 FD_READ,则包含调用 poll_oneoff 订阅 eventtype_t.FD_READ 的权限。若设置 FD_WRITE,则包含调用 poll_oneoff 订阅 eventtype_t.FD_WRITE 的权限。

SOCK_SHUTDOWN: bool = false

调用 sock_shutdown 的权限。

SOCK_ACCEPT: bool = false

调用 sock_accept 的权限。

_: u34 = 0

std.os.wasi.roflags_t

类型

第 309 行

std.os.wasi.sched_yield

函数

第 76 行

pub extern "wasi_snapshot_preview1" fn sched_yield() errno_t

std.os.wasi.sdflags_t

容器

第 394 行

字段

RD: bool = false
WR: bool = false
_: u6 = 0

std.os.wasi.siflags_t

类型

第 400 行

std.os.wasi.signal_t

容器

第 402 行

字段

NONE = 0
HUP = 1
INT = 2
QUIT = 3
ILL = 4
TRAP = 5
ABRT = 6
BUS = 7
FPE = 8
KILL = 9
USR1 = 10
SEGV = 11
USR2 = 12
PIPE = 13
ALRM = 14
TERM = 15
CHLD = 16
CONT = 17
STOP = 18
TSTP = 19
TTIN = 20
TTOU = 21
URG = 22
XCPU = 23
XFSZ = 24
VTALRM = 25
PROF = 26
WINCH = 27
POLL = 28
PWR = 29
SYS = 30

std.os.wasi.SOCK

命名空间

第 311 行

std.os.wasi.sock_accept

函数

第 78 行

pub extern "wasi_snapshot_preview1" fn sock_accept(sock: fd_t, flags: fdflags_t, result_fd: *fd_t) errno_t

参数

sock: fd_t
flags: fdflags_t
result_fd: *fd_t

std.os.wasi.sock_recv

函数

第 79 行

pub extern "wasi_snapshot_preview1" fn sock_recv(sock: fd_t, ri_data: [*]iovec_t, ri_data_len: usize, ri_flags: riflags_t, ro_datalen: *usize, ro_flags: *roflags_t) errno_t

参数

sock: fd_t
ri_data: [*]iovec_t
ri_data_len: usize
ri_flags: riflags_t
ro_datalen: *usize
ro_flags: *roflags_t

std.os.wasi.sock_send

函数

第 80 行

pub extern "wasi_snapshot_preview1" fn sock_send(sock: fd_t, si_data: [*]const ciovec_t, si_data_len: usize, si_flags: siflags_t, so_datalen: *usize) errno_t

参数

sock: fd_t
si_data: [*]const ciovec_t
si_data_len: usize
si_flags: siflags_t
so_datalen: *usize

std.os.wasi.sock_shutdown

函数

第 81 行

pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t

参数

sock: fd_t
how: sdflags_t

std.os.wasi.SOCK.RECV_DATA_TRUNCATED

常量

第 315 行

roflags_t

std.os.wasi.SOCK.RECV_PEEK

常量

第 312 行

riflags_t

std.os.wasi.SOCK.RECV_WAITALL

常量

第 313 行

riflags_t

std.os.wasi.std

别名

第 6 行

别名目标 std

std.os.wasi.subclockflags_t

类型

第 436 行

std.os.wasi.SUBSCRIPTION_CLOCK_ABSTIME

常量

第 437 行

subclockflags_t

std.os.wasi.subscription_clock_t

容器

第 444 行

字段

id: clockid_t
timeout: timestamp_t
precision: timestamp_t
flags: subclockflags_t

std.os.wasi.subscription_fd_readwrite_t

容器

第 451 行

字段

fd: fd_t

std.os.wasi.subscription_t

容器

第 439 行

字段

std.os.wasi.subscription_u_t

容器

第 455 行

字段

std.os.wasi.subscription_u_u_t

容器

第 460 行

字段

std.os.wasi.timestamp_t

类型

第 467 行

纳秒。

std.os.wasi.userdata_t

类型

第 469 行

std.os.wasi.whence_t

容器

第 471 行

字段

SET
CUR
END
源码

std/os/wasi.zig

//! wasi_snapshot_preview1 规范以 witx 格式提供于:
//! * 类型名:https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/typenames.witx
//! * 模块:https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/wasi_snapshot_preview1.witx
//! 注意,libc API *不*放在此文件;WASI libc API 放入 std/c.zig。
const builtin = @import("builtin");
const std = @import("std");
const assert = std.debug.assert;

comptime {
    if (builtin.os.tag == .wasi) {
        assert(@alignOf(i8) == 1);
        assert(@alignOf(u8) == 1);
        assert(@alignOf(i16) == 2);
        assert(@alignOf(u16) == 2);
        assert(@alignOf(i32) == 4);
        assert(@alignOf(u32) == 4);
        assert(@alignOf(i64) == 8);
        assert(@alignOf(u64) == 8);
    }
}

pub const iovec_t = std.posix.iovec;
pub const ciovec_t = std.posix.iovec_const;

pub extern "wasi_snapshot_preview1" fn args_get(argv: [*][*:0]u8, argv_buf: [*]u8) errno_t;
pub extern "wasi_snapshot_preview1" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t;

pub extern "wasi_snapshot_preview1" fn clock_res_get(clock_id: clockid_t, resolution: *timestamp_t) errno_t;
pub extern "wasi_snapshot_preview1" fn clock_time_get(clock_id: clockid_t, precision: timestamp_t, timestamp: *timestamp_t) errno_t;

pub extern "wasi_snapshot_preview1" fn environ_get(environ: [*][*:0]u8, environ_buf: [*]u8) errno_t;
pub extern "wasi_snapshot_preview1" fn environ_sizes_get(environ_count: *usize, environ_buf_size: *usize) errno_t;

pub extern "wasi_snapshot_preview1" fn fd_advise(fd: fd_t, offset: filesize_t, len: filesize_t, advice: advice_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_allocate(fd: fd_t, offset: filesize_t, len: filesize_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_close(fd: fd_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_datasync(fd: fd_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_pread(fd: fd_t, iovs: [*]const iovec_t, iovs_len: usize, offset: filesize_t, nread: *usize) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_pwrite(fd: fd_t, iovs: [*]const ciovec_t, iovs_len: usize, offset: filesize_t, nwritten: *usize) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_read(fd: fd_t, iovs: [*]const iovec_t, iovs_len: usize, nread: *usize) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_readdir(fd: fd_t, buf: [*]u8, buf_len: usize, cookie: dircookie_t, bufused: *usize) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_renumber(from: fd_t, to: fd_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_seek(fd: fd_t, offset: filedelta_t, whence: whence_t, newoffset: *filesize_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_sync(fd: fd_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_tell(fd: fd_t, newoffset: *filesize_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_write(fd: fd_t, iovs: [*]const ciovec_t, iovs_len: usize, nwritten: *usize) errno_t;

pub extern "wasi_snapshot_preview1" fn fd_fdstat_get(fd: fd_t, buf: *fdstat_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_fdstat_set_flags(fd: fd_t, flags: fdflags_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_fdstat_set_rights(fd: fd_t, fs_rights_base: rights_t, fs_rights_inheriting: rights_t) errno_t;

pub extern "wasi_snapshot_preview1" fn fd_filestat_get(fd: fd_t, buf: *filestat_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_filestat_set_size(fd: fd_t, st_size: filesize_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_filestat_set_times(fd: fd_t, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags_t) errno_t;

pub extern "wasi_snapshot_preview1" fn fd_prestat_get(fd: fd_t, buf: *prestat_t) errno_t;
pub extern "wasi_snapshot_preview1" fn fd_prestat_dir_name(fd: fd_t, path: [*]u8, path_len: usize) errno_t;

pub extern "wasi_snapshot_preview1" fn path_create_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t;
pub extern "wasi_snapshot_preview1" fn path_filestat_get(fd: fd_t, flags: lookupflags_t, path: [*]const u8, path_len: usize, buf: *filestat_t) errno_t;
pub extern "wasi_snapshot_preview1" fn path_filestat_set_times(fd: fd_t, flags: lookupflags_t, path: [*]const u8, path_len: usize, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags_t) errno_t;
pub extern "wasi_snapshot_preview1" fn path_link(old_fd: fd_t, old_flags: lookupflags_t, old_path: [*]const u8, old_path_len: usize, new_fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t;
pub extern "wasi_snapshot_preview1" fn path_open(dirfd: fd_t, dirflags: lookupflags_t, path: [*]const u8, path_len: usize, oflags: oflags_t, fs_rights_base: rights_t, fs_rights_inheriting: rights_t, fs_flags: fdflags_t, fd: *fd_t) errno_t;
pub extern "wasi_snapshot_preview1" fn path_readlink(fd: fd_t, path: [*]const u8, path_len: usize, buf: [*]u8, buf_len: usize, bufused: *usize) errno_t;
pub extern "wasi_snapshot_preview1" fn path_remove_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t;
pub extern "wasi_snapshot_preview1" fn path_rename(old_fd: fd_t, old_path: [*]const u8, old_path_len: usize, new_fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t;
pub extern "wasi_snapshot_preview1" fn path_symlink(old_path: [*]const u8, old_path_len: usize, fd: fd_t, new_path: [*]const u8, new_path_len: usize) errno_t;
pub extern "wasi_snapshot_preview1" fn path_unlink_file(fd: fd_t, path: [*]const u8, path_len: usize) errno_t;

pub extern "wasi_snapshot_preview1" fn poll_oneoff(in: *const subscription_t, out: *event_t, nsubscriptions: usize, nevents: *usize) errno_t;

pub extern "wasi_snapshot_preview1" fn proc_exit(rval: exitcode_t) noreturn;

pub extern "wasi_snapshot_preview1" fn random_get(buf: [*]u8, buf_len: usize) errno_t;

pub extern "wasi_snapshot_preview1" fn sched_yield() errno_t;

pub extern "wasi_snapshot_preview1" fn sock_accept(sock: fd_t, flags: fdflags_t, result_fd: *fd_t) errno_t;
pub extern "wasi_snapshot_preview1" fn sock_recv(sock: fd_t, ri_data: [*]iovec_t, ri_data_len: usize, ri_flags: riflags_t, ro_datalen: *usize, ro_flags: *roflags_t) errno_t;
pub extern "wasi_snapshot_preview1" fn sock_send(sock: fd_t, si_data: [*]const ciovec_t, si_data_len: usize, si_flags: siflags_t, so_datalen: *usize) errno_t;
pub extern "wasi_snapshot_preview1" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t;

// 定义于 wasi_snapshot_preview1 规范文件:
// https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/typenames.witx
pub const advice_t = enum(u8) {
    NORMAL = 0,
    SEQUENTIAL = 1,
    RANDOM = 2,
    WILLNEED = 3,
    DONTNEED = 4,
    NOREUSE = 5,
};

pub const clockid_t = enum(u32) {
    REALTIME = 0,
    MONOTONIC = 1,
    PROCESS_CPUTIME_ID = 2,
    THREAD_CPUTIME_ID = 3,
};

pub const device_t = u64;

pub const dircookie_t = u64;
pub const DIRCOOKIE_START: dircookie_t = 0;

pub const dirnamlen_t = u32;

pub const dirent_t = extern struct {
    next: dircookie_t,
    ino: inode_t,
    namlen: dirnamlen_t,
    type: filetype_t,
};

pub const errno_t = enum(u16) {
    SUCCESS = 0,
    @"2BIG" = 1,
    ACCES = 2,
    ADDRINUSE = 3,
    ADDRNOTAVAIL = 4,
    AFNOSUPPORT = 5,
    /// 此错误码也用于 `WOULDBLOCK`。
    AGAIN = 6,
    ALREADY = 7,
    BADF = 8,
    BADMSG = 9,
    BUSY = 10,
    CANCELED = 11,
    CHILD = 12,
    CONNABORTED = 13,
    CONNREFUSED = 14,
    CONNRESET = 15,
    DEADLK = 16,
    DESTADDRREQ = 17,
    DOM = 18,
    DQUOT = 19,
    EXIST = 20,
    FAULT = 21,
    FBIG = 22,
    HOSTUNREACH = 23,
    IDRM = 24,
    ILSEQ = 25,
    INPROGRESS = 26,
    INTR = 27,
    INVAL = 28,
    IO = 29,
    ISCONN = 30,
    ISDIR = 31,
    LOOP = 32,
    MFILE = 33,
    MLINK = 34,
    MSGSIZE = 35,
    MULTIHOP = 36,
    NAMETOOLONG = 37,
    NETDOWN = 38,
    NETRESET = 39,
    NETUNREACH = 40,
    NFILE = 41,
    NOBUFS = 42,
    NODEV = 43,
    NOENT = 44,
    NOEXEC = 45,
    NOLCK = 46,
    NOLINK = 47,
    NOMEM = 48,
    NOMSG = 49,
    NOPROTOOPT = 50,
    NOSPC = 51,
    NOSYS = 52,
    NOTCONN = 53,
    NOTDIR = 54,
    NOTEMPTY = 55,
    NOTRECOVERABLE = 56,
    NOTSOCK = 57,
    /// 这也是用于 `NOTSUP` 的代码。
    OPNOTSUPP = 58,
    NOTTY = 59,
    NXIO = 60,
    OVERFLOW = 61,
    OWNERDEAD = 62,
    PERM = 63,
    PIPE = 64,
    PROTO = 65,
    PROTONOSUPPORT = 66,
    PROTOTYPE = 67,
    RANGE = 68,
    ROFS = 69,
    SPIPE = 70,
    SRCH = 71,
    STALE = 72,
    TIMEDOUT = 73,
    TXTBSY = 74,
    XDEV = 75,
    NOTCAPABLE = 76,
    _,
};

pub const event_t = extern struct {
    userdata: userdata_t,
    @"error": errno_t,
    type: eventtype_t,
    fd_readwrite: eventfdreadwrite_t,
};

pub const eventfdreadwrite_t = extern struct {
    nbytes: filesize_t,
    flags: eventrwflags_t,
};

pub const eventrwflags_t = u16;
pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;

pub const eventtype_t = enum(u8) {
    CLOCK = 0,
    FD_READ = 1,
    FD_WRITE = 2,
};

pub const exitcode_t = u32;

pub const fd_t = i32;

pub const fdflags_t = packed struct(u16) {
    APPEND: bool = false,
    DSYNC: bool = false,
    NONBLOCK: bool = false,
    RSYNC: bool = false,
    SYNC: bool = false,
    _: u11 = 0,
};

pub const fdstat_t = extern struct {
    fs_filetype: filetype_t,
    fs_flags: fdflags_t,
    fs_rights_base: rights_t,
    fs_rights_inheriting: rights_t,
};

pub const filedelta_t = i64;

pub const filesize_t = u64;

pub const filestat_t = extern struct {
    dev: device_t,
    ino: inode_t,
    filetype: filetype_t,
    nlink: linkcount_t,
    size: filesize_t,
    atim: timestamp_t,
    mtim: timestamp_t,
    ctim: timestamp_t,
};

pub const filetype_t = enum(u8) {
    UNKNOWN,
    BLOCK_DEVICE,
    CHARACTER_DEVICE,
    DIRECTORY,
    REGULAR_FILE,
    SOCKET_DGRAM,
    SOCKET_STREAM,
    SYMBOLIC_LINK,
    _,
};

pub const fstflags_t = packed struct(u16) {
    ATIM: bool = false,
    ATIM_NOW: bool = false,
    MTIM: bool = false,
    MTIM_NOW: bool = false,
    _: u12 = 0,
};

pub const inode_t = u64;

pub const linkcount_t = u64;

pub const lookupflags_t = packed struct(u32) {
    SYMLINK_FOLLOW: bool = false,
    _: u31 = 0,
};

pub const oflags_t = packed struct(u16) {
    CREAT: bool = false,
    DIRECTORY: bool = false,
    EXCL: bool = false,
    TRUNC: bool = false,
    _: u12 = 0,
};

pub const preopentype_t = enum(u8) {
    DIR = 0,
};

pub const prestat_t = extern struct {
    pr_type: preopentype_t,
    u: prestat_u_t,
};

pub const prestat_dir_t = extern struct {
    pr_name_len: usize,
};

pub const prestat_u_t = extern union {
    dir: prestat_dir_t,
};

pub const riflags_t = u16;
pub const roflags_t = u16;

pub const SOCK = struct {
    pub const RECV_PEEK: riflags_t = 0x0001;
    pub const RECV_WAITALL: riflags_t = 0x0002;

    pub const RECV_DATA_TRUNCATED: roflags_t = 0x0001;
};

pub const rights_t = packed struct(u64) {
    /// 调用 fd_datasync 的权限。若设置了 PATH_OPEN,还包括使用
    /// fdflags_t.dsync 调用 path_open 的权限。
    FD_DATASYNC: bool = false,
    /// 调用 fd_read 和 sock_recv 的权限。若设置了 FD_SEEK,还包括调用
    /// fd_pread 的权限。
    FD_READ: bool = false,
    /// 调用 fd_seek 的权限。此标志隐含 FD_TELL 权限。
    FD_SEEK: bool = false,
    /// 调用 fd_fdstat_set_flags 的权限。
    FD_FDSTAT_SET_FLAGS: bool = false,
    /// 调用 fd_sync 的权限。若设置了 PATH_OPEN,还包括使用
    /// fdflags_t.RSYNC 和 fdflags_t.DSYNC 调用 path_open 的权限。
    FD_SYNC: bool = false,
    /// 以不改变文件偏移的方式调用 fd_seek(即 whence_t.CUR
    /// 且偏移为零),或调用 fd_tell 的权限。
    FD_TELL: bool = false,
    /// 调用 fd_write 和 sock_send 的权限。若设置了 FD_SEEK,还包括调用
    /// fd_pwrite 的权限。
    FD_WRITE: bool = false,
    /// 调用 fd_advise 的权限。
    FD_ADVISE: bool = false,
    /// 调用 fd_allocate 的权限。
    FD_ALLOCATE: bool = false,
    /// 调用 path_create_directory 的权限。
    PATH_CREATE_DIRECTORY: bool = false,
    /// 若设置 PATH_OPEN,则拥有使用 oflags_t.CREAT 调用 path_open 的权限。
    PATH_CREATE_FILE: bool = false,
    /// 以该文件描述符作为源目录调用 path_link 的权限。
    PATH_LINK_SOURCE: bool = false,
    /// 以该文件描述符作为目标目录调用 path_link 的权限。
    PATH_LINK_TARGET: bool = false,
    /// 调用 path_open 的权限。
    PATH_OPEN: bool = false,
    /// 调用 fd_readdir 的权限。
    FD_READDIR: bool = false,
    /// 调用 path_readlink 的权限。
    PATH_READLINK: bool = false,
    /// 以该文件描述符作为源目录调用 path_rename 的权限。
    PATH_RENAME_SOURCE: bool = false,
    /// 以该文件描述符作为目标目录调用 path_rename 的权限。
    PATH_RENAME_TARGET: bool = false,
    /// 调用 path_filestat_get 的权限。
    PATH_FILESTAT_GET: bool = false,
    /// 更改文件大小的权限。若设置 PATH_OPEN,则包括
    /// 以 oflags_t.TRUNC 调用 path_open 的权限。注意:不存在名为 path_filestat_set_size 的函数。
    /// 这遵循 POSIX 仅提供 ftruncate 而不提供 ftruncateat 的设计。
    /// 从 API 设计角度看,这样的函数可能有价值,但实际上几乎没有
    /// 使用场景,因为为 POSIX 系统编写的代码都不会使用它。此外,
    /// 实现该函数需要多次系统调用,性能会更差。
    PATH_FILESTAT_SET_SIZE: bool = false,
    /// 调用 path_filestat_set_times 的权限。
    PATH_FILESTAT_SET_TIMES: bool = false,
    /// 调用 fd_filestat_get 的权限。
    FD_FILESTAT_GET: bool = false,
    /// 调用 fd_filestat_set_size 的权限。
    FD_FILESTAT_SET_SIZE: bool = false,
    /// 调用 fd_filestat_set_times 的权限。
    FD_FILESTAT_SET_TIMES: bool = false,
    /// 调用 path_symlink 的权限。
    PATH_SYMLINK: bool = false,
    /// 调用 path_remove_directory 的权限。
    PATH_REMOVE_DIRECTORY: bool = false,
    /// 调用 path_unlink_file 的权限。
    PATH_UNLINK_FILE: bool = false,
    /// 若设置 FD_READ,则包含调用 poll_oneoff 订阅
    /// eventtype_t.FD_READ 的权限。若设置 FD_WRITE,则包含调用 poll_oneoff
    /// 订阅 eventtype_t.FD_WRITE 的权限。
    POLL_FD_READWRITE: bool = false,
    /// 调用 sock_shutdown 的权限。
    SOCK_SHUTDOWN: bool = false,
    /// 调用 sock_accept 的权限。
    SOCK_ACCEPT: bool = false,
    _: u34 = 0,
};

pub const sdflags_t = packed struct(u8) {
    RD: bool = false,
    WR: bool = false,
    _: u6 = 0,
};

pub const siflags_t = u16;

pub const signal_t = enum(u8) {
    NONE = 0,
    HUP = 1,
    INT = 2,
    QUIT = 3,
    ILL = 4,
    TRAP = 5,
    ABRT = 6,
    BUS = 7,
    FPE = 8,
    KILL = 9,
    USR1 = 10,
    SEGV = 11,
    USR2 = 12,
    PIPE = 13,
    ALRM = 14,
    TERM = 15,
    CHLD = 16,
    CONT = 17,
    STOP = 18,
    TSTP = 19,
    TTIN = 20,
    TTOU = 21,
    URG = 22,
    XCPU = 23,
    XFSZ = 24,
    VTALRM = 25,
    PROF = 26,
    WINCH = 27,
    POLL = 28,
    PWR = 29,
    SYS = 30,
};

pub const subclockflags_t = u16;
pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;

pub const subscription_t = extern struct {
    userdata: userdata_t,
    u: subscription_u_t,
};

pub const subscription_clock_t = extern struct {
    id: clockid_t,
    timeout: timestamp_t,
    precision: timestamp_t,
    flags: subclockflags_t,
};

pub const subscription_fd_readwrite_t = extern struct {
    fd: fd_t,
};

pub const subscription_u_t = extern struct {
    tag: eventtype_t,
    u: subscription_u_u_t,
};

pub const subscription_u_u_t = extern union {
    clock: subscription_clock_t,
    fd_read: subscription_fd_readwrite_t,
    fd_write: subscription_fd_readwrite_t,
};

/// 纳秒。
pub const timestamp_t = u64;

pub const userdata_t = u64;

pub const whence_t = enum(u8) { SET, CUR, END };