Skip to content

Instantly share code, notes, and snippets.

@jedisct1
Last active November 10, 2020 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedisct1/d16e47a02245ab981ba16a8cfd42dad0 to your computer and use it in GitHub Desktop.
Save jedisct1/d16e47a02245ab981ba16a8cfd42dad0 to your computer and use it in GitHub Desktop.
// This file was automatically generated by zig-witx - Do not edit manually.
pub const handle = i32;
pub const char = u8;
pub const untyped_ptr = usize;
pub const wasi_string_ptr = *u8;
// size
pub const size = u32;
// Non-negative file size or length of a region within a file.
pub const filesize = u64;
// Timestamp in nanoseconds.
pub const timestamp = u64;
// Identifiers for clocks.
pub const clockid = enum(u32) {
// The clock measuring real time. Time value zero corresponds with
// 1970-01-01T00:00:00Z.
REALTIME = 0,
// The store-wide monotonic clock, which is defined as a clock measuring
// real time, whose value cannot be adjusted and which cannot have negative
// clock jumps. The epoch of this clock is undefined. The absolute time
// value of this clock therefore has no meaning.
MONOTONIC = 1,
// The CPU-time clock associated with the current process.
PROCESS_CPUTIME_ID = 2,
// The CPU-time clock associated with the current thread.
THREAD_CPUTIME_ID = 3,
};
// Error codes returned by functions.
// Not all of these error codes are returned by the functions provided by this
// API; some are used in higher-level library layers, and others are provided
// merely for alignment with POSIX.
pub const errno = enum(u16) {
// No error occurred. System call completed successfully.
SUCCESS = 0,
// Argument list too long.
_2BIG = 1,
// Permission denied.
ACCES = 2,
// Address in use.
ADDRINUSE = 3,
// Address not available.
ADDRNOTAVAIL = 4,
// Address family not supported.
AFNOSUPPORT = 5,
// Resource unavailable, or operation would block.
AGAIN = 6,
// Connection already in progress.
ALREADY = 7,
// Bad file descriptor.
BADF = 8,
// Bad message.
BADMSG = 9,
// Device or resource busy.
BUSY = 10,
// Operation canceled.
CANCELED = 11,
// No child processes.
CHILD = 12,
// Connection aborted.
CONNABORTED = 13,
// Connection refused.
CONNREFUSED = 14,
// Connection reset.
CONNRESET = 15,
// Resource deadlock would occur.
DEADLK = 16,
// Destination address required.
DESTADDRREQ = 17,
// Mathematics argument out of domain of function.
DOM = 18,
// Reserved.
DQUOT = 19,
// File exists.
EXIST = 20,
// Bad address.
FAULT = 21,
// File too large.
FBIG = 22,
// Host is unreachable.
HOSTUNREACH = 23,
// Identifier removed.
IDRM = 24,
// Illegal byte sequence.
ILSEQ = 25,
// Operation in progress.
INPROGRESS = 26,
// Interrupted function.
INTR = 27,
// Invalid argument.
INVAL = 28,
// I/O error.
IO = 29,
// Socket is connected.
ISCONN = 30,
// Is a directory.
ISDIR = 31,
// Too many levels of symbolic links.
LOOP = 32,
// File descriptor value too large.
MFILE = 33,
// Too many links.
MLINK = 34,
// Message too large.
MSGSIZE = 35,
// Reserved.
MULTIHOP = 36,
// Filename too long.
NAMETOOLONG = 37,
// Network is down.
NETDOWN = 38,
// Connection aborted by network.
NETRESET = 39,
// Network unreachable.
NETUNREACH = 40,
// Too many files open in system.
NFILE = 41,
// No buffer space available.
NOBUFS = 42,
// No such device.
NODEV = 43,
// No such file or directory.
NOENT = 44,
// Executable file format error.
NOEXEC = 45,
// No locks available.
NOLCK = 46,
// Reserved.
NOLINK = 47,
// Not enough space.
NOMEM = 48,
// No message of the desired type.
NOMSG = 49,
// Protocol not available.
NOPROTOOPT = 50,
// No space left on device.
NOSPC = 51,
// Function not supported.
NOSYS = 52,
// The socket is not connected.
NOTCONN = 53,
// Not a directory or a symbolic link to a directory.
NOTDIR = 54,
// Directory not empty.
NOTEMPTY = 55,
// State not recoverable.
NOTRECOVERABLE = 56,
// Not a socket.
NOTSOCK = 57,
// Not supported, or operation not supported on socket.
NOTSUP = 58,
// Inappropriate I/O control operation.
NOTTY = 59,
// No such device or address.
NXIO = 60,
// Value too large to be stored in data type.
OVERFLOW = 61,
// Previous owner died.
OWNERDEAD = 62,
// Operation not permitted.
PERM = 63,
// Broken pipe.
PIPE = 64,
// Protocol error.
PROTO = 65,
// Protocol not supported.
PROTONOSUPPORT = 66,
// Protocol wrong type for socket.
PROTOTYPE = 67,
// Result too large.
RANGE = 68,
// Read-only file system.
ROFS = 69,
// Invalid seek.
SPIPE = 70,
// No such process.
SRCH = 71,
// Reserved.
STALE = 72,
// Connection timed out.
TIMEDOUT = 73,
// Text file busy.
TXTBSY = 74,
// Cross-device link.
XDEV = 75,
// Extension: Capabilities insufficient.
NOTCAPABLE = 76,
};
// File descriptor rights, determining which actions may be performed.
pub const rights = u64;
pub const rights_bits = struct {
// The right to invoke `fd_datasync`.
// If `path_open` is set, includes the right to invoke
// `path_open` with `fdflags::dsync`.
pub const FD_DATASYNC: rights = 1;
// The right to invoke `fd_read` and `sock_recv`.
// If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
pub const FD_READ: rights = 2;
// The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
pub const FD_SEEK: rights = 4;
// The right to invoke `fd_fdstat_set_flags`.
pub const FD_FDSTAT_SET_FLAGS: rights = 8;
// The right to invoke `fd_sync`.
// If `path_open` is set, includes the right to invoke
// `path_open` with `fdflags::rsync` and `fdflags::dsync`.
pub const FD_SYNC: rights = 16;
// The right to invoke `fd_seek` in such a way that the file offset
// remains unaltered (i.e., `whence::cur` with offset zero), or to
// invoke `fd_tell`.
pub const FD_TELL: rights = 32;
// The right to invoke `fd_write` and `sock_send`.
// If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
pub const FD_WRITE: rights = 64;
// The right to invoke `fd_advise`.
pub const FD_ADVISE: rights = 128;
// The right to invoke `fd_allocate`.
pub const FD_ALLOCATE: rights = 256;
// The right to invoke `path_create_directory`.
pub const PATH_CREATE_DIRECTORY: rights = 512;
// If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
pub const PATH_CREATE_FILE: rights = 1024;
// The right to invoke `path_link` with the file descriptor as the
// source directory.
pub const PATH_LINK_SOURCE: rights = 2048;
// The right to invoke `path_link` with the file descriptor as the
// target directory.
pub const PATH_LINK_TARGET: rights = 4096;
// The right to invoke `path_open`.
pub const PATH_OPEN: rights = 8192;
// The right to invoke `fd_readdir`.
pub const FD_READDIR: rights = 16384;
// The right to invoke `path_readlink`.
pub const PATH_READLINK: rights = 32768;
// The right to invoke `path_rename` with the file descriptor as the source directory.
pub const PATH_RENAME_SOURCE: rights = 65536;
// The right to invoke `path_rename` with the file descriptor as the target directory.
pub const PATH_RENAME_TARGET: rights = 131072;
// The right to invoke `path_filestat_get`.
pub const PATH_FILESTAT_GET: rights = 262144;
// The right to change a file's size (there is no `path_filestat_set_size`).
// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`.
pub const PATH_FILESTAT_SET_SIZE: rights = 524288;
// The right to invoke `path_filestat_set_times`.
pub const PATH_FILESTAT_SET_TIMES: rights = 1048576;
// The right to invoke `fd_filestat_get`.
pub const FD_FILESTAT_GET: rights = 2097152;
// The right to invoke `fd_filestat_set_size`.
pub const FD_FILESTAT_SET_SIZE: rights = 4194304;
// The right to invoke `fd_filestat_set_times`.
pub const FD_FILESTAT_SET_TIMES: rights = 8388608;
// The right to invoke `path_symlink`.
pub const PATH_SYMLINK: rights = 16777216;
// The right to invoke `path_remove_directory`.
pub const PATH_REMOVE_DIRECTORY: rights = 33554432;
// The right to invoke `path_unlink_file`.
pub const PATH_UNLINK_FILE: rights = 67108864;
// If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`.
// If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`.
pub const POLL_FD_READWRITE: rights = 134217728;
// The right to invoke `sock_shutdown`.
pub const SOCK_SHUTDOWN: rights = 268435456;
};
// A file descriptor handle.
pub const fd = handle;
// A region of memory for scatter/gather reads.
pub const iovec = struct {
// The address of the buffer to be filled.
buf: *u8,
// The length of the buffer to be filled.
buf_len: u32,
};
// A region of memory for scatter/gather writes.
pub const ciovec = struct {
// The address of the buffer to be written.
buf: *const u8,
// The length of the buffer to be written.
buf_len: u32,
};
// iovec_array
pub const iovec_array = *iovec;
// ciovec_array
pub const ciovec_array = *ciovec;
// Relative offset within a file.
pub const filedelta = i64;
// The position relative to which to set the offset of the file descriptor.
pub const whence = enum(u8) {
// Seek relative to start-of-file.
SET = 0,
// Seek relative to current position.
CUR = 1,
// Seek relative to end-of-file.
END = 2,
};
// A reference to the offset of a directory entry.
//
// The value 0 signifies the start of the directory.
pub const dircookie = u64;
// The type for the `dirent::d_namlen` field of `dirent` struct.
pub const dirnamlen = u32;
// File serial number that is unique within its file system.
pub const inode = u64;
// The type of a file descriptor or file.
pub const filetype = enum(u8) {
// The type of the file descriptor or file is unknown or is different from any of the other types specified.
UNKNOWN = 0,
// The file descriptor or file refers to a block device inode.
BLOCK_DEVICE = 1,
// The file descriptor or file refers to a character device inode.
CHARACTER_DEVICE = 2,
// The file descriptor or file refers to a directory inode.
DIRECTORY = 3,
// The file descriptor or file refers to a regular file inode.
REGULAR_FILE = 4,
// The file descriptor or file refers to a datagram socket.
SOCKET_DGRAM = 5,
// The file descriptor or file refers to a byte-stream socket.
SOCKET_STREAM = 6,
// The file refers to a symbolic link inode.
SYMBOLIC_LINK = 7,
};
// A directory entry.
pub const dirent = struct {
// The offset of the next directory entry stored in this directory.
d_next: u64,
// The serial number of the file referred to by this directory entry.
d_ino: u64,
// The length of the name of the directory entry.
d_namlen: u32,
// The type of the file referred to by this directory entry.
d_type: filetype,
};
// File or memory access pattern advisory information.
pub const advice = enum(u8) {
// The application has no advice to give on its behavior with respect to the specified data.
NORMAL = 0,
// The application expects to access the specified data sequentially from lower offsets to higher offsets.
SEQUENTIAL = 1,
// The application expects to access the specified data in a random order.
RANDOM = 2,
// The application expects to access the specified data in the near future.
WILLNEED = 3,
// The application expects that it will not access the specified data in the near future.
DONTNEED = 4,
// The application expects to access the specified data once and then not reuse it thereafter.
NOREUSE = 5,
};
// File descriptor flags.
pub const fdflags = u16;
pub const fdflags_bits = struct {
// Append mode: Data written to the file is always appended to the file's end.
pub const APPEND: fdflags = 1;
// Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
pub const DSYNC: fdflags = 2;
// Non-blocking mode.
pub const NONBLOCK: fdflags = 4;
// Synchronized read I/O operations.
pub const RSYNC: fdflags = 8;
// Write according to synchronized I/O file integrity completion. In
// addition to synchronizing the data stored in the file, the implementation
// may also synchronously update the file's metadata.
pub const SYNC: fdflags = 16;
};
// File descriptor attributes.
pub const fdstat = struct {
// File type.
fs_filetype: filetype,
// File descriptor flags.
fs_flags: fdflags,
// Rights that apply to this file descriptor.
fs_rights_base: rights,
// Maximum set of rights that may be installed on new file descriptors that
// are created through this file descriptor, e.g., through `path_open`.
fs_rights_inheriting: rights,
};
// Identifier for a device containing a file system. Can be used in combination
// with `inode` to uniquely identify a file or directory in the filesystem.
pub const device = u64;
// Which file time attributes to adjust.
pub const fstflags = u16;
pub const fstflags_bits = struct {
// Adjust the last data access timestamp to the value stored in `filestat::atim`.
pub const ATIM: fstflags = 1;
// Adjust the last data access timestamp to the time of clock `clockid::realtime`.
pub const ATIM_NOW: fstflags = 2;
// Adjust the last data modification timestamp to the value stored in `filestat::mtim`.
pub const MTIM: fstflags = 4;
// Adjust the last data modification timestamp to the time of clock `clockid::realtime`.
pub const MTIM_NOW: fstflags = 8;
};
// Flags determining the method of how paths are resolved.
pub const lookupflags = u32;
pub const lookupflags_bits = struct {
// As long as the resolved path corresponds to a symbolic link, it is expanded.
pub const SYMLINK_FOLLOW: lookupflags = 1;
};
// Open flags used by `path_open`.
pub const oflags = u16;
pub const oflags_bits = struct {
// Create file if it does not exist.
pub const CREAT: oflags = 1;
// Fail if not a directory.
pub const DIRECTORY: oflags = 2;
// Fail if file already exists.
pub const EXCL: oflags = 4;
// Truncate file to size 0.
pub const TRUNC: oflags = 8;
};
// Number of hard links to an inode.
pub const linkcount = u64;
// File attributes.
pub const filestat = struct {
// Device ID of device containing the file.
dev: u64,
// File serial number.
ino: u64,
// File type.
filetype: filetype,
// Number of hard links to the file.
nlink: u64,
// For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
size: u64,
// Last data access timestamp.
atim: u64,
// Last data modification timestamp.
mtim: u64,
// Last file status change timestamp.
ctim: u64,
};
// User-provided value that may be attached to objects that is retained when
// extracted from the implementation.
pub const userdata = u64;
// Type of a subscription to an event or its occurrence.
pub const eventtype = enum(u8) {
// The time value of clock `subscription_clock::id` has
// reached timestamp `subscription_clock::timeout`.
CLOCK = 0,
// File descriptor `subscription_fd_readwrite::file_descriptor` has data
// available for reading. This event always triggers for regular files.
FD_READ = 1,
// File descriptor `subscription_fd_readwrite::file_descriptor` has capacity
// available for writing. This event always triggers for regular files.
FD_WRITE = 2,
};
// The state of the file descriptor subscribed to with
// `eventtype::fd_read` or `eventtype::fd_write`.
pub const eventrwflags = u16;
pub const eventrwflags_bits = struct {
// The peer of this socket has closed or disconnected.
pub const FD_READWRITE_HANGUP: eventrwflags = 1;
};
// The contents of an `event` when type is `eventtype::fd_read` or
// `eventtype::fd_write`.
pub const event_fd_readwrite = struct {
// The number of bytes available for reading or writing.
nbytes: u64,
// The state of the file descriptor.
flags: eventrwflags,
};
// An event that occurred.
pub const event = struct {
// User-provided value that got attached to `subscription::userdata`.
userdata: u64,
// If non-zero, an error that occurred while processing the subscription request.
_error: errno,
// The type of event that occured
type: eventtype,
// The contents of the event, if it is an `eventtype::fd_read` or
// `eventtype::fd_write`. `eventtype::clock` events ignore this field.
fd_readwrite: event_fd_readwrite,
};
// Flags determining how to interpret the timestamp provided in
// `subscription_clock::timeout`.
pub const subclockflags = u16;
pub const subclockflags_bits = struct {
// If set, treat the timestamp provided in
// `subscription_clock::timeout` as an absolute timestamp of clock
// `subscription_clock::id`. If clear, treat the timestamp
// provided in `subscription_clock::timeout` relative to the
// current time value of clock `subscription_clock::id`.
pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags = 1;
};
// The contents of a `subscription` when type is `eventtype::clock`.
pub const subscription_clock = struct {
// The clock against which to compare the timestamp.
id: clockid,
// The absolute or relative timestamp.
timeout: u64,
// The amount of time that the implementation may wait additionally
// to coalesce with other events.
precision: u64,
// Flags specifying whether the timeout is absolute or relative
flags: subclockflags,
};
// The contents of a `subscription` when type is type is
// `eventtype::fd_read` or `eventtype::fd_write`.
pub const subscription_fd_readwrite = struct {
// The file descriptor on which to wait for it to become ready for reading or writing.
file_descriptor: fd,
};
// The contents of a `subscription`.
pub const subscription_u = struct {
tag: eventtype = undefined,
__pad64_0: u64 = 0,
__pad64_1: u64 = 0,
__pad64_2: u64 = 0,
__pad64_3: u64 = 0,
__pad64_4: u64 = 0,
const Self = @This();
pub fn new(tag: eventtype) void {
return Self{ .tag = tag };
}
pub fn init(comptime T: type, tag: u8, val: T) subscription_u {
var tu = subscription_u.new(tag);
tu.set(val);
return tu;
}
pub fn get(self: *const Self, comptime T: type) T {
const valBuf = @ptrToInt(self) + 8;
return @intToPtr(*const T, valBuf).*;
}
pub fn set(self: *Self, comptime T: type, val: T) void {
var valBuf = @ptrToInt(self) + 8;
mem.set(@intToPtr([32]u8, valBuf), 0);
@intToPtr(*T, valBuf).* = val;
}
// --- clock: subscription_clock if tag=0
pub fn clock(val: subscription_clock) subscription_u {
return subscription_u.new(0, val);
}
pub fn set_clock(self: *Self, val: subscription_clock) void {
self.tag = 0;
self.set(val);
}
pub fn is_clock(self: Self) bool {
return self.tag == 0;
}
pub fn get_clock(self: Self) subscription_clock {
return self.get(subscription_clock);
}
// --- fd_read: subscription_fd_readwrite if tag=1
pub fn fd_read(val: subscription_fd_readwrite) subscription_u {
return subscription_u.new(1, val);
}
pub fn set_fd_read(self: *Self, val: subscription_fd_readwrite) void {
self.tag = 1;
self.set(val);
}
pub fn is_fd_read(self: Self) bool {
return self.tag == 1;
}
pub fn get_fd_read(self: Self) subscription_fd_readwrite {
return self.get(subscription_fd_readwrite);
}
// --- fd_write: subscription_fd_readwrite if tag=2
pub fn fd_write(val: subscription_fd_readwrite) subscription_u {
return subscription_u.new(2, val);
}
pub fn set_fd_write(self: *Self, val: subscription_fd_readwrite) void {
self.tag = 2;
self.set(val);
}
pub fn is_fd_write(self: Self) bool {
return self.tag == 2;
}
pub fn get_fd_write(self: Self) subscription_fd_readwrite {
return self.get(subscription_fd_readwrite);
}
};
// Subscription to an event.
pub const subscription = struct {
// User-provided value that is attached to the subscription in the
// implementation and returned through `event::userdata`.
userdata: u64,
// The type of the event to which to subscribe, and its contents
u: subscription_u,
};
// Exit code generated by a process when exiting.
pub const exitcode = u32;
// Signal condition.
pub const signal = enum(u8) {
// No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
// so this value is reserved.
NONE = 0,
// Hangup.
// Action: Terminates the process.
HUP = 1,
// Terminate interrupt signal.
// Action: Terminates the process.
INT = 2,
// Terminal quit signal.
// Action: Terminates the process.
QUIT = 3,
// Illegal instruction.
// Action: Terminates the process.
ILL = 4,
// Trace/breakpoint trap.
// Action: Terminates the process.
TRAP = 5,
// Process abort signal.
// Action: Terminates the process.
ABRT = 6,
// Access to an undefined portion of a memory object.
// Action: Terminates the process.
BUS = 7,
// Erroneous arithmetic operation.
// Action: Terminates the process.
FPE = 8,
// Kill.
// Action: Terminates the process.
KILL = 9,
// User-defined signal 1.
// Action: Terminates the process.
USR1 = 10,
// Invalid memory reference.
// Action: Terminates the process.
SEGV = 11,
// User-defined signal 2.
// Action: Terminates the process.
USR2 = 12,
// Write on a pipe with no one to read it.
// Action: Ignored.
PIPE = 13,
// Alarm clock.
// Action: Terminates the process.
ALRM = 14,
// Termination signal.
// Action: Terminates the process.
TERM = 15,
// Child process terminated, stopped, or continued.
// Action: Ignored.
CHLD = 16,
// Continue executing, if stopped.
// Action: Continues executing, if stopped.
CONT = 17,
// Stop executing.
// Action: Stops executing.
STOP = 18,
// Terminal stop signal.
// Action: Stops executing.
TSTP = 19,
// Background process attempting read.
// Action: Stops executing.
TTIN = 20,
// Background process attempting write.
// Action: Stops executing.
TTOU = 21,
// High bandwidth data is available at a socket.
// Action: Ignored.
URG = 22,
// CPU time limit exceeded.
// Action: Terminates the process.
XCPU = 23,
// File size limit exceeded.
// Action: Terminates the process.
XFSZ = 24,
// Virtual timer expired.
// Action: Terminates the process.
VTALRM = 25,
// Profiling timer expired.
// Action: Terminates the process.
PROF = 26,
// Window changed.
// Action: Ignored.
WINCH = 27,
// I/O possible.
// Action: Terminates the process.
POLL = 28,
// Power failure.
// Action: Terminates the process.
PWR = 29,
// Bad system call.
// Action: Terminates the process.
SYS = 30,
};
// Flags provided to `sock_recv`.
pub const riflags = u16;
pub const riflags_bits = struct {
// Returns the message without removing it from the socket's receive queue.
pub const RECV_PEEK: riflags = 1;
// On byte-stream sockets, block until the full amount of data can be returned.
pub const RECV_WAITALL: riflags = 2;
};
// Flags returned by `sock_recv`.
pub const roflags = u16;
pub const roflags_bits = struct {
// Returned by `sock_recv`: Message data has been truncated.
pub const RECV_DATA_TRUNCATED: roflags = 1;
};
// Flags provided to `sock_send`. As there are currently no flags
// defined, it must be set to zero.
pub const siflags = u16;
// Which channels on a socket to shut down.
pub const sdflags = u8;
pub const sdflags_bits = struct {
// Disables further receive operations.
pub const RD: sdflags = 1;
// Disables further send operations.
pub const WR: sdflags = 2;
};
// Identifiers for preopened capabilities.
pub const preopentype = enum(u8) {
// A pre-opened directory.
DIR = 0,
};
// The contents of a $prestat when type is `preopentype::dir`.
pub const prestat_dir = struct {
// The length of the directory name for use with `fd_prestat_dir_name`.
pr_name_len: u32,
};
// Information about a pre-opened capability.
pub const prestat = struct {
tag: preopentype = undefined,
__pad64_0: u64 = 0,
const Self = @This();
pub fn new(tag: preopentype) void {
return Self{ .tag = tag };
}
pub fn init(comptime T: type, tag: u8, val: T) prestat {
var tu = prestat.new(tag);
tu.set(val);
return tu;
}
pub fn get(self: *const Self, comptime T: type) T {
const valBuf = @ptrToInt(self) + 4;
return @intToPtr(*const T, valBuf).*;
}
pub fn set(self: *Self, comptime T: type, val: T) void {
var valBuf = @ptrToInt(self) + 4;
mem.set(@intToPtr([4]u8, valBuf), 0);
@intToPtr(*T, valBuf).* = val;
}
// --- dir: prestat_dir if tag=0
pub fn dir(val: prestat_dir) prestat {
return prestat.new(0, val);
}
pub fn set_dir(self: *Self, val: prestat_dir) void {
self.tag = 0;
self.set(val);
}
pub fn is_dir(self: Self) bool {
return self.tag == 0;
}
pub fn get_dir(self: Self) prestat_dir {
return self.get(prestat_dir);
}
};
// ----------------------[wasi_snapshot_preview1]----------------------
pub const mod_wasi_snapshot_preview1 = struct {
// Read command-line argument data.
// The size of the array should match that returned by `args_sizes_get`
// in: argv, argv_buf
// out: error
extern "wasi_snapshot_preview1" fn args_get(argv: **u8, argv_buf: *u8) errno;
// Return command-line argument data sizes.
// in:
// out: error, argc, argv_buf_size
extern "wasi_snapshot_preview1" fn args_sizes_get(argc_ptr: *size, argv_buf_size_ptr: *size) errno;
// Read environment variable data.
// The sizes of the buffers should match that returned by `environ_sizes_get`.
// in: environ, environ_buf
// out: error
extern "wasi_snapshot_preview1" fn environ_get(environ: **u8, environ_buf: *u8) errno;
// Return environment variable data sizes.
// in:
// out: error, environc, environ_buf_size
extern "wasi_snapshot_preview1" fn environ_sizes_get(environc_ptr: *size, environ_buf_size_ptr: *size) errno;
// Return the resolution of a clock.
// Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
// return `errno::inval`.
// Note: This is similar to `clock_getres` in POSIX.
// in: id
// out: error, resolution
extern "wasi_snapshot_preview1" fn clock_res_get(id: clockid, resolution_ptr: *timestamp) errno;
// Return the time value of a clock.
// Note: This is similar to `clock_gettime` in POSIX.
// in: id, precision
// out: error, time
extern "wasi_snapshot_preview1" fn clock_time_get(id: clockid, precision: timestamp, time_ptr: *timestamp) errno;
// Provide file advisory information on a file descriptor.
// Note: This is similar to `posix_fadvise` in POSIX.
// in: fd, offset, len, advice
// out: error
extern "wasi_snapshot_preview1" fn fd_advise(fd: fd, offset: filesize, len: filesize, advice: advice) errno;
// Force the allocation of space in a file.
// Note: This is similar to `posix_fallocate` in POSIX.
// in: fd, offset, len
// out: error
extern "wasi_snapshot_preview1" fn fd_allocate(fd: fd, offset: filesize, len: filesize) errno;
// Close a file descriptor.
// Note: This is similar to `close` in POSIX.
// in: fd
// out: error
extern "wasi_snapshot_preview1" fn fd_close(fd: fd) errno;
// Synchronize the data of a file to disk.
// Note: This is similar to `fdatasync` in POSIX.
// in: fd
// out: error
extern "wasi_snapshot_preview1" fn fd_datasync(fd: fd) errno;
// Get the attributes of a file descriptor.
// Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
// in: fd
// out: error, stat
extern "wasi_snapshot_preview1" fn fd_fdstat_get(fd: fd, stat_ptr: *fdstat) errno;
// Adjust the flags associated with a file descriptor.
// Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
// in: fd, flags
// out: error
extern "wasi_snapshot_preview1" fn fd_fdstat_set_flags(fd: fd, flags: fdflags) errno;
// Adjust the rights associated with a file descriptor.
// This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights
// in: fd, fs_rights_base, fs_rights_inheriting
// out: error
extern "wasi_snapshot_preview1" fn fd_fdstat_set_rights(fd: fd, fs_rights_base: rights, fs_rights_inheriting: rights) errno;
// Return the attributes of an open file.
// in: fd
// out: error, buf
extern "wasi_snapshot_preview1" fn fd_filestat_get(fd: fd, buf_ptr: *filestat) errno;
// Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
// Note: This is similar to `ftruncate` in POSIX.
// in: fd, size
// out: error
extern "wasi_snapshot_preview1" fn fd_filestat_set_size(fd: fd, size: filesize) errno;
// Adjust the timestamps of an open file or directory.
// Note: This is similar to `futimens` in POSIX.
// in: fd, atim, mtim, fst_flags
// out: error
extern "wasi_snapshot_preview1" fn fd_filestat_set_times(fd: fd, atim: timestamp, mtim: timestamp, fst_flags: fstflags) errno;
// Read from a file descriptor, without using and updating the file descriptor's offset.
// Note: This is similar to `preadv` in POSIX.
// in: fd, iovs, offset
// out: error, nread
extern "wasi_snapshot_preview1" fn fd_pread(fd: fd, iovs_ptr: iovec_array, iovs_count: usize, offset: filesize, nread_ptr: *size) errno;
// Return a description of the given preopened file descriptor.
// in: fd
// out: error, buf
extern "wasi_snapshot_preview1" fn fd_prestat_get(fd: fd, buf_ptr: *prestat) errno;
// Return a description of the given preopened file descriptor.
// in: fd, path, path_len
// out: error
extern "wasi_snapshot_preview1" fn fd_prestat_dir_name(fd: fd, path: *u8, path_len: size) errno;
// Write to a file descriptor, without using and updating the file descriptor's offset.
// Note: This is similar to `pwritev` in POSIX.
// in: fd, iovs, offset
// out: error, nwritten
extern "wasi_snapshot_preview1" fn fd_pwrite(fd: fd, iovs_ptr: ciovec_array, iovs_count: usize, offset: filesize, nwritten_ptr: *size) errno;
// Read from a file descriptor.
// Note: This is similar to `readv` in POSIX.
// in: fd, iovs
// out: error, nread
extern "wasi_snapshot_preview1" fn fd_read(fd: fd, iovs_ptr: iovec_array, iovs_count: usize, nread_ptr: *size) errno;
// Read directory entries from a directory.
// When successful, the contents of the output buffer consist of a sequence of
// directory entries. Each directory entry consists of a `dirent` object,
// followed by `dirent::d_namlen` bytes holding the name of the directory
// entry.
// This function fills the output buffer as much as possible, potentially
// truncating the last directory entry. This allows the caller to grow its
// read buffer size in case it's too small to fit a single large directory
// entry, or skip the oversized directory entry.
// in: fd, buf, buf_len, cookie
// out: error, bufused
extern "wasi_snapshot_preview1" fn fd_readdir(fd: fd, buf: *u8, buf_len: size, cookie: dircookie, bufused_ptr: *size) errno;
// Atomically replace a file descriptor by renumbering another file descriptor.
// Due to the strong focus on thread safety, this environment does not provide
// a mechanism to duplicate or renumber a file descriptor to an arbitrary
// number, like `dup2()`. This would be prone to race conditions, as an actual
// file descriptor with the same number could be allocated by a different
// thread at the same time.
// This function provides a way to atomically renumber file descriptors, which
// would disappear if `dup2()` were to be removed entirely.
// in: fd, to
// out: error
extern "wasi_snapshot_preview1" fn fd_renumber(fd: fd, to: fd) errno;
// Move the offset of a file descriptor.
// Note: This is similar to `lseek` in POSIX.
// in: fd, offset, whence
// out: error, newoffset
extern "wasi_snapshot_preview1" fn fd_seek(fd: fd, offset: filedelta, whence: whence, newoffset_ptr: *filesize) errno;
// Synchronize the data and metadata of a file to disk.
// Note: This is similar to `fsync` in POSIX.
// in: fd
// out: error
extern "wasi_snapshot_preview1" fn fd_sync(fd: fd) errno;
// Return the current offset of a file descriptor.
// Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
// in: fd
// out: error, offset
extern "wasi_snapshot_preview1" fn fd_tell(fd: fd, offset_ptr: *filesize) errno;
// Write to a file descriptor.
// Note: This is similar to `writev` in POSIX.
// in: fd, iovs
// out: error, nwritten
extern "wasi_snapshot_preview1" fn fd_write(fd: fd, iovs_ptr: ciovec_array, iovs_count: usize, nwritten_ptr: *size) errno;
// Create a directory.
// Note: This is similar to `mkdirat` in POSIX.
// in: fd, path
// out: error
extern "wasi_snapshot_preview1" fn path_create_directory(fd: fd, path_ptr: wasi_string_ptr, path_len: usize) errno;
// Return the attributes of a file or directory.
// Note: This is similar to `stat` in POSIX.
// in: fd, flags, path
// out: error, buf
extern "wasi_snapshot_preview1" fn path_filestat_get(fd: fd, flags: lookupflags, path_ptr: wasi_string_ptr, path_len: usize, buf_ptr: *filestat) errno;
// Adjust the timestamps of a file or directory.
// Note: This is similar to `utimensat` in POSIX.
// in: fd, flags, path, atim, mtim, fst_flags
// out: error
extern "wasi_snapshot_preview1" fn path_filestat_set_times(fd: fd, flags: lookupflags, path_ptr: wasi_string_ptr, path_len: usize, atim: timestamp, mtim: timestamp, fst_flags: fstflags) errno;
// Create a hard link.
// Note: This is similar to `linkat` in POSIX.
// in: old_fd, old_flags, old_path, new_fd, new_path
// out: error
extern "wasi_snapshot_preview1" fn path_link(old_fd: fd, old_flags: lookupflags, old_path_ptr: wasi_string_ptr, old_path_len: usize, new_fd: fd, new_path_ptr: wasi_string_ptr, new_path_len: usize) errno;
// Open a file or directory.
// The returned file descriptor is not guaranteed to be the lowest-numbered
// file descriptor not currently open; it is randomized to prevent
// applications from depending on making assumptions about indexes, since this
// is error-prone in multi-threaded contexts. The returned file descriptor is
// guaranteed to be less than 2**31.
// Note: This is similar to `openat` in POSIX.
// in: fd, dirflags, path, oflags, fs_rights_base, fs_rights_inherting, fdflags
// out: error, opened_fd
extern "wasi_snapshot_preview1" fn path_open(fd: fd, dirflags: lookupflags, path_ptr: wasi_string_ptr, path_len: usize, oflags: oflags, fs_rights_base: rights, fs_rights_inherting: rights, fdflags: fdflags, opened_fd_ptr: *fd) errno;
// Read the contents of a symbolic link.
// Note: This is similar to `readlinkat` in POSIX.
// in: fd, path, buf, buf_len
// out: error, bufused
extern "wasi_snapshot_preview1" fn path_readlink(fd: fd, path_ptr: wasi_string_ptr, path_len: usize, buf: *u8, buf_len: size, bufused_ptr: *size) errno;
// Remove a directory.
// Return `errno::notempty` if the directory is not empty.
// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
// in: fd, path
// out: error
extern "wasi_snapshot_preview1" fn path_remove_directory(fd: fd, path_ptr: wasi_string_ptr, path_len: usize) errno;
// Rename a file or directory.
// Note: This is similar to `renameat` in POSIX.
// in: fd, old_path, new_fd, new_path
// out: error
extern "wasi_snapshot_preview1" fn path_rename(fd: fd, old_path_ptr: wasi_string_ptr, old_path_len: usize, new_fd: fd, new_path_ptr: wasi_string_ptr, new_path_len: usize) errno;
// Create a symbolic link.
// Note: This is similar to `symlinkat` in POSIX.
// in: old_path, fd, new_path
// out: error
extern "wasi_snapshot_preview1" fn path_symlink(old_path_ptr: wasi_string_ptr, old_path_len: usize, fd: fd, new_path_ptr: wasi_string_ptr, new_path_len: usize) errno;
// Unlink a file.
// Return `errno::isdir` if the path refers to a directory.
// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
// in: fd, path
// out: error
extern "wasi_snapshot_preview1" fn path_unlink_file(fd: fd, path_ptr: wasi_string_ptr, path_len: usize) errno;
// Concurrently poll for the occurrence of a set of events.
// in: in, out, nsubscriptions
// out: error, nevents
extern "wasi_snapshot_preview1" fn poll_oneoff(in: *const subscription, out: *event, nsubscriptions: size, nevents_ptr: *size) errno;
// Terminate the process normally. An exit code of 0 indicates successful
// termination of the program. The meanings of other values is dependent on
// the environment.
// in: rval
// out:
extern "wasi_snapshot_preview1" fn proc_exit(rval: exitcode) void;
// Send a signal to the process of the calling thread.
// Note: This is similar to `raise` in POSIX.
// in: sig
// out: error
extern "wasi_snapshot_preview1" fn proc_raise(sig: signal) errno;
// Temporarily yield execution of the calling thread.
// Note: This is similar to `sched_yield` in POSIX.
// in:
// out: error
extern "wasi_snapshot_preview1" fn sched_yield() errno;
// Write high-quality random data into a buffer.
// This function blocks when the implementation is unable to immediately
// provide sufficient high-quality random data.
// This function may execute slowly, so when large mounts of random data are
// required, it's advisable to use this function to seed a pseudo-random
// number generator, rather than to provide the random data directly.
// in: buf, buf_len
// out: error
extern "wasi_snapshot_preview1" fn random_get(buf: *u8, buf_len: size) errno;
// Receive a message from a socket.
// Note: This is similar to `recv` in POSIX, though it also supports reading
// the data into multiple buffers in the manner of `readv`.
// in: fd, ri_data, ri_flags
// out: error, ro_datalen, ro_flags
extern "wasi_snapshot_preview1" fn sock_recv(fd: fd, ri_data_ptr: iovec_array, ri_data_count: usize, ri_flags: riflags, ro_datalen_ptr: *size, ro_flags_ptr: *roflags) errno;
// Send a message on a socket.
// Note: This is similar to `send` in POSIX, though it also supports writing
// the data from multiple buffers in the manner of `writev`.
// in: fd, si_data, si_flags
// out: error, so_datalen
extern "wasi_snapshot_preview1" fn sock_send(fd: fd, si_data_ptr: ciovec_array, si_data_count: usize, si_flags: siflags, so_datalen_ptr: *size) errno;
// Shut down socket send and receive channels.
// Note: This is similar to `shutdown` in POSIX.
// in: fd, how
// out: error
extern "wasi_snapshot_preview1" fn sock_shutdown(fd: fd, how: sdflags) errno;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment