diff options
Diffstat (limited to 'lib/std/os')
55 files changed, 16361 insertions, 0 deletions
diff --git a/lib/std/os/bits.zig b/lib/std/os/bits.zig new file mode 100644 index 0000000000..f16da2487b --- /dev/null +++ b/lib/std/os/bits.zig @@ -0,0 +1,27 @@ +// Platform-dependent types and values that are used along with OS-specific APIs. +// These are imported into `std.c`, `std.os`, and `std.os.linux`. + +const builtin = @import("builtin"); + +pub usingnamespace switch (builtin.os) { + .macosx, .ios, .tvos, .watchos => @import("bits/darwin.zig"), + .freebsd => @import("bits/freebsd.zig"), + .linux => @import("bits/linux.zig"), + .netbsd => @import("bits/netbsd.zig"), + .wasi => @import("bits/wasi.zig"), + .windows => @import("bits/windows.zig"), + else => struct {}, +}; + +pub const pthread_t = *@OpaqueType(); +pub const FILE = @OpaqueType(); + +pub const iovec = extern struct { + iov_base: [*]u8, + iov_len: usize, +}; + +pub const iovec_const = extern struct { + iov_base: [*]const u8, + iov_len: usize, +}; diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig new file mode 100644 index 0000000000..b076f95884 --- /dev/null +++ b/lib/std/os/bits/darwin.zig @@ -0,0 +1,1180 @@ +const std = @import("../../std.zig"); +const assert = std.debug.assert; +const maxInt = std.math.maxInt; + +pub const fd_t = c_int; +pub const pid_t = c_int; + +pub const in_port_t = u16; +pub const sa_family_t = u8; +pub const socklen_t = u32; +pub const sockaddr = extern union { + in: sockaddr_in, + in6: sockaddr_in6, +}; +pub const sockaddr_in = extern struct { + len: u8, + family: sa_family_t, + port: in_port_t, + addr: u32, + zero: [8]u8, +}; +pub const sockaddr_in6 = extern struct { + len: u8, + family: sa_family_t, + port: in_port_t, + flowinfo: u32, + addr: [16]u8, + scope_id: u32, +}; + +pub const timeval = extern struct { + tv_sec: c_long, + tv_usec: i32, +}; + +pub const timezone = extern struct { + tz_minuteswest: i32, + tz_dsttime: i32, +}; + +pub const mach_timebase_info_data = extern struct { + numer: u32, + denom: u32, +}; + +pub const off_t = i64; + +/// Renamed to Stat to not conflict with the stat function. +/// atime, mtime, and ctime have functions to return `timespec`, +/// because although this is a POSIX API, the layout and names of +/// the structs are inconsistent across operating systems, and +/// in C, macros are used to hide the differences. Here we use +/// methods to accomplish this. +pub const Stat = extern struct { + dev: i32, + mode: u16, + nlink: u16, + ino: u64, + uid: u32, + gid: u32, + rdev: i32, + atimesec: isize, + atimensec: isize, + mtimesec: isize, + mtimensec: isize, + ctimesec: isize, + ctimensec: isize, + birthtimesec: isize, + birthtimensec: isize, + size: off_t, + blocks: i64, + blksize: i32, + flags: u32, + gen: u32, + lspare: i32, + qspare: [2]i64, + + pub fn atime(self: Stat) timespec { + return timespec{ + .tv_sec = self.atimesec, + .tv_nsec = self.atimensec, + }; + } + + pub fn mtime(self: Stat) timespec { + return timespec{ + .tv_sec = self.mtimesec, + .tv_nsec = self.mtimensec, + }; + } + + pub fn ctime(self: Stat) timespec { + return timespec{ + .tv_sec = self.ctimesec, + .tv_nsec = self.ctimensec, + }; + } +}; + +pub const timespec = extern struct { + tv_sec: isize, + tv_nsec: isize, +}; + +pub const sigset_t = u32; +pub const empty_sigset = sigset_t(0); + +/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name. +pub const Sigaction = extern struct { + handler: extern fn (c_int) void, + sa_mask: sigset_t, + sa_flags: c_int, +}; + +pub const dirent = extern struct { + d_ino: usize, + d_seekoff: usize, + d_reclen: u16, + d_namlen: u16, + d_type: u8, + d_name: u8, // field address is address of first byte of name +}; + +pub const pthread_attr_t = extern struct { + __sig: c_long, + __opaque: [56]u8, +}; + +/// Renamed from `kevent` to `Kevent` to avoid conflict with function name. +pub const Kevent = extern struct { + ident: usize, + filter: i16, + flags: u16, + fflags: u32, + data: isize, + udata: usize, +}; + +// sys/types.h on macos uses #pragma pack(4) so these checks are +// to make sure the struct is laid out the same. These values were +// produced from C code using the offsetof macro. +comptime { + assert(@byteOffsetOf(Kevent, "ident") == 0); + assert(@byteOffsetOf(Kevent, "filter") == 8); + assert(@byteOffsetOf(Kevent, "flags") == 10); + assert(@byteOffsetOf(Kevent, "fflags") == 12); + assert(@byteOffsetOf(Kevent, "data") == 16); + assert(@byteOffsetOf(Kevent, "udata") == 24); +} + +pub const kevent64_s = extern struct { + ident: u64, + filter: i16, + flags: u16, + fflags: u32, + data: i64, + udata: u64, + ext: [2]u64, +}; + +// sys/types.h on macos uses #pragma pack() so these checks are +// to make sure the struct is laid out the same. These values were +// produced from C code using the offsetof macro. +comptime { + assert(@byteOffsetOf(kevent64_s, "ident") == 0); + assert(@byteOffsetOf(kevent64_s, "filter") == 8); + assert(@byteOffsetOf(kevent64_s, "flags") == 10); + assert(@byteOffsetOf(kevent64_s, "fflags") == 12); + assert(@byteOffsetOf(kevent64_s, "data") == 16); + assert(@byteOffsetOf(kevent64_s, "udata") == 24); + assert(@byteOffsetOf(kevent64_s, "ext") == 32); +} + +pub const mach_port_t = c_uint; +pub const clock_serv_t = mach_port_t; +pub const clock_res_t = c_int; +pub const mach_port_name_t = natural_t; +pub const natural_t = c_uint; +pub const mach_timespec_t = extern struct { + tv_sec: c_uint, + tv_nsec: clock_res_t, +}; +pub const kern_return_t = c_int; +pub const host_t = mach_port_t; +pub const CALENDAR_CLOCK = 1; + +pub const PATH_MAX = 1024; + +pub const STDIN_FILENO = 0; +pub const STDOUT_FILENO = 1; +pub const STDERR_FILENO = 2; + +/// [MC2] no permissions +pub const PROT_NONE = 0x00; + +/// [MC2] pages can be read +pub const PROT_READ = 0x01; + +/// [MC2] pages can be written +pub const PROT_WRITE = 0x02; + +/// [MC2] pages can be executed +pub const PROT_EXEC = 0x04; + +/// allocated from memory, swap space +pub const MAP_ANONYMOUS = 0x1000; + +/// map from file (default) +pub const MAP_FILE = 0x0000; + +/// interpret addr exactly +pub const MAP_FIXED = 0x0010; + +/// region may contain semaphores +pub const MAP_HASSEMAPHORE = 0x0200; + +/// changes are private +pub const MAP_PRIVATE = 0x0002; + +/// share changes +pub const MAP_SHARED = 0x0001; + +/// don't cache pages for this mapping +pub const MAP_NOCACHE = 0x0400; + +/// don't reserve needed swap area +pub const MAP_NORESERVE = 0x0040; +pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize)); + +/// [XSI] no hang in wait/no child to reap +pub const WNOHANG = 0x00000001; + +/// [XSI] notify on stop, untraced child +pub const WUNTRACED = 0x00000002; + +/// take signal on signal stack +pub const SA_ONSTACK = 0x0001; + +/// restart system on signal return +pub const SA_RESTART = 0x0002; + +/// reset to SIG_DFL when taking signal +pub const SA_RESETHAND = 0x0004; + +/// do not generate SIGCHLD on child stop +pub const SA_NOCLDSTOP = 0x0008; + +/// don't mask the signal we're delivering +pub const SA_NODEFER = 0x0010; + +/// don't keep zombies around +pub const SA_NOCLDWAIT = 0x0020; + +/// signal handler with SA_SIGINFO args +pub const SA_SIGINFO = 0x0040; + +/// do not bounce off kernel's sigtramp +pub const SA_USERTRAMP = 0x0100; + +/// signal handler with SA_SIGINFO args with 64bit regs information +pub const SA_64REGSET = 0x0200; + +pub const O_LARGEFILE = 0x0000; +pub const O_PATH = 0x0000; + +pub const F_OK = 0; +pub const X_OK = 1; +pub const W_OK = 2; +pub const R_OK = 4; + +/// open for reading only +pub const O_RDONLY = 0x0000; + +/// open for writing only +pub const O_WRONLY = 0x0001; + +/// open for reading and writing +pub const O_RDWR = 0x0002; + +/// do not block on open or for data to become available +pub const O_NONBLOCK = 0x0004; + +/// append on each write +pub const O_APPEND = 0x0008; + +/// create file if it does not exist +pub const O_CREAT = 0x0200; + +/// truncate size to 0 +pub const O_TRUNC = 0x0400; + +/// error if O_CREAT and the file exists +pub const O_EXCL = 0x0800; + +/// atomically obtain a shared lock +pub const O_SHLOCK = 0x0010; + +/// atomically obtain an exclusive lock +pub const O_EXLOCK = 0x0020; + +/// do not follow symlinks +pub const O_NOFOLLOW = 0x0100; + +/// allow open of symlinks +pub const O_SYMLINK = 0x200000; + +/// descriptor requested for event notifications only +pub const O_EVTONLY = 0x8000; + +/// mark as close-on-exec +pub const O_CLOEXEC = 0x1000000; + +pub const O_ACCMODE = 3; +pub const O_ALERT = 536870912; +pub const O_ASYNC = 64; +pub const O_DIRECTORY = 1048576; +pub const O_DP_GETRAWENCRYPTED = 1; +pub const O_DP_GETRAWUNENCRYPTED = 2; +pub const O_DSYNC = 4194304; +pub const O_FSYNC = O_SYNC; +pub const O_NOCTTY = 131072; +pub const O_POPUP = 2147483648; +pub const O_SYNC = 128; + +pub const SEEK_SET = 0x0; +pub const SEEK_CUR = 0x1; +pub const SEEK_END = 0x2; + +pub const DT_UNKNOWN = 0; +pub const DT_FIFO = 1; +pub const DT_CHR = 2; +pub const DT_DIR = 4; +pub const DT_BLK = 6; +pub const DT_REG = 8; +pub const DT_LNK = 10; +pub const DT_SOCK = 12; +pub const DT_WHT = 14; + +/// block specified signal set +pub const SIG_BLOCK = 1; + +/// unblock specified signal set +pub const SIG_UNBLOCK = 2; + +/// set specified signal set +pub const SIG_SETMASK = 3; + +/// hangup +pub const SIGHUP = 1; + +/// interrupt +pub const SIGINT = 2; + +/// quit +pub const SIGQUIT = 3; + +/// illegal instruction (not reset when caught) +pub const SIGILL = 4; + +/// trace trap (not reset when caught) +pub const SIGTRAP = 5; + +/// abort() +pub const SIGABRT = 6; + +/// pollable event ([XSR] generated, not supported) +pub const SIGPOLL = 7; + +/// compatibility +pub const SIGIOT = SIGABRT; + +/// EMT instruction +pub const SIGEMT = 7; + +/// floating point exception +pub const SIGFPE = 8; + +/// kill (cannot be caught or ignored) +pub const SIGKILL = 9; + +/// bus error +pub const SIGBUS = 10; + +/// segmentation violation +pub const SIGSEGV = 11; + +/// bad argument to system call +pub const SIGSYS = 12; + +/// write on a pipe with no one to read it +pub const SIGPIPE = 13; + +/// alarm clock +pub const SIGALRM = 14; + +/// software termination signal from kill +pub const SIGTERM = 15; + +/// urgent condition on IO channel +pub const SIGURG = 16; + +/// sendable stop signal not from tty +pub const SIGSTOP = 17; + +/// stop signal from tty +pub const SIGTSTP = 18; + +/// continue a stopped process +pub const SIGCONT = 19; + +/// to parent on child stop or exit +pub const SIGCHLD = 20; + +/// to readers pgrp upon background tty read +pub const SIGTTIN = 21; + +/// like TTIN for output if (tp->t_local<OSTOP) +pub const SIGTTOU = 22; + +/// input/output possible signal +pub const SIGIO = 23; + +/// exceeded CPU time limit +pub const SIGXCPU = 24; + +/// exceeded file size limit +pub const SIGXFSZ = 25; + +/// virtual time alarm +pub const SIGVTALRM = 26; + +/// profiling time alarm +pub const SIGPROF = 27; + +/// window size changes +pub const SIGWINCH = 28; + +/// information request +pub const SIGINFO = 29; + +/// user defined signal 1 +pub const SIGUSR1 = 30; + +/// user defined signal 2 +pub const SIGUSR2 = 31; + +/// no flag value +pub const KEVENT_FLAG_NONE = 0x000; + +/// immediate timeout +pub const KEVENT_FLAG_IMMEDIATE = 0x001; + +/// output events only include change +pub const KEVENT_FLAG_ERROR_EVENTS = 0x002; + +/// add event to kq (implies enable) +pub const EV_ADD = 0x0001; + +/// delete event from kq +pub const EV_DELETE = 0x0002; + +/// enable event +pub const EV_ENABLE = 0x0004; + +/// disable event (not reported) +pub const EV_DISABLE = 0x0008; + +/// only report one occurrence +pub const EV_ONESHOT = 0x0010; + +/// clear event state after reporting +pub const EV_CLEAR = 0x0020; + +/// force immediate event output +/// ... with or without EV_ERROR +/// ... use KEVENT_FLAG_ERROR_EVENTS +/// on syscalls supporting flags +pub const EV_RECEIPT = 0x0040; + +/// disable event after reporting +pub const EV_DISPATCH = 0x0080; + +/// unique kevent per udata value +pub const EV_UDATA_SPECIFIC = 0x0100; + +/// ... in combination with EV_DELETE +/// will defer delete until udata-specific +/// event enabled. EINPROGRESS will be +/// returned to indicate the deferral +pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC; + +/// report that source has vanished +/// ... only valid with EV_DISPATCH2 +pub const EV_VANISHED = 0x0200; + +/// reserved by system +pub const EV_SYSFLAGS = 0xF000; + +/// filter-specific flag +pub const EV_FLAG0 = 0x1000; + +/// filter-specific flag +pub const EV_FLAG1 = 0x2000; + +/// EOF detected +pub const EV_EOF = 0x8000; + +/// error, data contains errno +pub const EV_ERROR = 0x4000; + +pub const EV_POLL = EV_FLAG0; +pub const EV_OOBAND = EV_FLAG1; + +pub const EVFILT_READ = -1; +pub const EVFILT_WRITE = -2; + +/// attached to aio requests +pub const EVFILT_AIO = -3; + +/// attached to vnodes +pub const EVFILT_VNODE = -4; + +/// attached to struct proc +pub const EVFILT_PROC = -5; + +/// attached to struct proc +pub const EVFILT_SIGNAL = -6; + +/// timers +pub const EVFILT_TIMER = -7; + +/// Mach portsets +pub const EVFILT_MACHPORT = -8; + +/// Filesystem events +pub const EVFILT_FS = -9; + +/// User events +pub const EVFILT_USER = -10; + +/// Virtual memory events +pub const EVFILT_VM = -12; + +/// Exception events +pub const EVFILT_EXCEPT = -15; + +pub const EVFILT_SYSCOUNT = 17; + +/// On input, NOTE_TRIGGER causes the event to be triggered for output. +pub const NOTE_TRIGGER = 0x01000000; + +/// ignore input fflags +pub const NOTE_FFNOP = 0x00000000; + +/// and fflags +pub const NOTE_FFAND = 0x40000000; + +/// or fflags +pub const NOTE_FFOR = 0x80000000; + +/// copy fflags +pub const NOTE_FFCOPY = 0xc0000000; + +/// mask for operations +pub const NOTE_FFCTRLMASK = 0xc0000000; +pub const NOTE_FFLAGSMASK = 0x00ffffff; + +/// low water mark +pub const NOTE_LOWAT = 0x00000001; + +/// OOB data +pub const NOTE_OOB = 0x00000002; + +/// vnode was removed +pub const NOTE_DELETE = 0x00000001; + +/// data contents changed +pub const NOTE_WRITE = 0x00000002; + +/// size increased +pub const NOTE_EXTEND = 0x00000004; + +/// attributes changed +pub const NOTE_ATTRIB = 0x00000008; + +/// link count changed +pub const NOTE_LINK = 0x00000010; + +/// vnode was renamed +pub const NOTE_RENAME = 0x00000020; + +/// vnode access was revoked +pub const NOTE_REVOKE = 0x00000040; + +/// No specific vnode event: to test for EVFILT_READ activation +pub const NOTE_NONE = 0x00000080; + +/// vnode was unlocked by flock(2) +pub const NOTE_FUNLOCK = 0x00000100; + +/// process exited +pub const NOTE_EXIT = 0x80000000; + +/// process forked +pub const NOTE_FORK = 0x40000000; + +/// process exec'd +pub const NOTE_EXEC = 0x20000000; + +/// shared with EVFILT_SIGNAL +pub const NOTE_SIGNAL = 0x08000000; + +/// exit status to be returned, valid for child process only +pub const NOTE_EXITSTATUS = 0x04000000; + +/// provide details on reasons for exit +pub const NOTE_EXIT_DETAIL = 0x02000000; + +/// mask for signal & exit status +pub const NOTE_PDATAMASK = 0x000fffff; +pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK); + +pub const NOTE_EXIT_DETAIL_MASK = 0x00070000; +pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000; +pub const NOTE_EXIT_MEMORY = 0x00020000; +pub const NOTE_EXIT_CSERROR = 0x00040000; + +/// will react on memory pressure +pub const NOTE_VM_PRESSURE = 0x80000000; + +/// will quit on memory pressure, possibly after cleaning up dirty state +pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000; + +/// will quit immediately on memory pressure +pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000; + +/// there was an error +pub const NOTE_VM_ERROR = 0x10000000; + +/// data is seconds +pub const NOTE_SECONDS = 0x00000001; + +/// data is microseconds +pub const NOTE_USECONDS = 0x00000002; + +/// data is nanoseconds +pub const NOTE_NSECONDS = 0x00000004; + +/// absolute timeout +pub const NOTE_ABSOLUTE = 0x00000008; + +/// ext[1] holds leeway for power aware timers +pub const NOTE_LEEWAY = 0x00000010; + +/// system does minimal timer coalescing +pub const NOTE_CRITICAL = 0x00000020; + +/// system does maximum timer coalescing +pub const NOTE_BACKGROUND = 0x00000040; +pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080; + +/// data is mach absolute time units +pub const NOTE_MACHTIME = 0x00000100; + +pub const AF_UNSPEC = 0; +pub const AF_LOCAL = 1; +pub const AF_UNIX = AF_LOCAL; +pub const AF_INET = 2; +pub const AF_SYS_CONTROL = 2; +pub const AF_IMPLINK = 3; +pub const AF_PUP = 4; +pub const AF_CHAOS = 5; +pub const AF_NS = 6; +pub const AF_ISO = 7; +pub const AF_OSI = AF_ISO; +pub const AF_ECMA = 8; +pub const AF_DATAKIT = 9; +pub const AF_CCITT = 10; +pub const AF_SNA = 11; +pub const AF_DECnet = 12; +pub const AF_DLI = 13; +pub const AF_LAT = 14; +pub const AF_HYLINK = 15; +pub const AF_APPLETALK = 16; +pub const AF_ROUTE = 17; +pub const AF_LINK = 18; +pub const AF_XTP = 19; +pub const AF_COIP = 20; +pub const AF_CNT = 21; +pub const AF_RTIP = 22; +pub const AF_IPX = 23; +pub const AF_SIP = 24; +pub const AF_PIP = 25; +pub const AF_ISDN = 28; +pub const AF_E164 = AF_ISDN; +pub const AF_KEY = 29; +pub const AF_INET6 = 30; +pub const AF_NATM = 31; +pub const AF_SYSTEM = 32; +pub const AF_NETBIOS = 33; +pub const AF_PPP = 34; +pub const AF_MAX = 40; + +pub const PF_UNSPEC = AF_UNSPEC; +pub const PF_LOCAL = AF_LOCAL; +pub const PF_UNIX = PF_LOCAL; +pub const PF_INET = AF_INET; +pub const PF_IMPLINK = AF_IMPLINK; +pub const PF_PUP = AF_PUP; +pub const PF_CHAOS = AF_CHAOS; +pub const PF_NS = AF_NS; +pub const PF_ISO = AF_ISO; +pub const PF_OSI = AF_ISO; +pub const PF_ECMA = AF_ECMA; +pub const PF_DATAKIT = AF_DATAKIT; +pub const PF_CCITT = AF_CCITT; +pub const PF_SNA = AF_SNA; +pub const PF_DECnet = AF_DECnet; +pub const PF_DLI = AF_DLI; +pub const PF_LAT = AF_LAT; +pub const PF_HYLINK = AF_HYLINK; +pub const PF_APPLETALK = AF_APPLETALK; +pub const PF_ROUTE = AF_ROUTE; +pub const PF_LINK = AF_LINK; +pub const PF_XTP = AF_XTP; +pub const PF_COIP = AF_COIP; +pub const PF_CNT = AF_CNT; +pub const PF_SIP = AF_SIP; +pub const PF_IPX = AF_IPX; +pub const PF_RTIP = AF_RTIP; +pub const PF_PIP = AF_PIP; +pub const PF_ISDN = AF_ISDN; +pub const PF_KEY = AF_KEY; +pub const PF_INET6 = AF_INET6; +pub const PF_NATM = AF_NATM; +pub const PF_SYSTEM = AF_SYSTEM; +pub const PF_NETBIOS = AF_NETBIOS; +pub const PF_PPP = AF_PPP; +pub const PF_MAX = AF_MAX; + +pub const SYSPROTO_EVENT = 1; +pub const SYSPROTO_CONTROL = 2; + +pub const SOCK_STREAM = 1; +pub const SOCK_DGRAM = 2; +pub const SOCK_RAW = 3; +pub const SOCK_RDM = 4; +pub const SOCK_SEQPACKET = 5; +pub const SOCK_MAXADDRLEN = 255; + +pub const IPPROTO_ICMP = 1; +pub const IPPROTO_ICMPV6 = 58; +pub const IPPROTO_TCP = 6; +pub const IPPROTO_UDP = 17; +pub const IPPROTO_IP = 0; +pub const IPPROTO_IPV6 = 41; + +fn wstatus(x: u32) u32 { + return x & 0o177; +} +const wstopped = 0o177; +pub fn WEXITSTATUS(x: u32) u32 { + return x >> 8; +} +pub fn WTERMSIG(x: u32) u32 { + return wstatus(x); +} +pub fn WSTOPSIG(x: u32) u32 { + return x >> 8; +} +pub fn WIFEXITED(x: u32) bool { + return wstatus(x) == 0; +} +pub fn WIFSTOPPED(x: u32) bool { + return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; +} +pub fn WIFSIGNALED(x: u32) bool { + return wstatus(x) != wstopped and wstatus(x) != 0; +} + +/// Operation not permitted +pub const EPERM = 1; + +/// No such file or directory +pub const ENOENT = 2; + +/// No such process +pub const ESRCH = 3; + +/// Interrupted system call +pub const EINTR = 4; + +/// Input/output error +pub const EIO = 5; + +/// Device not configured +pub const ENXIO = 6; + +/// Argument list too long +pub const E2BIG = 7; + +/// Exec format error +pub const ENOEXEC = 8; + +/// Bad file descriptor +pub const EBADF = 9; + +/// No child processes +pub const ECHILD = 10; + +/// Resource deadlock avoided +pub const EDEADLK = 11; + +/// Cannot allocate memory +pub const ENOMEM = 12; + +/// Permission denied +pub const EACCES = 13; + +/// Bad address +pub const EFAULT = 14; + +/// Block device required +pub const ENOTBLK = 15; + +/// Device / Resource busy +pub const EBUSY = 16; + +/// File exists +pub const EEXIST = 17; + +/// Cross-device link +pub const EXDEV = 18; + +/// Operation not supported by device +pub const ENODEV = 19; + +/// Not a directory +pub const ENOTDIR = 20; + +/// Is a directory +pub const EISDIR = 21; + +/// Invalid argument +pub const EINVAL = 22; + +/// Too many open files in system +pub const ENFILE = 23; + +/// Too many open files +pub const EMFILE = 24; + +/// Inappropriate ioctl for device +pub const ENOTTY = 25; + +/// Text file busy +pub const ETXTBSY = 26; + +/// File too large +pub const EFBIG = 27; + +/// No space left on device +pub const ENOSPC = 28; + +/// Illegal seek +pub const ESPIPE = 29; + +/// Read-only file system +pub const EROFS = 30; + +/// Too many links +pub const EMLINK = 31; +/// Broken pipe + +// math software +pub const EPIPE = 32; + +/// Numerical argument out of domain +pub const EDOM = 33; +/// Result too large + +// non-blocking and interrupt i/o +pub const ERANGE = 34; + +/// Resource temporarily unavailable +pub const EAGAIN = 35; + +/// Operation would block +pub const EWOULDBLOCK = EAGAIN; + +/// Operation now in progress +pub const EINPROGRESS = 36; +/// Operation already in progress + +// ipc/network software -- argument errors +pub const EALREADY = 37; + +/// Socket operation on non-socket +pub const ENOTSOCK = 38; + +/// Destination address required +pub const EDESTADDRREQ = 39; + +/// Message too long +pub const EMSGSIZE = 40; + +/// Protocol wrong type for socket +pub const EPROTOTYPE = 41; + +/// Protocol not available +pub const ENOPROTOOPT = 42; + +/// Protocol not supported +pub const EPROTONOSUPPORT = 43; + +/// Socket type not supported +pub const ESOCKTNOSUPPORT = 44; + +/// Operation not supported +pub const ENOTSUP = 45; + +/// Protocol family not supported +pub const EPFNOSUPPORT = 46; + +/// Address family not supported by protocol family +pub const EAFNOSUPPORT = 47; + +/// Address already in use +pub const EADDRINUSE = 48; +/// Can't assign requested address + +// ipc/network software -- operational errors +pub const EADDRNOTAVAIL = 49; + +/// Network is down +pub const ENETDOWN = 50; + +/// Network is unreachable +pub const ENETUNREACH = 51; + +/// Network dropped connection on reset +pub const ENETRESET = 52; + +/// Software caused connection abort +pub const ECONNABORTED = 53; + +/// Connection reset by peer +pub const ECONNRESET = 54; + +/// No buffer space available +pub const ENOBUFS = 55; + +/// Socket is already connected +pub const EISCONN = 56; + +/// Socket is not connected +pub const ENOTCONN = 57; + +/// Can't send after socket shutdown +pub const ESHUTDOWN = 58; + +/// Too many references: can't splice +pub const ETOOMANYREFS = 59; + +/// Operation timed out +pub const ETIMEDOUT = 60; + +/// Connection refused +pub const ECONNREFUSED = 61; + +/// Too many levels of symbolic links +pub const ELOOP = 62; + +/// File name too long +pub const ENAMETOOLONG = 63; + +/// Host is down +pub const EHOSTDOWN = 64; + +/// No route to host +pub const EHOSTUNREACH = 65; +/// Directory not empty + +// quotas & mush +pub const ENOTEMPTY = 66; + +/// Too many processes +pub const EPROCLIM = 67; + +/// Too many users +pub const EUSERS = 68; +/// Disc quota exceeded + +// Network File System +pub const EDQUOT = 69; + +/// Stale NFS file handle +pub const ESTALE = 70; + +/// Too many levels of remote in path +pub const EREMOTE = 71; + +/// RPC struct is bad +pub const EBADRPC = 72; + +/// RPC version wrong +pub const ERPCMISMATCH = 73; + +/// RPC prog. not avail +pub const EPROGUNAVAIL = 74; + +/// Program version wrong +pub const EPROGMISMATCH = 75; + +/// Bad procedure for program +pub const EPROCUNAVAIL = 76; + +/// No locks available +pub const ENOLCK = 77; + +/// Function not implemented +pub const ENOSYS = 78; + +/// Inappropriate file type or format +pub const EFTYPE = 79; + +/// Authentication error +pub const EAUTH = 80; +/// Need authenticator + +// Intelligent device errors +pub const ENEEDAUTH = 81; + +/// Device power is off +pub const EPWROFF = 82; + +/// Device error, e.g. paper out +pub const EDEVERR = 83; +/// Value too large to be stored in data type + +// Program loading errors +pub const EOVERFLOW = 84; + +/// Bad executable +pub const EBADEXEC = 85; + +/// Bad CPU type in executable +pub const EBADARCH = 86; + +/// Shared library version mismatch +pub const ESHLIBVERS = 87; + +/// Malformed Macho file +pub const EBADMACHO = 88; + +/// Operation canceled +pub const ECANCELED = 89; + +/// Identifier removed +pub const EIDRM = 90; + +/// No message of desired type +pub const ENOMSG = 91; + +/// Illegal byte sequence +pub const EILSEQ = 92; + +/// Attribute not found +pub const ENOATTR = 93; + +/// Bad message +pub const EBADMSG = 94; + +/// Reserved +pub const EMULTIHOP = 95; + +/// No message available on STREAM +pub const ENODATA = 96; + +/// Reserved +pub const ENOLINK = 97; + +/// No STREAM resources +pub const ENOSR = 98; + +/// Not a STREAM +pub const ENOSTR = 99; + +/// Protocol error +pub const EPROTO = 100; + +/// STREAM ioctl timeout +pub const ETIME = 101; + +/// No such policy registered +pub const ENOPOLICY = 103; + +/// State not recoverable +pub const ENOTRECOVERABLE = 104; + +/// Previous owner died +pub const EOWNERDEAD = 105; + +/// Interface output queue is full +pub const EQFULL = 106; + +/// Must be equal largest errno +pub const ELAST = 106; + +pub const SIGSTKSZ = 131072; +pub const MINSIGSTKSZ = 32768; + +pub const SS_ONSTACK = 1; +pub const SS_DISABLE = 4; + +pub const stack_t = extern struct { + ss_sp: [*]u8, + ss_size: isize, + ss_flags: i32, +}; + +pub const S_IFMT = 0o170000; + +pub const S_IFIFO = 0o010000; +pub const S_IFCHR = 0o020000; +pub const S_IFDIR = 0o040000; +pub const S_IFBLK = 0o060000; +pub const S_IFREG = 0o100000; +pub const S_IFLNK = 0o120000; +pub const S_IFSOCK = 0o140000; +pub const S_IFWHT = 0o160000; + +pub const S_ISUID = 0o4000; +pub const S_ISGID = 0o2000; +pub const S_ISVTX = 0o1000; +pub const S_IRWXU = 0o700; +pub const S_IRUSR = 0o400; +pub const S_IWUSR = 0o200; +pub const S_IXUSR = 0o100; +pub const S_IRWXG = 0o070; +pub const S_IRGRP = 0o040; +pub const S_IWGRP = 0o020; +pub const S_IXGRP = 0o010; +pub const S_IRWXO = 0o007; +pub const S_IROTH = 0o004; +pub const S_IWOTH = 0o002; +pub const S_IXOTH = 0o001; + +pub fn S_ISFIFO(m: u32) bool { + return m & S_IFMT == S_IFIFO; +} + +pub fn S_ISCHR(m: u32) bool { + return m & S_IFMT == S_IFCHR; +} + +pub fn S_ISDIR(m: u32) bool { + return m & S_IFMT == S_IFDIR; +} + +pub fn S_ISBLK(m: u32) bool { + return m & S_IFMT == S_IFBLK; +} + +pub fn S_ISREG(m: u32) bool { + return m & S_IFMT == S_IFREG; +} + +pub fn S_ISLNK(m: u32) bool { + return m & S_IFMT == S_IFLNK; +} + +pub fn S_ISSOCK(m: u32) bool { + return m & S_IFMT == S_IFSOCK; +} + +pub fn S_IWHT(m: u32) bool { + return m & S_IFMT == S_IFWHT; +} +pub const HOST_NAME_MAX = 72; diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig new file mode 100644 index 0000000000..3d07e92e01 --- /dev/null +++ b/lib/std/os/bits/freebsd.zig @@ -0,0 +1,941 @@ +const std = @import("../../std.zig"); +const maxInt = std.math.maxInt; + +pub const fd_t = c_int; +pub const pid_t = c_int; + +/// Renamed from `kevent` to `Kevent` to avoid conflict with function name. +pub const Kevent = extern struct { + ident: usize, + filter: i16, + flags: u16, + fflags: u32, + data: i64, + udata: usize, + // TODO ext +}; + +pub const pthread_attr_t = extern struct { + __size: [56]u8, + __align: c_long, +}; + +pub const dl_phdr_info = extern struct { + dlpi_addr: usize, + dlpi_name: ?[*]const u8, + dlpi_phdr: [*]std.elf.Phdr, + dlpi_phnum: u16, +}; + +pub const msghdr = extern struct { + /// optional address + msg_name: ?*sockaddr, + + /// size of address + msg_namelen: socklen_t, + + /// scatter/gather array + msg_iov: [*]iovec, + + /// # elements in msg_iov + msg_iovlen: i32, + + /// ancillary data + msg_control: ?*c_void, + + /// ancillary data buffer len + msg_controllen: socklen_t, + + /// flags on received message + msg_flags: i32, +}; + +pub const msghdr_const = extern struct { + /// optional address + msg_name: ?*const sockaddr, + + /// size of address + msg_namelen: socklen_t, + + /// scatter/gather array + msg_iov: [*]iovec_const, + + /// # elements in msg_iov + msg_iovlen: i32, + + /// ancillary data + msg_control: ?*c_void, + + /// ancillary data buffer len + msg_controllen: socklen_t, + + /// flags on received message + msg_flags: i32, +}; + +pub const off_t = i64; + +/// Renamed to Stat to not conflict with the stat function. +/// atime, mtime, and ctime have functions to return `timespec`, +/// because although this is a POSIX API, the layout and names of +/// the structs are inconsistent across operating systems, and +/// in C, macros are used to hide the differences. Here we use +/// methods to accomplish this. +pub const Stat = extern struct { + dev: u64, + ino: u64, + nlink: usize, + + mode: u16, + __pad0: u16, + uid: u32, + gid: u32, + __pad1: u32, + rdev: u64, + + atim: timespec, + mtim: timespec, + ctim: timespec, + birthtim: timespec, + + size: off_t, + blocks: i64, + blksize: isize, + flags: u32, + gen: u64, + __spare: [10]u64, + + pub fn atime(self: Stat) timespec { + return self.atim; + } + + pub fn mtime(self: Stat) timespec { + return self.mtim; + } + + pub fn ctime(self: Stat) timespec { + return self.ctim; + } +}; + +pub const timespec = extern struct { + tv_sec: isize, + tv_nsec: isize, +}; + +pub const dirent = extern struct { + d_fileno: usize, + d_off: i64, + d_reclen: u16, + d_type: u8, + d_pad0: u8, + d_namlen: u16, + d_pad1: u16, + d_name: [256]u8, +}; + +pub const in_port_t = u16; +pub const sa_family_t = u16; + +pub const sockaddr = extern union { + in: sockaddr_in, + in6: sockaddr_in6, +}; + +pub const sockaddr_in = extern struct { + len: u8, + family: sa_family_t, + port: in_port_t, + addr: [16]u8, + zero: [8]u8, +}; + +pub const sockaddr_in6 = extern struct { + len: u8, + family: sa_family_t, + port: in_port_t, + flowinfo: u32, + addr: [16]u8, + scope_id: u32, +}; + +pub const CTL_KERN = 1; +pub const CTL_DEBUG = 5; + +pub const KERN_PROC = 14; // struct: process entries +pub const KERN_PROC_PATHNAME = 12; // path to executable + +pub const PATH_MAX = 1024; + +pub const STDIN_FILENO = 0; +pub const STDOUT_FILENO = 1; +pub const STDERR_FILENO = 2; + +pub const PROT_NONE = 0; +pub const PROT_READ = 1; +pub const PROT_WRITE = 2; +pub const PROT_EXEC = 4; + +pub const CLOCK_REALTIME = 0; +pub const CLOCK_VIRTUAL = 1; +pub const CLOCK_PROF = 2; +pub const CLOCK_MONOTONIC = 4; +pub const CLOCK_UPTIME = 5; +pub const CLOCK_UPTIME_PRECISE = 7; +pub const CLOCK_UPTIME_FAST = 8; +pub const CLOCK_REALTIME_PRECISE = 9; +pub const CLOCK_REALTIME_FAST = 10; +pub const CLOCK_MONOTONIC_PRECISE = 11; +pub const CLOCK_MONOTONIC_FAST = 12; +pub const CLOCK_SECOND = 13; +pub const CLOCK_THREAD_CPUTIME_ID = 14; +pub const CLOCK_PROCESS_CPUTIME_ID = 15; + +pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize)); +pub const MAP_SHARED = 0x0001; +pub const MAP_PRIVATE = 0x0002; +pub const MAP_FIXED = 0x0010; +pub const MAP_STACK = 0x0400; +pub const MAP_NOSYNC = 0x0800; +pub const MAP_ANON = 0x1000; +pub const MAP_ANONYMOUS = MAP_ANON; +pub const MAP_FILE = 0; +pub const MAP_NORESERVE = 0; + +pub const MAP_GUARD = 0x00002000; +pub const MAP_EXCL = 0x00004000; +pub const MAP_NOCORE = 0x00020000; +pub const MAP_PREFAULT_READ = 0x00040000; +pub const MAP_32BIT = 0x00080000; + +pub const WNOHANG = 1; +pub const WUNTRACED = 2; +pub const WSTOPPED = WUNTRACED; +pub const WCONTINUED = 4; +pub const WNOWAIT = 8; +pub const WEXITED = 16; +pub const WTRAPPED = 32; + +pub const SA_ONSTACK = 0x0001; +pub const SA_RESTART = 0x0002; +pub const SA_RESETHAND = 0x0004; +pub const SA_NOCLDSTOP = 0x0008; +pub const SA_NODEFER = 0x0010; +pub const SA_NOCLDWAIT = 0x0020; +pub const SA_SIGINFO = 0x0040; + +pub const SIGHUP = 1; +pub const SIGINT = 2; +pub const SIGQUIT = 3; +pub const SIGILL = 4; +pub const SIGTRAP = 5; +pub const SIGABRT = 6; +pub const SIGIOT = SIGABRT; +pub const SIGEMT = 7; +pub const SIGFPE = 8; +pub const SIGKILL = 9; +pub const SIGBUS = 10; +pub const SIGSEGV = 11; +pub const SIGSYS = 12; +pub const SIGPIPE = 13; +pub const SIGALRM = 14; +pub const SIGTERM = 15; +pub const SIGURG = 16; +pub const SIGSTOP = 17; +pub const SIGTSTP = 18; +pub const SIGCONT = 19; +pub const SIGCHLD = 20; +pub const SIGTTIN = 21; +pub const SIGTTOU = 22; +pub const SIGIO = 23; +pub const SIGXCPU = 24; +pub const SIGXFSZ = 25; +pub const SIGVTALRM = 26; +pub const SIGPROF = 27; +pub const SIGWINCH = 28; +pub const SIGINFO = 29; +pub const SIGUSR1 = 30; +pub const SIGUSR2 = 31; +pub const SIGTHR = 32; +pub const SIGLWP = SIGTHR; +pub const SIGLIBRT = 33; + +pub const SIGRTMIN = 65; +pub const SIGRTMAX = 126; + +// access function +pub const F_OK = 0; // test for existence of file +pub const X_OK = 1; // test for execute or search permission +pub const W_OK = 2; // test for write permission +pub const R_OK = 4; // test for read permission + +pub const O_RDONLY = 0x0000; +pub const O_WRONLY = 0x0001; +pub const O_RDWR = 0x0002; +pub const O_ACCMODE = 0x0003; + +pub const O_CREAT = 0x0200; +pub const O_EXCL = 0x0800; +pub const O_NOCTTY = 0x8000; +pub const O_TRUNC = 0x0400; +pub const O_APPEND = 0x0008; +pub const O_NONBLOCK = 0x0004; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0x0080; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o200000; +pub const O_NOFOLLOW = 0x0100; +pub const O_CLOEXEC = 0x00100000; + +pub const O_ASYNC = 0x0040; +pub const O_DIRECT = 0x00010000; +pub const O_LARGEFILE = 0; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20200000; +pub const O_NDELAY = O_NONBLOCK; + +pub const F_DUPFD = 0; +pub const F_GETFD = 1; +pub const F_SETFD = 2; +pub const F_GETFL = 3; +pub const F_SETFL = 4; + +pub const F_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_GETLK = 5; +pub const F_SETLK = 6; +pub const F_SETLKW = 7; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; + +pub const SEEK_SET = 0; +pub const SEEK_CUR = 1; +pub const SEEK_END = 2; + +pub const SIG_BLOCK = 1; +pub const SIG_UNBLOCK = 2; +pub const SIG_SETMASK = 3; + +pub const SOCK_STREAM = 1; +pub const SOCK_DGRAM = 2; +pub const SOCK_RAW = 3; +pub const SOCK_RDM = 4; +pub const SOCK_SEQPACKET = 5; + +pub const SOCK_CLOEXEC = 0x10000000; +pub const SOCK_NONBLOCK = 0x20000000; + +pub const PROTO_ip = 0o000; +pub const PROTO_icmp = 0o001; +pub const PROTO_igmp = 0o002; +pub const PROTO_ggp = 0o003; +pub const PROTO_ipencap = 0o004; +pub const PROTO_st = 0o005; +pub const PROTO_tcp = 0o006; +pub const PROTO_egp = 0o010; +pub const PROTO_pup = 0o014; +pub const PROTO_udp = 0o021; +pub const PROTO_hmp = 0o024; +pub const PROTO_xns_idp = 0o026; +pub const PROTO_rdp = 0o033; +pub const PROTO_iso_tp4 = 0o035; +pub const PROTO_xtp = 0o044; +pub const PROTO_ddp = 0o045; +pub const PROTO_idpr_cmtp = 0o046; +pub const PROTO_ipv6 = 0o051; +pub const PROTO_ipv6_route = 0o053; +pub const PROTO_ipv6_frag = 0o054; +pub const PROTO_idrp = 0o055; +pub const PROTO_rsvp = 0o056; +pub const PROTO_gre = 0o057; +pub const PROTO_esp = 0o062; +pub const PROTO_ah = 0o063; +pub const PROTO_skip = 0o071; +pub const PROTO_ipv6_icmp = 0o072; +pub const PROTO_ipv6_nonxt = 0o073; +pub const PROTO_ipv6_opts = 0o074; +pub const PROTO_rspf = 0o111; +pub const PROTO_vmtp = 0o121; +pub const PROTO_ospf = 0o131; +pub const PROTO_ipip = 0o136; +pub const PROTO_encap = 0o142; +pub const PROTO_pim = 0o147; +pub const PROTO_raw = 0o377; + +pub const PF_UNSPEC = 0; +pub const PF_LOCAL = 1; +pub const PF_UNIX = PF_LOCAL; +pub const PF_FILE = PF_LOCAL; +pub const PF_INET = 2; +pub const PF_AX25 = 3; +pub const PF_IPX = 4; +pub const PF_APPLETALK = 5; +pub const PF_NETROM = 6; +pub const PF_BRIDGE = 7; +pub const PF_ATMPVC = 8; +pub const PF_X25 = 9; +pub const PF_INET6 = 10; +pub const PF_ROSE = 11; +pub const PF_DECnet = 12; +pub const PF_NETBEUI = 13; +pub const PF_SECURITY = 14; +pub const PF_KEY = 15; +pub const PF_NETLINK = 16; +pub const PF_ROUTE = PF_NETLINK; +pub const PF_PACKET = 17; +pub const PF_ASH = 18; +pub const PF_ECONET = 19; +pub const PF_ATMSVC = 20; +pub const PF_RDS = 21; +pub const PF_SNA = 22; +pub const PF_IRDA = 23; +pub const PF_PPPOX = 24; +pub const PF_WANPIPE = 25; +pub const PF_LLC = 26; +pub const PF_IB = 27; +pub const PF_MPLS = 28; +pub const PF_CAN = 29; +pub const PF_TIPC = 30; +pub const PF_BLUETOOTH = 31; +pub const PF_IUCV = 32; +pub const PF_RXRPC = 33; +pub const PF_ISDN = 34; +pub const PF_PHONET = 35; +pub const PF_IEEE802154 = 36; +pub const PF_CAIF = 37; +pub const PF_ALG = 38; +pub const PF_NFC = 39; +pub const PF_VSOCK = 40; +pub const PF_MAX = 41; + +pub const AF_UNSPEC = PF_UNSPEC; +pub const AF_LOCAL = PF_LOCAL; +pub const AF_UNIX = AF_LOCAL; +pub const AF_FILE = AF_LOCAL; +pub const AF_INET = PF_INET; +pub const AF_AX25 = PF_AX25; +pub const AF_IPX = PF_IPX; +pub const AF_APPLETALK = PF_APPLETALK; +pub const AF_NETROM = PF_NETROM; +pub const AF_BRIDGE = PF_BRIDGE; +pub const AF_ATMPVC = PF_ATMPVC; +pub const AF_X25 = PF_X25; +pub const AF_INET6 = PF_INET6; +pub const AF_ROSE = PF_ROSE; +pub const AF_DECnet = PF_DECnet; +pub const AF_NETBEUI = PF_NETBEUI; +pub const AF_SECURITY = PF_SECURITY; +pub const AF_KEY = PF_KEY; +pub const AF_NETLINK = PF_NETLINK; +pub const AF_ROUTE = PF_ROUTE; +pub const AF_PACKET = PF_PACKET; +pub const AF_ASH = PF_ASH; +pub const AF_ECONET = PF_ECONET; +pub const AF_ATMSVC = PF_ATMSVC; +pub const AF_RDS = PF_RDS; +pub const AF_SNA = PF_SNA; +pub const AF_IRDA = PF_IRDA; +pub const AF_PPPOX = PF_PPPOX; +pub const AF_WANPIPE = PF_WANPIPE; +pub const AF_LLC = PF_LLC; +pub const AF_IB = PF_IB; +pub const AF_MPLS = PF_MPLS; +pub const AF_CAN = PF_CAN; +pub const AF_TIPC = PF_TIPC; +pub const AF_BLUETOOTH = PF_BLUETOOTH; +pub const AF_IUCV = PF_IUCV; +pub const AF_RXRPC = PF_RXRPC; +pub const AF_ISDN = PF_ISDN; +pub const AF_PHONET = PF_PHONET; +pub const AF_IEEE802154 = PF_IEEE802154; +pub const AF_CAIF = PF_CAIF; +pub const AF_ALG = PF_ALG; +pub const AF_NFC = PF_NFC; +pub const AF_VSOCK = PF_VSOCK; +pub const AF_MAX = PF_MAX; + +pub const DT_UNKNOWN = 0; +pub const DT_FIFO = 1; +pub const DT_CHR = 2; +pub const DT_DIR = 4; +pub const DT_BLK = 6; +pub const DT_REG = 8; +pub const DT_LNK = 10; +pub const DT_SOCK = 12; +pub const DT_WHT = 14; + +/// add event to kq (implies enable) +pub const EV_ADD = 0x0001; + +/// delete event from kq +pub const EV_DELETE = 0x0002; + +/// enable event +pub const EV_ENABLE = 0x0004; + +/// disable event (not reported) +pub const EV_DISABLE = 0x0008; + +/// only report one occurrence +pub const EV_ONESHOT = 0x0010; + +/// clear event state after reporting +pub const EV_CLEAR = 0x0020; + +/// force immediate event output +/// ... with or without EV_ERROR +/// ... use KEVENT_FLAG_ERROR_EVENTS +/// on syscalls supporting flags +pub const EV_RECEIPT = 0x0040; + +/// disable event after reporting +pub const EV_DISPATCH = 0x0080; + +pub const EVFILT_READ = -1; +pub const EVFILT_WRITE = -2; + +/// attached to aio requests +pub const EVFILT_AIO = -3; + +/// attached to vnodes +pub const EVFILT_VNODE = -4; + +/// attached to struct proc +pub const EVFILT_PROC = -5; + +/// attached to struct proc +pub const EVFILT_SIGNAL = -6; + +/// timers +pub const EVFILT_TIMER = -7; + +/// Process descriptors +pub const EVFILT_PROCDESC = -8; + +/// Filesystem events +pub const EVFILT_FS = -9; + +pub const EVFILT_LIO = -10; + +/// User events +pub const EVFILT_USER = -11; + +/// Sendfile events +pub const EVFILT_SENDFILE = -12; + +pub const EVFILT_EMPTY = -13; + +/// On input, NOTE_TRIGGER causes the event to be triggered for output. +pub const NOTE_TRIGGER = 0x01000000; + +/// ignore input fflags +pub const NOTE_FFNOP = 0x00000000; + +/// and fflags +pub const NOTE_FFAND = 0x40000000; + +/// or fflags +pub const NOTE_FFOR = 0x80000000; + +/// copy fflags +pub const NOTE_FFCOPY = 0xc0000000; + +/// mask for operations +pub const NOTE_FFCTRLMASK = 0xc0000000; +pub const NOTE_FFLAGSMASK = 0x00ffffff; + +/// low water mark +pub const NOTE_LOWAT = 0x00000001; + +/// behave like poll() +pub const NOTE_FILE_POLL = 0x00000002; + +/// vnode was removed +pub const NOTE_DELETE = 0x00000001; + +/// data contents changed +pub const NOTE_WRITE = 0x00000002; + +/// size increased +pub const NOTE_EXTEND = 0x00000004; + +/// attributes changed +pub const NOTE_ATTRIB = 0x00000008; + +/// link count changed +pub const NOTE_LINK = 0x00000010; + +/// vnode was renamed +pub const NOTE_RENAME = 0x00000020; + +/// vnode access was revoked +pub const NOTE_REVOKE = 0x00000040; + +/// vnode was opened +pub const NOTE_OPEN = 0x00000080; + +/// file closed, fd did not allow write +pub const NOTE_CLOSE = 0x00000100; + +/// file closed, fd did allow write +pub const NOTE_CLOSE_WRITE = 0x00000200; + +/// file was read +pub const NOTE_READ = 0x00000400; + +/// process exited +pub const NOTE_EXIT = 0x80000000; + +/// process forked +pub const NOTE_FORK = 0x40000000; + +/// process exec'd +pub const NOTE_EXEC = 0x20000000; + +/// mask for signal & exit status +pub const NOTE_PDATAMASK = 0x000fffff; +pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK); + +/// data is seconds +pub const NOTE_SECONDS = 0x00000001; + +/// data is milliseconds +pub const NOTE_MSECONDS = 0x00000002; + +/// data is microseconds +pub const NOTE_USECONDS = 0x00000004; + +/// data is nanoseconds +pub const NOTE_NSECONDS = 0x00000008; + +/// timeout is absolute +pub const NOTE_ABSTIME = 0x00000010; + +pub const TCGETS = 0x5401; +pub const TCSETS = 0x5402; +pub const TCSETSW = 0x5403; +pub const TCSETSF = 0x5404; +pub const TCGETA = 0x5405; +pub const TCSETA = 0x5406; +pub const TCSETAW = 0x5407; +pub const TCSETAF = 0x5408; +pub const TCSBRK = 0x5409; +pub const TCXONC = 0x540A; +pub const TCFLSH = 0x540B; +pub const TIOCEXCL = 0x540C; +pub const TIOCNXCL = 0x540D; +pub const TIOCSCTTY = 0x540E; +pub const TIOCGPGRP = 0x540F; +pub const TIOCSPGRP = 0x5410; +pub const TIOCOUTQ = 0x5411; +pub const TIOCSTI = 0x5412; +pub const TIOCGWINSZ = 0x5413; +pub const TIOCSWINSZ = 0x5414; +pub const TIOCMGET = 0x5415; +pub const TIOCMBIS = 0x5416; +pub const TIOCMBIC = 0x5417; +pub const TIOCMSET = 0x5418; +pub const TIOCGSOFTCAR = 0x5419; +pub const TIOCSSOFTCAR = 0x541A; +pub const FIONREAD = 0x541B; +pub const TIOCINQ = FIONREAD; +pub const TIOCLINUX = 0x541C; +pub const TIOCCONS = 0x541D; +pub const TIOCGSERIAL = 0x541E; +pub const TIOCSSERIAL = 0x541F; +pub const TIOCPKT = 0x5420; +pub const FIONBIO = 0x5421; +pub const TIOCNOTTY = 0x5422; +pub const TIOCSETD = 0x5423; +pub const TIOCGETD = 0x5424; +pub const TCSBRKP = 0x5425; +pub const TIOCSBRK = 0x5427; +pub const TIOCCBRK = 0x5428; +pub const TIOCGSID = 0x5429; +pub const TIOCGRS485 = 0x542E; +pub const TIOCSRS485 = 0x542F; +pub const TIOCGPTN = 0x80045430; +pub const TIOCSPTLCK = 0x40045431; +pub const TIOCGDEV = 0x80045432; +pub const TCGETX = 0x5432; +pub const TCSETX = 0x5433; +pub const TCSETXF = 0x5434; +pub const TCSETXW = 0x5435; +pub const TIOCSIG = 0x40045436; +pub const TIOCVHANGUP = 0x5437; +pub const TIOCGPKT = 0x80045438; +pub const TIOCGPTLCK = 0x80045439; +pub const TIOCGEXCL = 0x80045440; + +pub fn WEXITSTATUS(s: u32) u32 { + return (s & 0xff00) >> 8; +} +pub fn WTERMSIG(s: u32) u32 { + return s & 0x7f; +} +pub fn WSTOPSIG(s: u32) u32 { + return WEXITSTATUS(s); +} +pub fn WIFEXITED(s: u32) bool { + return WTERMSIG(s) == 0; +} +pub fn WIFSTOPPED(s: u32) bool { + return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00; +} +pub fn WIFSIGNALED(s: u32) bool { + return (s & 0xffff) -% 1 < 0xff; +} + +pub const winsize = extern struct { + ws_row: u16, + ws_col: u16, + ws_xpixel: u16, + ws_ypixel: u16, +}; + +const NSIG = 32; + +pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); +pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); +pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); + +/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. +pub const Sigaction = extern struct { + /// signal handler + __sigaction_u: extern union { + __sa_handler: extern fn (i32) void, + __sa_sigaction: extern fn (i32, *__siginfo, usize) void, + }, + + /// see signal options + sa_flags: u32, + + /// signal mask to apply + sa_mask: sigset_t, +}; + +pub const _SIG_WORDS = 4; +pub const _SIG_MAXSIG = 128; + +pub inline fn _SIG_IDX(sig: usize) usize { + return sig - 1; +} +pub inline fn _SIG_WORD(sig: usize) usize { + return_SIG_IDX(sig) >> 5; +} +pub inline fn _SIG_BIT(sig: usize) usize { + return 1 << (_SIG_IDX(sig) & 31); +} +pub inline fn _SIG_VALID(sig: usize) usize { + return sig <= _SIG_MAXSIG and sig > 0; +} + +pub const sigset_t = extern struct { + __bits: [_SIG_WORDS]u32, +}; + +pub const EPERM = 1; // Operation not permitted +pub const ENOENT = 2; // No such file or directory +pub const ESRCH = 3; // No such process +pub const EINTR = 4; // Interrupted system call +pub const EIO = 5; // Input/output error +pub const ENXIO = 6; // Device not configured +pub const E2BIG = 7; // Argument list too long +pub const ENOEXEC = 8; // Exec format error +pub const EBADF = 9; // Bad file descriptor +pub const ECHILD = 10; // No child processes +pub const EDEADLK = 11; // Resource deadlock avoided +// 11 was EAGAIN +pub const ENOMEM = 12; // Cannot allocate memory +pub const EACCES = 13; // Permission denied +pub const EFAULT = 14; // Bad address +pub const ENOTBLK = 15; // Block device required +pub const EBUSY = 16; // Device busy +pub const EEXIST = 17; // File exists +pub const EXDEV = 18; // Cross-device link +pub const ENODEV = 19; // Operation not supported by device +pub const ENOTDIR = 20; // Not a directory +pub const EISDIR = 21; // Is a directory +pub const EINVAL = 22; // Invalid argument +pub const ENFILE = 23; // Too many open files in system +pub const EMFILE = 24; // Too many open files +pub const ENOTTY = 25; // Inappropriate ioctl for device +pub const ETXTBSY = 26; // Text file busy +pub const EFBIG = 27; // File too large +pub const ENOSPC = 28; // No space left on device +pub const ESPIPE = 29; // Illegal seek +pub const EROFS = 30; // Read-only filesystem +pub const EMLINK = 31; // Too many links +pub const EPIPE = 32; // Broken pipe + +// math software +pub const EDOM = 33; // Numerical argument out of domain +pub const ERANGE = 34; // Result too large + +// non-blocking and interrupt i/o +pub const EAGAIN = 35; // Resource temporarily unavailable +pub const EWOULDBLOCK = EAGAIN; // Operation would block +pub const EINPROGRESS = 36; // Operation now in progress +pub const EALREADY = 37; // Operation already in progress + +// ipc/network software -- argument errors +pub const ENOTSOCK = 38; // Socket operation on non-socket +pub const EDESTADDRREQ = 39; // Destination address required +pub const EMSGSIZE = 40; // Message too long +pub const EPROTOTYPE = 41; // Protocol wrong type for socket +pub const ENOPROTOOPT = 42; // Protocol not available +pub const EPROTONOSUPPORT = 43; // Protocol not supported +pub const ESOCKTNOSUPPORT = 44; // Socket type not supported +pub const EOPNOTSUPP = 45; // Operation not supported +pub const ENOTSUP = EOPNOTSUPP; // Operation not supported +pub const EPFNOSUPPORT = 46; // Protocol family not supported +pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family +pub const EADDRINUSE = 48; // Address already in use +pub const EADDRNOTAVAIL = 49; // Can't assign requested address + +// ipc/network software -- operational errors +pub const ENETDOWN = 50; // Network is down +pub const ENETUNREACH = 51; // Network is unreachable +pub const ENETRESET = 52; // Network dropped connection on reset +pub const ECONNABORTED = 53; // Software caused connection abort +pub const ECONNRESET = 54; // Connection reset by peer +pub const ENOBUFS = 55; // No buffer space available +pub const EISCONN = 56; // Socket is already connected +pub const ENOTCONN = 57; // Socket is not connected +pub const ESHUTDOWN = 58; // Can't send after socket shutdown +pub const ETOOMANYREFS = 59; // Too many references: can't splice +pub const ETIMEDOUT = 60; // Operation timed out +pub const ECONNREFUSED = 61; // Connection refused + +pub const ELOOP = 62; // Too many levels of symbolic links +pub const ENAMETOOLONG = 63; // File name too long + +// should be rearranged +pub const EHOSTDOWN = 64; // Host is down +pub const EHOSTUNREACH = 65; // No route to host +pub const ENOTEMPTY = 66; // Directory not empty + +// quotas & mush +pub const EPROCLIM = 67; // Too many processes +pub const EUSERS = 68; // Too many users +pub const EDQUOT = 69; // Disc quota exceeded + +// Network File System +pub const ESTALE = 70; // Stale NFS file handle +pub const EREMOTE = 71; // Too many levels of remote in path +pub const EBADRPC = 72; // RPC struct is bad +pub const ERPCMISMATCH = 73; // RPC version wrong +pub const EPROGUNAVAIL = 74; // RPC prog. not avail +pub const EPROGMISMATCH = 75; // Program version wrong +pub const EPROCUNAVAIL = 76; // Bad procedure for program + +pub const ENOLCK = 77; // No locks available +pub const ENOSYS = 78; // Function not implemented + +pub const EFTYPE = 79; // Inappropriate file type or format +pub const EAUTH = 80; // Authentication error +pub const ENEEDAUTH = 81; // Need authenticator +pub const EIDRM = 82; // Identifier removed +pub const ENOMSG = 83; // No message of desired type +pub const EOVERFLOW = 84; // Value too large to be stored in data type +pub const ECANCELED = 85; // Operation canceled +pub const EILSEQ = 86; // Illegal byte sequence +pub const ENOATTR = 87; // Attribute not found + +pub const EDOOFUS = 88; // Programming error + +pub const EBADMSG = 89; // Bad message +pub const EMULTIHOP = 90; // Multihop attempted +pub const ENOLINK = 91; // Link has been severed +pub const EPROTO = 92; // Protocol error + +pub const ENOTCAPABLE = 93; // Capabilities insufficient +pub const ECAPMODE = 94; // Not permitted in capability mode +pub const ENOTRECOVERABLE = 95; // State not recoverable +pub const EOWNERDEAD = 96; // Previous owner died + +pub const ELAST = 96; // Must be equal largest errno + +pub const MINSIGSTKSZ = switch (builtin.arch) { + .i386, .x86_64 => 2048, + .arm, .aarch64 => 4096, + else => @compileError("MINSIGSTKSZ not defined for this architecture"), +}; +pub const SIGSTKSZ = MINSIGSTKSZ + 32768; + +pub const SS_ONSTACK = 1; +pub const SS_DISABLE = 4; + +pub const stack_t = extern struct { + ss_sp: [*]u8, + ss_size: isize, + ss_flags: i32, +}; + +pub const S_IFMT = 0o170000; + +pub const S_IFIFO = 0o010000; +pub const S_IFCHR = 0o020000; +pub const S_IFDIR = 0o040000; +pub const S_IFBLK = 0o060000; +pub const S_IFREG = 0o100000; +pub const S_IFLNK = 0o120000; +pub const S_IFSOCK = 0o140000; +pub const S_IFWHT = 0o160000; + +pub const S_ISUID = 0o4000; +pub const S_ISGID = 0o2000; +pub const S_ISVTX = 0o1000; +pub const S_IRWXU = 0o700; +pub const S_IRUSR = 0o400; +pub const S_IWUSR = 0o200; +pub const S_IXUSR = 0o100; +pub const S_IRWXG = 0o070; +pub const S_IRGRP = 0o040; +pub const S_IWGRP = 0o020; +pub const S_IXGRP = 0o010; +pub const S_IRWXO = 0o007; +pub const S_IROTH = 0o004; +pub const S_IWOTH = 0o002; +pub const S_IXOTH = 0o001; + +pub fn S_ISFIFO(m: u32) bool { + return m & S_IFMT == S_IFIFO; +} + +pub fn S_ISCHR(m: u32) bool { + return m & S_IFMT == S_IFCHR; +} + +pub fn S_ISDIR(m: u32) bool { + return m & S_IFMT == S_IFDIR; +} + +pub fn S_ISBLK(m: u32) bool { + return m & S_IFMT == S_IFBLK; +} + +pub fn S_ISREG(m: u32) bool { + return m & S_IFMT == S_IFREG; +} + +pub fn S_ISLNK(m: u32) bool { + return m & S_IFMT == S_IFLNK; +} + +pub fn S_ISSOCK(m: u32) bool { + return m & S_IFMT == S_IFSOCK; +} + +pub fn S_IWHT(m: u32) bool { + return m & S_IFMT == S_IFWHT; +} + +pub const HOST_NAME_MAX = 255; diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig new file mode 100644 index 0000000000..939d203e8d --- /dev/null +++ b/lib/std/os/bits/linux.zig @@ -0,0 +1,1187 @@ +const builtin = @import("builtin"); +const std = @import("../../std.zig"); +const maxInt = std.math.maxInt; +usingnamespace @import("../bits.zig"); + +pub usingnamespace @import("linux/errno.zig"); +pub usingnamespace switch (builtin.arch) { + .x86_64 => @import("linux/x86_64.zig"), + .aarch64 => @import("linux/arm64.zig"), + .arm => @import("linux/arm-eabi.zig"), + .riscv64 => @import("linux/riscv64.zig"), + else => struct {}, +}; + +pub const pid_t = i32; +pub const fd_t = i32; +pub const uid_t = i32; +pub const gid_t = u32; +pub const clock_t = isize; + +pub const PATH_MAX = 4096; +pub const IOV_MAX = 1024; + +pub const STDIN_FILENO = 0; +pub const STDOUT_FILENO = 1; +pub const STDERR_FILENO = 2; + +/// Special value used to indicate openat should use the current working directory +pub const AT_FDCWD = -100; + +/// Do not follow symbolic links +pub const AT_SYMLINK_NOFOLLOW = 0x100; + +/// Remove directory instead of unlinking file +pub const AT_REMOVEDIR = 0x200; + +/// Follow symbolic links. +pub const AT_SYMLINK_FOLLOW = 0x400; + +/// Suppress terminal automount traversal +pub const AT_NO_AUTOMOUNT = 0x800; + +/// Allow empty relative pathname +pub const AT_EMPTY_PATH = 0x1000; + +/// Type of synchronisation required from statx() +pub const AT_STATX_SYNC_TYPE = 0x6000; + +/// - Do whatever stat() does +pub const AT_STATX_SYNC_AS_STAT = 0x0000; + +/// - Force the attributes to be sync'd with the server +pub const AT_STATX_FORCE_SYNC = 0x2000; + +/// - Don't sync attributes with the server +pub const AT_STATX_DONT_SYNC = 0x4000; + +/// Apply to the entire subtree +pub const AT_RECURSIVE = 0x8000; + +pub const FUTEX_WAIT = 0; +pub const FUTEX_WAKE = 1; +pub const FUTEX_FD = 2; +pub const FUTEX_REQUEUE = 3; +pub const FUTEX_CMP_REQUEUE = 4; +pub const FUTEX_WAKE_OP = 5; +pub const FUTEX_LOCK_PI = 6; +pub const FUTEX_UNLOCK_PI = 7; +pub const FUTEX_TRYLOCK_PI = 8; +pub const FUTEX_WAIT_BITSET = 9; + +pub const FUTEX_PRIVATE_FLAG = 128; + +pub const FUTEX_CLOCK_REALTIME = 256; + +pub const PROT_NONE = 0; +pub const PROT_READ = 1; +pub const PROT_WRITE = 2; +pub const PROT_EXEC = 4; +pub const PROT_GROWSDOWN = 0x01000000; +pub const PROT_GROWSUP = 0x02000000; + +/// Share changes +pub const MAP_SHARED = 0x01; + +/// Changes are private +pub const MAP_PRIVATE = 0x02; + +/// share + validate extension flags +pub const MAP_SHARED_VALIDATE = 0x03; + +/// Mask for type of mapping +pub const MAP_TYPE = 0x0f; + +/// Interpret addr exactly +pub const MAP_FIXED = 0x10; + +/// don't use a file +pub const MAP_ANONYMOUS = 0x20; + +// MAP_ 0x0100 - 0x4000 flags are per architecture + +/// populate (prefault) pagetables +pub const MAP_POPULATE = 0x8000; + +/// do not block on IO +pub const MAP_NONBLOCK = 0x10000; + +/// give out an address that is best suited for process/thread stacks +pub const MAP_STACK = 0x20000; + +/// create a huge page mapping +pub const MAP_HUGETLB = 0x40000; + +/// perform synchronous page faults for the mapping +pub const MAP_SYNC = 0x80000; + +/// MAP_FIXED which doesn't unmap underlying mapping +pub const MAP_FIXED_NOREPLACE = 0x100000; + +/// For anonymous mmap, memory could be uninitialized +pub const MAP_UNINITIALIZED = 0x4000000; + +pub const F_OK = 0; +pub const X_OK = 1; +pub const W_OK = 2; +pub const R_OK = 4; + +pub const WNOHANG = 1; +pub const WUNTRACED = 2; +pub const WSTOPPED = 2; +pub const WEXITED = 4; +pub const WCONTINUED = 8; +pub const WNOWAIT = 0x1000000; + +pub const SA_NOCLDSTOP = 1; +pub const SA_NOCLDWAIT = 2; +pub const SA_SIGINFO = 4; +pub const SA_ONSTACK = 0x08000000; +pub const SA_RESTART = 0x10000000; +pub const SA_NODEFER = 0x40000000; +pub const SA_RESETHAND = 0x80000000; +pub const SA_RESTORER = 0x04000000; + +pub const SIGHUP = 1; +pub const SIGINT = 2; +pub const SIGQUIT = 3; +pub const SIGILL = 4; +pub const SIGTRAP = 5; +pub const SIGABRT = 6; +pub const SIGIOT = SIGABRT; +pub const SIGBUS = 7; +pub const SIGFPE = 8; +pub const SIGKILL = 9; +pub const SIGUSR1 = 10; +pub const SIGSEGV = 11; +pub const SIGUSR2 = 12; +pub const SIGPIPE = 13; +pub const SIGALRM = 14; +pub const SIGTERM = 15; +pub const SIGSTKFLT = 16; +pub const SIGCHLD = 17; +pub const SIGCONT = 18; +pub const SIGSTOP = 19; +pub const SIGTSTP = 20; +pub const SIGTTIN = 21; +pub const SIGTTOU = 22; +pub const SIGURG = 23; +pub const SIGXCPU = 24; +pub const SIGXFSZ = 25; +pub const SIGVTALRM = 26; +pub const SIGPROF = 27; +pub const SIGWINCH = 28; +pub const SIGIO = 29; +pub const SIGPOLL = 29; +pub const SIGPWR = 30; +pub const SIGSYS = 31; +pub const SIGUNUSED = SIGSYS; + +pub const O_RDONLY = 0o0; +pub const O_WRONLY = 0o1; +pub const O_RDWR = 0o2; + +pub const kernel_rwf = u32; + +/// high priority request, poll if possible +pub const RWF_HIPRI = kernel_rwf(0x00000001); + +/// per-IO O_DSYNC +pub const RWF_DSYNC = kernel_rwf(0x00000002); + +/// per-IO O_SYNC +pub const RWF_SYNC = kernel_rwf(0x00000004); + +/// per-IO, return -EAGAIN if operation would block +pub const RWF_NOWAIT = kernel_rwf(0x00000008); + +/// per-IO O_APPEND +pub const RWF_APPEND = kernel_rwf(0x00000010); + +pub const SEEK_SET = 0; +pub const SEEK_CUR = 1; +pub const SEEK_END = 2; + +pub const SIG_BLOCK = 0; +pub const SIG_UNBLOCK = 1; +pub const SIG_SETMASK = 2; + +pub const PROTO_ip = 0o000; +pub const PROTO_icmp = 0o001; +pub const PROTO_igmp = 0o002; +pub const PROTO_ggp = 0o003; +pub const PROTO_ipencap = 0o004; +pub const PROTO_st = 0o005; +pub const PROTO_tcp = 0o006; +pub const PROTO_egp = 0o010; +pub const PROTO_pup = 0o014; +pub const PROTO_udp = 0o021; +pub const PROTO_hmp = 0o024; +pub const PROTO_xns_idp = 0o026; +pub const PROTO_rdp = 0o033; +pub const PROTO_iso_tp4 = 0o035; +pub const PROTO_xtp = 0o044; +pub const PROTO_ddp = 0o045; +pub const PROTO_idpr_cmtp = 0o046; +pub const PROTO_ipv6 = 0o051; +pub const PROTO_ipv6_route = 0o053; +pub const PROTO_ipv6_frag = 0o054; +pub const PROTO_idrp = 0o055; +pub const PROTO_rsvp = 0o056; +pub const PROTO_gre = 0o057; +pub const PROTO_esp = 0o062; +pub const PROTO_ah = 0o063; +pub const PROTO_skip = 0o071; +pub const PROTO_ipv6_icmp = 0o072; +pub const PROTO_ipv6_nonxt = 0o073; +pub const PROTO_ipv6_opts = 0o074; +pub const PROTO_rspf = 0o111; +pub const PROTO_vmtp = 0o121; +pub const PROTO_ospf = 0o131; +pub const PROTO_ipip = 0o136; +pub const PROTO_encap = 0o142; +pub const PROTO_pim = 0o147; +pub const PROTO_raw = 0o377; + +pub const SHUT_RD = 0; +pub const SHUT_WR = 1; +pub const SHUT_RDWR = 2; + +pub const SOCK_STREAM = 1; +pub const SOCK_DGRAM = 2; +pub const SOCK_RAW = 3; +pub const SOCK_RDM = 4; +pub const SOCK_SEQPACKET = 5; +pub const SOCK_DCCP = 6; +pub const SOCK_PACKET = 10; +pub const SOCK_CLOEXEC = 0o2000000; +pub const SOCK_NONBLOCK = 0o4000; + +pub const PF_UNSPEC = 0; +pub const PF_LOCAL = 1; +pub const PF_UNIX = PF_LOCAL; +pub const PF_FILE = PF_LOCAL; +pub const PF_INET = 2; +pub const PF_AX25 = 3; +pub const PF_IPX = 4; +pub const PF_APPLETALK = 5; +pub const PF_NETROM = 6; +pub const PF_BRIDGE = 7; +pub const PF_ATMPVC = 8; +pub const PF_X25 = 9; +pub const PF_INET6 = 10; +pub const PF_ROSE = 11; +pub const PF_DECnet = 12; +pub const PF_NETBEUI = 13; +pub const PF_SECURITY = 14; +pub const PF_KEY = 15; +pub const PF_NETLINK = 16; +pub const PF_ROUTE = PF_NETLINK; +pub const PF_PACKET = 17; +pub const PF_ASH = 18; +pub const PF_ECONET = 19; +pub const PF_ATMSVC = 20; +pub const PF_RDS = 21; +pub const PF_SNA = 22; +pub const PF_IRDA = 23; +pub const PF_PPPOX = 24; +pub const PF_WANPIPE = 25; +pub const PF_LLC = 26; +pub const PF_IB = 27; +pub const PF_MPLS = 28; +pub const PF_CAN = 29; +pub const PF_TIPC = 30; +pub const PF_BLUETOOTH = 31; +pub const PF_IUCV = 32; +pub const PF_RXRPC = 33; +pub const PF_ISDN = 34; +pub const PF_PHONET = 35; +pub const PF_IEEE802154 = 36; +pub const PF_CAIF = 37; +pub const PF_ALG = 38; +pub const PF_NFC = 39; +pub const PF_VSOCK = 40; +pub const PF_KCM = 41; +pub const PF_QIPCRTR = 42; +pub const PF_SMC = 43; +pub const PF_MAX = 44; + +pub const AF_UNSPEC = PF_UNSPEC; +pub const AF_LOCAL = PF_LOCAL; +pub const AF_UNIX = AF_LOCAL; +pub const AF_FILE = AF_LOCAL; +pub const AF_INET = PF_INET; +pub const AF_AX25 = PF_AX25; +pub const AF_IPX = PF_IPX; +pub const AF_APPLETALK = PF_APPLETALK; +pub const AF_NETROM = PF_NETROM; +pub const AF_BRIDGE = PF_BRIDGE; +pub const AF_ATMPVC = PF_ATMPVC; +pub const AF_X25 = PF_X25; +pub const AF_INET6 = PF_INET6; +pub const AF_ROSE = PF_ROSE; +pub const AF_DECnet = PF_DECnet; +pub const AF_NETBEUI = PF_NETBEUI; +pub const AF_SECURITY = PF_SECURITY; +pub const AF_KEY = PF_KEY; +pub const AF_NETLINK = PF_NETLINK; +pub const AF_ROUTE = PF_ROUTE; +pub const AF_PACKET = PF_PACKET; +pub const AF_ASH = PF_ASH; +pub const AF_ECONET = PF_ECONET; +pub const AF_ATMSVC = PF_ATMSVC; +pub const AF_RDS = PF_RDS; +pub const AF_SNA = PF_SNA; +pub const AF_IRDA = PF_IRDA; +pub const AF_PPPOX = PF_PPPOX; +pub const AF_WANPIPE = PF_WANPIPE; +pub const AF_LLC = PF_LLC; +pub const AF_IB = PF_IB; +pub const AF_MPLS = PF_MPLS; +pub const AF_CAN = PF_CAN; +pub const AF_TIPC = PF_TIPC; +pub const AF_BLUETOOTH = PF_BLUETOOTH; +pub const AF_IUCV = PF_IUCV; +pub const AF_RXRPC = PF_RXRPC; +pub const AF_ISDN = PF_ISDN; +pub const AF_PHONET = PF_PHONET; +pub const AF_IEEE802154 = PF_IEEE802154; +pub const AF_CAIF = PF_CAIF; +pub const AF_ALG = PF_ALG; +pub const AF_NFC = PF_NFC; +pub const AF_VSOCK = PF_VSOCK; +pub const AF_KCM = PF_KCM; +pub const AF_QIPCRTR = PF_QIPCRTR; +pub const AF_SMC = PF_SMC; +pub const AF_MAX = PF_MAX; + +pub const SO_DEBUG = 1; +pub const SO_REUSEADDR = 2; +pub const SO_TYPE = 3; +pub const SO_ERROR = 4; +pub const SO_DONTROUTE = 5; +pub const SO_BROADCAST = 6; +pub const SO_SNDBUF = 7; +pub const SO_RCVBUF = 8; +pub const SO_KEEPALIVE = 9; +pub const SO_OOBINLINE = 10; +pub const SO_NO_CHECK = 11; +pub const SO_PRIORITY = 12; +pub const SO_LINGER = 13; +pub const SO_BSDCOMPAT = 14; +pub const SO_REUSEPORT = 15; +pub const SO_PASSCRED = 16; +pub const SO_PEERCRED = 17; +pub const SO_RCVLOWAT = 18; +pub const SO_SNDLOWAT = 19; +pub const SO_RCVTIMEO = 20; +pub const SO_SNDTIMEO = 21; +pub const SO_ACCEPTCONN = 30; +pub const SO_SNDBUFFORCE = 32; +pub const SO_RCVBUFFORCE = 33; +pub const SO_PROTOCOL = 38; +pub const SO_DOMAIN = 39; + +pub const SO_SECURITY_AUTHENTICATION = 22; +pub const SO_SECURITY_ENCRYPTION_TRANSPORT = 23; +pub const SO_SECURITY_ENCRYPTION_NETWORK = 24; + +pub const SO_BINDTODEVICE = 25; + +pub const SO_ATTACH_FILTER = 26; +pub const SO_DETACH_FILTER = 27; +pub const SO_GET_FILTER = SO_ATTACH_FILTER; + +pub const SO_PEERNAME = 28; +pub const SO_TIMESTAMP_OLD = 29; +pub const SO_PEERSEC = 31; +pub const SO_PASSSEC = 34; +pub const SO_TIMESTAMPNS_OLD = 35; +pub const SO_MARK = 36; +pub const SO_TIMESTAMPING_OLD = 37; +pub const SO_RXQ_OVFL = 40; +pub const SO_WIFI_STATUS = 41; +pub const SCM_WIFI_STATUS = SO_WIFI_STATUS; +pub const SO_PEEK_OFF = 42; +pub const SO_NOFCS = 43; +pub const SO_LOCK_FILTER = 44; +pub const SO_SELECT_ERR_QUEUE = 45; +pub const SO_BUSY_POLL = 46; +pub const SO_MAX_PACING_RATE = 47; +pub const SO_BPF_EXTENSIONS = 48; +pub const SO_INCOMING_CPU = 49; +pub const SO_ATTACH_BPF = 50; +pub const SO_DETACH_BPF = SO_DETACH_FILTER; +pub const SO_ATTACH_REUSEPORT_CBPF = 51; +pub const SO_ATTACH_REUSEPORT_EBPF = 52; +pub const SO_CNX_ADVICE = 53; +pub const SCM_TIMESTAMPING_OPT_STATS = 54; +pub const SO_MEMINFO = 55; +pub const SO_INCOMING_NAPI_ID = 56; +pub const SO_COOKIE = 57; +pub const SCM_TIMESTAMPING_PKTINFO = 58; +pub const SO_PEERGROUPS = 59; +pub const SO_ZEROCOPY = 60; +pub const SO_TXTIME = 61; +pub const SCM_TXTIME = SO_TXTIME; +pub const SO_BINDTOIFINDEX = 62; +pub const SO_TIMESTAMP_NEW = 63; +pub const SO_TIMESTAMPNS_NEW = 64; +pub const SO_TIMESTAMPING_NEW = 65; +pub const SO_RCVTIMEO_NEW = 66; +pub const SO_SNDTIMEO_NEW = 67; +pub const SO_DETACH_REUSEPORT_BPF = 68; + +pub const SOL_SOCKET = 1; + +pub const SOL_IP = 0; +pub const SOL_IPV6 = 41; +pub const SOL_ICMPV6 = 58; + +pub const SOL_RAW = 255; +pub const SOL_DECNET = 261; +pub const SOL_X25 = 262; +pub const SOL_PACKET = 263; +pub const SOL_ATM = 264; +pub const SOL_AAL = 265; +pub const SOL_IRDA = 266; +pub const SOL_NETBEUI = 267; +pub const SOL_LLC = 268; +pub const SOL_DCCP = 269; +pub const SOL_NETLINK = 270; +pub const SOL_TIPC = 271; +pub const SOL_RXRPC = 272; +pub const SOL_PPPOL2TP = 273; +pub const SOL_BLUETOOTH = 274; +pub const SOL_PNPIPE = 275; +pub const SOL_RDS = 276; +pub const SOL_IUCV = 277; +pub const SOL_CAIF = 278; +pub const SOL_ALG = 279; +pub const SOL_NFC = 280; +pub const SOL_KCM = 281; +pub const SOL_TLS = 282; + +pub const SOMAXCONN = 128; + +pub const MSG_OOB = 0x0001; +pub const MSG_PEEK = 0x0002; +pub const MSG_DONTROUTE = 0x0004; +pub const MSG_CTRUNC = 0x0008; +pub const MSG_PROXY = 0x0010; +pub const MSG_TRUNC = 0x0020; +pub const MSG_DONTWAIT = 0x0040; +pub const MSG_EOR = 0x0080; +pub const MSG_WAITALL = 0x0100; +pub const MSG_FIN = 0x0200; +pub const MSG_SYN = 0x0400; +pub const MSG_CONFIRM = 0x0800; +pub const MSG_RST = 0x1000; +pub const MSG_ERRQUEUE = 0x2000; +pub const MSG_NOSIGNAL = 0x4000; +pub const MSG_MORE = 0x8000; +pub const MSG_WAITFORONE = 0x10000; +pub const MSG_BATCH = 0x40000; +pub const MSG_ZEROCOPY = 0x4000000; +pub const MSG_FASTOPEN = 0x20000000; +pub const MSG_CMSG_CLOEXEC = 0x40000000; + +pub const DT_UNKNOWN = 0; +pub const DT_FIFO = 1; +pub const DT_CHR = 2; +pub const DT_DIR = 4; +pub const DT_BLK = 6; +pub const DT_REG = 8; +pub const DT_LNK = 10; +pub const DT_SOCK = 12; +pub const DT_WHT = 14; + +pub const TCGETS = 0x5401; +pub const TCSETS = 0x5402; +pub const TCSETSW = 0x5403; +pub const TCSETSF = 0x5404; +pub const TCGETA = 0x5405; +pub const TCSETA = 0x5406; +pub const TCSETAW = 0x5407; +pub const TCSETAF = 0x5408; +pub const TCSBRK = 0x5409; +pub const TCXONC = 0x540A; +pub const TCFLSH = 0x540B; +pub const TIOCEXCL = 0x540C; +pub const TIOCNXCL = 0x540D; +pub const TIOCSCTTY = 0x540E; +pub const TIOCGPGRP = 0x540F; +pub const TIOCSPGRP = 0x5410; +pub const TIOCOUTQ = 0x5411; +pub const TIOCSTI = 0x5412; +pub const TIOCGWINSZ = 0x5413; +pub const TIOCSWINSZ = 0x5414; +pub const TIOCMGET = 0x5415; +pub const TIOCMBIS = 0x5416; +pub const TIOCMBIC = 0x5417; +pub const TIOCMSET = 0x5418; +pub const TIOCGSOFTCAR = 0x5419; +pub const TIOCSSOFTCAR = 0x541A; +pub const FIONREAD = 0x541B; +pub const TIOCINQ = FIONREAD; +pub const TIOCLINUX = 0x541C; +pub const TIOCCONS = 0x541D; +pub const TIOCGSERIAL = 0x541E; +pub const TIOCSSERIAL = 0x541F; +pub const TIOCPKT = 0x5420; +pub const FIONBIO = 0x5421; +pub const TIOCNOTTY = 0x5422; +pub const TIOCSETD = 0x5423; +pub const TIOCGETD = 0x5424; +pub const TCSBRKP = 0x5425; +pub const TIOCSBRK = 0x5427; +pub const TIOCCBRK = 0x5428; +pub const TIOCGSID = 0x5429; +pub const TIOCGRS485 = 0x542E; +pub const TIOCSRS485 = 0x542F; +pub const TIOCGPTN = 0x80045430; +pub const TIOCSPTLCK = 0x40045431; +pub const TIOCGDEV = 0x80045432; +pub const TCGETX = 0x5432; +pub const TCSETX = 0x5433; +pub const TCSETXF = 0x5434; +pub const TCSETXW = 0x5435; +pub const TIOCSIG = 0x40045436; +pub const TIOCVHANGUP = 0x5437; +pub const TIOCGPKT = 0x80045438; +pub const TIOCGPTLCK = 0x80045439; +pub const TIOCGEXCL = 0x80045440; + +pub const EPOLL_CLOEXEC = O_CLOEXEC; + +pub const EPOLL_CTL_ADD = 1; +pub const EPOLL_CTL_DEL = 2; +pub const EPOLL_CTL_MOD = 3; + +pub const EPOLLIN = 0x001; +pub const EPOLLPRI = 0x002; +pub const EPOLLOUT = 0x004; +pub const EPOLLRDNORM = 0x040; +pub const EPOLLRDBAND = 0x080; +pub const EPOLLWRNORM = 0x100; +pub const EPOLLWRBAND = 0x200; +pub const EPOLLMSG = 0x400; +pub const EPOLLERR = 0x008; +pub const EPOLLHUP = 0x010; +pub const EPOLLRDHUP = 0x2000; +pub const EPOLLEXCLUSIVE = (u32(1) << 28); +pub const EPOLLWAKEUP = (u32(1) << 29); +pub const EPOLLONESHOT = (u32(1) << 30); +pub const EPOLLET = (u32(1) << 31); + +pub const CLOCK_REALTIME = 0; +pub const CLOCK_MONOTONIC = 1; +pub const CLOCK_PROCESS_CPUTIME_ID = 2; +pub const CLOCK_THREAD_CPUTIME_ID = 3; +pub const CLOCK_MONOTONIC_RAW = 4; +pub const CLOCK_REALTIME_COARSE = 5; +pub const CLOCK_MONOTONIC_COARSE = 6; +pub const CLOCK_BOOTTIME = 7; +pub const CLOCK_REALTIME_ALARM = 8; +pub const CLOCK_BOOTTIME_ALARM = 9; +pub const CLOCK_SGI_CYCLE = 10; +pub const CLOCK_TAI = 11; + +pub const CSIGNAL = 0x000000ff; +pub const CLONE_VM = 0x00000100; +pub const CLONE_FS = 0x00000200; +pub const CLONE_FILES = 0x00000400; +pub const CLONE_SIGHAND = 0x00000800; +pub const CLONE_PTRACE = 0x00002000; +pub const CLONE_VFORK = 0x00004000; +pub const CLONE_PARENT = 0x00008000; +pub const CLONE_THREAD = 0x00010000; +pub const CLONE_NEWNS = 0x00020000; +pub const CLONE_SYSVSEM = 0x00040000; +pub const CLONE_SETTLS = 0x00080000; +pub const CLONE_PARENT_SETTID = 0x00100000; +pub const CLONE_CHILD_CLEARTID = 0x00200000; +pub const CLONE_DETACHED = 0x00400000; +pub const CLONE_UNTRACED = 0x00800000; +pub const CLONE_CHILD_SETTID = 0x01000000; +pub const CLONE_NEWCGROUP = 0x02000000; +pub const CLONE_NEWUTS = 0x04000000; +pub const CLONE_NEWIPC = 0x08000000; +pub const CLONE_NEWUSER = 0x10000000; +pub const CLONE_NEWPID = 0x20000000; +pub const CLONE_NEWNET = 0x40000000; +pub const CLONE_IO = 0x80000000; + +pub const EFD_SEMAPHORE = 1; +pub const EFD_CLOEXEC = O_CLOEXEC; +pub const EFD_NONBLOCK = O_NONBLOCK; + +pub const MS_RDONLY = 1; +pub const MS_NOSUID = 2; +pub const MS_NODEV = 4; +pub const MS_NOEXEC = 8; +pub const MS_SYNCHRONOUS = 16; +pub const MS_REMOUNT = 32; +pub const MS_MANDLOCK = 64; +pub const MS_DIRSYNC = 128; +pub const MS_NOATIME = 1024; +pub const MS_NODIRATIME = 2048; +pub const MS_BIND = 4096; +pub const MS_MOVE = 8192; +pub const MS_REC = 16384; +pub const MS_SILENT = 32768; +pub const MS_POSIXACL = (1 << 16); +pub const MS_UNBINDABLE = (1 << 17); +pub const MS_PRIVATE = (1 << 18); +pub const MS_SLAVE = (1 << 19); +pub const MS_SHARED = (1 << 20); +pub const MS_RELATIME = (1 << 21); +pub const MS_KERNMOUNT = (1 << 22); +pub const MS_I_VERSION = (1 << 23); +pub const MS_STRICTATIME = (1 << 24); +pub const MS_LAZYTIME = (1 << 25); +pub const MS_NOREMOTELOCK = (1 << 27); +pub const MS_NOSEC = (1 << 28); +pub const MS_BORN = (1 << 29); +pub const MS_ACTIVE = (1 << 30); +pub const MS_NOUSER = (1 << 31); + +pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME); + +pub const MS_MGC_VAL = 0xc0ed0000; +pub const MS_MGC_MSK = 0xffff0000; + +pub const MNT_FORCE = 1; +pub const MNT_DETACH = 2; +pub const MNT_EXPIRE = 4; +pub const UMOUNT_NOFOLLOW = 8; + +pub const IN_CLOEXEC = O_CLOEXEC; +pub const IN_NONBLOCK = O_NONBLOCK; + +pub const IN_ACCESS = 0x00000001; +pub const IN_MODIFY = 0x00000002; +pub const IN_ATTRIB = 0x00000004; +pub const IN_CLOSE_WRITE = 0x00000008; +pub const IN_CLOSE_NOWRITE = 0x00000010; +pub const IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE; +pub const IN_OPEN = 0x00000020; +pub const IN_MOVED_FROM = 0x00000040; +pub const IN_MOVED_TO = 0x00000080; +pub const IN_MOVE = IN_MOVED_FROM | IN_MOVED_TO; +pub const IN_CREATE = 0x00000100; +pub const IN_DELETE = 0x00000200; +pub const IN_DELETE_SELF = 0x00000400; +pub const IN_MOVE_SELF = 0x00000800; +pub const IN_ALL_EVENTS = 0x00000fff; + +pub const IN_UNMOUNT = 0x00002000; +pub const IN_Q_OVERFLOW = 0x00004000; +pub const IN_IGNORED = 0x00008000; + +pub const IN_ONLYDIR = 0x01000000; +pub const IN_DONT_FOLLOW = 0x02000000; +pub const IN_EXCL_UNLINK = 0x04000000; +pub const IN_MASK_ADD = 0x20000000; + +pub const IN_ISDIR = 0x40000000; +pub const IN_ONESHOT = 0x80000000; + +pub const S_IFMT = 0o170000; + +pub const S_IFDIR = 0o040000; +pub const S_IFCHR = 0o020000; +pub const S_IFBLK = 0o060000; +pub const S_IFREG = 0o100000; +pub const S_IFIFO = 0o010000; +pub const S_IFLNK = 0o120000; +pub const S_IFSOCK = 0o140000; + +pub const S_ISUID = 0o4000; +pub const S_ISGID = 0o2000; +pub const S_ISVTX = 0o1000; +pub const S_IRUSR = 0o400; +pub const S_IWUSR = 0o200; +pub const S_IXUSR = 0o100; +pub const S_IRWXU = 0o700; +pub const S_IRGRP = 0o040; +pub const S_IWGRP = 0o020; +pub const S_IXGRP = 0o010; +pub const S_IRWXG = 0o070; +pub const S_IROTH = 0o004; +pub const S_IWOTH = 0o002; +pub const S_IXOTH = 0o001; +pub const S_IRWXO = 0o007; + +pub fn S_ISREG(m: u32) bool { + return m & S_IFMT == S_IFREG; +} + +pub fn S_ISDIR(m: u32) bool { + return m & S_IFMT == S_IFDIR; +} + +pub fn S_ISCHR(m: u32) bool { + return m & S_IFMT == S_IFCHR; +} + +pub fn S_ISBLK(m: u32) bool { + return m & S_IFMT == S_IFBLK; +} + +pub fn S_ISFIFO(m: u32) bool { + return m & S_IFMT == S_IFIFO; +} + +pub fn S_ISLNK(m: u32) bool { + return m & S_IFMT == S_IFLNK; +} + +pub fn S_ISSOCK(m: u32) bool { + return m & S_IFMT == S_IFSOCK; +} + +pub const TFD_NONBLOCK = O_NONBLOCK; +pub const TFD_CLOEXEC = O_CLOEXEC; + +pub const TFD_TIMER_ABSTIME = 1; +pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); + +pub fn WEXITSTATUS(s: u32) u32 { + return (s & 0xff00) >> 8; +} +pub fn WTERMSIG(s: u32) u32 { + return s & 0x7f; +} +pub fn WSTOPSIG(s: u32) u32 { + return WEXITSTATUS(s); +} +pub fn WIFEXITED(s: u32) bool { + return WTERMSIG(s) == 0; +} +pub fn WIFSTOPPED(s: u32) bool { + return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00; +} +pub fn WIFSIGNALED(s: u32) bool { + return (s & 0xffff) -% 1 < 0xff; +} + +pub const winsize = extern struct { + ws_row: u16, + ws_col: u16, + ws_xpixel: u16, + ws_ypixel: u16, +}; + +pub const NSIG = 65; +pub const sigset_t = [128 / @sizeOf(usize)]usize; +pub const all_mask = [_]u32{ 0xffffffff, 0xffffffff }; +pub const app_mask = [_]u32{ 0xfffffffc, 0x7fffffff }; + +pub const k_sigaction = extern struct { + sigaction: ?extern fn (i32, *siginfo_t, *c_void) void, + flags: usize, + restorer: extern fn () void, + mask: [2]u32, +}; + +/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. +pub const Sigaction = extern struct { + sigaction: ?extern fn (i32, *siginfo_t, *c_void) void, + mask: sigset_t, + flags: u32, + restorer: ?extern fn () void = null, +}; + +pub const SIG_ERR = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, maxInt(usize)); +pub const SIG_DFL = @intToPtr(?extern fn (i32, *siginfo_t, *c_void) void, 0); +pub const SIG_IGN = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, 1); +pub const empty_sigset = [_]usize{0} ** sigset_t.len; + +pub const in_port_t = u16; +pub const sa_family_t = u16; +pub const socklen_t = u32; + +/// This intentionally only has ip4 and ip6 +pub const sockaddr = extern union { + in: sockaddr_in, + in6: sockaddr_in6, + un: sockaddr_un, +}; + +pub const sockaddr_in = extern struct { + family: sa_family_t, + port: in_port_t, + addr: u32, + zero: [8]u8, +}; + +pub const sockaddr_in6 = extern struct { + family: sa_family_t, + port: in_port_t, + flowinfo: u32, + addr: [16]u8, + scope_id: u32, +}; + +pub const sockaddr_un = extern struct { + family: sa_family_t, + path: [108]u8, +}; + +pub const mmsghdr = extern struct { + msg_hdr: msghdr, + msg_len: u32, +}; + +pub const mmsghdr_const = extern struct { + msg_hdr: msghdr_const, + msg_len: u32, +}; + +pub const epoll_data = extern union { + ptr: usize, + fd: i32, + @"u32": u32, + @"u64": u64, +}; + +// On x86_64 the structure is packed so that it matches the definition of its +// 32bit counterpart +pub const epoll_event = switch (builtin.arch) { + .x86_64 => packed struct { + events: u32, + data: epoll_data, + }, + else => extern struct { + events: u32, + data: epoll_data, + }, +}; + +pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330; +pub const _LINUX_CAPABILITY_U32S_1 = 1; + +pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026; +pub const _LINUX_CAPABILITY_U32S_2 = 2; + +pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522; +pub const _LINUX_CAPABILITY_U32S_3 = 2; + +pub const VFS_CAP_REVISION_MASK = 0xFF000000; +pub const VFS_CAP_REVISION_SHIFT = 24; +pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK; +pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001; + +pub const VFS_CAP_REVISION_1 = 0x01000000; +pub const VFS_CAP_U32_1 = 1; +pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1); + +pub const VFS_CAP_REVISION_2 = 0x02000000; +pub const VFS_CAP_U32_2 = 2; +pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2); + +pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2; +pub const VFS_CAP_U32 = VFS_CAP_U32_2; +pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2; + +pub const vfs_cap_data = extern struct { + //all of these are mandated as little endian + //when on disk. + const Data = struct { + permitted: u32, + inheritable: u32, + }; + + magic_etc: u32, + data: [VFS_CAP_U32]Data, +}; + +pub const CAP_CHOWN = 0; +pub const CAP_DAC_OVERRIDE = 1; +pub const CAP_DAC_READ_SEARCH = 2; +pub const CAP_FOWNER = 3; +pub const CAP_FSETID = 4; +pub const CAP_KILL = 5; +pub const CAP_SETGID = 6; +pub const CAP_SETUID = 7; +pub const CAP_SETPCAP = 8; +pub const CAP_LINUX_IMMUTABLE = 9; +pub const CAP_NET_BIND_SERVICE = 10; +pub const CAP_NET_BROADCAST = 11; +pub const CAP_NET_ADMIN = 12; +pub const CAP_NET_RAW = 13; +pub const CAP_IPC_LOCK = 14; +pub const CAP_IPC_OWNER = 15; +pub const CAP_SYS_MODULE = 16; +pub const CAP_SYS_RAWIO = 17; +pub const CAP_SYS_CHROOT = 18; +pub const CAP_SYS_PTRACE = 19; +pub const CAP_SYS_PACCT = 20; +pub const CAP_SYS_ADMIN = 21; +pub const CAP_SYS_BOOT = 22; +pub const CAP_SYS_NICE = 23; +pub const CAP_SYS_RESOURCE = 24; +pub const CAP_SYS_TIME = 25; +pub const CAP_SYS_TTY_CONFIG = 26; +pub const CAP_MKNOD = 27; +pub const CAP_LEASE = 28; +pub const CAP_AUDIT_WRITE = 29; +pub const CAP_AUDIT_CONTROL = 30; +pub const CAP_SETFCAP = 31; +pub const CAP_MAC_OVERRIDE = 32; +pub const CAP_MAC_ADMIN = 33; +pub const CAP_SYSLOG = 34; +pub const CAP_WAKE_ALARM = 35; +pub const CAP_BLOCK_SUSPEND = 36; +pub const CAP_AUDIT_READ = 37; +pub const CAP_LAST_CAP = CAP_AUDIT_READ; + +pub fn cap_valid(u8: x) bool { + return x >= 0 and x <= CAP_LAST_CAP; +} + +pub fn CAP_TO_MASK(cap: u8) u32 { + return u32(1) << u5(cap & 31); +} + +pub fn CAP_TO_INDEX(cap: u8) u8 { + return cap >> 5; +} + +pub const cap_t = extern struct { + hdrp: *cap_user_header_t, + datap: *cap_user_data_t, +}; + +pub const cap_user_header_t = extern struct { + version: u32, + pid: usize, +}; + +pub const cap_user_data_t = extern struct { + effective: u32, + permitted: u32, + inheritable: u32, +}; + +pub const inotify_event = extern struct { + wd: i32, + mask: u32, + cookie: u32, + len: u32, + //name: [?]u8, +}; + +pub const dirent64 = extern struct { + d_ino: u64, + d_off: u64, + d_reclen: u16, + d_type: u8, + d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173 +}; + +pub const dl_phdr_info = extern struct { + dlpi_addr: usize, + dlpi_name: ?[*]const u8, + dlpi_phdr: [*]std.elf.Phdr, + dlpi_phnum: u16, +}; + +pub const pthread_attr_t = extern struct { + __size: [56]u8, + __align: c_long, +}; + +pub const CPU_SETSIZE = 128; +pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize; +pub const cpu_count_t = @IntType(false, std.math.log2(CPU_SETSIZE * 8)); + +pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t { + var sum: cpu_count_t = 0; + for (set) |x| { + sum += @popCount(usize, x); + } + return sum; +} + +// TODO port these over +//#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) +//#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) +//#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) +//#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) +//#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) +//#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) +//#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) +//#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) +//#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) + +pub const MINSIGSTKSZ = switch (builtin.arch) { + .i386, .x86_64, .arm => 2048, + .aarch64 => 5120, + else => @compileError("MINSIGSTKSZ not defined for this architecture"), +}; +pub const SIGSTKSZ = switch (builtin.arch) { + .i386, .x86_64, .arm => 8192, + .aarch64 => 16384, + else => @compileError("SIGSTKSZ not defined for this architecture"), +}; + +pub const SS_ONSTACK = 1; +pub const SS_DISABLE = 2; +pub const SS_AUTODISARM = 1 << 31; + +pub const stack_t = extern struct { + ss_sp: [*]u8, + ss_flags: i32, + ss_size: isize, +}; + +pub const io_uring_params = extern struct { + sq_entries: u32, + cq_entries: u32, + flags: u32, + sq_thread_cpu: u32, + sq_thread_idle: u32, + resv: [5]u32, + sq_off: io_sqring_offsets, + cq_off: io_cqring_offsets, +}; + +// io_uring_params.flags + +/// io_context is polled +pub const IORING_SETUP_IOPOLL = (1 << 0); + +/// SQ poll thread +pub const IORING_SETUP_SQPOLL = (1 << 1); + +/// sq_thread_cpu is valid +pub const IORING_SETUP_SQ_AFF = (1 << 2); + +pub const io_sqring_offsets = extern struct { + /// offset of ring head + head: u32, + + /// offset of ring tail + tail: u32, + + /// ring mask value + ring_mask: u32, + + /// entries in ring + ring_entries: u32, + + /// ring flags + flags: u32, + + /// number of sqes not submitted + dropped: u32, + + /// sqe index array + array: u32, + + resv1: u32, + resv2: u64, +}; + +// io_sqring_offsets.flags + +/// needs io_uring_enter wakeup +pub const IORING_SQ_NEED_WAKEUP = 1 << 0; + +pub const io_cqring_offsets = extern struct { + head: u32, + tail: u32, + ring_mask: u32, + ring_entries: u32, + overflow: u32, + cqes: u32, + resv: [2]u64, +}; + +pub const io_uring_sqe = extern struct { + opcode: u8, + flags: u8, + ioprio: u16, + fd: i32, + off: u64, + addr: u64, + len: u32, + pub const union1 = extern union { + rw_flags: kernel_rwf, + fsync_flags: u32, + poll_events: u16, + sync_range_flags: u32, + msg_flags: u32, + }; + union1: union1, + user_data: u64, + pub const union2 = extern union { + buf_index: u16, + __pad2: [3]u64, + }; + union2: union2, +}; + +// io_uring_sqe.flags + +/// use fixed fileset +pub const IOSQE_FIXED_FILE = (1 << 0); + +/// issue after inflight IO +pub const IOSQE_IO_DRAIN = (1 << 1); + +/// links next sqe +pub const IOSQE_IO_LINK = (1 << 2); + +pub const IORING_OP_NOP = 0; +pub const IORING_OP_READV = 1; +pub const IORING_OP_WRITEV = 2; +pub const IORING_OP_FSYNC = 3; +pub const IORING_OP_READ_FIXED = 4; +pub const IORING_OP_WRITE_FIXED = 5; +pub const IORING_OP_POLL_ADD = 6; +pub const IORING_OP_POLL_REMOVE = 7; +pub const IORING_OP_SYNC_FILE_RANGE = 8; +pub const IORING_OP_SENDMSG = 9; +pub const IORING_OP_RECVMSG = 10; + +// io_uring_sqe.fsync_flags +pub const IORING_FSYNC_DATASYNC = (1 << 0); + +// IO completion data structure (Completion Queue Entry) +pub const io_uring_cqe = extern struct { + /// io_uring_sqe.data submission passed back + user_data: u64, + + /// result code for this event + res: i32, + flags: u32, +}; + +pub const IORING_OFF_SQ_RING = 0; +pub const IORING_OFF_CQ_RING = 0x8000000; +pub const IORING_OFF_SQES = 0x10000000; + +// io_uring_enter flags +pub const IORING_ENTER_GETEVENTS = (1 << 0); +pub const IORING_ENTER_SQ_WAKEUP = (1 << 1); + +// io_uring_register opcodes and arguments +pub const IORING_REGISTER_BUFFERS = 0; +pub const IORING_UNREGISTER_BUFFERS = 1; +pub const IORING_REGISTER_FILES = 2; +pub const IORING_UNREGISTER_FILES = 3; +pub const IORING_REGISTER_EVENTFD = 4; +pub const IORING_UNREGISTER_EVENTFD = 5; + +pub const utsname = extern struct { + sysname: [65]u8, + nodename: [65]u8, + release: [65]u8, + version: [65]u8, + machine: [65]u8, + domainname: [65]u8, +}; +pub const HOST_NAME_MAX = 64; diff --git a/lib/std/os/bits/linux/arm-eabi.zig b/lib/std/os/bits/linux/arm-eabi.zig new file mode 100644 index 0000000000..4b3e1094da --- /dev/null +++ b/lib/std/os/bits/linux/arm-eabi.zig @@ -0,0 +1,568 @@ +// arm-eabi-specific declarations that are intended to be imported into the POSIX namespace. + +const std = @import("../../std.zig"); +const linux = std.os.linux; +const socklen_t = linux.socklen_t; +const iovec = linux.iovec; +const iovec_const = linux.iovec_const; + +pub const SYS_restart_syscall = 0; +pub const SYS_exit = 1; +pub const SYS_fork = 2; +pub const SYS_read = 3; +pub const SYS_write = 4; +pub const SYS_open = 5; +pub const SYS_close = 6; +pub const SYS_creat = 8; +pub const SYS_link = 9; +pub const SYS_unlink = 10; +pub const SYS_execve = 11; +pub const SYS_chdir = 12; +pub const SYS_mknod = 14; +pub const SYS_chmod = 15; +pub const SYS_lchown = 16; +pub const SYS_lseek = 19; +pub const SYS_getpid = 20; +pub const SYS_mount = 21; +pub const SYS_setuid = 23; +pub const SYS_getuid = 24; +pub const SYS_ptrace = 26; +pub const SYS_pause = 29; +pub const SYS_access = 33; +pub const SYS_nice = 34; +pub const SYS_sync = 36; +pub const SYS_kill = 37; +pub const SYS_rename = 38; +pub const SYS_mkdir = 39; +pub const SYS_rmdir = 40; +pub const SYS_dup = 41; +pub const SYS_pipe = 42; +pub const SYS_times = 43; +pub const SYS_brk = 45; +pub const SYS_setgid = 46; +pub const SYS_getgid = 47; +pub const SYS_geteuid = 49; +pub const SYS_getegid = 50; +pub const SYS_acct = 51; +pub const SYS_umount2 = 52; +pub const SYS_ioctl = 54; +pub const SYS_fcntl = 55; +pub const SYS_setpgid = 57; +pub const SYS_umask = 60; +pub const SYS_chroot = 61; +pub const SYS_ustat = 62; +pub const SYS_dup2 = 63; +pub const SYS_getppid = 64; +pub const SYS_getpgrp = 65; +pub const SYS_setsid = 66; +pub const SYS_sigaction = 67; +pub const SYS_setreuid = 70; +pub const SYS_setregid = 71; +pub const SYS_sigsuspend = 72; +pub const SYS_sigpending = 73; +pub const SYS_sethostname = 74; +pub const SYS_setrlimit = 75; +pub const SYS_getrusage = 77; +pub const SYS_gettimeofday = 78; +pub const SYS_settimeofday = 79; +pub const SYS_getgroups = 80; +pub const SYS_setgroups = 81; +pub const SYS_symlink = 83; +pub const SYS_readlink = 85; +pub const SYS_uselib = 86; +pub const SYS_swapon = 87; +pub const SYS_reboot = 88; +pub const SYS_munmap = 91; +pub const SYS_truncate = 92; +pub const SYS_ftruncate = 93; +pub const SYS_fchmod = 94; +pub const SYS_fchown = 95; +pub const SYS_getpriority = 96; +pub const SYS_setpriority = 97; +pub const SYS_statfs = 99; +pub const SYS_fstatfs = 100; +pub const SYS_syslog = 103; +pub const SYS_setitimer = 104; +pub const SYS_getitimer = 105; +pub const SYS_stat = 106; +pub const SYS_lstat = 107; +pub const SYS_fstat = 108; +pub const SYS_vhangup = 111; +pub const SYS_wait4 = 114; +pub const SYS_swapoff = 115; +pub const SYS_sysinfo = 116; +pub const SYS_fsync = 118; +pub const SYS_sigreturn = 119; +pub const SYS_clone = 120; +pub const SYS_setdomainname = 121; +pub const SYS_uname = 122; +pub const SYS_adjtimex = 124; +pub const SYS_mprotect = 125; +pub const SYS_sigprocmask = 126; +pub const SYS_init_module = 128; +pub const SYS_delete_module = 129; +pub const SYS_quotactl = 131; +pub const SYS_getpgid = 132; +pub const SYS_fchdir = 133; +pub const SYS_bdflush = 134; +pub const SYS_sysfs = 135; +pub const SYS_personality = 136; +pub const SYS_setfsuid = 138; +pub const SYS_setfsgid = 139; +pub const SYS__llseek = 140; +pub const SYS_getdents = 141; +pub const SYS__newselect = 142; +pub const SYS_flock = 143; +pub const SYS_msync = 144; +pub const SYS_readv = 145; +pub const SYS_writev = 146; +pub const SYS_getsid = 147; +pub const SYS_fdatasync = 148; +pub const SYS__sysctl = 149; +pub const SYS_mlock = 150; +pub const SYS_munlock = 151; +pub const SYS_mlockall = 152; +pub const SYS_munlockall = 153; +pub const SYS_sched_setparam = 154; +pub const SYS_sched_getparam = 155; +pub const SYS_sched_setscheduler = 156; +pub const SYS_sched_getscheduler = 157; +pub const SYS_sched_yield = 158; +pub const SYS_sched_get_priority_max = 159; +pub const SYS_sched_get_priority_min = 160; +pub const SYS_sched_rr_get_interval = 161; +pub const SYS_nanosleep = 162; +pub const SYS_mremap = 163; +pub const SYS_setresuid = 164; +pub const SYS_getresuid = 165; +pub const SYS_poll = 168; +pub const SYS_nfsservctl = 169; +pub const SYS_setresgid = 170; +pub const SYS_getresgid = 171; +pub const SYS_prctl = 172; +pub const SYS_rt_sigreturn = 173; +pub const SYS_rt_sigaction = 174; +pub const SYS_rt_sigprocmask = 175; +pub const SYS_rt_sigpending = 176; +pub const SYS_rt_sigtimedwait = 177; +pub const SYS_rt_sigqueueinfo = 178; +pub const SYS_rt_sigsuspend = 179; +pub const SYS_pread64 = 180; +pub const SYS_pwrite64 = 181; +pub const SYS_chown = 182; +pub const SYS_getcwd = 183; +pub const SYS_capget = 184; +pub const SYS_capset = 185; +pub const SYS_sigaltstack = 186; +pub const SYS_sendfile = 187; +pub const SYS_vfork = 190; +pub const SYS_ugetrlimit = 191; +pub const SYS_mmap2 = 192; +pub const SYS_truncate64 = 193; +pub const SYS_ftruncate64 = 194; +pub const SYS_stat64 = 195; +pub const SYS_lstat64 = 196; +pub const SYS_fstat64 = 197; +pub const SYS_lchown32 = 198; +pub const SYS_getuid32 = 199; +pub const SYS_getgid32 = 200; +pub const SYS_geteuid32 = 201; +pub const SYS_getegid32 = 202; +pub const SYS_setreuid32 = 203; +pub const SYS_setregid32 = 204; +pub const SYS_getgroups32 = 205; +pub const SYS_setgroups32 = 206; +pub const SYS_fchown32 = 207; +pub const SYS_setresuid32 = 208; +pub const SYS_getresuid32 = 209; +pub const SYS_setresgid32 = 210; +pub const SYS_getresgid32 = 211; +pub const SYS_chown32 = 212; +pub const SYS_setuid32 = 213; +pub const SYS_setgid32 = 214; +pub const SYS_setfsuid32 = 215; +pub const SYS_setfsgid32 = 216; +pub const SYS_getdents64 = 217; +pub const SYS_pivot_root = 218; +pub const SYS_mincore = 219; +pub const SYS_madvise = 220; +pub const SYS_fcntl64 = 221; +pub const SYS_gettid = 224; +pub const SYS_readahead = 225; +pub const SYS_setxattr = 226; +pub const SYS_lsetxattr = 227; +pub const SYS_fsetxattr = 228; +pub const SYS_getxattr = 229; +pub const SYS_lgetxattr = 230; +pub const SYS_fgetxattr = 231; +pub const SYS_listxattr = 232; +pub const SYS_llistxattr = 233; +pub const SYS_flistxattr = 234; +pub const SYS_removexattr = 235; +pub const SYS_lremovexattr = 236; +pub const SYS_fremovexattr = 237; +pub const SYS_tkill = 238; +pub const SYS_sendfile64 = 239; +pub const SYS_futex = 240; +pub const SYS_sched_setaffinity = 241; +pub const SYS_sched_getaffinity = 242; +pub const SYS_io_setup = 243; +pub const SYS_io_destroy = 244; +pub const SYS_io_getevents = 245; +pub const SYS_io_submit = 246; +pub const SYS_io_cancel = 247; +pub const SYS_exit_group = 248; +pub const SYS_lookup_dcookie = 249; +pub const SYS_epoll_create = 250; +pub const SYS_epoll_ctl = 251; +pub const SYS_epoll_wait = 252; +pub const SYS_remap_file_pages = 253; +pub const SYS_set_tid_address = 256; +pub const SYS_timer_create = 257; +pub const SYS_timer_settime = 258; +pub const SYS_timer_gettime = 259; +pub const SYS_timer_getoverrun = 260; +pub const SYS_timer_delete = 261; +pub const SYS_clock_settime = 262; +pub const SYS_clock_gettime = 263; +pub const SYS_clock_getres = 264; +pub const SYS_clock_nanosleep = 265; +pub const SYS_statfs64 = 266; +pub const SYS_fstatfs64 = 267; +pub const SYS_tgkill = 268; +pub const SYS_utimes = 269; +pub const SYS_fadvise64_64 = 270; +pub const SYS_arm_fadvise64_64 = 270; +pub const SYS_pciconfig_iobase = 271; +pub const SYS_pciconfig_read = 272; +pub const SYS_pciconfig_write = 273; +pub const SYS_mq_open = 274; +pub const SYS_mq_unlink = 275; +pub const SYS_mq_timedsend = 276; +pub const SYS_mq_timedreceive = 277; +pub const SYS_mq_notify = 278; +pub const SYS_mq_getsetattr = 279; +pub const SYS_waitid = 280; +pub const SYS_socket = 281; +pub const SYS_bind = 282; +pub const SYS_connect = 283; +pub const SYS_listen = 284; +pub const SYS_accept = 285; +pub const SYS_getsockname = 286; +pub const SYS_getpeername = 287; +pub const SYS_socketpair = 288; +pub const SYS_send = 289; +pub const SYS_sendto = 290; +pub const SYS_recv = 291; +pub const SYS_recvfrom = 292; +pub const SYS_shutdown = 293; +pub const SYS_setsockopt = 294; +pub const SYS_getsockopt = 295; +pub const SYS_sendmsg = 296; +pub const SYS_recvmsg = 297; +pub const SYS_semop = 298; +pub const SYS_semget = 299; +pub const SYS_semctl = 300; +pub const SYS_msgsnd = 301; +pub const SYS_msgrcv = 302; +pub const SYS_msgget = 303; +pub const SYS_msgctl = 304; +pub const SYS_shmat = 305; +pub const SYS_shmdt = 306; +pub const SYS_shmget = 307; +pub const SYS_shmctl = 308; +pub const SYS_add_key = 309; +pub const SYS_request_key = 310; +pub const SYS_keyctl = 311; +pub const SYS_semtimedop = 312; +pub const SYS_vserver = 313; +pub const SYS_ioprio_set = 314; +pub const SYS_ioprio_get = 315; +pub const SYS_inotify_init = 316; +pub const SYS_inotify_add_watch = 317; +pub const SYS_inotify_rm_watch = 318; +pub const SYS_mbind = 319; +pub const SYS_get_mempolicy = 320; +pub const SYS_set_mempolicy = 321; +pub const SYS_openat = 322; +pub const SYS_mkdirat = 323; +pub const SYS_mknodat = 324; +pub const SYS_fchownat = 325; +pub const SYS_futimesat = 326; +pub const SYS_fstatat64 = 327; +pub const SYS_unlinkat = 328; +pub const SYS_renameat = 329; +pub const SYS_linkat = 330; +pub const SYS_symlinkat = 331; +pub const SYS_readlinkat = 332; +pub const SYS_fchmodat = 333; +pub const SYS_faccessat = 334; +pub const SYS_pselect6 = 335; +pub const SYS_ppoll = 336; +pub const SYS_unshare = 337; +pub const SYS_set_robust_list = 338; +pub const SYS_get_robust_list = 339; +pub const SYS_splice = 340; +pub const SYS_sync_file_range2 = 341; +pub const SYS_arm_sync_file_range = 341; +pub const SYS_tee = 342; +pub const SYS_vmsplice = 343; +pub const SYS_move_pages = 344; +pub const SYS_getcpu = 345; +pub const SYS_epoll_pwait = 346; +pub const SYS_kexec_load = 347; +pub const SYS_utimensat = 348; +pub const SYS_signalfd = 349; +pub const SYS_timerfd_create = 350; +pub const SYS_eventfd = 351; +pub const SYS_fallocate = 352; +pub const SYS_timerfd_settime = 353; +pub const SYS_timerfd_gettime = 354; +pub const SYS_signalfd4 = 355; +pub const SYS_eventfd2 = 356; +pub const SYS_epoll_create1 = 357; +pub const SYS_dup3 = 358; +pub const SYS_pipe2 = 359; +pub const SYS_inotify_init1 = 360; +pub const SYS_preadv = 361; +pub const SYS_pwritev = 362; +pub const SYS_rt_tgsigqueueinfo = 363; +pub const SYS_perf_event_open = 364; +pub const SYS_recvmmsg = 365; +pub const SYS_accept4 = 366; +pub const SYS_fanotify_init = 367; +pub const SYS_fanotify_mark = 368; +pub const SYS_prlimit64 = 369; +pub const SYS_name_to_handle_at = 370; +pub const SYS_open_by_handle_at = 371; +pub const SYS_clock_adjtime = 372; +pub const SYS_syncfs = 373; +pub const SYS_sendmmsg = 374; +pub const SYS_setns = 375; +pub const SYS_process_vm_readv = 376; +pub const SYS_process_vm_writev = 377; +pub const SYS_kcmp = 378; +pub const SYS_finit_module = 379; +pub const SYS_sched_setattr = 380; +pub const SYS_sched_getattr = 381; +pub const SYS_renameat2 = 382; +pub const SYS_seccomp = 383; +pub const SYS_getrandom = 384; +pub const SYS_memfd_create = 385; +pub const SYS_bpf = 386; +pub const SYS_execveat = 387; +pub const SYS_userfaultfd = 388; +pub const SYS_membarrier = 389; +pub const SYS_mlock2 = 390; +pub const SYS_copy_file_range = 391; +pub const SYS_preadv2 = 392; +pub const SYS_pwritev2 = 393; +pub const SYS_pkey_mprotect = 394; +pub const SYS_pkey_alloc = 395; +pub const SYS_pkey_free = 396; +pub const SYS_statx = 397; +pub const SYS_rseq = 398; +pub const SYS_io_pgetevents = 399; +pub const SYS_migrate_pages = 400; +pub const SYS_kexec_file_load = 401; +pub const SYS_clock_gettime64 = 403; +pub const SYS_clock_settime64 = 404; +pub const SYS_clock_adjtime64 = 405; +pub const SYS_clock_getres_time64 = 406; +pub const SYS_clock_nanosleep_time64 = 407; +pub const SYS_timer_gettime64 = 408; +pub const SYS_timer_settime64 = 409; +pub const SYS_timerfd_gettime64 = 410; +pub const SYS_timerfd_settime64 = 411; +pub const SYS_utimensat_time64 = 412; +pub const SYS_pselect6_time64 = 413; +pub const SYS_ppoll_time64 = 414; +pub const SYS_io_pgetevents_time64 = 416; +pub const SYS_recvmmsg_time64 = 417; +pub const SYS_mq_timedsend_time64 = 418; +pub const SYS_mq_timedreceive_time64 = 419; +pub const SYS_semtimedop_time64 = 420; +pub const SYS_rt_sigtimedwait_time64 = 421; +pub const SYS_futex_time64 = 422; +pub const SYS_sched_rr_get_interval_time64 = 423; +pub const SYS_pidfd_send_signal = 424; +pub const SYS_io_uring_setup = 425; +pub const SYS_io_uring_enter = 426; +pub const SYS_io_uring_register = 427; +pub const SYS_open_tree = 428; +pub const SYS_move_mount = 429; +pub const SYS_fsopen = 430; +pub const SYS_fsconfig = 431; +pub const SYS_fsmount = 432; +pub const SYS_fspick = 433; +pub const SYS_pidfd_open = 434; +pub const SYS_clone3 = 435; + +pub const SYS_breakpoint = 0x0f0001; +pub const SYS_cacheflush = 0x0f0002; +pub const SYS_usr26 = 0x0f0003; +pub const SYS_usr32 = 0x0f0004; +pub const SYS_set_tls = 0x0f0005; +pub const SYS_get_tls = 0x0f0006; + +pub const MMAP2_UNIT = 4096; + +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o40000; +pub const O_NOFOLLOW = 0o100000; +pub const O_CLOEXEC = 0o2000000; + +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o200000; +pub const O_LARGEFILE = 0o400000; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20040000; +pub const O_NDELAY = O_NONBLOCK; + +pub const F_DUPFD = 0; +pub const F_GETFD = 1; +pub const F_SETFD = 2; +pub const F_GETFL = 3; +pub const F_SETFL = 4; + +pub const F_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_GETLK = 12; +pub const F_SETLK = 13; +pub const F_SETLKW = 14; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; + +/// stack-like segment +pub const MAP_GROWSDOWN = 0x0100; + +/// ETXTBSY +pub const MAP_DENYWRITE = 0x0800; + +/// mark it as an executable +pub const MAP_EXECUTABLE = 0x1000; + +/// pages are locked +pub const MAP_LOCKED = 0x2000; + +/// don't check for reservations +pub const MAP_NORESERVE = 0x4000; + +pub const VDSO_USEFUL = true; +pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; +pub const VDSO_CGT_VER = "LINUX_2.6"; + +pub const HWCAP_SWP = 1 << 0; +pub const HWCAP_HALF = 1 << 1; +pub const HWCAP_THUMB = 1 << 2; +pub const HWCAP_26BIT = 1 << 3; +pub const HWCAP_FAST_MULT = 1 << 4; +pub const HWCAP_FPA = 1 << 5; +pub const HWCAP_VFP = 1 << 6; +pub const HWCAP_EDSP = 1 << 7; +pub const HWCAP_JAVA = 1 << 8; +pub const HWCAP_IWMMXT = 1 << 9; +pub const HWCAP_CRUNCH = 1 << 10; +pub const HWCAP_THUMBEE = 1 << 11; +pub const HWCAP_NEON = 1 << 12; +pub const HWCAP_VFPv3 = 1 << 13; +pub const HWCAP_VFPv3D16 = 1 << 14; +pub const HWCAP_TLS = 1 << 15; +pub const HWCAP_VFPv4 = 1 << 16; +pub const HWCAP_IDIVA = 1 << 17; +pub const HWCAP_IDIVT = 1 << 18; +pub const HWCAP_VFPD32 = 1 << 19; +pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT; +pub const HWCAP_LPAE = 1 << 20; +pub const HWCAP_EVTSTRM = 1 << 21; + +pub const msghdr = extern struct { + msg_name: ?*sockaddr, + msg_namelen: socklen_t, + msg_iov: [*]iovec, + msg_iovlen: i32, + msg_control: ?*c_void, + msg_controllen: socklen_t, + msg_flags: i32, +}; + +pub const msghdr_const = extern struct { + msg_name: ?*const sockaddr, + msg_namelen: socklen_t, + msg_iov: [*]iovec_const, + msg_iovlen: i32, + msg_control: ?*c_void, + msg_controllen: socklen_t, + msg_flags: i32, +}; + +pub const off_t = i64; + +/// Renamed to Stat to not conflict with the stat function. +/// atime, mtime, and ctime have functions to return `timespec`, +/// because although this is a POSIX API, the layout and names of +/// the structs are inconsistent across operating systems, and +/// in C, macros are used to hide the differences. Here we use +/// methods to accomplish this. +pub const Stat = extern struct { + dev: u64, + __dev_padding: u32, + __ino_truncated: u32, + mode: u32, + nlink: u32, + uid: u32, + gid: u32, + rdev: u64, + __rdev_padding: u32, + size: off_t, + blksize: i32, + blocks: u64, + atim: timespec, + mtim: timespec, + ctim: timespec, + ino: u64, + + pub fn atime(self: Stat) timespec { + return self.atim; + } + + pub fn mtime(self: Stat) timespec { + return self.mtim; + } + + pub fn ctime(self: Stat) timespec { + return self.ctim; + } +}; + +pub const timespec = extern struct { + tv_sec: i32, + tv_nsec: i32, +}; + +pub const timeval = extern struct { + tv_sec: i32, + tv_usec: i32, +}; + +pub const timezone = extern struct { + tz_minuteswest: i32, + tz_dsttime: i32, +}; + +pub const Elf_Symndx = u32; diff --git a/lib/std/os/bits/linux/arm64.zig b/lib/std/os/bits/linux/arm64.zig new file mode 100644 index 0000000000..692efc0eb3 --- /dev/null +++ b/lib/std/os/bits/linux/arm64.zig @@ -0,0 +1,448 @@ +// arm64-specific declarations that are intended to be imported into the POSIX namespace. +// This does include Linux-only APIs. + +const std = @import("../../../std.zig"); +const linux = std.os.linux; +const socklen_t = linux.socklen_t; +const iovec = linux.iovec; +const iovec_const = linux.iovec_const; +const uid_t = linux.uid_t; +const gid_t = linux.gid_t; + +pub const SYS_io_setup = 0; +pub const SYS_io_destroy = 1; +pub const SYS_io_submit = 2; +pub const SYS_io_cancel = 3; +pub const SYS_io_getevents = 4; +pub const SYS_setxattr = 5; +pub const SYS_lsetxattr = 6; +pub const SYS_fsetxattr = 7; +pub const SYS_getxattr = 8; +pub const SYS_lgetxattr = 9; +pub const SYS_fgetxattr = 10; +pub const SYS_listxattr = 11; +pub const SYS_llistxattr = 12; +pub const SYS_flistxattr = 13; +pub const SYS_removexattr = 14; +pub const SYS_lremovexattr = 15; +pub const SYS_fremovexattr = 16; +pub const SYS_getcwd = 17; +pub const SYS_lookup_dcookie = 18; +pub const SYS_eventfd2 = 19; +pub const SYS_epoll_create1 = 20; +pub const SYS_epoll_ctl = 21; +pub const SYS_epoll_pwait = 22; +pub const SYS_dup = 23; +pub const SYS_dup3 = 24; +pub const SYS_fcntl = 25; +pub const SYS_inotify_init1 = 26; +pub const SYS_inotify_add_watch = 27; +pub const SYS_inotify_rm_watch = 28; +pub const SYS_ioctl = 29; +pub const SYS_ioprio_set = 30; +pub const SYS_ioprio_get = 31; +pub const SYS_flock = 32; +pub const SYS_mknodat = 33; +pub const SYS_mkdirat = 34; +pub const SYS_unlinkat = 35; +pub const SYS_symlinkat = 36; +pub const SYS_linkat = 37; +pub const SYS_renameat = 38; +pub const SYS_umount2 = 39; +pub const SYS_mount = 40; +pub const SYS_pivot_root = 41; +pub const SYS_nfsservctl = 42; +pub const SYS_statfs = 43; +pub const SYS_fstatfs = 44; +pub const SYS_truncate = 45; +pub const SYS_ftruncate = 46; +pub const SYS_fallocate = 47; +pub const SYS_faccessat = 48; +pub const SYS_chdir = 49; +pub const SYS_fchdir = 50; +pub const SYS_chroot = 51; +pub const SYS_fchmod = 52; +pub const SYS_fchmodat = 53; +pub const SYS_fchownat = 54; +pub const SYS_fchown = 55; +pub const SYS_openat = 56; +pub const SYS_close = 57; +pub const SYS_vhangup = 58; +pub const SYS_pipe2 = 59; +pub const SYS_quotactl = 60; +pub const SYS_getdents64 = 61; +pub const SYS_lseek = 62; +pub const SYS_read = 63; +pub const SYS_write = 64; +pub const SYS_readv = 65; +pub const SYS_writev = 66; +pub const SYS_pread64 = 67; +pub const SYS_pwrite64 = 68; +pub const SYS_preadv = 69; +pub const SYS_pwritev = 70; +pub const SYS_pselect6 = 72; +pub const SYS_ppoll = 73; +pub const SYS_signalfd4 = 74; +pub const SYS_vmsplice = 75; +pub const SYS_splice = 76; +pub const SYS_tee = 77; +pub const SYS_readlinkat = 78; +pub const SYS_fstatat = 79; +pub const SYS_fstat = 80; +pub const SYS_sync = 81; +pub const SYS_fsync = 82; +pub const SYS_fdatasync = 83; +pub const SYS_sync_file_range2 = 84; +pub const SYS_sync_file_range = 84; +pub const SYS_timerfd_create = 85; +pub const SYS_timerfd_settime = 86; +pub const SYS_timerfd_gettime = 87; +pub const SYS_utimensat = 88; +pub const SYS_acct = 89; +pub const SYS_capget = 90; +pub const SYS_capset = 91; +pub const SYS_personality = 92; +pub const SYS_exit = 93; +pub const SYS_exit_group = 94; +pub const SYS_waitid = 95; +pub const SYS_set_tid_address = 96; +pub const SYS_unshare = 97; +pub const SYS_futex = 98; +pub const SYS_set_robust_list = 99; +pub const SYS_get_robust_list = 100; +pub const SYS_nanosleep = 101; +pub const SYS_getitimer = 102; +pub const SYS_setitimer = 103; +pub const SYS_kexec_load = 104; +pub const SYS_init_module = 105; +pub const SYS_delete_module = 106; +pub const SYS_timer_create = 107; +pub const SYS_timer_gettime = 108; +pub const SYS_timer_getoverrun = 109; +pub const SYS_timer_settime = 110; +pub const SYS_timer_delete = 111; +pub const SYS_clock_settime = 112; +pub const SYS_clock_gettime = 113; +pub const SYS_clock_getres = 114; +pub const SYS_clock_nanosleep = 115; +pub const SYS_syslog = 116; +pub const SYS_ptrace = 117; +pub const SYS_sched_setparam = 118; +pub const SYS_sched_setscheduler = 119; +pub const SYS_sched_getscheduler = 120; +pub const SYS_sched_getparam = 121; +pub const SYS_sched_setaffinity = 122; +pub const SYS_sched_getaffinity = 123; +pub const SYS_sched_yield = 124; +pub const SYS_sched_get_priority_max = 125; +pub const SYS_sched_get_priority_min = 126; +pub const SYS_sched_rr_get_interval = 127; +pub const SYS_restart_syscall = 128; +pub const SYS_kill = 129; +pub const SYS_tkill = 130; +pub const SYS_tgkill = 131; +pub const SYS_sigaltstack = 132; +pub const SYS_rt_sigsuspend = 133; +pub const SYS_rt_sigaction = 134; +pub const SYS_rt_sigprocmask = 135; +pub const SYS_rt_sigpending = 136; +pub const SYS_rt_sigtimedwait = 137; +pub const SYS_rt_sigqueueinfo = 138; +pub const SYS_rt_sigreturn = 139; +pub const SYS_setpriority = 140; +pub const SYS_getpriority = 141; +pub const SYS_reboot = 142; +pub const SYS_setregid = 143; +pub const SYS_setgid = 144; +pub const SYS_setreuid = 145; +pub const SYS_setuid = 146; +pub const SYS_setresuid = 147; +pub const SYS_getresuid = 148; +pub const SYS_setresgid = 149; +pub const SYS_getresgid = 150; +pub const SYS_setfsuid = 151; +pub const SYS_setfsgid = 152; +pub const SYS_times = 153; +pub const SYS_setpgid = 154; +pub const SYS_getpgid = 155; +pub const SYS_getsid = 156; +pub const SYS_setsid = 157; +pub const SYS_getgroups = 158; +pub const SYS_setgroups = 159; +pub const SYS_uname = 160; +pub const SYS_sethostname = 161; +pub const SYS_setdomainname = 162; +pub const SYS_getrlimit = 163; +pub const SYS_setrlimit = 164; +pub const SYS_getrusage = 165; +pub const SYS_umask = 166; +pub const SYS_prctl = 167; +pub const SYS_getcpu = 168; +pub const SYS_gettimeofday = 169; +pub const SYS_settimeofday = 170; +pub const SYS_adjtimex = 171; +pub const SYS_getpid = 172; +pub const SYS_getppid = 173; +pub const SYS_getuid = 174; +pub const SYS_geteuid = 175; +pub const SYS_getgid = 176; +pub const SYS_getegid = 177; +pub const SYS_gettid = 178; +pub const SYS_sysinfo = 179; +pub const SYS_mq_open = 180; +pub const SYS_mq_unlink = 181; +pub const SYS_mq_timedsend = 182; +pub const SYS_mq_timedreceive = 183; +pub const SYS_mq_notify = 184; +pub const SYS_mq_getsetattr = 185; +pub const SYS_msgget = 186; +pub const SYS_msgctl = 187; +pub const SYS_msgrcv = 188; +pub const SYS_msgsnd = 189; +pub const SYS_semget = 190; +pub const SYS_semctl = 191; +pub const SYS_semtimedop = 192; +pub const SYS_semop = 193; +pub const SYS_shmget = 194; +pub const SYS_shmctl = 195; +pub const SYS_shmat = 196; +pub const SYS_shmdt = 197; +pub const SYS_socket = 198; +pub const SYS_socketpair = 199; +pub const SYS_bind = 200; +pub const SYS_listen = 201; +pub const SYS_accept = 202; +pub const SYS_connect = 203; +pub const SYS_getsockname = 204; +pub const SYS_getpeername = 205; +pub const SYS_sendto = 206; +pub const SYS_recvfrom = 207; +pub const SYS_setsockopt = 208; +pub const SYS_getsockopt = 209; +pub const SYS_shutdown = 210; +pub const SYS_sendmsg = 211; +pub const SYS_recvmsg = 212; +pub const SYS_readahead = 213; +pub const SYS_brk = 214; +pub const SYS_munmap = 215; +pub const SYS_mremap = 216; +pub const SYS_add_key = 217; +pub const SYS_request_key = 218; +pub const SYS_keyctl = 219; +pub const SYS_clone = 220; +pub const SYS_execve = 221; +pub const SYS_mmap = 222; +pub const SYS_fadvise64 = 223; +pub const SYS_swapon = 224; +pub const SYS_swapoff = 225; +pub const SYS_mprotect = 226; +pub const SYS_msync = 227; +pub const SYS_mlock = 228; +pub const SYS_munlock = 229; +pub const SYS_mlockall = 230; +pub const SYS_munlockall = 231; +pub const SYS_mincore = 232; +pub const SYS_madvise = 233; +pub const SYS_remap_file_pages = 234; +pub const SYS_mbind = 235; +pub const SYS_get_mempolicy = 236; +pub const SYS_set_mempolicy = 237; +pub const SYS_migrate_pages = 238; +pub const SYS_move_pages = 239; +pub const SYS_rt_tgsigqueueinfo = 240; +pub const SYS_perf_event_open = 241; +pub const SYS_accept4 = 242; +pub const SYS_recvmmsg = 243; +pub const SYS_arch_specific_syscall = 244; +pub const SYS_wait4 = 260; +pub const SYS_prlimit64 = 261; +pub const SYS_fanotify_init = 262; +pub const SYS_fanotify_mark = 263; +pub const SYS_clock_adjtime = 266; +pub const SYS_syncfs = 267; +pub const SYS_setns = 268; +pub const SYS_sendmmsg = 269; +pub const SYS_process_vm_readv = 270; +pub const SYS_process_vm_writev = 271; +pub const SYS_kcmp = 272; +pub const SYS_finit_module = 273; +pub const SYS_sched_setattr = 274; +pub const SYS_sched_getattr = 275; +pub const SYS_renameat2 = 276; +pub const SYS_seccomp = 277; +pub const SYS_getrandom = 278; +pub const SYS_memfd_create = 279; +pub const SYS_bpf = 280; +pub const SYS_execveat = 281; +pub const SYS_userfaultfd = 282; +pub const SYS_membarrier = 283; +pub const SYS_mlock2 = 284; +pub const SYS_copy_file_range = 285; +pub const SYS_preadv2 = 286; +pub const SYS_pwritev2 = 287; +pub const SYS_pkey_mprotect = 288; +pub const SYS_pkey_alloc = 289; +pub const SYS_pkey_free = 290; +pub const SYS_statx = 291; +pub const SYS_io_pgetevents = 292; +pub const SYS_rseq = 293; +pub const SYS_kexec_file_load = 294; +pub const SYS_pidfd_send_signal = 424; +pub const SYS_io_uring_setup = 425; +pub const SYS_io_uring_enter = 426; +pub const SYS_io_uring_register = 427; +pub const SYS_open_tree = 428; +pub const SYS_move_mount = 429; +pub const SYS_fsopen = 430; +pub const SYS_fsconfig = 431; +pub const SYS_fsmount = 432; +pub const SYS_fspick = 433; +pub const SYS_pidfd_open = 434; +pub const SYS_clone3 = 435; + +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o40000; +pub const O_NOFOLLOW = 0o100000; +pub const O_CLOEXEC = 0o2000000; + +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o200000; +pub const O_LARGEFILE = 0o400000; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20040000; +pub const O_NDELAY = O_NONBLOCK; + +pub const F_DUPFD = 0; +pub const F_GETFD = 1; +pub const F_SETFD = 2; +pub const F_GETFL = 3; +pub const F_SETFL = 4; + +pub const F_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_GETLK = 5; +pub const F_SETLK = 6; +pub const F_SETLKW = 7; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; + +/// stack-like segment +pub const MAP_GROWSDOWN = 0x0100; + +/// ETXTBSY +pub const MAP_DENYWRITE = 0x0800; + +/// mark it as an executable +pub const MAP_EXECUTABLE = 0x1000; + +/// pages are locked +pub const MAP_LOCKED = 0x2000; + +/// don't check for reservations +pub const MAP_NORESERVE = 0x4000; + +pub const VDSO_USEFUL = true; +pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; +pub const VDSO_CGT_VER = "LINUX_2.6.39"; + +pub const msghdr = extern struct { + msg_name: ?*sockaddr, + msg_namelen: socklen_t, + msg_iov: [*]iovec, + msg_iovlen: i32, + __pad1: i32, + msg_control: ?*c_void, + msg_controllen: socklen_t, + __pad2: socklen_t, + msg_flags: i32, +}; + +pub const msghdr_const = extern struct { + msg_name: ?*const sockaddr, + msg_namelen: socklen_t, + msg_iov: [*]iovec_const, + msg_iovlen: i32, + __pad1: i32, + msg_control: ?*c_void, + msg_controllen: socklen_t, + __pad2: socklen_t, + msg_flags: i32, +}; + +pub const blksize_t = i32; +pub const nlink_t = u32; +pub const time_t = isize; +pub const mode_t = u32; +pub const off_t = isize; +pub const ino_t = usize; +pub const dev_t = usize; +pub const blkcnt_t = isize; + +/// Renamed to Stat to not conflict with the stat function. +/// atime, mtime, and ctime have functions to return `timespec`, +/// because although this is a POSIX API, the layout and names of +/// the structs are inconsistent across operating systems, and +/// in C, macros are used to hide the differences. Here we use +/// methods to accomplish this. +pub const Stat = extern struct { + dev: dev_t, + ino: ino_t, + mode: mode_t, + nlink: nlink_t, + uid: uid_t, + gid: gid_t, + rdev: dev_t, + __pad: usize, + size: off_t, + blksize: blksize_t, + __pad2: i32, + blocks: blkcnt_t, + atim: timespec, + mtim: timespec, + ctim: timespec, + __unused: [2]u32, + + pub fn atime(self: Stat) timespec { + return self.atim; + } + + pub fn mtime(self: Stat) timespec { + return self.mtim; + } + + pub fn ctime(self: Stat) timespec { + return self.ctim; + } +}; + +pub const timespec = extern struct { + tv_sec: time_t, + tv_nsec: isize, +}; + +pub const timeval = extern struct { + tv_sec: isize, + tv_usec: isize, +}; + +pub const timezone = extern struct { + tz_minuteswest: i32, + tz_dsttime: i32, +}; + +pub const Elf_Symndx = u32; diff --git a/lib/std/os/bits/linux/errno.zig b/lib/std/os/bits/linux/errno.zig new file mode 100644 index 0000000000..741f76fdee --- /dev/null +++ b/lib/std/os/bits/linux/errno.zig @@ -0,0 +1,428 @@ +/// Operation not permitted +pub const EPERM = 1; + +/// No such file or directory +pub const ENOENT = 2; + +/// No such process +pub const ESRCH = 3; + +/// Interrupted system call +pub const EINTR = 4; + +/// I/O error +pub const EIO = 5; + +/// No such device or address +pub const ENXIO = 6; + +/// Arg list too long +pub const E2BIG = 7; + +/// Exec format error +pub const ENOEXEC = 8; + +/// Bad file number +pub const EBADF = 9; + +/// No child processes +pub const ECHILD = 10; + +/// Try again +pub const EAGAIN = 11; + +/// Out of memory +pub const ENOMEM = 12; + +/// Permission denied +pub const EACCES = 13; + +/// Bad address +pub const EFAULT = 14; + +/// Block device required +pub const ENOTBLK = 15; + +/// Device or resource busy +pub const EBUSY = 16; + +/// File exists +pub const EEXIST = 17; + +/// Cross-device link +pub const EXDEV = 18; + +/// No such device +pub const ENODEV = 19; + +/// Not a directory +pub const ENOTDIR = 20; + +/// Is a directory +pub const EISDIR = 21; + +/// Invalid argument +pub const EINVAL = 22; + +/// File table overflow +pub const ENFILE = 23; + +/// Too many open files +pub const EMFILE = 24; + +/// Not a typewriter +pub const ENOTTY = 25; + +/// Text file busy +pub const ETXTBSY = 26; + +/// File too large +pub const EFBIG = 27; + +/// No space left on device +pub const ENOSPC = 28; + +/// Illegal seek +pub const ESPIPE = 29; + +/// Read-only file system +pub const EROFS = 30; + +/// Too many links +pub const EMLINK = 31; + +/// Broken pipe +pub const EPIPE = 32; + +/// Math argument out of domain of func +pub const EDOM = 33; + +/// Math result not representable +pub const ERANGE = 34; + +/// Resource deadlock would occur +pub const EDEADLK = 35; + +/// File name too long +pub const ENAMETOOLONG = 36; + +/// No record locks available +pub const ENOLCK = 37; + +/// Function not implemented +pub const ENOSYS = 38; + +/// Directory not empty +pub const ENOTEMPTY = 39; + +/// Too many symbolic links encountered +pub const ELOOP = 40; + +/// Operation would block +pub const EWOULDBLOCK = EAGAIN; + +/// No message of desired type +pub const ENOMSG = 42; + +/// Identifier removed +pub const EIDRM = 43; + +/// Channel number out of range +pub const ECHRNG = 44; + +/// Level 2 not synchronized +pub const EL2NSYNC = 45; + +/// Level 3 halted +pub const EL3HLT = 46; + +/// Level 3 reset +pub const EL3RST = 47; + +/// Link number out of range +pub const ELNRNG = 48; + +/// Protocol driver not attached +pub const EUNATCH = 49; + +/// No CSI structure available +pub const ENOCSI = 50; + +/// Level 2 halted +pub const EL2HLT = 51; + +/// Invalid exchange +pub const EBADE = 52; + +/// Invalid request descriptor +pub const EBADR = 53; + +/// Exchange full +pub const EXFULL = 54; + +/// No anode +pub const ENOANO = 55; + +/// Invalid request code +pub const EBADRQC = 56; + +/// Invalid slot +pub const EBADSLT = 57; + +/// Bad font file format +pub const EBFONT = 59; + +/// Device not a stream +pub const ENOSTR = 60; + +/// No data available +pub const ENODATA = 61; + +/// Timer expired +pub const ETIME = 62; + +/// Out of streams resources +pub const ENOSR = 63; + +/// Machine is not on the network +pub const ENONET = 64; + +/// Package not installed +pub const ENOPKG = 65; + +/// Object is remote +pub const EREMOTE = 66; + +/// Link has been severed +pub const ENOLINK = 67; + +/// Advertise error +pub const EADV = 68; + +/// Srmount error +pub const ESRMNT = 69; + +/// Communication error on send +pub const ECOMM = 70; + +/// Protocol error +pub const EPROTO = 71; + +/// Multihop attempted +pub const EMULTIHOP = 72; + +/// RFS specific error +pub const EDOTDOT = 73; + +/// Not a data message +pub const EBADMSG = 74; + +/// Value too large for defined data type +pub const EOVERFLOW = 75; + +/// Name not unique on network +pub const ENOTUNIQ = 76; + +/// File descriptor in bad state +pub const EBADFD = 77; + +/// Remote address changed +pub const EREMCHG = 78; + +/// Can not access a needed shared library +pub const ELIBACC = 79; + +/// Accessing a corrupted shared library +pub const ELIBBAD = 80; + +/// .lib section in a.out corrupted +pub const ELIBSCN = 81; + +/// Attempting to link in too many shared libraries +pub const ELIBMAX = 82; + +/// Cannot exec a shared library directly +pub const ELIBEXEC = 83; + +/// Illegal byte sequence +pub const EILSEQ = 84; + +/// Interrupted system call should be restarted +pub const ERESTART = 85; + +/// Streams pipe error +pub const ESTRPIPE = 86; + +/// Too many users +pub const EUSERS = 87; + +/// Socket operation on non-socket +pub const ENOTSOCK = 88; + +/// Destination address required +pub const EDESTADDRREQ = 89; + +/// Message too long +pub const EMSGSIZE = 90; + +/// Protocol wrong type for socket +pub const EPROTOTYPE = 91; + +/// Protocol not available +pub const ENOPROTOOPT = 92; + +/// Protocol not supported +pub const EPROTONOSUPPORT = 93; + +/// Socket type not supported +pub const ESOCKTNOSUPPORT = 94; + +/// Operation not supported on transport endpoint +pub const EOPNOTSUPP = 95; +pub const ENOTSUP = EOPNOTSUPP; + +/// Protocol family not supported +pub const EPFNOSUPPORT = 96; + +/// Address family not supported by protocol +pub const EAFNOSUPPORT = 97; + +/// Address already in use +pub const EADDRINUSE = 98; + +/// Cannot assign requested address +pub const EADDRNOTAVAIL = 99; + +/// Network is down +pub const ENETDOWN = 100; + +/// Network is unreachable +pub const ENETUNREACH = 101; + +/// Network dropped connection because of reset +pub const ENETRESET = 102; + +/// Software caused connection abort +pub const ECONNABORTED = 103; + +/// Connection reset by peer +pub const ECONNRESET = 104; + +/// No buffer space available +pub const ENOBUFS = 105; + +/// Transport endpoint is already connected +pub const EISCONN = 106; + +/// Transport endpoint is not connected +pub const ENOTCONN = 107; + +/// Cannot send after transport endpoint shutdown +pub const ESHUTDOWN = 108; + +/// Too many references: cannot splice +pub const ETOOMANYREFS = 109; + +/// Connection timed out +pub const ETIMEDOUT = 110; + +/// Connection refused +pub const ECONNREFUSED = 111; + +/// Host is down +pub const EHOSTDOWN = 112; + +/// No route to host +pub const EHOSTUNREACH = 113; + +/// Operation already in progress +pub const EALREADY = 114; + +/// Operation now in progress +pub const EINPROGRESS = 115; + +/// Stale NFS file handle +pub const ESTALE = 116; + +/// Structure needs cleaning +pub const EUCLEAN = 117; + +/// Not a XENIX named type file +pub const ENOTNAM = 118; + +/// No XENIX semaphores available +pub const ENAVAIL = 119; + +/// Is a named type file +pub const EISNAM = 120; + +/// Remote I/O error +pub const EREMOTEIO = 121; + +/// Quota exceeded +pub const EDQUOT = 122; + +/// No medium found +pub const ENOMEDIUM = 123; + +/// Wrong medium type +pub const EMEDIUMTYPE = 124; + +// nameserver query return codes + +/// DNS server returned answer with no data +pub const ENSROK = 0; + +/// DNS server returned answer with no data +pub const ENSRNODATA = 160; + +/// DNS server claims query was misformatted +pub const ENSRFORMERR = 161; + +/// DNS server returned general failure +pub const ENSRSERVFAIL = 162; + +/// Domain name not found +pub const ENSRNOTFOUND = 163; + +/// DNS server does not implement requested operation +pub const ENSRNOTIMP = 164; + +/// DNS server refused query +pub const ENSRREFUSED = 165; + +/// Misformatted DNS query +pub const ENSRBADQUERY = 166; + +/// Misformatted domain name +pub const ENSRBADNAME = 167; + +/// Unsupported address family +pub const ENSRBADFAMILY = 168; + +/// Misformatted DNS reply +pub const ENSRBADRESP = 169; + +/// Could not contact DNS servers +pub const ENSRCONNREFUSED = 170; + +/// Timeout while contacting DNS servers +pub const ENSRTIMEOUT = 171; + +/// End of file +pub const ENSROF = 172; + +/// Error reading file +pub const ENSRFILE = 173; + +/// Out of memory +pub const ENSRNOMEM = 174; + +/// Application terminated lookup +pub const ENSRDESTRUCTION = 175; + +/// Domain name is too long +pub const ENSRQUERYDOMAINTOOLONG = 176; + +/// Domain name is too long +pub const ENSRCNAMELOOP = 177; diff --git a/lib/std/os/bits/linux/riscv64.zig b/lib/std/os/bits/linux/riscv64.zig new file mode 100644 index 0000000000..e0c10ef7c0 --- /dev/null +++ b/lib/std/os/bits/linux/riscv64.zig @@ -0,0 +1,390 @@ +// riscv64-specific declarations that are intended to be imported into the POSIX namespace. +const std = @import("../../../std.zig"); +const uid_t = std.os.linux.uid_t; +const gid_t = std.os.linux.gid_t; + +pub const SYS_io_setup = 0; +pub const SYS_io_destroy = 1; +pub const SYS_io_submit = 2; +pub const SYS_io_cancel = 3; +pub const SYS_io_getevents = 4; +pub const SYS_setxattr = 5; +pub const SYS_lsetxattr = 6; +pub const SYS_fsetxattr = 7; +pub const SYS_getxattr = 8; +pub const SYS_lgetxattr = 9; +pub const SYS_fgetxattr = 10; +pub const SYS_listxattr = 11; +pub const SYS_llistxattr = 12; +pub const SYS_flistxattr = 13; +pub const SYS_removexattr = 14; +pub const SYS_lremovexattr = 15; +pub const SYS_fremovexattr = 16; +pub const SYS_getcwd = 17; +pub const SYS_lookup_dcookie = 18; +pub const SYS_eventfd2 = 19; +pub const SYS_epoll_create1 = 20; +pub const SYS_epoll_ctl = 21; +pub const SYS_epoll_pwait = 22; +pub const SYS_dup = 23; +pub const SYS_dup3 = 24; +pub const SYS_fcntl = 25; +pub const SYS_inotify_init1 = 26; +pub const SYS_inotify_add_watch = 27; +pub const SYS_inotify_rm_watch = 28; +pub const SYS_ioctl = 29; +pub const SYS_ioprio_set = 30; +pub const SYS_ioprio_get = 31; +pub const SYS_flock = 32; +pub const SYS_mknodat = 33; +pub const SYS_mkdirat = 34; +pub const SYS_unlinkat = 35; +pub const SYS_symlinkat = 36; +pub const SYS_linkat = 37; +pub const SYS_umount2 = 39; +pub const SYS_mount = 40; +pub const SYS_pivot_root = 41; +pub const SYS_nfsservctl = 42; +pub const SYS_statfs = 43; +pub const SYS_fstatfs = 44; +pub const SYS_truncate = 45; +pub const SYS_ftruncate = 46; +pub const SYS_fallocate = 47; +pub const SYS_faccessat = 48; +pub const SYS_chdir = 49; +pub const SYS_fchdir = 50; +pub const SYS_chroot = 51; +pub const SYS_fchmod = 52; +pub const SYS_fchmodat = 53; +pub const SYS_fchownat = 54; +pub const SYS_fchown = 55; +pub const SYS_openat = 56; +pub const SYS_close = 57; +pub const SYS_vhangup = 58; +pub const SYS_pipe2 = 59; +pub const SYS_quotactl = 60; +pub const SYS_getdents64 = 61; +pub const SYS_lseek = 62; +pub const SYS_read = 63; +pub const SYS_write = 64; +pub const SYS_readv = 65; +pub const SYS_writev = 66; +pub const SYS_pread64 = 67; +pub const SYS_pwrite64 = 68; +pub const SYS_preadv = 69; +pub const SYS_pwritev = 70; +pub const SYS_sendfile = 71; +pub const SYS_pselect6 = 72; +pub const SYS_ppoll = 73; +pub const SYS_signalfd4 = 74; +pub const SYS_vmsplice = 75; +pub const SYS_splice = 76; +pub const SYS_tee = 77; +pub const SYS_readlinkat = 78; +pub const SYS_fstatat = 79; +pub const SYS_fstat = 80; +pub const SYS_sync = 81; +pub const SYS_fsync = 82; +pub const SYS_fdatasync = 83; +pub const SYS_sync_file_range = 84; +pub const SYS_timerfd_create = 85; +pub const SYS_timerfd_settime = 86; +pub const SYS_timerfd_gettime = 87; +pub const SYS_utimensat = 88; +pub const SYS_acct = 89; +pub const SYS_capget = 90; +pub const SYS_capset = 91; +pub const SYS_personality = 92; +pub const SYS_exit = 93; +pub const SYS_exit_group = 94; +pub const SYS_waitid = 95; +pub const SYS_set_tid_address = 96; +pub const SYS_unshare = 97; +pub const SYS_futex = 98; +pub const SYS_set_robust_list = 99; +pub const SYS_get_robust_list = 100; +pub const SYS_nanosleep = 101; +pub const SYS_getitimer = 102; +pub const SYS_setitimer = 103; +pub const SYS_kexec_load = 104; +pub const SYS_init_module = 105; +pub const SYS_delete_module = 106; +pub const SYS_timer_create = 107; +pub const SYS_timer_gettime = 108; +pub const SYS_timer_getoverrun = 109; +pub const SYS_timer_settime = 110; +pub const SYS_timer_delete = 111; +pub const SYS_clock_settime = 112; +pub const SYS_clock_gettime = 113; +pub const SYS_clock_getres = 114; +pub const SYS_clock_nanosleep = 115; +pub const SYS_syslog = 116; +pub const SYS_ptrace = 117; +pub const SYS_sched_setparam = 118; +pub const SYS_sched_setscheduler = 119; +pub const SYS_sched_getscheduler = 120; +pub const SYS_sched_getparam = 121; +pub const SYS_sched_setaffinity = 122; +pub const SYS_sched_getaffinity = 123; +pub const SYS_sched_yield = 124; +pub const SYS_sched_get_priority_max = 125; +pub const SYS_sched_get_priority_min = 126; +pub const SYS_sched_rr_get_interval = 127; +pub const SYS_restart_syscall = 128; +pub const SYS_kill = 129; +pub const SYS_tkill = 130; +pub const SYS_tgkill = 131; +pub const SYS_sigaltstack = 132; +pub const SYS_rt_sigsuspend = 133; +pub const SYS_rt_sigaction = 134; +pub const SYS_rt_sigprocmask = 135; +pub const SYS_rt_sigpending = 136; +pub const SYS_rt_sigtimedwait = 137; +pub const SYS_rt_sigqueueinfo = 138; +pub const SYS_rt_sigreturn = 139; +pub const SYS_setpriority = 140; +pub const SYS_getpriority = 141; +pub const SYS_reboot = 142; +pub const SYS_setregid = 143; +pub const SYS_setgid = 144; +pub const SYS_setreuid = 145; +pub const SYS_setuid = 146; +pub const SYS_setresuid = 147; +pub const SYS_getresuid = 148; +pub const SYS_setresgid = 149; +pub const SYS_getresgid = 150; +pub const SYS_setfsuid = 151; +pub const SYS_setfsgid = 152; +pub const SYS_times = 153; +pub const SYS_setpgid = 154; +pub const SYS_getpgid = 155; +pub const SYS_getsid = 156; +pub const SYS_setsid = 157; +pub const SYS_getgroups = 158; +pub const SYS_setgroups = 159; +pub const SYS_uname = 160; +pub const SYS_sethostname = 161; +pub const SYS_setdomainname = 162; +pub const SYS_getrlimit = 163; +pub const SYS_setrlimit = 164; +pub const SYS_getrusage = 165; +pub const SYS_umask = 166; +pub const SYS_prctl = 167; +pub const SYS_getcpu = 168; +pub const SYS_gettimeofday = 169; +pub const SYS_settimeofday = 170; +pub const SYS_adjtimex = 171; +pub const SYS_getpid = 172; +pub const SYS_getppid = 173; +pub const SYS_getuid = 174; +pub const SYS_geteuid = 175; +pub const SYS_getgid = 176; +pub const SYS_getegid = 177; +pub const SYS_gettid = 178; +pub const SYS_sysinfo = 179; +pub const SYS_mq_open = 180; +pub const SYS_mq_unlink = 181; +pub const SYS_mq_timedsend = 182; +pub const SYS_mq_timedreceive = 183; +pub const SYS_mq_notify = 184; +pub const SYS_mq_getsetattr = 185; +pub const SYS_msgget = 186; +pub const SYS_msgctl = 187; +pub const SYS_msgrcv = 188; +pub const SYS_msgsnd = 189; +pub const SYS_semget = 190; +pub const SYS_semctl = 191; +pub const SYS_semtimedop = 192; +pub const SYS_semop = 193; +pub const SYS_shmget = 194; +pub const SYS_shmctl = 195; +pub const SYS_shmat = 196; +pub const SYS_shmdt = 197; +pub const SYS_socket = 198; +pub const SYS_socketpair = 199; +pub const SYS_bind = 200; +pub const SYS_listen = 201; +pub const SYS_accept = 202; +pub const SYS_connect = 203; +pub const SYS_getsockname = 204; +pub const SYS_getpeername = 205; +pub const SYS_sendto = 206; +pub const SYS_recvfrom = 207; +pub const SYS_setsockopt = 208; +pub const SYS_getsockopt = 209; +pub const SYS_shutdown = 210; +pub const SYS_sendmsg = 211; +pub const SYS_recvmsg = 212; +pub const SYS_readahead = 213; +pub const SYS_brk = 214; +pub const SYS_munmap = 215; +pub const SYS_mremap = 216; +pub const SYS_add_key = 217; +pub const SYS_request_key = 218; +pub const SYS_keyctl = 219; +pub const SYS_clone = 220; +pub const SYS_execve = 221; +pub const SYS_mmap = 222; +pub const SYS_fadvise64 = 223; +pub const SYS_swapon = 224; +pub const SYS_swapoff = 225; +pub const SYS_mprotect = 226; +pub const SYS_msync = 227; +pub const SYS_mlock = 228; +pub const SYS_munlock = 229; +pub const SYS_mlockall = 230; +pub const SYS_munlockall = 231; +pub const SYS_mincore = 232; +pub const SYS_madvise = 233; +pub const SYS_remap_file_pages = 234; +pub const SYS_mbind = 235; +pub const SYS_get_mempolicy = 236; +pub const SYS_set_mempolicy = 237; +pub const SYS_migrate_pages = 238; +pub const SYS_move_pages = 239; +pub const SYS_rt_tgsigqueueinfo = 240; +pub const SYS_perf_event_open = 241; +pub const SYS_accept4 = 242; +pub const SYS_recvmmsg = 243; + +pub const SYS_arch_specific_syscall = 244; +pub const SYS_riscv_flush_icache = SYS_arch_specific_syscall + 15; + +pub const SYS_wait4 = 260; +pub const SYS_prlimit64 = 261; +pub const SYS_fanotify_init = 262; +pub const SYS_fanotify_mark = 263; +pub const SYS_name_to_handle_at = 264; +pub const SYS_open_by_handle_at = 265; +pub const SYS_clock_adjtime = 266; +pub const SYS_syncfs = 267; +pub const SYS_setns = 268; +pub const SYS_sendmmsg = 269; +pub const SYS_process_vm_readv = 270; +pub const SYS_process_vm_writev = 271; +pub const SYS_kcmp = 272; +pub const SYS_finit_module = 273; +pub const SYS_sched_setattr = 274; +pub const SYS_sched_getattr = 275; +pub const SYS_renameat2 = 276; +pub const SYS_seccomp = 277; +pub const SYS_getrandom = 278; +pub const SYS_memfd_create = 279; +pub const SYS_bpf = 280; +pub const SYS_execveat = 281; +pub const SYS_userfaultfd = 282; +pub const SYS_membarrier = 283; +pub const SYS_mlock2 = 284; +pub const SYS_copy_file_range = 285; +pub const SYS_preadv2 = 286; +pub const SYS_pwritev2 = 287; +pub const SYS_pkey_mprotect = 288; +pub const SYS_pkey_alloc = 289; +pub const SYS_pkey_free = 290; +pub const SYS_statx = 291; +pub const SYS_io_pgetevents = 292; +pub const SYS_rseq = 293; +pub const SYS_kexec_file_load = 294; +pub const SYS_pidfd_send_signal = 424; +pub const SYS_io_uring_setup = 425; +pub const SYS_io_uring_enter = 426; +pub const SYS_io_uring_register = 427; +pub const SYS_open_tree = 428; +pub const SYS_move_mount = 429; +pub const SYS_fsopen = 430; +pub const SYS_fsconfig = 431; +pub const SYS_fsmount = 432; +pub const SYS_fspick = 433; +pub const SYS_pidfd_open = 434; +pub const SYS_clone3 = 435; + +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o200000; +pub const O_NOFOLLOW = 0o400000; +pub const O_CLOEXEC = 0o2000000; + +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o40000; +pub const O_LARGEFILE = 0o100000; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20200000; +pub const O_NDELAY = O_NONBLOCK; + +pub const F_DUPFD = 0; +pub const F_GETFD = 1; +pub const F_SETFD = 2; +pub const F_GETFL = 3; +pub const F_SETFL = 4; +pub const F_GETLK = 5; +pub const F_SETLK = 6; +pub const F_SETLKW = 7; +pub const F_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; + +pub const blksize_t = i32; +pub const nlink_t = u32; +pub const time_t = isize; +pub const mode_t = u32; +pub const off_t = isize; +pub const ino_t = usize; +pub const dev_t = usize; +pub const blkcnt_t = isize; +pub const timespec = extern struct { + tv_sec: time_t, + tv_nsec: isize, +}; + +/// Renamed to Stat to not conflict with the stat function. +/// atime, mtime, and ctime have functions to return `timespec`, +/// because although this is a POSIX API, the layout and names of +/// the structs are inconsistent across operating systems, and +/// in C, macros are used to hide the differences. Here we use +/// methods to accomplish this. +pub const Stat = extern struct { + dev: dev_t, + ino: ino_t, + mode: mode_t, + nlink: nlink_t, + uid: uid_t, + gid: gid_t, + rdev: dev_t, + __pad: usize, + size: off_t, + blksize: blksize_t, + __pad2: i32, + blocks: blkcnt_t, + atim: timespec, + mtim: timespec, + ctim: timespec, + __unused: [2]u32, + + pub fn atime(self: Stat) timespec { + return self.atim; + } + + pub fn mtime(self: Stat) timespec { + return self.mtim; + } + + pub fn ctime(self: Stat) timespec { + return self.ctim; + } +}; + +pub const Elf_Symndx = u32; diff --git a/lib/std/os/bits/linux/x86_64.zig b/lib/std/os/bits/linux/x86_64.zig new file mode 100644 index 0000000000..626acd00d6 --- /dev/null +++ b/lib/std/os/bits/linux/x86_64.zig @@ -0,0 +1,663 @@ +// x86-64-specific declarations that are intended to be imported into the POSIX namespace. +const std = @import("../../../std.zig"); +const pid_t = linux.pid_t; +const uid_t = linux.uid_t; +const clock_t = linux.clock_t; +const stack_t = linux.stack_t; +const sigset_t = linux.sigset_t; + +const linux = std.os.linux; +const sockaddr = linux.sockaddr; +const socklen_t = linux.socklen_t; +const iovec = linux.iovec; +const iovec_const = linux.iovec_const; + +pub const SYS_read = 0; +pub const SYS_write = 1; +pub const SYS_open = 2; +pub const SYS_close = 3; +pub const SYS_stat = 4; +pub const SYS_fstat = 5; +pub const SYS_lstat = 6; +pub const SYS_poll = 7; +pub const SYS_lseek = 8; +pub const SYS_mmap = 9; +pub const SYS_mprotect = 10; +pub const SYS_munmap = 11; +pub const SYS_brk = 12; +pub const SYS_rt_sigaction = 13; +pub const SYS_rt_sigprocmask = 14; +pub const SYS_rt_sigreturn = 15; +pub const SYS_ioctl = 16; +pub const SYS_pread = 17; +pub const SYS_pwrite = 18; +pub const SYS_readv = 19; +pub const SYS_writev = 20; +pub const SYS_access = 21; +pub const SYS_pipe = 22; +pub const SYS_select = 23; +pub const SYS_sched_yield = 24; +pub const SYS_mremap = 25; +pub const SYS_msync = 26; +pub const SYS_mincore = 27; +pub const SYS_madvise = 28; +pub const SYS_shmget = 29; +pub const SYS_shmat = 30; +pub const SYS_shmctl = 31; +pub const SYS_dup = 32; +pub const SYS_dup2 = 33; +pub const SYS_pause = 34; +pub const SYS_nanosleep = 35; +pub const SYS_getitimer = 36; +pub const SYS_alarm = 37; +pub const SYS_setitimer = 38; +pub const SYS_getpid = 39; +pub const SYS_sendfile = 40; +pub const SYS_socket = 41; +pub const SYS_connect = 42; +pub const SYS_accept = 43; +pub const SYS_sendto = 44; +pub const SYS_recvfrom = 45; +pub const SYS_sendmsg = 46; +pub const SYS_recvmsg = 47; +pub const SYS_shutdown = 48; +pub const SYS_bind = 49; +pub const SYS_listen = 50; +pub const SYS_getsockname = 51; +pub const SYS_getpeername = 52; +pub const SYS_socketpair = 53; +pub const SYS_setsockopt = 54; +pub const SYS_getsockopt = 55; +pub const SYS_clone = 56; +pub const SYS_fork = 57; +pub const SYS_vfork = 58; +pub const SYS_execve = 59; +pub const SYS_exit = 60; +pub const SYS_wait4 = 61; +pub const SYS_kill = 62; +pub const SYS_uname = 63; +pub const SYS_semget = 64; +pub const SYS_semop = 65; +pub const SYS_semctl = 66; +pub const SYS_shmdt = 67; +pub const SYS_msgget = 68; +pub const SYS_msgsnd = 69; +pub const SYS_msgrcv = 70; +pub const SYS_msgctl = 71; +pub const SYS_fcntl = 72; +pub const SYS_flock = 73; +pub const SYS_fsync = 74; +pub const SYS_fdatasync = 75; +pub const SYS_truncate = 76; +pub const SYS_ftruncate = 77; +pub const SYS_getdents = 78; +pub const SYS_getcwd = 79; +pub const SYS_chdir = 80; +pub const SYS_fchdir = 81; +pub const SYS_rename = 82; +pub const SYS_mkdir = 83; +pub const SYS_rmdir = 84; +pub const SYS_creat = 85; +pub const SYS_link = 86; +pub const SYS_unlink = 87; +pub const SYS_symlink = 88; +pub const SYS_readlink = 89; +pub const SYS_chmod = 90; +pub const SYS_fchmod = 91; +pub const SYS_chown = 92; +pub const SYS_fchown = 93; +pub const SYS_lchown = 94; +pub const SYS_umask = 95; +pub const SYS_gettimeofday = 96; +pub const SYS_getrlimit = 97; +pub const SYS_getrusage = 98; +pub const SYS_sysinfo = 99; +pub const SYS_times = 100; +pub const SYS_ptrace = 101; +pub const SYS_getuid = 102; +pub const SYS_syslog = 103; +pub const SYS_getgid = 104; +pub const SYS_setuid = 105; +pub const SYS_setgid = 106; +pub const SYS_geteuid = 107; +pub const SYS_getegid = 108; +pub const SYS_setpgid = 109; +pub const SYS_getppid = 110; +pub const SYS_getpgrp = 111; +pub const SYS_setsid = 112; +pub const SYS_setreuid = 113; +pub const SYS_setregid = 114; +pub const SYS_getgroups = 115; +pub const SYS_setgroups = 116; +pub const SYS_setresuid = 117; +pub const SYS_getresuid = 118; +pub const SYS_setresgid = 119; +pub const SYS_getresgid = 120; +pub const SYS_getpgid = 121; +pub const SYS_setfsuid = 122; +pub const SYS_setfsgid = 123; +pub const SYS_getsid = 124; +pub const SYS_capget = 125; +pub const SYS_capset = 126; +pub const SYS_rt_sigpending = 127; +pub const SYS_rt_sigtimedwait = 128; +pub const SYS_rt_sigqueueinfo = 129; +pub const SYS_rt_sigsuspend = 130; +pub const SYS_sigaltstack = 131; +pub const SYS_utime = 132; +pub const SYS_mknod = 133; +pub const SYS_uselib = 134; +pub const SYS_personality = 135; +pub const SYS_ustat = 136; +pub const SYS_statfs = 137; +pub const SYS_fstatfs = 138; +pub const SYS_sysfs = 139; +pub const SYS_getpriority = 140; +pub const SYS_setpriority = 141; +pub const SYS_sched_setparam = 142; +pub const SYS_sched_getparam = 143; +pub const SYS_sched_setscheduler = 144; +pub const SYS_sched_getscheduler = 145; +pub const SYS_sched_get_priority_max = 146; +pub const SYS_sched_get_priority_min = 147; +pub const SYS_sched_rr_get_interval = 148; +pub const SYS_mlock = 149; +pub const SYS_munlock = 150; +pub const SYS_mlockall = 151; +pub const SYS_munlockall = 152; +pub const SYS_vhangup = 153; +pub const SYS_modify_ldt = 154; +pub const SYS_pivot_root = 155; +pub const SYS__sysctl = 156; +pub const SYS_prctl = 157; +pub const SYS_arch_prctl = 158; +pub const SYS_adjtimex = 159; +pub const SYS_setrlimit = 160; +pub const SYS_chroot = 161; +pub const SYS_sync = 162; +pub const SYS_acct = 163; +pub const SYS_settimeofday = 164; +pub const SYS_mount = 165; +pub const SYS_umount2 = 166; +pub const SYS_swapon = 167; +pub const SYS_swapoff = 168; +pub const SYS_reboot = 169; +pub const SYS_sethostname = 170; +pub const SYS_setdomainname = 171; +pub const SYS_iopl = 172; +pub const SYS_ioperm = 173; +pub const SYS_create_module = 174; +pub const SYS_init_module = 175; +pub const SYS_delete_module = 176; +pub const SYS_get_kernel_syms = 177; +pub const SYS_query_module = 178; +pub const SYS_quotactl = 179; +pub const SYS_nfsservctl = 180; +pub const SYS_getpmsg = 181; +pub const SYS_putpmsg = 182; +pub const SYS_afs_syscall = 183; +pub const SYS_tuxcall = 184; +pub const SYS_security = 185; +pub const SYS_gettid = 186; +pub const SYS_readahead = 187; +pub const SYS_setxattr = 188; +pub const SYS_lsetxattr = 189; +pub const SYS_fsetxattr = 190; +pub const SYS_getxattr = 191; +pub const SYS_lgetxattr = 192; +pub const SYS_fgetxattr = 193; +pub const SYS_listxattr = 194; +pub const SYS_llistxattr = 195; +pub const SYS_flistxattr = 196; +pub const SYS_removexattr = 197; +pub const SYS_lremovexattr = 198; +pub const SYS_fremovexattr = 199; +pub const SYS_tkill = 200; +pub const SYS_time = 201; +pub const SYS_futex = 202; +pub const SYS_sched_setaffinity = 203; +pub const SYS_sched_getaffinity = 204; +pub const SYS_set_thread_area = 205; +pub const SYS_io_setup = 206; +pub const SYS_io_destroy = 207; +pub const SYS_io_getevents = 208; +pub const SYS_io_submit = 209; +pub const SYS_io_cancel = 210; +pub const SYS_get_thread_area = 211; +pub const SYS_lookup_dcookie = 212; +pub const SYS_epoll_create = 213; +pub const SYS_epoll_ctl_old = 214; +pub const SYS_epoll_wait_old = 215; +pub const SYS_remap_file_pages = 216; +pub const SYS_getdents64 = 217; +pub const SYS_set_tid_address = 218; +pub const SYS_restart_syscall = 219; +pub const SYS_semtimedop = 220; +pub const SYS_fadvise64 = 221; +pub const SYS_timer_create = 222; +pub const SYS_timer_settime = 223; +pub const SYS_timer_gettime = 224; +pub const SYS_timer_getoverrun = 225; +pub const SYS_timer_delete = 226; +pub const SYS_clock_settime = 227; +pub const SYS_clock_gettime = 228; +pub const SYS_clock_getres = 229; +pub const SYS_clock_nanosleep = 230; +pub const SYS_exit_group = 231; +pub const SYS_epoll_wait = 232; +pub const SYS_epoll_ctl = 233; +pub const SYS_tgkill = 234; +pub const SYS_utimes = 235; +pub const SYS_vserver = 236; +pub const SYS_mbind = 237; +pub const SYS_set_mempolicy = 238; +pub const SYS_get_mempolicy = 239; +pub const SYS_mq_open = 240; +pub const SYS_mq_unlink = 241; +pub const SYS_mq_timedsend = 242; +pub const SYS_mq_timedreceive = 243; +pub const SYS_mq_notify = 244; +pub const SYS_mq_getsetattr = 245; +pub const SYS_kexec_load = 246; +pub const SYS_waitid = 247; +pub const SYS_add_key = 248; +pub const SYS_request_key = 249; +pub const SYS_keyctl = 250; +pub const SYS_ioprio_set = 251; +pub const SYS_ioprio_get = 252; +pub const SYS_inotify_init = 253; +pub const SYS_inotify_add_watch = 254; +pub const SYS_inotify_rm_watch = 255; +pub const SYS_migrate_pages = 256; +pub const SYS_openat = 257; +pub const SYS_mkdirat = 258; +pub const SYS_mknodat = 259; +pub const SYS_fchownat = 260; +pub const SYS_futimesat = 261; +pub const SYS_newfstatat = 262; +pub const SYS_fstatat = 262; +pub const SYS_unlinkat = 263; +pub const SYS_renameat = 264; +pub const SYS_linkat = 265; +pub const SYS_symlinkat = 266; +pub const SYS_readlinkat = 267; +pub const SYS_fchmodat = 268; +pub const SYS_faccessat = 269; +pub const SYS_pselect6 = 270; +pub const SYS_ppoll = 271; +pub const SYS_unshare = 272; +pub const SYS_set_robust_list = 273; +pub const SYS_get_robust_list = 274; +pub const SYS_splice = 275; +pub const SYS_tee = 276; +pub const SYS_sync_file_range = 277; +pub const SYS_vmsplice = 278; +pub const SYS_move_pages = 279; +pub const SYS_utimensat = 280; +pub const SYS_epoll_pwait = 281; +pub const SYS_signalfd = 282; +pub const SYS_timerfd_create = 283; +pub const SYS_eventfd = 284; +pub const SYS_fallocate = 285; +pub const SYS_timerfd_settime = 286; +pub const SYS_timerfd_gettime = 287; +pub const SYS_accept4 = 288; +pub const SYS_signalfd4 = 289; +pub const SYS_eventfd2 = 290; +pub const SYS_epoll_create1 = 291; +pub const SYS_dup3 = 292; +pub const SYS_pipe2 = 293; +pub const SYS_inotify_init1 = 294; +pub const SYS_preadv = 295; +pub const SYS_pwritev = 296; +pub const SYS_rt_tgsigqueueinfo = 297; +pub const SYS_perf_event_open = 298; +pub const SYS_recvmmsg = 299; +pub const SYS_fanotify_init = 300; +pub const SYS_fanotify_mark = 301; +pub const SYS_prlimit64 = 302; +pub const SYS_name_to_handle_at = 303; +pub const SYS_open_by_handle_at = 304; +pub const SYS_clock_adjtime = 305; +pub const SYS_syncfs = 306; +pub const SYS_sendmmsg = 307; +pub const SYS_setns = 308; +pub const SYS_getcpu = 309; +pub const SYS_process_vm_readv = 310; +pub const SYS_process_vm_writev = 311; +pub const SYS_kcmp = 312; +pub const SYS_finit_module = 313; +pub const SYS_sched_setattr = 314; +pub const SYS_sched_getattr = 315; +pub const SYS_renameat2 = 316; +pub const SYS_seccomp = 317; +pub const SYS_getrandom = 318; +pub const SYS_memfd_create = 319; +pub const SYS_kexec_file_load = 320; +pub const SYS_bpf = 321; +pub const SYS_execveat = 322; +pub const SYS_userfaultfd = 323; +pub const SYS_membarrier = 324; +pub const SYS_mlock2 = 325; +pub const SYS_copy_file_range = 326; +pub const SYS_preadv2 = 327; +pub const SYS_pwritev2 = 328; +pub const SYS_pkey_mprotect = 329; +pub const SYS_pkey_alloc = 330; +pub const SYS_pkey_free = 331; +pub const SYS_statx = 332; +pub const SYS_io_pgetevents = 333; +pub const SYS_rseq = 334; +pub const SYS_pidfd_send_signal = 424; +pub const SYS_io_uring_setup = 425; +pub const SYS_io_uring_enter = 426; +pub const SYS_io_uring_register = 427; +pub const SYS_open_tree = 428; +pub const SYS_move_mount = 429; +pub const SYS_fsopen = 430; +pub const SYS_fsconfig = 431; +pub const SYS_fsmount = 432; +pub const SYS_fspick = 433; +pub const SYS_pidfd_open = 434; +pub const SYS_clone3 = 435; + +pub const O_CREAT = 0o100; +pub const O_EXCL = 0o200; +pub const O_NOCTTY = 0o400; +pub const O_TRUNC = 0o1000; +pub const O_APPEND = 0o2000; +pub const O_NONBLOCK = 0o4000; +pub const O_DSYNC = 0o10000; +pub const O_SYNC = 0o4010000; +pub const O_RSYNC = 0o4010000; +pub const O_DIRECTORY = 0o200000; +pub const O_NOFOLLOW = 0o400000; +pub const O_CLOEXEC = 0o2000000; + +pub const O_ASYNC = 0o20000; +pub const O_DIRECT = 0o40000; +pub const O_LARGEFILE = 0; +pub const O_NOATIME = 0o1000000; +pub const O_PATH = 0o10000000; +pub const O_TMPFILE = 0o20200000; +pub const O_NDELAY = O_NONBLOCK; + +pub const F_DUPFD = 0; +pub const F_GETFD = 1; +pub const F_SETFD = 2; +pub const F_GETFL = 3; +pub const F_SETFL = 4; + +pub const F_SETOWN = 8; +pub const F_GETOWN = 9; +pub const F_SETSIG = 10; +pub const F_GETSIG = 11; + +pub const F_GETLK = 5; +pub const F_SETLK = 6; +pub const F_SETLKW = 7; + +pub const F_SETOWN_EX = 15; +pub const F_GETOWN_EX = 16; + +pub const F_GETOWNER_UIDS = 17; + +/// only give out 32bit addresses +pub const MAP_32BIT = 0x40; + +/// stack-like segment +pub const MAP_GROWSDOWN = 0x0100; + +/// ETXTBSY +pub const MAP_DENYWRITE = 0x0800; + +/// mark it as an executable +pub const MAP_EXECUTABLE = 0x1000; + +/// pages are locked +pub const MAP_LOCKED = 0x2000; + +/// don't check for reservations +pub const MAP_NORESERVE = 0x4000; + +pub const VDSO_USEFUL = true; +pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; +pub const VDSO_CGT_VER = "LINUX_2.6"; +pub const VDSO_GETCPU_SYM = "__vdso_getcpu"; +pub const VDSO_GETCPU_VER = "LINUX_2.6"; + +pub const ARCH_SET_GS = 0x1001; +pub const ARCH_SET_FS = 0x1002; +pub const ARCH_GET_FS = 0x1003; +pub const ARCH_GET_GS = 0x1004; + +pub const REG_R8 = 0; +pub const REG_R9 = 1; +pub const REG_R10 = 2; +pub const REG_R11 = 3; +pub const REG_R12 = 4; +pub const REG_R13 = 5; +pub const REG_R14 = 6; +pub const REG_R15 = 7; +pub const REG_RDI = 8; +pub const REG_RSI = 9; +pub const REG_RBP = 10; +pub const REG_RBX = 11; +pub const REG_RDX = 12; +pub const REG_RAX = 13; +pub const REG_RCX = 14; +pub const REG_RSP = 15; +pub const REG_RIP = 16; +pub const REG_EFL = 17; +pub const REG_CSGSFS = 18; +pub const REG_ERR = 19; +pub const REG_TRAPNO = 20; +pub const REG_OLDMASK = 21; +pub const REG_CR2 = 22; + +pub const msghdr = extern struct { + msg_name: ?*sockaddr, + msg_namelen: socklen_t, + msg_iov: [*]iovec, + msg_iovlen: i32, + __pad1: i32, + msg_control: ?*c_void, + msg_controllen: socklen_t, + __pad2: socklen_t, + msg_flags: i32, +}; + +pub const msghdr_const = extern struct { + msg_name: ?*const sockaddr, + msg_namelen: socklen_t, + msg_iov: [*]iovec_const, + msg_iovlen: i32, + __pad1: i32, + msg_control: ?*c_void, + msg_controllen: socklen_t, + __pad2: socklen_t, + msg_flags: i32, +}; + +pub const off_t = i64; + +/// Renamed to Stat to not conflict with the stat function. +/// atime, mtime, and ctime have functions to return `timespec`, +/// because although this is a POSIX API, the layout and names of +/// the structs are inconsistent across operating systems, and +/// in C, macros are used to hide the differences. Here we use +/// methods to accomplish this. +pub const Stat = extern struct { + dev: u64, + ino: u64, + nlink: usize, + + mode: u32, + uid: u32, + gid: u32, + __pad0: u32, + rdev: u64, + size: off_t, + blksize: isize, + blocks: i64, + + atim: timespec, + mtim: timespec, + ctim: timespec, + __unused: [3]isize, + + pub fn atime(self: Stat) timespec { + return self.atim; + } + + pub fn mtime(self: Stat) timespec { + return self.mtim; + } + + pub fn ctime(self: Stat) timespec { + return self.ctim; + } +}; + +pub const timespec = extern struct { + tv_sec: isize, + tv_nsec: isize, +}; + +pub const timeval = extern struct { + tv_sec: isize, + tv_usec: isize, +}; + +pub const timezone = extern struct { + tz_minuteswest: i32, + tz_dsttime: i32, +}; + +pub const Elf_Symndx = u32; + +pub const sigval = extern union { + int: i32, + ptr: *c_void, +}; + +pub const siginfo_t = extern struct { + signo: i32, + errno: i32, + code: i32, + fields: extern union { + pad: [128 - 2 * @sizeOf(c_int) - @sizeOf(c_long)]u8, + common: extern struct { + first: extern union { + piduid: extern struct { + pid: pid_t, + uid: uid_t, + }, + timer: extern struct { + timerid: i32, + overrun: i32, + }, + }, + second: extern union { + value: sigval, + sigchld: extern struct { + status: i32, + utime: clock_t, + stime: clock_t, + }, + }, + }, + sigfault: extern struct { + addr: *c_void, + addr_lsb: i16, + first: extern union { + addr_bnd: extern struct { + lower: *c_void, + upper: *c_void, + }, + pkey: u32, + }, + }, + sigpoll: extern struct { + band: isize, + fd: i32, + }, + sigsys: extern struct { + call_addr: *c_void, + syscall: i32, + arch: u32, + }, + }, +}; + +pub const greg_t = usize; +pub const gregset_t = [23]greg_t; +pub const fpstate = extern struct { + cwd: u16, + swd: u16, + ftw: u16, + fop: u16, + rip: usize, + rdp: usize, + mxcsr: u32, + mxcr_mask: u32, + st: [8]extern struct { + significand: [4]u16, + exponent: u16, + padding: [3]u16 = undefined, + }, + xmm: [16]extern struct { + element: [4]u32, + }, + padding: [24]u32 = undefined, +}; +pub const fpregset_t = *fpstate; +pub const sigcontext = extern struct { + r8: usize, + r9: usize, + r10: usize, + r11: usize, + r12: usize, + r13: usize, + r14: usize, + r15: usize, + + rdi: usize, + rsi: usize, + rbp: usize, + rbx: usize, + rdx: usize, + rax: usize, + rcx: usize, + rsp: usize, + rip: usize, + eflags: usize, + + cs: u16, + gs: u16, + fs: u16, + pad0: u16 = undefined, + + err: usize, + trapno: usize, + oldmask: usize, + cr2: usize, + + fpstate: *fpstate, + reserved1: [8]usize = undefined, +}; + +pub const mcontext_t = extern struct { + gregs: gregset_t, + fpregs: fpregset_t, + reserved1: [8]usize = undefined, +}; + +pub const ucontext_t = extern struct { + flags: usize, + link: *ucontext_t, + stack: stack_t, + mcontext: mcontext_t, + sigmask: sigset_t, + fpregs_mem: [64]usize, +}; diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig new file mode 100644 index 0000000000..14c35faf6c --- /dev/null +++ b/lib/std/os/bits/netbsd.zig @@ -0,0 +1,825 @@ +const std = @import("../../std.zig"); +const maxInt = std.math.maxInt; + +pub const fd_t = c_int; +pub const pid_t = c_int; + +/// Renamed from `kevent` to `Kevent` to avoid conflict with function name. +pub const Kevent = extern struct { + ident: usize, + filter: i32, + flags: u32, + fflags: u32, + data: i64, + udata: usize, +}; + +pub const pthread_attr_t = extern struct { + pta_magic: u32, + pta_flags: c_int, + pta_private: *c_void, +}; + +pub const dl_phdr_info = extern struct { + dlpi_addr: usize, + dlpi_name: ?[*]const u8, + dlpi_phdr: [*]std.elf.Phdr, + dlpi_phnum: u16, +}; + +pub const msghdr = extern struct { + /// optional address + msg_name: ?*sockaddr, + + /// size of address + msg_namelen: socklen_t, + + /// scatter/gather array + msg_iov: [*]iovec, + + /// # elements in msg_iov + msg_iovlen: i32, + + /// ancillary data + msg_control: ?*c_void, + + /// ancillary data buffer len + msg_controllen: socklen_t, + + /// flags on received message + msg_flags: i32, +}; + +pub const msghdr_const = extern struct { + /// optional address + msg_name: ?*const sockaddr, + + /// size of address + msg_namelen: socklen_t, + + /// scatter/gather array + msg_iov: [*]iovec_const, + + /// # elements in msg_iov + msg_iovlen: i32, + + /// ancillary data + msg_control: ?*c_void, + + /// ancillary data buffer len + msg_controllen: socklen_t, + + /// flags on received message + msg_flags: i32, +}; + +pub const off_t = i64; + +/// Renamed to Stat to not conflict with the stat function. +/// atime, mtime, and ctime have functions to return `timespec`, +/// because although this is a POSIX API, the layout and names of +/// the structs are inconsistent across operating systems, and +/// in C, macros are used to hide the differences. Here we use +/// methods to accomplish this. +pub const Stat = extern struct { + dev: u64, + mode: u32, + ino: u64, + nlink: usize, + + uid: u32, + gid: u32, + rdev: u64, + + atim: timespec, + mtim: timespec, + ctim: timespec, + birthtim: timespec, + + size: off_t, + blocks: i64, + blksize: isize, + flags: u32, + gen: u32, + __spare: [2]u32, + + pub fn atime(self: Stat) timespec { + return self.atim; + } + + pub fn mtime(self: Stat) timespec { + return self.mtim; + } + + pub fn ctime(self: Stat) timespec { + return self.ctim; + } +}; + +pub const timespec = extern struct { + tv_sec: i64, + tv_nsec: isize, +}; + +pub const dirent = extern struct { + d_fileno: u64, + d_reclen: u16, + d_namlen: u16, + d_type: u8, + d_off: i64, + d_name: [512]u8, +}; + +pub const in_port_t = u16; +pub const sa_family_t = u8; + +pub const sockaddr = extern union { + in: sockaddr_in, + in6: sockaddr_in6, +}; + +pub const sockaddr_in = extern struct { + len: u8, + family: sa_family_t, + port: in_port_t, + addr: u32, + zero: [8]u8, +}; + +pub const sockaddr_in6 = extern struct { + len: u8, + family: sa_family_t, + port: in_port_t, + flowinfo: u32, + addr: [16]u8, + scope_id: u32, +}; + +pub const CTL_KERN = 1; +pub const CTL_DEBUG = 5; + +pub const KERN_PROC_ARGS = 48; // struct: process argv/env +pub const KERN_PROC_PATHNAME = 5; // path to executable + +pub const PATH_MAX = 1024; + +pub const STDIN_FILENO = 0; +pub const STDOUT_FILENO = 1; +pub const STDERR_FILENO = 2; + +pub const PROT_NONE = 0; +pub const PROT_READ = 1; +pub const PROT_WRITE = 2; +pub const PROT_EXEC = 4; + +pub const CLOCK_REALTIME = 0; +pub const CLOCK_VIRTUAL = 1; +pub const CLOCK_PROF = 2; +pub const CLOCK_MONOTONIC = 3; +pub const CLOCK_THREAD_CPUTIME_ID = 0x20000000; +pub const CLOCK_PROCESS_CPUTIME_ID = 0x40000000; + +pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize)); +pub const MAP_SHARED = 0x0001; +pub const MAP_PRIVATE = 0x0002; +pub const MAP_REMAPDUP = 0x0004; +pub const MAP_FIXED = 0x0010; +pub const MAP_RENAME = 0x0020; +pub const MAP_NORESERVE = 0x0040; +pub const MAP_INHERIT = 0x0080; +pub const MAP_HASSEMAPHORE = 0x0200; +pub const MAP_TRYFIXED = 0x0400; +pub const MAP_WIRED = 0x0800; + +pub const MAP_FILE = 0x0000; +pub const MAP_NOSYNC = 0x0800; +pub const MAP_ANON = 0x1000; +pub const MAP_ANONYMOUS = MAP_ANON; +pub const MAP_STACK = 0x2000; + +pub const WNOHANG = 0x00000001; +pub const WUNTRACED = 0x00000002; +pub const WSTOPPED = WUNTRACED; +pub const WCONTINUED = 0x00000010; +pub const WNOWAIT = 0x00010000; +pub const WEXITED = 0x00000020; +pub const WTRAPPED = 0x00000040; + +pub const SA_ONSTACK = 0x0001; +pub const SA_RESTART = 0x0002; +pub const SA_RESETHAND = 0x0004; +pub const SA_NOCLDSTOP = 0x0008; +pub const SA_NODEFER = 0x0010; +pub const SA_NOCLDWAIT = 0x0020; +pub const SA_SIGINFO = 0x0040; + +pub const SIGHUP = 1; +pub const SIGINT = 2; +pub const SIGQUIT = 3; +pub const SIGILL = 4; +pub const SIGTRAP = 5; +pub const SIGABRT = 6; +pub const SIGIOT = SIGABRT; +pub const SIGEMT = 7; +pub const SIGFPE = 8; +pub const SIGKILL = 9; +pub const SIGBUS = 10; +pub const SIGSEGV = 11; +pub const SIGSYS = 12; +pub const SIGPIPE = 13; +pub const SIGALRM = 14; +pub const SIGTERM = 15; +pub const SIGURG = 16; +pub const SIGSTOP = 17; +pub const SIGTSTP = 18; +pub const SIGCONT = 19; +pub const SIGCHLD = 20; +pub const SIGTTIN = 21; +pub const SIGTTOU = 22; +pub const SIGIO = 23; +pub const SIGXCPU = 24; +pub const SIGXFSZ = 25; +pub const SIGVTALRM = 26; +pub const SIGPROF = 27; +pub const SIGWINCH = 28; +pub const SIGINFO = 29; +pub const SIGUSR1 = 30; +pub const SIGUSR2 = 31; +pub const SIGPWR = 32; + +pub const SIGRTMIN = 33; +pub const SIGRTMAX = 63; + +// access function +pub const F_OK = 0; // test for existence of file +pub const X_OK = 1; // test for execute or search permission +pub const W_OK = 2; // test for write permission +pub const R_OK = 4; // test for read permission + +pub const O_RDONLY = 0x0000; +pub const O_WRONLY = 0x0001; +pub const O_RDWR = 0x0002; +pub const O_ACCMODE = 0x0003; + +pub const O_CREAT = 0x0200; +pub const O_EXCL = 0x0800; +pub const O_NOCTTY = 0x8000; +pub const O_TRUNC = 0x0400; +pub const O_APPEND = 0x0008; +pub const O_NONBLOCK = 0x0004; +pub const O_DSYNC = 0x00010000; +pub const O_SYNC = 0x0080; +pub const O_RSYNC = 0x00020000; +pub const O_DIRECTORY = 0x00080000; +pub const O_NOFOLLOW = 0x00000100; +pub const O_CLOEXEC = 0x00400000; + +pub const O_ASYNC = 0x0040; +pub const O_DIRECT = 0x00080000; +pub const O_LARGEFILE = 0; +pub const O_NOATIME = 0; +pub const O_PATH = 0; +pub const O_TMPFILE = 0; +pub const O_NDELAY = O_NONBLOCK; + +pub const F_DUPFD = 0; +pub const F_GETFD = 1; +pub const F_SETFD = 2; +pub const F_GETFL = 3; +pub const F_SETFL = 4; + +pub const F_GETOWN = 5; +pub const F_SETOWN = 6; + +pub const F_GETLK = 7; +pub const F_SETLK = 8; +pub const F_SETLKW = 9; + +pub const SEEK_SET = 0; +pub const SEEK_CUR = 1; +pub const SEEK_END = 2; + +pub const SIG_BLOCK = 1; +pub const SIG_UNBLOCK = 2; +pub const SIG_SETMASK = 3; + +pub const SOCK_STREAM = 1; +pub const SOCK_DGRAM = 2; +pub const SOCK_RAW = 3; +pub const SOCK_RDM = 4; +pub const SOCK_SEQPACKET = 5; + +pub const SOCK_CLOEXEC = 0x10000000; +pub const SOCK_NONBLOCK = 0x20000000; + +pub const PROTO_ip = 0; +pub const PROTO_icmp = 1; +pub const PROTO_igmp = 2; +pub const PROTO_ggp = 3; +pub const PROTO_ipencap = 4; +pub const PROTO_tcp = 6; +pub const PROTO_egp = 8; +pub const PROTO_pup = 12; +pub const PROTO_udp = 17; +pub const PROTO_xns_idp = 22; +pub const PROTO_iso_tp4 = 29; +pub const PROTO_ipv6 = 41; +pub const PROTO_ipv6_route = 43; +pub const PROTO_ipv6_frag = 44; +pub const PROTO_rsvp = 46; +pub const PROTO_gre = 47; +pub const PROTO_esp = 50; +pub const PROTO_ah = 51; +pub const PROTO_ipv6_icmp = 58; +pub const PROTO_ipv6_nonxt = 59; +pub const PROTO_ipv6_opts = 60; +pub const PROTO_encap = 98; +pub const PROTO_pim = 103; +pub const PROTO_raw = 255; + +pub const PF_UNSPEC = 0; +pub const PF_LOCAL = 1; +pub const PF_UNIX = PF_LOCAL; +pub const PF_FILE = PF_LOCAL; +pub const PF_INET = 2; +pub const PF_APPLETALK = 16; +pub const PF_INET6 = 24; +pub const PF_DECnet = 12; +pub const PF_KEY = 29; +pub const PF_ROUTE = 34; +pub const PF_SNA = 11; +pub const PF_MPLS = 33; +pub const PF_CAN = 35; +pub const PF_BLUETOOTH = 31; +pub const PF_ISDN = 26; +pub const PF_MAX = 37; + +pub const AF_UNSPEC = PF_UNSPEC; +pub const AF_LOCAL = PF_LOCAL; +pub const AF_UNIX = AF_LOCAL; +pub const AF_FILE = AF_LOCAL; +pub const AF_INET = PF_INET; +pub const AF_APPLETALK = PF_APPLETALK; +pub const AF_INET6 = PF_INET6; +pub const AF_KEY = PF_KEY; +pub const AF_ROUTE = PF_ROUTE; +pub const AF_SNA = PF_SNA; +pub const AF_MPLS = PF_MPLS; +pub const AF_CAN = PF_CAN; +pub const AF_BLUETOOTH = PF_BLUETOOTH; +pub const AF_ISDN = PF_ISDN; +pub const AF_MAX = PF_MAX; + +pub const DT_UNKNOWN = 0; +pub const DT_FIFO = 1; +pub const DT_CHR = 2; +pub const DT_DIR = 4; +pub const DT_BLK = 6; +pub const DT_REG = 8; +pub const DT_LNK = 10; +pub const DT_SOCK = 12; +pub const DT_WHT = 14; + +/// add event to kq (implies enable) +pub const EV_ADD = 0x0001; + +/// delete event from kq +pub const EV_DELETE = 0x0002; + +/// enable event +pub const EV_ENABLE = 0x0004; + +/// disable event (not reported) +pub const EV_DISABLE = 0x0008; + +/// only report one occurrence +pub const EV_ONESHOT = 0x0010; + +/// clear event state after reporting +pub const EV_CLEAR = 0x0020; + +/// force immediate event output +/// ... with or without EV_ERROR +/// ... use KEVENT_FLAG_ERROR_EVENTS +/// on syscalls supporting flags +pub const EV_RECEIPT = 0x0040; + +/// disable event after reporting +pub const EV_DISPATCH = 0x0080; + +pub const EVFILT_READ = 0; +pub const EVFILT_WRITE = 1; + +/// attached to aio requests +pub const EVFILT_AIO = 2; + +/// attached to vnodes +pub const EVFILT_VNODE = 3; + +/// attached to struct proc +pub const EVFILT_PROC = 4; + +/// attached to struct proc +pub const EVFILT_SIGNAL = 5; + +/// timers +pub const EVFILT_TIMER = 6; + +/// Filesystem events +pub const EVFILT_FS = 7; + +/// On input, NOTE_TRIGGER causes the event to be triggered for output. +pub const NOTE_TRIGGER = 0x08000000; + +/// low water mark +pub const NOTE_LOWAT = 0x00000001; + +/// vnode was removed +pub const NOTE_DELETE = 0x00000001; + +/// data contents changed +pub const NOTE_WRITE = 0x00000002; + +/// size increased +pub const NOTE_EXTEND = 0x00000004; + +/// attributes changed +pub const NOTE_ATTRIB = 0x00000008; + +/// link count changed +pub const NOTE_LINK = 0x00000010; + +/// vnode was renamed +pub const NOTE_RENAME = 0x00000020; + +/// vnode access was revoked +pub const NOTE_REVOKE = 0x00000040; + +/// process exited +pub const NOTE_EXIT = 0x80000000; + +/// process forked +pub const NOTE_FORK = 0x40000000; + +/// process exec'd +pub const NOTE_EXEC = 0x20000000; + +/// mask for signal & exit status +pub const NOTE_PDATAMASK = 0x000fffff; +pub const NOTE_PCTRLMASK = 0xf0000000; + +pub const TIOCCBRK = 0x2000747a; +pub const TIOCCDTR = 0x20007478; +pub const TIOCCONS = 0x80047462; +pub const TIOCDCDTIMESTAMP = 0x40107458; +pub const TIOCDRAIN = 0x2000745e; +pub const TIOCEXCL = 0x2000740d; +pub const TIOCEXT = 0x80047460; +pub const TIOCFLAG_CDTRCTS = 0x10; +pub const TIOCFLAG_CLOCAL = 0x2; +pub const TIOCFLAG_CRTSCTS = 0x4; +pub const TIOCFLAG_MDMBUF = 0x8; +pub const TIOCFLAG_SOFTCAR = 0x1; +pub const TIOCFLUSH = 0x80047410; +pub const TIOCGETA = 0x402c7413; +pub const TIOCGETD = 0x4004741a; +pub const TIOCGFLAGS = 0x4004745d; +pub const TIOCGLINED = 0x40207442; +pub const TIOCGPGRP = 0x40047477; +pub const TIOCGQSIZE = 0x40047481; +pub const TIOCGRANTPT = 0x20007447; +pub const TIOCGSID = 0x40047463; +pub const TIOCGSIZE = 0x40087468; +pub const TIOCGWINSZ = 0x40087468; +pub const TIOCMBIC = 0x8004746b; +pub const TIOCMBIS = 0x8004746c; +pub const TIOCMGET = 0x4004746a; +pub const TIOCMSET = 0x8004746d; +pub const TIOCM_CAR = 0x40; +pub const TIOCM_CD = 0x40; +pub const TIOCM_CTS = 0x20; +pub const TIOCM_DSR = 0x100; +pub const TIOCM_DTR = 0x2; +pub const TIOCM_LE = 0x1; +pub const TIOCM_RI = 0x80; +pub const TIOCM_RNG = 0x80; +pub const TIOCM_RTS = 0x4; +pub const TIOCM_SR = 0x10; +pub const TIOCM_ST = 0x8; +pub const TIOCNOTTY = 0x20007471; +pub const TIOCNXCL = 0x2000740e; +pub const TIOCOUTQ = 0x40047473; +pub const TIOCPKT = 0x80047470; +pub const TIOCPKT_DATA = 0x0; +pub const TIOCPKT_DOSTOP = 0x20; +pub const TIOCPKT_FLUSHREAD = 0x1; +pub const TIOCPKT_FLUSHWRITE = 0x2; +pub const TIOCPKT_IOCTL = 0x40; +pub const TIOCPKT_NOSTOP = 0x10; +pub const TIOCPKT_START = 0x8; +pub const TIOCPKT_STOP = 0x4; +pub const TIOCPTMGET = 0x40287446; +pub const TIOCPTSNAME = 0x40287448; +pub const TIOCRCVFRAME = 0x80087445; +pub const TIOCREMOTE = 0x80047469; +pub const TIOCSBRK = 0x2000747b; +pub const TIOCSCTTY = 0x20007461; +pub const TIOCSDTR = 0x20007479; +pub const TIOCSETA = 0x802c7414; +pub const TIOCSETAF = 0x802c7416; +pub const TIOCSETAW = 0x802c7415; +pub const TIOCSETD = 0x8004741b; +pub const TIOCSFLAGS = 0x8004745c; +pub const TIOCSIG = 0x2000745f; +pub const TIOCSLINED = 0x80207443; +pub const TIOCSPGRP = 0x80047476; +pub const TIOCSQSIZE = 0x80047480; +pub const TIOCSSIZE = 0x80087467; +pub const TIOCSTART = 0x2000746e; +pub const TIOCSTAT = 0x80047465; +pub const TIOCSTI = 0x80017472; +pub const TIOCSTOP = 0x2000746f; +pub const TIOCSWINSZ = 0x80087467; +pub const TIOCUCNTL = 0x80047466; +pub const TIOCXMTFRAME = 0x80087444; + +pub fn WEXITSTATUS(s: u32) u32 { + return (s >> 8) & 0xff; +} +pub fn WTERMSIG(s: u32) u32 { + return s & 0x7f; +} +pub fn WSTOPSIG(s: u32) u32 { + return WEXITSTATUS(s); +} +pub fn WIFEXITED(s: u32) bool { + return WTERMSIG(s) == 0; +} + +pub fn WIFCONTINUED(s: u32) bool { + return ((s & 0x7f) == 0xffff); +} + +pub fn WIFSTOPPED(s: u32) bool { + return ((s & 0x7f != 0x7f) and !WIFCONTINUED(s)); +} + +pub fn WIFSIGNALED(s: u32) bool { + return !WIFSTOPPED(s) and !WIFCONTINUED(s) and !WIFEXITED(s); +} + +pub const winsize = extern struct { + ws_row: u16, + ws_col: u16, + ws_xpixel: u16, + ws_ypixel: u16, +}; + +const NSIG = 32; + +pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); +pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); +pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); + +/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. +pub const Sigaction = extern struct { + /// signal handler + __sigaction_u: extern union { + __sa_handler: extern fn (i32) void, + __sa_sigaction: extern fn (i32, *__siginfo, usize) void, + }, + + /// see signal options + sa_flags: u32, + + /// signal mask to apply + sa_mask: sigset_t, +}; + +pub const _SIG_WORDS = 4; +pub const _SIG_MAXSIG = 128; + +pub inline fn _SIG_IDX(sig: usize) usize { + return sig - 1; +} +pub inline fn _SIG_WORD(sig: usize) usize { + return_SIG_IDX(sig) >> 5; +} +pub inline fn _SIG_BIT(sig: usize) usize { + return 1 << (_SIG_IDX(sig) & 31); +} +pub inline fn _SIG_VALID(sig: usize) usize { + return sig <= _SIG_MAXSIG and sig > 0; +} + +pub const sigset_t = extern struct { + __bits: [_SIG_WORDS]u32, +}; + +pub const EPERM = 1; // Operation not permitted +pub const ENOENT = 2; // No such file or directory +pub const ESRCH = 3; // No such process +pub const EINTR = 4; // Interrupted system call +pub const EIO = 5; // Input/output error +pub const ENXIO = 6; // Device not configured +pub const E2BIG = 7; // Argument list too long +pub const ENOEXEC = 8; // Exec format error +pub const EBADF = 9; // Bad file descriptor +pub const ECHILD = 10; // No child processes +pub const EDEADLK = 11; // Resource deadlock avoided +// 11 was EAGAIN +pub const ENOMEM = 12; // Cannot allocate memory +pub const EACCES = 13; // Permission denied +pub const EFAULT = 14; // Bad address +pub const ENOTBLK = 15; // Block device required +pub const EBUSY = 16; // Device busy +pub const EEXIST = 17; // File exists +pub const EXDEV = 18; // Cross-device link +pub const ENODEV = 19; // Operation not supported by device +pub const ENOTDIR = 20; // Not a directory +pub const EISDIR = 21; // Is a directory +pub const EINVAL = 22; // Invalid argument +pub const ENFILE = 23; // Too many open files in system +pub const EMFILE = 24; // Too many open files +pub const ENOTTY = 25; // Inappropriate ioctl for device +pub const ETXTBSY = 26; // Text file busy +pub const EFBIG = 27; // File too large +pub const ENOSPC = 28; // No space left on device +pub const ESPIPE = 29; // Illegal seek +pub const EROFS = 30; // Read-only file system +pub const EMLINK = 31; // Too many links +pub const EPIPE = 32; // Broken pipe + +// math software +pub const EDOM = 33; // Numerical argument out of domain +pub const ERANGE = 34; // Result too large or too small + +// non-blocking and interrupt i/o +pub const EAGAIN = 35; // Resource temporarily unavailable +pub const EWOULDBLOCK = EAGAIN; // Operation would block +pub const EINPROGRESS = 36; // Operation now in progress +pub const EALREADY = 37; // Operation already in progress + +// ipc/network software -- argument errors +pub const ENOTSOCK = 38; // Socket operation on non-socket +pub const EDESTADDRREQ = 39; // Destination address required +pub const EMSGSIZE = 40; // Message too long +pub const EPROTOTYPE = 41; // Protocol wrong type for socket +pub const ENOPROTOOPT = 42; // Protocol option not available +pub const EPROTONOSUPPORT = 43; // Protocol not supported +pub const ESOCKTNOSUPPORT = 44; // Socket type not supported +pub const EOPNOTSUPP = 45; // Operation not supported +pub const EPFNOSUPPORT = 46; // Protocol family not supported +pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family +pub const EADDRINUSE = 48; // Address already in use +pub const EADDRNOTAVAIL = 49; // Can't assign requested address + +// ipc/network software -- operational errors +pub const ENETDOWN = 50; // Network is down +pub const ENETUNREACH = 51; // Network is unreachable +pub const ENETRESET = 52; // Network dropped connection on reset +pub const ECONNABORTED = 53; // Software caused connection abort +pub const ECONNRESET = 54; // Connection reset by peer +pub const ENOBUFS = 55; // No buffer space available +pub const EISCONN = 56; // Socket is already connected +pub const ENOTCONN = 57; // Socket is not connected +pub const ESHUTDOWN = 58; // Can't send after socket shutdown +pub const ETOOMANYREFS = 59; // Too many references: can't splice +pub const ETIMEDOUT = 60; // Operation timed out +pub const ECONNREFUSED = 61; // Connection refused + +pub const ELOOP = 62; // Too many levels of symbolic links +pub const ENAMETOOLONG = 63; // File name too long + +// should be rearranged +pub const EHOSTDOWN = 64; // Host is down +pub const EHOSTUNREACH = 65; // No route to host +pub const ENOTEMPTY = 66; // Directory not empty + +// quotas & mush +pub const EPROCLIM = 67; // Too many processes +pub const EUSERS = 68; // Too many users +pub const EDQUOT = 69; // Disc quota exceeded + +// Network File System +pub const ESTALE = 70; // Stale NFS file handle +pub const EREMOTE = 71; // Too many levels of remote in path +pub const EBADRPC = 72; // RPC struct is bad +pub const ERPCMISMATCH = 73; // RPC version wrong +pub const EPROGUNAVAIL = 74; // RPC prog. not avail +pub const EPROGMISMATCH = 75; // Program version wrong +pub const EPROCUNAVAIL = 76; // Bad procedure for program + +pub const ENOLCK = 77; // No locks available +pub const ENOSYS = 78; // Function not implemented + +pub const EFTYPE = 79; // Inappropriate file type or format +pub const EAUTH = 80; // Authentication error +pub const ENEEDAUTH = 81; // Need authenticator + +// SystemV IPC +pub const EIDRM = 82; // Identifier removed +pub const ENOMSG = 83; // No message of desired type +pub const EOVERFLOW = 84; // Value too large to be stored in data type + +// Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 +pub const EILSEQ = 85; // Illegal byte sequence + +// From IEEE Std 1003.1-2001 +// Base, Realtime, Threads or Thread Priority Scheduling option errors +pub const ENOTSUP = 86; // Not supported + +// Realtime option errors +pub const ECANCELED = 87; // Operation canceled + +// Realtime, XSI STREAMS option errors +pub const EBADMSG = 88; // Bad or Corrupt message + +// XSI STREAMS option errors +pub const ENODATA = 89; // No message available +pub const ENOSR = 90; // No STREAM resources +pub const ENOSTR = 91; // Not a STREAM +pub const ETIME = 92; // STREAM ioctl timeout + +// File system extended attribute errors +pub const ENOATTR = 93; // Attribute not found + +// Realtime, XSI STREAMS option errors +pub const EMULTIHOP = 94; // Multihop attempted +pub const ENOLINK = 95; // Link has been severed +pub const EPROTO = 96; // Protocol error + +pub const ELAST = 96; // Must equal largest errno + +pub const MINSIGSTKSZ = 8192; +pub const SIGSTKSZ = MINSIGSTKSZ + 32768; + +pub const SS_ONSTACK = 1; +pub const SS_DISABLE = 4; + +pub const stack_t = extern struct { + ss_sp: [*]u8, + ss_size: isize, + ss_flags: i32, +}; + +pub const S_IFMT = 0o170000; + +pub const S_IFIFO = 0o010000; +pub const S_IFCHR = 0o020000; +pub const S_IFDIR = 0o040000; +pub const S_IFBLK = 0o060000; +pub const S_IFREG = 0o100000; +pub const S_IFLNK = 0o120000; +pub const S_IFSOCK = 0o140000; +pub const S_IFWHT = 0o160000; + +pub const S_ISUID = 0o4000; +pub const S_ISGID = 0o2000; +pub const S_ISVTX = 0o1000; +pub const S_IRWXU = 0o700; +pub const S_IRUSR = 0o400; +pub const S_IWUSR = 0o200; +pub const S_IXUSR = 0o100; +pub const S_IRWXG = 0o070; +pub const S_IRGRP = 0o040; +pub const S_IWGRP = 0o020; +pub const S_IXGRP = 0o010; +pub const S_IRWXO = 0o007; +pub const S_IROTH = 0o004; +pub const S_IWOTH = 0o002; +pub const S_IXOTH = 0o001; + +pub fn S_ISFIFO(m: u32) bool { + return m & S_IFMT == S_IFIFO; +} + +pub fn S_ISCHR(m: u32) bool { + return m & S_IFMT == S_IFCHR; +} + +pub fn S_ISDIR(m: u32) bool { + return m & S_IFMT == S_IFDIR; +} + +pub fn S_ISBLK(m: u32) bool { + return m & S_IFMT == S_IFBLK; +} + +pub fn S_ISREG(m: u32) bool { + return m & S_IFMT == S_IFREG; +} + +pub fn S_ISLNK(m: u32) bool { + return m & S_IFMT == S_IFLNK; +} + +pub fn S_ISSOCK(m: u32) bool { + return m & S_IFMT == S_IFSOCK; +} + +pub fn S_IWHT(m: u32) bool { + return m & S_IFMT == S_IFWHT; +} + +pub const HOST_NAME_MAX = 255; diff --git a/lib/std/os/bits/wasi.zig b/lib/std/os/bits/wasi.zig new file mode 100644 index 0000000000..93d2a82fde --- /dev/null +++ b/lib/std/os/bits/wasi.zig @@ -0,0 +1,307 @@ +pub const STDIN_FILENO = 0; +pub const STDOUT_FILENO = 1; +pub const STDERR_FILENO = 2; + +pub const advice_t = u8; +pub const ADVICE_NORMAL: advice_t = 0; +pub const ADVICE_SEQUENTIAL: advice_t = 1; +pub const ADVICE_RANDOM: advice_t = 2; +pub const ADVICE_WILLNEED: advice_t = 3; +pub const ADVICE_DONTNEED: advice_t = 4; +pub const ADVICE_NOREUSE: advice_t = 5; + +pub const clockid_t = u32; +pub const CLOCK_REALTIME: clockid_t = 0; +pub const CLOCK_MONOTONIC: clockid_t = 1; +pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; +pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; + +pub const device_t = u64; + +pub const dircookie_t = u64; +pub const DIRCOOKIE_START: dircookie_t = 0; + +pub const dirent_t = extern struct { + d_next: dircookie_t, + d_ino: inode_t, + d_namlen: u32, + d_type: filetype_t, +}; + +pub const errno_t = u16; +pub const ESUCCESS: errno_t = 0; +pub const E2BIG: errno_t = 1; +pub const EACCES: errno_t = 2; +pub const EADDRINUSE: errno_t = 3; +pub const EADDRNOTAVAIL: errno_t = 4; +pub const EAFNOSUPPORT: errno_t = 5; +pub const EAGAIN: errno_t = 6; +pub const EALREADY: errno_t = 7; +pub const EBADF: errno_t = 8; +pub const EBADMSG: errno_t = 9; +pub const EBUSY: errno_t = 10; +pub const ECANCELED: errno_t = 11; +pub const ECHILD: errno_t = 12; +pub const ECONNABORTED: errno_t = 13; +pub const ECONNREFUSED: errno_t = 14; +pub const ECONNRESET: errno_t = 15; +pub const EDEADLK: errno_t = 16; +pub const EDESTADDRREQ: errno_t = 17; +pub const EDOM: errno_t = 18; +pub const EDQUOT: errno_t = 19; +pub const EEXIST: errno_t = 20; +pub const EFAULT: errno_t = 21; +pub const EFBIG: errno_t = 22; +pub const EHOSTUNREACH: errno_t = 23; +pub const EIDRM: errno_t = 24; +pub const EILSEQ: errno_t = 25; +pub const EINPROGRESS: errno_t = 26; +pub const EINTR: errno_t = 27; +pub const EINVAL: errno_t = 28; +pub const EIO: errno_t = 29; +pub const EISCONN: errno_t = 30; +pub const EISDIR: errno_t = 31; +pub const ELOOP: errno_t = 32; +pub const EMFILE: errno_t = 33; +pub const EMLINK: errno_t = 34; +pub const EMSGSIZE: errno_t = 35; +pub const EMULTIHOP: errno_t = 36; +pub const ENAMETOOLONG: errno_t = 37; +pub const ENETDOWN: errno_t = 38; +pub const ENETRESET: errno_t = 39; +pub const ENETUNREACH: errno_t = 40; +pub const ENFILE: errno_t = 41; +pub const ENOBUFS: errno_t = 42; +pub const ENODEV: errno_t = 43; +pub const ENOENT: errno_t = 44; +pub const ENOEXEC: errno_t = 45; +pub const ENOLCK: errno_t = 46; +pub const ENOLINK: errno_t = 47; +pub const ENOMEM: errno_t = 48; +pub const ENOMSG: errno_t = 49; +pub const ENOPROTOOPT: errno_t = 50; +pub const ENOSPC: errno_t = 51; +pub const ENOSYS: errno_t = 52; +pub const ENOTCONN: errno_t = 53; +pub const ENOTDIR: errno_t = 54; +pub const ENOTEMPTY: errno_t = 55; +pub const ENOTRECOVERABLE: errno_t = 56; +pub const ENOTSOCK: errno_t = 57; +pub const ENOTSUP: errno_t = 58; +pub const ENOTTY: errno_t = 59; +pub const ENXIO: errno_t = 60; +pub const EOVERFLOW: errno_t = 61; +pub const EOWNERDEAD: errno_t = 62; +pub const EPERM: errno_t = 63; +pub const EPIPE: errno_t = 64; +pub const EPROTO: errno_t = 65; +pub const EPROTONOSUPPORT: errno_t = 66; +pub const EPROTOTYPE: errno_t = 67; +pub const ERANGE: errno_t = 68; +pub const EROFS: errno_t = 69; +pub const ESPIPE: errno_t = 70; +pub const ESRCH: errno_t = 71; +pub const ESTALE: errno_t = 72; +pub const ETIMEDOUT: errno_t = 73; +pub const ETXTBSY: errno_t = 74; +pub const EXDEV: errno_t = 75; +pub const ENOTCAPABLE: errno_t = 76; + +pub const event_t = extern struct { + userdata: userdata_t, + @"error": errno_t, + @"type": eventtype_t, + u: extern union { + fd_readwrite: 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 = u8; +pub const EVENTTYPE_CLOCK: eventtype_t = 0; +pub const EVENTTYPE_FD_READ: eventtype_t = 1; +pub const EVENTTYPE_FD_WRITE: eventtype_t = 2; + +pub const exitcode_t = u32; + +pub const fd_t = u32; + +pub const fdflags_t = u16; +pub const FDFLAG_APPEND: fdflags_t = 0x0001; +pub const FDFLAG_DSYNC: fdflags_t = 0x0002; +pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004; +pub const FDFLAG_RSYNC: fdflags_t = 0x0008; +pub const FDFLAG_SYNC: fdflags_t = 0x0010; + +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 { + st_dev: device_t, + st_ino: inode_t, + st_filetype: filetype_t, + st_nlink: linkcount_t, + st_size: filesize_t, + st_atim: timestamp_t, + st_mtim: timestamp_t, + st_ctim: timestamp_t, +}; + +pub const filetype_t = u8; +pub const FILETYPE_UNKNOWN: filetype_t = 0; +pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1; +pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2; +pub const FILETYPE_DIRECTORY: filetype_t = 3; +pub const FILETYPE_REGULAR_FILE: filetype_t = 4; +pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5; +pub const FILETYPE_SOCKET_STREAM: filetype_t = 6; +pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7; + +pub const fstflags_t = u16; +pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001; +pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002; +pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004; +pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008; + +pub const inode_t = u64; + +pub const linkcount_t = u32; + +pub const lookupflags_t = u32; +pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001; + +pub const oflags_t = u16; +pub const O_CREAT: oflags_t = 0x0001; +pub const O_DIRECTORY: oflags_t = 0x0002; +pub const O_EXCL: oflags_t = 0x0004; +pub const O_TRUNC: oflags_t = 0x0008; + +pub const preopentype_t = u8; +pub const PREOPENTYPE_DIR: preopentype_t = 0; + +pub const prestat_t = extern struct { + pr_type: preopentype_t, + u: extern union { + dir: extern struct { + pr_name_len: usize, + }, + }, +}; + +pub const riflags_t = u16; +pub const SOCK_RECV_PEEK: riflags_t = 0x0001; +pub const SOCK_RECV_WAITALL: riflags_t = 0x0002; + +pub const rights_t = u64; +pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001; +pub const RIGHT_FD_READ: rights_t = 0x0000000000000002; +pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004; +pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008; +pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010; +pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020; +pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040; +pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080; +pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100; +pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200; +pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400; +pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800; +pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000; +pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000; +pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000; +pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000; +pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000; +pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000; +pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000; +pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000; +pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000; +pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000; +pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000; +pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000; +pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000; +pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000; +pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000; +pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000; +pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000; + +pub const roflags_t = u16; +pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001; + +pub const sdflags_t = u8; +pub const SHUT_RD: sdflags_t = 0x01; +pub const SHUT_WR: sdflags_t = 0x02; + +pub const siflags_t = u16; + +pub const signal_t = u8; +pub const SIGHUP: signal_t = 1; +pub const SIGINT: signal_t = 2; +pub const SIGQUIT: signal_t = 3; +pub const SIGILL: signal_t = 4; +pub const SIGTRAP: signal_t = 5; +pub const SIGABRT: signal_t = 6; +pub const SIGBUS: signal_t = 7; +pub const SIGFPE: signal_t = 8; +pub const SIGKILL: signal_t = 9; +pub const SIGUSR1: signal_t = 10; +pub const SIGSEGV: signal_t = 11; +pub const SIGUSR2: signal_t = 12; +pub const SIGPIPE: signal_t = 13; +pub const SIGALRM: signal_t = 14; +pub const SIGTERM: signal_t = 15; +pub const SIGCHLD: signal_t = 16; +pub const SIGCONT: signal_t = 17; +pub const SIGSTOP: signal_t = 18; +pub const SIGTSTP: signal_t = 19; +pub const SIGTTIN: signal_t = 20; +pub const SIGTTOU: signal_t = 21; +pub const SIGURG: signal_t = 22; +pub const SIGXCPU: signal_t = 23; +pub const SIGXFSZ: signal_t = 24; +pub const SIGVTALRM: signal_t = 25; +pub const SIGPROF: signal_t = 26; +pub const SIGWINCH: signal_t = 27; +pub const SIGPOLL: signal_t = 28; +pub const SIGPWR: signal_t = 29; +pub const SIGSYS: signal_t = 30; + +pub const subclockflags_t = u16; +pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001; + +pub const subscription_t = extern struct { + userdata: userdata_t, + @"type": eventtype_t, + u: extern union { + clock: extern struct { + identifier: userdata_t, + clock_id: clockid_t, + timeout: timestamp_t, + precision: timestamp_t, + flags: subclockflags_t, + }, + fd_readwrite: extern struct { + fd: fd_t, + }, + }, +}; + +pub const timestamp_t = u64; + +pub const userdata_t = u64; + +pub const whence_t = u8; +pub const WHENCE_CUR: whence_t = 0; +pub const WHENCE_END: whence_t = 1; +pub const WHENCE_SET: whence_t = 2; diff --git a/lib/std/os/bits/windows.zig b/lib/std/os/bits/windows.zig new file mode 100644 index 0000000000..fc148d812f --- /dev/null +++ b/lib/std/os/bits/windows.zig @@ -0,0 +1,160 @@ +// The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime). + +usingnamespace @import("../windows/bits.zig"); + +pub const fd_t = HANDLE; +pub const pid_t = HANDLE; + +pub const PATH_MAX = 260; + +pub const time_t = c_longlong; + +pub const timespec = extern struct { + tv_sec: time_t, + tv_nsec: c_long, +}; + +pub const sig_atomic_t = c_int; + +/// maximum signal number + 1 +pub const NSIG = 23; + +// Signal types + +/// interrupt +pub const SIGINT = 2; + +/// illegal instruction - invalid function image +pub const SIGILL = 4; + +/// floating point exception +pub const SIGFPE = 8; + +/// segment violation +pub const SIGSEGV = 11; + +/// Software termination signal from kill +pub const SIGTERM = 15; + +/// Ctrl-Break sequence +pub const SIGBREAK = 21; + +/// abnormal termination triggered by abort call +pub const SIGABRT = 22; + +/// SIGABRT compatible with other platforms, same as SIGABRT +pub const SIGABRT_COMPAT = 6; + +// Signal action codes + +/// default signal action +pub const SIG_DFL = 0; + +/// ignore signal +pub const SIG_IGN = 1; + +/// return current value +pub const SIG_GET = 2; + +/// signal gets error +pub const SIG_SGE = 3; + +/// acknowledge +pub const SIG_ACK = 4; + +/// Signal error value (returned by signal call on error) +pub const SIG_ERR = -1; + +pub const SEEK_SET = 0; +pub const SEEK_CUR = 1; +pub const SEEK_END = 2; + +pub const EPERM = 1; +pub const ENOENT = 2; +pub const ESRCH = 3; +pub const EINTR = 4; +pub const EIO = 5; +pub const ENXIO = 6; +pub const E2BIG = 7; +pub const ENOEXEC = 8; +pub const EBADF = 9; +pub const ECHILD = 10; +pub const EAGAIN = 11; +pub const ENOMEM = 12; +pub const EACCES = 13; +pub const EFAULT = 14; +pub const EBUSY = 16; +pub const EEXIST = 17; +pub const EXDEV = 18; +pub const ENODEV = 19; +pub const ENOTDIR = 20; +pub const EISDIR = 21; +pub const ENFILE = 23; +pub const EMFILE = 24; +pub const ENOTTY = 25; +pub const EFBIG = 27; +pub const ENOSPC = 28; +pub const ESPIPE = 29; +pub const EROFS = 30; +pub const EMLINK = 31; +pub const EPIPE = 32; +pub const EDOM = 33; +pub const EDEADLK = 36; +pub const ENAMETOOLONG = 38; +pub const ENOLCK = 39; +pub const ENOSYS = 40; +pub const ENOTEMPTY = 41; + +pub const EINVAL = 22; +pub const ERANGE = 34; +pub const EILSEQ = 42; +pub const STRUNCATE = 80; + +// Support EDEADLOCK for compatibility with older Microsoft C versions +pub const EDEADLOCK = EDEADLK; + +// POSIX Supplement +pub const EADDRINUSE = 100; +pub const EADDRNOTAVAIL = 101; +pub const EAFNOSUPPORT = 102; +pub const EALREADY = 103; +pub const EBADMSG = 104; +pub const ECANCELED = 105; +pub const ECONNABORTED = 106; +pub const ECONNREFUSED = 107; +pub const ECONNRESET = 108; +pub const EDESTADDRREQ = 109; +pub const EHOSTUNREACH = 110; +pub const EIDRM = 111; +pub const EINPROGRESS = 112; +pub const EISCONN = 113; +pub const ELOOP = 114; +pub const EMSGSIZE = 115; +pub const ENETDOWN = 116; +pub const ENETRESET = 117; +pub const ENETUNREACH = 118; +pub const ENOBUFS = 119; +pub const ENODATA = 120; +pub const ENOLINK = 121; +pub const ENOMSG = 122; +pub const ENOPROTOOPT = 123; +pub const ENOSR = 124; +pub const ENOSTR = 125; +pub const ENOTCONN = 126; +pub const ENOTRECOVERABLE = 127; +pub const ENOTSOCK = 128; +pub const ENOTSUP = 129; +pub const EOPNOTSUPP = 130; +pub const EOTHER = 131; +pub const EOVERFLOW = 132; +pub const EOWNERDEAD = 133; +pub const EPROTO = 134; +pub const EPROTONOSUPPORT = 135; +pub const EPROTOTYPE = 136; +pub const ETIME = 137; +pub const ETIMEDOUT = 138; +pub const ETXTBSY = 139; +pub const EWOULDBLOCK = 140; +pub const EDQUOT = 10069; + +pub const F_OK = 0; diff --git a/lib/std/os/darwin.zig b/lib/std/os/darwin.zig new file mode 100644 index 0000000000..0adf71affb --- /dev/null +++ b/lib/std/os/darwin.zig @@ -0,0 +1,8 @@ +const builtin = @import("builtin"); +const std = @import("../std.zig"); +pub const is_the_target = switch (builtin.os) { + .macosx, .tvos, .watchos, .ios => true, + else => false, +}; +pub usingnamespace std.c; +pub usingnamespace @import("bits.zig"); diff --git a/lib/std/os/freebsd.zig b/lib/std/os/freebsd.zig new file mode 100644 index 0000000000..ddbf98f2bc --- /dev/null +++ b/lib/std/os/freebsd.zig @@ -0,0 +1,5 @@ +const std = @import("../std.zig"); +const builtin = @import("builtin"); +pub const is_the_target = builtin.os == .freebsd; +pub usingnamespace std.c; +pub usingnamespace @import("bits.zig"); diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig new file mode 100644 index 0000000000..7dcd01572e --- /dev/null +++ b/lib/std/os/linux.zig @@ -0,0 +1,1045 @@ +// This file provides the system interface functions for Linux matching those +// that are provided by libc, whether or not libc is linked. The following +// abstractions are made: +// * Work around kernel bugs and limitations. For example, see sendmmsg. +// * Implement all the syscalls in the same way that libc functions will +// provide `rename` when only the `renameat` syscall exists. +// * Does not support POSIX thread cancellation. +const std = @import("../std.zig"); +const builtin = @import("builtin"); +const assert = std.debug.assert; +const maxInt = std.math.maxInt; +const elf = std.elf; +const vdso = @import("linux/vdso.zig"); +const dl = @import("../dynamic_library.zig"); + +pub const is_the_target = builtin.os == .linux; +pub usingnamespace switch (builtin.arch) { + .x86_64 => @import("linux/x86_64.zig"), + .aarch64 => @import("linux/arm64.zig"), + .arm => @import("linux/arm-eabi.zig"), + .riscv64 => @import("linux/riscv64.zig"), + else => struct {}, +}; +pub usingnamespace @import("bits.zig"); +pub const tls = @import("linux/tls.zig"); + +/// Set by startup code, used by `getauxval`. +pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; + +/// See `std.elf` for the constants. +pub fn getauxval(index: usize) usize { + const auxv = elf_aux_maybe orelse return 0; + var i: usize = 0; + while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { + if (auxv[i].a_type == index) + return auxv[i].a_un.a_val; + } + return 0; +} + +/// Get the errno from a syscall return value, or 0 for no error. +pub fn getErrno(r: usize) u12 { + const signed_r = @bitCast(isize, r); + return if (signed_r > -4096 and signed_r < 0) @intCast(u12, -signed_r) else 0; +} + +pub fn dup2(old: i32, new: i32) usize { + if (@hasDecl(@This(), "SYS_dup2")) { + return syscall2(SYS_dup2, @bitCast(usize, isize(old)), @bitCast(usize, isize(new))); + } else { + if (old == new) { + if (std.debug.runtime_safety) { + const rc = syscall2(SYS_fcntl, @bitCast(usize, isize(old)), F_GETFD); + if (@bitCast(isize, rc) < 0) return rc; + } + return @intCast(usize, old); + } else { + return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), 0); + } + } +} + +pub fn dup3(old: i32, new: i32, flags: u32) usize { + return syscall3(SYS_dup3, @bitCast(usize, isize(old)), @bitCast(usize, isize(new)), flags); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn chdir(path: [*]const u8) usize { + return syscall1(SYS_chdir, @ptrToInt(path)); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn chroot(path: [*]const u8) usize { + return syscall1(SYS_chroot, @ptrToInt(path)); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { + return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); +} + +pub fn fork() usize { + if (@hasDecl(@This(), "SYS_fork")) { + return syscall0(SYS_fork); + } else { + return syscall2(SYS_clone, SIGCHLD, 0); + } +} + +/// This must be inline, and inline call the syscall function, because if the +/// child does a return it will clobber the parent's stack. +/// It is advised to avoid this function and use clone instead, because +/// the compiler is not aware of how vfork affects control flow and you may +/// see different results in optimized builds. +pub inline fn vfork() usize { + return @inlineCall(syscall0, SYS_vfork); +} + +pub fn futimens(fd: i32, times: *const [2]timespec) usize { + return utimensat(fd, null, times, 0); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn utimensat(dirfd: i32, path: ?[*]const u8, times: *const [2]timespec, flags: u32) usize { + return syscall4(SYS_utimensat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(times), flags); +} + +pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize { + return syscall4(SYS_futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val), @ptrToInt(timeout)); +} + +pub fn futex_wake(uaddr: *const i32, futex_op: u32, val: i32) usize { + return syscall3(SYS_futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val)); +} + +pub fn getcwd(buf: [*]u8, size: usize) usize { + return syscall2(SYS_getcwd, @ptrToInt(buf), size); +} + +pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { + return syscall3( + SYS_getdents, + @bitCast(usize, isize(fd)), + @ptrToInt(dirp), + std.math.min(len, maxInt(c_int)), + ); +} + +pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize { + return syscall3( + SYS_getdents64, + @bitCast(usize, isize(fd)), + @ptrToInt(dirp), + std.math.min(len, maxInt(c_int)), + ); +} + +pub fn inotify_init1(flags: u32) usize { + return syscall1(SYS_inotify_init1, flags); +} + +pub fn inotify_add_watch(fd: i32, pathname: [*]const u8, mask: u32) usize { + return syscall3(SYS_inotify_add_watch, @bitCast(usize, isize(fd)), @ptrToInt(pathname), mask); +} + +pub fn inotify_rm_watch(fd: i32, wd: i32) usize { + return syscall2(SYS_inotify_rm_watch, @bitCast(usize, isize(fd)), @bitCast(usize, isize(wd))); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { + if (@hasDecl(@This(), "SYS_readlink")) { + return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); + } else { + return syscall4(SYS_readlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { + return syscall4(SYS_readlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn mkdir(path: [*]const u8, mode: u32) usize { + if (@hasDecl(@This(), "SYS_mkdir")) { + return syscall2(SYS_mkdir, @ptrToInt(path), mode); + } else { + return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize { + return syscall3(SYS_mkdirat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn mount(special: [*]const u8, dir: [*]const u8, fstype: [*]const u8, flags: u32, data: usize) usize { + return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn umount(special: [*]const u8) usize { + return syscall2(SYS_umount2, @ptrToInt(special), 0); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn umount2(special: [*]const u8, flags: u32) usize { + return syscall2(SYS_umount2, @ptrToInt(special), flags); +} + +pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: u64) usize { + if (@hasDecl(@This(), "SYS_mmap2")) { + return syscall6(SYS_mmap2, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @truncate(usize, offset / MMAP2_UNIT)); + } else { + return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), offset); + } +} + +pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize { + return syscall3(SYS_mprotect, @ptrToInt(address), length, protection); +} + +pub fn munmap(address: [*]const u8, length: usize) usize { + return syscall2(SYS_munmap, @ptrToInt(address), length); +} + +pub fn read(fd: i32, buf: [*]u8, count: usize) usize { + return syscall3(SYS_read, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); +} + +pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { + return syscall5( + SYS_preadv, + @bitCast(usize, isize(fd)), + @ptrToInt(iov), + count, + @truncate(usize, offset), + @truncate(usize, offset >> 32), + ); +} + +pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize { + return syscall6( + SYS_preadv2, + @bitCast(usize, isize(fd)), + @ptrToInt(iov), + count, + @truncate(usize, offset), + @truncate(usize, offset >> 32), + flags, + ); +} + +pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize { + return syscall3(SYS_readv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count); +} + +pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { + return syscall3(SYS_writev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count); +} + +pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { + return syscall5( + SYS_pwritev, + @bitCast(usize, isize(fd)), + @ptrToInt(iov), + count, + @truncate(usize, offset), + @truncate(usize, offset >> 32), + ); +} + +pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize { + return syscall6( + SYS_pwritev2, + @bitCast(usize, isize(fd)), + @ptrToInt(iov), + count, + @truncate(usize, offset), + @truncate(usize, offset >> 32), + flags, + ); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn rmdir(path: [*]const u8) usize { + if (@hasDecl(@This(), "SYS_rmdir")) { + return syscall1(SYS_rmdir, @ptrToInt(path)); + } else { + return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { + if (@hasDecl(@This(), "SYS_symlink")) { + return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); + } else { + return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize { + return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(newfd)), @ptrToInt(newpath)); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { + return syscall4(SYS_pread, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn access(path: [*]const u8, mode: u32) usize { + if (@hasDecl(@This(), "SYS_access")) { + return syscall2(SYS_access, @ptrToInt(path), mode); + } else { + return syscall4(SYS_faccessat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode, 0); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize { + return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags); +} + +pub fn pipe(fd: *[2]i32) usize { + if (@hasDecl(@This(), "SYS_pipe")) { + return syscall1(SYS_pipe, @ptrToInt(fd)); + } else { + return syscall2(SYS_pipe2, @ptrToInt(fd), 0); + } +} + +pub fn pipe2(fd: *[2]i32, flags: u32) usize { + return syscall2(SYS_pipe2, @ptrToInt(fd), flags); +} + +pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { + return syscall3(SYS_write, @bitCast(usize, isize(fd)), @ptrToInt(buf), count); +} + +pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { + return syscall4(SYS_pwrite, @bitCast(usize, isize(fd)), @ptrToInt(buf), count, offset); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn rename(old: [*]const u8, new: [*]const u8) usize { + if (@hasDecl(@This(), "SYS_rename")) { + return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); + } else if (@hasDecl(@This(), "SYS_renameat")) { + return syscall4(SYS_renameat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new)); + } else { + return syscall5(SYS_renameat2, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new), 0); + } +} + +pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8) usize { + if (@hasDecl(@This(), "SYS_renameat")) { + return syscall4( + SYS_renameat, + @bitCast(usize, isize(oldfd)), + @ptrToInt(old), + @bitCast(usize, isize(newfd)), + @ptrToInt(new), + ); + } else { + return syscall5( + SYS_renameat2, + @bitCast(usize, isize(oldfd)), + @ptrToInt(old), + @bitCast(usize, isize(newfd)), + @ptrToInt(new), + 0, + ); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize { + return syscall5( + SYS_renameat2, + @bitCast(usize, isize(oldfd)), + @ptrToInt(oldpath), + @bitCast(usize, isize(newfd)), + @ptrToInt(newpath), + flags, + ); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { + if (@hasDecl(@This(), "SYS_open")) { + return syscall3(SYS_open, @ptrToInt(path), flags, perm); + } else { + return syscall4( + SYS_openat, + @bitCast(usize, isize(AT_FDCWD)), + @ptrToInt(path), + flags, + perm, + ); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn create(path: [*]const u8, perm: usize) usize { + return syscall2(SYS_creat, @ptrToInt(path), perm); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize { + // dirfd could be negative, for example AT_FDCWD is -100 + return syscall4(SYS_openat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags, mode); +} + +/// See also `clone` (from the arch-specific include) +pub fn clone5(flags: usize, child_stack_ptr: usize, parent_tid: *i32, child_tid: *i32, newtls: usize) usize { + return syscall5(SYS_clone, flags, child_stack_ptr, @ptrToInt(parent_tid), @ptrToInt(child_tid), newtls); +} + +/// See also `clone` (from the arch-specific include) +pub fn clone2(flags: u32, child_stack_ptr: usize) usize { + return syscall2(SYS_clone, flags, child_stack_ptr); +} + +pub fn close(fd: i32) usize { + return syscall1(SYS_close, @bitCast(usize, isize(fd))); +} + +/// Can only be called on 32 bit systems. For 64 bit see `lseek`. +pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { + return syscall5( + SYS__llseek, + @bitCast(usize, isize(fd)), + @truncate(usize, offset >> 32), + @truncate(usize, offset), + @ptrToInt(result), + whence, + ); +} + +/// Can only be called on 64 bit systems. For 32 bit see `llseek`. +pub fn lseek(fd: i32, offset: i64, whence: usize) usize { + return syscall3(SYS_lseek, @bitCast(usize, isize(fd)), @bitCast(usize, offset), whence); +} + +pub fn exit(status: i32) noreturn { + _ = syscall1(SYS_exit, @bitCast(usize, isize(status))); + unreachable; +} + +pub fn exit_group(status: i32) noreturn { + _ = syscall1(SYS_exit_group, @bitCast(usize, isize(status))); + unreachable; +} + +pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { + return syscall3(SYS_getrandom, @ptrToInt(buf), count, flags); +} + +pub fn kill(pid: i32, sig: i32) usize { + return syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig))); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn unlink(path: [*]const u8) usize { + if (@hasDecl(@This(), "SYS_unlink")) { + return syscall1(SYS_unlink, @ptrToInt(path)); + } else { + return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize { + return syscall3(SYS_unlinkat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), flags); +} + +pub fn waitpid(pid: i32, status: *u32, flags: u32) usize { + return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), flags, 0); +} + +var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime); + +// We must follow the C calling convention when we call into the VDSO +const vdso_clock_gettime_ty = extern fn (i32, *timespec) usize; + +pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { + if (@hasDecl(@This(), "VDSO_CGT_SYM")) { + const ptr = @atomicLoad(?*const c_void, &vdso_clock_gettime, .Unordered); + if (ptr) |fn_ptr| { + const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); + const rc = f(clk_id, tp); + switch (rc) { + 0, @bitCast(usize, isize(-EINVAL)) => return rc, + else => {}, + } + } + } + return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); +} + +extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { + const ptr = @intToPtr(?*const c_void, vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM)); + // Note that we may not have a VDSO at all, update the stub address anyway + // so that clock_gettime will fall back on the good old (and slow) syscall + _ = @cmpxchgStrong(?*const c_void, &vdso_clock_gettime, &init_vdso_clock_gettime, ptr, .Monotonic, .Monotonic); + // Call into the VDSO if available + if (ptr) |fn_ptr| { + const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr); + return f(clk, ts); + } + return @bitCast(usize, isize(-ENOSYS)); +} + +pub fn clock_getres(clk_id: i32, tp: *timespec) usize { + return syscall2(SYS_clock_getres, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); +} + +pub fn clock_settime(clk_id: i32, tp: *const timespec) usize { + return syscall2(SYS_clock_settime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); +} + +pub fn gettimeofday(tv: *timeval, tz: *timezone) usize { + return syscall2(SYS_gettimeofday, @ptrToInt(tv), @ptrToInt(tz)); +} + +pub fn settimeofday(tv: *const timeval, tz: *const timezone) usize { + return syscall2(SYS_settimeofday, @ptrToInt(tv), @ptrToInt(tz)); +} + +pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { + return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); +} + +pub fn setuid(uid: u32) usize { + if (@hasDecl(@This(), "SYS_setuid32")) { + return syscall1(SYS_setuid32, uid); + } else { + return syscall1(SYS_setuid, uid); + } +} + +pub fn setgid(gid: u32) usize { + if (@hasDecl(@This(), "SYS_setgid32")) { + return syscall1(SYS_setgid32, gid); + } else { + return syscall1(SYS_setgid, gid); + } +} + +pub fn setreuid(ruid: u32, euid: u32) usize { + if (@hasDecl(@This(), "SYS_setreuid32")) { + return syscall2(SYS_setreuid32, ruid, euid); + } else { + return syscall2(SYS_setreuid, ruid, euid); + } +} + +pub fn setregid(rgid: u32, egid: u32) usize { + if (@hasDecl(@This(), "SYS_setregid32")) { + return syscall2(SYS_setregid32, rgid, egid); + } else { + return syscall2(SYS_setregid, rgid, egid); + } +} + +pub fn getuid() u32 { + if (@hasDecl(@This(), "SYS_getuid32")) { + return u32(syscall0(SYS_getuid32)); + } else { + return u32(syscall0(SYS_getuid)); + } +} + +pub fn getgid() u32 { + if (@hasDecl(@This(), "SYS_getgid32")) { + return u32(syscall0(SYS_getgid32)); + } else { + return u32(syscall0(SYS_getgid)); + } +} + +pub fn geteuid() u32 { + if (@hasDecl(@This(), "SYS_geteuid32")) { + return u32(syscall0(SYS_geteuid32)); + } else { + return u32(syscall0(SYS_geteuid)); + } +} + +pub fn getegid() u32 { + if (@hasDecl(@This(), "SYS_getegid32")) { + return u32(syscall0(SYS_getegid32)); + } else { + return u32(syscall0(SYS_getegid)); + } +} + +pub fn seteuid(euid: u32) usize { + return setreuid(std.math.maxInt(u32), euid); +} + +pub fn setegid(egid: u32) usize { + return setregid(std.math.maxInt(u32), egid); +} + +pub fn getresuid(ruid: *u32, euid: *u32, suid: *u32) usize { + if (@hasDecl(@This(), "SYS_getresuid32")) { + return syscall3(SYS_getresuid32, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid)); + } else { + return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid)); + } +} + +pub fn getresgid(rgid: *u32, egid: *u32, sgid: *u32) usize { + if (@hasDecl(@This(), "SYS_getresgid32")) { + return syscall3(SYS_getresgid32, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid)); + } else { + return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid)); + } +} + +pub fn setresuid(ruid: u32, euid: u32, suid: u32) usize { + if (@hasDecl(@This(), "SYS_setresuid32")) { + return syscall3(SYS_setresuid32, ruid, euid, suid); + } else { + return syscall3(SYS_setresuid, ruid, euid, suid); + } +} + +pub fn setresgid(rgid: u32, egid: u32, sgid: u32) usize { + if (@hasDecl(@This(), "SYS_setresgid32")) { + return syscall3(SYS_setresgid32, rgid, egid, sgid); + } else { + return syscall3(SYS_setresgid, rgid, egid, sgid); + } +} + +pub fn getgroups(size: usize, list: *u32) usize { + if (@hasDecl(@This(), "SYS_getgroups32")) { + return syscall2(SYS_getgroups32, size, @ptrToInt(list)); + } else { + return syscall2(SYS_getgroups, size, @ptrToInt(list)); + } +} + +pub fn setgroups(size: usize, list: *const u32) usize { + if (@hasDecl(@This(), "SYS_setgroups32")) { + return syscall2(SYS_setgroups32, size, @ptrToInt(list)); + } else { + return syscall2(SYS_setgroups, size, @ptrToInt(list)); + } +} + +pub fn getpid() i32 { + return @bitCast(i32, @truncate(u32, syscall0(SYS_getpid))); +} + +pub fn gettid() i32 { + return @bitCast(i32, @truncate(u32, syscall0(SYS_gettid))); +} + +pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize { + return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8); +} + +pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize { + assert(sig >= 1); + assert(sig != SIGKILL); + assert(sig != SIGSTOP); + var ksa = k_sigaction{ + .sigaction = act.sigaction, + .flags = act.flags | SA_RESTORER, + .mask = undefined, + .restorer = @ptrCast(extern fn () void, restore_rt), + }; + var ksa_old: k_sigaction = undefined; + @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), 8); + const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask))); + const err = getErrno(result); + if (err != 0) { + return result; + } + if (oact) |old| { + old.sigaction = ksa_old.sigaction; + old.flags = @truncate(u32, ksa_old.flags); + @memcpy(@ptrCast([*]u8, &old.mask), @ptrCast([*]const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask))); + } + return 0; +} + +pub fn blockAllSignals(set: *sigset_t) void { + _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8); +} + +pub fn blockAppSignals(set: *sigset_t) void { + _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8); +} + +pub fn restoreSignals(set: *sigset_t) void { + _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8); +} + +pub fn sigaddset(set: *sigset_t, sig: u6) void { + const s = sig - 1; + (set.*)[@intCast(usize, s) / usize.bit_count] |= @intCast(usize, 1) << (s & (usize.bit_count - 1)); +} + +pub fn sigismember(set: *const sigset_t, sig: u6) bool { + const s = sig - 1; + return ((set.*)[@intCast(usize, s) / usize.bit_count] & (@intCast(usize, 1) << (s & (usize.bit_count - 1)))) != 0; +} + +pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { + return syscall3(SYS_getsockname, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); +} + +pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { + return syscall3(SYS_getpeername, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len)); +} + +pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { + return syscall3(SYS_socket, domain, socket_type, protocol); +} + +pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize { + return syscall5(SYS_setsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); +} + +pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize { + return syscall5(SYS_getsockopt, @bitCast(usize, isize(fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); +} + +pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize { + return syscall3(SYS_sendmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags); +} + +pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize { + if (@typeInfo(usize).Int.bits > @typeInfo(@typeOf(mmsghdr(undefined).msg_len)).Int.bits) { + // workaround kernel brokenness: + // if adding up all iov_len overflows a i32 then split into multiple calls + // see https://www.openwall.com/lists/musl/2014/06/07/5 + const kvlen = if (vlen > IOV_MAX) IOV_MAX else vlen; // matches kernel + var next_unsent: usize = 0; + for (msgvec[0..kvlen]) |*msg, i| { + var size: i32 = 0; + const msg_iovlen = @intCast(usize, msg.msg_hdr.msg_iovlen); // kernel side this is treated as unsigned + for (msg.msg_hdr.msg_iov[0..msg_iovlen]) |iov, j| { + if (iov.iov_len > std.math.maxInt(i32) or @addWithOverflow(i32, size, @intCast(i32, iov.iov_len), &size)) { + // batch-send all messages up to the current message + if (next_unsent < i) { + const batch_size = i - next_unsent; + const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); + if (getErrno(r) != 0) return next_unsent; + if (r < batch_size) return next_unsent + r; + } + // send current message as own packet + const r = sendmsg(fd, &msg.msg_hdr, flags); + if (getErrno(r) != 0) return r; + // Linux limits the total bytes sent by sendmsg to INT_MAX, so this cast is safe. + msg.msg_len = @intCast(u32, r); + next_unsent = i + 1; + break; + } + } + } + if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR) + const batch_size = kvlen - next_unsent; + const r = syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); + if (getErrno(r) != 0) return r; + return next_unsent + r; + } + return kvlen; + } + return syscall4(SYS_sendmmsg, @bitCast(usize, isize(fd)), @ptrToInt(msgvec), vlen, flags); +} + +pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { + return syscall3(SYS_connect, @bitCast(usize, isize(fd)), @ptrToInt(addr), len); +} + +pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize { + return syscall3(SYS_recvmsg, @bitCast(usize, isize(fd)), @ptrToInt(msg), flags); +} + +pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize { + return syscall6(SYS_recvfrom, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); +} + +pub fn shutdown(fd: i32, how: i32) usize { + return syscall2(SYS_shutdown, @bitCast(usize, isize(fd)), @bitCast(usize, isize(how))); +} + +pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { + return syscall3(SYS_bind, @bitCast(usize, isize(fd)), @ptrToInt(addr), @intCast(usize, len)); +} + +pub fn listen(fd: i32, backlog: u32) usize { + return syscall2(SYS_listen, @bitCast(usize, isize(fd)), backlog); +} + +pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize { + return syscall6(SYS_sendto, @bitCast(usize, isize(fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); +} + +pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { + return syscall4(SYS_socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0])); +} + +pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { + return accept4(fd, addr, len, 0); +} + +pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: u32) usize { + return syscall4(SYS_accept4, @bitCast(usize, isize(fd)), @ptrToInt(addr), @ptrToInt(len), flags); +} + +pub fn fstat(fd: i32, stat_buf: *Stat) usize { + if (@hasDecl(@This(), "SYS_fstat64")) { + return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); + } else { + return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf)); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize { + if (@hasDecl(@This(), "SYS_stat64")) { + return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf)); + } else { + return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf)); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { + if (@hasDecl(@This(), "SYS_lstat64")) { + return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf)); + } else { + return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf)); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize { + if (@hasDecl(@This(), "SYS_fstatat64")) { + return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); + } else { + return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); + } +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn listxattr(path: [*]const u8, list: [*]u8, size: usize) usize { + return syscall3(SYS_listxattr, @ptrToInt(path), @ptrToInt(list), size); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn llistxattr(path: [*]const u8, list: [*]u8, size: usize) usize { + return syscall3(SYS_llistxattr, @ptrToInt(path), @ptrToInt(list), size); +} + +pub fn flistxattr(fd: usize, list: [*]u8, size: usize) usize { + return syscall3(SYS_flistxattr, fd, @ptrToInt(list), size); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn getxattr(path: [*]const u8, name: [*]const u8, value: [*]u8, size: usize) usize { + return syscall4(SYS_getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn lgetxattr(path: [*]const u8, name: [*]const u8, value: [*]u8, size: usize) usize { + return syscall4(SYS_lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn fgetxattr(fd: usize, name: [*]const u8, value: [*]u8, size: usize) usize { + return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn setxattr(path: [*]const u8, name: [*]const u8, value: *const void, size: usize, flags: usize) usize { + return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn lsetxattr(path: [*]const u8, name: [*]const u8, value: *const void, size: usize, flags: usize) usize { + return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn fsetxattr(fd: usize, name: [*]const u8, value: *const void, size: usize, flags: usize) usize { + return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn removexattr(path: [*]const u8, name: [*]const u8) usize { + return syscall2(SYS_removexattr, @ptrToInt(path), @ptrToInt(name)); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn lremovexattr(path: [*]const u8, name: [*]const u8) usize { + return syscall2(SYS_lremovexattr, @ptrToInt(path), @ptrToInt(name)); +} + +// TODO https://github.com/ziglang/zig/issues/265 +pub fn fremovexattr(fd: usize, name: [*]const u8) usize { + return syscall2(SYS_fremovexattr, fd, @ptrToInt(name)); +} + +pub fn sched_getaffinity(pid: i32, size: usize, set: *cpu_set_t) usize { + const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, isize(pid)), size, @ptrToInt(set)); + if (@bitCast(isize, rc) < 0) return rc; + if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc); + return 0; +} + +pub fn epoll_create() usize { + return epoll_create1(0); +} + +pub fn epoll_create1(flags: usize) usize { + return syscall1(SYS_epoll_create1, flags); +} + +pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize { + return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev)); +} + +pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { + return epoll_pwait(epoll_fd, events, maxevents, timeout, null); +} + +pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { + return syscall6( + SYS_epoll_pwait, + @bitCast(usize, isize(epoll_fd)), + @ptrToInt(events), + @intCast(usize, maxevents), + @bitCast(usize, isize(timeout)), + @ptrToInt(sigmask), + @sizeOf(sigset_t), + ); +} + +pub fn eventfd(count: u32, flags: u32) usize { + return syscall2(SYS_eventfd2, count, flags); +} + +pub fn timerfd_create(clockid: i32, flags: u32) usize { + return syscall2(SYS_timerfd_create, @bitCast(usize, isize(clockid)), flags); +} + +pub const itimerspec = extern struct { + it_interval: timespec, + it_value: timespec, +}; + +pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize { + return syscall2(SYS_timerfd_gettime, @bitCast(usize, isize(fd)), @ptrToInt(curr_value)); +} + +pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { + return syscall4(SYS_timerfd_settime, @bitCast(usize, isize(fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); +} + +pub fn unshare(flags: usize) usize { + return syscall1(SYS_unshare, flags); +} + +pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize { + return syscall2(SYS_capget, @ptrToInt(hdrp), @ptrToInt(datap)); +} + +pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize { + return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap)); +} + +pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) usize { + return syscall2(SYS_sigaltstack, @ptrToInt(ss), @ptrToInt(old_ss)); +} + +pub fn uname(uts: *utsname) usize { + return syscall1(SYS_uname, @ptrToInt(uts)); +} + +// XXX: This should be weak +extern const __ehdr_start: elf.Ehdr = undefined; + +pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_info, size: usize, data: ?*T) i32, data: ?*T) isize { + if (builtin.link_libc) { + return std.c.dl_iterate_phdr(@ptrCast(std.c.dl_iterate_phdr_callback, callback), @ptrCast(?*c_void, data)); + } + + const elf_base = @ptrToInt(&__ehdr_start); + const n_phdr = __ehdr_start.e_phnum; + const phdrs = (@intToPtr([*]elf.Phdr, elf_base + __ehdr_start.e_phoff))[0..n_phdr]; + + var it = dl.linkmap_iterator(phdrs) catch return 0; + + // The executable has no dynamic link segment, create a single entry for + // the whole ELF image + if (it.end()) { + var info = dl_phdr_info{ + .dlpi_addr = elf_base, + .dlpi_name = c"/proc/self/exe", + .dlpi_phdr = @intToPtr([*]elf.Phdr, elf_base + __ehdr_start.e_phoff), + .dlpi_phnum = __ehdr_start.e_phnum, + }; + + return callback(&info, @sizeOf(dl_phdr_info), data); + } + + // Last return value from the callback function + var last_r: isize = 0; + while (it.next()) |entry| { + var dlpi_phdr: usize = undefined; + var dlpi_phnum: u16 = undefined; + + if (entry.l_addr != 0) { + const elf_header = @intToPtr(*elf.Ehdr, entry.l_addr); + dlpi_phdr = entry.l_addr + elf_header.e_phoff; + dlpi_phnum = elf_header.e_phnum; + } else { + // This is the running ELF image + dlpi_phdr = elf_base + __ehdr_start.e_phoff; + dlpi_phnum = __ehdr_start.e_phnum; + } + + var info = dl_phdr_info{ + .dlpi_addr = entry.l_addr, + .dlpi_name = entry.l_name, + .dlpi_phdr = @intToPtr([*]elf.Phdr, dlpi_phdr), + .dlpi_phnum = dlpi_phnum, + }; + + last_r = callback(&info, @sizeOf(dl_phdr_info), data); + if (last_r != 0) break; + } + + return last_r; +} + +pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize { + return syscall2(SYS_io_uring_setup, entries, @ptrToInt(p)); +} + +pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize { + return syscall6(SYS_io_uring_enter, @bitCast(usize, isize(fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8); +} + +pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize { + return syscall4(SYS_io_uring_register, @bitCast(usize, isize(fd)), opcode, @ptrToInt(arg), nr_args); +} + +test "" { + if (is_the_target) { + _ = @import("linux/test.zig"); + } +} diff --git a/lib/std/os/linux/arm-eabi.zig b/lib/std/os/linux/arm-eabi.zig new file mode 100644 index 0000000000..a15234d742 --- /dev/null +++ b/lib/std/os/linux/arm-eabi.zig @@ -0,0 +1,96 @@ +pub fn syscall0(number: usize) usize { + return asm volatile ("svc #0" + : [ret] "={r0}" (-> usize) + : [number] "{r7}" (number) + : "memory" + ); +} + +pub fn syscall1(number: usize, arg1: usize) usize { + return asm volatile ("svc #0" + : [ret] "={r0}" (-> usize) + : [number] "{r7}" (number), + [arg1] "{r0}" (arg1) + : "memory" + ); +} + +pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { + return asm volatile ("svc #0" + : [ret] "={r0}" (-> usize) + : [number] "{r7}" (number), + [arg1] "{r0}" (arg1), + [arg2] "{r1}" (arg2) + : "memory" + ); +} + +pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { + return asm volatile ("svc #0" + : [ret] "={r0}" (-> usize) + : [number] "{r7}" (number), + [arg1] "{r0}" (arg1), + [arg2] "{r1}" (arg2), + [arg3] "{r2}" (arg3) + : "memory" + ); +} + +pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { + return asm volatile ("svc #0" + : [ret] "={r0}" (-> usize) + : [number] "{r7}" (number), + [arg1] "{r0}" (arg1), + [arg2] "{r1}" (arg2), + [arg3] "{r2}" (arg3), + [arg4] "{r3}" (arg4) + : "memory" + ); +} + +pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { + return asm volatile ("svc #0" + : [ret] "={r0}" (-> usize) + : [number] "{r7}" (number), + [arg1] "{r0}" (arg1), + [arg2] "{r1}" (arg2), + [arg3] "{r2}" (arg3), + [arg4] "{r3}" (arg4), + [arg5] "{r4}" (arg5) + : "memory" + ); +} + +pub fn syscall6( + number: usize, + arg1: usize, + arg2: usize, + arg3: usize, + arg4: usize, + arg5: usize, + arg6: usize, +) usize { + return asm volatile ("svc #0" + : [ret] "={r0}" (-> usize) + : [number] "{r7}" (number), + [arg1] "{r0}" (arg1), + [arg2] "{r1}" (arg2), + [arg3] "{r2}" (arg3), + [arg4] "{r3}" (arg4), + [arg5] "{r4}" (arg5), + [arg6] "{r5}" (arg6) + : "memory" + ); +} + +/// This matches the libc clone function. +pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; + +// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass +// that to llvm via zig, see https://github.com/ziglang/zig/issues/2883. +// LLVM expects libc to provide this function as __aeabi_read_tp, so it is exported if needed from special/c.zig. +pub extern fn getThreadPointer() usize { + return asm volatile ("mrc p15, 0, %[ret], c13, c0, 3" + : [ret] "=r" (-> usize) + ); +} diff --git a/lib/std/os/linux/arm64.zig b/lib/std/os/linux/arm64.zig new file mode 100644 index 0000000000..28da9af1c6 --- /dev/null +++ b/lib/std/os/linux/arm64.zig @@ -0,0 +1,87 @@ +pub fn syscall0(number: usize) usize { + return asm volatile ("svc #0" + : [ret] "={x0}" (-> usize) + : [number] "{x8}" (number) + : "memory", "cc" + ); +} + +pub fn syscall1(number: usize, arg1: usize) usize { + return asm volatile ("svc #0" + : [ret] "={x0}" (-> usize) + : [number] "{x8}" (number), + [arg1] "{x0}" (arg1) + : "memory", "cc" + ); +} + +pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { + return asm volatile ("svc #0" + : [ret] "={x0}" (-> usize) + : [number] "{x8}" (number), + [arg1] "{x0}" (arg1), + [arg2] "{x1}" (arg2) + : "memory", "cc" + ); +} + +pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { + return asm volatile ("svc #0" + : [ret] "={x0}" (-> usize) + : [number] "{x8}" (number), + [arg1] "{x0}" (arg1), + [arg2] "{x1}" (arg2), + [arg3] "{x2}" (arg3) + : "memory", "cc" + ); +} + +pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { + return asm volatile ("svc #0" + : [ret] "={x0}" (-> usize) + : [number] "{x8}" (number), + [arg1] "{x0}" (arg1), + [arg2] "{x1}" (arg2), + [arg3] "{x2}" (arg3), + [arg4] "{x3}" (arg4) + : "memory", "cc" + ); +} + +pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { + return asm volatile ("svc #0" + : [ret] "={x0}" (-> usize) + : [number] "{x8}" (number), + [arg1] "{x0}" (arg1), + [arg2] "{x1}" (arg2), + [arg3] "{x2}" (arg3), + [arg4] "{x3}" (arg4), + [arg5] "{x4}" (arg5) + : "memory", "cc" + ); +} + +pub fn syscall6( + number: usize, + arg1: usize, + arg2: usize, + arg3: usize, + arg4: usize, + arg5: usize, + arg6: usize, +) usize { + return asm volatile ("svc #0" + : [ret] "={x0}" (-> usize) + : [number] "{x8}" (number), + [arg1] "{x0}" (arg1), + [arg2] "{x1}" (arg2), + [arg3] "{x2}" (arg3), + [arg4] "{x3}" (arg4), + [arg5] "{x4}" (arg5), + [arg6] "{x5}" (arg6) + : "memory", "cc" + ); +} + +/// This matches the libc clone function. +pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig new file mode 100644 index 0000000000..7bfe0295d3 --- /dev/null +++ b/lib/std/os/linux/riscv64.zig @@ -0,0 +1,86 @@ +pub fn syscall0(number: usize) usize { + return asm volatile ("ecall" + : [ret] "={x10}" (-> usize) + : [number] "{x17}" (number) + : "memory" + ); +} + +pub fn syscall1(number: usize, arg1: usize) usize { + return asm volatile ("ecall" + : [ret] "={x10}" (-> usize) + : [number] "{x17}" (number), + [arg1] "{x10}" (arg1) + : "memory" + ); +} + +pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { + return asm volatile ("ecall" + : [ret] "={x10}" (-> usize) + : [number] "{x17}" (number), + [arg1] "{x10}" (arg1), + [arg2] "{x11}" (arg2) + : "memory" + ); +} + +pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { + return asm volatile ("ecall" + : [ret] "={x10}" (-> usize) + : [number] "{x17}" (number), + [arg1] "{x10}" (arg1), + [arg2] "{x11}" (arg2), + [arg3] "{x12}" (arg3) + : "memory" + ); +} + +pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { + return asm volatile ("ecall" + : [ret] "={x10}" (-> usize) + : [number] "{x17}" (number), + [arg1] "{x10}" (arg1), + [arg2] "{x11}" (arg2), + [arg3] "{x12}" (arg3), + [arg4] "{x13}" (arg4) + : "memory" + ); +} + +pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { + return asm volatile ("ecall" + : [ret] "={x10}" (-> usize) + : [number] "{x17}" (number), + [arg1] "{x10}" (arg1), + [arg2] "{x11}" (arg2), + [arg3] "{x12}" (arg3), + [arg4] "{x13}" (arg4), + [arg5] "{x14}" (arg5) + : "memory" + ); +} + +pub fn syscall6( + number: usize, + arg1: usize, + arg2: usize, + arg3: usize, + arg4: usize, + arg5: usize, + arg6: usize, +) usize { + return asm volatile ("ecall" + : [ret] "={x10}" (-> usize) + : [number] "{x17}" (number), + [arg1] "{x10}" (arg1), + [arg2] "{x11}" (arg2), + [arg3] "{x12}" (arg3), + [arg4] "{x13}" (arg4), + [arg5] "{x14}" (arg5), + [arg6] "{x15}" (arg6) + : "memory" + ); +} + +pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig new file mode 100644 index 0000000000..97bbcc402d --- /dev/null +++ b/lib/std/os/linux/test.zig @@ -0,0 +1,46 @@ +const std = @import("../../std.zig"); +const builtin = @import("builtin"); +const linux = std.os.linux; +const mem = std.mem; +const elf = std.elf; +const expect = std.testing.expect; + +test "getpid" { + expect(linux.getpid() != 0); +} + +test "timer" { + const epoll_fd = linux.epoll_create(); + var err: usize = linux.getErrno(epoll_fd); + expect(err == 0); + + const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0); + expect(linux.getErrno(timer_fd) == 0); + + const time_interval = linux.timespec{ + .tv_sec = 0, + .tv_nsec = 2000000, + }; + + const new_time = linux.itimerspec{ + .it_interval = time_interval, + .it_value = time_interval, + }; + + err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null); + expect(err == 0); + + var event = linux.epoll_event{ + .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET, + .data = linux.epoll_data{ .ptr = 0 }, + }; + + err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event); + expect(err == 0); + + const events_one: linux.epoll_event = undefined; + var events = [_]linux.epoll_event{events_one} ** 8; + + // TODO implicit cast from *[N]T to [*]T + err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1); +} diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig new file mode 100644 index 0000000000..167839570e --- /dev/null +++ b/lib/std/os/linux/tls.zig @@ -0,0 +1,285 @@ +const std = @import("std"); +const os = std.os; +const mem = std.mem; +const elf = std.elf; +const builtin = @import("builtin"); +const assert = std.debug.assert; + +// This file implements the two TLS variants [1] used by ELF-based systems. +// +// The variant I has the following layout in memory: +// ------------------------------------------------------- +// | DTV | Zig | DTV | Alignment | TLS | +// | storage | thread data | pointer | | block | +// ------------------------^------------------------------ +// `-- The thread pointer register points here +// +// In this case we allocate additional space for our control structure that's +// placed _before_ the DTV pointer together with the DTV. +// +// NOTE: Some systems such as power64 or mips use this variant with a twist: the +// alignment is not present and the tp and DTV addresses are offset by a +// constant. +// +// On the other hand the variant II has the following layout in memory: +// --------------------------------------- +// | TLS | TCB | Zig | DTV | +// | block | | thread data | storage | +// --------^------------------------------ +// `-- The thread pointer register points here +// +// The structure of the TCB is not defined by the ABI so we reserve enough space +// for a single pointer as some architectures such as i386 and x86_64 need a +// pointer to the TCB block itself at the address pointed by the tp. +// +// In this case the control structure and DTV are placed one after another right +// after the TLS block data. +// +// At the moment the DTV is very simple since we only support static TLS, all we +// need is a two word vector to hold the number of entries (1) and the address +// of the first TLS block. +// +// [1] https://www.akkadia.org/drepper/tls.pdf + +const TLSVariant = enum { + VariantI, + VariantII, +}; + +const tls_variant = switch (builtin.arch) { + .arm, .armeb, .aarch64, .aarch64_be, .riscv32, .riscv64, .mipsel => TLSVariant.VariantI, + .x86_64, .i386 => TLSVariant.VariantII, + else => @compileError("undefined tls_variant for this architecture"), +}; + +// Controls how many bytes are reserved for the Thread Control Block +const tls_tcb_size = switch (builtin.arch) { + // ARM EABI mandates enough space for two pointers: the first one points to + // the DTV while the second one is unspecified but reserved + .arm, .armeb, .aarch64, .aarch64_be => 2 * @sizeOf(usize), + else => @sizeOf(usize), +}; + +// Controls if the TCB should be aligned according to the TLS segment p_align +const tls_tcb_align_size = switch (builtin.arch) { + .arm, .armeb, .aarch64, .aarch64_be => true, + else => false, +}; + +// Controls if the TP points to the end of the TCB instead of its beginning +const tls_tp_points_past_tcb = switch (builtin.arch) { + .riscv32, .riscv64, .mipsel, .powerpc64, .powerpc64le => true, + else => false, +}; + +// Check if the architecture-specific parameters look correct +comptime { + if (tls_tcb_align_size and tls_variant != TLSVariant.VariantI) { + @compileError("tls_tcb_align_size is only meaningful for variant I TLS"); + } +} + +// Some architectures add some offset to the tp and dtv addresses in order to +// make the generated code more efficient + +const tls_tp_offset = switch (builtin.arch) { + .mipsel => 0x7000, + else => 0, +}; + +const tls_dtv_offset = switch (builtin.arch) { + .mipsel => 0x8000, + .riscv32, .riscv64 => 0x800, + else => 0, +}; + +// Per-thread storage for Zig's use +const CustomData = packed struct {}; + +// Dynamic Thread Vector +const DTV = packed struct { + entries: usize, + tls_block: [1]usize, +}; + +// Holds all the information about the process TLS image +const TLSImage = struct { + data_src: []u8, + alloc_size: usize, + tcb_offset: usize, + dtv_offset: usize, + data_offset: usize, +}; + +pub var tls_image: ?TLSImage = null; + +pub fn setThreadPointer(addr: usize) void { + switch (builtin.arch) { + .x86_64 => { + const rc = std.os.linux.syscall2(std.os.linux.SYS_arch_prctl, std.os.linux.ARCH_SET_FS, addr); + assert(rc == 0); + }, + .aarch64 => { + asm volatile ( + \\ msr tpidr_el0, %[addr] + : + : [addr] "r" (addr) + ); + }, + .arm => |arm| { + const rc = std.os.linux.syscall1(std.os.linux.SYS_set_tls, addr); + assert(rc == 0); + }, + .riscv64 => { + asm volatile ( + \\ mv tp, %[addr] + : + : [addr] "r" (addr) + ); + }, + else => @compileError("Unsupported architecture"), + } +} + +pub fn initTLS() ?*elf.Phdr { + var tls_phdr: ?*elf.Phdr = null; + var img_base: usize = 0; + + const auxv = std.os.linux.elf_aux_maybe.?; + var at_phent: usize = undefined; + var at_phnum: usize = undefined; + var at_phdr: usize = undefined; + var at_hwcap: usize = undefined; + + var i: usize = 0; + while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { + switch (auxv[i].a_type) { + elf.AT_PHENT => at_phent = auxv[i].a_un.a_val, + elf.AT_PHNUM => at_phnum = auxv[i].a_un.a_val, + elf.AT_PHDR => at_phdr = auxv[i].a_un.a_val, + elf.AT_HWCAP => at_hwcap = auxv[i].a_un.a_val, + else => continue, + } + } + + // Sanity check + assert(at_phent == @sizeOf(elf.Phdr)); + + // Search the TLS section + const phdrs = (@intToPtr([*]elf.Phdr, at_phdr))[0..at_phnum]; + + var gnu_stack: ?*elf.Phdr = null; + + for (phdrs) |*phdr| { + switch (phdr.p_type) { + elf.PT_PHDR => img_base = at_phdr - phdr.p_vaddr, + elf.PT_TLS => tls_phdr = phdr, + elf.PT_GNU_STACK => gnu_stack = phdr, + else => continue, + } + } + + if (tls_phdr) |phdr| { + // If the cpu is arm-based, check if it supports the TLS register + if (builtin.arch == builtin.Arch.arm and at_hwcap & std.os.linux.HWCAP_TLS == 0) { + // If the CPU does not support TLS via a coprocessor register, + // a kernel helper function can be used instead on certain linux kernels. + // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c. + @panic("TODO: Implement ARM fallback TLS functionality"); + } + + // Offsets into the allocated TLS area + var tcb_offset: usize = undefined; + var dtv_offset: usize = undefined; + var data_offset: usize = undefined; + var thread_data_offset: usize = undefined; + // Compute the total size of the ABI-specific data plus our own control + // structures + const alloc_size = switch (tls_variant) { + .VariantI => blk: { + var l: usize = 0; + dtv_offset = l; + l += @sizeOf(DTV); + thread_data_offset = l; + l += @sizeOf(CustomData); + l = mem.alignForward(l, phdr.p_align); + tcb_offset = l; + if (tls_tcb_align_size) { + l += mem.alignForward(tls_tcb_size, phdr.p_align); + } else { + l += tls_tcb_size; + } + data_offset = l; + l += phdr.p_memsz; + break :blk l; + }, + .VariantII => blk: { + var l: usize = 0; + data_offset = l; + l += phdr.p_memsz; + l = mem.alignForward(l, phdr.p_align); + tcb_offset = l; + l += tls_tcb_size; + thread_data_offset = l; + l += @sizeOf(CustomData); + dtv_offset = l; + l += @sizeOf(DTV); + break :blk l; + }, + }; + + tls_image = TLSImage{ + .data_src = @intToPtr([*]u8, phdr.p_vaddr + img_base)[0..phdr.p_filesz], + .alloc_size = alloc_size, + .tcb_offset = tcb_offset, + .dtv_offset = dtv_offset, + .data_offset = data_offset, + }; + } + + return gnu_stack; +} + +pub fn copyTLS(addr: usize) usize { + const tls_img = tls_image.?; + + // Be paranoid, clear the area we're going to use + @memset(@intToPtr([*]u8, addr), 0, tls_img.alloc_size); + // Prepare the DTV + const dtv = @intToPtr(*DTV, addr + tls_img.dtv_offset); + dtv.entries = 1; + dtv.tls_block[0] = addr + tls_img.data_offset + tls_dtv_offset; + // Set-up the TCB + const tcb_ptr = @intToPtr(*usize, addr + tls_img.tcb_offset); + if (tls_variant == TLSVariant.VariantI) { + tcb_ptr.* = addr + tls_img.dtv_offset; + } else { + tcb_ptr.* = addr + tls_img.tcb_offset; + } + // Copy the data + @memcpy(@intToPtr([*]u8, addr + tls_img.data_offset), tls_img.data_src.ptr, tls_img.data_src.len); + + // Return the corrected (if needed) value for the tp register + return addr + tls_tp_offset + + if (tls_tp_points_past_tcb) tls_img.data_offset else tls_img.tcb_offset; +} + +var main_thread_tls_buffer: [256]u8 align(32) = undefined; + +pub fn allocateTLS(size: usize) usize { + // Small TLS allocation, use our local buffer + if (size < main_thread_tls_buffer.len) { + return @ptrToInt(&main_thread_tls_buffer); + } + + const slice = os.mmap( + null, + size, + os.PROT_READ | os.PROT_WRITE, + os.MAP_PRIVATE | os.MAP_ANONYMOUS, + -1, + 0, + ) catch @panic("out of memory"); + + return @ptrToInt(slice.ptr); +} diff --git a/lib/std/os/linux/vdso.zig b/lib/std/os/linux/vdso.zig new file mode 100644 index 0000000000..86d54bfbf8 --- /dev/null +++ b/lib/std/os/linux/vdso.zig @@ -0,0 +1,91 @@ +const std = @import("../../std.zig"); +const elf = std.elf; +const linux = std.os.linux; +const mem = std.mem; +const maxInt = std.math.maxInt; + +pub fn lookup(vername: []const u8, name: []const u8) usize { + const vdso_addr = std.os.system.getauxval(std.elf.AT_SYSINFO_EHDR); + if (vdso_addr == 0) return 0; + + const eh = @intToPtr(*elf.Ehdr, vdso_addr); + var ph_addr: usize = vdso_addr + eh.e_phoff; + const ph = @intToPtr(*elf.Phdr, ph_addr); + + var maybe_dynv: ?[*]usize = null; + var base: usize = maxInt(usize); + { + var i: usize = 0; + while (i < eh.e_phnum) : ({ + i += 1; + ph_addr += eh.e_phentsize; + }) { + const this_ph = @intToPtr(*elf.Phdr, ph_addr); + switch (this_ph.p_type) { + elf.PT_LOAD => base = vdso_addr + this_ph.p_offset - this_ph.p_vaddr, + elf.PT_DYNAMIC => maybe_dynv = @intToPtr([*]usize, vdso_addr + this_ph.p_offset), + else => {}, + } + } + } + const dynv = maybe_dynv orelse return 0; + if (base == maxInt(usize)) return 0; + + var maybe_strings: ?[*]u8 = null; + var maybe_syms: ?[*]elf.Sym = null; + var maybe_hashtab: ?[*]linux.Elf_Symndx = null; + var maybe_versym: ?[*]u16 = null; + var maybe_verdef: ?*elf.Verdef = null; + + { + var i: usize = 0; + while (dynv[i] != 0) : (i += 2) { + const p = base + dynv[i + 1]; + switch (dynv[i]) { + elf.DT_STRTAB => maybe_strings = @intToPtr([*]u8, p), + elf.DT_SYMTAB => maybe_syms = @intToPtr([*]elf.Sym, p), + elf.DT_HASH => maybe_hashtab = @intToPtr([*]linux.Elf_Symndx, p), + elf.DT_VERSYM => maybe_versym = @intToPtr([*]u16, p), + elf.DT_VERDEF => maybe_verdef = @intToPtr(*elf.Verdef, p), + else => {}, + } + } + } + + const strings = maybe_strings orelse return 0; + const syms = maybe_syms orelse return 0; + const hashtab = maybe_hashtab orelse return 0; + if (maybe_verdef == null) maybe_versym = null; + + const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON); + const OK_BINDS = (1 << elf.STB_GLOBAL | 1 << elf.STB_WEAK | 1 << elf.STB_GNU_UNIQUE); + + var i: usize = 0; + while (i < hashtab[1]) : (i += 1) { + if (0 == (u32(1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue; + if (0 == (u32(1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; + if (0 == syms[i].st_shndx) continue; + if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue; + if (maybe_versym) |versym| { + if (!checkver(maybe_verdef.?, versym[i], vername, strings)) + continue; + } + return base + syms[i].st_value; + } + + return 0; +} + +fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*]u8) bool { + var def = def_arg; + const vsym = @bitCast(u32, vsym_arg) & 0x7fff; + while (true) { + if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym) + break; + if (def.vd_next == 0) + return false; + def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next); + } + const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux); + return mem.eql(u8, vername, mem.toSliceConst(u8, strings + aux.vda_name)); +} diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig new file mode 100644 index 0000000000..0f3a36636a --- /dev/null +++ b/lib/std/os/linux/x86_64.zig @@ -0,0 +1,97 @@ +usingnamespace @import("../bits.zig"); + +pub fn syscall0(number: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number) + : "rcx", "r11", "memory" + ); +} + +pub fn syscall1(number: usize, arg1: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1) + : "rcx", "r11", "memory" + ); +} + +pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2) + : "rcx", "r11", "memory" + ); +} + +pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3) + : "rcx", "r11", "memory" + ); +} + +pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4) + : "rcx", "r11", "memory" + ); +} + +pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4), + [arg5] "{r8}" (arg5) + : "rcx", "r11", "memory" + ); +} + +pub fn syscall6( + number: usize, + arg1: usize, + arg2: usize, + arg3: usize, + arg4: usize, + arg5: usize, + arg6: usize, +) usize { + return asm volatile ("syscall" + : [ret] "={rax}" (-> usize) + : [number] "{rax}" (number), + [arg1] "{rdi}" (arg1), + [arg2] "{rsi}" (arg2), + [arg3] "{rdx}" (arg3), + [arg4] "{r10}" (arg4), + [arg5] "{r8}" (arg5), + [arg6] "{r9}" (arg6) + : "rcx", "r11", "memory" + ); +} + +/// This matches the libc clone function. +pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: usize, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; + +pub nakedcc fn restore_rt() void { + return asm volatile ("syscall" + : + : [number] "{rax}" (usize(SYS_rt_sigreturn)) + : "rcx", "r11" + ); +} diff --git a/lib/std/os/netbsd.zig b/lib/std/os/netbsd.zig new file mode 100644 index 0000000000..d484e7374b --- /dev/null +++ b/lib/std/os/netbsd.zig @@ -0,0 +1,5 @@ +const builtin = @import("builtin"); +const std = @import("../std.zig"); +pub const is_the_target = builtin.os == .netbsd; +pub usingnamespace std.c; +pub usingnamespace @import("bits.zig"); diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig new file mode 100644 index 0000000000..87d57b36c0 --- /dev/null +++ b/lib/std/os/test.zig @@ -0,0 +1,225 @@ +const std = @import("../std.zig"); +const os = std.os; +const testing = std.testing; +const expect = std.testing.expect; +const io = std.io; +const fs = std.fs; +const mem = std.mem; +const elf = std.elf; +const File = std.fs.File; +const Thread = std.Thread; + +const a = std.debug.global_allocator; + +const builtin = @import("builtin"); +const AtomicRmwOp = builtin.AtomicRmwOp; +const AtomicOrder = builtin.AtomicOrder; + +test "makePath, put some files in it, deleteTree" { + try fs.makePath(a, "os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c"); + try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense"); + try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah"); + try fs.deleteTree(a, "os_test_tmp"); + if (fs.Dir.open(a, "os_test_tmp")) |dir| { + @panic("expected error"); + } else |err| { + expect(err == error.FileNotFound); + } +} + +test "access file" { + try fs.makePath(a, "os_test_tmp"); + if (File.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt")) |ok| { + @panic("expected error"); + } else |err| { + expect(err == error.FileNotFound); + } + + try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", ""); + try os.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", os.F_OK); + try fs.deleteTree(a, "os_test_tmp"); +} + +fn testThreadIdFn(thread_id: *Thread.Id) void { + thread_id.* = Thread.getCurrentId(); +} + +test "std.Thread.getCurrentId" { + if (builtin.single_threaded) return error.SkipZigTest; + + var thread_current_id: Thread.Id = undefined; + const thread = try Thread.spawn(&thread_current_id, testThreadIdFn); + const thread_id = thread.handle(); + thread.wait(); + if (Thread.use_pthreads) { + expect(thread_current_id == thread_id); + } else if (os.windows.is_the_target) { + expect(Thread.getCurrentId() != thread_current_id); + } else { + // If the thread completes very quickly, then thread_id can be 0. See the + // documentation comments for `std.Thread.handle`. + expect(thread_id == 0 or thread_current_id == thread_id); + } +} + +test "spawn threads" { + if (builtin.single_threaded) return error.SkipZigTest; + + var shared_ctx: i32 = 1; + + const thread1 = try Thread.spawn({}, start1); + const thread2 = try Thread.spawn(&shared_ctx, start2); + const thread3 = try Thread.spawn(&shared_ctx, start2); + const thread4 = try Thread.spawn(&shared_ctx, start2); + + thread1.wait(); + thread2.wait(); + thread3.wait(); + thread4.wait(); + + expect(shared_ctx == 4); +} + +fn start1(ctx: void) u8 { + return 0; +} + +fn start2(ctx: *i32) u8 { + _ = @atomicRmw(i32, ctx, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst); + return 0; +} + +test "cpu count" { + const cpu_count = try Thread.cpuCount(); + expect(cpu_count >= 1); +} + +test "AtomicFile" { + if (builtin.arch == .aarch64 and builtin.glibc_version != null) { + // TODO https://github.com/ziglang/zig/issues/3288 + return error.SkipZigTest; + } + var buffer: [1024]u8 = undefined; + const allocator = &std.heap.FixedBufferAllocator.init(buffer[0..]).allocator; + const test_out_file = "tmp_atomic_file_test_dest.txt"; + const test_content = + \\ hello! + \\ this is a test file + ; + { + var af = try fs.AtomicFile.init(test_out_file, File.default_mode); + defer af.deinit(); + try af.file.write(test_content); + try af.finish(); + } + const content = try io.readFileAlloc(allocator, test_out_file); + expect(mem.eql(u8, content, test_content)); + + try fs.deleteFile(test_out_file); +} + +test "thread local storage" { + if (builtin.single_threaded) return error.SkipZigTest; + const thread1 = try Thread.spawn({}, testTls); + const thread2 = try Thread.spawn({}, testTls); + testTls({}); + thread1.wait(); + thread2.wait(); +} + +threadlocal var x: i32 = 1234; +fn testTls(context: void) void { + if (x != 1234) @panic("bad start value"); + x += 1; + if (x != 1235) @panic("bad end value"); +} + +test "getrandom" { + var buf_a: [50]u8 = undefined; + var buf_b: [50]u8 = undefined; + try os.getrandom(&buf_a); + try os.getrandom(&buf_b); + // If this test fails the chance is significantly higher that there is a bug than + // that two sets of 50 bytes were equal. + expect(!mem.eql(u8, buf_a, buf_b)); +} + +test "getcwd" { + // at least call it so it gets compiled + var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + _ = os.getcwd(&buf) catch undefined; +} + +test "realpath" { + var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + testing.expectError(error.FileNotFound, fs.realpath("definitely_bogus_does_not_exist1234", &buf)); +} + +test "sigaltstack" { + if (builtin.os == .windows or builtin.os == .wasi) return error.SkipZigTest; + + var st: os.stack_t = undefined; + try os.sigaltstack(null, &st); + // Setting a stack size less than MINSIGSTKSZ returns ENOMEM + st.ss_flags = 0; + st.ss_size = 1; + testing.expectError(error.SizeTooSmall, os.sigaltstack(&st, null)); +} + +// If the type is not available use void to avoid erroring out when `iter_fn` is +// analyzed +const dl_phdr_info = if (@hasDecl(os, "dl_phdr_info")) os.dl_phdr_info else c_void; + +export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 { + if (builtin.os == .windows or builtin.os == .wasi or builtin.os == .macosx) + return 0; + + var counter = data.?; + // Count how many libraries are loaded + counter.* += usize(1); + + // The image should contain at least a PT_LOAD segment + if (info.dlpi_phnum < 1) return -1; + + // Quick & dirty validation of the phdr pointers, make sure we're not + // pointing to some random gibberish + var i: usize = 0; + var found_load = false; + while (i < info.dlpi_phnum) : (i += 1) { + const phdr = info.dlpi_phdr[i]; + + if (phdr.p_type != elf.PT_LOAD) continue; + + // Find the ELF header + const elf_header = @intToPtr(*elf.Ehdr, phdr.p_vaddr - phdr.p_offset); + // Validate the magic + if (!mem.eql(u8, elf_header.e_ident[0..4], "\x7fELF")) return -1; + // Consistency check + if (elf_header.e_phnum != info.dlpi_phnum) return -1; + + found_load = true; + break; + } + + if (!found_load) return -1; + + return 42; +} + +test "dl_iterate_phdr" { + if (builtin.os == .windows or builtin.os == .wasi or builtin.os == .macosx) + return error.SkipZigTest; + + var counter: usize = 0; + expect(os.dl_iterate_phdr(usize, iter_fn, &counter) != 0); + expect(counter != 0); +} + +test "gethostname" { + if (os.windows.is_the_target) + return error.SkipZigTest; + + var buf: [os.HOST_NAME_MAX]u8 = undefined; + const hostname = try os.gethostname(&buf); + expect(hostname.len != 0); +} diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig new file mode 100644 index 0000000000..db46d50c1f --- /dev/null +++ b/lib/std/os/uefi.zig @@ -0,0 +1,45 @@ +pub const protocols = @import("uefi/protocols.zig"); +pub const status = @import("uefi/status.zig"); +pub const tables = @import("uefi/tables.zig"); + +const builtin = @import("builtin"); +pub const is_the_target = builtin.os == .uefi; + +pub var handle: Handle = undefined; +pub var system_table: *tables.SystemTable = undefined; + +pub const Event = *@OpaqueType(); +// GUIDs must be align(8) +pub const Guid = extern struct { + time_low: u32, + time_mid: u16, + time_high_and_version: u16, + clock_seq_high_and_reserved: u8, + clock_seq_low: u8, + node: [6]u8, +}; +pub const Handle = *@OpaqueType(); +pub const Time = extern struct { + year: u16, + month: u8, + day: u8, + hour: u8, + minute: u8, + second: u8, + _pad1: u8, + nanosecond: u32, + timezone: i16, + daylight: packed struct { + _pad1: u6, + in_daylight: bool, + adjust_daylight: bool, + }, + _pad2: u8, + + pub const unspecified_timezone: i16 = 0x7ff; +}; +pub const TimeCapabilities = extern struct { + resolution: u32, + accuracy: u32, + sets_to_zero: bool, +}; diff --git a/lib/std/os/uefi/protocols.zig b/lib/std/os/uefi/protocols.zig new file mode 100644 index 0000000000..2c8d870af0 --- /dev/null +++ b/lib/std/os/uefi/protocols.zig @@ -0,0 +1,32 @@ +pub const InputKey = @import("protocols/simple_text_input_ex_protocol.zig").InputKey; +pub const KeyData = @import("protocols/simple_text_input_ex_protocol.zig").KeyData; +pub const KeyState = @import("protocols/simple_text_input_ex_protocol.zig").KeyState; +pub const SimpleTextInputExProtocol = @import("protocols/simple_text_input_ex_protocol.zig").SimpleTextInputExProtocol; + +pub const SimpleTextOutputMode = @import("protocols/simple_text_output_protocol.zig").SimpleTextOutputMode; +pub const SimpleTextOutputProtocol = @import("protocols/simple_text_output_protocol.zig").SimpleTextOutputProtocol; + +pub const SimplePointerMode = @import("protocols/simple_pointer_protocol.zig").SimplePointerMode; +pub const SimplePointerProtocol = @import("protocols/simple_pointer_protocol.zig").SimplePointerProtocol; +pub const SimplePointerState = @import("protocols/simple_pointer_protocol.zig").SimplePointerState; + +pub const AbsolutePointerMode = @import("protocols/absolute_pointer_protocol.zig").AbsolutePointerMode; +pub const AbsolutePointerProtocol = @import("protocols/absolute_pointer_protocol.zig").AbsolutePointerProtocol; +pub const AbsolutePointerState = @import("protocols/absolute_pointer_protocol.zig").AbsolutePointerState; + +pub const GraphicsOutputBltPixel = @import("protocols/graphics_output_protocol.zig").GraphicsOutputBltPixel; +pub const GraphicsOutputBltOperation = @import("protocols/graphics_output_protocol.zig").GraphicsOutputBltOperation; +pub const GraphicsOutputModeInformation = @import("protocols/graphics_output_protocol.zig").GraphicsOutputModeInformation; +pub const GraphicsOutputProtocol = @import("protocols/graphics_output_protocol.zig").GraphicsOutputProtocol; +pub const GraphicsOutputProtocolMode = @import("protocols/graphics_output_protocol.zig").GraphicsOutputProtocolMode; +pub const GraphicsPixelFormat = @import("protocols/graphics_output_protocol.zig").GraphicsPixelFormat; +pub const PixelBitmask = @import("protocols/graphics_output_protocol.zig").PixelBitmask; + +pub const EdidDiscoveredProtocol = @import("protocols/edid_discovered_protocol.zig").EdidDiscoveredProtocol; + +pub const EdidActiveProtocol = @import("protocols/edid_active_protocol.zig").EdidActiveProtocol; + +pub const EdidOverrideProtocol = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocol; +pub const EdidOverrideProtocolAttributes = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocolAttributes; + +pub const RNGProtocol = @import("protocols/rng_protocol.zig").RNGProtocol; diff --git a/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig b/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig new file mode 100644 index 0000000000..df5a930319 --- /dev/null +++ b/lib/std/os/uefi/protocols/absolute_pointer_protocol.zig @@ -0,0 +1,53 @@ +const uefi = @import("std").os.uefi; +const Event = uefi.Event; +const Guid = uefi.Guid; + +/// UEFI Specification, Version 2.8, 12.7 +pub const AbsolutePointerProtocol = extern struct { + _reset: extern fn (*const AbsolutePointerProtocol, bool) usize, + _get_state: extern fn (*const AbsolutePointerProtocol, *AbsolutePointerState) usize, + wait_for_input: Event, + mode: *AbsolutePointerMode, + + pub fn reset(self: *const AbsolutePointerProtocol, verify: bool) usize { + return self._reset(self, verify); + } + + pub fn getState(self: *const AbsolutePointerProtocol, state: *AbsolutePointerState) usize { + return self._get_state(self, state); + } + + pub const guid align(8) = Guid{ + .time_low = 0x8d59d32b, + .time_mid = 0xc655, + .time_high_and_version = 0x4ae9, + .clock_seq_high_and_reserved = 0x9b, + .clock_seq_low = 0x15, + .node = [_]u8{ 0xf2, 0x59, 0x04, 0x99, 0x2a, 0x43 }, + }; +}; + +pub const AbsolutePointerMode = extern struct { + absolute_min_x: u64, + absolute_min_y: u64, + absolute_min_z: u64, + absolute_max_x: u64, + absolute_max_y: u64, + absolute_max_z: u64, + attributes: packed struct { + supports_alt_active: bool, + supports_pressure_as_z: bool, + _pad1: u30, + }, +}; + +pub const AbsolutePointerState = extern struct { + current_x: u64 = undefined, + current_y: u64 = undefined, + current_z: u64 = undefined, + active_buttons: packed struct { + touch_active: bool, + alt_active: bool, + _pad1: u30, + } = undefined, +}; diff --git a/lib/std/os/uefi/protocols/edid_active_protocol.zig b/lib/std/os/uefi/protocols/edid_active_protocol.zig new file mode 100644 index 0000000000..1a96cb6cd5 --- /dev/null +++ b/lib/std/os/uefi/protocols/edid_active_protocol.zig @@ -0,0 +1,17 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; + +/// UEFI Specification, Version 2.8, 12.9 +pub const EdidActiveProtocol = extern struct { + size_of_edid: u32, + edid: ?[*]u8, + + pub const guid align(8) = Guid{ + .time_low = 0xbd8c1056, + .time_mid = 0x9f36, + .time_high_and_version = 0x44ec, + .clock_seq_high_and_reserved = 0x92, + .clock_seq_low = 0xa8, + .node = [_]u8{ 0xa6, 0x33, 0x7f, 0x81, 0x79, 0x86 }, + }; +}; diff --git a/lib/std/os/uefi/protocols/edid_discovered_protocol.zig b/lib/std/os/uefi/protocols/edid_discovered_protocol.zig new file mode 100644 index 0000000000..f68b0fa3d6 --- /dev/null +++ b/lib/std/os/uefi/protocols/edid_discovered_protocol.zig @@ -0,0 +1,17 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; + +/// UEFI Specification, Version 2.8, 12.9 +pub const EdidDiscoveredProtocol = extern struct { + size_of_edid: u32, + edid: ?[*]u8, + + pub const guid align(8) = Guid{ + .time_low = 0x1c0c34f6, + .time_mid = 0xd380, + .time_high_and_version = 0x41fa, + .clock_seq_high_and_reserved = 0xa0, + .clock_seq_low = 0x49, + .node = [_]u8{ 0x8a, 0xd0, 0x6c, 0x1a, 0x66, 0xaa }, + }; +}; diff --git a/lib/std/os/uefi/protocols/edid_override_protocol.zig b/lib/std/os/uefi/protocols/edid_override_protocol.zig new file mode 100644 index 0000000000..ad2eec1207 --- /dev/null +++ b/lib/std/os/uefi/protocols/edid_override_protocol.zig @@ -0,0 +1,28 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; +const Handle = uefi.Handle; + +/// UEFI Specification, Version 2.8, 12.9 +pub const EdidOverrideProtocol = extern struct { + _get_edid: extern fn (*const EdidOverrideProtocol, Handle, *u32, *usize, *?[*]u8) usize, + + /// attributes must be align(4) + pub fn getEdid(self: *const EdidOverrideProtocol, handle: Handle, attributes: *EdidOverrideProtocolAttributes, edid_size: *usize, edid: *?[*]u8) usize { + return self._get_edid(self, handle, attributes, edid_size, edid); + } + + pub const guid align(8) = Guid{ + .time_low = 0x48ecb431, + .time_mid = 0xfb72, + .time_high_and_version = 0x45c0, + .clock_seq_high_and_reserved = 0xa9, + .clock_seq_low = 0x22, + .node = [_]u8{ 0xf4, 0x58, 0xfe, 0x04, 0x0b, 0xd5 }, + }; +}; + +pub const EdidOverrideProtocolAttributes = packed struct { + dont_override: bool, + enable_hot_plug: bool, + _pad1: u30, +}; diff --git a/lib/std/os/uefi/protocols/graphics_output_protocol.zig b/lib/std/os/uefi/protocols/graphics_output_protocol.zig new file mode 100644 index 0000000000..4713df0501 --- /dev/null +++ b/lib/std/os/uefi/protocols/graphics_output_protocol.zig @@ -0,0 +1,79 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; + +/// UEFI Specification, Version 2.8, 12.9 +pub const GraphicsOutputProtocol = extern struct { + _query_mode: extern fn (*const GraphicsOutputProtocol, u32, *usize, **GraphicsOutputModeInformation) usize, + _set_mode: extern fn (*const GraphicsOutputProtocol, u32) usize, + _blt: extern fn (*const GraphicsOutputProtocol, ?[*]GraphicsOutputBltPixel, GraphicsOutputBltOperation, usize, usize, usize, usize, usize, usize, usize) usize, + mode: *GraphicsOutputProtocolMode, + + pub fn queryMode(self: *const GraphicsOutputProtocol, mode: u32, size_of_info: *usize, info: **GraphicsOutputModeInformation) usize { + return self._query_mode(self, mode, size_of_info, info); + } + + pub fn setMode(self: *const GraphicsOutputProtocol, mode: u32) usize { + return self._set_mode(self, mode); + } + + pub fn blt(self: *const GraphicsOutputProtocol, blt_buffer: ?[*]GraphicsOutputBltPixel, blt_operation: GraphicsOutputBltOperation, source_x: usize, source_y: usize, destination_x: usize, destination_y: usize, width: usize, height: usize, delta: usize) usize { + return self._blt(self, blt_buffer, blt_operation, source_x, source_y, destination_x, destination_y, width, height, delta); + } + + pub const guid align(8) = Guid{ + .time_low = 0x9042a9de, + .time_mid = 0x23dc, + .time_high_and_version = 0x4a38, + .clock_seq_high_and_reserved = 0x96, + .clock_seq_low = 0xfb, + .node = [_]u8{ 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a }, + }; +}; + +pub const GraphicsOutputProtocolMode = extern struct { + max_mode: u32, + mode: u32, + info: *GraphicsOutputModeInformation, + size_of_info: usize, + frame_buffer_base: u64, + frame_buffer_size: usize, +}; + +pub const GraphicsOutputModeInformation = extern struct { + version: u32 = undefined, + horizontal_resolution: u32 = undefined, + vertical_resolution: u32 = undefined, + pixel_format: GraphicsPixelFormat = undefined, + pixel_information: PixelBitmask = undefined, + pixels_per_scan_line: u32 = undefined, +}; + +pub const GraphicsPixelFormat = extern enum(u32) { + PixelRedGreenBlueReserved8BitPerColor, + PixelBlueGreenRedReserved8BitPerColor, + PixelBitMask, + PixelBltOnly, + PixelFormatMax, +}; + +pub const PixelBitmask = extern struct { + red_mask: u32, + green_mask: u32, + blue_mask: u32, + reserved_mask: u32, +}; + +pub const GraphicsOutputBltPixel = extern struct { + blue: u8, + green: u8, + red: u8, + reserved: u8 = undefined, +}; + +pub const GraphicsOutputBltOperation = extern enum(u32) { + BltVideoFill, + BltVideoToBltBuffer, + BltBufferToVideo, + BltVideoToVideo, + GraphicsOutputBltOperationMax, +}; diff --git a/lib/std/os/uefi/protocols/rng_protocol.zig b/lib/std/os/uefi/protocols/rng_protocol.zig new file mode 100644 index 0000000000..565832caf9 --- /dev/null +++ b/lib/std/os/uefi/protocols/rng_protocol.zig @@ -0,0 +1,73 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; + +/// UEFI Specification, Version 2.8, 37.5 +pub const RNGProtocol = extern struct { + _get_info: extern fn (*const RNGProtocol, *usize, [*]align(8) Guid) usize, + _get_rng: extern fn (*const RNGProtocol, ?*align(8) const Guid, usize, [*]u8) usize, + + pub fn getInfo(self: *const RNGProtocol, list_size: *usize, list: [*]align(8) Guid) usize { + return self._get_info(self, list_size, list); + } + + pub fn getRNG(self: *const RNGProtocol, algo: ?*const Guid, value_length: usize, value: [*]u8) usize { + return self._get_rng(self, algo, value_length, value); + } + + pub const guid align(8) = Guid{ + .time_low = 0x3152bca5, + .time_mid = 0xeade, + .time_high_and_version = 0x433d, + .clock_seq_high_and_reserved = 0x86, + .clock_seq_low = 0x2e, + .node = [_]u8{ 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 }, + }; + pub const algorithm_sp800_90_hash_256 align(8) = Guid{ + .time_low = 0xa7af67cb, + .time_mid = 0x603b, + .time_high_and_version = 0x4d42, + .clock_seq_high_and_reserved = 0xba, + .clock_seq_low = 0x21, + .node = [_]u8{ 0x70, 0xbf, 0xb6, 0x29, 0x3f, 0x96 }, + }; + pub const algorithm_sp800_90_hmac_256 align(8) = Guid{ + .time_low = 0xc5149b43, + .time_mid = 0xae85, + .time_high_and_version = 0x4f53, + .clock_seq_high_and_reserved = 0x99, + .clock_seq_low = 0x82, + .node = [_]u8{ 0xb9, 0x43, 0x35, 0xd3, 0xa9, 0xe7 }, + }; + pub const algorithm_sp800_90_ctr_256 align(8) = Guid{ + .time_low = 0x44f0de6e, + .time_mid = 0x4d8c, + .time_high_and_version = 0x4045, + .clock_seq_high_and_reserved = 0xa8, + .clock_seq_low = 0xc7, + .node = [_]u8{ 0x4d, 0xd1, 0x68, 0x85, 0x6b, 0x9e }, + }; + pub const algorithm_x9_31_3des align(8) = Guid{ + .time_low = 0x63c4785a, + .time_mid = 0xca34, + .time_high_and_version = 0x4012, + .clock_seq_high_and_reserved = 0xa3, + .clock_seq_low = 0xc8, + .node = [_]u8{ 0x0b, 0x6a, 0x32, 0x4f, 0x55, 0x46 }, + }; + pub const algorithm_x9_31_aes align(8) = Guid{ + .time_low = 0xacd03321, + .time_mid = 0x777e, + .time_high_and_version = 0x4d3d, + .clock_seq_high_and_reserved = 0xb1, + .clock_seq_low = 0xc8, + .node = [_]u8{ 0x20, 0xcf, 0xd8, 0x88, 0x20, 0xc9 }, + }; + pub const algorithm_raw align(8) = Guid{ + .time_low = 0xe43176d7, + .time_mid = 0xb6e8, + .time_high_and_version = 0x4827, + .clock_seq_high_and_reserved = 0xb7, + .clock_seq_low = 0x84, + .node = [_]u8{ 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61 }, + }; +}; diff --git a/lib/std/os/uefi/protocols/simple_pointer_protocol.zig b/lib/std/os/uefi/protocols/simple_pointer_protocol.zig new file mode 100644 index 0000000000..369bc76aaa --- /dev/null +++ b/lib/std/os/uefi/protocols/simple_pointer_protocol.zig @@ -0,0 +1,44 @@ +const uefi = @import("std").os.uefi; +const Event = uefi.Event; +const Guid = uefi.Guid; + +/// UEFI Specification, Version 2.8, 12.5 +pub const SimplePointerProtocol = struct { + _reset: extern fn (*const SimplePointerProtocol, bool) usize, + _get_state: extern fn (*const SimplePointerProtocol, *SimplePointerState) usize, + wait_for_input: Event, + mode: *SimplePointerMode, + + pub fn reset(self: *const SimplePointerProtocol, verify: bool) usize { + return self._reset(self, verify); + } + + pub fn getState(self: *const SimplePointerProtocol, state: *SimplePointerState) usize { + return self._get_state(self, state); + } + + pub const guid align(8) = Guid{ + .time_low = 0x31878c87, + .time_mid = 0x0b75, + .time_high_and_version = 0x11d5, + .clock_seq_high_and_reserved = 0x9a, + .clock_seq_low = 0x4f, + .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, + }; +}; + +pub const SimplePointerMode = struct { + resolution_x: u64, + resolution_y: u64, + resolution_z: u64, + left_button: bool, + right_button: bool, +}; + +pub const SimplePointerState = struct { + relative_movement_x: i32 = undefined, + relative_movement_y: i32 = undefined, + relative_movement_z: i32 = undefined, + left_button: bool = undefined, + right_button: bool = undefined, +}; diff --git a/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig b/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig new file mode 100644 index 0000000000..5507b8950c --- /dev/null +++ b/lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig @@ -0,0 +1,77 @@ +const uefi = @import("std").os.uefi; +const Event = uefi.Event; +const Guid = uefi.Guid; + +/// UEFI Specification, Version 2.8, 12.3 +pub const SimpleTextInputExProtocol = extern struct { + _reset: extern fn (*const SimpleTextInputExProtocol, bool) usize, + _read_key_stroke_ex: extern fn (*const SimpleTextInputExProtocol, *KeyData) usize, + wait_for_key_ex: Event, + _set_state: extern fn (*const SimpleTextInputExProtocol, *const u8) usize, + _register_key_notify: extern fn (*const SimpleTextInputExProtocol, *const KeyData, extern fn (*const KeyData) usize, **c_void) usize, + _unregister_key_notify: extern fn (*const SimpleTextInputExProtocol, *const c_void) usize, + + pub fn reset(self: *const SimpleTextInputExProtocol, verify: bool) usize { + return self._reset(self, verify); + } + + pub fn readKeyStrokeEx(self: *const SimpleTextInputExProtocol, key_data: *KeyData) usize { + return self._read_key_stroke_ex(self, key_data); + } + + pub fn setState(self: *const SimpleTextInputExProtocol, state: *const u8) usize { + return self._set_state(self, state); + } + + pub fn registerKeyNotify(self: *const SimpleTextInputExProtocol, key_data: *const KeyData, notify: extern fn (*const KeyData) usize, handle: **c_void) usize { + return self._register_key_notify(self, key_data, notify, handle); + } + + pub fn unregisterKeyNotify(self: *const SimpleTextInputExProtocol, handle: *const c_void) usize { + return self._unregister_key_notify(self, handle); + } + + pub const guid align(8) = Guid{ + .time_low = 0xdd9e7534, + .time_mid = 0x7762, + .time_high_and_version = 0x4698, + .clock_seq_high_and_reserved = 0x8c, + .clock_seq_low = 0x14, + .node = [_]u8{ 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa }, + }; +}; + +pub const KeyData = extern struct { + key: InputKey = undefined, + key_state: KeyState = undefined, +}; + +pub const KeyState = extern struct { + key_shift_state: packed struct { + right_shift_pressed: bool, + left_shift_pressed: bool, + right_control_pressed: bool, + left_control_pressed: bool, + right_alt_pressed: bool, + left_alt_pressed: bool, + right_logo_pressed: bool, + left_logo_pressed: bool, + menu_key_pressed: bool, + sys_req_pressed: bool, + _pad1: u21, + shift_state_valid: bool, + }, + key_toggle_state: packed struct { + scroll_lock_active: bool, + num_lock_active: bool, + caps_lock_active: bool, + _pad1: u3, + key_state_exposed: bool, + toggle_state_valid: bool, + }, +}; + +pub const InputKey = extern struct { + scan_code: u16, + unicode_char: u16, +}; diff --git a/lib/std/os/uefi/protocols/simple_text_output_protocol.zig b/lib/std/os/uefi/protocols/simple_text_output_protocol.zig new file mode 100644 index 0000000000..e6b2e21c70 --- /dev/null +++ b/lib/std/os/uefi/protocols/simple_text_output_protocol.zig @@ -0,0 +1,143 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; + +/// UEFI Specification, Version 2.8, 12.4 +pub const SimpleTextOutputProtocol = extern struct { + _reset: extern fn (*const SimpleTextOutputProtocol, bool) usize, + _output_string: extern fn (*const SimpleTextOutputProtocol, [*]const u16) usize, + _test_string: extern fn (*const SimpleTextOutputProtocol, [*]const u16) usize, + _query_mode: extern fn (*const SimpleTextOutputProtocol, usize, *usize, *usize) usize, + _set_mode: extern fn (*const SimpleTextOutputProtocol, usize) usize, + _set_attribute: extern fn (*const SimpleTextOutputProtocol, usize) usize, + _clear_screen: extern fn (*const SimpleTextOutputProtocol) usize, + _set_cursor_position: extern fn (*const SimpleTextOutputProtocol, usize, usize) usize, + _enable_cursor: extern fn (*const SimpleTextOutputProtocol, bool) usize, + mode: *SimpleTextOutputMode, + + pub fn reset(self: *const SimpleTextOutputProtocol, verify: bool) usize { + return self._reset(self, verify); + } + + pub fn outputString(self: *const SimpleTextOutputProtocol, msg: [*]const u16) usize { + return self._output_string(self, msg); + } + + pub fn testString(self: *const SimpleTextOutputProtocol, msg: [*]const u16) usize { + return self._test_string(self, msg); + } + + pub fn queryMode(self: *const SimpleTextOutputProtocol, mode_number: usize, columns: *usize, rows: *usize) usize { + return self._query_mode(self, mode_number, columns, rows); + } + + pub fn setMode(self: *const SimpleTextOutputProtocol, mode_number: usize) usize { + return self._set_mode(self, mode_number); + } + + pub fn setAttribute(self: *const SimpleTextOutputProtocol, attribute: usize) usize { + return self._set_attribute(self, attribute); + } + + pub fn clearScreen(self: *const SimpleTextOutputProtocol) usize { + return self._clear_screen(self); + } + + pub fn setCursorPosition(self: *const SimpleTextOutputProtocol, column: usize, row: usize) usize { + return self._set_cursor_position(self, column, row); + } + + pub fn enableCursor(self: *const SimpleTextOutputProtocol, visible: bool) usize { + return self._enable_cursor(self, visible); + } + + pub const guid align(8) = Guid{ + .time_low = 0x387477c2, + .time_mid = 0x69c7, + .time_high_and_version = 0x11d2, + .clock_seq_high_and_reserved = 0x8e, + .clock_seq_low = 0x39, + .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b }, + }; + pub const boxdraw_horizontal: u16 = 0x2500; + pub const boxdraw_vertical: u16 = 0x2502; + pub const boxdraw_down_right: u16 = 0x250c; + pub const boxdraw_down_left: u16 = 0x2510; + pub const boxdraw_up_right: u16 = 0x2514; + pub const boxdraw_up_left: u16 = 0x2518; + pub const boxdraw_vertical_right: u16 = 0x251c; + pub const boxdraw_vertical_left: u16 = 0x2524; + pub const boxdraw_down_horizontal: u16 = 0x252c; + pub const boxdraw_up_horizontal: u16 = 0x2534; + pub const boxdraw_vertical_horizontal: u16 = 0x253c; + pub const boxdraw_double_horizontal: u16 = 0x2550; + pub const boxdraw_double_vertical: u16 = 0x2551; + pub const boxdraw_down_right_double: u16 = 0x2552; + pub const boxdraw_down_double_right: u16 = 0x2553; + pub const boxdraw_double_down_right: u16 = 0x2554; + pub const boxdraw_down_left_double: u16 = 0x2555; + pub const boxdraw_down_double_left: u16 = 0x2556; + pub const boxdraw_double_down_left: u16 = 0x2557; + pub const boxdraw_up_right_double: u16 = 0x2558; + pub const boxdraw_up_double_right: u16 = 0x2559; + pub const boxdraw_double_up_right: u16 = 0x255a; + pub const boxdraw_up_left_double: u16 = 0x255b; + pub const boxdraw_up_double_left: u16 = 0x255c; + pub const boxdraw_double_up_left: u16 = 0x255d; + pub const boxdraw_vertical_right_double: u16 = 0x255e; + pub const boxdraw_vertical_double_right: u16 = 0x255f; + pub const boxdraw_double_vertical_right: u16 = 0x2560; + pub const boxdraw_vertical_left_double: u16 = 0x2561; + pub const boxdraw_vertical_double_left: u16 = 0x2562; + pub const boxdraw_double_vertical_left: u16 = 0x2563; + pub const boxdraw_down_horizontal_double: u16 = 0x2564; + pub const boxdraw_down_double_horizontal: u16 = 0x2565; + pub const boxdraw_double_down_horizontal: u16 = 0x2566; + pub const boxdraw_up_horizontal_double: u16 = 0x2567; + pub const boxdraw_up_double_horizontal: u16 = 0x2568; + pub const boxdraw_double_up_horizontal: u16 = 0x2569; + pub const boxdraw_vertical_horizontal_double: u16 = 0x256a; + pub const boxdraw_vertical_double_horizontal: u16 = 0x256b; + pub const boxdraw_double_vertical_horizontal: u16 = 0x256c; + pub const blockelement_full_block: u16 = 0x2588; + pub const blockelement_light_shade: u16 = 0x2591; + pub const geometricshape_up_triangle: u16 = 0x25b2; + pub const geometricshape_right_triangle: u16 = 0x25ba; + pub const geometricshape_down_triangle: u16 = 0x25bc; + pub const geometricshape_left_triangle: u16 = 0x25c4; + pub const arrow_up: u16 = 0x2591; + pub const arrow_down: u16 = 0x2593; + pub const black: u8 = 0x00; + pub const blue: u8 = 0x01; + pub const green: u8 = 0x02; + pub const cyan: u8 = 0x03; + pub const red: u8 = 0x04; + pub const magenta: u8 = 0x05; + pub const brown: u8 = 0x06; + pub const lightgray: u8 = 0x07; + pub const bright: u8 = 0x08; + pub const darkgray: u8 = 0x08; + pub const lightblue: u8 = 0x09; + pub const lightgreen: u8 = 0x0a; + pub const lightcyan: u8 = 0x0b; + pub const lightred: u8 = 0x0c; + pub const lightmagenta: u8 = 0x0d; + pub const yellow: u8 = 0x0e; + pub const white: u8 = 0x0f; + pub const background_black: u8 = 0x00; + pub const background_blue: u8 = 0x10; + pub const background_green: u8 = 0x20; + pub const background_cyan: u8 = 0x30; + pub const background_red: u8 = 0x40; + pub const background_magenta: u8 = 0x50; + pub const background_brown: u8 = 0x60; + pub const background_lightgray: u8 = 0x70; +}; + +pub const SimpleTextOutputMode = extern struct { + max_mode: u32, // specified as signed + mode: u32, // specified as signed + attribute: i32, + cursor_column: i32, + cursor_row: i32, + cursor_visible: bool, +}; diff --git a/lib/std/os/uefi/status.zig b/lib/std/os/uefi/status.zig new file mode 100644 index 0000000000..6deb741d0d --- /dev/null +++ b/lib/std/os/uefi/status.zig @@ -0,0 +1,46 @@ +const high_bit = 1 << @typeInfo(usize).Int.bits - 1; + +/// UEFI Specification, Version 2.8, Appendix D +pub const success: usize = 0; + +pub const load_error: usize = high_bit | 1; +pub const invalid_parameter: usize = high_bit | 2; +pub const unsupported: usize = high_bit | 3; +pub const bad_buffer_size: usize = high_bit | 4; +pub const buffer_too_small: usize = high_bit | 5; +pub const not_ready: usize = high_bit | 6; +pub const device_error: usize = high_bit | 7; +pub const write_protected: usize = high_bit | 8; +pub const out_of_resources: usize = high_bit | 9; +pub const volume_corrupted: usize = high_bit | 10; +pub const volume_full: usize = high_bit | 11; +pub const no_media: usize = high_bit | 12; +pub const media_changed: usize = high_bit | 13; +pub const not_found: usize = high_bit | 14; +pub const access_denied: usize = high_bit | 15; +pub const no_response: usize = high_bit | 16; +pub const no_mapping: usize = high_bit | 17; +pub const timeout: usize = high_bit | 18; +pub const not_started: usize = high_bit | 19; +pub const already_started: usize = high_bit | 20; +pub const aborted: usize = high_bit | 21; +pub const icmp_error: usize = high_bit | 22; +pub const tftp_error: usize = high_bit | 23; +pub const protocol_error: usize = high_bit | 24; +pub const incompatible_version: usize = high_bit | 25; +pub const security_violation: usize = high_bit | 26; +pub const crc_error: usize = high_bit | 27; +pub const end_of_media: usize = high_bit | 28; +pub const end_of_file: usize = high_bit | 31; +pub const invalid_language: usize = high_bit | 32; +pub const compromised_data: usize = high_bit | 33; +pub const ip_address_conflict: usize = high_bit | 34; +pub const http_error: usize = high_bit | 35; + +pub const warn_unknown_glyph: usize = 1; +pub const warn_delete_failure: usize = 2; +pub const warn_write_failure: usize = 3; +pub const warn_buffer_too_small: usize = 4; +pub const warn_stale_data: usize = 5; +pub const warn_file_system: usize = 6; +pub const warn_reset_required: usize = 7; diff --git a/lib/std/os/uefi/tables.zig b/lib/std/os/uefi/tables.zig new file mode 100644 index 0000000000..fbb9abe7f6 --- /dev/null +++ b/lib/std/os/uefi/tables.zig @@ -0,0 +1,9 @@ +pub const BootServices = @import("tables/boot_services.zig").BootServices; +pub const ConfigurationTable = @import("tables/configuration_table.zig").ConfigurationTable; +pub const global_variable align(8) = @import("tables/runtime_services.zig").global_variable; +pub const MemoryDescriptor = @import("tables/boot_services.zig").MemoryDescriptor; +pub const ResetType = @import("tables/runtime_services.zig").ResetType; +pub const RuntimeServices = @import("tables/runtime_services.zig").RuntimeServices; +pub const SystemTable = @import("tables/system_table.zig").SystemTable; +pub const TableHeader = @import("tables/table_header.zig").TableHeader; +pub const TimerDelay = @import("tables/boot_services.zig").TimerDelay; diff --git a/lib/std/os/uefi/tables/boot_services.zig b/lib/std/os/uefi/tables/boot_services.zig new file mode 100644 index 0000000000..55b0de3478 --- /dev/null +++ b/lib/std/os/uefi/tables/boot_services.zig @@ -0,0 +1,125 @@ +const uefi = @import("std").os.uefi; +const Event = uefi.Event; +const Guid = uefi.Guid; +const Handle = uefi.Handle; +const TableHeader = uefi.tables.TableHeader; + +/// UEFI Specification, Version 2.8, 4.4 +/// +/// As the boot_services table may grow with new UEFI versions, it is important to check hdr.header_size. +/// +/// Boot Services must not be used after exitBootServices has been called. The only exception is +/// getMemoryMap, which may be used after the first unsuccessful call to exitBootServices. +/// After successfully calling exitBootServices, system_table.console_in_handle, system_table.con_in, +/// system_table.console_out_handle, system_table.con_out, system_table.standard_error_handle, +/// system_table.std_err, and system_table.boot_services should be set to null. After setting these +/// attributes to null, system_table.hdr.crc32 must be recomputed. See UEFI Specification, Version 2.8, 7.4. +pub const BootServices = extern struct { + hdr: TableHeader, + raiseTpl: usize, // TODO + restoreTpl: usize, // TODO + allocatePages: usize, // TODO + freePages: usize, // TODO + getMemoryMap: extern fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) usize, + allocatePool: usize, // TODO + freePool: usize, // TODO + createEvent: extern fn (u32, usize, ?extern fn (Event, ?*const c_void) void, ?*const c_void, *Event) usize, + setTimer: extern fn (Event, TimerDelay, u64) usize, + waitForEvent: extern fn (usize, [*]const Event, *usize) usize, + signalEvent: extern fn (Event) usize, + closeEvent: extern fn (Event) usize, + checkEvent: usize, // TODO + installProtocolInterface: usize, // TODO + reinstallProtocolInterface: usize, // TODO + uninstallProtocolInterface: usize, // TODO + handleProtocol: usize, // TODO + reserved: *c_void, + registerProtocolNotify: usize, // TODO + locateHandle: usize, // TODO + locateDevicePath: usize, // TODO + installConfigurationTable: usize, // TODO + imageLoad: usize, // TODO + imageStart: usize, // TODO + exit: extern fn (Handle, usize, usize, ?*const c_void) usize, + imageUnload: usize, // TODO + exitBootServices: usize, // TODO + getNextMonotonicCount: usize, // TODO + stall: extern fn (usize) usize, + setWatchdogTimer: extern fn (usize, u64, usize, ?[*]const u16) usize, + connectController: usize, // TODO + disconnectController: usize, // TODO + openProtocol: usize, // TODO + closeProtocol: usize, // TODO + openProtocolInformation: usize, // TODO + protocolsPerHandle: usize, // TODO + locateHandleBuffer: usize, // TODO + locateProtocol: extern fn (*align(8) const Guid, ?*const c_void, *?*c_void) usize, + installMultipleProtocolInterfaces: usize, // TODO + uninstallMultipleProtocolInterfaces: usize, // TODO + calculateCrc32: usize, // TODO + copyMem: usize, // TODO + setMem: usize, // TODO + createEventEx: usize, // TODO + + pub const signature: u64 = 0x56524553544f4f42; + + pub const event_timer: u32 = 0x80000000; + pub const event_runtime: u32 = 0x40000000; + pub const event_notify_wait: u32 = 0x00000100; + pub const event_notify_signal: u32 = 0x00000200; + pub const event_signal_exit_boot_services: u32 = 0x00000201; + pub const event_signal_virtual_address_change: u32 = 0x00000202; + + pub const tpl_application: usize = 4; + pub const tpl_callback: usize = 8; + pub const tpl_notify: usize = 16; + pub const tpl_high_level: usize = 31; +}; + +pub const TimerDelay = extern enum(u32) { + TimerCancel, + TimerPeriodic, + TimerRelative, +}; + +pub const MemoryDescriptor = extern struct { + type: extern enum(u32) { + ReservedMemoryType, + LoaderCode, + LoaderData, + BootServicesCode, + BootServicesData, + RuntimeServicesCode, + RuntimeServicesData, + ConventionalMemory, + UnusableMemory, + ACPIReclaimMemory, + ACPIMemoryNVS, + MemoryMappedIO, + MemoryMappedIOPortSpace, + PalCode, + PersistentMemory, + MaxMemoryType, + }, + physical_start: u64, + virtual_start: u64, + number_of_pages: usize, + attribute: packed struct { + uc: bool, + wc: bool, + wt: bool, + wb: bool, + uce: bool, + _pad1: u7, + wp: bool, + rp: bool, + xp: bool, + nv: bool, + more_reliable: bool, + ro: bool, + sp: bool, + cpu_crypto: bool, + _pad2: u43, + memory_runtime: bool, + }, +}; diff --git a/lib/std/os/uefi/tables/configuration_table.zig b/lib/std/os/uefi/tables/configuration_table.zig new file mode 100644 index 0000000000..eb99e08477 --- /dev/null +++ b/lib/std/os/uefi/tables/configuration_table.zig @@ -0,0 +1,82 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; + +/// UEFI Specification, Version 2.8, 4.6 +/// Because GUIDs must be align(8), structs of this type also must be align(8) +pub const ConfigurationTable = extern struct { + vendor_guid: Guid, + vendor_table: *c_void, + + pub const acpi_20_table_guid align(8) = Guid{ + .time_low = 0x8868e871, + .time_mid = 0xe4f1, + .time_high_and_version = 0x11d3, + .clock_seq_high_and_reserved = 0xbc, + .clock_seq_low = 0x22, + .node = [_]u8{ 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81 }, + }; + pub const acpi_10_table_guid align(8) = Guid{ + .time_low = 0xeb9d2d30, + .time_mid = 0x2d88, + .time_high_and_version = 0x11d3, + .clock_seq_high_and_reserved = 0x9a, + .clock_seq_low = 0x16, + .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, + }; + pub const sal_system_table_guid align(8) = Guid{ + .time_low = 0xeb9d2d32, + .time_mid = 0x2d88, + .time_high_and_version = 0x113d, + .clock_seq_high_and_reserved = 0x9a, + .clock_seq_low = 0x16, + .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, + }; + pub const smbios_table_guid align(8) = Guid{ + .time_low = 0xeb9d2d31, + .time_mid = 0x2d88, + .time_high_and_version = 0x11d3, + .clock_seq_high_and_reserved = 0x9a, + .clock_seq_low = 0x16, + .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, + }; + pub const smbios3_table_guid align(8) = Guid{ + .time_low = 0xf2fd1544, + .time_mid = 0x9794, + .time_high_and_version = 0x4a2c, + .clock_seq_high_and_reserved = 0x99, + .clock_seq_low = 0x2e, + .node = [_]u8{ 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 }, + }; + pub const mps_table_guid align(8) = Guid{ + .time_low = 0xeb9d2d2f, + .time_mid = 0x2d88, + .time_high_and_version = 0x11d3, + .clock_seq_high_and_reserved = 0x9a, + .clock_seq_low = 0x16, + .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, + }; + pub const json_config_data_table_guid align(8) = Guid{ + .time_low = 0x87367f87, + .time_mid = 0x1119, + .time_high_and_version = 0x41ce, + .clock_seq_high_and_reserved = 0xaa, + .clock_seq_low = 0xec, + .node = [_]u8{ 0x8b, 0xe0, 0x11, 0x1f, 0x55, 0x8a }, + }; + pub const json_capsule_data_table_guid align(8) = Guid{ + .time_low = 0x35e7a725, + .time_mid = 0x8dd2, + .time_high_and_version = 0x4cac, + .clock_seq_high_and_reserved = 0x80, + .clock_seq_low = 0x11, + .node = [_]u8{ 0x33, 0xcd, 0xa8, 0x10, 0x90, 0x56 }, + }; + pub const json_capsule_result_table_guid align(8) = Guid{ + .time_low = 0xdbc461c3, + .time_mid = 0xb3de, + .time_high_and_version = 0x422a, + .clock_seq_high_and_reserved = 0xb9, + .clock_seq_low = 0xb4, + .node = [_]u8{ 0x98, 0x86, 0xfd, 0x49, 0xa1, 0xe5 }, + }; +}; diff --git a/lib/std/os/uefi/tables/runtime_services.zig b/lib/std/os/uefi/tables/runtime_services.zig new file mode 100644 index 0000000000..53cb17db50 --- /dev/null +++ b/lib/std/os/uefi/tables/runtime_services.zig @@ -0,0 +1,51 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; +const TableHeader = uefi.tables.TableHeader; +const Time = uefi.Time; +const TimeCapabilities = uefi.TimeCapabilities; + +/// UEFI Specification, Version 2.8, 4.5 +/// +/// As the runtime_services table may grow with new UEFI versions, it is important to check hdr.header_size. +/// +/// Some functions may not be supported. Check the RuntimeServicesSupported variable using getVariable. +/// getVariable is one of the functions that may not be supported. See UEFI Specification, Version 2.8, 8.1. +/// +/// Some functions may not be called while other functions are running. See UEFI Specification, Version 2.8, 8.1. +pub const RuntimeServices = extern struct { + hdr: TableHeader, + getTime: extern fn (*uefi.Time, ?*TimeCapabilities) usize, + setTime: usize, // TODO + getWakeupTime: usize, // TODO + setWakeupTime: usize, // TODO + setVirtualAddressMap: usize, // TODO + convertPointer: usize, // TODO + getVariable: extern fn ([*]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize, + getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize, + setVariable: extern fn ([*]const u16, *align(8) const Guid, u32, usize, *c_void) usize, + getNextHighMonotonicCount: usize, // TODO + resetSystem: extern fn (ResetType, usize, usize, ?*const c_void) noreturn, + updateCapsule: usize, // TODO + queryCapsuleCapabilities: usize, // TODO + queryVariableInfo: usize, // TODO + + pub const signature: u64 = 0x56524553544e5552; +}; + +/// UEFI Specification, Version 2.8, 8.5.1 +pub const ResetType = extern enum(u32) { + ResetCold, + ResetWarm, + ResetShutdown, + ResetPlatformSpecific, +}; + +/// UEFI Specification, Version 2.8, 3.3 +pub const global_variable align(8) = Guid{ + .time_low = 0x8be4df61, + .time_mid = 0x93ca, + .time_high_and_version = 0x11d2, + .clock_seq_high_and_reserved = 0xaa, + .clock_seq_low = 0x0d, + .node = [_]u8{ 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c }, +}; diff --git a/lib/std/os/uefi/tables/system_table.zig b/lib/std/os/uefi/tables/system_table.zig new file mode 100644 index 0000000000..23140f984e --- /dev/null +++ b/lib/std/os/uefi/tables/system_table.zig @@ -0,0 +1,46 @@ +const uefi = @import("std").os.uefi; +const BootServices = uefi.tables.BootServices; +const ConfigurationTable = uefi.tables.ConfigurationTable; +const Handle = uefi.Handle; +const RuntimeServices = uefi.tables.RuntimeServices; +const SimpleTextInputExProtocol = uefi.protocols.SimpleTextInputExProtocol; +const SimpleTextOutputProtocol = uefi.protocols.SimpleTextOutputProtocol; +const TableHeader = uefi.tables.TableHeader; + +/// UEFI Specification, Version 2.8, 4.3 +/// +/// As the system_table may grow with new UEFI versions, it is important to check hdr.header_size. +/// +/// After successfully calling boot_services.exitBootServices, console_in_handle, +/// con_in, console_out_handle, con_out, standard_error_handle, std_err, and +/// boot_services should be set to null. After setting these attributes to null, +/// hdr.crc32 must be recomputed. See UEFI Specification, Version 2.8, 7.4. +pub const SystemTable = extern struct { + hdr: TableHeader, + firmware_vendor: *u16, + firmware_revision: u32, + console_in_handle: ?Handle, + con_in: ?*SimpleTextInputExProtocol, + console_out_handle: ?Handle, + con_out: ?*SimpleTextOutputProtocol, + standard_error_handle: ?Handle, + std_err: ?*SimpleTextOutputProtocol, + runtime_services: *RuntimeServices, + boot_services: ?*BootServices, + number_of_table_entries: usize, + configuration_table: *ConfigurationTable, + + pub const signature: u64 = 0x5453595320494249; + pub const revision_1_02: u32 = (1 << 16) | 2; + pub const revision_1_10: u32 = (1 << 16) | 10; + pub const revision_2_00: u32 = (2 << 16); + pub const revision_2_10: u32 = (2 << 16) | 10; + pub const revision_2_20: u32 = (2 << 16) | 20; + pub const revision_2_30: u32 = (2 << 16) | 30; + pub const revision_2_31: u32 = (2 << 16) | 31; + pub const revision_2_40: u32 = (2 << 16) | 40; + pub const revision_2_50: u32 = (2 << 16) | 50; + pub const revision_2_60: u32 = (2 << 16) | 60; + pub const revision_2_70: u32 = (2 << 16) | 70; + pub const revision_2_80: u32 = (2 << 16) | 80; +}; diff --git a/lib/std/os/uefi/tables/table_header.zig b/lib/std/os/uefi/tables/table_header.zig new file mode 100644 index 0000000000..b955768e63 --- /dev/null +++ b/lib/std/os/uefi/tables/table_header.zig @@ -0,0 +1,8 @@ +/// UEFI Specification, Version 2.8, 4.2 +pub const TableHeader = extern struct { + signature: u64, + revision: u32, + header_size: u32, + crc32: u32, + reserved: u32, +}; diff --git a/lib/std/os/wasi.zig b/lib/std/os/wasi.zig new file mode 100644 index 0000000000..57b708395c --- /dev/null +++ b/lib/std/os/wasi.zig @@ -0,0 +1,80 @@ +// Based on https://github.com/CraneStation/wasi-sysroot/blob/wasi/libc-bottom-half/headers/public/wasi/core.h +// and https://github.com/WebAssembly/WASI/blob/master/design/WASI-core.md +const builtin = @import("builtin"); +const std = @import("std"); +const assert = std.debug.assert; + +pub const is_the_target = builtin.os == .wasi; +pub usingnamespace @import("bits.zig"); + +comptime { + 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 = iovec; +pub const ciovec_t = iovec_const; + +pub extern "wasi_unstable" fn args_get(argv: [*][*]u8, argv_buf: [*]u8) errno_t; +pub extern "wasi_unstable" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t; + +pub extern "wasi_unstable" fn clock_res_get(clock_id: clockid_t, resolution: *timestamp_t) errno_t; +pub extern "wasi_unstable" fn clock_time_get(clock_id: clockid_t, precision: timestamp_t, timestamp: *timestamp_t) errno_t; + +pub extern "wasi_unstable" fn environ_get(environ: [*]?[*]u8, environ_buf: [*]u8) errno_t; +pub extern "wasi_unstable" fn environ_sizes_get(environ_count: *usize, environ_buf_size: *usize) errno_t; + +pub extern "wasi_unstable" fn fd_advise(fd: fd_t, offset: filesize_t, len: filesize_t, advice: advice_t) errno_t; +pub extern "wasi_unstable" fn fd_allocate(fd: fd_t, offset: filesize_t, len: filesize_t) errno_t; +pub extern "wasi_unstable" fn fd_close(fd: fd_t) errno_t; +pub extern "wasi_unstable" fn fd_datasync(fd: fd_t) errno_t; +pub extern "wasi_unstable" fn fd_pread(fd: fd_t, iovs: [*]const iovec_t, iovs_len: usize, offset: filesize_t, nread: *usize) errno_t; +pub extern "wasi_unstable" fn fd_pwrite(fd: fd_t, iovs: [*]const ciovec_t, iovs_len: usize, offset: filesize_t, nwritten: *usize) errno_t; +pub extern "wasi_unstable" fn fd_read(fd: fd_t, iovs: [*]const iovec_t, iovs_len: usize, nread: *usize) errno_t; +pub extern "wasi_unstable" fn fd_readdir(fd: fd_t, buf: [*]u8, buf_len: usize, cookie: dircookie_t, bufused: *usize) errno_t; +pub extern "wasi_unstable" fn fd_renumber(from: fd_t, to: fd_t) errno_t; +pub extern "wasi_unstable" fn fd_seek(fd: fd_t, offset: filedelta_t, whence: whence_t, newoffset: *filesize_t) errno_t; +pub extern "wasi_unstable" fn fd_sync(fd: fd_t) errno_t; +pub extern "wasi_unstable" fn fd_tell(fd: fd_t, newoffset: *filesize_t) errno_t; +pub extern "wasi_unstable" fn fd_write(fd: fd_t, iovs: [*]const ciovec_t, iovs_len: usize, nwritten: *usize) errno_t; + +pub extern "wasi_unstable" fn fd_fdstat_get(fd: fd_t, buf: *fdstat_t) errno_t; +pub extern "wasi_unstable" fn fd_fdstat_set_flags(fd: fd_t, flags: fdflags_t) errno_t; +pub extern "wasi_unstable" fn fd_fdstat_set_rights(fd: fd_t, fs_rights_base: rights_t, fs_rights_inheriting: rights_t) errno_t; + +pub extern "wasi_unstable" fn fd_filestat_get(fd: fd_t, buf: *filestat_t) errno_t; +pub extern "wasi_unstable" fn fd_filestat_set_size(fd: fd_t, st_size: filesize_t) errno_t; +pub extern "wasi_unstable" fn fd_filestat_set_times(fd: fd_t, st_atim: timestamp_t, st_mtim: timestamp_t, fstflags: fstflags_t) errno_t; + +pub extern "wasi_unstable" fn fd_prestat_get(fd: fd_t, buf: *prestat_t) errno_t; +pub extern "wasi_unstable" fn fd_prestat_dir_name(fd: fd_t, path: [*]u8, path_len: usize) errno_t; + +pub extern "wasi_unstable" fn path_create_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t; +pub extern "wasi_unstable" fn path_filestat_get(fd: fd_t, flags: lookupflags_t, path: [*]const u8, path_len: usize, buf: *filestat_t) errno_t; +pub extern "wasi_unstable" 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_unstable" 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_unstable" 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_unstable" fn path_readlink(fd: fd_t, path: [*]const u8, path_len: usize, buf: [*]u8, buf_len: usize, bufused: *usize) errno_t; +pub extern "wasi_unstable" fn path_remove_directory(fd: fd_t, path: [*]const u8, path_len: usize) errno_t; +pub extern "wasi_unstable" 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_unstable" 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_unstable" fn path_unlink_file(fd: fd_t, path: [*]const u8, path_len: usize) errno_t; + +pub extern "wasi_unstable" fn poll_oneoff(in: *const subscription_t, out: *event_t, nsubscriptions: usize, nevents: *usize) errno_t; + +pub extern "wasi_unstable" fn proc_exit(rval: exitcode_t) noreturn; +pub extern "wasi_unstable" fn proc_raise(sig: signal_t) errno_t; + +pub extern "wasi_unstable" fn random_get(buf: [*]u8, buf_len: usize) errno_t; + +pub extern "wasi_unstable" fn sched_yield() errno_t; + +pub extern "wasi_unstable" fn sock_recv(sock: fd_t, ri_data: *const iovec_t, ri_data_len: usize, ri_flags: riflags_t, ro_datalen: *usize, ro_flags: *roflags_t) errno_t; +pub extern "wasi_unstable" 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_unstable" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t; diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig new file mode 100644 index 0000000000..7c1761a4b8 --- /dev/null +++ b/lib/std/os/windows.zig @@ -0,0 +1,886 @@ +// This file contains thin wrappers around Windows-specific APIs, with these +// specific goals in mind: +// * Convert "errno"-style error codes into Zig errors. +// * When null-terminated or UTF16LE byte buffers are required, provide APIs which accept +// slices as well as APIs which accept null-terminated UTF16LE byte buffers. + +const builtin = @import("builtin"); +const std = @import("../std.zig"); +const mem = std.mem; +const assert = std.debug.assert; +const math = std.math; +const maxInt = std.math.maxInt; + +pub const is_the_target = builtin.os == .windows; +pub const advapi32 = @import("windows/advapi32.zig"); +pub const kernel32 = @import("windows/kernel32.zig"); +pub const ntdll = @import("windows/ntdll.zig"); +pub const ole32 = @import("windows/ole32.zig"); +pub const shell32 = @import("windows/shell32.zig"); + +pub usingnamespace @import("windows/bits.zig"); + +/// `builtin` is missing `subsystem` when the subsystem is automatically detected, +/// so Zig standard library has the subsystem detection logic here. This should generally be +/// used rather than `builtin.subsystem`. +/// On non-windows targets, this is `null`. +pub const subsystem: ?builtin.SubSystem = blk: { + if (@hasDecl(builtin, "subsystem")) break :blk builtin.subsystem; + switch (builtin.os) { + .windows => { + if (builtin.is_test) { + break :blk builtin.SubSystem.Console; + } + const root = @import("root"); + if (@hasDecl(root, "WinMain") or + @hasDecl(root, "wWinMain") or + @hasDecl(root, "WinMainCRTStartup") or + @hasDecl(root, "wWinMainCRTStartup")) + { + break :blk builtin.SubSystem.Windows; + } else { + break :blk builtin.SubSystem.Console; + } + }, + .uefi => break :blk builtin.SubSystem.EfiApplication, + else => break :blk null, + } +}; + +pub const CreateFileError = error{ + SharingViolation, + PathAlreadyExists, + + /// When any of the path components can not be found or the file component can not + /// be found. Some operating systems distinguish between path components not found and + /// file components not found, but they are collapsed into FileNotFound to gain + /// consistency across operating systems. + FileNotFound, + + AccessDenied, + PipeBusy, + NameTooLong, + + /// On Windows, file paths must be valid Unicode. + InvalidUtf8, + + /// On Windows, file paths cannot contain these characters: + /// '/', '*', '?', '"', '<', '>', '|' + BadPathName, + + Unexpected, +}; + +pub fn CreateFile( + file_path: []const u8, + desired_access: DWORD, + share_mode: DWORD, + lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, + creation_disposition: DWORD, + flags_and_attrs: DWORD, + hTemplateFile: ?HANDLE, +) CreateFileError!HANDLE { + const file_path_w = try sliceToPrefixedFileW(file_path); + return CreateFileW(&file_path_w, desired_access, share_mode, lpSecurityAttributes, creation_disposition, flags_and_attrs, hTemplateFile); +} + +pub fn CreateFileW( + file_path_w: [*]const u16, + desired_access: DWORD, + share_mode: DWORD, + lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, + creation_disposition: DWORD, + flags_and_attrs: DWORD, + hTemplateFile: ?HANDLE, +) CreateFileError!HANDLE { + const result = kernel32.CreateFileW(file_path_w, desired_access, share_mode, lpSecurityAttributes, creation_disposition, flags_and_attrs, hTemplateFile); + + if (result == INVALID_HANDLE_VALUE) { + switch (kernel32.GetLastError()) { + ERROR.SHARING_VIOLATION => return error.SharingViolation, + ERROR.ALREADY_EXISTS => return error.PathAlreadyExists, + ERROR.FILE_EXISTS => return error.PathAlreadyExists, + ERROR.FILE_NOT_FOUND => return error.FileNotFound, + ERROR.PATH_NOT_FOUND => return error.FileNotFound, + ERROR.ACCESS_DENIED => return error.AccessDenied, + ERROR.PIPE_BUSY => return error.PipeBusy, + ERROR.FILENAME_EXCED_RANGE => return error.NameTooLong, + else => |err| return unexpectedError(err), + } + } + + return result; +} + +pub const CreatePipeError = error{Unexpected}; + +pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) CreatePipeError!void { + if (kernel32.CreatePipe(rd, wr, sattr, 0) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} + +pub const SetHandleInformationError = error{Unexpected}; + +pub fn SetHandleInformation(h: HANDLE, mask: DWORD, flags: DWORD) SetHandleInformationError!void { + if (kernel32.SetHandleInformation(h, mask, flags) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} + +pub const RtlGenRandomError = error{Unexpected}; + +/// Call RtlGenRandom() instead of CryptGetRandom() on Windows +/// https://github.com/rust-lang-nursery/rand/issues/111 +/// https://bugzilla.mozilla.org/show_bug.cgi?id=504270 +pub fn RtlGenRandom(output: []u8) RtlGenRandomError!void { + var total_read: usize = 0; + var buff: []u8 = output[0..]; + const max_read_size: ULONG = maxInt(ULONG); + + while (total_read < output.len) { + const to_read: ULONG = math.min(buff.len, max_read_size); + + if (advapi32.RtlGenRandom(buff.ptr, to_read) == 0) { + return unexpectedError(kernel32.GetLastError()); + } + + total_read += to_read; + buff = buff[to_read..]; + } +} + +pub const WaitForSingleObjectError = error{ + WaitAbandoned, + WaitTimeOut, + Unexpected, +}; + +pub fn WaitForSingleObject(handle: HANDLE, milliseconds: DWORD) WaitForSingleObjectError!void { + switch (kernel32.WaitForSingleObject(handle, milliseconds)) { + WAIT_ABANDONED => return error.WaitAbandoned, + WAIT_OBJECT_0 => return, + WAIT_TIMEOUT => return error.WaitTimeOut, + WAIT_FAILED => switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + }, + else => return error.Unexpected, + } +} + +pub const FindFirstFileError = error{ + FileNotFound, + InvalidUtf8, + BadPathName, + NameTooLong, + Unexpected, +}; + +pub fn FindFirstFile(dir_path: []const u8, find_file_data: *WIN32_FIND_DATAW) FindFirstFileError!HANDLE { + const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, [_]u16{ '\\', '*', 0 }); + const handle = kernel32.FindFirstFileW(&dir_path_w, find_file_data); + + if (handle == INVALID_HANDLE_VALUE) { + switch (kernel32.GetLastError()) { + ERROR.FILE_NOT_FOUND => return error.FileNotFound, + ERROR.PATH_NOT_FOUND => return error.FileNotFound, + else => |err| return unexpectedError(err), + } + } + + return handle; +} + +pub const FindNextFileError = error{Unexpected}; + +/// Returns `true` if there was another file, `false` otherwise. +pub fn FindNextFile(handle: HANDLE, find_file_data: *WIN32_FIND_DATAW) FindNextFileError!bool { + if (kernel32.FindNextFileW(handle, find_file_data) == 0) { + switch (kernel32.GetLastError()) { + ERROR.NO_MORE_FILES => return false, + else => |err| return unexpectedError(err), + } + } + return true; +} + +pub const CreateIoCompletionPortError = error{Unexpected}; + +pub fn CreateIoCompletionPort( + file_handle: HANDLE, + existing_completion_port: ?HANDLE, + completion_key: usize, + concurrent_thread_count: DWORD, +) CreateIoCompletionPortError!HANDLE { + const handle = kernel32.CreateIoCompletionPort(file_handle, existing_completion_port, completion_key, concurrent_thread_count) orelse { + switch (kernel32.GetLastError()) { + ERROR.INVALID_PARAMETER => unreachable, + else => |err| return unexpectedError(err), + } + }; + return handle; +} + +pub const PostQueuedCompletionStatusError = error{Unexpected}; + +pub fn PostQueuedCompletionStatus( + completion_port: HANDLE, + bytes_transferred_count: DWORD, + completion_key: usize, + lpOverlapped: ?*OVERLAPPED, +) PostQueuedCompletionStatusError!void { + if (kernel32.PostQueuedCompletionStatus(completion_port, bytes_transferred_count, completion_key, lpOverlapped) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} + +pub const GetQueuedCompletionStatusResult = enum { + Normal, + Aborted, + Cancelled, + EOF, +}; + +pub fn GetQueuedCompletionStatus( + completion_port: HANDLE, + bytes_transferred_count: *DWORD, + lpCompletionKey: *usize, + lpOverlapped: *?*OVERLAPPED, + dwMilliseconds: DWORD, +) GetQueuedCompletionStatusResult { + if (kernel32.GetQueuedCompletionStatus( + completion_port, + bytes_transferred_count, + lpCompletionKey, + lpOverlapped, + dwMilliseconds, + ) == FALSE) { + switch (kernel32.GetLastError()) { + ERROR.ABANDONED_WAIT_0 => return GetQueuedCompletionStatusResult.Aborted, + ERROR.OPERATION_ABORTED => return GetQueuedCompletionStatusResult.Cancelled, + ERROR.HANDLE_EOF => return GetQueuedCompletionStatusResult.EOF, + else => |err| { + if (std.debug.runtime_safety) { + std.debug.panic("unexpected error: {}\n", err); + } + }, + } + } + return GetQueuedCompletionStatusResult.Normal; +} + +pub fn CloseHandle(hObject: HANDLE) void { + assert(kernel32.CloseHandle(hObject) != 0); +} + +pub fn FindClose(hFindFile: HANDLE) void { + assert(kernel32.FindClose(hFindFile) != 0); +} + +pub const ReadFileError = error{Unexpected}; + +pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize { + var index: usize = 0; + while (index < buffer.len) { + const want_read_count = @intCast(DWORD, math.min(DWORD(maxInt(DWORD)), buffer.len - index)); + var amt_read: DWORD = undefined; + if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, null) == 0) { + switch (kernel32.GetLastError()) { + ERROR.OPERATION_ABORTED => continue, + ERROR.BROKEN_PIPE => return index, + else => |err| return unexpectedError(err), + } + } + if (amt_read == 0) return index; + index += amt_read; + } + return index; +} + +pub const WriteFileError = error{ + SystemResources, + OperationAborted, + BrokenPipe, + Unexpected, +}; + +/// This function is for blocking file descriptors only. For non-blocking, see +/// `WriteFileAsync`. +pub fn WriteFile(handle: HANDLE, bytes: []const u8) WriteFileError!void { + var bytes_written: DWORD = undefined; + // TODO replace this @intCast with a loop that writes all the bytes + if (kernel32.WriteFile(handle, bytes.ptr, @intCast(u32, bytes.len), &bytes_written, null) == 0) { + switch (kernel32.GetLastError()) { + ERROR.INVALID_USER_BUFFER => return error.SystemResources, + ERROR.NOT_ENOUGH_MEMORY => return error.SystemResources, + ERROR.OPERATION_ABORTED => return error.OperationAborted, + ERROR.NOT_ENOUGH_QUOTA => return error.SystemResources, + ERROR.IO_PENDING => unreachable, // this function is for blocking files only + ERROR.BROKEN_PIPE => return error.BrokenPipe, + else => |err| return unexpectedError(err), + } + } +} + +pub const GetCurrentDirectoryError = error{ + NameTooLong, + Unexpected, +}; + +/// The result is a slice of `buffer`, indexed from 0. +pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 { + var utf16le_buf: [PATH_MAX_WIDE]u16 = undefined; + const result = kernel32.GetCurrentDirectoryW(utf16le_buf.len, &utf16le_buf); + if (result == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } + assert(result <= utf16le_buf.len); + const utf16le_slice = utf16le_buf[0..result]; + // Trust that Windows gives us valid UTF-16LE. + var end_index: usize = 0; + var it = std.unicode.Utf16LeIterator.init(utf16le_slice); + while (it.nextCodepoint() catch unreachable) |codepoint| { + const seq_len = std.unicode.utf8CodepointSequenceLength(codepoint) catch unreachable; + if (end_index + seq_len >= buffer.len) + return error.NameTooLong; + end_index += std.unicode.utf8Encode(codepoint, buffer[end_index..]) catch unreachable; + } + return buffer[0..end_index]; +} + +pub const CreateSymbolicLinkError = error{Unexpected}; + +pub fn CreateSymbolicLink( + sym_link_path: []const u8, + target_path: []const u8, + flags: DWORD, +) CreateSymbolicLinkError!void { + const sym_link_path_w = try sliceToPrefixedFileW(sym_link_path); + const target_path_w = try sliceToPrefixedFileW(target_path); + return CreateSymbolicLinkW(&sym_link_path_w, &target_path_w, flags); +} + +pub fn CreateSymbolicLinkW( + sym_link_path: [*]const u16, + target_path: [*]const u16, + flags: DWORD, +) CreateSymbolicLinkError!void { + if (kernel32.CreateSymbolicLinkW(sym_link_path, target_path, flags) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} + +pub const DeleteFileError = error{ + FileNotFound, + AccessDenied, + NameTooLong, + FileBusy, + Unexpected, +}; + +pub fn DeleteFile(filename: []const u8) DeleteFileError!void { + const filename_w = try sliceToPrefixedFileW(filename); + return DeleteFileW(&filename_w); +} + +pub fn DeleteFileW(filename: [*]const u16) DeleteFileError!void { + if (kernel32.DeleteFileW(filename) == 0) { + switch (kernel32.GetLastError()) { + ERROR.FILE_NOT_FOUND => return error.FileNotFound, + ERROR.PATH_NOT_FOUND => return error.FileNotFound, + ERROR.ACCESS_DENIED => return error.AccessDenied, + ERROR.FILENAME_EXCED_RANGE => return error.NameTooLong, + ERROR.INVALID_PARAMETER => return error.NameTooLong, + ERROR.SHARING_VIOLATION => return error.FileBusy, + else => |err| return unexpectedError(err), + } + } +} + +pub const MoveFileError = error{Unexpected}; + +pub fn MoveFileEx(old_path: []const u8, new_path: []const u8, flags: DWORD) MoveFileError!void { + const old_path_w = try sliceToPrefixedFileW(old_path); + const new_path_w = try sliceToPrefixedFileW(new_path); + return MoveFileExW(&old_path_w, &new_path_w, flags); +} + +pub fn MoveFileExW(old_path: [*]const u16, new_path: [*]const u16, flags: DWORD) MoveFileError!void { + if (kernel32.MoveFileExW(old_path, new_path, flags) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} + +pub const CreateDirectoryError = error{ + PathAlreadyExists, + FileNotFound, + Unexpected, +}; + +pub fn CreateDirectory(pathname: []const u8, attrs: ?*SECURITY_ATTRIBUTES) CreateDirectoryError!void { + const pathname_w = try sliceToPrefixedFileW(pathname); + return CreateDirectoryW(&pathname_w, attrs); +} + +pub fn CreateDirectoryW(pathname: [*]const u16, attrs: ?*SECURITY_ATTRIBUTES) CreateDirectoryError!void { + if (kernel32.CreateDirectoryW(pathname, attrs) == 0) { + switch (kernel32.GetLastError()) { + ERROR.ALREADY_EXISTS => return error.PathAlreadyExists, + ERROR.PATH_NOT_FOUND => return error.FileNotFound, + else => |err| return unexpectedError(err), + } + } +} + +pub const RemoveDirectoryError = error{ + FileNotFound, + DirNotEmpty, + Unexpected, +}; + +pub fn RemoveDirectory(dir_path: []const u8) RemoveDirectoryError!void { + const dir_path_w = try sliceToPrefixedFileW(dir_path); + return RemoveDirectoryW(&dir_path_w); +} + +pub fn RemoveDirectoryW(dir_path_w: [*]const u16) RemoveDirectoryError!void { + if (kernel32.RemoveDirectoryW(dir_path_w) == 0) { + switch (kernel32.GetLastError()) { + ERROR.PATH_NOT_FOUND => return error.FileNotFound, + ERROR.DIR_NOT_EMPTY => return error.DirNotEmpty, + else => |err| return unexpectedError(err), + } + } +} + +pub const GetStdHandleError = error{ + NoStandardHandleAttached, + Unexpected, +}; + +pub fn GetStdHandle(handle_id: DWORD) GetStdHandleError!HANDLE { + const handle = kernel32.GetStdHandle(handle_id) orelse return error.NoStandardHandleAttached; + if (handle == INVALID_HANDLE_VALUE) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } + return handle; +} + +pub const SetFilePointerError = error{Unexpected}; + +/// The SetFilePointerEx function with the `dwMoveMethod` parameter set to `FILE_BEGIN`. +pub fn SetFilePointerEx_BEGIN(handle: HANDLE, offset: u64) SetFilePointerError!void { + // "The starting point is zero or the beginning of the file. If [FILE_BEGIN] + // is specified, then the liDistanceToMove parameter is interpreted as an unsigned value." + // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setfilepointerex + const ipos = @bitCast(LARGE_INTEGER, offset); + if (kernel32.SetFilePointerEx(handle, ipos, null, FILE_BEGIN) == 0) { + switch (kernel32.GetLastError()) { + ERROR.INVALID_PARAMETER => unreachable, + ERROR.INVALID_HANDLE => unreachable, + else => |err| return unexpectedError(err), + } + } +} + +/// The SetFilePointerEx function with the `dwMoveMethod` parameter set to `FILE_CURRENT`. +pub fn SetFilePointerEx_CURRENT(handle: HANDLE, offset: i64) SetFilePointerError!void { + if (kernel32.SetFilePointerEx(handle, offset, null, FILE_CURRENT) == 0) { + switch (kernel32.GetLastError()) { + ERROR.INVALID_PARAMETER => unreachable, + ERROR.INVALID_HANDLE => unreachable, + else => |err| return unexpectedError(err), + } + } +} + +/// The SetFilePointerEx function with the `dwMoveMethod` parameter set to `FILE_END`. +pub fn SetFilePointerEx_END(handle: HANDLE, offset: i64) SetFilePointerError!void { + if (kernel32.SetFilePointerEx(handle, offset, null, FILE_END) == 0) { + switch (kernel32.GetLastError()) { + ERROR.INVALID_PARAMETER => unreachable, + ERROR.INVALID_HANDLE => unreachable, + else => |err| return unexpectedError(err), + } + } +} + +/// The SetFilePointerEx function with parameters to get the current offset. +pub fn SetFilePointerEx_CURRENT_get(handle: HANDLE) SetFilePointerError!u64 { + var result: LARGE_INTEGER = undefined; + if (kernel32.SetFilePointerEx(handle, 0, &result, FILE_CURRENT) == 0) { + switch (kernel32.GetLastError()) { + ERROR.INVALID_PARAMETER => unreachable, + ERROR.INVALID_HANDLE => unreachable, + else => |err| return unexpectedError(err), + } + } + // Based on the docs for FILE_BEGIN, it seems that the returned signed integer + // should be interpreted as an unsigned integer. + return @bitCast(u64, result); +} + +pub const GetFinalPathNameByHandleError = error{ + FileNotFound, + SystemResources, + NameTooLong, + Unexpected, +}; + +pub fn GetFinalPathNameByHandleW( + hFile: HANDLE, + buf_ptr: [*]u16, + buf_len: DWORD, + flags: DWORD, +) GetFinalPathNameByHandleError!DWORD { + const rc = kernel32.GetFinalPathNameByHandleW(hFile, buf_ptr, buf_len, flags); + if (rc == 0) { + switch (kernel32.GetLastError()) { + ERROR.FILE_NOT_FOUND => return error.FileNotFound, + ERROR.PATH_NOT_FOUND => return error.FileNotFound, + ERROR.NOT_ENOUGH_MEMORY => return error.SystemResources, + ERROR.FILENAME_EXCED_RANGE => return error.NameTooLong, + ERROR.INVALID_PARAMETER => unreachable, + else => |err| return unexpectedError(err), + } + } + return rc; +} + +pub const GetFileSizeError = error{Unexpected}; + +pub fn GetFileSizeEx(hFile: HANDLE) GetFileSizeError!u64 { + var file_size: LARGE_INTEGER = undefined; + if (kernel32.GetFileSizeEx(hFile, &file_size) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } + return @bitCast(u64, file_size); +} + +pub const GetFileAttributesError = error{ + FileNotFound, + PermissionDenied, + Unexpected, +}; + +pub fn GetFileAttributes(filename: []const u8) GetFileAttributesError!DWORD { + const filename_w = try sliceToPrefixedFileW(filename); + return GetFileAttributesW(&filename_w); +} + +pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD { + const rc = kernel32.GetFileAttributesW(lpFileName); + if (rc == INVALID_FILE_ATTRIBUTES) { + switch (kernel32.GetLastError()) { + ERROR.FILE_NOT_FOUND => return error.FileNotFound, + ERROR.PATH_NOT_FOUND => return error.FileNotFound, + ERROR.ACCESS_DENIED => return error.PermissionDenied, + else => |err| return unexpectedError(err), + } + } + return rc; +} + +const GetModuleFileNameError = error{Unexpected}; + +pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![]u16 { + const rc = kernel32.GetModuleFileNameW(hModule, buf_ptr, buf_len); + if (rc == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } + return buf_ptr[0..rc]; +} + +pub const TerminateProcessError = error{Unexpected}; + +pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) TerminateProcessError!void { + if (kernel32.TerminateProcess(hProcess, uExitCode) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} + +pub const VirtualAllocError = error{Unexpected}; + +pub fn VirtualAlloc(addr: ?LPVOID, size: usize, alloc_type: DWORD, flProtect: DWORD) VirtualAllocError!LPVOID { + return kernel32.VirtualAlloc(addr, size, alloc_type, flProtect) orelse { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + }; +} + +pub fn VirtualFree(lpAddress: ?LPVOID, dwSize: usize, dwFreeType: DWORD) void { + assert(kernel32.VirtualFree(lpAddress, dwSize, dwFreeType) != 0); +} + +pub const SetConsoleTextAttributeError = error{Unexpected}; + +pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetConsoleTextAttributeError!void { + if (kernel32.SetConsoleTextAttribute(hConsoleOutput, wAttributes) == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} + +pub const GetEnvironmentStringsError = error{OutOfMemory}; + +pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*]u16 { + return kernel32.GetEnvironmentStringsW() orelse return error.OutOfMemory; +} + +pub fn FreeEnvironmentStringsW(penv: [*]u16) void { + assert(kernel32.FreeEnvironmentStringsW(penv) != 0); +} + +pub const GetEnvironmentVariableError = error{ + EnvironmentVariableNotFound, + Unexpected, +}; + +pub fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) GetEnvironmentVariableError!DWORD { + const rc = kernel32.GetEnvironmentVariableW(lpName, lpBuffer, nSize); + if (rc == 0) { + switch (kernel32.GetLastError()) { + ERROR.ENVVAR_NOT_FOUND => return error.EnvironmentVariableNotFound, + else => |err| return unexpectedError(err), + } + } + return rc; +} + +pub const CreateProcessError = error{ + FileNotFound, + AccessDenied, + InvalidName, + Unexpected, +}; + +pub fn CreateProcessW( + lpApplicationName: ?LPWSTR, + lpCommandLine: LPWSTR, + lpProcessAttributes: ?*SECURITY_ATTRIBUTES, + lpThreadAttributes: ?*SECURITY_ATTRIBUTES, + bInheritHandles: BOOL, + dwCreationFlags: DWORD, + lpEnvironment: ?*c_void, + lpCurrentDirectory: ?LPWSTR, + lpStartupInfo: *STARTUPINFOW, + lpProcessInformation: *PROCESS_INFORMATION, +) CreateProcessError!void { + if (kernel32.CreateProcessW( + lpApplicationName, + lpCommandLine, + lpProcessAttributes, + lpThreadAttributes, + bInheritHandles, + dwCreationFlags, + lpEnvironment, + lpCurrentDirectory, + lpStartupInfo, + lpProcessInformation, + ) == 0) { + switch (kernel32.GetLastError()) { + ERROR.FILE_NOT_FOUND => return error.FileNotFound, + ERROR.PATH_NOT_FOUND => return error.FileNotFound, + ERROR.ACCESS_DENIED => return error.AccessDenied, + ERROR.INVALID_PARAMETER => unreachable, + ERROR.INVALID_NAME => return error.InvalidName, + else => |err| return unexpectedError(err), + } + } +} + +pub const LoadLibraryError = error{ + FileNotFound, + Unexpected, +}; + +pub fn LoadLibraryW(lpLibFileName: [*]const u16) LoadLibraryError!HMODULE { + return kernel32.LoadLibraryW(lpLibFileName) orelse { + switch (kernel32.GetLastError()) { + ERROR.FILE_NOT_FOUND => return error.FileNotFound, + ERROR.PATH_NOT_FOUND => return error.FileNotFound, + ERROR.MOD_NOT_FOUND => return error.FileNotFound, + else => |err| return unexpectedError(err), + } + }; +} + +pub fn FreeLibrary(hModule: HMODULE) void { + assert(kernel32.FreeLibrary(hModule) != 0); +} + +pub fn QueryPerformanceFrequency() u64 { + // "On systems that run Windows XP or later, the function will always succeed" + // https://docs.microsoft.com/en-us/windows/desktop/api/profileapi/nf-profileapi-queryperformancefrequency + var result: LARGE_INTEGER = undefined; + assert(kernel32.QueryPerformanceFrequency(&result) != 0); + // The kernel treats this integer as unsigned. + return @bitCast(u64, result); +} + +pub fn QueryPerformanceCounter() u64 { + // "On systems that run Windows XP or later, the function will always succeed" + // https://docs.microsoft.com/en-us/windows/desktop/api/profileapi/nf-profileapi-queryperformancecounter + var result: LARGE_INTEGER = undefined; + assert(kernel32.QueryPerformanceCounter(&result) != 0); + // The kernel treats this integer as unsigned. + return @bitCast(u64, result); +} + +pub fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*c_void, Context: ?*c_void) void { + assert(kernel32.InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context) != 0); +} + +pub fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void) void { + assert(kernel32.HeapFree(hHeap, dwFlags, lpMem) != 0); +} + +pub fn HeapDestroy(hHeap: HANDLE) void { + assert(kernel32.HeapDestroy(hHeap) != 0); +} + +pub const GetFileInformationByHandleError = error{Unexpected}; + +pub fn GetFileInformationByHandle( + hFile: HANDLE, +) GetFileInformationByHandleError!BY_HANDLE_FILE_INFORMATION { + var info: BY_HANDLE_FILE_INFORMATION = undefined; + const rc = ntdll.GetFileInformationByHandle(hFile, &info); + if (rc == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } + return info; +} + +pub const SetFileTimeError = error{Unexpected}; + +pub fn SetFileTime( + hFile: HANDLE, + lpCreationTime: ?*const FILETIME, + lpLastAccessTime: ?*const FILETIME, + lpLastWriteTime: ?*const FILETIME, +) SetFileTimeError!void { + const rc = kernel32.SetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime); + if (rc == 0) { + switch (kernel32.GetLastError()) { + else => |err| return unexpectedError(err), + } + } +} + +/// A file time is a 64-bit value that represents the number of 100-nanosecond +/// intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated +/// Universal Time (UTC). +/// This function returns the number of nanoseconds since the canonical epoch, +/// which is the POSIX one (Jan 01, 1970 AD). +pub fn fromSysTime(hns: i64) i64 { + const adjusted_epoch = hns + std.time.epoch.windows * (std.time.ns_per_s / 100); + return adjusted_epoch * 100; +} + +pub fn toSysTime(ns: i64) i64 { + const hns = @divFloor(ns, 100); + return hns - std.time.epoch.windows * (std.time.ns_per_s / 100); +} + +pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 { + const hns = @bitCast(i64, (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime); + return fromSysTime(hns); +} + +/// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME. +pub fn nanoSecondsToFileTime(ns: i64) FILETIME { + const adjusted = @bitCast(u64, toSysTime(ns)); + return FILETIME{ + .dwHighDateTime = @truncate(u32, adjusted >> 32), + .dwLowDateTime = @truncate(u32, adjusted), + }; +} + +pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 { + return sliceToPrefixedFileW(mem.toSliceConst(u8, s)); +} + +pub fn sliceToPrefixedFileW(s: []const u8) ![PATH_MAX_WIDE + 1]u16 { + return sliceToPrefixedSuffixedFileW(s, [_]u16{0}); +} + +pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) ![PATH_MAX_WIDE + suffix.len]u16 { + // TODO https://github.com/ziglang/zig/issues/2765 + var result: [PATH_MAX_WIDE + suffix.len]u16 = undefined; + // > File I/O functions in the Windows API convert "/" to "\" as part of + // > converting the name to an NT-style name, except when using the "\\?\" + // > prefix as detailed in the following sections. + // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation + // Because we want the larger maximum path length for absolute paths, we + // disallow forward slashes in zig std lib file functions on Windows. + for (s) |byte| { + switch (byte) { + '/', '*', '?', '"', '<', '>', '|' => return error.BadPathName, + else => {}, + } + } + const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: { + const prefix = [_]u16{ '\\', '\\', '?', '\\' }; + mem.copy(u16, result[0..], prefix); + break :blk prefix.len; + }; + const end_index = start_index + try std.unicode.utf8ToUtf16Le(result[start_index..], s); + assert(end_index <= result.len); + if (end_index + suffix.len > result.len) return error.NameTooLong; + mem.copy(u16, result[end_index..], suffix); + return result; +} + +inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID { + return (s << 10) | p; +} + +/// Call this when you made a windows DLL call or something that does SetLastError +/// and you get an unexpected error. +pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { + if (std.os.unexpected_error_tracing) { + // 614 is the length of the longest windows error desciption + var buf_u16: [614]u16 = undefined; + var buf_u8: [614]u8 = undefined; + var len = kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null); + _ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable; + std.debug.warn("error.Unexpected: GetLastError({}): {}\n", err, buf_u8[0..len]); + std.debug.dumpCurrentStackTrace(null); + } + return error.Unexpected; +} + +/// Call this when you made a windows NtDll call +/// and you get an unexpected status. +pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { + if (std.os.unexpected_error_tracing) { + std.debug.warn("error.Unexpected NTSTATUS={}\n", status); + std.debug.dumpCurrentStackTrace(null); + } + return error.Unexpected; +} diff --git a/lib/std/os/windows/advapi32.zig b/lib/std/os/windows/advapi32.zig new file mode 100644 index 0000000000..940f10994c --- /dev/null +++ b/lib/std/os/windows/advapi32.zig @@ -0,0 +1,23 @@ +usingnamespace @import("bits.zig"); + +pub extern "advapi32" stdcallcc fn RegOpenKeyExW( + hKey: HKEY, + lpSubKey: LPCWSTR, + ulOptions: DWORD, + samDesired: REGSAM, + phkResult: *HKEY, +) LSTATUS; + +pub extern "advapi32" stdcallcc fn RegQueryValueExW( + hKey: HKEY, + lpValueName: LPCWSTR, + lpReserved: LPDWORD, + lpType: LPDWORD, + lpData: LPBYTE, + lpcbData: LPDWORD, +) LSTATUS; + +// RtlGenRandom is known as SystemFunction036 under advapi32 +// http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx */ +pub extern "advapi32" stdcallcc fn SystemFunction036(output: [*]u8, length: ULONG) BOOL; +pub const RtlGenRandom = SystemFunction036; diff --git a/lib/std/os/windows/bits.zig b/lib/std/os/windows/bits.zig new file mode 100644 index 0000000000..ddfdd27e1b --- /dev/null +++ b/lib/std/os/windows/bits.zig @@ -0,0 +1,734 @@ +// Platform-dependent types and values that are used along with OS-specific APIs. + +const builtin = @import("builtin"); +const std = @import("../../std.zig"); +const assert = std.debug.assert; +const maxInt = std.math.maxInt; + +pub const ERROR = @import("error.zig"); +pub const STATUS = @import("status.zig"); +pub const LANG = @import("lang.zig"); +pub const SUBLANG = @import("sublang.zig"); + +/// The standard input device. Initially, this is the console input buffer, CONIN$. +pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1; + +/// The standard output device. Initially, this is the active console screen buffer, CONOUT$. +pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1; + +/// The standard error device. Initially, this is the active console screen buffer, CONOUT$. +pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1; + +pub const SHORT = c_short; +pub const BOOL = c_int; +pub const BOOLEAN = BYTE; +pub const BYTE = u8; +pub const CHAR = u8; +pub const DWORD = u32; +pub const FLOAT = f32; +pub const HANDLE = *c_void; +pub const HCRYPTPROV = ULONG_PTR; +pub const HINSTANCE = *@OpaqueType(); +pub const HMODULE = *@OpaqueType(); +pub const FARPROC = *@OpaqueType(); +pub const INT = c_int; +pub const LPBYTE = *BYTE; +pub const LPCH = *CHAR; +pub const LPCSTR = [*]const CHAR; +pub const LPCTSTR = [*]const TCHAR; +pub const LPCVOID = *const c_void; +pub const LPDWORD = *DWORD; +pub const LPSTR = [*]CHAR; +pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR; +pub const LPVOID = *c_void; +pub const LPWSTR = [*]WCHAR; +pub const LPCWSTR = [*]const WCHAR; +pub const PVOID = *c_void; +pub const PWSTR = [*]WCHAR; +pub const SIZE_T = usize; +pub const TCHAR = if (UNICODE) WCHAR else u8; +pub const UINT = c_uint; +pub const ULONG_PTR = usize; +pub const DWORD_PTR = ULONG_PTR; +pub const UNICODE = false; +pub const WCHAR = u16; +pub const WORD = u16; +pub const LARGE_INTEGER = i64; +pub const ULONG = u32; +pub const LONG = i32; +pub const ULONGLONG = u64; +pub const LONGLONG = i64; +pub const HLOCAL = HANDLE; +pub const LANGID = c_ushort; +pub const NTSTATUS = ULONG; + +pub const va_list = *@OpaqueType(); + +pub const TRUE = 1; +pub const FALSE = 0; + +pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); + +pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD)); + +pub const FILE_ALL_INFORMATION = extern struct { + BasicInformation: FILE_BASIC_INFORMATION, + StandardInformation: FILE_STANDARD_INFORMATION, + InternalInformation: FILE_INTERNAL_INFORMATION, + EaInformation: FILE_EA_INFORMATION, + AccessInformation: FILE_ACCESS_INFORMATION, + PositionInformation: FILE_POSITION_INFORMATION, + ModeInformation: FILE_MODE_INFORMATION, + AlignmentInformation: FILE_ALIGNMENT_INFORMATION, + NameInformation: FILE_NAME_INFORMATION, +}; + +pub const FILE_BASIC_INFORMATION = extern struct { + CreationTime: LARGE_INTEGER, + LastAccessTime: LARGE_INTEGER, + LastWriteTime: LARGE_INTEGER, + ChangeTime: LARGE_INTEGER, + FileAttributes: ULONG, +}; + +pub const FILE_STANDARD_INFORMATION = extern struct { + AllocationSize: LARGE_INTEGER, + EndOfFile: LARGE_INTEGER, + NumberOfLinks: ULONG, + DeletePending: BOOLEAN, + Directory: BOOLEAN, +}; + +pub const FILE_INTERNAL_INFORMATION = extern struct { + IndexNumber: LARGE_INTEGER, +}; + +pub const FILE_EA_INFORMATION = extern struct { + EaSize: ULONG, +}; + +pub const FILE_ACCESS_INFORMATION = extern struct { + AccessFlags: ACCESS_MASK, +}; + +pub const FILE_POSITION_INFORMATION = extern struct { + CurrentByteOffset: LARGE_INTEGER, +}; + +pub const FILE_MODE_INFORMATION = extern struct { + Mode: ULONG, +}; + +pub const FILE_ALIGNMENT_INFORMATION = extern struct { + AlignmentRequirement: ULONG, +}; + +pub const FILE_NAME_INFORMATION = extern struct { + FileNameLength: ULONG, + FileName: [1]WCHAR, +}; + +pub const IO_STATUS_BLOCK = extern struct { + Status: usize, + Information: ULONG_PTR, +}; + +pub const FILE_INFORMATION_CLASS = extern enum { + FileDirectoryInformation = 1, + FileFullDirectoryInformation, + FileBothDirectoryInformation, + FileBasicInformation, + FileStandardInformation, + FileInternalInformation, + FileEaInformation, + FileAccessInformation, + FileNameInformation, + FileRenameInformation, + FileLinkInformation, + FileNamesInformation, + FileDispositionInformation, + FilePositionInformation, + FileFullEaInformation, + FileModeInformation, + FileAlignmentInformation, + FileAllInformation, + FileAllocationInformation, + FileEndOfFileInformation, + FileAlternateNameInformation, + FileStreamInformation, + FilePipeInformation, + FilePipeLocalInformation, + FilePipeRemoteInformation, + FileMailslotQueryInformation, + FileMailslotSetInformation, + FileCompressionInformation, + FileObjectIdInformation, + FileCompletionInformation, + FileMoveClusterInformation, + FileQuotaInformation, + FileReparsePointInformation, + FileNetworkOpenInformation, + FileAttributeTagInformation, + FileTrackingInformation, + FileIdBothDirectoryInformation, + FileIdFullDirectoryInformation, + FileValidDataLengthInformation, + FileShortNameInformation, + FileIoCompletionNotificationInformation, + FileIoStatusBlockRangeInformation, + FileIoPriorityHintInformation, + FileSfioReserveInformation, + FileSfioVolumeInformation, + FileHardLinkInformation, + FileProcessIdsUsingFileInformation, + FileNormalizedNameInformation, + FileNetworkPhysicalNameInformation, + FileIdGlobalTxDirectoryInformation, + FileIsRemoteDeviceInformation, + FileUnusedInformation, + FileNumaNodeInformation, + FileStandardLinkInformation, + FileRemoteProtocolInformation, + FileRenameInformationBypassAccessCheck, + FileLinkInformationBypassAccessCheck, + FileVolumeNameInformation, + FileIdInformation, + FileIdExtdDirectoryInformation, + FileReplaceCompletionInformation, + FileHardLinkFullIdInformation, + FileIdExtdBothDirectoryInformation, + FileDispositionInformationEx, + FileRenameInformationEx, + FileRenameInformationExBypassAccessCheck, + FileDesiredStorageClassInformation, + FileStatInformation, + FileMemoryPartitionInformation, + FileStatLxInformation, + FileCaseSensitiveInformation, + FileLinkInformationEx, + FileLinkInformationExBypassAccessCheck, + FileStorageReserveIdInformation, + FileCaseSensitiveInformationForceAccessCheck, + FileMaximumInformation, +}; + +pub const OVERLAPPED = extern struct { + Internal: ULONG_PTR, + InternalHigh: ULONG_PTR, + Offset: DWORD, + OffsetHigh: DWORD, + hEvent: ?HANDLE, +}; +pub const LPOVERLAPPED = *OVERLAPPED; + +pub const MAX_PATH = 260; + +// TODO issue #305 +pub const FILE_INFO_BY_HANDLE_CLASS = u32; +pub const FileBasicInfo = 0; +pub const FileStandardInfo = 1; +pub const FileNameInfo = 2; +pub const FileRenameInfo = 3; +pub const FileDispositionInfo = 4; +pub const FileAllocationInfo = 5; +pub const FileEndOfFileInfo = 6; +pub const FileStreamInfo = 7; +pub const FileCompressionInfo = 8; +pub const FileAttributeTagInfo = 9; +pub const FileIdBothDirectoryInfo = 10; +pub const FileIdBothDirectoryRestartInfo = 11; +pub const FileIoPriorityHintInfo = 12; +pub const FileRemoteProtocolInfo = 13; +pub const FileFullDirectoryInfo = 14; +pub const FileFullDirectoryRestartInfo = 15; +pub const FileStorageInfo = 16; +pub const FileAlignmentInfo = 17; +pub const FileIdInfo = 18; +pub const FileIdExtdDirectoryInfo = 19; +pub const FileIdExtdDirectoryRestartInfo = 20; + +pub const BY_HANDLE_FILE_INFORMATION = extern struct { + dwFileAttributes: DWORD, + ftCreationTime: FILETIME, + ftLastAccessTime: FILETIME, + ftLastWriteTime: FILETIME, + dwVolumeSerialNumber: DWORD, + nFileSizeHigh: DWORD, + nFileSizeLow: DWORD, + nNumberOfLinks: DWORD, + nFileIndexHigh: DWORD, + nFileIndexLow: DWORD, +}; + +pub const FILE_NAME_INFO = extern struct { + FileNameLength: DWORD, + FileName: [1]WCHAR, +}; + +/// Return the normalized drive name. This is the default. +pub const FILE_NAME_NORMALIZED = 0x0; + +/// Return the opened file name (not normalized). +pub const FILE_NAME_OPENED = 0x8; + +/// Return the path with the drive letter. This is the default. +pub const VOLUME_NAME_DOS = 0x0; + +/// Return the path with a volume GUID path instead of the drive name. +pub const VOLUME_NAME_GUID = 0x1; + +/// Return the path with no drive information. +pub const VOLUME_NAME_NONE = 0x4; + +/// Return the path with the volume device path. +pub const VOLUME_NAME_NT = 0x2; + +pub const SECURITY_ATTRIBUTES = extern struct { + nLength: DWORD, + lpSecurityDescriptor: ?*c_void, + bInheritHandle: BOOL, +}; +pub const PSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES; +pub const LPSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES; + +pub const GENERIC_READ = 0x80000000; +pub const GENERIC_WRITE = 0x40000000; +pub const GENERIC_EXECUTE = 0x20000000; +pub const GENERIC_ALL = 0x10000000; + +pub const FILE_SHARE_DELETE = 0x00000004; +pub const FILE_SHARE_READ = 0x00000001; +pub const FILE_SHARE_WRITE = 0x00000002; + +pub const CREATE_ALWAYS = 2; +pub const CREATE_NEW = 1; +pub const OPEN_ALWAYS = 4; +pub const OPEN_EXISTING = 3; +pub const TRUNCATE_EXISTING = 5; + +pub const FILE_ATTRIBUTE_ARCHIVE = 0x20; +pub const FILE_ATTRIBUTE_COMPRESSED = 0x800; +pub const FILE_ATTRIBUTE_DEVICE = 0x40; +pub const FILE_ATTRIBUTE_DIRECTORY = 0x10; +pub const FILE_ATTRIBUTE_ENCRYPTED = 0x4000; +pub const FILE_ATTRIBUTE_HIDDEN = 0x2; +pub const FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x8000; +pub const FILE_ATTRIBUTE_NORMAL = 0x80; +pub const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000; +pub const FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x20000; +pub const FILE_ATTRIBUTE_OFFLINE = 0x1000; +pub const FILE_ATTRIBUTE_READONLY = 0x1; +pub const FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x400000; +pub const FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x40000; +pub const FILE_ATTRIBUTE_REPARSE_POINT = 0x400; +pub const FILE_ATTRIBUTE_SPARSE_FILE = 0x200; +pub const FILE_ATTRIBUTE_SYSTEM = 0x4; +pub const FILE_ATTRIBUTE_TEMPORARY = 0x100; +pub const FILE_ATTRIBUTE_VIRTUAL = 0x10000; + +pub const PROCESS_INFORMATION = extern struct { + hProcess: HANDLE, + hThread: HANDLE, + dwProcessId: DWORD, + dwThreadId: DWORD, +}; + +pub const STARTUPINFOW = extern struct { + cb: DWORD, + lpReserved: ?LPWSTR, + lpDesktop: ?LPWSTR, + lpTitle: ?LPWSTR, + dwX: DWORD, + dwY: DWORD, + dwXSize: DWORD, + dwYSize: DWORD, + dwXCountChars: DWORD, + dwYCountChars: DWORD, + dwFillAttribute: DWORD, + dwFlags: DWORD, + wShowWindow: WORD, + cbReserved2: WORD, + lpReserved2: ?LPBYTE, + hStdInput: ?HANDLE, + hStdOutput: ?HANDLE, + hStdError: ?HANDLE, +}; + +pub const STARTF_FORCEONFEEDBACK = 0x00000040; +pub const STARTF_FORCEOFFFEEDBACK = 0x00000080; +pub const STARTF_PREVENTPINNING = 0x00002000; +pub const STARTF_RUNFULLSCREEN = 0x00000020; +pub const STARTF_TITLEISAPPID = 0x00001000; +pub const STARTF_TITLEISLINKNAME = 0x00000800; +pub const STARTF_UNTRUSTEDSOURCE = 0x00008000; +pub const STARTF_USECOUNTCHARS = 0x00000008; +pub const STARTF_USEFILLATTRIBUTE = 0x00000010; +pub const STARTF_USEHOTKEY = 0x00000200; +pub const STARTF_USEPOSITION = 0x00000004; +pub const STARTF_USESHOWWINDOW = 0x00000001; +pub const STARTF_USESIZE = 0x00000002; +pub const STARTF_USESTDHANDLES = 0x00000100; + +pub const INFINITE = 4294967295; + +pub const WAIT_ABANDONED = 0x00000080; +pub const WAIT_OBJECT_0 = 0x00000000; +pub const WAIT_TIMEOUT = 0x00000102; +pub const WAIT_FAILED = 0xFFFFFFFF; + +pub const HANDLE_FLAG_INHERIT = 0x00000001; +pub const HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002; + +pub const MOVEFILE_COPY_ALLOWED = 2; +pub const MOVEFILE_CREATE_HARDLINK = 16; +pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4; +pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32; +pub const MOVEFILE_REPLACE_EXISTING = 1; +pub const MOVEFILE_WRITE_THROUGH = 8; + +pub const FILE_BEGIN = 0; +pub const FILE_CURRENT = 1; +pub const FILE_END = 2; + +pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000; +pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004; +pub const HEAP_NO_SERIALIZE = 0x00000001; + +// AllocationType values +pub const MEM_COMMIT = 0x1000; +pub const MEM_RESERVE = 0x2000; +pub const MEM_RESET = 0x80000; +pub const MEM_RESET_UNDO = 0x1000000; +pub const MEM_LARGE_PAGES = 0x20000000; +pub const MEM_PHYSICAL = 0x400000; +pub const MEM_TOP_DOWN = 0x100000; +pub const MEM_WRITE_WATCH = 0x200000; + +// Protect values +pub const PAGE_EXECUTE = 0x10; +pub const PAGE_EXECUTE_READ = 0x20; +pub const PAGE_EXECUTE_READWRITE = 0x40; +pub const PAGE_EXECUTE_WRITECOPY = 0x80; +pub const PAGE_NOACCESS = 0x01; +pub const PAGE_READONLY = 0x02; +pub const PAGE_READWRITE = 0x04; +pub const PAGE_WRITECOPY = 0x08; +pub const PAGE_TARGETS_INVALID = 0x40000000; +pub const PAGE_TARGETS_NO_UPDATE = 0x40000000; // Same as PAGE_TARGETS_INVALID +pub const PAGE_GUARD = 0x100; +pub const PAGE_NOCACHE = 0x200; +pub const PAGE_WRITECOMBINE = 0x400; + +// FreeType values +pub const MEM_COALESCE_PLACEHOLDERS = 0x1; +pub const MEM_RESERVE_PLACEHOLDERS = 0x2; +pub const MEM_DECOMMIT = 0x4000; +pub const MEM_RELEASE = 0x8000; + +pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD; +pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE; + +pub const WIN32_FIND_DATAW = extern struct { + dwFileAttributes: DWORD, + ftCreationTime: FILETIME, + ftLastAccessTime: FILETIME, + ftLastWriteTime: FILETIME, + nFileSizeHigh: DWORD, + nFileSizeLow: DWORD, + dwReserved0: DWORD, + dwReserved1: DWORD, + cFileName: [260]u16, + cAlternateFileName: [14]u16, +}; + +pub const FILETIME = extern struct { + dwLowDateTime: DWORD, + dwHighDateTime: DWORD, +}; + +pub const SYSTEM_INFO = extern struct { + anon1: extern union { + dwOemId: DWORD, + anon2: extern struct { + wProcessorArchitecture: WORD, + wReserved: WORD, + }, + }, + dwPageSize: DWORD, + lpMinimumApplicationAddress: LPVOID, + lpMaximumApplicationAddress: LPVOID, + dwActiveProcessorMask: DWORD_PTR, + dwNumberOfProcessors: DWORD, + dwProcessorType: DWORD, + dwAllocationGranularity: DWORD, + wProcessorLevel: WORD, + wProcessorRevision: WORD, +}; + +pub const HRESULT = c_long; + +pub const KNOWNFOLDERID = GUID; +pub const GUID = extern struct { + Data1: c_ulong, + Data2: c_ushort, + Data3: c_ushort, + Data4: [8]u8, + + pub fn parse(str: []const u8) GUID { + var guid: GUID = undefined; + var index: usize = 0; + assert(str[index] == '{'); + index += 1; + + guid.Data1 = std.fmt.parseUnsigned(c_ulong, str[index .. index + 8], 16) catch unreachable; + index += 8; + + assert(str[index] == '-'); + index += 1; + + guid.Data2 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable; + index += 4; + + assert(str[index] == '-'); + index += 1; + + guid.Data3 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable; + index += 4; + + assert(str[index] == '-'); + index += 1; + + guid.Data4[0] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable; + index += 2; + guid.Data4[1] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable; + index += 2; + + assert(str[index] == '-'); + index += 1; + + var i: usize = 2; + while (i < guid.Data4.len) : (i += 1) { + guid.Data4[i] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable; + index += 2; + } + + assert(str[index] == '}'); + index += 1; + return guid; + } +}; + +pub const FOLDERID_LocalAppData = GUID.parse("{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}"); + +pub const KF_FLAG_DEFAULT = 0; +pub const KF_FLAG_NO_APPCONTAINER_REDIRECTION = 65536; +pub const KF_FLAG_CREATE = 32768; +pub const KF_FLAG_DONT_VERIFY = 16384; +pub const KF_FLAG_DONT_UNEXPAND = 8192; +pub const KF_FLAG_NO_ALIAS = 4096; +pub const KF_FLAG_INIT = 2048; +pub const KF_FLAG_DEFAULT_PATH = 1024; +pub const KF_FLAG_NOT_PARENT_RELATIVE = 512; +pub const KF_FLAG_SIMPLE_IDLIST = 256; +pub const KF_FLAG_ALIAS_ONLY = -2147483648; + +pub const S_OK = 0; +pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001)); +pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002)); +pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003)); +pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004)); +pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005)); +pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF)); +pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005)); +pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006)); +pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E)); +pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057)); + +pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; +pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000; +pub const FILE_FLAG_NO_BUFFERING = 0x20000000; +pub const FILE_FLAG_OPEN_NO_RECALL = 0x00100000; +pub const FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000; +pub const FILE_FLAG_OVERLAPPED = 0x40000000; +pub const FILE_FLAG_POSIX_SEMANTICS = 0x0100000; +pub const FILE_FLAG_RANDOM_ACCESS = 0x10000000; +pub const FILE_FLAG_SESSION_AWARE = 0x00800000; +pub const FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000; +pub const FILE_FLAG_WRITE_THROUGH = 0x80000000; + +pub const SMALL_RECT = extern struct { + Left: SHORT, + Top: SHORT, + Right: SHORT, + Bottom: SHORT, +}; + +pub const COORD = extern struct { + X: SHORT, + Y: SHORT, +}; + +pub const CREATE_UNICODE_ENVIRONMENT = 1024; + +pub const TLS_OUT_OF_INDEXES = 4294967295; +pub const IMAGE_TLS_DIRECTORY = extern struct { + StartAddressOfRawData: usize, + EndAddressOfRawData: usize, + AddressOfIndex: usize, + AddressOfCallBacks: usize, + SizeOfZeroFill: u32, + Characteristics: u32, +}; +pub const IMAGE_TLS_DIRECTORY64 = IMAGE_TLS_DIRECTORY; +pub const IMAGE_TLS_DIRECTORY32 = IMAGE_TLS_DIRECTORY; + +pub const PIMAGE_TLS_CALLBACK = ?extern fn (PVOID, DWORD, PVOID) void; + +pub const PROV_RSA_FULL = 1; + +pub const REGSAM = ACCESS_MASK; +pub const ACCESS_MASK = DWORD; +pub const PHKEY = *HKEY; +pub const HKEY = *HKEY__; +pub const HKEY__ = extern struct { + unused: c_int, +}; +pub const LSTATUS = LONG; + +pub const FILE_NOTIFY_INFORMATION = extern struct { + NextEntryOffset: DWORD, + Action: DWORD, + FileNameLength: DWORD, + FileName: [1]WCHAR, +}; + +pub const FILE_ACTION_ADDED = 0x00000001; +pub const FILE_ACTION_REMOVED = 0x00000002; +pub const FILE_ACTION_MODIFIED = 0x00000003; +pub const FILE_ACTION_RENAMED_OLD_NAME = 0x00000004; +pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005; + +pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void; + +pub const FILE_LIST_DIRECTORY = 1; + +pub const FILE_NOTIFY_CHANGE_CREATION = 64; +pub const FILE_NOTIFY_CHANGE_SIZE = 8; +pub const FILE_NOTIFY_CHANGE_SECURITY = 256; +pub const FILE_NOTIFY_CHANGE_LAST_ACCESS = 32; +pub const FILE_NOTIFY_CHANGE_LAST_WRITE = 16; +pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2; +pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1; +pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4; + +pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct { + dwSize: COORD, + dwCursorPosition: COORD, + wAttributes: WORD, + srWindow: SMALL_RECT, + dwMaximumWindowSize: COORD, +}; + +pub const FOREGROUND_BLUE = 1; +pub const FOREGROUND_GREEN = 2; +pub const FOREGROUND_RED = 4; +pub const FOREGROUND_INTENSITY = 8; + +pub const LIST_ENTRY = extern struct { + Flink: *LIST_ENTRY, + Blink: *LIST_ENTRY, +}; + +pub const RTL_CRITICAL_SECTION_DEBUG = extern struct { + Type: WORD, + CreatorBackTraceIndex: WORD, + CriticalSection: *RTL_CRITICAL_SECTION, + ProcessLocksList: LIST_ENTRY, + EntryCount: DWORD, + ContentionCount: DWORD, + Flags: DWORD, + CreatorBackTraceIndexHigh: WORD, + SpareWORD: WORD, +}; + +pub const RTL_CRITICAL_SECTION = extern struct { + DebugInfo: *RTL_CRITICAL_SECTION_DEBUG, + LockCount: LONG, + RecursionCount: LONG, + OwningThread: HANDLE, + LockSemaphore: HANDLE, + SpinCount: ULONG_PTR, +}; + +pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION; +pub const INIT_ONCE = RTL_RUN_ONCE; +pub const INIT_ONCE_STATIC_INIT = RTL_RUN_ONCE_INIT; +pub const INIT_ONCE_FN = extern fn (InitOnce: *INIT_ONCE, Parameter: ?*c_void, Context: ?*c_void) BOOL; + +pub const RTL_RUN_ONCE = extern struct { + Ptr: ?*c_void, +}; + +pub const RTL_RUN_ONCE_INIT = RTL_RUN_ONCE{ .Ptr = null }; + +pub const COINIT_APARTMENTTHREADED = COINIT.COINIT_APARTMENTTHREADED; +pub const COINIT_MULTITHREADED = COINIT.COINIT_MULTITHREADED; +pub const COINIT_DISABLE_OLE1DDE = COINIT.COINIT_DISABLE_OLE1DDE; +pub const COINIT_SPEED_OVER_MEMORY = COINIT.COINIT_SPEED_OVER_MEMORY; +pub const COINIT = extern enum { + COINIT_APARTMENTTHREADED = 2, + COINIT_MULTITHREADED = 0, + COINIT_DISABLE_OLE1DDE = 4, + COINIT_SPEED_OVER_MEMORY = 8, +}; + +/// > The maximum path of 32,767 characters is approximate, because the "\\?\" +/// > prefix may be expanded to a longer string by the system at run time, and +/// > this expansion applies to the total length. +/// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation +pub const PATH_MAX_WIDE = 32767; + +pub const FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100; +pub const FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000; +pub const FORMAT_MESSAGE_FROM_HMODULE = 0x00000800; +pub const FORMAT_MESSAGE_FROM_STRING = 0x00000400; +pub const FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000; +pub const FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200; +pub const FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF; + +pub const EXCEPTION_DATATYPE_MISALIGNMENT = 0x80000002; +pub const EXCEPTION_ACCESS_VIOLATION = 0xc0000005; +pub const EXCEPTION_ILLEGAL_INSTRUCTION = 0xc000001d; +pub const EXCEPTION_STACK_OVERFLOW = 0xc00000fd; +pub const EXCEPTION_CONTINUE_SEARCH = 0; + +pub const EXCEPTION_RECORD = extern struct { + ExceptionCode: u32, + ExceptionFlags: u32, + ExceptionRecord: *EXCEPTION_RECORD, + ExceptionAddress: *c_void, + NumberParameters: u32, + ExceptionInformation: [15]usize, +}; + +pub const EXCEPTION_POINTERS = extern struct { + ExceptionRecord: *EXCEPTION_RECORD, + ContextRecord: *c_void, +}; + +pub const VECTORED_EXCEPTION_HANDLER = stdcallcc fn (ExceptionInfo: *EXCEPTION_POINTERS) c_long; + +pub const OBJECT_ATTRIBUTES = extern struct { + Length: ULONG, + RootDirectory: HANDLE, + ObjectName: *UNICODE_STRING, + Attributes: ULONG, + SecurityDescriptor: ?*c_void, + SecurityQualityOfService: ?*c_void, +}; + +pub const UNICODE_STRING = extern struct { + Length: USHORT, + MaximumLength: USHORT, + Buffer: [*]WCHAR, +}; diff --git a/lib/std/os/windows/error.zig b/lib/std/os/windows/error.zig new file mode 100644 index 0000000000..f90945d00e --- /dev/null +++ b/lib/std/os/windows/error.zig @@ -0,0 +1,3567 @@ +/// The operation completed successfully. +pub const SUCCESS = 0; + +/// Incorrect function. +pub const INVALID_FUNCTION = 1; + +/// The system cannot find the file specified. +pub const FILE_NOT_FOUND = 2; + +/// The system cannot find the path specified. +pub const PATH_NOT_FOUND = 3; + +/// The system cannot open the file. +pub const TOO_MANY_OPEN_FILES = 4; + +/// Access is denied. +pub const ACCESS_DENIED = 5; + +/// The handle is invalid. +pub const INVALID_HANDLE = 6; + +/// The storage control blocks were destroyed. +pub const ARENA_TRASHED = 7; + +/// Not enough storage is available to process this command. +pub const NOT_ENOUGH_MEMORY = 8; + +/// The storage control block address is invalid. +pub const INVALID_BLOCK = 9; + +/// The environment is incorrect. +pub const BAD_ENVIRONMENT = 10; + +/// An attempt was made to load a program with an incorrect format. +pub const BAD_FORMAT = 11; + +/// The access code is invalid. +pub const INVALID_ACCESS = 12; + +/// The data is invalid. +pub const INVALID_DATA = 13; + +/// Not enough storage is available to complete this operation. +pub const OUTOFMEMORY = 14; + +/// The system cannot find the drive specified. +pub const INVALID_DRIVE = 15; + +/// The directory cannot be removed. +pub const CURRENT_DIRECTORY = 16; + +/// The system cannot move the file to a different disk drive. +pub const NOT_SAME_DEVICE = 17; + +/// There are no more files. +pub const NO_MORE_FILES = 18; + +/// The media is write protected. +pub const WRITE_PROTECT = 19; + +/// The system cannot find the device specified. +pub const BAD_UNIT = 20; + +/// The device is not ready. +pub const NOT_READY = 21; + +/// The device does not recognize the command. +pub const BAD_COMMAND = 22; + +/// Data error (cyclic redundancy check). +pub const CRC = 23; + +/// The program issued a command but the command length is incorrect. +pub const BAD_LENGTH = 24; + +/// The drive cannot locate a specific area or track on the disk. +pub const SEEK = 25; + +/// The specified disk or diskette cannot be accessed. +pub const NOT_DOS_DISK = 26; + +/// The drive cannot find the sector requested. +pub const SECTOR_NOT_FOUND = 27; + +/// The printer is out of paper. +pub const OUT_OF_PAPER = 28; + +/// The system cannot write to the specified device. +pub const WRITE_FAULT = 29; + +/// The system cannot read from the specified device. +pub const READ_FAULT = 30; + +/// A device attached to the system is not functioning. +pub const GEN_FAILURE = 31; + +/// The process cannot access the file because it is being used by another process. +pub const SHARING_VIOLATION = 32; + +/// The process cannot access the file because another process has locked a portion of the file. +pub const LOCK_VIOLATION = 33; + +/// The wrong diskette is in the drive. Insert %2 (Volume Serial Number: %3) into drive %1. +pub const WRONG_DISK = 34; + +/// Too many files opened for sharing. +pub const SHARING_BUFFER_EXCEEDED = 36; + +/// Reached the end of the file. +pub const HANDLE_EOF = 38; + +/// The disk is full. +pub const HANDLE_DISK_FULL = 39; + +/// The request is not supported. +pub const NOT_SUPPORTED = 50; + +/// Windows cannot find the network path. Verify that the network path is correct and the destination computer is not busy or turned off. If Windows still cannot find the network path, contact your network administrator. +pub const REM_NOT_LIST = 51; + +/// You were not connected because a duplicate name exists on the network. If joining a domain, go to System in Control Panel to change the computer name and try again. If joining a workgroup, choose another workgroup name. +pub const DUP_NAME = 52; + +/// The network path was not found. +pub const BAD_NETPATH = 53; + +/// The network is busy. +pub const NETWORK_BUSY = 54; + +/// The specified network resource or device is no longer available. +pub const DEV_NOT_EXIST = 55; + +/// The network BIOS command limit has been reached. +pub const TOO_MANY_CMDS = 56; + +/// A network adapter hardware error occurred. +pub const ADAP_HDW_ERR = 57; + +/// The specified server cannot perform the requested operation. +pub const BAD_NET_RESP = 58; + +/// An unexpected network error occurred. +pub const UNEXP_NET_ERR = 59; + +/// The remote adapter is not compatible. +pub const BAD_REM_ADAP = 60; + +/// The printer queue is full. +pub const PRINTQ_FULL = 61; + +/// Space to store the file waiting to be printed is not available on the server. +pub const NO_SPOOL_SPACE = 62; + +/// Your file waiting to be printed was deleted. +pub const PRINT_CANCELLED = 63; + +/// The specified network name is no longer available. +pub const NETNAME_DELETED = 64; + +/// Network access is denied. +pub const NETWORK_ACCESS_DENIED = 65; + +/// The network resource type is not correct. +pub const BAD_DEV_TYPE = 66; + +/// The network name cannot be found. +pub const BAD_NET_NAME = 67; + +/// The name limit for the local computer network adapter card was exceeded. +pub const TOO_MANY_NAMES = 68; + +/// The network BIOS session limit was exceeded. +pub const TOO_MANY_SESS = 69; + +/// The remote server has been paused or is in the process of being started. +pub const SHARING_PAUSED = 70; + +/// No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept. +pub const REQ_NOT_ACCEP = 71; + +/// The specified printer or disk device has been paused. +pub const REDIR_PAUSED = 72; + +/// The file exists. +pub const FILE_EXISTS = 80; + +/// The directory or file cannot be created. +pub const CANNOT_MAKE = 82; + +/// Fail on INT 24. +pub const FAIL_I24 = 83; + +/// Storage to process this request is not available. +pub const OUT_OF_STRUCTURES = 84; + +/// The local device name is already in use. +pub const ALREADY_ASSIGNED = 85; + +/// The specified network password is not correct. +pub const INVALID_PASSWORD = 86; + +/// The parameter is incorrect. +pub const INVALID_PARAMETER = 87; + +/// A write fault occurred on the network. +pub const NET_WRITE_FAULT = 88; + +/// The system cannot start another process at this time. +pub const NO_PROC_SLOTS = 89; + +/// Cannot create another system semaphore. +pub const TOO_MANY_SEMAPHORES = 100; + +/// The exclusive semaphore is owned by another process. +pub const EXCL_SEM_ALREADY_OWNED = 101; + +/// The semaphore is set and cannot be closed. +pub const SEM_IS_SET = 102; + +/// The semaphore cannot be set again. +pub const TOO_MANY_SEM_REQUESTS = 103; + +/// Cannot request exclusive semaphores at interrupt time. +pub const INVALID_AT_INTERRUPT_TIME = 104; + +/// The previous ownership of this semaphore has ended. +pub const SEM_OWNER_DIED = 105; + +/// Insert the diskette for drive %1. +pub const SEM_USER_LIMIT = 106; + +/// The program stopped because an alternate diskette was not inserted. +pub const DISK_CHANGE = 107; + +/// The disk is in use or locked by another process. +pub const DRIVE_LOCKED = 108; + +/// The pipe has been ended. +pub const BROKEN_PIPE = 109; + +/// The system cannot open the device or file specified. +pub const OPEN_FAILED = 110; + +/// The file name is too long. +pub const BUFFER_OVERFLOW = 111; + +/// There is not enough space on the disk. +pub const DISK_FULL = 112; + +/// No more internal file identifiers available. +pub const NO_MORE_SEARCH_HANDLES = 113; + +/// The target internal file identifier is incorrect. +pub const INVALID_TARGET_HANDLE = 114; + +/// The IOCTL call made by the application program is not correct. +pub const INVALID_CATEGORY = 117; + +/// The verify-on-write switch parameter value is not correct. +pub const INVALID_VERIFY_SWITCH = 118; + +/// The system does not support the command requested. +pub const BAD_DRIVER_LEVEL = 119; + +/// This function is not supported on this system. +pub const CALL_NOT_IMPLEMENTED = 120; + +/// The semaphore timeout period has expired. +pub const SEM_TIMEOUT = 121; + +/// The data area passed to a system call is too small. +pub const INSUFFICIENT_BUFFER = 122; + +/// The filename, directory name, or volume label syntax is incorrect. +pub const INVALID_NAME = 123; + +/// The system call level is not correct. +pub const INVALID_LEVEL = 124; + +/// The disk has no volume label. +pub const NO_VOLUME_LABEL = 125; + +/// The specified module could not be found. +pub const MOD_NOT_FOUND = 126; + +/// The specified procedure could not be found. +pub const PROC_NOT_FOUND = 127; + +/// There are no child processes to wait for. +pub const WAIT_NO_CHILDREN = 128; + +/// The %1 application cannot be run in Win32 mode. +pub const CHILD_NOT_COMPLETE = 129; + +/// Attempt to use a file handle to an open disk partition for an operation other than raw disk I/O. +pub const DIRECT_ACCESS_HANDLE = 130; + +/// An attempt was made to move the file pointer before the beginning of the file. +pub const NEGATIVE_SEEK = 131; + +/// The file pointer cannot be set on the specified device or file. +pub const SEEK_ON_DEVICE = 132; + +/// A JOIN or SUBST command cannot be used for a drive that contains previously joined drives. +pub const IS_JOIN_TARGET = 133; + +/// An attempt was made to use a JOIN or SUBST command on a drive that has already been joined. +pub const IS_JOINED = 134; + +/// An attempt was made to use a JOIN or SUBST command on a drive that has already been substituted. +pub const IS_SUBSTED = 135; + +/// The system tried to delete the JOIN of a drive that is not joined. +pub const NOT_JOINED = 136; + +/// The system tried to delete the substitution of a drive that is not substituted. +pub const NOT_SUBSTED = 137; + +/// The system tried to join a drive to a directory on a joined drive. +pub const JOIN_TO_JOIN = 138; + +/// The system tried to substitute a drive to a directory on a substituted drive. +pub const SUBST_TO_SUBST = 139; + +/// The system tried to join a drive to a directory on a substituted drive. +pub const JOIN_TO_SUBST = 140; + +/// The system tried to SUBST a drive to a directory on a joined drive. +pub const SUBST_TO_JOIN = 141; + +/// The system cannot perform a JOIN or SUBST at this time. +pub const BUSY_DRIVE = 142; + +/// The system cannot join or substitute a drive to or for a directory on the same drive. +pub const SAME_DRIVE = 143; + +/// The directory is not a subdirectory of the root directory. +pub const DIR_NOT_ROOT = 144; + +/// The directory is not empty. +pub const DIR_NOT_EMPTY = 145; + +/// The path specified is being used in a substitute. +pub const IS_SUBST_PATH = 146; + +/// Not enough resources are available to process this command. +pub const IS_JOIN_PATH = 147; + +/// The path specified cannot be used at this time. +pub const PATH_BUSY = 148; + +/// An attempt was made to join or substitute a drive for which a directory on the drive is the target of a previous substitute. +pub const IS_SUBST_TARGET = 149; + +/// System trace information was not specified in your CONFIG.SYS file, or tracing is disallowed. +pub const SYSTEM_TRACE = 150; + +/// The number of specified semaphore events for DosMuxSemWait is not correct. +pub const INVALID_EVENT_COUNT = 151; + +/// DosMuxSemWait did not execute; too many semaphores are already set. +pub const TOO_MANY_MUXWAITERS = 152; + +/// The DosMuxSemWait list is not correct. +pub const INVALID_LIST_FORMAT = 153; + +/// The volume label you entered exceeds the label character limit of the target file system. +pub const LABEL_TOO_LONG = 154; + +/// Cannot create another thread. +pub const TOO_MANY_TCBS = 155; + +/// The recipient process has refused the signal. +pub const SIGNAL_REFUSED = 156; + +/// The segment is already discarded and cannot be locked. +pub const DISCARDED = 157; + +/// The segment is already unlocked. +pub const NOT_LOCKED = 158; + +/// The address for the thread ID is not correct. +pub const BAD_THREADID_ADDR = 159; + +/// One or more arguments are not correct. +pub const BAD_ARGUMENTS = 160; + +/// The specified path is invalid. +pub const BAD_PATHNAME = 161; + +/// A signal is already pending. +pub const SIGNAL_PENDING = 162; + +/// No more threads can be created in the system. +pub const MAX_THRDS_REACHED = 164; + +/// Unable to lock a region of a file. +pub const LOCK_FAILED = 167; + +/// The requested resource is in use. +pub const BUSY = 170; + +/// Device's command support detection is in progress. +pub const DEVICE_SUPPORT_IN_PROGRESS = 171; + +/// A lock request was not outstanding for the supplied cancel region. +pub const CANCEL_VIOLATION = 173; + +/// The file system does not support atomic changes to the lock type. +pub const ATOMIC_LOCKS_NOT_SUPPORTED = 174; + +/// The system detected a segment number that was not correct. +pub const INVALID_SEGMENT_NUMBER = 180; + +/// The operating system cannot run %1. +pub const INVALID_ORDINAL = 182; + +/// Cannot create a file when that file already exists. +pub const ALREADY_EXISTS = 183; + +/// The flag passed is not correct. +pub const INVALID_FLAG_NUMBER = 186; + +/// The specified system semaphore name was not found. +pub const SEM_NOT_FOUND = 187; + +/// The operating system cannot run %1. +pub const INVALID_STARTING_CODESEG = 188; + +/// The operating system cannot run %1. +pub const INVALID_STACKSEG = 189; + +/// The operating system cannot run %1. +pub const INVALID_MODULETYPE = 190; + +/// Cannot run %1 in Win32 mode. +pub const INVALID_EXE_SIGNATURE = 191; + +/// The operating system cannot run %1. +pub const EXE_MARKED_INVALID = 192; + +/// %1 is not a valid Win32 application. +pub const BAD_EXE_FORMAT = 193; + +/// The operating system cannot run %1. +pub const ITERATED_DATA_EXCEEDS_64k = 194; + +/// The operating system cannot run %1. +pub const INVALID_MINALLOCSIZE = 195; + +/// The operating system cannot run this application program. +pub const DYNLINK_FROM_INVALID_RING = 196; + +/// The operating system is not presently configured to run this application. +pub const IOPL_NOT_ENABLED = 197; + +/// The operating system cannot run %1. +pub const INVALID_SEGDPL = 198; + +/// The operating system cannot run this application program. +pub const AUTODATASEG_EXCEEDS_64k = 199; + +/// The code segment cannot be greater than or equal to 64K. +pub const RING2SEG_MUST_BE_MOVABLE = 200; + +/// The operating system cannot run %1. +pub const RELOC_CHAIN_XEEDS_SEGLIM = 201; + +/// The operating system cannot run %1. +pub const INFLOOP_IN_RELOC_CHAIN = 202; + +/// The system could not find the environment option that was entered. +pub const ENVVAR_NOT_FOUND = 203; + +/// No process in the command subtree has a signal handler. +pub const NO_SIGNAL_SENT = 205; + +/// The filename or extension is too long. +pub const FILENAME_EXCED_RANGE = 206; + +/// The ring 2 stack is in use. +pub const RING2_STACK_IN_USE = 207; + +/// The global filename characters, * or ?, are entered incorrectly or too many global filename characters are specified. +pub const META_EXPANSION_TOO_LONG = 208; + +/// The signal being posted is not correct. +pub const INVALID_SIGNAL_NUMBER = 209; + +/// The signal handler cannot be set. +pub const THREAD_1_INACTIVE = 210; + +/// The segment is locked and cannot be reallocated. +pub const LOCKED = 212; + +/// Too many dynamic-link modules are attached to this program or dynamic-link module. +pub const TOO_MANY_MODULES = 214; + +/// Cannot nest calls to LoadModule. +pub const NESTING_NOT_ALLOWED = 215; + +/// This version of %1 is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher. +pub const EXE_MACHINE_TYPE_MISMATCH = 216; + +/// The image file %1 is signed, unable to modify. +pub const EXE_CANNOT_MODIFY_SIGNED_BINARY = 217; + +/// The image file %1 is strong signed, unable to modify. +pub const EXE_CANNOT_MODIFY_STRONG_SIGNED_BINARY = 218; + +/// This file is checked out or locked for editing by another user. +pub const FILE_CHECKED_OUT = 220; + +/// The file must be checked out before saving changes. +pub const CHECKOUT_REQUIRED = 221; + +/// The file type being saved or retrieved has been blocked. +pub const BAD_FILE_TYPE = 222; + +/// The file size exceeds the limit allowed and cannot be saved. +pub const FILE_TOO_LARGE = 223; + +/// Access Denied. Before opening files in this location, you must first add the web site to your trusted sites list, browse to the web site, and select the option to login automatically. +pub const FORMS_AUTH_REQUIRED = 224; + +/// Operation did not complete successfully because the file contains a virus or potentially unwanted software. +pub const VIRUS_INFECTED = 225; + +/// This file contains a virus or potentially unwanted software and cannot be opened. Due to the nature of this virus or potentially unwanted software, the file has been removed from this location. +pub const VIRUS_DELETED = 226; + +/// The pipe is local. +pub const PIPE_LOCAL = 229; + +/// The pipe state is invalid. +pub const BAD_PIPE = 230; + +/// All pipe instances are busy. +pub const PIPE_BUSY = 231; + +/// The pipe is being closed. +pub const NO_DATA = 232; + +/// No process is on the other end of the pipe. +pub const PIPE_NOT_CONNECTED = 233; + +/// More data is available. +pub const MORE_DATA = 234; + +/// The session was canceled. +pub const VC_DISCONNECTED = 240; + +/// The specified extended attribute name was invalid. +pub const INVALID_EA_NAME = 254; + +/// The extended attributes are inconsistent. +pub const EA_LIST_INCONSISTENT = 255; + +/// The wait operation timed out. +pub const IMEOUT = 258; + +/// No more data is available. +pub const NO_MORE_ITEMS = 259; + +/// The copy functions cannot be used. +pub const CANNOT_COPY = 266; + +/// The directory name is invalid. +pub const DIRECTORY = 267; + +/// The extended attributes did not fit in the buffer. +pub const EAS_DIDNT_FIT = 275; + +/// The extended attribute file on the mounted file system is corrupt. +pub const EA_FILE_CORRUPT = 276; + +/// The extended attribute table file is full. +pub const EA_TABLE_FULL = 277; + +/// The specified extended attribute handle is invalid. +pub const INVALID_EA_HANDLE = 278; + +/// The mounted file system does not support extended attributes. +pub const EAS_NOT_SUPPORTED = 282; + +/// Attempt to release mutex not owned by caller. +pub const NOT_OWNER = 288; + +/// Too many posts were made to a semaphore. +pub const TOO_MANY_POSTS = 298; + +/// Only part of a ReadProcessMemory or WriteProcessMemory request was completed. +pub const PARTIAL_COPY = 299; + +/// The oplock request is denied. +pub const OPLOCK_NOT_GRANTED = 300; + +/// An invalid oplock acknowledgment was received by the system. +pub const INVALID_OPLOCK_PROTOCOL = 301; + +/// The volume is too fragmented to complete this operation. +pub const DISK_TOO_FRAGMENTED = 302; + +/// The file cannot be opened because it is in the process of being deleted. +pub const DELETE_PENDING = 303; + +/// Short name settings may not be changed on this volume due to the global registry setting. +pub const INCOMPATIBLE_WITH_GLOBAL_SHORT_NAME_REGISTRY_SETTING = 304; + +/// Short names are not enabled on this volume. +pub const SHORT_NAMES_NOT_ENABLED_ON_VOLUME = 305; + +/// The security stream for the given volume is in an inconsistent state. Please run CHKDSK on the volume. +pub const SECURITY_STREAM_IS_INCONSISTENT = 306; + +/// A requested file lock operation cannot be processed due to an invalid byte range. +pub const INVALID_LOCK_RANGE = 307; + +/// The subsystem needed to support the image type is not present. +pub const IMAGE_SUBSYSTEM_NOT_PRESENT = 308; + +/// The specified file already has a notification GUID associated with it. +pub const NOTIFICATION_GUID_ALREADY_DEFINED = 309; + +/// An invalid exception handler routine has been detected. +pub const INVALID_EXCEPTION_HANDLER = 310; + +/// Duplicate privileges were specified for the token. +pub const DUPLICATE_PRIVILEGES = 311; + +/// No ranges for the specified operation were able to be processed. +pub const NO_RANGES_PROCESSED = 312; + +/// Operation is not allowed on a file system internal file. +pub const NOT_ALLOWED_ON_SYSTEM_FILE = 313; + +/// The physical resources of this disk have been exhausted. +pub const DISK_RESOURCES_EXHAUSTED = 314; + +/// The token representing the data is invalid. +pub const INVALID_TOKEN = 315; + +/// The device does not support the command feature. +pub const DEVICE_FEATURE_NOT_SUPPORTED = 316; + +/// The system cannot find message text for message number 0x%1 in the message file for %2. +pub const MR_MID_NOT_FOUND = 317; + +/// The scope specified was not found. +pub const SCOPE_NOT_FOUND = 318; + +/// The Central Access Policy specified is not defined on the target machine. +pub const UNDEFINED_SCOPE = 319; + +/// The Central Access Policy obtained from Active Directory is invalid. +pub const INVALID_CAP = 320; + +/// The device is unreachable. +pub const DEVICE_UNREACHABLE = 321; + +/// The target device has insufficient resources to complete the operation. +pub const DEVICE_NO_RESOURCES = 322; + +/// A data integrity checksum error occurred. Data in the file stream is corrupt. +pub const DATA_CHECKSUM_ERROR = 323; + +/// An attempt was made to modify both a KERNEL and normal Extended Attribute (EA) in the same operation. +pub const INTERMIXED_KERNEL_EA_OPERATION = 324; + +/// Device does not support file-level TRIM. +pub const FILE_LEVEL_TRIM_NOT_SUPPORTED = 326; + +/// The command specified a data offset that does not align to the device's granularity/alignment. +pub const OFFSET_ALIGNMENT_VIOLATION = 327; + +/// The command specified an invalid field in its parameter list. +pub const INVALID_FIELD_IN_PARAMETER_LIST = 328; + +/// An operation is currently in progress with the device. +pub const OPERATION_IN_PROGRESS = 329; + +/// An attempt was made to send down the command via an invalid path to the target device. +pub const BAD_DEVICE_PATH = 330; + +/// The command specified a number of descriptors that exceeded the maximum supported by the device. +pub const TOO_MANY_DESCRIPTORS = 331; + +/// Scrub is disabled on the specified file. +pub const SCRUB_DATA_DISABLED = 332; + +/// The storage device does not provide redundancy. +pub const NOT_REDUNDANT_STORAGE = 333; + +/// An operation is not supported on a resident file. +pub const RESIDENT_FILE_NOT_SUPPORTED = 334; + +/// An operation is not supported on a compressed file. +pub const COMPRESSED_FILE_NOT_SUPPORTED = 335; + +/// An operation is not supported on a directory. +pub const DIRECTORY_NOT_SUPPORTED = 336; + +/// The specified copy of the requested data could not be read. +pub const NOT_READ_FROM_COPY = 337; + +/// No action was taken as a system reboot is required. +pub const FAIL_NOACTION_REBOOT = 350; + +/// The shutdown operation failed. +pub const FAIL_SHUTDOWN = 351; + +/// The restart operation failed. +pub const FAIL_RESTART = 352; + +/// The maximum number of sessions has been reached. +pub const MAX_SESSIONS_REACHED = 353; + +/// The thread is already in background processing mode. +pub const THREAD_MODE_ALREADY_BACKGROUND = 400; + +/// The thread is not in background processing mode. +pub const THREAD_MODE_NOT_BACKGROUND = 401; + +/// The process is already in background processing mode. +pub const PROCESS_MODE_ALREADY_BACKGROUND = 402; + +/// The process is not in background processing mode. +pub const PROCESS_MODE_NOT_BACKGROUND = 403; + +/// Attempt to access invalid address. +pub const INVALID_ADDRESS = 487; + +/// User profile cannot be loaded. +pub const USER_PROFILE_LOAD = 500; + +/// Arithmetic result exceeded 32 bits. +pub const ARITHMETIC_OVERFLOW = 534; + +/// There is a process on other end of the pipe. +pub const PIPE_CONNECTED = 535; + +/// Waiting for a process to open the other end of the pipe. +pub const PIPE_LISTENING = 536; + +/// Application verifier has found an error in the current process. +pub const VERIFIER_STOP = 537; + +/// An error occurred in the ABIOS subsystem. +pub const ABIOS_ERROR = 538; + +/// A warning occurred in the WX86 subsystem. +pub const WX86_WARNING = 539; + +/// An error occurred in the WX86 subsystem. +pub const WX86_ERROR = 540; + +/// An attempt was made to cancel or set a timer that has an associated APC and the subject thread is not the thread that originally set the timer with an associated APC routine. +pub const TIMER_NOT_CANCELED = 541; + +/// Unwind exception code. +pub const UNWIND = 542; + +/// An invalid or unaligned stack was encountered during an unwind operation. +pub const BAD_STACK = 543; + +/// An invalid unwind target was encountered during an unwind operation. +pub const INVALID_UNWIND_TARGET = 544; + +/// Invalid Object Attributes specified to NtCreatePort or invalid Port Attributes specified to NtConnectPort +pub const INVALID_PORT_ATTRIBUTES = 545; + +/// Length of message passed to NtRequestPort or NtRequestWaitReplyPort was longer than the maximum message allowed by the port. +pub const PORT_MESSAGE_TOO_LONG = 546; + +/// An attempt was made to lower a quota limit below the current usage. +pub const INVALID_QUOTA_LOWER = 547; + +/// An attempt was made to attach to a device that was already attached to another device. +pub const DEVICE_ALREADY_ATTACHED = 548; + +/// An attempt was made to execute an instruction at an unaligned address and the host system does not support unaligned instruction references. +pub const INSTRUCTION_MISALIGNMENT = 549; + +/// Profiling not started. +pub const PROFILING_NOT_STARTED = 550; + +/// Profiling not stopped. +pub const PROFILING_NOT_STOPPED = 551; + +/// The passed ACL did not contain the minimum required information. +pub const COULD_NOT_INTERPRET = 552; + +/// The number of active profiling objects is at the maximum and no more may be started. +pub const PROFILING_AT_LIMIT = 553; + +/// Used to indicate that an operation cannot continue without blocking for I/O. +pub const CANT_WAIT = 554; + +/// Indicates that a thread attempted to terminate itself by default (called NtTerminateThread with NULL) and it was the last thread in the current process. +pub const CANT_TERMINATE_SELF = 555; + +/// If an MM error is returned which is not defined in the standard FsRtl filter, it is converted to one of the following errors which is guaranteed to be in the filter. In this case information is lost, however, the filter correctly handles the exception. +pub const UNEXPECTED_MM_CREATE_ERR = 556; + +/// If an MM error is returned which is not defined in the standard FsRtl filter, it is converted to one of the following errors which is guaranteed to be in the filter. In this case information is lost, however, the filter correctly handles the exception. +pub const UNEXPECTED_MM_MAP_ERROR = 557; + +/// If an MM error is returned which is not defined in the standard FsRtl filter, it is converted to one of the following errors which is guaranteed to be in the filter. In this case information is lost, however, the filter correctly handles the exception. +pub const UNEXPECTED_MM_EXTEND_ERR = 558; + +/// A malformed function table was encountered during an unwind operation. +pub const BAD_FUNCTION_TABLE = 559; + +/// Indicates that an attempt was made to assign protection to a file system file or directory and one of the SIDs in the security descriptor could not be translated into a GUID that could be stored by the file system. This causes the protection attempt to fail, which may cause a file creation attempt to fail. +pub const NO_GUID_TRANSLATION = 560; + +/// Indicates that an attempt was made to grow an LDT by setting its size, or that the size was not an even number of selectors. +pub const INVALID_LDT_SIZE = 561; + +/// Indicates that the starting value for the LDT information was not an integral multiple of the selector size. +pub const INVALID_LDT_OFFSET = 563; + +/// Indicates that the user supplied an invalid descriptor when trying to set up Ldt descriptors. +pub const INVALID_LDT_DESCRIPTOR = 564; + +/// Indicates a process has too many threads to perform the requested action. For example, assignment of a primary token may only be performed when a process has zero or one threads. +pub const TOO_MANY_THREADS = 565; + +/// An attempt was made to operate on a thread within a specific process, but the thread specified is not in the process specified. +pub const THREAD_NOT_IN_PROCESS = 566; + +/// Page file quota was exceeded. +pub const PAGEFILE_QUOTA_EXCEEDED = 567; + +/// The Netlogon service cannot start because another Netlogon service running in the domain conflicts with the specified role. +pub const LOGON_SERVER_CONFLICT = 568; + +/// The SAM database on a Windows Server is significantly out of synchronization with the copy on the Domain Controller. A complete synchronization is required. +pub const SYNCHRONIZATION_REQUIRED = 569; + +/// The NtCreateFile API failed. This error should never be returned to an application, it is a place holder for the Windows Lan Manager Redirector to use in its internal error mapping routines. +pub const NET_OPEN_FAILED = 570; + +/// {Privilege Failed} The I/O permissions for the process could not be changed. +pub const IO_PRIVILEGE_FAILED = 571; + +/// {Application Exit by CTRL+C} The application terminated as a result of a CTRL+C. +pub const CONTROL_C_EXIT = 572; + +/// {Missing System File} The required system file %hs is bad or missing. +pub const MISSING_SYSTEMFILE = 573; + +/// {Application Error} The exception %s (0x%08lx) occurred in the application at location 0x%08lx. +pub const UNHANDLED_EXCEPTION = 574; + +/// {Application Error} The application was unable to start correctly (0x%lx). Click OK to close the application. +pub const APP_INIT_FAILURE = 575; + +/// {Unable to Create Paging File} The creation of the paging file %hs failed (%lx). The requested size was %ld. +pub const PAGEFILE_CREATE_FAILED = 576; + +/// Windows cannot verify the digital signature for this file. A recent hardware or software change might have installed a file that is signed incorrectly or damaged, or that might be malicious software from an unknown source. +pub const INVALID_IMAGE_HASH = 577; + +/// {No Paging File Specified} No paging file was specified in the system configuration. +pub const NO_PAGEFILE = 578; + +/// {EXCEPTION} A real-mode application issued a floating-point instruction and floating-point hardware is not present. +pub const ILLEGAL_FLOAT_CONTEXT = 579; + +/// An event pair synchronization operation was performed using the thread specific client/server event pair object, but no event pair object was associated with the thread. +pub const NO_EVENT_PAIR = 580; + +/// A Windows Server has an incorrect configuration. +pub const DOMAIN_CTRLR_CONFIG_ERROR = 581; + +/// An illegal character was encountered. For a multi-byte character set this includes a lead byte without a succeeding trail byte. For the Unicode character set this includes the characters 0xFFFF and 0xFFFE. +pub const ILLEGAL_CHARACTER = 582; + +/// The Unicode character is not defined in the Unicode character set installed on the system. +pub const UNDEFINED_CHARACTER = 583; + +/// The paging file cannot be created on a floppy diskette. +pub const FLOPPY_VOLUME = 584; + +/// The system BIOS failed to connect a system interrupt to the device or bus for which the device is connected. +pub const BIOS_FAILED_TO_CONNECT_INTERRUPT = 585; + +/// This operation is only allowed for the Primary Domain Controller of the domain. +pub const BACKUP_CONTROLLER = 586; + +/// An attempt was made to acquire a mutant such that its maximum count would have been exceeded. +pub const MUTANT_LIMIT_EXCEEDED = 587; + +/// A volume has been accessed for which a file system driver is required that has not yet been loaded. +pub const FS_DRIVER_REQUIRED = 588; + +/// {Registry File Failure} The registry cannot load the hive (file): %hs or its log or alternate. It is corrupt, absent, or not writable. +pub const CANNOT_LOAD_REGISTRY_FILE = 589; + +/// {Unexpected Failure in DebugActiveProcess} An unexpected failure occurred while processing a DebugActiveProcess API request. You may choose OK to terminate the process, or Cancel to ignore the error. +pub const DEBUG_ATTACH_FAILED = 590; + +/// {Fatal System Error} The %hs system process terminated unexpectedly with a status of 0x%08x (0x%08x 0x%08x). The system has been shut down. +pub const SYSTEM_PROCESS_TERMINATED = 591; + +/// {Data Not Accepted} The TDI client could not handle the data received during an indication. +pub const DATA_NOT_ACCEPTED = 592; + +/// NTVDM encountered a hard error. +pub const VDM_HARD_ERROR = 593; + +/// {Cancel Timeout} The driver %hs failed to complete a cancelled I/O request in the allotted time. +pub const DRIVER_CANCEL_TIMEOUT = 594; + +/// {Reply Message Mismatch} An attempt was made to reply to an LPC message, but the thread specified by the client ID in the message was not waiting on that message. +pub const REPLY_MESSAGE_MISMATCH = 595; + +/// {Delayed Write Failed} Windows was unable to save all the data for the file %hs. The data has been lost. This error may be caused by a failure of your computer hardware or network connection. Please try to save this file elsewhere. +pub const LOST_WRITEBEHIND_DATA = 596; + +/// The parameter(s) passed to the server in the client/server shared memory window were invalid. Too much data may have been put in the shared memory window. +pub const CLIENT_SERVER_PARAMETERS_INVALID = 597; + +/// The stream is not a tiny stream. +pub const NOT_TINY_STREAM = 598; + +/// The request must be handled by the stack overflow code. +pub const STACK_OVERFLOW_READ = 599; + +/// Internal OFS status codes indicating how an allocation operation is handled. Either it is retried after the containing onode is moved or the extent stream is converted to a large stream. +pub const CONVERT_TO_LARGE = 600; + +/// The attempt to find the object found an object matching by ID on the volume but it is out of the scope of the handle used for the operation. +pub const FOUND_OUT_OF_SCOPE = 601; + +/// The bucket array must be grown. Retry transaction after doing so. +pub const ALLOCATE_BUCKET = 602; + +/// The user/kernel marshalling buffer has overflowed. +pub const MARSHALL_OVERFLOW = 603; + +/// The supplied variant structure contains invalid data. +pub const INVALID_VARIANT = 604; + +/// The specified buffer contains ill-formed data. +pub const BAD_COMPRESSION_BUFFER = 605; + +/// {Audit Failed} An attempt to generate a security audit failed. +pub const AUDIT_FAILED = 606; + +/// The timer resolution was not previously set by the current process. +pub const TIMER_RESOLUTION_NOT_SET = 607; + +/// There is insufficient account information to log you on. +pub const INSUFFICIENT_LOGON_INFO = 608; + +/// {Invalid DLL Entrypoint} The dynamic link library %hs is not written correctly. The stack pointer has been left in an inconsistent state. The entrypoint should be declared as WINAPI or STDCALL. Select YES to fail the DLL load. Select NO to continue execution. Selecting NO may cause the application to operate incorrectly. +pub const BAD_DLL_ENTRYPOINT = 609; + +/// {Invalid Service Callback Entrypoint} The %hs service is not written correctly. The stack pointer has been left in an inconsistent state. The callback entrypoint should be declared as WINAPI or STDCALL. Selecting OK will cause the service to continue operation. However, the service process may operate incorrectly. +pub const BAD_SERVICE_ENTRYPOINT = 610; + +/// There is an IP address conflict with another system on the network. +pub const IP_ADDRESS_CONFLICT1 = 611; + +/// There is an IP address conflict with another system on the network. +pub const IP_ADDRESS_CONFLICT2 = 612; + +/// {Low On Registry Space} The system has reached the maximum size allowed for the system part of the registry. Additional storage requests will be ignored. +pub const REGISTRY_QUOTA_LIMIT = 613; + +/// A callback return system service cannot be executed when no callback is active. +pub const NO_CALLBACK_ACTIVE = 614; + +/// The password provided is too short to meet the policy of your user account. Please choose a longer password. +pub const PWD_TOO_SHORT = 615; + +/// The policy of your user account does not allow you to change passwords too frequently. This is done to prevent users from changing back to a familiar, but potentially discovered, password. If you feel your password has been compromised then please contact your administrator immediately to have a new one assigned. +pub const PWD_TOO_RECENT = 616; + +/// You have attempted to change your password to one that you have used in the past. The policy of your user account does not allow this. Please select a password that you have not previously used. +pub const PWD_HISTORY_CONFLICT = 617; + +/// The specified compression format is unsupported. +pub const UNSUPPORTED_COMPRESSION = 618; + +/// The specified hardware profile configuration is invalid. +pub const INVALID_HW_PROFILE = 619; + +/// The specified Plug and Play registry device path is invalid. +pub const INVALID_PLUGPLAY_DEVICE_PATH = 620; + +/// The specified quota list is internally inconsistent with its descriptor. +pub const QUOTA_LIST_INCONSISTENT = 621; + +/// {Windows Evaluation Notification} The evaluation period for this installation of Windows has expired. This system will shutdown in 1 hour. To restore access to this installation of Windows, please upgrade this installation using a licensed distribution of this product. +pub const EVALUATION_EXPIRATION = 622; + +/// {Illegal System DLL Relocation} The system DLL %hs was relocated in memory. The application will not run properly. The relocation occurred because the DLL %hs occupied an address range reserved for Windows system DLLs. The vendor supplying the DLL should be contacted for a new DLL. +pub const ILLEGAL_DLL_RELOCATION = 623; + +/// {DLL Initialization Failed} The application failed to initialize because the window station is shutting down. +pub const DLL_INIT_FAILED_LOGOFF = 624; + +/// The validation process needs to continue on to the next step. +pub const VALIDATE_CONTINUE = 625; + +/// There are no more matches for the current index enumeration. +pub const NO_MORE_MATCHES = 626; + +/// The range could not be added to the range list because of a conflict. +pub const RANGE_LIST_CONFLICT = 627; + +/// The server process is running under a SID different than that required by client. +pub const SERVER_SID_MISMATCH = 628; + +/// A group marked use for deny only cannot be enabled. +pub const CANT_ENABLE_DENY_ONLY = 629; + +/// {EXCEPTION} Multiple floating point faults. +pub const FLOAT_MULTIPLE_FAULTS = 630; + +/// {EXCEPTION} Multiple floating point traps. +pub const FLOAT_MULTIPLE_TRAPS = 631; + +/// The requested interface is not supported. +pub const NOINTERFACE = 632; + +/// {System Standby Failed} The driver %hs does not support standby mode. Updating this driver may allow the system to go to standby mode. +pub const DRIVER_FAILED_SLEEP = 633; + +/// The system file %1 has become corrupt and has been replaced. +pub const CORRUPT_SYSTEM_FILE = 634; + +/// {Virtual Memory Minimum Too Low} Your system is low on virtual memory. Windows is increasing the size of your virtual memory paging file. During this process, memory requests for some applications may be denied. For more information, see Help. +pub const COMMITMENT_MINIMUM = 635; + +/// A device was removed so enumeration must be restarted. +pub const PNP_RESTART_ENUMERATION = 636; + +/// {Fatal System Error} The system image %s is not properly signed. The file has been replaced with the signed file. The system has been shut down. +pub const SYSTEM_IMAGE_BAD_SIGNATURE = 637; + +/// Device will not start without a reboot. +pub const PNP_REBOOT_REQUIRED = 638; + +/// There is not enough power to complete the requested operation. +pub const INSUFFICIENT_POWER = 639; + +/// ERROR_MULTIPLE_FAULT_VIOLATION +pub const MULTIPLE_FAULT_VIOLATION = 640; + +/// The system is in the process of shutting down. +pub const SYSTEM_SHUTDOWN = 641; + +/// An attempt to remove a processes DebugPort was made, but a port was not already associated with the process. +pub const PORT_NOT_SET = 642; + +/// This version of Windows is not compatible with the behavior version of directory forest, domain or domain controller. +pub const DS_VERSION_CHECK_FAILURE = 643; + +/// The specified range could not be found in the range list. +pub const RANGE_NOT_FOUND = 644; + +/// The driver was not loaded because the system is booting into safe mode. +pub const NOT_SAFE_MODE_DRIVER = 646; + +/// The driver was not loaded because it failed its initialization call. +pub const FAILED_DRIVER_ENTRY = 647; + +/// The "%hs" encountered an error while applying power or reading the device configuration. This may be caused by a failure of your hardware or by a poor connection. +pub const DEVICE_ENUMERATION_ERROR = 648; + +/// The create operation failed because the name contained at least one mount point which resolves to a volume to which the specified device object is not attached. +pub const MOUNT_POINT_NOT_RESOLVED = 649; + +/// The device object parameter is either not a valid device object or is not attached to the volume specified by the file name. +pub const INVALID_DEVICE_OBJECT_PARAMETER = 650; + +/// A Machine Check Error has occurred. Please check the system eventlog for additional information. +pub const MCA_OCCURED = 651; + +/// There was error [%2] processing the driver database. +pub const DRIVER_DATABASE_ERROR = 652; + +/// System hive size has exceeded its limit. +pub const SYSTEM_HIVE_TOO_LARGE = 653; + +/// The driver could not be loaded because a previous version of the driver is still in memory. +pub const DRIVER_FAILED_PRIOR_UNLOAD = 654; + +/// {Volume Shadow Copy Service} Please wait while the Volume Shadow Copy Service prepares volume %hs for hibernation. +pub const VOLSNAP_PREPARE_HIBERNATE = 655; + +/// The system has failed to hibernate (The error code is %hs). Hibernation will be disabled until the system is restarted. +pub const HIBERNATION_FAILURE = 656; + +/// The password provided is too long to meet the policy of your user account. Please choose a shorter password. +pub const PWD_TOO_LONG = 657; + +/// The requested operation could not be completed due to a file system limitation. +pub const FILE_SYSTEM_LIMITATION = 665; + +/// An assertion failure has occurred. +pub const ASSERTION_FAILURE = 668; + +/// An error occurred in the ACPI subsystem. +pub const ACPI_ERROR = 669; + +/// WOW Assertion Error. +pub const WOW_ASSERTION = 670; + +/// A device is missing in the system BIOS MPS table. This device will not be used. Please contact your system vendor for system BIOS update. +pub const PNP_BAD_MPS_TABLE = 671; + +/// A translator failed to translate resources. +pub const PNP_TRANSLATION_FAILED = 672; + +/// A IRQ translator failed to translate resources. +pub const PNP_IRQ_TRANSLATION_FAILED = 673; + +/// Driver %2 returned invalid ID for a child device (%3). +pub const PNP_INVALID_ID = 674; + +/// {Kernel Debugger Awakened} the system debugger was awakened by an interrupt. +pub const WAKE_SYSTEM_DEBUGGER = 675; + +/// {Handles Closed} Handles to objects have been automatically closed as a result of the requested operation. +pub const HANDLES_CLOSED = 676; + +/// {Too Much Information} The specified access control list (ACL) contained more information than was expected. +pub const EXTRANEOUS_INFORMATION = 677; + +/// This warning level status indicates that the transaction state already exists for the registry sub-tree, but that a transaction commit was previously aborted. The commit has NOT been completed, but has not been rolled back either (so it may still be committed if desired). +pub const RXACT_COMMIT_NECESSARY = 678; + +/// {Media Changed} The media may have changed. +pub const MEDIA_CHECK = 679; + +/// {GUID Substitution} During the translation of a global identifier (GUID) to a Windows security ID (SID), no administratively-defined GUID prefix was found. A substitute prefix was used, which will not compromise system security. However, this may provide a more restrictive access than intended. +pub const GUID_SUBSTITUTION_MADE = 680; + +/// The create operation stopped after reaching a symbolic link. +pub const STOPPED_ON_SYMLINK = 681; + +/// A long jump has been executed. +pub const LONGJUMP = 682; + +/// The Plug and Play query operation was not successful. +pub const PLUGPLAY_QUERY_VETOED = 683; + +/// A frame consolidation has been executed. +pub const UNWIND_CONSOLIDATE = 684; + +/// {Registry Hive Recovered} Registry hive (file): %hs was corrupted and it has been recovered. Some data might have been lost. +pub const REGISTRY_HIVE_RECOVERED = 685; + +/// The application is attempting to run executable code from the module %hs. This may be insecure. An alternative, %hs, is available. Should the application use the secure module %hs? +pub const DLL_MIGHT_BE_INSECURE = 686; + +/// The application is loading executable code from the module %hs. This is secure, but may be incompatible with previous releases of the operating system. An alternative, %hs, is available. Should the application use the secure module %hs? +pub const DLL_MIGHT_BE_INCOMPATIBLE = 687; + +/// Debugger did not handle the exception. +pub const DBG_EXCEPTION_NOT_HANDLED = 688; + +/// Debugger will reply later. +pub const DBG_REPLY_LATER = 689; + +/// Debugger cannot provide handle. +pub const DBG_UNABLE_TO_PROVIDE_HANDLE = 690; + +/// Debugger terminated thread. +pub const DBG_TERMINATE_THREAD = 691; + +/// Debugger terminated process. +pub const DBG_TERMINATE_PROCESS = 692; + +/// Debugger got control C. +pub const DBG_CONTROL_C = 693; + +/// Debugger printed exception on control C. +pub const DBG_PRINTEXCEPTION_C = 694; + +/// Debugger received RIP exception. +pub const DBG_RIPEXCEPTION = 695; + +/// Debugger received control break. +pub const DBG_CONTROL_BREAK = 696; + +/// Debugger command communication exception. +pub const DBG_COMMAND_EXCEPTION = 697; + +/// {Object Exists} An attempt was made to create an object and the object name already existed. +pub const OBJECT_NAME_EXISTS = 698; + +/// {Thread Suspended} A thread termination occurred while the thread was suspended. The thread was resumed, and termination proceeded. +pub const THREAD_WAS_SUSPENDED = 699; + +/// {Image Relocated} An image file could not be mapped at the address specified in the image file. Local fixups must be performed on this image. +pub const IMAGE_NOT_AT_BASE = 700; + +/// This informational level status indicates that a specified registry sub-tree transaction state did not yet exist and had to be created. +pub const RXACT_STATE_CREATED = 701; + +/// {Segment Load} A virtual DOS machine (VDM) is loading, unloading, or moving an MS-DOS or Win16 program segment image. An exception is raised so a debugger can load, unload or track symbols and breakpoints within these 16-bit segments. +pub const SEGMENT_NOTIFICATION = 702; + +/// {Invalid Current Directory} The process cannot switch to the startup current directory %hs. Select OK to set current directory to %hs, or select CANCEL to exit. +pub const BAD_CURRENT_DIRECTORY = 703; + +/// {Redundant Read} To satisfy a read request, the NT fault-tolerant file system successfully read the requested data from a redundant copy. This was done because the file system encountered a failure on a member of the fault-tolerant volume, but was unable to reassign the failing area of the device. +pub const FT_READ_RECOVERY_FROM_BACKUP = 704; + +/// {Redundant Write} To satisfy a write request, the NT fault-tolerant file system successfully wrote a redundant copy of the information. This was done because the file system encountered a failure on a member of the fault-tolerant volume, but was not able to reassign the failing area of the device. +pub const FT_WRITE_RECOVERY = 705; + +/// {Machine Type Mismatch} The image file %hs is valid, but is for a machine type other than the current machine. Select OK to continue, or CANCEL to fail the DLL load. +pub const IMAGE_MACHINE_TYPE_MISMATCH = 706; + +/// {Partial Data Received} The network transport returned partial data to its client. The remaining data will be sent later. +pub const RECEIVE_PARTIAL = 707; + +/// {Expedited Data Received} The network transport returned data to its client that was marked as expedited by the remote system. +pub const RECEIVE_EXPEDITED = 708; + +/// {Partial Expedited Data Received} The network transport returned partial data to its client and this data was marked as expedited by the remote system. The remaining data will be sent later. +pub const RECEIVE_PARTIAL_EXPEDITED = 709; + +/// {TDI Event Done} The TDI indication has completed successfully. +pub const EVENT_DONE = 710; + +/// {TDI Event Pending} The TDI indication has entered the pending state. +pub const EVENT_PENDING = 711; + +/// Checking file system on %wZ. +pub const CHECKING_FILE_SYSTEM = 712; + +/// {Fatal Application Exit} %hs. +pub const FATAL_APP_EXIT = 713; + +/// The specified registry key is referenced by a predefined handle. +pub const PREDEFINED_HANDLE = 714; + +/// {Page Unlocked} The page protection of a locked page was changed to 'No Access' and the page was unlocked from memory and from the process. +pub const WAS_UNLOCKED = 715; + +/// %hs +pub const SERVICE_NOTIFICATION = 716; + +/// {Page Locked} One of the pages to lock was already locked. +pub const WAS_LOCKED = 717; + +/// Application popup: %1 : %2 +pub const LOG_HARD_ERROR = 718; + +/// ERROR_ALREADY_WIN32 +pub const ALREADY_WIN32 = 719; + +/// {Machine Type Mismatch} The image file %hs is valid, but is for a machine type other than the current machine. +pub const IMAGE_MACHINE_TYPE_MISMATCH_EXE = 720; + +/// A yield execution was performed and no thread was available to run. +pub const NO_YIELD_PERFORMED = 721; + +/// The resumable flag to a timer API was ignored. +pub const TIMER_RESUME_IGNORED = 722; + +/// The arbiter has deferred arbitration of these resources to its parent. +pub const ARBITRATION_UNHANDLED = 723; + +/// The inserted CardBus device cannot be started because of a configuration error on "%hs". +pub const CARDBUS_NOT_SUPPORTED = 724; + +/// The CPUs in this multiprocessor system are not all the same revision level. To use all processors the operating system restricts itself to the features of the least capable processor in the system. Should problems occur with this system, contact the CPU manufacturer to see if this mix of processors is supported. +pub const MP_PROCESSOR_MISMATCH = 725; + +/// The system was put into hibernation. +pub const HIBERNATED = 726; + +/// The system was resumed from hibernation. +pub const RESUME_HIBERNATION = 727; + +/// Windows has detected that the system firmware (BIOS) was updated [previous firmware date = %2, current firmware date %3]. +pub const FIRMWARE_UPDATED = 728; + +/// A device driver is leaking locked I/O pages causing system degradation. The system has automatically enabled tracking code in order to try and catch the culprit. +pub const DRIVERS_LEAKING_LOCKED_PAGES = 729; + +/// The system has awoken. +pub const WAKE_SYSTEM = 730; + +/// ERROR_WAIT_1 +pub const WAIT_1 = 731; + +/// ERROR_WAIT_2 +pub const WAIT_2 = 732; + +/// ERROR_WAIT_3 +pub const WAIT_3 = 733; + +/// ERROR_WAIT_63 +pub const WAIT_63 = 734; + +/// ERROR_ABANDONED_WAIT_0 +pub const ABANDONED_WAIT_0 = 735; + +/// ERROR_ABANDONED_WAIT_63 +pub const ABANDONED_WAIT_63 = 736; + +/// ERROR_USER_APC +pub const USER_APC = 737; + +/// ERROR_KERNEL_APC +pub const KERNEL_APC = 738; + +/// ERROR_ALERTED +pub const ALERTED = 739; + +/// The requested operation requires elevation. +pub const ELEVATION_REQUIRED = 740; + +/// A reparse should be performed by the Object Manager since the name of the file resulted in a symbolic link. +pub const REPARSE = 741; + +/// An open/create operation completed while an oplock break is underway. +pub const OPLOCK_BREAK_IN_PROGRESS = 742; + +/// A new volume has been mounted by a file system. +pub const VOLUME_MOUNTED = 743; + +/// This success level status indicates that the transaction state already exists for the registry sub-tree, but that a transaction commit was previously aborted. The commit has now been completed. +pub const RXACT_COMMITTED = 744; + +/// This indicates that a notify change request has been completed due to closing the handle which made the notify change request. +pub const NOTIFY_CLEANUP = 745; + +/// {Connect Failure on Primary Transport} An attempt was made to connect to the remote server %hs on the primary transport, but the connection failed. The computer WAS able to connect on a secondary transport. +pub const PRIMARY_TRANSPORT_CONNECT_FAILED = 746; + +/// Page fault was a transition fault. +pub const PAGE_FAULT_TRANSITION = 747; + +/// Page fault was a demand zero fault. +pub const PAGE_FAULT_DEMAND_ZERO = 748; + +/// Page fault was a demand zero fault. +pub const PAGE_FAULT_COPY_ON_WRITE = 749; + +/// Page fault was a demand zero fault. +pub const PAGE_FAULT_GUARD_PAGE = 750; + +/// Page fault was satisfied by reading from a secondary storage device. +pub const PAGE_FAULT_PAGING_FILE = 751; + +/// Cached page was locked during operation. +pub const CACHE_PAGE_LOCKED = 752; + +/// Crash dump exists in paging file. +pub const CRASH_DUMP = 753; + +/// Specified buffer contains all zeros. +pub const BUFFER_ALL_ZEROS = 754; + +/// A reparse should be performed by the Object Manager since the name of the file resulted in a symbolic link. +pub const REPARSE_OBJECT = 755; + +/// The device has succeeded a query-stop and its resource requirements have changed. +pub const RESOURCE_REQUIREMENTS_CHANGED = 756; + +/// The translator has translated these resources into the global space and no further translations should be performed. +pub const TRANSLATION_COMPLETE = 757; + +/// A process being terminated has no threads to terminate. +pub const NOTHING_TO_TERMINATE = 758; + +/// The specified process is not part of a job. +pub const PROCESS_NOT_IN_JOB = 759; + +/// The specified process is part of a job. +pub const PROCESS_IN_JOB = 760; + +/// {Volume Shadow Copy Service} The system is now ready for hibernation. +pub const VOLSNAP_HIBERNATE_READY = 761; + +/// A file system or file system filter driver has successfully completed an FsFilter operation. +pub const FSFILTER_OP_COMPLETED_SUCCESSFULLY = 762; + +/// The specified interrupt vector was already connected. +pub const INTERRUPT_VECTOR_ALREADY_CONNECTED = 763; + +/// The specified interrupt vector is still connected. +pub const INTERRUPT_STILL_CONNECTED = 764; + +/// An operation is blocked waiting for an oplock. +pub const WAIT_FOR_OPLOCK = 765; + +/// Debugger handled exception. +pub const DBG_EXCEPTION_HANDLED = 766; + +/// Debugger continued. +pub const DBG_CONTINUE = 767; + +/// An exception occurred in a user mode callback and the kernel callback frame should be removed. +pub const CALLBACK_POP_STACK = 768; + +/// Compression is disabled for this volume. +pub const COMPRESSION_DISABLED = 769; + +/// The data provider cannot fetch backwards through a result set. +pub const CANTFETCHBACKWARDS = 770; + +/// The data provider cannot scroll backwards through a result set. +pub const CANTSCROLLBACKWARDS = 771; + +/// The data provider requires that previously fetched data is released before asking for more data. +pub const ROWSNOTRELEASED = 772; + +/// The data provider was not able to interpret the flags set for a column binding in an accessor. +pub const BAD_ACCESSOR_FLAGS = 773; + +/// One or more errors occurred while processing the request. +pub const ERRORS_ENCOUNTERED = 774; + +/// The implementation is not capable of performing the request. +pub const NOT_CAPABLE = 775; + +/// The client of a component requested an operation which is not valid given the state of the component instance. +pub const REQUEST_OUT_OF_SEQUENCE = 776; + +/// A version number could not be parsed. +pub const VERSION_PARSE_ERROR = 777; + +/// The iterator's start position is invalid. +pub const BADSTARTPOSITION = 778; + +/// The hardware has reported an uncorrectable memory error. +pub const MEMORY_HARDWARE = 779; + +/// The attempted operation required self healing to be enabled. +pub const DISK_REPAIR_DISABLED = 780; + +/// The Desktop heap encountered an error while allocating session memory. There is more information in the system event log. +pub const INSUFFICIENT_RESOURCE_FOR_SPECIFIED_SHARED_SECTION_SIZE = 781; + +/// The system power state is transitioning from %2 to %3. +pub const SYSTEM_POWERSTATE_TRANSITION = 782; + +/// The system power state is transitioning from %2 to %3 but could enter %4. +pub const SYSTEM_POWERSTATE_COMPLEX_TRANSITION = 783; + +/// A thread is getting dispatched with MCA EXCEPTION because of MCA. +pub const MCA_EXCEPTION = 784; + +/// Access to %1 is monitored by policy rule %2. +pub const ACCESS_AUDIT_BY_POLICY = 785; + +/// Access to %1 has been restricted by your Administrator by policy rule %2. +pub const ACCESS_DISABLED_NO_SAFER_UI_BY_POLICY = 786; + +/// A valid hibernation file has been invalidated and should be abandoned. +pub const ABANDON_HIBERFILE = 787; + +/// {Delayed Write Failed} Windows was unable to save all the data for the file %hs; the data has been lost. This error may be caused by network connectivity issues. Please try to save this file elsewhere. +pub const LOST_WRITEBEHIND_DATA_NETWORK_DISCONNECTED = 788; + +/// {Delayed Write Failed} Windows was unable to save all the data for the file %hs; the data has been lost. This error was returned by the server on which the file exists. Please try to save this file elsewhere. +pub const LOST_WRITEBEHIND_DATA_NETWORK_SERVER_ERROR = 789; + +/// {Delayed Write Failed} Windows was unable to save all the data for the file %hs; the data has been lost. This error may be caused if the device has been removed or the media is write-protected. +pub const LOST_WRITEBEHIND_DATA_LOCAL_DISK_ERROR = 790; + +/// The resources required for this device conflict with the MCFG table. +pub const BAD_MCFG_TABLE = 791; + +/// The volume repair could not be performed while it is online. Please schedule to take the volume offline so that it can be repaired. +pub const DISK_REPAIR_REDIRECTED = 792; + +/// The volume repair was not successful. +pub const DISK_REPAIR_UNSUCCESSFUL = 793; + +/// One of the volume corruption logs is full. Further corruptions that may be detected won't be logged. +pub const CORRUPT_LOG_OVERFULL = 794; + +/// One of the volume corruption logs is internally corrupted and needs to be recreated. The volume may contain undetected corruptions and must be scanned. +pub const CORRUPT_LOG_CORRUPTED = 795; + +/// One of the volume corruption logs is unavailable for being operated on. +pub const CORRUPT_LOG_UNAVAILABLE = 796; + +/// One of the volume corruption logs was deleted while still having corruption records in them. The volume contains detected corruptions and must be scanned. +pub const CORRUPT_LOG_DELETED_FULL = 797; + +/// One of the volume corruption logs was cleared by chkdsk and no longer contains real corruptions. +pub const CORRUPT_LOG_CLEARED = 798; + +/// Orphaned files exist on the volume but could not be recovered because no more new names could be created in the recovery directory. Files must be moved from the recovery directory. +pub const ORPHAN_NAME_EXHAUSTED = 799; + +/// The oplock that was associated with this handle is now associated with a different handle. +pub const OPLOCK_SWITCHED_TO_NEW_HANDLE = 800; + +/// An oplock of the requested level cannot be granted. An oplock of a lower level may be available. +pub const CANNOT_GRANT_REQUESTED_OPLOCK = 801; + +/// The operation did not complete successfully because it would cause an oplock to be broken. The caller has requested that existing oplocks not be broken. +pub const CANNOT_BREAK_OPLOCK = 802; + +/// The handle with which this oplock was associated has been closed. The oplock is now broken. +pub const OPLOCK_HANDLE_CLOSED = 803; + +/// The specified access control entry (ACE) does not contain a condition. +pub const NO_ACE_CONDITION = 804; + +/// The specified access control entry (ACE) contains an invalid condition. +pub const INVALID_ACE_CONDITION = 805; + +/// Access to the specified file handle has been revoked. +pub const FILE_HANDLE_REVOKED = 806; + +/// An image file was mapped at a different address from the one specified in the image file but fixups will still be automatically performed on the image. +pub const IMAGE_AT_DIFFERENT_BASE = 807; + +/// Access to the extended attribute was denied. +pub const EA_ACCESS_DENIED = 994; + +/// The I/O operation has been aborted because of either a thread exit or an application request. +pub const OPERATION_ABORTED = 995; + +/// Overlapped I/O event is not in a signaled state. +pub const IO_INCOMPLETE = 996; + +/// Overlapped I/O operation is in progress. +pub const IO_PENDING = 997; + +/// Invalid access to memory location. +pub const NOACCESS = 998; + +/// Error performing inpage operation. +pub const SWAPERROR = 999; + +/// Recursion too deep; the stack overflowed. +pub const STACK_OVERFLOW = 1001; + +/// The window cannot act on the sent message. +pub const INVALID_MESSAGE = 1002; + +/// Cannot complete this function. +pub const CAN_NOT_COMPLETE = 1003; + +/// Invalid flags. +pub const INVALID_FLAGS = 1004; + +/// The volume does not contain a recognized file system. Please make sure that all required file system drivers are loaded and that the volume is not corrupted. +pub const UNRECOGNIZED_VOLUME = 1005; + +/// The volume for a file has been externally altered so that the opened file is no longer valid. +pub const FILE_INVALID = 1006; + +/// The requested operation cannot be performed in full-screen mode. +pub const FULLSCREEN_MODE = 1007; + +/// An attempt was made to reference a token that does not exist. +pub const NO_TOKEN = 1008; + +/// The configuration registry database is corrupt. +pub const BADDB = 1009; + +/// The configuration registry key is invalid. +pub const BADKEY = 1010; + +/// The configuration registry key could not be opened. +pub const CANTOPEN = 1011; + +/// The configuration registry key could not be read. +pub const CANTREAD = 1012; + +/// The configuration registry key could not be written. +pub const CANTWRITE = 1013; + +/// One of the files in the registry database had to be recovered by use of a log or alternate copy. The recovery was successful. +pub const REGISTRY_RECOVERED = 1014; + +/// The registry is corrupted. The structure of one of the files containing registry data is corrupted, or the system's memory image of the file is corrupted, or the file could not be recovered because the alternate copy or log was absent or corrupted. +pub const REGISTRY_CORRUPT = 1015; + +/// An I/O operation initiated by the registry failed unrecoverably. The registry could not read in, or write out, or flush, one of the files that contain the system's image of the registry. +pub const REGISTRY_IO_FAILED = 1016; + +/// The system has attempted to load or restore a file into the registry, but the specified file is not in a registry file format. +pub const NOT_REGISTRY_FILE = 1017; + +/// Illegal operation attempted on a registry key that has been marked for deletion. +pub const KEY_DELETED = 1018; + +/// System could not allocate the required space in a registry log. +pub const NO_LOG_SPACE = 1019; + +/// Cannot create a symbolic link in a registry key that already has subkeys or values. +pub const KEY_HAS_CHILDREN = 1020; + +/// Cannot create a stable subkey under a volatile parent key. +pub const CHILD_MUST_BE_VOLATILE = 1021; + +/// A notify change request is being completed and the information is not being returned in the caller's buffer. The caller now needs to enumerate the files to find the changes. +pub const NOTIFY_ENUM_DIR = 1022; + +/// A stop control has been sent to a service that other running services are dependent on. +pub const DEPENDENT_SERVICES_RUNNING = 1051; + +/// The requested control is not valid for this service. +pub const INVALID_SERVICE_CONTROL = 1052; + +/// The service did not respond to the start or control request in a timely fashion. +pub const SERVICE_REQUEST_TIMEOUT = 1053; + +/// A thread could not be created for the service. +pub const SERVICE_NO_THREAD = 1054; + +/// The service database is locked. +pub const SERVICE_DATABASE_LOCKED = 1055; + +/// An instance of the service is already running. +pub const SERVICE_ALREADY_RUNNING = 1056; + +/// The account name is invalid or does not exist, or the password is invalid for the account name specified. +pub const INVALID_SERVICE_ACCOUNT = 1057; + +/// The service cannot be started, either because it is disabled or because it has no enabled devices associated with it. +pub const SERVICE_DISABLED = 1058; + +/// Circular service dependency was specified. +pub const CIRCULAR_DEPENDENCY = 1059; + +/// The specified service does not exist as an installed service. +pub const SERVICE_DOES_NOT_EXIST = 1060; + +/// The service cannot accept control messages at this time. +pub const SERVICE_CANNOT_ACCEPT_CTRL = 1061; + +/// The service has not been started. +pub const SERVICE_NOT_ACTIVE = 1062; + +/// The service process could not connect to the service controller. +pub const FAILED_SERVICE_CONTROLLER_CONNECT = 1063; + +/// An exception occurred in the service when handling the control request. +pub const EXCEPTION_IN_SERVICE = 1064; + +/// The database specified does not exist. +pub const DATABASE_DOES_NOT_EXIST = 1065; + +/// The service has returned a service-specific error code. +pub const SERVICE_SPECIFIC_ERROR = 1066; + +/// The process terminated unexpectedly. +pub const PROCESS_ABORTED = 1067; + +/// The dependency service or group failed to start. +pub const SERVICE_DEPENDENCY_FAIL = 1068; + +/// The service did not start due to a logon failure. +pub const SERVICE_LOGON_FAILED = 1069; + +/// After starting, the service hung in a start-pending state. +pub const SERVICE_START_HANG = 1070; + +/// The specified service database lock is invalid. +pub const INVALID_SERVICE_LOCK = 1071; + +/// The specified service has been marked for deletion. +pub const SERVICE_MARKED_FOR_DELETE = 1072; + +/// The specified service already exists. +pub const SERVICE_EXISTS = 1073; + +/// The system is currently running with the last-known-good configuration. +pub const ALREADY_RUNNING_LKG = 1074; + +/// The dependency service does not exist or has been marked for deletion. +pub const SERVICE_DEPENDENCY_DELETED = 1075; + +/// The current boot has already been accepted for use as the last-known-good control set. +pub const BOOT_ALREADY_ACCEPTED = 1076; + +/// No attempts to start the service have been made since the last boot. +pub const SERVICE_NEVER_STARTED = 1077; + +/// The name is already in use as either a service name or a service display name. +pub const DUPLICATE_SERVICE_NAME = 1078; + +/// The account specified for this service is different from the account specified for other services running in the same process. +pub const DIFFERENT_SERVICE_ACCOUNT = 1079; + +/// Failure actions can only be set for Win32 services, not for drivers. +pub const CANNOT_DETECT_DRIVER_FAILURE = 1080; + +/// This service runs in the same process as the service control manager. Therefore, the service control manager cannot take action if this service's process terminates unexpectedly. +pub const CANNOT_DETECT_PROCESS_ABORT = 1081; + +/// No recovery program has been configured for this service. +pub const NO_RECOVERY_PROGRAM = 1082; + +/// The executable program that this service is configured to run in does not implement the service. +pub const SERVICE_NOT_IN_EXE = 1083; + +/// This service cannot be started in Safe Mode. +pub const NOT_SAFEBOOT_SERVICE = 1084; + +/// The physical end of the tape has been reached. +pub const END_OF_MEDIA = 1100; + +/// A tape access reached a filemark. +pub const FILEMARK_DETECTED = 1101; + +/// The beginning of the tape or a partition was encountered. +pub const BEGINNING_OF_MEDIA = 1102; + +/// A tape access reached the end of a set of files. +pub const SETMARK_DETECTED = 1103; + +/// No more data is on the tape. +pub const NO_DATA_DETECTED = 1104; + +/// Tape could not be partitioned. +pub const PARTITION_FAILURE = 1105; + +/// When accessing a new tape of a multivolume partition, the current block size is incorrect. +pub const INVALID_BLOCK_LENGTH = 1106; + +/// Tape partition information could not be found when loading a tape. +pub const DEVICE_NOT_PARTITIONED = 1107; + +/// Unable to lock the media eject mechanism. +pub const UNABLE_TO_LOCK_MEDIA = 1108; + +/// Unable to unload the media. +pub const UNABLE_TO_UNLOAD_MEDIA = 1109; + +/// The media in the drive may have changed. +pub const MEDIA_CHANGED = 1110; + +/// The I/O bus was reset. +pub const BUS_RESET = 1111; + +/// No media in drive. +pub const NO_MEDIA_IN_DRIVE = 1112; + +/// No mapping for the Unicode character exists in the target multi-byte code page. +pub const NO_UNICODE_TRANSLATION = 1113; + +/// A dynamic link library (DLL) initialization routine failed. +pub const DLL_INIT_FAILED = 1114; + +/// A system shutdown is in progress. +pub const SHUTDOWN_IN_PROGRESS = 1115; + +/// Unable to abort the system shutdown because no shutdown was in progress. +pub const NO_SHUTDOWN_IN_PROGRESS = 1116; + +/// The request could not be performed because of an I/O device error. +pub const IO_DEVICE = 1117; + +/// No serial device was successfully initialized. The serial driver will unload. +pub const SERIAL_NO_DEVICE = 1118; + +/// Unable to open a device that was sharing an interrupt request (IRQ) with other devices. At least one other device that uses that IRQ was already opened. +pub const IRQ_BUSY = 1119; + +/// A serial I/O operation was completed by another write to the serial port. The IOCTL_SERIAL_XOFF_COUNTER reached zero.) +pub const MORE_WRITES = 1120; + +/// A serial I/O operation completed because the timeout period expired. The IOCTL_SERIAL_XOFF_COUNTER did not reach zero.) +pub const COUNTER_TIMEOUT = 1121; + +/// No ID address mark was found on the floppy disk. +pub const FLOPPY_ID_MARK_NOT_FOUND = 1122; + +/// Mismatch between the floppy disk sector ID field and the floppy disk controller track address. +pub const FLOPPY_WRONG_CYLINDER = 1123; + +/// The floppy disk controller reported an error that is not recognized by the floppy disk driver. +pub const FLOPPY_UNKNOWN_ERROR = 1124; + +/// The floppy disk controller returned inconsistent results in its registers. +pub const FLOPPY_BAD_REGISTERS = 1125; + +/// While accessing the hard disk, a recalibrate operation failed, even after retries. +pub const DISK_RECALIBRATE_FAILED = 1126; + +/// While accessing the hard disk, a disk operation failed even after retries. +pub const DISK_OPERATION_FAILED = 1127; + +/// While accessing the hard disk, a disk controller reset was needed, but even that failed. +pub const DISK_RESET_FAILED = 1128; + +/// Physical end of tape encountered. +pub const EOM_OVERFLOW = 1129; + +/// Not enough server storage is available to process this command. +pub const NOT_ENOUGH_SERVER_MEMORY = 1130; + +/// A potential deadlock condition has been detected. +pub const POSSIBLE_DEADLOCK = 1131; + +/// The base address or the file offset specified does not have the proper alignment. +pub const MAPPED_ALIGNMENT = 1132; + +/// An attempt to change the system power state was vetoed by another application or driver. +pub const SET_POWER_STATE_VETOED = 1140; + +/// The system BIOS failed an attempt to change the system power state. +pub const SET_POWER_STATE_FAILED = 1141; + +/// An attempt was made to create more links on a file than the file system supports. +pub const TOO_MANY_LINKS = 1142; + +/// The specified program requires a newer version of Windows. +pub const OLD_WIN_VERSION = 1150; + +/// The specified program is not a Windows or MS-DOS program. +pub const APP_WRONG_OS = 1151; + +/// Cannot start more than one instance of the specified program. +pub const SINGLE_INSTANCE_APP = 1152; + +/// The specified program was written for an earlier version of Windows. +pub const RMODE_APP = 1153; + +/// One of the library files needed to run this application is damaged. +pub const INVALID_DLL = 1154; + +/// No application is associated with the specified file for this operation. +pub const NO_ASSOCIATION = 1155; + +/// An error occurred in sending the command to the application. +pub const DDE_FAIL = 1156; + +/// One of the library files needed to run this application cannot be found. +pub const DLL_NOT_FOUND = 1157; + +/// The current process has used all of its system allowance of handles for Window Manager objects. +pub const NO_MORE_USER_HANDLES = 1158; + +/// The message can be used only with synchronous operations. +pub const MESSAGE_SYNC_ONLY = 1159; + +/// The indicated source element has no media. +pub const SOURCE_ELEMENT_EMPTY = 1160; + +/// The indicated destination element already contains media. +pub const DESTINATION_ELEMENT_FULL = 1161; + +/// The indicated element does not exist. +pub const ILLEGAL_ELEMENT_ADDRESS = 1162; + +/// The indicated element is part of a magazine that is not present. +pub const MAGAZINE_NOT_PRESENT = 1163; + +/// The indicated device requires reinitialization due to hardware errors. +pub const DEVICE_REINITIALIZATION_NEEDED = 1164; + +/// The device has indicated that cleaning is required before further operations are attempted. +pub const DEVICE_REQUIRES_CLEANING = 1165; + +/// The device has indicated that its door is open. +pub const DEVICE_DOOR_OPEN = 1166; + +/// The device is not connected. +pub const DEVICE_NOT_CONNECTED = 1167; + +/// Element not found. +pub const NOT_FOUND = 1168; + +/// There was no match for the specified key in the index. +pub const NO_MATCH = 1169; + +/// The property set specified does not exist on the object. +pub const SET_NOT_FOUND = 1170; + +/// The point passed to GetMouseMovePoints is not in the buffer. +pub const POINT_NOT_FOUND = 1171; + +/// The tracking (workstation) service is not running. +pub const NO_TRACKING_SERVICE = 1172; + +/// The Volume ID could not be found. +pub const NO_VOLUME_ID = 1173; + +/// Unable to remove the file to be replaced. +pub const UNABLE_TO_REMOVE_REPLACED = 1175; + +/// Unable to move the replacement file to the file to be replaced. The file to be replaced has retained its original name. +pub const UNABLE_TO_MOVE_REPLACEMENT = 1176; + +/// Unable to move the replacement file to the file to be replaced. The file to be replaced has been renamed using the backup name. +pub const UNABLE_TO_MOVE_REPLACEMENT_2 = 1177; + +/// The volume change journal is being deleted. +pub const JOURNAL_DELETE_IN_PROGRESS = 1178; + +/// The volume change journal is not active. +pub const JOURNAL_NOT_ACTIVE = 1179; + +/// A file was found, but it may not be the correct file. +pub const POTENTIAL_FILE_FOUND = 1180; + +/// The journal entry has been deleted from the journal. +pub const JOURNAL_ENTRY_DELETED = 1181; + +/// A system shutdown has already been scheduled. +pub const SHUTDOWN_IS_SCHEDULED = 1190; + +/// The system shutdown cannot be initiated because there are other users logged on to the computer. +pub const SHUTDOWN_USERS_LOGGED_ON = 1191; + +/// The specified device name is invalid. +pub const BAD_DEVICE = 1200; + +/// The device is not currently connected but it is a remembered connection. +pub const CONNECTION_UNAVAIL = 1201; + +/// The local device name has a remembered connection to another network resource. +pub const DEVICE_ALREADY_REMEMBERED = 1202; + +/// The network path was either typed incorrectly, does not exist, or the network provider is not currently available. Please try retyping the path or contact your network administrator. +pub const NO_NET_OR_BAD_PATH = 1203; + +/// The specified network provider name is invalid. +pub const BAD_PROVIDER = 1204; + +/// Unable to open the network connection profile. +pub const CANNOT_OPEN_PROFILE = 1205; + +/// The network connection profile is corrupted. +pub const BAD_PROFILE = 1206; + +/// Cannot enumerate a noncontainer. +pub const NOT_CONTAINER = 1207; + +/// An extended error has occurred. +pub const EXTENDED_ERROR = 1208; + +/// The format of the specified group name is invalid. +pub const INVALID_GROUPNAME = 1209; + +/// The format of the specified computer name is invalid. +pub const INVALID_COMPUTERNAME = 1210; + +/// The format of the specified event name is invalid. +pub const INVALID_EVENTNAME = 1211; + +/// The format of the specified domain name is invalid. +pub const INVALID_DOMAINNAME = 1212; + +/// The format of the specified service name is invalid. +pub const INVALID_SERVICENAME = 1213; + +/// The format of the specified network name is invalid. +pub const INVALID_NETNAME = 1214; + +/// The format of the specified share name is invalid. +pub const INVALID_SHARENAME = 1215; + +/// The format of the specified password is invalid. +pub const INVALID_PASSWORDNAME = 1216; + +/// The format of the specified message name is invalid. +pub const INVALID_MESSAGENAME = 1217; + +/// The format of the specified message destination is invalid. +pub const INVALID_MESSAGEDEST = 1218; + +/// Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again. +pub const SESSION_CREDENTIAL_CONFLICT = 1219; + +/// An attempt was made to establish a session to a network server, but there are already too many sessions established to that server. +pub const REMOTE_SESSION_LIMIT_EXCEEDED = 1220; + +/// The workgroup or domain name is already in use by another computer on the network. +pub const DUP_DOMAINNAME = 1221; + +/// The network is not present or not started. +pub const NO_NETWORK = 1222; + +/// The operation was canceled by the user. +pub const CANCELLED = 1223; + +/// The requested operation cannot be performed on a file with a user-mapped section open. +pub const USER_MAPPED_FILE = 1224; + +/// The remote computer refused the network connection. +pub const CONNECTION_REFUSED = 1225; + +/// The network connection was gracefully closed. +pub const GRACEFUL_DISCONNECT = 1226; + +/// The network transport endpoint already has an address associated with it. +pub const ADDRESS_ALREADY_ASSOCIATED = 1227; + +/// An address has not yet been associated with the network endpoint. +pub const ADDRESS_NOT_ASSOCIATED = 1228; + +/// An operation was attempted on a nonexistent network connection. +pub const CONNECTION_INVALID = 1229; + +/// An invalid operation was attempted on an active network connection. +pub const CONNECTION_ACTIVE = 1230; + +/// The network location cannot be reached. For information about network troubleshooting, see Windows Help. +pub const NETWORK_UNREACHABLE = 1231; + +/// The network location cannot be reached. For information about network troubleshooting, see Windows Help. +pub const HOST_UNREACHABLE = 1232; + +/// The network location cannot be reached. For information about network troubleshooting, see Windows Help. +pub const PROTOCOL_UNREACHABLE = 1233; + +/// No service is operating at the destination network endpoint on the remote system. +pub const PORT_UNREACHABLE = 1234; + +/// The request was aborted. +pub const REQUEST_ABORTED = 1235; + +/// The network connection was aborted by the local system. +pub const CONNECTION_ABORTED = 1236; + +/// The operation could not be completed. A retry should be performed. +pub const RETRY = 1237; + +/// A connection to the server could not be made because the limit on the number of concurrent connections for this account has been reached. +pub const CONNECTION_COUNT_LIMIT = 1238; + +/// Attempting to log in during an unauthorized time of day for this account. +pub const LOGIN_TIME_RESTRICTION = 1239; + +/// The account is not authorized to log in from this station. +pub const LOGIN_WKSTA_RESTRICTION = 1240; + +/// The network address could not be used for the operation requested. +pub const INCORRECT_ADDRESS = 1241; + +/// The service is already registered. +pub const ALREADY_REGISTERED = 1242; + +/// The specified service does not exist. +pub const SERVICE_NOT_FOUND = 1243; + +/// The operation being requested was not performed because the user has not been authenticated. +pub const NOT_AUTHENTICATED = 1244; + +/// The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist. +pub const NOT_LOGGED_ON = 1245; + +/// Continue with work in progress. +pub const CONTINUE = 1246; + +/// An attempt was made to perform an initialization operation when initialization has already been completed. +pub const ALREADY_INITIALIZED = 1247; + +/// No more local devices. +pub const NO_MORE_DEVICES = 1248; + +/// The specified site does not exist. +pub const NO_SUCH_SITE = 1249; + +/// A domain controller with the specified name already exists. +pub const DOMAIN_CONTROLLER_EXISTS = 1250; + +/// This operation is supported only when you are connected to the server. +pub const ONLY_IF_CONNECTED = 1251; + +/// The group policy framework should call the extension even if there are no changes. +pub const OVERRIDE_NOCHANGES = 1252; + +/// The specified user does not have a valid profile. +pub const BAD_USER_PROFILE = 1253; + +/// This operation is not supported on a computer running Windows Server 2003 for Small Business Server. +pub const NOT_SUPPORTED_ON_SBS = 1254; + +/// The server machine is shutting down. +pub const SERVER_SHUTDOWN_IN_PROGRESS = 1255; + +/// The remote system is not available. For information about network troubleshooting, see Windows Help. +pub const HOST_DOWN = 1256; + +/// The security identifier provided is not from an account domain. +pub const NON_ACCOUNT_SID = 1257; + +/// The security identifier provided does not have a domain component. +pub const NON_DOMAIN_SID = 1258; + +/// AppHelp dialog canceled thus preventing the application from starting. +pub const APPHELP_BLOCK = 1259; + +/// This program is blocked by group policy. For more information, contact your system administrator. +pub const ACCESS_DISABLED_BY_POLICY = 1260; + +/// A program attempt to use an invalid register value. Normally caused by an uninitialized register. This error is Itanium specific. +pub const REG_NAT_CONSUMPTION = 1261; + +/// The share is currently offline or does not exist. +pub const CSCSHARE_OFFLINE = 1262; + +/// The Kerberos protocol encountered an error while validating the KDC certificate during smartcard logon. There is more information in the system event log. +pub const PKINIT_FAILURE = 1263; + +/// The Kerberos protocol encountered an error while attempting to utilize the smartcard subsystem. +pub const SMARTCARD_SUBSYSTEM_FAILURE = 1264; + +/// The system cannot contact a domain controller to service the authentication request. Please try again later. +pub const DOWNGRADE_DETECTED = 1265; + +/// The machine is locked and cannot be shut down without the force option. +pub const MACHINE_LOCKED = 1271; + +/// An application-defined callback gave invalid data when called. +pub const CALLBACK_SUPPLIED_INVALID_DATA = 1273; + +/// The group policy framework should call the extension in the synchronous foreground policy refresh. +pub const SYNC_FOREGROUND_REFRESH_REQUIRED = 1274; + +/// This driver has been blocked from loading. +pub const DRIVER_BLOCKED = 1275; + +/// A dynamic link library (DLL) referenced a module that was neither a DLL nor the process's executable image. +pub const INVALID_IMPORT_OF_NON_DLL = 1276; + +/// Windows cannot open this program since it has been disabled. +pub const ACCESS_DISABLED_WEBBLADE = 1277; + +/// Windows cannot open this program because the license enforcement system has been tampered with or become corrupted. +pub const ACCESS_DISABLED_WEBBLADE_TAMPER = 1278; + +/// A transaction recover failed. +pub const RECOVERY_FAILURE = 1279; + +/// The current thread has already been converted to a fiber. +pub const ALREADY_FIBER = 1280; + +/// The current thread has already been converted from a fiber. +pub const ALREADY_THREAD = 1281; + +/// The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application. +pub const STACK_BUFFER_OVERRUN = 1282; + +/// Data present in one of the parameters is more than the function can operate on. +pub const PARAMETER_QUOTA_EXCEEDED = 1283; + +/// An attempt to do an operation on a debug object failed because the object is in the process of being deleted. +pub const DEBUGGER_INACTIVE = 1284; + +/// An attempt to delay-load a .dll or get a function address in a delay-loaded .dll failed. +pub const DELAY_LOAD_FAILED = 1285; + +/// %1 is a 16-bit application. You do not have permissions to execute 16-bit applications. Check your permissions with your system administrator. +pub const VDM_DISALLOWED = 1286; + +/// Insufficient information exists to identify the cause of failure. +pub const UNIDENTIFIED_ERROR = 1287; + +/// The parameter passed to a C runtime function is incorrect. +pub const INVALID_CRUNTIME_PARAMETER = 1288; + +/// The operation occurred beyond the valid data length of the file. +pub const BEYOND_VDL = 1289; + +/// The service start failed since one or more services in the same process have an incompatible service SID type setting. A service with restricted service SID type can only coexist in the same process with other services with a restricted SID type. If the service SID type for this service was just configured, the hosting process must be restarted in order to start this service. +/// On Windows Server 2003 and Windows XP, an unrestricted service cannot coexist in the same process with other services. The service with the unrestricted service SID type must be moved to an owned process in order to start this service. +pub const INCOMPATIBLE_SERVICE_SID_TYPE = 1290; + +/// The process hosting the driver for this device has been terminated. +pub const DRIVER_PROCESS_TERMINATED = 1291; + +/// An operation attempted to exceed an implementation-defined limit. +pub const IMPLEMENTATION_LIMIT = 1292; + +/// Either the target process, or the target thread's containing process, is a protected process. +pub const PROCESS_IS_PROTECTED = 1293; + +/// The service notification client is lagging too far behind the current state of services in the machine. +pub const SERVICE_NOTIFY_CLIENT_LAGGING = 1294; + +/// The requested file operation failed because the storage quota was exceeded. To free up disk space, move files to a different location or delete unnecessary files. For more information, contact your system administrator. +pub const DISK_QUOTA_EXCEEDED = 1295; + +/// The requested file operation failed because the storage policy blocks that type of file. For more information, contact your system administrator. +pub const CONTENT_BLOCKED = 1296; + +/// A privilege that the service requires to function properly does not exist in the service account configuration. You may use the Services Microsoft Management Console (MMC) snap-in (services.msc) and the Local Security Settings MMC snap-in (secpol.msc) to view the service configuration and the account configuration. +pub const INCOMPATIBLE_SERVICE_PRIVILEGE = 1297; + +/// A thread involved in this operation appears to be unresponsive. +pub const APP_HANG = 1298; + +/// Indicates a particular Security ID may not be assigned as the label of an object. +pub const INVALID_LABEL = 1299; + +/// Not all privileges or groups referenced are assigned to the caller. +pub const NOT_ALL_ASSIGNED = 1300; + +/// Some mapping between account names and security IDs was not done. +pub const SOME_NOT_MAPPED = 1301; + +/// No system quota limits are specifically set for this account. +pub const NO_QUOTAS_FOR_ACCOUNT = 1302; + +/// No encryption key is available. A well-known encryption key was returned. +pub const LOCAL_USER_SESSION_KEY = 1303; + +/// The password is too complex to be converted to a LAN Manager password. The LAN Manager password returned is a NULL string. +pub const NULL_LM_PASSWORD = 1304; + +/// The revision level is unknown. +pub const UNKNOWN_REVISION = 1305; + +/// Indicates two revision levels are incompatible. +pub const REVISION_MISMATCH = 1306; + +/// This security ID may not be assigned as the owner of this object. +pub const INVALID_OWNER = 1307; + +/// This security ID may not be assigned as the primary group of an object. +pub const INVALID_PRIMARY_GROUP = 1308; + +/// An attempt has been made to operate on an impersonation token by a thread that is not currently impersonating a client. +pub const NO_IMPERSONATION_TOKEN = 1309; + +/// The group may not be disabled. +pub const CANT_DISABLE_MANDATORY = 1310; + +/// There are currently no logon servers available to service the logon request. +pub const NO_LOGON_SERVERS = 1311; + +/// A specified logon session does not exist. It may already have been terminated. +pub const NO_SUCH_LOGON_SESSION = 1312; + +/// A specified privilege does not exist. +pub const NO_SUCH_PRIVILEGE = 1313; + +/// A required privilege is not held by the client. +pub const PRIVILEGE_NOT_HELD = 1314; + +/// The name provided is not a properly formed account name. +pub const INVALID_ACCOUNT_NAME = 1315; + +/// The specified account already exists. +pub const USER_EXISTS = 1316; + +/// The specified account does not exist. +pub const NO_SUCH_USER = 1317; + +/// The specified group already exists. +pub const GROUP_EXISTS = 1318; + +/// The specified group does not exist. +pub const NO_SUCH_GROUP = 1319; + +/// Either the specified user account is already a member of the specified group, or the specified group cannot be deleted because it contains a member. +pub const MEMBER_IN_GROUP = 1320; + +/// The specified user account is not a member of the specified group account. +pub const MEMBER_NOT_IN_GROUP = 1321; + +/// This operation is disallowed as it could result in an administration account being disabled, deleted or unable to log on. +pub const LAST_ADMIN = 1322; + +/// Unable to update the password. The value provided as the current password is incorrect. +pub const WRONG_PASSWORD = 1323; + +/// Unable to update the password. The value provided for the new password contains values that are not allowed in passwords. +pub const ILL_FORMED_PASSWORD = 1324; + +/// Unable to update the password. The value provided for the new password does not meet the length, complexity, or history requirements of the domain. +pub const PASSWORD_RESTRICTION = 1325; + +/// The user name or password is incorrect. +pub const LOGON_FAILURE = 1326; + +/// Account restrictions are preventing this user from signing in. For example: blank passwords aren't allowed, sign-in times are limited, or a policy restriction has been enforced. +pub const ACCOUNT_RESTRICTION = 1327; + +/// Your account has time restrictions that keep you from signing in right now. +pub const INVALID_LOGON_HOURS = 1328; + +/// This user isn't allowed to sign in to this computer. +pub const INVALID_WORKSTATION = 1329; + +/// The password for this account has expired. +pub const PASSWORD_EXPIRED = 1330; + +/// This user can't sign in because this account is currently disabled. +pub const ACCOUNT_DISABLED = 1331; + +/// No mapping between account names and security IDs was done. +pub const NONE_MAPPED = 1332; + +/// Too many local user identifiers (LUIDs) were requested at one time. +pub const TOO_MANY_LUIDS_REQUESTED = 1333; + +/// No more local user identifiers (LUIDs) are available. +pub const LUIDS_EXHAUSTED = 1334; + +/// The subauthority part of a security ID is invalid for this particular use. +pub const INVALID_SUB_AUTHORITY = 1335; + +/// The access control list (ACL) structure is invalid. +pub const INVALID_ACL = 1336; + +/// The security ID structure is invalid. +pub const INVALID_SID = 1337; + +/// The security descriptor structure is invalid. +pub const INVALID_SECURITY_DESCR = 1338; + +/// The inherited access control list (ACL) or access control entry (ACE) could not be built. +pub const BAD_INHERITANCE_ACL = 1340; + +/// The server is currently disabled. +pub const SERVER_DISABLED = 1341; + +/// The server is currently enabled. +pub const SERVER_NOT_DISABLED = 1342; + +/// The value provided was an invalid value for an identifier authority. +pub const INVALID_ID_AUTHORITY = 1343; + +/// No more memory is available for security information updates. +pub const ALLOTTED_SPACE_EXCEEDED = 1344; + +/// The specified attributes are invalid, or incompatible with the attributes for the group as a whole. +pub const INVALID_GROUP_ATTRIBUTES = 1345; + +/// Either a required impersonation level was not provided, or the provided impersonation level is invalid. +pub const BAD_IMPERSONATION_LEVEL = 1346; + +/// Cannot open an anonymous level security token. +pub const CANT_OPEN_ANONYMOUS = 1347; + +/// The validation information class requested was invalid. +pub const BAD_VALIDATION_CLASS = 1348; + +/// The type of the token is inappropriate for its attempted use. +pub const BAD_TOKEN_TYPE = 1349; + +/// Unable to perform a security operation on an object that has no associated security. +pub const NO_SECURITY_ON_OBJECT = 1350; + +/// Configuration information could not be read from the domain controller, either because the machine is unavailable, or access has been denied. +pub const CANT_ACCESS_DOMAIN_INFO = 1351; + +/// The security account manager (SAM) or local security authority (LSA) server was in the wrong state to perform the security operation. +pub const INVALID_SERVER_STATE = 1352; + +/// The domain was in the wrong state to perform the security operation. +pub const INVALID_DOMAIN_STATE = 1353; + +/// This operation is only allowed for the Primary Domain Controller of the domain. +pub const INVALID_DOMAIN_ROLE = 1354; + +/// The specified domain either does not exist or could not be contacted. +pub const NO_SUCH_DOMAIN = 1355; + +/// The specified domain already exists. +pub const DOMAIN_EXISTS = 1356; + +/// An attempt was made to exceed the limit on the number of domains per server. +pub const DOMAIN_LIMIT_EXCEEDED = 1357; + +/// Unable to complete the requested operation because of either a catastrophic media failure or a data structure corruption on the disk. +pub const INTERNAL_DB_CORRUPTION = 1358; + +/// An internal error occurred. +pub const INTERNAL_ERROR = 1359; + +/// Generic access types were contained in an access mask which should already be mapped to nongeneric types. +pub const GENERIC_NOT_MAPPED = 1360; + +/// A security descriptor is not in the right format (absolute or self-relative). +pub const BAD_DESCRIPTOR_FORMAT = 1361; + +/// The requested action is restricted for use by logon processes only. The calling process has not registered as a logon process. +pub const NOT_LOGON_PROCESS = 1362; + +/// Cannot start a new logon session with an ID that is already in use. +pub const LOGON_SESSION_EXISTS = 1363; + +/// A specified authentication package is unknown. +pub const NO_SUCH_PACKAGE = 1364; + +/// The logon session is not in a state that is consistent with the requested operation. +pub const BAD_LOGON_SESSION_STATE = 1365; + +/// The logon session ID is already in use. +pub const LOGON_SESSION_COLLISION = 1366; + +/// A logon request contained an invalid logon type value. +pub const INVALID_LOGON_TYPE = 1367; + +/// Unable to impersonate using a named pipe until data has been read from that pipe. +pub const CANNOT_IMPERSONATE = 1368; + +/// The transaction state of a registry subtree is incompatible with the requested operation. +pub const RXACT_INVALID_STATE = 1369; + +/// An internal security database corruption has been encountered. +pub const RXACT_COMMIT_FAILURE = 1370; + +/// Cannot perform this operation on built-in accounts. +pub const SPECIAL_ACCOUNT = 1371; + +/// Cannot perform this operation on this built-in special group. +pub const SPECIAL_GROUP = 1372; + +/// Cannot perform this operation on this built-in special user. +pub const SPECIAL_USER = 1373; + +/// The user cannot be removed from a group because the group is currently the user's primary group. +pub const MEMBERS_PRIMARY_GROUP = 1374; + +/// The token is already in use as a primary token. +pub const TOKEN_ALREADY_IN_USE = 1375; + +/// The specified local group does not exist. +pub const NO_SUCH_ALIAS = 1376; + +/// The specified account name is not a member of the group. +pub const MEMBER_NOT_IN_ALIAS = 1377; + +/// The specified account name is already a member of the group. +pub const MEMBER_IN_ALIAS = 1378; + +/// The specified local group already exists. +pub const ALIAS_EXISTS = 1379; + +/// Logon failure: the user has not been granted the requested logon type at this computer. +pub const LOGON_NOT_GRANTED = 1380; + +/// The maximum number of secrets that may be stored in a single system has been exceeded. +pub const TOO_MANY_SECRETS = 1381; + +/// The length of a secret exceeds the maximum length allowed. +pub const SECRET_TOO_LONG = 1382; + +/// The local security authority database contains an internal inconsistency. +pub const INTERNAL_DB_ERROR = 1383; + +/// During a logon attempt, the user's security context accumulated too many security IDs. +pub const TOO_MANY_CONTEXT_IDS = 1384; + +/// Logon failure: the user has not been granted the requested logon type at this computer. +pub const LOGON_TYPE_NOT_GRANTED = 1385; + +/// A cross-encrypted password is necessary to change a user password. +pub const NT_CROSS_ENCRYPTION_REQUIRED = 1386; + +/// A member could not be added to or removed from the local group because the member does not exist. +pub const NO_SUCH_MEMBER = 1387; + +/// A new member could not be added to a local group because the member has the wrong account type. +pub const INVALID_MEMBER = 1388; + +/// Too many security IDs have been specified. +pub const TOO_MANY_SIDS = 1389; + +/// A cross-encrypted password is necessary to change this user password. +pub const LM_CROSS_ENCRYPTION_REQUIRED = 1390; + +/// Indicates an ACL contains no inheritable components. +pub const NO_INHERITANCE = 1391; + +/// The file or directory is corrupted and unreadable. +pub const FILE_CORRUPT = 1392; + +/// The disk structure is corrupted and unreadable. +pub const DISK_CORRUPT = 1393; + +/// There is no user session key for the specified logon session. +pub const NO_USER_SESSION_KEY = 1394; + +/// The service being accessed is licensed for a particular number of connections. No more connections can be made to the service at this time because there are already as many connections as the service can accept. +pub const LICENSE_QUOTA_EXCEEDED = 1395; + +/// The target account name is incorrect. +pub const WRONG_TARGET_NAME = 1396; + +/// Mutual Authentication failed. The server's password is out of date at the domain controller. +pub const MUTUAL_AUTH_FAILED = 1397; + +/// There is a time and/or date difference between the client and server. +pub const TIME_SKEW = 1398; + +/// This operation cannot be performed on the current domain. +pub const CURRENT_DOMAIN_NOT_ALLOWED = 1399; + +/// Invalid window handle. +pub const INVALID_WINDOW_HANDLE = 1400; + +/// Invalid menu handle. +pub const INVALID_MENU_HANDLE = 1401; + +/// Invalid cursor handle. +pub const INVALID_CURSOR_HANDLE = 1402; + +/// Invalid accelerator table handle. +pub const INVALID_ACCEL_HANDLE = 1403; + +/// Invalid hook handle. +pub const INVALID_HOOK_HANDLE = 1404; + +/// Invalid handle to a multiple-window position structure. +pub const INVALID_DWP_HANDLE = 1405; + +/// Cannot create a top-level child window. +pub const TLW_WITH_WSCHILD = 1406; + +/// Cannot find window class. +pub const CANNOT_FIND_WND_CLASS = 1407; + +/// Invalid window; it belongs to other thread. +pub const WINDOW_OF_OTHER_THREAD = 1408; + +/// Hot key is already registered. +pub const HOTKEY_ALREADY_REGISTERED = 1409; + +/// Class already exists. +pub const CLASS_ALREADY_EXISTS = 1410; + +/// Class does not exist. +pub const CLASS_DOES_NOT_EXIST = 1411; + +/// Class still has open windows. +pub const CLASS_HAS_WINDOWS = 1412; + +/// Invalid index. +pub const INVALID_INDEX = 1413; + +/// Invalid icon handle. +pub const INVALID_ICON_HANDLE = 1414; + +/// Using private DIALOG window words. +pub const PRIVATE_DIALOG_INDEX = 1415; + +/// The list box identifier was not found. +pub const LISTBOX_ID_NOT_FOUND = 1416; + +/// No wildcards were found. +pub const NO_WILDCARD_CHARACTERS = 1417; + +/// Thread does not have a clipboard open. +pub const CLIPBOARD_NOT_OPEN = 1418; + +/// Hot key is not registered. +pub const HOTKEY_NOT_REGISTERED = 1419; + +/// The window is not a valid dialog window. +pub const WINDOW_NOT_DIALOG = 1420; + +/// Control ID not found. +pub const CONTROL_ID_NOT_FOUND = 1421; + +/// Invalid message for a combo box because it does not have an edit control. +pub const INVALID_COMBOBOX_MESSAGE = 1422; + +/// The window is not a combo box. +pub const WINDOW_NOT_COMBOBOX = 1423; + +/// Height must be less than 256. +pub const INVALID_EDIT_HEIGHT = 1424; + +/// Invalid device context (DC) handle. +pub const DC_NOT_FOUND = 1425; + +/// Invalid hook procedure type. +pub const INVALID_HOOK_FILTER = 1426; + +/// Invalid hook procedure. +pub const INVALID_FILTER_PROC = 1427; + +/// Cannot set nonlocal hook without a module handle. +pub const HOOK_NEEDS_HMOD = 1428; + +/// This hook procedure can only be set globally. +pub const GLOBAL_ONLY_HOOK = 1429; + +/// The journal hook procedure is already installed. +pub const JOURNAL_HOOK_SET = 1430; + +/// The hook procedure is not installed. +pub const HOOK_NOT_INSTALLED = 1431; + +/// Invalid message for single-selection list box. +pub const INVALID_LB_MESSAGE = 1432; + +/// LB_SETCOUNT sent to non-lazy list box. +pub const SETCOUNT_ON_BAD_LB = 1433; + +/// This list box does not support tab stops. +pub const LB_WITHOUT_TABSTOPS = 1434; + +/// Cannot destroy object created by another thread. +pub const DESTROY_OBJECT_OF_OTHER_THREAD = 1435; + +/// Child windows cannot have menus. +pub const CHILD_WINDOW_MENU = 1436; + +/// The window does not have a system menu. +pub const NO_SYSTEM_MENU = 1437; + +/// Invalid message box style. +pub const INVALID_MSGBOX_STYLE = 1438; + +/// Invalid system-wide (SPI_*) parameter. +pub const INVALID_SPI_VALUE = 1439; + +/// Screen already locked. +pub const SCREEN_ALREADY_LOCKED = 1440; + +/// All handles to windows in a multiple-window position structure must have the same parent. +pub const HWNDS_HAVE_DIFF_PARENT = 1441; + +/// The window is not a child window. +pub const NOT_CHILD_WINDOW = 1442; + +/// Invalid GW_* command. +pub const INVALID_GW_COMMAND = 1443; + +/// Invalid thread identifier. +pub const INVALID_THREAD_ID = 1444; + +/// Cannot process a message from a window that is not a multiple document interface (MDI) window. +pub const NON_MDICHILD_WINDOW = 1445; + +/// Popup menu already active. +pub const POPUP_ALREADY_ACTIVE = 1446; + +/// The window does not have scroll bars. +pub const NO_SCROLLBARS = 1447; + +/// Scroll bar range cannot be greater than MAXLONG. +pub const INVALID_SCROLLBAR_RANGE = 1448; + +/// Cannot show or remove the window in the way specified. +pub const INVALID_SHOWWIN_COMMAND = 1449; + +/// Insufficient system resources exist to complete the requested service. +pub const NO_SYSTEM_RESOURCES = 1450; + +/// Insufficient system resources exist to complete the requested service. +pub const NONPAGED_SYSTEM_RESOURCES = 1451; + +/// Insufficient system resources exist to complete the requested service. +pub const PAGED_SYSTEM_RESOURCES = 1452; + +/// Insufficient quota to complete the requested service. +pub const WORKING_SET_QUOTA = 1453; + +/// Insufficient quota to complete the requested service. +pub const PAGEFILE_QUOTA = 1454; + +/// The paging file is too small for this operation to complete. +pub const COMMITMENT_LIMIT = 1455; + +/// A menu item was not found. +pub const MENU_ITEM_NOT_FOUND = 1456; + +/// Invalid keyboard layout handle. +pub const INVALID_KEYBOARD_HANDLE = 1457; + +/// Hook type not allowed. +pub const HOOK_TYPE_NOT_ALLOWED = 1458; + +/// This operation requires an interactive window station. +pub const REQUIRES_INTERACTIVE_WINDOWSTATION = 1459; + +/// This operation returned because the timeout period expired. +pub const TIMEOUT = 1460; + +/// Invalid monitor handle. +pub const INVALID_MONITOR_HANDLE = 1461; + +/// Incorrect size argument. +pub const INCORRECT_SIZE = 1462; + +/// The symbolic link cannot be followed because its type is disabled. +pub const SYMLINK_CLASS_DISABLED = 1463; + +/// This application does not support the current operation on symbolic links. +pub const SYMLINK_NOT_SUPPORTED = 1464; + +/// Windows was unable to parse the requested XML data. +pub const XML_PARSE_ERROR = 1465; + +/// An error was encountered while processing an XML digital signature. +pub const XMLDSIG_ERROR = 1466; + +/// This application must be restarted. +pub const RESTART_APPLICATION = 1467; + +/// The caller made the connection request in the wrong routing compartment. +pub const WRONG_COMPARTMENT = 1468; + +/// There was an AuthIP failure when attempting to connect to the remote host. +pub const AUTHIP_FAILURE = 1469; + +/// Insufficient NVRAM resources exist to complete the requested service. A reboot might be required. +pub const NO_NVRAM_RESOURCES = 1470; + +/// Unable to finish the requested operation because the specified process is not a GUI process. +pub const NOT_GUI_PROCESS = 1471; + +/// The event log file is corrupted. +pub const EVENTLOG_FILE_CORRUPT = 1500; + +/// No event log file could be opened, so the event logging service did not start. +pub const EVENTLOG_CANT_START = 1501; + +/// The event log file is full. +pub const LOG_FILE_FULL = 1502; + +/// The event log file has changed between read operations. +pub const EVENTLOG_FILE_CHANGED = 1503; + +/// The specified task name is invalid. +pub const INVALID_TASK_NAME = 1550; + +/// The specified task index is invalid. +pub const INVALID_TASK_INDEX = 1551; + +/// The specified thread is already joining a task. +pub const THREAD_ALREADY_IN_TASK = 1552; + +/// The Windows Installer Service could not be accessed. This can occur if the Windows Installer is not correctly installed. Contact your support personnel for assistance. +pub const INSTALL_SERVICE_FAILURE = 1601; + +/// User cancelled installation. +pub const INSTALL_USEREXIT = 1602; + +/// Fatal error during installation. +pub const INSTALL_FAILURE = 1603; + +/// Installation suspended, incomplete. +pub const INSTALL_SUSPEND = 1604; + +/// This action is only valid for products that are currently installed. +pub const UNKNOWN_PRODUCT = 1605; + +/// Feature ID not registered. +pub const UNKNOWN_FEATURE = 1606; + +/// Component ID not registered. +pub const UNKNOWN_COMPONENT = 1607; + +/// Unknown property. +pub const UNKNOWN_PROPERTY = 1608; + +/// Handle is in an invalid state. +pub const INVALID_HANDLE_STATE = 1609; + +/// The configuration data for this product is corrupt. Contact your support personnel. +pub const BAD_CONFIGURATION = 1610; + +/// Component qualifier not present. +pub const INDEX_ABSENT = 1611; + +/// The installation source for this product is not available. Verify that the source exists and that you can access it. +pub const INSTALL_SOURCE_ABSENT = 1612; + +/// This installation package cannot be installed by the Windows Installer service. You must install a Windows service pack that contains a newer version of the Windows Installer service. +pub const INSTALL_PACKAGE_VERSION = 1613; + +/// Product is uninstalled. +pub const PRODUCT_UNINSTALLED = 1614; + +/// SQL query syntax invalid or unsupported. +pub const BAD_QUERY_SYNTAX = 1615; + +/// Record field does not exist. +pub const INVALID_FIELD = 1616; + +/// The device has been removed. +pub const DEVICE_REMOVED = 1617; + +/// Another installation is already in progress. Complete that installation before proceeding with this install. +pub const INSTALL_ALREADY_RUNNING = 1618; + +/// This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package. +pub const INSTALL_PACKAGE_OPEN_FAILED = 1619; + +/// This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package. +pub const INSTALL_PACKAGE_INVALID = 1620; + +/// There was an error starting the Windows Installer service user interface. Contact your support personnel. +pub const INSTALL_UI_FAILURE = 1621; + +/// Error opening installation log file. Verify that the specified log file location exists and that you can write to it. +pub const INSTALL_LOG_FAILURE = 1622; + +/// The language of this installation package is not supported by your system. +pub const INSTALL_LANGUAGE_UNSUPPORTED = 1623; + +/// Error applying transforms. Verify that the specified transform paths are valid. +pub const INSTALL_TRANSFORM_FAILURE = 1624; + +/// This installation is forbidden by system policy. Contact your system administrator. +pub const INSTALL_PACKAGE_REJECTED = 1625; + +/// Function could not be executed. +pub const FUNCTION_NOT_CALLED = 1626; + +/// Function failed during execution. +pub const FUNCTION_FAILED = 1627; + +/// Invalid or unknown table specified. +pub const INVALID_TABLE = 1628; + +/// Data supplied is of wrong type. +pub const DATATYPE_MISMATCH = 1629; + +/// Data of this type is not supported. +pub const UNSUPPORTED_TYPE = 1630; + +/// The Windows Installer service failed to start. Contact your support personnel. +pub const CREATE_FAILED = 1631; + +/// The Temp folder is on a drive that is full or is inaccessible. Free up space on the drive or verify that you have write permission on the Temp folder. +pub const INSTALL_TEMP_UNWRITABLE = 1632; + +/// This installation package is not supported by this processor type. Contact your product vendor. +pub const INSTALL_PLATFORM_UNSUPPORTED = 1633; + +/// Component not used on this computer. +pub const INSTALL_NOTUSED = 1634; + +/// This update package could not be opened. Verify that the update package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer update package. +pub const PATCH_PACKAGE_OPEN_FAILED = 1635; + +/// This update package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer update package. +pub const PATCH_PACKAGE_INVALID = 1636; + +/// This update package cannot be processed by the Windows Installer service. You must install a Windows service pack that contains a newer version of the Windows Installer service. +pub const PATCH_PACKAGE_UNSUPPORTED = 1637; + +/// Another version of this product is already installed. Installation of this version cannot continue. To configure or remove the existing version of this product, use Add/Remove Programs on the Control Panel. +pub const PRODUCT_VERSION = 1638; + +/// Invalid command line argument. Consult the Windows Installer SDK for detailed command line help. +pub const INVALID_COMMAND_LINE = 1639; + +/// Only administrators have permission to add, remove, or configure server software during a Terminal services remote session. If you want to install or configure software on the server, contact your network administrator. +pub const INSTALL_REMOTE_DISALLOWED = 1640; + +/// The requested operation completed successfully. The system will be restarted so the changes can take effect. +pub const SUCCESS_REBOOT_INITIATED = 1641; + +/// The upgrade cannot be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade. +pub const PATCH_TARGET_NOT_FOUND = 1642; + +/// The update package is not permitted by software restriction policy. +pub const PATCH_PACKAGE_REJECTED = 1643; + +/// One or more customizations are not permitted by software restriction policy. +pub const INSTALL_TRANSFORM_REJECTED = 1644; + +/// The Windows Installer does not permit installation from a Remote Desktop Connection. +pub const INSTALL_REMOTE_PROHIBITED = 1645; + +/// Uninstallation of the update package is not supported. +pub const PATCH_REMOVAL_UNSUPPORTED = 1646; + +/// The update is not applied to this product. +pub const UNKNOWN_PATCH = 1647; + +/// No valid sequence could be found for the set of updates. +pub const PATCH_NO_SEQUENCE = 1648; + +/// Update removal was disallowed by policy. +pub const PATCH_REMOVAL_DISALLOWED = 1649; + +/// The XML update data is invalid. +pub const INVALID_PATCH_XML = 1650; + +/// Windows Installer does not permit updating of managed advertised products. At least one feature of the product must be installed before applying the update. +pub const PATCH_MANAGED_ADVERTISED_PRODUCT = 1651; + +/// The Windows Installer service is not accessible in Safe Mode. Please try again when your computer is not in Safe Mode or you can use System Restore to return your machine to a previous good state. +pub const INSTALL_SERVICE_SAFEBOOT = 1652; + +/// A fail fast exception occurred. Exception handlers will not be invoked and the process will be terminated immediately. +pub const FAIL_FAST_EXCEPTION = 1653; + +/// The app that you are trying to run is not supported on this version of Windows. +pub const INSTALL_REJECTED = 1654; + +/// The string binding is invalid. +pub const RPC_S_INVALID_STRING_BINDING = 1700; + +/// The binding handle is not the correct type. +pub const RPC_S_WRONG_KIND_OF_BINDING = 1701; + +/// The binding handle is invalid. +pub const RPC_S_INVALID_BINDING = 1702; + +/// The RPC protocol sequence is not supported. +pub const RPC_S_PROTSEQ_NOT_SUPPORTED = 1703; + +/// The RPC protocol sequence is invalid. +pub const RPC_S_INVALID_RPC_PROTSEQ = 1704; + +/// The string universal unique identifier (UUID) is invalid. +pub const RPC_S_INVALID_STRING_UUID = 1705; + +/// The endpoint format is invalid. +pub const RPC_S_INVALID_ENDPOINT_FORMAT = 1706; + +/// The network address is invalid. +pub const RPC_S_INVALID_NET_ADDR = 1707; + +/// No endpoint was found. +pub const RPC_S_NO_ENDPOINT_FOUND = 1708; + +/// The timeout value is invalid. +pub const RPC_S_INVALID_TIMEOUT = 1709; + +/// The object universal unique identifier (UUID) was not found. +pub const RPC_S_OBJECT_NOT_FOUND = 1710; + +/// The object universal unique identifier (UUID) has already been registered. +pub const RPC_S_ALREADY_REGISTERED = 1711; + +/// The type universal unique identifier (UUID) has already been registered. +pub const RPC_S_TYPE_ALREADY_REGISTERED = 1712; + +/// The RPC server is already listening. +pub const RPC_S_ALREADY_LISTENING = 1713; + +/// No protocol sequences have been registered. +pub const RPC_S_NO_PROTSEQS_REGISTERED = 1714; + +/// The RPC server is not listening. +pub const RPC_S_NOT_LISTENING = 1715; + +/// The manager type is unknown. +pub const RPC_S_UNKNOWN_MGR_TYPE = 1716; + +/// The interface is unknown. +pub const RPC_S_UNKNOWN_IF = 1717; + +/// There are no bindings. +pub const RPC_S_NO_BINDINGS = 1718; + +/// There are no protocol sequences. +pub const RPC_S_NO_PROTSEQS = 1719; + +/// The endpoint cannot be created. +pub const RPC_S_CANT_CREATE_ENDPOINT = 1720; + +/// Not enough resources are available to complete this operation. +pub const RPC_S_OUT_OF_RESOURCES = 1721; + +/// The RPC server is unavailable. +pub const RPC_S_SERVER_UNAVAILABLE = 1722; + +/// The RPC server is too busy to complete this operation. +pub const RPC_S_SERVER_TOO_BUSY = 1723; + +/// The network options are invalid. +pub const RPC_S_INVALID_NETWORK_OPTIONS = 1724; + +/// There are no remote procedure calls active on this thread. +pub const RPC_S_NO_CALL_ACTIVE = 1725; + +/// The remote procedure call failed. +pub const RPC_S_CALL_FAILED = 1726; + +/// The remote procedure call failed and did not execute. +pub const RPC_S_CALL_FAILED_DNE = 1727; + +/// A remote procedure call (RPC) protocol error occurred. +pub const RPC_S_PROTOCOL_ERROR = 1728; + +/// Access to the HTTP proxy is denied. +pub const RPC_S_PROXY_ACCESS_DENIED = 1729; + +/// The transfer syntax is not supported by the RPC server. +pub const RPC_S_UNSUPPORTED_TRANS_SYN = 1730; + +/// The universal unique identifier (UUID) type is not supported. +pub const RPC_S_UNSUPPORTED_TYPE = 1732; + +/// The tag is invalid. +pub const RPC_S_INVALID_TAG = 1733; + +/// The array bounds are invalid. +pub const RPC_S_INVALID_BOUND = 1734; + +/// The binding does not contain an entry name. +pub const RPC_S_NO_ENTRY_NAME = 1735; + +/// The name syntax is invalid. +pub const RPC_S_INVALID_NAME_SYNTAX = 1736; + +/// The name syntax is not supported. +pub const RPC_S_UNSUPPORTED_NAME_SYNTAX = 1737; + +/// No network address is available to use to construct a universal unique identifier (UUID). +pub const RPC_S_UUID_NO_ADDRESS = 1739; + +/// The endpoint is a duplicate. +pub const RPC_S_DUPLICATE_ENDPOINT = 1740; + +/// The authentication type is unknown. +pub const RPC_S_UNKNOWN_AUTHN_TYPE = 1741; + +/// The maximum number of calls is too small. +pub const RPC_S_MAX_CALLS_TOO_SMALL = 1742; + +/// The string is too long. +pub const RPC_S_STRING_TOO_LONG = 1743; + +/// The RPC protocol sequence was not found. +pub const RPC_S_PROTSEQ_NOT_FOUND = 1744; + +/// The procedure number is out of range. +pub const RPC_S_PROCNUM_OUT_OF_RANGE = 1745; + +/// The binding does not contain any authentication information. +pub const RPC_S_BINDING_HAS_NO_AUTH = 1746; + +/// The authentication service is unknown. +pub const RPC_S_UNKNOWN_AUTHN_SERVICE = 1747; + +/// The authentication level is unknown. +pub const RPC_S_UNKNOWN_AUTHN_LEVEL = 1748; + +/// The security context is invalid. +pub const RPC_S_INVALID_AUTH_IDENTITY = 1749; + +/// The authorization service is unknown. +pub const RPC_S_UNKNOWN_AUTHZ_SERVICE = 1750; + +/// The entry is invalid. +pub const EPT_S_INVALID_ENTRY = 1751; + +/// The server endpoint cannot perform the operation. +pub const EPT_S_CANT_PERFORM_OP = 1752; + +/// There are no more endpoints available from the endpoint mapper. +pub const EPT_S_NOT_REGISTERED = 1753; + +/// No interfaces have been exported. +pub const RPC_S_NOTHING_TO_EXPORT = 1754; + +/// The entry name is incomplete. +pub const RPC_S_INCOMPLETE_NAME = 1755; + +/// The version option is invalid. +pub const RPC_S_INVALID_VERS_OPTION = 1756; + +/// There are no more members. +pub const RPC_S_NO_MORE_MEMBERS = 1757; + +/// There is nothing to unexport. +pub const RPC_S_NOT_ALL_OBJS_UNEXPORTED = 1758; + +/// The interface was not found. +pub const RPC_S_INTERFACE_NOT_FOUND = 1759; + +/// The entry already exists. +pub const RPC_S_ENTRY_ALREADY_EXISTS = 1760; + +/// The entry is not found. +pub const RPC_S_ENTRY_NOT_FOUND = 1761; + +/// The name service is unavailable. +pub const RPC_S_NAME_SERVICE_UNAVAILABLE = 1762; + +/// The network address family is invalid. +pub const RPC_S_INVALID_NAF_ID = 1763; + +/// The requested operation is not supported. +pub const RPC_S_CANNOT_SUPPORT = 1764; + +/// No security context is available to allow impersonation. +pub const RPC_S_NO_CONTEXT_AVAILABLE = 1765; + +/// An internal error occurred in a remote procedure call (RPC). +pub const RPC_S_INTERNAL_ERROR = 1766; + +/// The RPC server attempted an integer division by zero. +pub const RPC_S_ZERO_DIVIDE = 1767; + +/// An addressing error occurred in the RPC server. +pub const RPC_S_ADDRESS_ERROR = 1768; + +/// A floating-point operation at the RPC server caused a division by zero. +pub const RPC_S_FP_DIV_ZERO = 1769; + +/// A floating-point underflow occurred at the RPC server. +pub const RPC_S_FP_UNDERFLOW = 1770; + +/// A floating-point overflow occurred at the RPC server. +pub const RPC_S_FP_OVERFLOW = 1771; + +/// The list of RPC servers available for the binding of auto handles has been exhausted. +pub const RPC_X_NO_MORE_ENTRIES = 1772; + +/// Unable to open the character translation table file. +pub const RPC_X_SS_CHAR_TRANS_OPEN_FAIL = 1773; + +/// The file containing the character translation table has fewer than 512 bytes. +pub const RPC_X_SS_CHAR_TRANS_SHORT_FILE = 1774; + +/// A null context handle was passed from the client to the host during a remote procedure call. +pub const RPC_X_SS_IN_NULL_CONTEXT = 1775; + +/// The context handle changed during a remote procedure call. +pub const RPC_X_SS_CONTEXT_DAMAGED = 1777; + +/// The binding handles passed to a remote procedure call do not match. +pub const RPC_X_SS_HANDLES_MISMATCH = 1778; + +/// The stub is unable to get the remote procedure call handle. +pub const RPC_X_SS_CANNOT_GET_CALL_HANDLE = 1779; + +/// A null reference pointer was passed to the stub. +pub const RPC_X_NULL_REF_POINTER = 1780; + +/// The enumeration value is out of range. +pub const RPC_X_ENUM_VALUE_OUT_OF_RANGE = 1781; + +/// The byte count is too small. +pub const RPC_X_BYTE_COUNT_TOO_SMALL = 1782; + +/// The stub received bad data. +pub const RPC_X_BAD_STUB_DATA = 1783; + +/// The supplied user buffer is not valid for the requested operation. +pub const INVALID_USER_BUFFER = 1784; + +/// The disk media is not recognized. It may not be formatted. +pub const UNRECOGNIZED_MEDIA = 1785; + +/// The workstation does not have a trust secret. +pub const NO_TRUST_LSA_SECRET = 1786; + +/// The security database on the server does not have a computer account for this workstation trust relationship. +pub const NO_TRUST_SAM_ACCOUNT = 1787; + +/// The trust relationship between the primary domain and the trusted domain failed. +pub const TRUSTED_DOMAIN_FAILURE = 1788; + +/// The trust relationship between this workstation and the primary domain failed. +pub const TRUSTED_RELATIONSHIP_FAILURE = 1789; + +/// The network logon failed. +pub const TRUST_FAILURE = 1790; + +/// A remote procedure call is already in progress for this thread. +pub const RPC_S_CALL_IN_PROGRESS = 1791; + +/// An attempt was made to logon, but the network logon service was not started. +pub const NETLOGON_NOT_STARTED = 1792; + +/// The user's account has expired. +pub const ACCOUNT_EXPIRED = 1793; + +/// The redirector is in use and cannot be unloaded. +pub const REDIRECTOR_HAS_OPEN_HANDLES = 1794; + +/// The specified printer driver is already installed. +pub const PRINTER_DRIVER_ALREADY_INSTALLED = 1795; + +/// The specified port is unknown. +pub const UNKNOWN_PORT = 1796; + +/// The printer driver is unknown. +pub const UNKNOWN_PRINTER_DRIVER = 1797; + +/// The print processor is unknown. +pub const UNKNOWN_PRINTPROCESSOR = 1798; + +/// The specified separator file is invalid. +pub const INVALID_SEPARATOR_FILE = 1799; + +/// The specified priority is invalid. +pub const INVALID_PRIORITY = 1800; + +/// The printer name is invalid. +pub const INVALID_PRINTER_NAME = 1801; + +/// The printer already exists. +pub const PRINTER_ALREADY_EXISTS = 1802; + +/// The printer command is invalid. +pub const INVALID_PRINTER_COMMAND = 1803; + +/// The specified datatype is invalid. +pub const INVALID_DATATYPE = 1804; + +/// The environment specified is invalid. +pub const INVALID_ENVIRONMENT = 1805; + +/// There are no more bindings. +pub const RPC_S_NO_MORE_BINDINGS = 1806; + +/// The account used is an interdomain trust account. Use your global user account or local user account to access this server. +pub const NOLOGON_INTERDOMAIN_TRUST_ACCOUNT = 1807; + +/// The account used is a computer account. Use your global user account or local user account to access this server. +pub const NOLOGON_WORKSTATION_TRUST_ACCOUNT = 1808; + +/// The account used is a server trust account. Use your global user account or local user account to access this server. +pub const NOLOGON_SERVER_TRUST_ACCOUNT = 1809; + +/// The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain. +pub const DOMAIN_TRUST_INCONSISTENT = 1810; + +/// The server is in use and cannot be unloaded. +pub const SERVER_HAS_OPEN_HANDLES = 1811; + +/// The specified image file did not contain a resource section. +pub const RESOURCE_DATA_NOT_FOUND = 1812; + +/// The specified resource type cannot be found in the image file. +pub const RESOURCE_TYPE_NOT_FOUND = 1813; + +/// The specified resource name cannot be found in the image file. +pub const RESOURCE_NAME_NOT_FOUND = 1814; + +/// The specified resource language ID cannot be found in the image file. +pub const RESOURCE_LANG_NOT_FOUND = 1815; + +/// Not enough quota is available to process this command. +pub const NOT_ENOUGH_QUOTA = 1816; + +/// No interfaces have been registered. +pub const RPC_S_NO_INTERFACES = 1817; + +/// The remote procedure call was cancelled. +pub const RPC_S_CALL_CANCELLED = 1818; + +/// The binding handle does not contain all required information. +pub const RPC_S_BINDING_INCOMPLETE = 1819; + +/// A communications failure occurred during a remote procedure call. +pub const RPC_S_COMM_FAILURE = 1820; + +/// The requested authentication level is not supported. +pub const RPC_S_UNSUPPORTED_AUTHN_LEVEL = 1821; + +/// No principal name registered. +pub const RPC_S_NO_PRINC_NAME = 1822; + +/// The error specified is not a valid Windows RPC error code. +pub const RPC_S_NOT_RPC_ERROR = 1823; + +/// A UUID that is valid only on this computer has been allocated. +pub const RPC_S_UUID_LOCAL_ONLY = 1824; + +/// A security package specific error occurred. +pub const RPC_S_SEC_PKG_ERROR = 1825; + +/// Thread is not canceled. +pub const RPC_S_NOT_CANCELLED = 1826; + +/// Invalid operation on the encoding/decoding handle. +pub const RPC_X_INVALID_ES_ACTION = 1827; + +/// Incompatible version of the serializing package. +pub const RPC_X_WRONG_ES_VERSION = 1828; + +/// Incompatible version of the RPC stub. +pub const RPC_X_WRONG_STUB_VERSION = 1829; + +/// The RPC pipe object is invalid or corrupted. +pub const RPC_X_INVALID_PIPE_OBJECT = 1830; + +/// An invalid operation was attempted on an RPC pipe object. +pub const RPC_X_WRONG_PIPE_ORDER = 1831; + +/// Unsupported RPC pipe version. +pub const RPC_X_WRONG_PIPE_VERSION = 1832; + +/// HTTP proxy server rejected the connection because the cookie authentication failed. +pub const RPC_S_COOKIE_AUTH_FAILED = 1833; + +/// The group member was not found. +pub const RPC_S_GROUP_MEMBER_NOT_FOUND = 1898; + +/// The endpoint mapper database entry could not be created. +pub const EPT_S_CANT_CREATE = 1899; + +/// The object universal unique identifier (UUID) is the nil UUID. +pub const RPC_S_INVALID_OBJECT = 1900; + +/// The specified time is invalid. +pub const INVALID_TIME = 1901; + +/// The specified form name is invalid. +pub const INVALID_FORM_NAME = 1902; + +/// The specified form size is invalid. +pub const INVALID_FORM_SIZE = 1903; + +/// The specified printer handle is already being waited on. +pub const ALREADY_WAITING = 1904; + +/// The specified printer has been deleted. +pub const PRINTER_DELETED = 1905; + +/// The state of the printer is invalid. +pub const INVALID_PRINTER_STATE = 1906; + +/// The user's password must be changed before signing in. +pub const PASSWORD_MUST_CHANGE = 1907; + +/// Could not find the domain controller for this domain. +pub const DOMAIN_CONTROLLER_NOT_FOUND = 1908; + +/// The referenced account is currently locked out and may not be logged on to. +pub const ACCOUNT_LOCKED_OUT = 1909; + +/// The object exporter specified was not found. +pub const OR_INVALID_OXID = 1910; + +/// The object specified was not found. +pub const OR_INVALID_OID = 1911; + +/// The object resolver set specified was not found. +pub const OR_INVALID_SET = 1912; + +/// Some data remains to be sent in the request buffer. +pub const RPC_S_SEND_INCOMPLETE = 1913; + +/// Invalid asynchronous remote procedure call handle. +pub const RPC_S_INVALID_ASYNC_HANDLE = 1914; + +/// Invalid asynchronous RPC call handle for this operation. +pub const RPC_S_INVALID_ASYNC_CALL = 1915; + +/// The RPC pipe object has already been closed. +pub const RPC_X_PIPE_CLOSED = 1916; + +/// The RPC call completed before all pipes were processed. +pub const RPC_X_PIPE_DISCIPLINE_ERROR = 1917; + +/// No more data is available from the RPC pipe. +pub const RPC_X_PIPE_EMPTY = 1918; + +/// No site name is available for this machine. +pub const NO_SITENAME = 1919; + +/// The file cannot be accessed by the system. +pub const CANT_ACCESS_FILE = 1920; + +/// The name of the file cannot be resolved by the system. +pub const CANT_RESOLVE_FILENAME = 1921; + +/// The entry is not of the expected type. +pub const RPC_S_ENTRY_TYPE_MISMATCH = 1922; + +/// Not all object UUIDs could be exported to the specified entry. +pub const RPC_S_NOT_ALL_OBJS_EXPORTED = 1923; + +/// Interface could not be exported to the specified entry. +pub const RPC_S_INTERFACE_NOT_EXPORTED = 1924; + +/// The specified profile entry could not be added. +pub const RPC_S_PROFILE_NOT_ADDED = 1925; + +/// The specified profile element could not be added. +pub const RPC_S_PRF_ELT_NOT_ADDED = 1926; + +/// The specified profile element could not be removed. +pub const RPC_S_PRF_ELT_NOT_REMOVED = 1927; + +/// The group element could not be added. +pub const RPC_S_GRP_ELT_NOT_ADDED = 1928; + +/// The group element could not be removed. +pub const RPC_S_GRP_ELT_NOT_REMOVED = 1929; + +/// The printer driver is not compatible with a policy enabled on your computer that blocks NT 4.0 drivers. +pub const KM_DRIVER_BLOCKED = 1930; + +/// The context has expired and can no longer be used. +pub const CONTEXT_EXPIRED = 1931; + +/// The current user's delegated trust creation quota has been exceeded. +pub const PER_USER_TRUST_QUOTA_EXCEEDED = 1932; + +/// The total delegated trust creation quota has been exceeded. +pub const ALL_USER_TRUST_QUOTA_EXCEEDED = 1933; + +/// The current user's delegated trust deletion quota has been exceeded. +pub const USER_DELETE_TRUST_QUOTA_EXCEEDED = 1934; + +/// The computer you are signing into is protected by an authentication firewall. The specified account is not allowed to authenticate to the computer. +pub const AUTHENTICATION_FIREWALL_FAILED = 1935; + +/// Remote connections to the Print Spooler are blocked by a policy set on your machine. +pub const REMOTE_PRINT_CONNECTIONS_BLOCKED = 1936; + +/// Authentication failed because NTLM authentication has been disabled. +pub const NTLM_BLOCKED = 1937; + +/// Logon Failure: EAS policy requires that the user change their password before this operation can be performed. +pub const PASSWORD_CHANGE_REQUIRED = 1938; + +/// The pixel format is invalid. +pub const INVALID_PIXEL_FORMAT = 2000; + +/// The specified driver is invalid. +pub const BAD_DRIVER = 2001; + +/// The window style or class attribute is invalid for this operation. +pub const INVALID_WINDOW_STYLE = 2002; + +/// The requested metafile operation is not supported. +pub const METAFILE_NOT_SUPPORTED = 2003; + +/// The requested transformation operation is not supported. +pub const TRANSFORM_NOT_SUPPORTED = 2004; + +/// The requested clipping operation is not supported. +pub const CLIPPING_NOT_SUPPORTED = 2005; + +/// The specified color management module is invalid. +pub const INVALID_CMM = 2010; + +/// The specified color profile is invalid. +pub const INVALID_PROFILE = 2011; + +/// The specified tag was not found. +pub const TAG_NOT_FOUND = 2012; + +/// A required tag is not present. +pub const TAG_NOT_PRESENT = 2013; + +/// The specified tag is already present. +pub const DUPLICATE_TAG = 2014; + +/// The specified color profile is not associated with the specified device. +pub const PROFILE_NOT_ASSOCIATED_WITH_DEVICE = 2015; + +/// The specified color profile was not found. +pub const PROFILE_NOT_FOUND = 2016; + +/// The specified color space is invalid. +pub const INVALID_COLORSPACE = 2017; + +/// Image Color Management is not enabled. +pub const ICM_NOT_ENABLED = 2018; + +/// There was an error while deleting the color transform. +pub const DELETING_ICM_XFORM = 2019; + +/// The specified color transform is invalid. +pub const INVALID_TRANSFORM = 2020; + +/// The specified transform does not match the bitmap's color space. +pub const COLORSPACE_MISMATCH = 2021; + +/// The specified named color index is not present in the profile. +pub const INVALID_COLORINDEX = 2022; + +/// The specified profile is intended for a device of a different type than the specified device. +pub const PROFILE_DOES_NOT_MATCH_DEVICE = 2023; + +/// The network connection was made successfully, but the user had to be prompted for a password other than the one originally specified. +pub const CONNECTED_OTHER_PASSWORD = 2108; + +/// The network connection was made successfully using default credentials. +pub const CONNECTED_OTHER_PASSWORD_DEFAULT = 2109; + +/// The specified username is invalid. +pub const BAD_USERNAME = 2202; + +/// This network connection does not exist. +pub const NOT_CONNECTED = 2250; + +/// This network connection has files open or requests pending. +pub const OPEN_FILES = 2401; + +/// Active connections still exist. +pub const ACTIVE_CONNECTIONS = 2402; + +/// The device is in use by an active process and cannot be disconnected. +pub const DEVICE_IN_USE = 2404; + +/// The specified print monitor is unknown. +pub const UNKNOWN_PRINT_MONITOR = 3000; + +/// The specified printer driver is currently in use. +pub const PRINTER_DRIVER_IN_USE = 3001; + +/// The spool file was not found. +pub const SPOOL_FILE_NOT_FOUND = 3002; + +/// A StartDocPrinter call was not issued. +pub const SPL_NO_STARTDOC = 3003; + +/// An AddJob call was not issued. +pub const SPL_NO_ADDJOB = 3004; + +/// The specified print processor has already been installed. +pub const PRINT_PROCESSOR_ALREADY_INSTALLED = 3005; + +/// The specified print monitor has already been installed. +pub const PRINT_MONITOR_ALREADY_INSTALLED = 3006; + +/// The specified print monitor does not have the required functions. +pub const INVALID_PRINT_MONITOR = 3007; + +/// The specified print monitor is currently in use. +pub const PRINT_MONITOR_IN_USE = 3008; + +/// The requested operation is not allowed when there are jobs queued to the printer. +pub const PRINTER_HAS_JOBS_QUEUED = 3009; + +/// The requested operation is successful. Changes will not be effective until the system is rebooted. +pub const SUCCESS_REBOOT_REQUIRED = 3010; + +/// The requested operation is successful. Changes will not be effective until the service is restarted. +pub const SUCCESS_RESTART_REQUIRED = 3011; + +/// No printers were found. +pub const PRINTER_NOT_FOUND = 3012; + +/// The printer driver is known to be unreliable. +pub const PRINTER_DRIVER_WARNED = 3013; + +/// The printer driver is known to harm the system. +pub const PRINTER_DRIVER_BLOCKED = 3014; + +/// The specified printer driver package is currently in use. +pub const PRINTER_DRIVER_PACKAGE_IN_USE = 3015; + +/// Unable to find a core driver package that is required by the printer driver package. +pub const CORE_DRIVER_PACKAGE_NOT_FOUND = 3016; + +/// The requested operation failed. A system reboot is required to roll back changes made. +pub const FAIL_REBOOT_REQUIRED = 3017; + +/// The requested operation failed. A system reboot has been initiated to roll back changes made. +pub const FAIL_REBOOT_INITIATED = 3018; + +/// The specified printer driver was not found on the system and needs to be downloaded. +pub const PRINTER_DRIVER_DOWNLOAD_NEEDED = 3019; + +/// The requested print job has failed to print. A print system update requires the job to be resubmitted. +pub const PRINT_JOB_RESTART_REQUIRED = 3020; + +/// The printer driver does not contain a valid manifest, or contains too many manifests. +pub const INVALID_PRINTER_DRIVER_MANIFEST = 3021; + +/// The specified printer cannot be shared. +pub const PRINTER_NOT_SHAREABLE = 3022; + +/// The operation was paused. +pub const REQUEST_PAUSED = 3050; + +/// Reissue the given operation as a cached IO operation. +pub const IO_REISSUE_AS_CACHED = 3950; diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig new file mode 100644 index 0000000000..2ae73ad45a --- /dev/null +++ b/lib/std/os/windows/kernel32.zig @@ -0,0 +1,214 @@ +usingnamespace @import("bits.zig"); + +pub extern "kernel32" stdcallcc fn AddVectoredExceptionHandler(First: c_ulong, Handler: ?VECTORED_EXCEPTION_HANDLER) ?*c_void; +pub extern "kernel32" stdcallcc fn RemoveVectoredExceptionHandler(Handle: HANDLE) c_ulong; + +pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) BOOL; + +pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL; + +pub extern "kernel32" stdcallcc fn CreateDirectoryW(lpPathName: [*]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) BOOL; + +pub extern "kernel32" stdcallcc fn CreateFileW( + lpFileName: [*]const u16, // TODO null terminated pointer type + dwDesiredAccess: DWORD, + dwShareMode: DWORD, + lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, + dwCreationDisposition: DWORD, + dwFlagsAndAttributes: DWORD, + hTemplateFile: ?HANDLE, +) HANDLE; + +pub extern "kernel32" stdcallcc fn CreatePipe( + hReadPipe: *HANDLE, + hWritePipe: *HANDLE, + lpPipeAttributes: *const SECURITY_ATTRIBUTES, + nSize: DWORD, +) BOOL; + +pub extern "kernel32" stdcallcc fn CreateProcessW( + lpApplicationName: ?LPWSTR, + lpCommandLine: LPWSTR, + lpProcessAttributes: ?*SECURITY_ATTRIBUTES, + lpThreadAttributes: ?*SECURITY_ATTRIBUTES, + bInheritHandles: BOOL, + dwCreationFlags: DWORD, + lpEnvironment: ?*c_void, + lpCurrentDirectory: ?LPWSTR, + lpStartupInfo: *STARTUPINFOW, + lpProcessInformation: *PROCESS_INFORMATION, +) BOOL; + +pub extern "kernel32" stdcallcc fn CreateSymbolicLinkW(lpSymlinkFileName: [*]const u16, lpTargetFileName: [*]const u16, dwFlags: DWORD) BOOLEAN; + +pub extern "kernel32" stdcallcc fn CreateIoCompletionPort(FileHandle: HANDLE, ExistingCompletionPort: ?HANDLE, CompletionKey: ULONG_PTR, NumberOfConcurrentThreads: DWORD) ?HANDLE; + +pub extern "kernel32" stdcallcc fn CreateThread(lpThreadAttributes: ?LPSECURITY_ATTRIBUTES, dwStackSize: SIZE_T, lpStartAddress: LPTHREAD_START_ROUTINE, lpParameter: ?LPVOID, dwCreationFlags: DWORD, lpThreadId: ?LPDWORD) ?HANDLE; + +pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*]const u16) BOOL; + +pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) noreturn; + +pub extern "kernel32" stdcallcc fn FindFirstFileW(lpFileName: [*]const u16, lpFindFileData: *WIN32_FIND_DATAW) HANDLE; +pub extern "kernel32" stdcallcc fn FindClose(hFindFile: HANDLE) BOOL; +pub extern "kernel32" stdcallcc fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) BOOL; + +pub extern "kernel32" stdcallcc fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list) DWORD; + +pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsW(penv: [*]u16) BOOL; + +pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR; + +pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: *DWORD) BOOL; + +pub extern "kernel32" stdcallcc fn GetConsoleScreenBufferInfo(hConsoleOutput: HANDLE, lpConsoleScreenBufferInfo: *CONSOLE_SCREEN_BUFFER_INFO) BOOL; + +pub extern "kernel32" stdcallcc fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: ?[*]WCHAR) DWORD; + +pub extern "kernel32" stdcallcc fn GetCurrentThread() HANDLE; +pub extern "kernel32" stdcallcc fn GetCurrentThreadId() DWORD; + +pub extern "kernel32" stdcallcc fn GetEnvironmentStringsW() ?[*]u16; + +pub extern "kernel32" stdcallcc fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) DWORD; + +pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) BOOL; + +pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: *LARGE_INTEGER) BOOL; + +pub extern "kernel32" stdcallcc fn GetFileAttributesW(lpFileName: [*]const WCHAR) DWORD; + +pub extern "kernel32" stdcallcc fn GetModuleFileNameW(hModule: ?HMODULE, lpFilename: [*]u16, nSize: DWORD) DWORD; + +pub extern "kernel32" stdcallcc fn GetModuleHandleW(lpModuleName: ?[*]const WCHAR) HMODULE; + +pub extern "kernel32" stdcallcc fn GetLastError() DWORD; + +pub extern "kernel32" stdcallcc fn GetFileInformationByHandle( + hFile: HANDLE, + lpFileInformation: *BY_HANDLE_FILE_INFORMATION, +) BOOL; + +pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx( + in_hFile: HANDLE, + in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, + out_lpFileInformation: *c_void, + in_dwBufferSize: DWORD, +) BOOL; + +pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleW( + hFile: HANDLE, + lpszFilePath: [*]u16, + cchFilePath: DWORD, + dwFlags: DWORD, +) DWORD; + +pub extern "kernel32" stdcallcc fn GetOverlappedResult(hFile: HANDLE, lpOverlapped: *OVERLAPPED, lpNumberOfBytesTransferred: *DWORD, bWait: BOOL) BOOL; + +pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE; +pub extern "kernel32" stdcallcc fn GetQueuedCompletionStatus(CompletionPort: HANDLE, lpNumberOfBytesTransferred: LPDWORD, lpCompletionKey: *ULONG_PTR, lpOverlapped: *?*OVERLAPPED, dwMilliseconds: DWORD) BOOL; + +pub extern "kernel32" stdcallcc fn GetSystemInfo(lpSystemInfo: *SYSTEM_INFO) void; +pub extern "kernel32" stdcallcc fn GetSystemTimeAsFileTime(*FILETIME) void; + +pub extern "kernel32" stdcallcc fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) ?HANDLE; +pub extern "kernel32" stdcallcc fn HeapDestroy(hHeap: HANDLE) BOOL; +pub extern "kernel32" stdcallcc fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void, dwBytes: SIZE_T) ?*c_void; +pub extern "kernel32" stdcallcc fn HeapSize(hHeap: HANDLE, dwFlags: DWORD, lpMem: *const c_void) SIZE_T; +pub extern "kernel32" stdcallcc fn HeapCompact(hHeap: HANDLE, dwFlags: DWORD) SIZE_T; +pub extern "kernel32" stdcallcc fn HeapSummary(hHeap: HANDLE, dwFlags: DWORD, lpSummary: LPHEAP_SUMMARY) BOOL; + +pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) ?HANDLE; + +pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) ?*c_void; + +pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void) BOOL; + +pub extern "kernel32" stdcallcc fn HeapValidate(hHeap: HANDLE, dwFlags: DWORD, lpMem: ?*const c_void) BOOL; + +pub extern "kernel32" stdcallcc fn VirtualAlloc(lpAddress: ?LPVOID, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD) ?LPVOID; +pub extern "kernel32" stdcallcc fn VirtualFree(lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) BOOL; + +pub extern "kernel32" stdcallcc fn MoveFileExW( + lpExistingFileName: [*]const u16, + lpNewFileName: [*]const u16, + dwFlags: DWORD, +) BOOL; + +pub extern "kernel32" stdcallcc fn PostQueuedCompletionStatus(CompletionPort: HANDLE, dwNumberOfBytesTransferred: DWORD, dwCompletionKey: ULONG_PTR, lpOverlapped: ?*OVERLAPPED) BOOL; + +pub extern "kernel32" stdcallcc fn QueryPerformanceCounter(lpPerformanceCount: *LARGE_INTEGER) BOOL; + +pub extern "kernel32" stdcallcc fn QueryPerformanceFrequency(lpFrequency: *LARGE_INTEGER) BOOL; + +pub extern "kernel32" stdcallcc fn ReadDirectoryChangesW( + hDirectory: HANDLE, + lpBuffer: [*]align(@alignOf(FILE_NOTIFY_INFORMATION)) u8, + nBufferLength: DWORD, + bWatchSubtree: BOOL, + dwNotifyFilter: DWORD, + lpBytesReturned: ?*DWORD, + lpOverlapped: ?*OVERLAPPED, + lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE, +) BOOL; + +pub extern "kernel32" stdcallcc fn ReadFile( + in_hFile: HANDLE, + out_lpBuffer: [*]u8, + in_nNumberOfBytesToRead: DWORD, + out_lpNumberOfBytesRead: ?*DWORD, + in_out_lpOverlapped: ?*OVERLAPPED, +) BOOL; + +pub extern "kernel32" stdcallcc fn RemoveDirectoryW(lpPathName: [*]const u16) BOOL; + +pub extern "kernel32" stdcallcc fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) BOOL; + +pub extern "kernel32" stdcallcc fn SetFilePointerEx( + in_fFile: HANDLE, + in_liDistanceToMove: LARGE_INTEGER, + out_opt_ldNewFilePointer: ?*LARGE_INTEGER, + in_dwMoveMethod: DWORD, +) BOOL; + +pub extern "kernel32" stdcallcc fn SetFileTime( + hFile: HANDLE, + lpCreationTime: ?*const FILETIME, + lpLastAccessTime: ?*const FILETIME, + lpLastWriteTime: ?*const FILETIME, +) BOOL; + +pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) BOOL; + +pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD) void; + +pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) BOOL; + +pub extern "kernel32" stdcallcc fn TlsAlloc() DWORD; + +pub extern "kernel32" stdcallcc fn TlsFree(dwTlsIndex: DWORD) BOOL; + +pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) DWORD; + +pub extern "kernel32" stdcallcc fn WriteFile( + in_hFile: HANDLE, + in_lpBuffer: [*]const u8, + in_nNumberOfBytesToWrite: DWORD, + out_lpNumberOfBytesWritten: ?*DWORD, + in_out_lpOverlapped: ?*OVERLAPPED, +) BOOL; + +pub extern "kernel32" stdcallcc fn WriteFileEx(hFile: HANDLE, lpBuffer: [*]const u8, nNumberOfBytesToWrite: DWORD, lpOverlapped: LPOVERLAPPED, lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE) BOOL; + +pub extern "kernel32" stdcallcc fn LoadLibraryW(lpLibFileName: [*]const u16) ?HMODULE; + +pub extern "kernel32" stdcallcc fn GetProcAddress(hModule: HMODULE, lpProcName: [*]const u8) ?FARPROC; + +pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) BOOL; + +pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void; +pub extern "kernel32" stdcallcc fn EnterCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void; +pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void; +pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void; + +pub extern "kernel32" stdcallcc fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*c_void, Context: ?*c_void) BOOL; diff --git a/lib/std/os/windows/lang.zig b/lib/std/os/windows/lang.zig new file mode 100644 index 0000000000..b173a62a73 --- /dev/null +++ b/lib/std/os/windows/lang.zig @@ -0,0 +1,140 @@ +pub const NEUTRAL = 0x00; +pub const INVARIANT = 0x7f; +pub const AFRIKAANS = 0x36; +pub const ALBANIAN = 0x1c; +pub const ALSATIAN = 0x84; +pub const AMHARIC = 0x5e; +pub const ARABIC = 0x01; +pub const ARMENIAN = 0x2b; +pub const ASSAMESE = 0x4d; +pub const AZERI = 0x2c; +pub const AZERBAIJANI = 0x2c; +pub const BANGLA = 0x45; +pub const BASHKIR = 0x6d; +pub const BASQUE = 0x2d; +pub const BELARUSIAN = 0x23; +pub const BENGALI = 0x45; +pub const BRETON = 0x7e; +pub const BOSNIAN = 0x1a; +pub const BOSNIAN_NEUTRAL = 0x781a; +pub const BULGARIAN = 0x02; +pub const CATALAN = 0x03; +pub const CENTRAL_KURDISH = 0x92; +pub const CHEROKEE = 0x5c; +pub const CHINESE = 0x04; +pub const CHINESE_SIMPLIFIED = 0x04; +pub const CHINESE_TRADITIONAL = 0x7c04; +pub const CORSICAN = 0x83; +pub const CROATIAN = 0x1a; +pub const CZECH = 0x05; +pub const DANISH = 0x06; +pub const DARI = 0x8c; +pub const DIVEHI = 0x65; +pub const DUTCH = 0x13; +pub const ENGLISH = 0x09; +pub const ESTONIAN = 0x25; +pub const FAEROESE = 0x38; +pub const FARSI = 0x29; +pub const FILIPINO = 0x64; +pub const FINNISH = 0x0b; +pub const FRENCH = 0x0c; +pub const FRISIAN = 0x62; +pub const FULAH = 0x67; +pub const GALICIAN = 0x56; +pub const GEORGIAN = 0x37; +pub const GERMAN = 0x07; +pub const GREEK = 0x08; +pub const GREENLANDIC = 0x6f; +pub const GUJARATI = 0x47; +pub const HAUSA = 0x68; +pub const HAWAIIAN = 0x75; +pub const HEBREW = 0x0d; +pub const HINDI = 0x39; +pub const HUNGARIAN = 0x0e; +pub const ICELANDIC = 0x0f; +pub const IGBO = 0x70; +pub const INDONESIAN = 0x21; +pub const INUKTITUT = 0x5d; +pub const IRISH = 0x3c; +pub const ITALIAN = 0x10; +pub const JAPANESE = 0x11; +pub const KANNADA = 0x4b; +pub const KASHMIRI = 0x60; +pub const KAZAK = 0x3f; +pub const KHMER = 0x53; +pub const KICHE = 0x86; +pub const KINYARWANDA = 0x87; +pub const KONKANI = 0x57; +pub const KOREAN = 0x12; +pub const KYRGYZ = 0x40; +pub const LAO = 0x54; +pub const LATVIAN = 0x26; +pub const LITHUANIAN = 0x27; +pub const LOWER_SORBIAN = 0x2e; +pub const LUXEMBOURGISH = 0x6e; +pub const MACEDONIAN = 0x2f; +pub const MALAY = 0x3e; +pub const MALAYALAM = 0x4c; +pub const MALTESE = 0x3a; +pub const MANIPURI = 0x58; +pub const MAORI = 0x81; +pub const MAPUDUNGUN = 0x7a; +pub const MARATHI = 0x4e; +pub const MOHAWK = 0x7c; +pub const MONGOLIAN = 0x50; +pub const NEPALI = 0x61; +pub const NORWEGIAN = 0x14; +pub const OCCITAN = 0x82; +pub const ODIA = 0x48; +pub const ORIYA = 0x48; +pub const PASHTO = 0x63; +pub const PERSIAN = 0x29; +pub const POLISH = 0x15; +pub const PORTUGUESE = 0x16; +pub const PULAR = 0x67; +pub const PUNJABI = 0x46; +pub const QUECHUA = 0x6b; +pub const ROMANIAN = 0x18; +pub const ROMANSH = 0x17; +pub const RUSSIAN = 0x19; +pub const SAKHA = 0x85; +pub const SAMI = 0x3b; +pub const SANSKRIT = 0x4f; +pub const SCOTTISH_GAELIC = 0x91; +pub const SERBIAN = 0x1a; +pub const SERBIAN_NEUTRAL = 0x7c1a; +pub const SINDHI = 0x59; +pub const SINHALESE = 0x5b; +pub const SLOVAK = 0x1b; +pub const SLOVENIAN = 0x24; +pub const SOTHO = 0x6c; +pub const SPANISH = 0x0a; +pub const SWAHILI = 0x41; +pub const SWEDISH = 0x1d; +pub const SYRIAC = 0x5a; +pub const TAJIK = 0x28; +pub const TAMAZIGHT = 0x5f; +pub const TAMIL = 0x49; +pub const TATAR = 0x44; +pub const TELUGU = 0x4a; +pub const THAI = 0x1e; +pub const TIBETAN = 0x51; +pub const TIGRIGNA = 0x73; +pub const TIGRINYA = 0x73; +pub const TSWANA = 0x32; +pub const TURKISH = 0x1f; +pub const TURKMEN = 0x42; +pub const UIGHUR = 0x80; +pub const UKRAINIAN = 0x22; +pub const UPPER_SORBIAN = 0x2e; +pub const URDU = 0x20; +pub const UZBEK = 0x43; +pub const VALENCIAN = 0x03; +pub const VIETNAMESE = 0x2a; +pub const WELSH = 0x52; +pub const WOLOF = 0x88; +pub const XHOSA = 0x34; +pub const YAKUT = 0x85; +pub const YI = 0x78; +pub const YORUBA = 0x6a; +pub const ZULU = 0x35; diff --git a/lib/std/os/windows/ntdll.zig b/lib/std/os/windows/ntdll.zig new file mode 100644 index 0000000000..bfc98aba8a --- /dev/null +++ b/lib/std/os/windows/ntdll.zig @@ -0,0 +1,24 @@ +usingnamespace @import("bits.zig"); + +pub extern "NtDll" stdcallcc fn RtlCaptureStackBackTrace(FramesToSkip: DWORD, FramesToCapture: DWORD, BackTrace: **c_void, BackTraceHash: ?*DWORD) WORD; +pub extern "NtDll" stdcallcc fn NtQueryInformationFile( + FileHandle: HANDLE, + IoStatusBlock: *IO_STATUS_BLOCK, + FileInformation: *c_void, + Length: ULONG, + FileInformationClass: FILE_INFORMATION_CLASS, +) NTSTATUS; +pub extern "NtDll" stdcallcc fn NtCreateFile( + FileHandle: *HANDLE, + DesiredAccess: ACCESS_MASK, + ObjectAttributes: *OBJECT_ATTRIBUTES, + IoStatusBlock: *IO_STATUS_BLOCK, + AllocationSize: *LARGE_INTEGER, + FileAttributes: ULONG, + ShareAccess: ULONG, + CreateDisposition: ULONG, + CreateOptions: ULONG, + EaBuffer: *c_void, + EaLength: ULONG, +) NTSTATUS; +pub extern "NtDll" stdcallcc fn NtClose(Handle: HANDLE) NTSTATUS; diff --git a/lib/std/os/windows/ole32.zig b/lib/std/os/windows/ole32.zig new file mode 100644 index 0000000000..39c12d074c --- /dev/null +++ b/lib/std/os/windows/ole32.zig @@ -0,0 +1,6 @@ +usingnamespace @import("bits.zig"); + +pub extern "ole32" stdcallcc fn CoTaskMemFree(pv: LPVOID) void; +pub extern "ole32" stdcallcc fn CoUninitialize() void; +pub extern "ole32" stdcallcc fn CoGetCurrentProcess() DWORD; +pub extern "ole32" stdcallcc fn CoInitializeEx(pvReserved: LPVOID, dwCoInit: DWORD) HRESULT; diff --git a/lib/std/os/windows/shell32.zig b/lib/std/os/windows/shell32.zig new file mode 100644 index 0000000000..c178997aad --- /dev/null +++ b/lib/std/os/windows/shell32.zig @@ -0,0 +1,3 @@ +usingnamespace @import("bits.zig"); + +pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT; diff --git a/lib/std/os/windows/status.zig b/lib/std/os/windows/status.zig new file mode 100644 index 0000000000..b9fd2b495f --- /dev/null +++ b/lib/std/os/windows/status.zig @@ -0,0 +1,5 @@ +/// The operation completed successfully. +pub const SUCCESS = 0x00000000; + +/// The data was too large to fit into the specified buffer. +pub const BUFFER_OVERFLOW = 0x80000005; diff --git a/lib/std/os/windows/sublang.zig b/lib/std/os/windows/sublang.zig new file mode 100644 index 0000000000..e9929c6d79 --- /dev/null +++ b/lib/std/os/windows/sublang.zig @@ -0,0 +1,244 @@ +pub const NEUTRAL = 0x00; +pub const DEFAULT = 0x01; +pub const SYS_DEFAULT = 0x02; +pub const CUSTOM_DEFAULT = 0x03; +pub const CUSTOM_UNSPECIFIED = 0x04; +pub const UI_CUSTOM_DEFAULT = 0x05; +pub const AFRIKAANS_SOUTH_AFRICA = 0x01; +pub const ALBANIAN_ALBANIA = 0x01; +pub const ALSATIAN_FRANCE = 0x01; +pub const AMHARIC_ETHIOPIA = 0x01; +pub const ARABIC_SAUDI_ARABIA = 0x01; +pub const ARABIC_IRAQ = 0x02; +pub const ARABIC_EGYPT = 0x03; +pub const ARABIC_LIBYA = 0x04; +pub const ARABIC_ALGERIA = 0x05; +pub const ARABIC_MOROCCO = 0x06; +pub const ARABIC_TUNISIA = 0x07; +pub const ARABIC_OMAN = 0x08; +pub const ARABIC_YEMEN = 0x09; +pub const ARABIC_SYRIA = 0x0a; +pub const ARABIC_JORDAN = 0x0b; +pub const ARABIC_LEBANON = 0x0c; +pub const ARABIC_KUWAIT = 0x0d; +pub const ARABIC_UAE = 0x0e; +pub const ARABIC_BAHRAIN = 0x0f; +pub const ARABIC_QATAR = 0x10; +pub const ARMENIAN_ARMENIA = 0x01; +pub const ASSAMESE_INDIA = 0x01; +pub const AZERI_LATIN = 0x01; +pub const AZERI_CYRILLIC = 0x02; +pub const AZERBAIJANI_AZERBAIJAN_LATIN = 0x01; +pub const AZERBAIJANI_AZERBAIJAN_CYRILLIC = 0x02; +pub const BANGLA_INDIA = 0x01; +pub const BANGLA_BANGLADESH = 0x02; +pub const BASHKIR_RUSSIA = 0x01; +pub const BASQUE_BASQUE = 0x01; +pub const BELARUSIAN_BELARUS = 0x01; +pub const BENGALI_INDIA = 0x01; +pub const BENGALI_BANGLADESH = 0x02; +pub const BOSNIAN_BOSNIA_HERZEGOVINA_LATIN = 0x05; +pub const BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC = 0x08; +pub const BRETON_FRANCE = 0x01; +pub const BULGARIAN_BULGARIA = 0x01; +pub const CATALAN_CATALAN = 0x01; +pub const CENTRAL_KURDISH_IRAQ = 0x01; +pub const CHEROKEE_CHEROKEE = 0x01; +pub const CHINESE_TRADITIONAL = 0x01; +pub const CHINESE_SIMPLIFIED = 0x02; +pub const CHINESE_HONGKONG = 0x03; +pub const CHINESE_SINGAPORE = 0x04; +pub const CHINESE_MACAU = 0x05; +pub const CORSICAN_FRANCE = 0x01; +pub const CZECH_CZECH_REPUBLIC = 0x01; +pub const CROATIAN_CROATIA = 0x01; +pub const CROATIAN_BOSNIA_HERZEGOVINA_LATIN = 0x04; +pub const DANISH_DENMARK = 0x01; +pub const DARI_AFGHANISTAN = 0x01; +pub const DIVEHI_MALDIVES = 0x01; +pub const DUTCH = 0x01; +pub const DUTCH_BELGIAN = 0x02; +pub const ENGLISH_US = 0x01; +pub const ENGLISH_UK = 0x02; +pub const ENGLISH_AUS = 0x03; +pub const ENGLISH_CAN = 0x04; +pub const ENGLISH_NZ = 0x05; +pub const ENGLISH_EIRE = 0x06; +pub const ENGLISH_SOUTH_AFRICA = 0x07; +pub const ENGLISH_JAMAICA = 0x08; +pub const ENGLISH_CARIBBEAN = 0x09; +pub const ENGLISH_BELIZE = 0x0a; +pub const ENGLISH_TRINIDAD = 0x0b; +pub const ENGLISH_ZIMBABWE = 0x0c; +pub const ENGLISH_PHILIPPINES = 0x0d; +pub const ENGLISH_INDIA = 0x10; +pub const ENGLISH_MALAYSIA = 0x11; +pub const ENGLISH_SINGAPORE = 0x12; +pub const ESTONIAN_ESTONIA = 0x01; +pub const FAEROESE_FAROE_ISLANDS = 0x01; +pub const FILIPINO_PHILIPPINES = 0x01; +pub const FINNISH_FINLAND = 0x01; +pub const FRENCH = 0x01; +pub const FRENCH_BELGIAN = 0x02; +pub const FRENCH_CANADIAN = 0x03; +pub const FRENCH_SWISS = 0x04; +pub const FRENCH_LUXEMBOURG = 0x05; +pub const FRENCH_MONACO = 0x06; +pub const FRISIAN_NETHERLANDS = 0x01; +pub const FULAH_SENEGAL = 0x02; +pub const GALICIAN_GALICIAN = 0x01; +pub const GEORGIAN_GEORGIA = 0x01; +pub const GERMAN = 0x01; +pub const GERMAN_SWISS = 0x02; +pub const GERMAN_AUSTRIAN = 0x03; +pub const GERMAN_LUXEMBOURG = 0x04; +pub const GERMAN_LIECHTENSTEIN = 0x05; +pub const GREEK_GREECE = 0x01; +pub const GREENLANDIC_GREENLAND = 0x01; +pub const GUJARATI_INDIA = 0x01; +pub const HAUSA_NIGERIA_LATIN = 0x01; +pub const HAWAIIAN_US = 0x01; +pub const HEBREW_ISRAEL = 0x01; +pub const HINDI_INDIA = 0x01; +pub const HUNGARIAN_HUNGARY = 0x01; +pub const ICELANDIC_ICELAND = 0x01; +pub const IGBO_NIGERIA = 0x01; +pub const INDONESIAN_INDONESIA = 0x01; +pub const INUKTITUT_CANADA = 0x01; +pub const INUKTITUT_CANADA_LATIN = 0x02; +pub const IRISH_IRELAND = 0x02; +pub const ITALIAN = 0x01; +pub const ITALIAN_SWISS = 0x02; +pub const JAPANESE_JAPAN = 0x01; +pub const KANNADA_INDIA = 0x01; +pub const KASHMIRI_SASIA = 0x02; +pub const KASHMIRI_INDIA = 0x02; +pub const KAZAK_KAZAKHSTAN = 0x01; +pub const KHMER_CAMBODIA = 0x01; +pub const KICHE_GUATEMALA = 0x01; +pub const KINYARWANDA_RWANDA = 0x01; +pub const KONKANI_INDIA = 0x01; +pub const KOREAN = 0x01; +pub const KYRGYZ_KYRGYZSTAN = 0x01; +pub const LAO_LAO = 0x01; +pub const LATVIAN_LATVIA = 0x01; +pub const LITHUANIAN = 0x01; +pub const LOWER_SORBIAN_GERMANY = 0x02; +pub const LUXEMBOURGISH_LUXEMBOURG = 0x01; +pub const MACEDONIAN_MACEDONIA = 0x01; +pub const MALAY_MALAYSIA = 0x01; +pub const MALAY_BRUNEI_DARUSSALAM = 0x02; +pub const MALAYALAM_INDIA = 0x01; +pub const MALTESE_MALTA = 0x01; +pub const MAORI_NEW_ZEALAND = 0x01; +pub const MAPUDUNGUN_CHILE = 0x01; +pub const MARATHI_INDIA = 0x01; +pub const MOHAWK_MOHAWK = 0x01; +pub const MONGOLIAN_CYRILLIC_MONGOLIA = 0x01; +pub const MONGOLIAN_PRC = 0x02; +pub const NEPALI_INDIA = 0x02; +pub const NEPALI_NEPAL = 0x01; +pub const NORWEGIAN_BOKMAL = 0x01; +pub const NORWEGIAN_NYNORSK = 0x02; +pub const OCCITAN_FRANCE = 0x01; +pub const ODIA_INDIA = 0x01; +pub const ORIYA_INDIA = 0x01; +pub const PASHTO_AFGHANISTAN = 0x01; +pub const PERSIAN_IRAN = 0x01; +pub const POLISH_POLAND = 0x01; +pub const PORTUGUESE = 0x02; +pub const PORTUGUESE_BRAZILIAN = 0x01; +pub const PULAR_SENEGAL = 0x02; +pub const PUNJABI_INDIA = 0x01; +pub const PUNJABI_PAKISTAN = 0x02; +pub const QUECHUA_BOLIVIA = 0x01; +pub const QUECHUA_ECUADOR = 0x02; +pub const QUECHUA_PERU = 0x03; +pub const ROMANIAN_ROMANIA = 0x01; +pub const ROMANSH_SWITZERLAND = 0x01; +pub const RUSSIAN_RUSSIA = 0x01; +pub const SAKHA_RUSSIA = 0x01; +pub const SAMI_NORTHERN_NORWAY = 0x01; +pub const SAMI_NORTHERN_SWEDEN = 0x02; +pub const SAMI_NORTHERN_FINLAND = 0x03; +pub const SAMI_LULE_NORWAY = 0x04; +pub const SAMI_LULE_SWEDEN = 0x05; +pub const SAMI_SOUTHERN_NORWAY = 0x06; +pub const SAMI_SOUTHERN_SWEDEN = 0x07; +pub const SAMI_SKOLT_FINLAND = 0x08; +pub const SAMI_INARI_FINLAND = 0x09; +pub const SANSKRIT_INDIA = 0x01; +pub const SCOTTISH_GAELIC = 0x01; +pub const SERBIAN_BOSNIA_HERZEGOVINA_LATIN = 0x06; +pub const SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC = 0x07; +pub const SERBIAN_MONTENEGRO_LATIN = 0x0b; +pub const SERBIAN_MONTENEGRO_CYRILLIC = 0x0c; +pub const SERBIAN_SERBIA_LATIN = 0x09; +pub const SERBIAN_SERBIA_CYRILLIC = 0x0a; +pub const SERBIAN_CROATIA = 0x01; +pub const SERBIAN_LATIN = 0x02; +pub const SERBIAN_CYRILLIC = 0x03; +pub const SINDHI_INDIA = 0x01; +pub const SINDHI_PAKISTAN = 0x02; +pub const SINDHI_AFGHANISTAN = 0x02; +pub const SINHALESE_SRI_LANKA = 0x01; +pub const SOTHO_NORTHERN_SOUTH_AFRICA = 0x01; +pub const SLOVAK_SLOVAKIA = 0x01; +pub const SLOVENIAN_SLOVENIA = 0x01; +pub const SPANISH = 0x01; +pub const SPANISH_MEXICAN = 0x02; +pub const SPANISH_MODERN = 0x03; +pub const SPANISH_GUATEMALA = 0x04; +pub const SPANISH_COSTA_RICA = 0x05; +pub const SPANISH_PANAMA = 0x06; +pub const SPANISH_DOMINICAN_REPUBLIC = 0x07; +pub const SPANISH_VENEZUELA = 0x08; +pub const SPANISH_COLOMBIA = 0x09; +pub const SPANISH_PERU = 0x0a; +pub const SPANISH_ARGENTINA = 0x0b; +pub const SPANISH_ECUADOR = 0x0c; +pub const SPANISH_CHILE = 0x0d; +pub const SPANISH_URUGUAY = 0x0e; +pub const SPANISH_PARAGUAY = 0x0f; +pub const SPANISH_BOLIVIA = 0x10; +pub const SPANISH_EL_SALVADOR = 0x11; +pub const SPANISH_HONDURAS = 0x12; +pub const SPANISH_NICARAGUA = 0x13; +pub const SPANISH_PUERTO_RICO = 0x14; +pub const SPANISH_US = 0x15; +pub const SWAHILI_KENYA = 0x01; +pub const SWEDISH = 0x01; +pub const SWEDISH_FINLAND = 0x02; +pub const SYRIAC_SYRIA = 0x01; +pub const TAJIK_TAJIKISTAN = 0x01; +pub const TAMAZIGHT_ALGERIA_LATIN = 0x02; +pub const TAMAZIGHT_MOROCCO_TIFINAGH = 0x04; +pub const TAMIL_INDIA = 0x01; +pub const TAMIL_SRI_LANKA = 0x02; +pub const TATAR_RUSSIA = 0x01; +pub const TELUGU_INDIA = 0x01; +pub const THAI_THAILAND = 0x01; +pub const TIBETAN_PRC = 0x01; +pub const TIGRIGNA_ERITREA = 0x02; +pub const TIGRINYA_ERITREA = 0x02; +pub const TIGRINYA_ETHIOPIA = 0x01; +pub const TSWANA_BOTSWANA = 0x02; +pub const TSWANA_SOUTH_AFRICA = 0x01; +pub const TURKISH_TURKEY = 0x01; +pub const TURKMEN_TURKMENISTAN = 0x01; +pub const UIGHUR_PRC = 0x01; +pub const UKRAINIAN_UKRAINE = 0x01; +pub const UPPER_SORBIAN_GERMANY = 0x01; +pub const URDU_PAKISTAN = 0x01; +pub const URDU_INDIA = 0x02; +pub const UZBEK_LATIN = 0x01; +pub const UZBEK_CYRILLIC = 0x02; +pub const VALENCIAN_VALENCIA = 0x02; +pub const VIETNAMESE_VIETNAM = 0x01; +pub const WELSH_UNITED_KINGDOM = 0x01; +pub const WOLOF_SENEGAL = 0x01; +pub const XHOSA_SOUTH_AFRICA = 0x01; +pub const YAKUT_RUSSIA = 0x01; +pub const YI_PRC = 0x01; +pub const YORUBA_NIGERIA = 0x01; +pub const ZULU_SOUTH_AFRICA = 0x01; diff --git a/lib/std/os/zen.zig b/lib/std/os/zen.zig new file mode 100644 index 0000000000..727f55fa6d --- /dev/null +++ b/lib/std/os/zen.zig @@ -0,0 +1,260 @@ +const std = @import("../std.zig"); +const assert = std.debug.assert; + +////////////////////////// +//// IPC structures //// +////////////////////////// + +pub const Message = struct { + sender: MailboxId, + receiver: MailboxId, + code: usize, + args: [5]usize, + payload: ?[]const u8, + + pub fn from(mailbox_id: MailboxId) Message { + return Message{ + .sender = MailboxId.Undefined, + .receiver = mailbox_id, + .code = undefined, + .args = undefined, + .payload = null, + }; + } + + pub fn to(mailbox_id: MailboxId, msg_code: usize, args: ...) Message { + var message = Message{ + .sender = MailboxId.This, + .receiver = mailbox_id, + .code = msg_code, + .args = undefined, + .payload = null, + }; + + assert(args.len <= message.args.len); + comptime var i = 0; + inline while (i < args.len) : (i += 1) { + message.args[i] = args[i]; + } + + return message; + } + + pub fn as(self: Message, sender: MailboxId) Message { + var message = self; + message.sender = sender; + return message; + } + + pub fn withPayload(self: Message, payload: []const u8) Message { + var message = self; + message.payload = payload; + return message; + } +}; + +pub const MailboxId = union(enum) { + Undefined, + This, + Kernel, + Port: u16, + Thread: u16, +}; + +////////////////////////////////////// +//// Ports reserved for servers //// +////////////////////////////////////// + +pub const Server = struct { + pub const Keyboard = MailboxId{ .Port = 0 }; + pub const Terminal = MailboxId{ .Port = 1 }; +}; + +//////////////////////// +//// POSIX things //// +//////////////////////// + +// Standard streams. +pub const STDIN_FILENO = 0; +pub const STDOUT_FILENO = 1; +pub const STDERR_FILENO = 2; + +// FIXME: let's borrow Linux's error numbers for now. +usingnamespace @import("bits/linux/errno.zig"); +// Get the errno from a syscall return value, or 0 for no error. +pub fn getErrno(r: usize) usize { + const signed_r = @bitCast(isize, r); + return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; +} + +// TODO: implement this correctly. +pub fn read(fd: i32, buf: [*]u8, count: usize) usize { + switch (fd) { + STDIN_FILENO => { + var i: usize = 0; + while (i < count) : (i += 1) { + send(&Message.to(Server.Keyboard, 0)); + + // FIXME: we should be certain that we are receiving from Keyboard. + var message = Message.from(MailboxId.This); + receive(&message); + + buf[i] = @intCast(u8, message.args[0]); + } + }, + else => unreachable, + } + return count; +} + +// TODO: implement this correctly. +pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { + switch (fd) { + STDOUT_FILENO, STDERR_FILENO => { + send(&Message.to(Server.Terminal, 1).withPayload(buf[0..count])); + }, + else => unreachable, + } + return count; +} + +/////////////////////////// +//// Syscall numbers //// +/////////////////////////// + +pub const Syscall = enum(usize) { + exit = 0, + send = 1, + receive = 2, + subscribeIRQ = 3, + inb = 4, + outb = 5, + map = 6, + createThread = 7, +}; + +//////////////////// +//// Syscalls //// +//////////////////// + +pub fn exit(status: i32) noreturn { + _ = syscall1(Syscall.exit, @bitCast(usize, isize(status))); + unreachable; +} + +pub fn send(message: *const Message) void { + _ = syscall1(Syscall.send, @ptrToInt(message)); +} + +pub fn receive(destination: *Message) void { + _ = syscall1(Syscall.receive, @ptrToInt(destination)); +} + +pub fn subscribeIRQ(irq: u8, mailbox_id: *const MailboxId) void { + _ = syscall2(Syscall.subscribeIRQ, irq, @ptrToInt(mailbox_id)); +} + +pub fn inb(port: u16) u8 { + return @intCast(u8, syscall1(Syscall.inb, port)); +} + +pub fn outb(port: u16, value: u8) void { + _ = syscall2(Syscall.outb, port, value); +} + +pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { + return syscall4(Syscall.map, v_addr, p_addr, size, @boolToInt(writable)) != 0; +} + +pub fn createThread(function: fn () void) u16 { + return u16(syscall1(Syscall.createThread, @ptrToInt(function))); +} + +///////////////////////// +//// Syscall stubs //// +///////////////////////// + +inline fn syscall0(number: Syscall) usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number) + ); +} + +inline fn syscall1(number: Syscall, arg1: usize) usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1) + ); +} + +inline fn syscall2(number: Syscall, arg1: usize, arg2: usize) usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1), + [arg2] "{edx}" (arg2) + ); +} + +inline fn syscall3(number: Syscall, arg1: usize, arg2: usize, arg3: usize) usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1), + [arg2] "{edx}" (arg2), + [arg3] "{ebx}" (arg3) + ); +} + +inline fn syscall4(number: Syscall, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1), + [arg2] "{edx}" (arg2), + [arg3] "{ebx}" (arg3), + [arg4] "{esi}" (arg4) + ); +} + +inline fn syscall5( + number: Syscall, + arg1: usize, + arg2: usize, + arg3: usize, + arg4: usize, + arg5: usize, +) usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1), + [arg2] "{edx}" (arg2), + [arg3] "{ebx}" (arg3), + [arg4] "{esi}" (arg4), + [arg5] "{edi}" (arg5) + ); +} + +inline fn syscall6( + number: Syscall, + arg1: usize, + arg2: usize, + arg3: usize, + arg4: usize, + arg5: usize, + arg6: usize, +) usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1), + [arg2] "{edx}" (arg2), + [arg3] "{ebx}" (arg3), + [arg4] "{esi}" (arg4), + [arg5] "{edi}" (arg5), + [arg6] "{ebp}" (arg6) + ); +} |
