| author | |
| committer | |
| log | 44d8d654a0ba463a1d4cf34d435c8422bfcd1c81 |
| tree | 8ef92e3af15a5daf359163d46404171695ae89a1 |
| parent | ec59f765266749a29d5ba1804f4ab5afdcabee1d |
17 files changed, 2033 insertions(+), 2236 deletions(-)
CMakeLists.txt+4-5| ... | @@ -439,11 +439,10 @@ set(ZIG_STD_FILES | ... | @@ -439,11 +439,10 @@ set(ZIG_STD_FILES |
| 439 | "os/darwin_errno.zig" | 439 | "os/darwin_errno.zig" |
| 440 | "os/get_user_id.zig" | 440 | "os/get_user_id.zig" |
| 441 | "os/index.zig" | 441 | "os/index.zig" |
| 442 | "os/linux.zig" | 442 | "os/linux/index.zig" |
| 443 | "os/linux_errno.zig" | 443 | "os/linux/errno.zig" |
| 444 | "os/linux_random.zig" | 444 | "os/linux/i386.zig" |
| 445 | "os/linux_i386.zig" | 445 | "os/linux/x86_64.zig" |
| 446 | "os/linux_x86_64.zig" | ||
| 447 | "os/path.zig" | 446 | "os/path.zig" |
| 448 | "os/windows/error.zig" | 447 | "os/windows/error.zig" |
| 449 | "os/windows/index.zig" | 448 | "os/windows/index.zig" |
src/ir.cpp+18| ... | @@ -6193,6 +6193,15 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -6193,6 +6193,15 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 6193 | if (other_type->id == TypeTableEntryIdFloat) { | 6193 | if (other_type->id == TypeTableEntryIdFloat) { |
| 6194 | return true; | 6194 | return true; |
| 6195 | } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) { | 6195 | } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) { |
| 6196 | if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { | ||
| 6197 | Buf *val_buf = buf_alloc(); | ||
| 6198 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); | ||
| 6199 | ir_add_error(ira, instruction, | ||
| 6200 | buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", | ||
| 6201 | buf_ptr(val_buf), | ||
| 6202 | buf_ptr(&other_type->name))); | ||
| 6203 | return false; | ||
| 6204 | } | ||
| 6196 | if (bigint_fits_in_bits(&const_val->data.x_bigint, other_type->data.integral.bit_count, | 6205 | if (bigint_fits_in_bits(&const_val->data.x_bigint, other_type->data.integral.bit_count, |
| 6197 | other_type->data.integral.is_signed)) | 6206 | other_type->data.integral.is_signed)) |
| 6198 | { | 6207 | { |
| ... | @@ -6205,6 +6214,15 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -6205,6 +6214,15 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 6205 | if (const_val_fits_in_num_lit(const_val, child_type)) { | 6214 | if (const_val_fits_in_num_lit(const_val, child_type)) { |
| 6206 | return true; | 6215 | return true; |
| 6207 | } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) { | 6216 | } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) { |
| 6217 | if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { | ||
| 6218 | Buf *val_buf = buf_alloc(); | ||
| 6219 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); | ||
| 6220 | ir_add_error(ira, instruction, | ||
| 6221 | buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", | ||
| 6222 | buf_ptr(val_buf), | ||
| 6223 | buf_ptr(&child_type->name))); | ||
| 6224 | return false; | ||
| 6225 | } | ||
| 6208 | if (bigint_fits_in_bits(&const_val->data.x_bigint, | 6226 | if (bigint_fits_in_bits(&const_val->data.x_bigint, |
| 6209 | child_type->data.integral.bit_count, | 6227 | child_type->data.integral.bit_count, |
| 6210 | child_type->data.integral.is_signed)) | 6228 | child_type->data.integral.is_signed)) |
std/c/linux.zig+1-1| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | pub use @import("../os/linux_errno.zig"); | 1 | pub use @import("../os/linux/errno.zig"); |
| 2 | 2 | ||
| 3 | pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) c_int; | 3 | pub extern "c" fn getrandom(buf_ptr: &u8, buf_len: usize, flags: c_uint) c_int; |
| 4 | extern "c" fn __errno_location() &c_int; | 4 | extern "c" fn __errno_location() &c_int; |
std/io.zig+1-1| ... | @@ -2,7 +2,7 @@ const std = @import("index.zig"); | ... | @@ -2,7 +2,7 @@ const std = @import("index.zig"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const Os = builtin.Os; | 3 | const Os = builtin.Os; |
| 4 | const system = switch(builtin.os) { | 4 | const system = switch(builtin.os) { |
| 5 | Os.linux => @import("os/linux.zig"), | 5 | Os.linux => @import("os/linux/index.zig"), |
| 6 | Os.macosx, Os.ios => @import("os/darwin.zig"), | 6 | Os.macosx, Os.ios => @import("os/darwin.zig"), |
| 7 | Os.windows => @import("os/windows/index.zig"), | 7 | Os.windows => @import("os/windows/index.zig"), |
| 8 | else => @compileError("Unsupported OS"), | 8 | else => @compileError("Unsupported OS"), |
std/os/index.zig+28-9| ... | @@ -6,7 +6,7 @@ const os = this; | ... | @@ -6,7 +6,7 @@ const os = this; |
| 6 | 6 | ||
| 7 | pub const windows = @import("windows/index.zig"); | 7 | pub const windows = @import("windows/index.zig"); |
| 8 | pub const darwin = @import("darwin.zig"); | 8 | pub const darwin = @import("darwin.zig"); |
| 9 | pub const linux = @import("linux.zig"); | 9 | pub const linux = @import("linux/index.zig"); |
| 10 | pub const zen = @import("zen.zig"); | 10 | pub const zen = @import("zen.zig"); |
| 11 | pub const posix = switch(builtin.os) { | 11 | pub const posix = switch(builtin.os) { |
| 12 | Os.linux => linux, | 12 | Os.linux => linux, |
| ... | @@ -78,13 +78,28 @@ error WouldBlock; | ... | @@ -78,13 +78,28 @@ error WouldBlock; |
| 78 | pub fn getRandomBytes(buf: []u8) %void { | 78 | pub fn getRandomBytes(buf: []u8) %void { |
| 79 | switch (builtin.os) { | 79 | switch (builtin.os) { |
| 80 | Os.linux => while (true) { | 80 | Os.linux => while (true) { |
| 81 | const err = posix.getErrno(posix.getRandomBytes(buf)); | 81 | // TODO check libc version and potentially call c.getrandom. |
| 82 | if (err > 0) return unexpectedErrorPosix(err); | 82 | // See #397 |
| 83 | const err = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0)); | ||
| 84 | if (err > 0) { | ||
| 85 | switch (err) { | ||
| 86 | posix.EINVAL => unreachable, | ||
| 87 | posix.EFAULT => unreachable, | ||
| 88 | posix.EINTR => continue, | ||
| 89 | posix.ENOSYS => { | ||
| 90 | const fd = try posixOpenC(c"/dev/urandom", posix.O_RDONLY|posix.O_CLOEXEC, 0); | ||
| 91 | defer close(fd); | ||
| 92 | |||
| 93 | try posixRead(fd, buf); | ||
| 94 | return; | ||
| 95 | }, | ||
| 96 | else => return unexpectedErrorPosix(err), | ||
| 97 | } | ||
| 98 | } | ||
| 83 | return; | 99 | return; |
| 84 | }, | 100 | }, |
| 85 | Os.macosx, Os.ios => { | 101 | Os.macosx, Os.ios => { |
| 86 | const fd = try posixOpen("/dev/urandom", posix.O_RDONLY|posix.O_CLOEXEC, | 102 | const fd = try posixOpenC(c"/dev/urandom", posix.O_RDONLY|posix.O_CLOEXEC, 0); |
| 87 | 0, null); | ||
| 88 | defer close(fd); | 103 | defer close(fd); |
| 89 | 104 | ||
| 90 | try posixRead(fd, buf); | 105 | try posixRead(fd, buf); |
| ... | @@ -253,8 +268,12 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al | ... | @@ -253,8 +268,12 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al |
| 253 | mem.copy(u8, path0, file_path); | 268 | mem.copy(u8, path0, file_path); |
| 254 | path0[file_path.len] = 0; | 269 | path0[file_path.len] = 0; |
| 255 | 270 | ||
| 271 | return posixOpenC(path0.ptr, flags, perm); | ||
| 272 | } | ||
| 273 | |||
| 274 | pub fn posixOpenC(file_path: &const u8, flags: u32, perm: usize) %i32 { | ||
| 256 | while (true) { | 275 | while (true) { |
| 257 | const result = posix.open(path0.ptr, flags, perm); | 276 | const result = posix.open(file_path, flags, perm); |
| 258 | const err = posix.getErrno(result); | 277 | const err = posix.getErrno(result); |
| 259 | if (err > 0) { | 278 | if (err > 0) { |
| 260 | return switch (err) { | 279 | return switch (err) { |
| ... | @@ -1486,10 +1505,10 @@ test "std.os" { | ... | @@ -1486,10 +1505,10 @@ test "std.os" { |
| 1486 | _ = @import("darwin_errno.zig"); | 1505 | _ = @import("darwin_errno.zig"); |
| 1487 | _ = @import("darwin.zig"); | 1506 | _ = @import("darwin.zig"); |
| 1488 | _ = @import("get_user_id.zig"); | 1507 | _ = @import("get_user_id.zig"); |
| 1489 | _ = @import("linux_errno.zig"); | 1508 | _ = @import("linux/errno.zig"); |
| 1490 | //_ = @import("linux_i386.zig"); | 1509 | //_ = @import("linux_i386.zig"); |
| 1491 | _ = @import("linux_x86_64.zig"); | 1510 | _ = @import("linux/x86_64.zig"); |
| 1492 | _ = @import("linux.zig"); | 1511 | _ = @import("linux/index.zig"); |
| 1493 | _ = @import("path.zig"); | 1512 | _ = @import("path.zig"); |
| 1494 | _ = @import("windows/index.zig"); | 1513 | _ = @import("windows/index.zig"); |
| 1495 | } | 1514 | } |
std/os/linux.zig deleted-797| ... | @@ -1,797 +0,0 @@ | ||
| 1 | const std = @import("../index.zig"); | ||
| 2 | const assert = std.debug.assert; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | const arch = switch (builtin.arch) { | ||
| 5 | builtin.Arch.x86_64 => @import("linux_x86_64.zig"), | ||
| 6 | builtin.Arch.i386 => @import("linux_i386.zig"), | ||
| 7 | else => @compileError("unsupported arch"), | ||
| 8 | }; | ||
| 9 | pub use @import("linux_errno.zig"); | ||
| 10 | pub use @import("linux_random.zig"); | ||
| 11 | |||
| 12 | pub const PATH_MAX = 4096; | ||
| 13 | |||
| 14 | pub const STDIN_FILENO = 0; | ||
| 15 | pub const STDOUT_FILENO = 1; | ||
| 16 | pub const STDERR_FILENO = 2; | ||
| 17 | |||
| 18 | pub const PROT_NONE = 0; | ||
| 19 | pub const PROT_READ = 1; | ||
| 20 | pub const PROT_WRITE = 2; | ||
| 21 | pub const PROT_EXEC = 4; | ||
| 22 | pub const PROT_GROWSDOWN = 0x01000000; | ||
| 23 | pub const PROT_GROWSUP = 0x02000000; | ||
| 24 | |||
| 25 | pub const MAP_FAILED = @maxValue(usize); | ||
| 26 | pub const MAP_SHARED = 0x01; | ||
| 27 | pub const MAP_PRIVATE = 0x02; | ||
| 28 | pub const MAP_TYPE = 0x0f; | ||
| 29 | pub const MAP_FIXED = 0x10; | ||
| 30 | pub const MAP_ANONYMOUS = 0x20; | ||
| 31 | pub const MAP_NORESERVE = 0x4000; | ||
| 32 | pub const MAP_GROWSDOWN = 0x0100; | ||
| 33 | pub const MAP_DENYWRITE = 0x0800; | ||
| 34 | pub const MAP_EXECUTABLE = 0x1000; | ||
| 35 | pub const MAP_LOCKED = 0x2000; | ||
| 36 | pub const MAP_POPULATE = 0x8000; | ||
| 37 | pub const MAP_NONBLOCK = 0x10000; | ||
| 38 | pub const MAP_STACK = 0x20000; | ||
| 39 | pub const MAP_HUGETLB = 0x40000; | ||
| 40 | pub const MAP_FILE = 0; | ||
| 41 | |||
| 42 | pub const WNOHANG = 1; | ||
| 43 | pub const WUNTRACED = 2; | ||
| 44 | pub const WSTOPPED = 2; | ||
| 45 | pub const WEXITED = 4; | ||
| 46 | pub const WCONTINUED = 8; | ||
| 47 | pub const WNOWAIT = 0x1000000; | ||
| 48 | |||
| 49 | pub const SA_NOCLDSTOP = 1; | ||
| 50 | pub const SA_NOCLDWAIT = 2; | ||
| 51 | pub const SA_SIGINFO = 4; | ||
| 52 | pub const SA_ONSTACK = 0x08000000; | ||
| 53 | pub const SA_RESTART = 0x10000000; | ||
| 54 | pub const SA_NODEFER = 0x40000000; | ||
| 55 | pub const SA_RESETHAND = 0x80000000; | ||
| 56 | pub const SA_RESTORER = 0x04000000; | ||
| 57 | |||
| 58 | pub const SIGHUP = 1; | ||
| 59 | pub const SIGINT = 2; | ||
| 60 | pub const SIGQUIT = 3; | ||
| 61 | pub const SIGILL = 4; | ||
| 62 | pub const SIGTRAP = 5; | ||
| 63 | pub const SIGABRT = 6; | ||
| 64 | pub const SIGIOT = SIGABRT; | ||
| 65 | pub const SIGBUS = 7; | ||
| 66 | pub const SIGFPE = 8; | ||
| 67 | pub const SIGKILL = 9; | ||
| 68 | pub const SIGUSR1 = 10; | ||
| 69 | pub const SIGSEGV = 11; | ||
| 70 | pub const SIGUSR2 = 12; | ||
| 71 | pub const SIGPIPE = 13; | ||
| 72 | pub const SIGALRM = 14; | ||
| 73 | pub const SIGTERM = 15; | ||
| 74 | pub const SIGSTKFLT = 16; | ||
| 75 | pub const SIGCHLD = 17; | ||
| 76 | pub const SIGCONT = 18; | ||
| 77 | pub const SIGSTOP = 19; | ||
| 78 | pub const SIGTSTP = 20; | ||
| 79 | pub const SIGTTIN = 21; | ||
| 80 | pub const SIGTTOU = 22; | ||
| 81 | pub const SIGURG = 23; | ||
| 82 | pub const SIGXCPU = 24; | ||
| 83 | pub const SIGXFSZ = 25; | ||
| 84 | pub const SIGVTALRM = 26; | ||
| 85 | pub const SIGPROF = 27; | ||
| 86 | pub const SIGWINCH = 28; | ||
| 87 | pub const SIGIO = 29; | ||
| 88 | pub const SIGPOLL = 29; | ||
| 89 | pub const SIGPWR = 30; | ||
| 90 | pub const SIGSYS = 31; | ||
| 91 | pub const SIGUNUSED = SIGSYS; | ||
| 92 | |||
| 93 | pub const O_RDONLY = 0o0; | ||
| 94 | pub const O_WRONLY = 0o1; | ||
| 95 | pub const O_RDWR = 0o2; | ||
| 96 | |||
| 97 | pub const O_CREAT = arch.O_CREAT; | ||
| 98 | pub const O_EXCL = arch.O_EXCL; | ||
| 99 | pub const O_NOCTTY = arch.O_NOCTTY; | ||
| 100 | pub const O_TRUNC = arch.O_TRUNC; | ||
| 101 | pub const O_APPEND = arch.O_APPEND; | ||
| 102 | pub const O_NONBLOCK = arch.O_NONBLOCK; | ||
| 103 | pub const O_DSYNC = arch.O_DSYNC; | ||
| 104 | pub const O_SYNC = arch.O_SYNC; | ||
| 105 | pub const O_RSYNC = arch.O_RSYNC; | ||
| 106 | pub const O_DIRECTORY = arch.O_DIRECTORY; | ||
| 107 | pub const O_NOFOLLOW = arch.O_NOFOLLOW; | ||
| 108 | pub const O_CLOEXEC = arch.O_CLOEXEC; | ||
| 109 | |||
| 110 | pub const O_ASYNC = arch.O_ASYNC; | ||
| 111 | pub const O_DIRECT = arch.O_DIRECT; | ||
| 112 | pub const O_LARGEFILE = arch.O_LARGEFILE; | ||
| 113 | pub const O_NOATIME = arch.O_NOATIME; | ||
| 114 | pub const O_PATH = arch.O_PATH; | ||
| 115 | pub const O_TMPFILE = arch.O_TMPFILE; | ||
| 116 | pub const O_NDELAY = arch.O_NDELAY; | ||
| 117 | |||
| 118 | pub const SEEK_SET = 0; | ||
| 119 | pub const SEEK_CUR = 1; | ||
| 120 | pub const SEEK_END = 2; | ||
| 121 | |||
| 122 | pub const SIG_BLOCK = 0; | ||
| 123 | pub const SIG_UNBLOCK = 1; | ||
| 124 | pub const SIG_SETMASK = 2; | ||
| 125 | |||
| 126 | pub const SOCK_STREAM = 1; | ||
| 127 | pub const SOCK_DGRAM = 2; | ||
| 128 | pub const SOCK_RAW = 3; | ||
| 129 | pub const SOCK_RDM = 4; | ||
| 130 | pub const SOCK_SEQPACKET = 5; | ||
| 131 | pub const SOCK_DCCP = 6; | ||
| 132 | pub const SOCK_PACKET = 10; | ||
| 133 | pub const SOCK_CLOEXEC = 0o2000000; | ||
| 134 | pub const SOCK_NONBLOCK = 0o4000; | ||
| 135 | |||
| 136 | |||
| 137 | pub const PROTO_ip = 0o000; | ||
| 138 | pub const PROTO_icmp = 0o001; | ||
| 139 | pub const PROTO_igmp = 0o002; | ||
| 140 | pub const PROTO_ggp = 0o003; | ||
| 141 | pub const PROTO_ipencap = 0o004; | ||
| 142 | pub const PROTO_st = 0o005; | ||
| 143 | pub const PROTO_tcp = 0o006; | ||
| 144 | pub const PROTO_egp = 0o010; | ||
| 145 | pub const PROTO_pup = 0o014; | ||
| 146 | pub const PROTO_udp = 0o021; | ||
| 147 | pub const PROTO_hmp = 0o024; | ||
| 148 | pub const PROTO_xns_idp = 0o026; | ||
| 149 | pub const PROTO_rdp = 0o033; | ||
| 150 | pub const PROTO_iso_tp4 = 0o035; | ||
| 151 | pub const PROTO_xtp = 0o044; | ||
| 152 | pub const PROTO_ddp = 0o045; | ||
| 153 | pub const PROTO_idpr_cmtp = 0o046; | ||
| 154 | pub const PROTO_ipv6 = 0o051; | ||
| 155 | pub const PROTO_ipv6_route = 0o053; | ||
| 156 | pub const PROTO_ipv6_frag = 0o054; | ||
| 157 | pub const PROTO_idrp = 0o055; | ||
| 158 | pub const PROTO_rsvp = 0o056; | ||
| 159 | pub const PROTO_gre = 0o057; | ||
| 160 | pub const PROTO_esp = 0o062; | ||
| 161 | pub const PROTO_ah = 0o063; | ||
| 162 | pub const PROTO_skip = 0o071; | ||
| 163 | pub const PROTO_ipv6_icmp = 0o072; | ||
| 164 | pub const PROTO_ipv6_nonxt = 0o073; | ||
| 165 | pub const PROTO_ipv6_opts = 0o074; | ||
| 166 | pub const PROTO_rspf = 0o111; | ||
| 167 | pub const PROTO_vmtp = 0o121; | ||
| 168 | pub const PROTO_ospf = 0o131; | ||
| 169 | pub const PROTO_ipip = 0o136; | ||
| 170 | pub const PROTO_encap = 0o142; | ||
| 171 | pub const PROTO_pim = 0o147; | ||
| 172 | pub const PROTO_raw = 0o377; | ||
| 173 | |||
| 174 | pub const PF_UNSPEC = 0; | ||
| 175 | pub const PF_LOCAL = 1; | ||
| 176 | pub const PF_UNIX = PF_LOCAL; | ||
| 177 | pub const PF_FILE = PF_LOCAL; | ||
| 178 | pub const PF_INET = 2; | ||
| 179 | pub const PF_AX25 = 3; | ||
| 180 | pub const PF_IPX = 4; | ||
| 181 | pub const PF_APPLETALK = 5; | ||
| 182 | pub const PF_NETROM = 6; | ||
| 183 | pub const PF_BRIDGE = 7; | ||
| 184 | pub const PF_ATMPVC = 8; | ||
| 185 | pub const PF_X25 = 9; | ||
| 186 | pub const PF_INET6 = 10; | ||
| 187 | pub const PF_ROSE = 11; | ||
| 188 | pub const PF_DECnet = 12; | ||
| 189 | pub const PF_NETBEUI = 13; | ||
| 190 | pub const PF_SECURITY = 14; | ||
| 191 | pub const PF_KEY = 15; | ||
| 192 | pub const PF_NETLINK = 16; | ||
| 193 | pub const PF_ROUTE = PF_NETLINK; | ||
| 194 | pub const PF_PACKET = 17; | ||
| 195 | pub const PF_ASH = 18; | ||
| 196 | pub const PF_ECONET = 19; | ||
| 197 | pub const PF_ATMSVC = 20; | ||
| 198 | pub const PF_RDS = 21; | ||
| 199 | pub const PF_SNA = 22; | ||
| 200 | pub const PF_IRDA = 23; | ||
| 201 | pub const PF_PPPOX = 24; | ||
| 202 | pub const PF_WANPIPE = 25; | ||
| 203 | pub const PF_LLC = 26; | ||
| 204 | pub const PF_IB = 27; | ||
| 205 | pub const PF_MPLS = 28; | ||
| 206 | pub const PF_CAN = 29; | ||
| 207 | pub const PF_TIPC = 30; | ||
| 208 | pub const PF_BLUETOOTH = 31; | ||
| 209 | pub const PF_IUCV = 32; | ||
| 210 | pub const PF_RXRPC = 33; | ||
| 211 | pub const PF_ISDN = 34; | ||
| 212 | pub const PF_PHONET = 35; | ||
| 213 | pub const PF_IEEE802154 = 36; | ||
| 214 | pub const PF_CAIF = 37; | ||
| 215 | pub const PF_ALG = 38; | ||
| 216 | pub const PF_NFC = 39; | ||
| 217 | pub const PF_VSOCK = 40; | ||
| 218 | pub const PF_MAX = 41; | ||
| 219 | |||
| 220 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 221 | pub const AF_LOCAL = PF_LOCAL; | ||
| 222 | pub const AF_UNIX = AF_LOCAL; | ||
| 223 | pub const AF_FILE = AF_LOCAL; | ||
| 224 | pub const AF_INET = PF_INET; | ||
| 225 | pub const AF_AX25 = PF_AX25; | ||
| 226 | pub const AF_IPX = PF_IPX; | ||
| 227 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 228 | pub const AF_NETROM = PF_NETROM; | ||
| 229 | pub const AF_BRIDGE = PF_BRIDGE; | ||
| 230 | pub const AF_ATMPVC = PF_ATMPVC; | ||
| 231 | pub const AF_X25 = PF_X25; | ||
| 232 | pub const AF_INET6 = PF_INET6; | ||
| 233 | pub const AF_ROSE = PF_ROSE; | ||
| 234 | pub const AF_DECnet = PF_DECnet; | ||
| 235 | pub const AF_NETBEUI = PF_NETBEUI; | ||
| 236 | pub const AF_SECURITY = PF_SECURITY; | ||
| 237 | pub const AF_KEY = PF_KEY; | ||
| 238 | pub const AF_NETLINK = PF_NETLINK; | ||
| 239 | pub const AF_ROUTE = PF_ROUTE; | ||
| 240 | pub const AF_PACKET = PF_PACKET; | ||
| 241 | pub const AF_ASH = PF_ASH; | ||
| 242 | pub const AF_ECONET = PF_ECONET; | ||
| 243 | pub const AF_ATMSVC = PF_ATMSVC; | ||
| 244 | pub const AF_RDS = PF_RDS; | ||
| 245 | pub const AF_SNA = PF_SNA; | ||
| 246 | pub const AF_IRDA = PF_IRDA; | ||
| 247 | pub const AF_PPPOX = PF_PPPOX; | ||
| 248 | pub const AF_WANPIPE = PF_WANPIPE; | ||
| 249 | pub const AF_LLC = PF_LLC; | ||
| 250 | pub const AF_IB = PF_IB; | ||
| 251 | pub const AF_MPLS = PF_MPLS; | ||
| 252 | pub const AF_CAN = PF_CAN; | ||
| 253 | pub const AF_TIPC = PF_TIPC; | ||
| 254 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 255 | pub const AF_IUCV = PF_IUCV; | ||
| 256 | pub const AF_RXRPC = PF_RXRPC; | ||
| 257 | pub const AF_ISDN = PF_ISDN; | ||
| 258 | pub const AF_PHONET = PF_PHONET; | ||
| 259 | pub const AF_IEEE802154 = PF_IEEE802154; | ||
| 260 | pub const AF_CAIF = PF_CAIF; | ||
| 261 | pub const AF_ALG = PF_ALG; | ||
| 262 | pub const AF_NFC = PF_NFC; | ||
| 263 | pub const AF_VSOCK = PF_VSOCK; | ||
| 264 | pub const AF_MAX = PF_MAX; | ||
| 265 | |||
| 266 | pub const DT_UNKNOWN = 0; | ||
| 267 | pub const DT_FIFO = 1; | ||
| 268 | pub const DT_CHR = 2; | ||
| 269 | pub const DT_DIR = 4; | ||
| 270 | pub const DT_BLK = 6; | ||
| 271 | pub const DT_REG = 8; | ||
| 272 | pub const DT_LNK = 10; | ||
| 273 | pub const DT_SOCK = 12; | ||
| 274 | pub const DT_WHT = 14; | ||
| 275 | |||
| 276 | |||
| 277 | pub const TCGETS = 0x5401; | ||
| 278 | pub const TCSETS = 0x5402; | ||
| 279 | pub const TCSETSW = 0x5403; | ||
| 280 | pub const TCSETSF = 0x5404; | ||
| 281 | pub const TCGETA = 0x5405; | ||
| 282 | pub const TCSETA = 0x5406; | ||
| 283 | pub const TCSETAW = 0x5407; | ||
| 284 | pub const TCSETAF = 0x5408; | ||
| 285 | pub const TCSBRK = 0x5409; | ||
| 286 | pub const TCXONC = 0x540A; | ||
| 287 | pub const TCFLSH = 0x540B; | ||
| 288 | pub const TIOCEXCL = 0x540C; | ||
| 289 | pub const TIOCNXCL = 0x540D; | ||
| 290 | pub const TIOCSCTTY = 0x540E; | ||
| 291 | pub const TIOCGPGRP = 0x540F; | ||
| 292 | pub const TIOCSPGRP = 0x5410; | ||
| 293 | pub const TIOCOUTQ = 0x5411; | ||
| 294 | pub const TIOCSTI = 0x5412; | ||
| 295 | pub const TIOCGWINSZ = 0x5413; | ||
| 296 | pub const TIOCSWINSZ = 0x5414; | ||
| 297 | pub const TIOCMGET = 0x5415; | ||
| 298 | pub const TIOCMBIS = 0x5416; | ||
| 299 | pub const TIOCMBIC = 0x5417; | ||
| 300 | pub const TIOCMSET = 0x5418; | ||
| 301 | pub const TIOCGSOFTCAR = 0x5419; | ||
| 302 | pub const TIOCSSOFTCAR = 0x541A; | ||
| 303 | pub const FIONREAD = 0x541B; | ||
| 304 | pub const TIOCINQ = FIONREAD; | ||
| 305 | pub const TIOCLINUX = 0x541C; | ||
| 306 | pub const TIOCCONS = 0x541D; | ||
| 307 | pub const TIOCGSERIAL = 0x541E; | ||
| 308 | pub const TIOCSSERIAL = 0x541F; | ||
| 309 | pub const TIOCPKT = 0x5420; | ||
| 310 | pub const FIONBIO = 0x5421; | ||
| 311 | pub const TIOCNOTTY = 0x5422; | ||
| 312 | pub const TIOCSETD = 0x5423; | ||
| 313 | pub const TIOCGETD = 0x5424; | ||
| 314 | pub const TCSBRKP = 0x5425; | ||
| 315 | pub const TIOCSBRK = 0x5427; | ||
| 316 | pub const TIOCCBRK = 0x5428; | ||
| 317 | pub const TIOCGSID = 0x5429; | ||
| 318 | pub const TIOCGRS485 = 0x542E; | ||
| 319 | pub const TIOCSRS485 = 0x542F; | ||
| 320 | pub const TIOCGPTN = 0x80045430; | ||
| 321 | pub const TIOCSPTLCK = 0x40045431; | ||
| 322 | pub const TIOCGDEV = 0x80045432; | ||
| 323 | pub const TCGETX = 0x5432; | ||
| 324 | pub const TCSETX = 0x5433; | ||
| 325 | pub const TCSETXF = 0x5434; | ||
| 326 | pub const TCSETXW = 0x5435; | ||
| 327 | pub const TIOCSIG = 0x40045436; | ||
| 328 | pub const TIOCVHANGUP = 0x5437; | ||
| 329 | pub const TIOCGPKT = 0x80045438; | ||
| 330 | pub const TIOCGPTLCK = 0x80045439; | ||
| 331 | pub const TIOCGEXCL = 0x80045440; | ||
| 332 | |||
| 333 | pub const EPOLL_CTL_ADD = 1; | ||
| 334 | pub const EPOLL_CTL_DEL = 2; | ||
| 335 | pub const EPOLL_CTL_MOD = 3; | ||
| 336 | |||
| 337 | pub const EPOLLIN = 0x001; | ||
| 338 | pub const EPOLLPRI = 0x002; | ||
| 339 | pub const EPOLLOUT = 0x004; | ||
| 340 | pub const EPOLLRDNORM = 0x040; | ||
| 341 | pub const EPOLLRDBAND = 0x080; | ||
| 342 | pub const EPOLLWRNORM = 0x100; | ||
| 343 | pub const EPOLLWRBAND = 0x200; | ||
| 344 | pub const EPOLLMSG = 0x400; | ||
| 345 | pub const EPOLLERR = 0x008; | ||
| 346 | pub const EPOLLHUP = 0x010; | ||
| 347 | pub const EPOLLRDHUP = 0x2000; | ||
| 348 | pub const EPOLLEXCLUSIVE = (u32(1) << 28); | ||
| 349 | pub const EPOLLWAKEUP = (u32(1) << 29); | ||
| 350 | pub const EPOLLONESHOT = (u32(1) << 30); | ||
| 351 | pub const EPOLLET = (u32(1) << 31); | ||
| 352 | |||
| 353 | pub const CLOCK_REALTIME = 0; | ||
| 354 | pub const CLOCK_MONOTONIC = 1; | ||
| 355 | pub const CLOCK_PROCESS_CPUTIME_ID = 2; | ||
| 356 | pub const CLOCK_THREAD_CPUTIME_ID = 3; | ||
| 357 | pub const CLOCK_MONOTONIC_RAW = 4; | ||
| 358 | pub const CLOCK_REALTIME_COARSE = 5; | ||
| 359 | pub const CLOCK_MONOTONIC_COARSE = 6; | ||
| 360 | pub const CLOCK_BOOTTIME = 7; | ||
| 361 | pub const CLOCK_REALTIME_ALARM = 8; | ||
| 362 | pub const CLOCK_BOOTTIME_ALARM = 9; | ||
| 363 | pub const CLOCK_SGI_CYCLE = 10; | ||
| 364 | pub const CLOCK_TAI = 11; | ||
| 365 | |||
| 366 | pub const TFD_NONBLOCK = O_NONBLOCK; | ||
| 367 | pub const TFD_CLOEXEC = O_CLOEXEC; | ||
| 368 | |||
| 369 | pub const TFD_TIMER_ABSTIME = 1; | ||
| 370 | pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); | ||
| 371 | |||
| 372 | fn unsigned(s: i32) u32 { return @bitCast(u32, s); } | ||
| 373 | fn signed(s: u32) i32 { return @bitCast(i32, s); } | ||
| 374 | pub fn WEXITSTATUS(s: i32) i32 { return signed((unsigned(s) & 0xff00) >> 8); } | ||
| 375 | pub fn WTERMSIG(s: i32) i32 { return signed(unsigned(s) & 0x7f); } | ||
| 376 | pub fn WSTOPSIG(s: i32) i32 { return WEXITSTATUS(s); } | ||
| 377 | pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; } | ||
| 378 | pub fn WIFSTOPPED(s: i32) bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; } | ||
| 379 | pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s)&0xffff)-%1 < 0xff; } | ||
| 380 | |||
| 381 | |||
| 382 | pub const winsize = extern struct { | ||
| 383 | ws_row: u16, | ||
| 384 | ws_col: u16, | ||
| 385 | ws_xpixel: u16, | ||
| 386 | ws_ypixel: u16, | ||
| 387 | }; | ||
| 388 | |||
| 389 | /// Get the errno from a syscall return value, or 0 for no error. | ||
| 390 | pub fn getErrno(r: usize) usize { | ||
| 391 | const signed_r = @bitCast(isize, r); | ||
| 392 | return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0; | ||
| 393 | } | ||
| 394 | |||
| 395 | pub fn dup2(old: i32, new: i32) usize { | ||
| 396 | return arch.syscall2(arch.SYS_dup2, usize(old), usize(new)); | ||
| 397 | } | ||
| 398 | |||
| 399 | pub fn chdir(path: &const u8) usize { | ||
| 400 | return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); | ||
| 401 | } | ||
| 402 | |||
| 403 | pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize { | ||
| 404 | return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); | ||
| 405 | } | ||
| 406 | |||
| 407 | pub fn fork() usize { | ||
| 408 | return arch.syscall0(arch.SYS_fork); | ||
| 409 | } | ||
| 410 | |||
| 411 | pub fn getcwd(buf: &u8, size: usize) usize { | ||
| 412 | return arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size); | ||
| 413 | } | ||
| 414 | |||
| 415 | pub fn getdents(fd: i32, dirp: &u8, count: usize) usize { | ||
| 416 | return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count); | ||
| 417 | } | ||
| 418 | |||
| 419 | pub fn isatty(fd: i32) bool { | ||
| 420 | var wsz: winsize = undefined; | ||
| 421 | return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | ||
| 422 | } | ||
| 423 | |||
| 424 | pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize { | ||
| 425 | return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | ||
| 426 | } | ||
| 427 | |||
| 428 | pub fn mkdir(path: &const u8, mode: u32) usize { | ||
| 429 | return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode); | ||
| 430 | } | ||
| 431 | |||
| 432 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { | ||
| 433 | return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), | ||
| 434 | @bitCast(usize, offset)); | ||
| 435 | } | ||
| 436 | |||
| 437 | pub fn munmap(address: &u8, length: usize) usize { | ||
| 438 | return arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length); | ||
| 439 | } | ||
| 440 | |||
| 441 | pub fn read(fd: i32, buf: &u8, count: usize) usize { | ||
| 442 | return arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count); | ||
| 443 | } | ||
| 444 | |||
| 445 | pub fn rmdir(path: &const u8) usize { | ||
| 446 | return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); | ||
| 447 | } | ||
| 448 | |||
| 449 | pub fn symlink(existing: &const u8, new: &const u8) usize { | ||
| 450 | return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); | ||
| 451 | } | ||
| 452 | |||
| 453 | pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize { | ||
| 454 | return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); | ||
| 455 | } | ||
| 456 | |||
| 457 | pub fn pipe(fd: &[2]i32) usize { | ||
| 458 | return pipe2(fd, 0); | ||
| 459 | } | ||
| 460 | |||
| 461 | pub fn pipe2(fd: &[2]i32, flags: usize) usize { | ||
| 462 | return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags); | ||
| 463 | } | ||
| 464 | |||
| 465 | pub fn write(fd: i32, buf: &const u8, count: usize) usize { | ||
| 466 | return arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count); | ||
| 467 | } | ||
| 468 | |||
| 469 | pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize { | ||
| 470 | return arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset); | ||
| 471 | } | ||
| 472 | |||
| 473 | pub fn rename(old: &const u8, new: &const u8) usize { | ||
| 474 | return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)); | ||
| 475 | } | ||
| 476 | |||
| 477 | pub fn open(path: &const u8, flags: u32, perm: usize) usize { | ||
| 478 | return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm); | ||
| 479 | } | ||
| 480 | |||
| 481 | pub fn create(path: &const u8, perm: usize) usize { | ||
| 482 | return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm); | ||
| 483 | } | ||
| 484 | |||
| 485 | pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize { | ||
| 486 | return arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode); | ||
| 487 | } | ||
| 488 | |||
| 489 | pub fn close(fd: i32) usize { | ||
| 490 | return arch.syscall1(arch.SYS_close, usize(fd)); | ||
| 491 | } | ||
| 492 | |||
| 493 | pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { | ||
| 494 | return arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos); | ||
| 495 | } | ||
| 496 | |||
| 497 | pub fn exit(status: i32) noreturn { | ||
| 498 | _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); | ||
| 499 | unreachable; | ||
| 500 | } | ||
| 501 | |||
| 502 | pub fn getrandom(buf: &u8, count: usize, flags: u32) usize { | ||
| 503 | return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags)); | ||
| 504 | } | ||
| 505 | |||
| 506 | pub fn kill(pid: i32, sig: i32) usize { | ||
| 507 | return arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig)); | ||
| 508 | } | ||
| 509 | |||
| 510 | pub fn unlink(path: &const u8) usize { | ||
| 511 | return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); | ||
| 512 | } | ||
| 513 | |||
| 514 | pub fn waitpid(pid: i32, status: &i32, options: i32) usize { | ||
| 515 | return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); | ||
| 516 | } | ||
| 517 | |||
| 518 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { | ||
| 519 | return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); | ||
| 520 | } | ||
| 521 | |||
| 522 | pub fn setuid(uid: u32) usize { | ||
| 523 | return arch.syscall1(arch.SYS_setuid, uid); | ||
| 524 | } | ||
| 525 | |||
| 526 | pub fn setgid(gid: u32) usize { | ||
| 527 | return arch.syscall1(arch.SYS_setgid, gid); | ||
| 528 | } | ||
| 529 | |||
| 530 | pub fn setreuid(ruid: u32, euid: u32) usize { | ||
| 531 | return arch.syscall2(arch.SYS_setreuid, ruid, euid); | ||
| 532 | } | ||
| 533 | |||
| 534 | pub fn setregid(rgid: u32, egid: u32) usize { | ||
| 535 | return arch.syscall2(arch.SYS_setregid, rgid, egid); | ||
| 536 | } | ||
| 537 | |||
| 538 | pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize { | ||
| 539 | return arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8); | ||
| 540 | } | ||
| 541 | |||
| 542 | pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize { | ||
| 543 | assert(sig >= 1); | ||
| 544 | assert(sig != SIGKILL); | ||
| 545 | assert(sig != SIGSTOP); | ||
| 546 | var ksa = k_sigaction { | ||
| 547 | .handler = act.handler, | ||
| 548 | .flags = act.flags | SA_RESTORER, | ||
| 549 | .mask = undefined, | ||
| 550 | .restorer = @ptrCast(extern fn()void, arch.restore_rt), | ||
| 551 | }; | ||
| 552 | var ksa_old: k_sigaction = undefined; | ||
| 553 | @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8); | ||
| 554 | const result = arch.syscall4(arch.SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask))); | ||
| 555 | const err = getErrno(result); | ||
| 556 | if (err != 0) { | ||
| 557 | return result; | ||
| 558 | } | ||
| 559 | if (oact) |old| { | ||
| 560 | old.handler = ksa_old.handler; | ||
| 561 | old.flags = @truncate(u32, ksa_old.flags); | ||
| 562 | @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask))); | ||
| 563 | } | ||
| 564 | return 0; | ||
| 565 | } | ||
| 566 | |||
| 567 | const NSIG = 65; | ||
| 568 | const sigset_t = [128 / @sizeOf(usize)]usize; | ||
| 569 | const all_mask = []usize{@maxValue(usize)}; | ||
| 570 | const app_mask = []usize{0xfffffffc7fffffff}; | ||
| 571 | |||
| 572 | const k_sigaction = extern struct { | ||
| 573 | handler: extern fn(i32)void, | ||
| 574 | flags: usize, | ||
| 575 | restorer: extern fn()void, | ||
| 576 | mask: [2]u32, | ||
| 577 | }; | ||
| 578 | |||
| 579 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 580 | pub const Sigaction = struct { | ||
| 581 | handler: extern fn(i32)void, | ||
| 582 | mask: sigset_t, | ||
| 583 | flags: u32, | ||
| 584 | }; | ||
| 585 | |||
| 586 | pub const SIG_ERR = @intToPtr(extern fn(i32)void, @maxValue(usize)); | ||
| 587 | pub const SIG_DFL = @intToPtr(extern fn(i32)void, 0); | ||
| 588 | pub const SIG_IGN = @intToPtr(extern fn(i32)void, 1); | ||
| 589 | pub const empty_sigset = []usize{0} ** sigset_t.len; | ||
| 590 | |||
| 591 | pub fn raise(sig: i32) usize { | ||
| 592 | var set: sigset_t = undefined; | ||
| 593 | blockAppSignals(&set); | ||
| 594 | const tid = i32(arch.syscall0(arch.SYS_gettid)); | ||
| 595 | const ret = arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig)); | ||
| 596 | restoreSignals(&set); | ||
| 597 | return ret; | ||
| 598 | } | ||
| 599 | |||
| 600 | fn blockAllSignals(set: &sigset_t) void { | ||
| 601 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8); | ||
| 602 | } | ||
| 603 | |||
| 604 | fn blockAppSignals(set: &sigset_t) void { | ||
| 605 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8); | ||
| 606 | } | ||
| 607 | |||
| 608 | fn restoreSignals(set: &sigset_t) void { | ||
| 609 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8); | ||
| 610 | } | ||
| 611 | |||
| 612 | pub fn sigaddset(set: &sigset_t, sig: u6) void { | ||
| 613 | const s = sig - 1; | ||
| 614 | (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); | ||
| 615 | } | ||
| 616 | |||
| 617 | pub fn sigismember(set: &const sigset_t, sig: u6) bool { | ||
| 618 | const s = sig - 1; | ||
| 619 | return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; | ||
| 620 | } | ||
| 621 | |||
| 622 | |||
| 623 | pub const sa_family_t = u16; | ||
| 624 | pub const socklen_t = u32; | ||
| 625 | pub const in_addr = u32; | ||
| 626 | pub const in6_addr = [16]u8; | ||
| 627 | |||
| 628 | pub const sockaddr = extern struct { | ||
| 629 | family: sa_family_t, | ||
| 630 | port: u16, | ||
| 631 | data: [12]u8, | ||
| 632 | }; | ||
| 633 | |||
| 634 | pub const sockaddr_in = extern struct { | ||
| 635 | family: sa_family_t, | ||
| 636 | port: u16, | ||
| 637 | addr: in_addr, | ||
| 638 | zero: [8]u8, | ||
| 639 | }; | ||
| 640 | |||
| 641 | pub const sockaddr_in6 = extern struct { | ||
| 642 | family: sa_family_t, | ||
| 643 | port: u16, | ||
| 644 | flowinfo: u32, | ||
| 645 | addr: in6_addr, | ||
| 646 | scope_id: u32, | ||
| 647 | }; | ||
| 648 | |||
| 649 | pub const iovec = extern struct { | ||
| 650 | iov_base: &u8, | ||
| 651 | iov_len: usize, | ||
| 652 | }; | ||
| 653 | |||
| 654 | pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { | ||
| 655 | return arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len)); | ||
| 656 | } | ||
| 657 | |||
| 658 | pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { | ||
| 659 | return arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len)); | ||
| 660 | } | ||
| 661 | |||
| 662 | pub fn socket(domain: i32, socket_type: i32, protocol: i32) usize { | ||
| 663 | return arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol)); | ||
| 664 | } | ||
| 665 | |||
| 666 | pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) usize { | ||
| 667 | return arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen)); | ||
| 668 | } | ||
| 669 | |||
| 670 | pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) usize { | ||
| 671 | return arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen)); | ||
| 672 | } | ||
| 673 | |||
| 674 | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) usize { | ||
| 675 | return arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags); | ||
| 676 | } | ||
| 677 | |||
| 678 | pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize { | ||
| 679 | return arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len)); | ||
| 680 | } | ||
| 681 | |||
| 682 | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) usize { | ||
| 683 | return arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags); | ||
| 684 | } | ||
| 685 | |||
| 686 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, | ||
| 687 | noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize | ||
| 688 | { | ||
| 689 | return arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); | ||
| 690 | } | ||
| 691 | |||
| 692 | pub fn shutdown(fd: i32, how: i32) usize { | ||
| 693 | return arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)); | ||
| 694 | } | ||
| 695 | |||
| 696 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize { | ||
| 697 | return arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len)); | ||
| 698 | } | ||
| 699 | |||
| 700 | pub fn listen(fd: i32, backlog: i32) usize { | ||
| 701 | return arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)); | ||
| 702 | } | ||
| 703 | |||
| 704 | pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize { | ||
| 705 | return arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen)); | ||
| 706 | } | ||
| 707 | |||
| 708 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { | ||
| 709 | return arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0])); | ||
| 710 | } | ||
| 711 | |||
| 712 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { | ||
| 713 | return accept4(fd, addr, len, 0); | ||
| 714 | } | ||
| 715 | |||
| 716 | pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize { | ||
| 717 | return arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags); | ||
| 718 | } | ||
| 719 | |||
| 720 | // error NameTooLong; | ||
| 721 | // error SystemResources; | ||
| 722 | // error Io; | ||
| 723 | // | ||
| 724 | // pub fn if_nametoindex(name: []u8) %u32 { | ||
| 725 | // var ifr: ifreq = undefined; | ||
| 726 | // | ||
| 727 | // if (name.len >= ifr.ifr_name.len) { | ||
| 728 | // return error.NameTooLong; | ||
| 729 | // } | ||
| 730 | // | ||
| 731 | // const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); | ||
| 732 | // const socket_err = getErrno(socket_ret); | ||
| 733 | // if (socket_err > 0) { | ||
| 734 | // return error.SystemResources; | ||
| 735 | // } | ||
| 736 | // const socket_fd = i32(socket_ret); | ||
| 737 | // @memcpy(&ifr.ifr_name[0], &name[0], name.len); | ||
| 738 | // ifr.ifr_name[name.len] = 0; | ||
| 739 | // const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr); | ||
| 740 | // close(socket_fd); | ||
| 741 | // const ioctl_err = getErrno(ioctl_ret); | ||
| 742 | // if (ioctl_err > 0) { | ||
| 743 | // return error.Io; | ||
| 744 | // } | ||
| 745 | // return ifr.ifr_ifindex; | ||
| 746 | // } | ||
| 747 | |||
| 748 | pub const Stat = arch.Stat; | ||
| 749 | pub const timespec = arch.timespec; | ||
| 750 | |||
| 751 | pub fn fstat(fd: i32, stat_buf: &Stat) usize { | ||
| 752 | return arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)); | ||
| 753 | } | ||
| 754 | |||
| 755 | pub const epoll_data = u64; | ||
| 756 | |||
| 757 | pub const epoll_event = extern struct { | ||
| 758 | events: u32, | ||
| 759 | data: epoll_data | ||
| 760 | }; | ||
| 761 | |||
| 762 | pub fn epoll_create() usize { | ||
| 763 | return arch.syscall1(arch.SYS_epoll_create, usize(1)); | ||
| 764 | } | ||
| 765 | |||
| 766 | pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) usize { | ||
| 767 | return arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev)); | ||
| 768 | } | ||
| 769 | |||
| 770 | pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) usize { | ||
| 771 | return arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout)); | ||
| 772 | } | ||
| 773 | |||
| 774 | pub fn timerfd_create(clockid: i32, flags: u32) usize { | ||
| 775 | return arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags)); | ||
| 776 | } | ||
| 777 | |||
| 778 | pub const itimerspec = extern struct { | ||
| 779 | it_interval: timespec, | ||
| 780 | it_value: timespec | ||
| 781 | }; | ||
| 782 | |||
| 783 | pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize { | ||
| 784 | return arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value)); | ||
| 785 | } | ||
| 786 | |||
| 787 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize { | ||
| 788 | return arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value)); | ||
| 789 | } | ||
| 790 | |||
| 791 | test "import linux_test" { | ||
| 792 | // TODO lazy analysis should prevent this test from being compiled on windows, but | ||
| 793 | // it is still compiled on windows | ||
| 794 | if (builtin.os == builtin.Os.linux) { | ||
| 795 | _ = @import("linux_test.zig"); | ||
| 796 | } | ||
| 797 | } | ||
std/os/linux/errno.zig created+146| ... | @@ -0,0 +1,146 @@ | ||
| 1 | pub const EPERM = 1; /// Operation not permitted | ||
| 2 | pub const ENOENT = 2; /// No such file or directory | ||
| 3 | pub const ESRCH = 3; /// No such process | ||
| 4 | pub const EINTR = 4; /// Interrupted system call | ||
| 5 | pub const EIO = 5; /// I/O error | ||
| 6 | pub const ENXIO = 6; /// No such device or address | ||
| 7 | pub const E2BIG = 7; /// Arg list too long | ||
| 8 | pub const ENOEXEC = 8; /// Exec format error | ||
| 9 | pub const EBADF = 9; /// Bad file number | ||
| 10 | pub const ECHILD = 10; /// No child processes | ||
| 11 | pub const EAGAIN = 11; /// Try again | ||
| 12 | pub const ENOMEM = 12; /// Out of memory | ||
| 13 | pub const EACCES = 13; /// Permission denied | ||
| 14 | pub const EFAULT = 14; /// Bad address | ||
| 15 | pub const ENOTBLK = 15; /// Block device required | ||
| 16 | pub const EBUSY = 16; /// Device or resource busy | ||
| 17 | pub const EEXIST = 17; /// File exists | ||
| 18 | pub const EXDEV = 18; /// Cross-device link | ||
| 19 | pub const ENODEV = 19; /// No such device | ||
| 20 | pub const ENOTDIR = 20; /// Not a directory | ||
| 21 | pub const EISDIR = 21; /// Is a directory | ||
| 22 | pub const EINVAL = 22; /// Invalid argument | ||
| 23 | pub const ENFILE = 23; /// File table overflow | ||
| 24 | pub const EMFILE = 24; /// Too many open files | ||
| 25 | pub const ENOTTY = 25; /// Not a typewriter | ||
| 26 | pub const ETXTBSY = 26; /// Text file busy | ||
| 27 | pub const EFBIG = 27; /// File too large | ||
| 28 | pub const ENOSPC = 28; /// No space left on device | ||
| 29 | pub const ESPIPE = 29; /// Illegal seek | ||
| 30 | pub const EROFS = 30; /// Read-only file system | ||
| 31 | pub const EMLINK = 31; /// Too many links | ||
| 32 | pub const EPIPE = 32; /// Broken pipe | ||
| 33 | pub const EDOM = 33; /// Math argument out of domain of func | ||
| 34 | pub const ERANGE = 34; /// Math result not representable | ||
| 35 | pub const EDEADLK = 35; /// Resource deadlock would occur | ||
| 36 | pub const ENAMETOOLONG = 36; /// File name too long | ||
| 37 | pub const ENOLCK = 37; /// No record locks available | ||
| 38 | pub const ENOSYS = 38; /// Function not implemented | ||
| 39 | pub const ENOTEMPTY = 39; /// Directory not empty | ||
| 40 | pub const ELOOP = 40; /// Too many symbolic links encountered | ||
| 41 | pub const EWOULDBLOCK = EAGAIN; /// Operation would block | ||
| 42 | pub const ENOMSG = 42; /// No message of desired type | ||
| 43 | pub const EIDRM = 43; /// Identifier removed | ||
| 44 | pub const ECHRNG = 44; /// Channel number out of range | ||
| 45 | pub const EL2NSYNC = 45; /// Level 2 not synchronized | ||
| 46 | pub const EL3HLT = 46; /// Level 3 halted | ||
| 47 | pub const EL3RST = 47; /// Level 3 reset | ||
| 48 | pub const ELNRNG = 48; /// Link number out of range | ||
| 49 | pub const EUNATCH = 49; /// Protocol driver not attached | ||
| 50 | pub const ENOCSI = 50; /// No CSI structure available | ||
| 51 | pub const EL2HLT = 51; /// Level 2 halted | ||
| 52 | pub const EBADE = 52; /// Invalid exchange | ||
| 53 | pub const EBADR = 53; /// Invalid request descriptor | ||
| 54 | pub const EXFULL = 54; /// Exchange full | ||
| 55 | pub const ENOANO = 55; /// No anode | ||
| 56 | pub const EBADRQC = 56; /// Invalid request code | ||
| 57 | pub const EBADSLT = 57; /// Invalid slot | ||
| 58 | |||
| 59 | pub const EBFONT = 59; /// Bad font file format | ||
| 60 | pub const ENOSTR = 60; /// Device not a stream | ||
| 61 | pub const ENODATA = 61; /// No data available | ||
| 62 | pub const ETIME = 62; /// Timer expired | ||
| 63 | pub const ENOSR = 63; /// Out of streams resources | ||
| 64 | pub const ENONET = 64; /// Machine is not on the network | ||
| 65 | pub const ENOPKG = 65; /// Package not installed | ||
| 66 | pub const EREMOTE = 66; /// Object is remote | ||
| 67 | pub const ENOLINK = 67; /// Link has been severed | ||
| 68 | pub const EADV = 68; /// Advertise error | ||
| 69 | pub const ESRMNT = 69; /// Srmount error | ||
| 70 | pub const ECOMM = 70; /// Communication error on send | ||
| 71 | pub const EPROTO = 71; /// Protocol error | ||
| 72 | pub const EMULTIHOP = 72; /// Multihop attempted | ||
| 73 | pub const EDOTDOT = 73; /// RFS specific error | ||
| 74 | pub const EBADMSG = 74; /// Not a data message | ||
| 75 | pub const EOVERFLOW = 75; /// Value too large for defined data type | ||
| 76 | pub const ENOTUNIQ = 76; /// Name not unique on network | ||
| 77 | pub const EBADFD = 77; /// File descriptor in bad state | ||
| 78 | pub const EREMCHG = 78; /// Remote address changed | ||
| 79 | pub const ELIBACC = 79; /// Can not access a needed shared library | ||
| 80 | pub const ELIBBAD = 80; /// Accessing a corrupted shared library | ||
| 81 | pub const ELIBSCN = 81; /// .lib section in a.out corrupted | ||
| 82 | pub const ELIBMAX = 82; /// Attempting to link in too many shared libraries | ||
| 83 | pub const ELIBEXEC = 83; /// Cannot exec a shared library directly | ||
| 84 | pub const EILSEQ = 84; /// Illegal byte sequence | ||
| 85 | pub const ERESTART = 85; /// Interrupted system call should be restarted | ||
| 86 | pub const ESTRPIPE = 86; /// Streams pipe error | ||
| 87 | pub const EUSERS = 87; /// Too many users | ||
| 88 | pub const ENOTSOCK = 88; /// Socket operation on non-socket | ||
| 89 | pub const EDESTADDRREQ = 89; /// Destination address required | ||
| 90 | pub const EMSGSIZE = 90; /// Message too long | ||
| 91 | pub const EPROTOTYPE = 91; /// Protocol wrong type for socket | ||
| 92 | pub const ENOPROTOOPT = 92; /// Protocol not available | ||
| 93 | pub const EPROTONOSUPPORT = 93; /// Protocol not supported | ||
| 94 | pub const ESOCKTNOSUPPORT = 94; /// Socket type not supported | ||
| 95 | pub const EOPNOTSUPP = 95; /// Operation not supported on transport endpoint | ||
| 96 | pub const EPFNOSUPPORT = 96; /// Protocol family not supported | ||
| 97 | pub const EAFNOSUPPORT = 97; /// Address family not supported by protocol | ||
| 98 | pub const EADDRINUSE = 98; /// Address already in use | ||
| 99 | pub const EADDRNOTAVAIL = 99; /// Cannot assign requested address | ||
| 100 | pub const ENETDOWN = 100; /// Network is down | ||
| 101 | pub const ENETUNREACH = 101; /// Network is unreachable | ||
| 102 | pub const ENETRESET = 102; /// Network dropped connection because of reset | ||
| 103 | pub const ECONNABORTED = 103; /// Software caused connection abort | ||
| 104 | pub const ECONNRESET = 104; /// Connection reset by peer | ||
| 105 | pub const ENOBUFS = 105; /// No buffer space available | ||
| 106 | pub const EISCONN = 106; /// Transport endpoint is already connected | ||
| 107 | pub const ENOTCONN = 107; /// Transport endpoint is not connected | ||
| 108 | pub const ESHUTDOWN = 108; /// Cannot send after transport endpoint shutdown | ||
| 109 | pub const ETOOMANYREFS = 109; /// Too many references: cannot splice | ||
| 110 | pub const ETIMEDOUT = 110; /// Connection timed out | ||
| 111 | pub const ECONNREFUSED = 111; /// Connection refused | ||
| 112 | pub const EHOSTDOWN = 112; /// Host is down | ||
| 113 | pub const EHOSTUNREACH = 113; /// No route to host | ||
| 114 | pub const EALREADY = 114; /// Operation already in progress | ||
| 115 | pub const EINPROGRESS = 115; /// Operation now in progress | ||
| 116 | pub const ESTALE = 116; /// Stale NFS file handle | ||
| 117 | pub const EUCLEAN = 117; /// Structure needs cleaning | ||
| 118 | pub const ENOTNAM = 118; /// Not a XENIX named type file | ||
| 119 | pub const ENAVAIL = 119; /// No XENIX semaphores available | ||
| 120 | pub const EISNAM = 120; /// Is a named type file | ||
| 121 | pub const EREMOTEIO = 121; /// Remote I/O error | ||
| 122 | pub const EDQUOT = 122; /// Quota exceeded | ||
| 123 | |||
| 124 | pub const ENOMEDIUM = 123; /// No medium found | ||
| 125 | pub const EMEDIUMTYPE = 124; /// Wrong medium type | ||
| 126 | |||
| 127 | // nameserver query return codes | ||
| 128 | pub const ENSROK = 0; /// DNS server returned answer with no data | ||
| 129 | pub const ENSRNODATA = 160; /// DNS server returned answer with no data | ||
| 130 | pub const ENSRFORMERR = 161; /// DNS server claims query was misformatted | ||
| 131 | pub const ENSRSERVFAIL = 162; /// DNS server returned general failure | ||
| 132 | pub const ENSRNOTFOUND = 163; /// Domain name not found | ||
| 133 | pub const ENSRNOTIMP = 164; /// DNS server does not implement requested operation | ||
| 134 | pub const ENSRREFUSED = 165; /// DNS server refused query | ||
| 135 | pub const ENSRBADQUERY = 166; /// Misformatted DNS query | ||
| 136 | pub const ENSRBADNAME = 167; /// Misformatted domain name | ||
| 137 | pub const ENSRBADFAMILY = 168; /// Unsupported address family | ||
| 138 | pub const ENSRBADRESP = 169; /// Misformatted DNS reply | ||
| 139 | pub const ENSRCONNREFUSED = 170; /// Could not contact DNS servers | ||
| 140 | pub const ENSRTIMEOUT = 171; /// Timeout while contacting DNS servers | ||
| 141 | pub const ENSROF = 172; /// End of file | ||
| 142 | pub const ENSRFILE = 173; /// Error reading file | ||
| 143 | pub const ENSRNOMEM = 174; /// Out of memory | ||
| 144 | pub const ENSRDESTRUCTION = 175; /// Application terminated lookup | ||
| 145 | pub const ENSRQUERYDOMAINTOOLONG = 176; /// Domain name is too long | ||
| 146 | pub const ENSRCNAMELOOP = 177; /// Domain name is too long | ||
std/os/linux/i386.zig created+505| ... | @@ -0,0 +1,505 @@ | ||
| 1 | const std = @import("../../index.zig"); | ||
| 2 | const linux = std.os.linux; | ||
| 3 | const socklen_t = linux.socklen_t; | ||
| 4 | const iovec = linux.iovec; | ||
| 5 | |||
| 6 | pub const SYS_restart_syscall = 0; | ||
| 7 | pub const SYS_exit = 1; | ||
| 8 | pub const SYS_fork = 2; | ||
| 9 | pub const SYS_read = 3; | ||
| 10 | pub const SYS_write = 4; | ||
| 11 | pub const SYS_open = 5; | ||
| 12 | pub const SYS_close = 6; | ||
| 13 | pub const SYS_waitpid = 7; | ||
| 14 | pub const SYS_creat = 8; | ||
| 15 | pub const SYS_link = 9; | ||
| 16 | pub const SYS_unlink = 10; | ||
| 17 | pub const SYS_execve = 11; | ||
| 18 | pub const SYS_chdir = 12; | ||
| 19 | pub const SYS_time = 13; | ||
| 20 | pub const SYS_mknod = 14; | ||
| 21 | pub const SYS_chmod = 15; | ||
| 22 | pub const SYS_lchown = 16; | ||
| 23 | pub const SYS_break = 17; | ||
| 24 | pub const SYS_oldstat = 18; | ||
| 25 | pub const SYS_lseek = 19; | ||
| 26 | pub const SYS_getpid = 20; | ||
| 27 | pub const SYS_mount = 21; | ||
| 28 | pub const SYS_umount = 22; | ||
| 29 | pub const SYS_setuid = 23; | ||
| 30 | pub const SYS_getuid = 24; | ||
| 31 | pub const SYS_stime = 25; | ||
| 32 | pub const SYS_ptrace = 26; | ||
| 33 | pub const SYS_alarm = 27; | ||
| 34 | pub const SYS_oldfstat = 28; | ||
| 35 | pub const SYS_pause = 29; | ||
| 36 | pub const SYS_utime = 30; | ||
| 37 | pub const SYS_stty = 31; | ||
| 38 | pub const SYS_gtty = 32; | ||
| 39 | pub const SYS_access = 33; | ||
| 40 | pub const SYS_nice = 34; | ||
| 41 | pub const SYS_ftime = 35; | ||
| 42 | pub const SYS_sync = 36; | ||
| 43 | pub const SYS_kill = 37; | ||
| 44 | pub const SYS_rename = 38; | ||
| 45 | pub const SYS_mkdir = 39; | ||
| 46 | pub const SYS_rmdir = 40; | ||
| 47 | pub const SYS_dup = 41; | ||
| 48 | pub const SYS_pipe = 42; | ||
| 49 | pub const SYS_times = 43; | ||
| 50 | pub const SYS_prof = 44; | ||
| 51 | pub const SYS_brk = 45; | ||
| 52 | pub const SYS_setgid = 46; | ||
| 53 | pub const SYS_getgid = 47; | ||
| 54 | pub const SYS_signal = 48; | ||
| 55 | pub const SYS_geteuid = 49; | ||
| 56 | pub const SYS_getegid = 50; | ||
| 57 | pub const SYS_acct = 51; | ||
| 58 | pub const SYS_umount2 = 52; | ||
| 59 | pub const SYS_lock = 53; | ||
| 60 | pub const SYS_ioctl = 54; | ||
| 61 | pub const SYS_fcntl = 55; | ||
| 62 | pub const SYS_mpx = 56; | ||
| 63 | pub const SYS_setpgid = 57; | ||
| 64 | pub const SYS_ulimit = 58; | ||
| 65 | pub const SYS_oldolduname = 59; | ||
| 66 | pub const SYS_umask = 60; | ||
| 67 | pub const SYS_chroot = 61; | ||
| 68 | pub const SYS_ustat = 62; | ||
| 69 | pub const SYS_dup2 = 63; | ||
| 70 | pub const SYS_getppid = 64; | ||
| 71 | pub const SYS_getpgrp = 65; | ||
| 72 | pub const SYS_setsid = 66; | ||
| 73 | pub const SYS_sigaction = 67; | ||
| 74 | pub const SYS_sgetmask = 68; | ||
| 75 | pub const SYS_ssetmask = 69; | ||
| 76 | pub const SYS_setreuid = 70; | ||
| 77 | pub const SYS_setregid = 71; | ||
| 78 | pub const SYS_sigsuspend = 72; | ||
| 79 | pub const SYS_sigpending = 73; | ||
| 80 | pub const SYS_sethostname = 74; | ||
| 81 | pub const SYS_setrlimit = 75; | ||
| 82 | pub const SYS_getrlimit = 76; | ||
| 83 | pub const SYS_getrusage = 77; | ||
| 84 | pub const SYS_gettimeofday = 78; | ||
| 85 | pub const SYS_settimeofday = 79; | ||
| 86 | pub const SYS_getgroups = 80; | ||
| 87 | pub const SYS_setgroups = 81; | ||
| 88 | pub const SYS_select = 82; | ||
| 89 | pub const SYS_symlink = 83; | ||
| 90 | pub const SYS_oldlstat = 84; | ||
| 91 | pub const SYS_readlink = 85; | ||
| 92 | pub const SYS_uselib = 86; | ||
| 93 | pub const SYS_swapon = 87; | ||
| 94 | pub const SYS_reboot = 88; | ||
| 95 | pub const SYS_readdir = 89; | ||
| 96 | pub const SYS_mmap = 90; | ||
| 97 | pub const SYS_munmap = 91; | ||
| 98 | pub const SYS_truncate = 92; | ||
| 99 | pub const SYS_ftruncate = 93; | ||
| 100 | pub const SYS_fchmod = 94; | ||
| 101 | pub const SYS_fchown = 95; | ||
| 102 | pub const SYS_getpriority = 96; | ||
| 103 | pub const SYS_setpriority = 97; | ||
| 104 | pub const SYS_profil = 98; | ||
| 105 | pub const SYS_statfs = 99; | ||
| 106 | pub const SYS_fstatfs = 100; | ||
| 107 | pub const SYS_ioperm = 101; | ||
| 108 | pub const SYS_socketcall = 102; | ||
| 109 | pub const SYS_syslog = 103; | ||
| 110 | pub const SYS_setitimer = 104; | ||
| 111 | pub const SYS_getitimer = 105; | ||
| 112 | pub const SYS_stat = 106; | ||
| 113 | pub const SYS_lstat = 107; | ||
| 114 | pub const SYS_fstat = 108; | ||
| 115 | pub const SYS_olduname = 109; | ||
| 116 | pub const SYS_iopl = 110; | ||
| 117 | pub const SYS_vhangup = 111; | ||
| 118 | pub const SYS_idle = 112; | ||
| 119 | pub const SYS_vm86old = 113; | ||
| 120 | pub const SYS_wait4 = 114; | ||
| 121 | pub const SYS_swapoff = 115; | ||
| 122 | pub const SYS_sysinfo = 116; | ||
| 123 | pub const SYS_ipc = 117; | ||
| 124 | pub const SYS_fsync = 118; | ||
| 125 | pub const SYS_sigreturn = 119; | ||
| 126 | pub const SYS_clone = 120; | ||
| 127 | pub const SYS_setdomainname = 121; | ||
| 128 | pub const SYS_uname = 122; | ||
| 129 | pub const SYS_modify_ldt = 123; | ||
| 130 | pub const SYS_adjtimex = 124; | ||
| 131 | pub const SYS_mprotect = 125; | ||
| 132 | pub const SYS_sigprocmask = 126; | ||
| 133 | pub const SYS_create_module = 127; | ||
| 134 | pub const SYS_init_module = 128; | ||
| 135 | pub const SYS_delete_module = 129; | ||
| 136 | pub const SYS_get_kernel_syms = 130; | ||
| 137 | pub const SYS_quotactl = 131; | ||
| 138 | pub const SYS_getpgid = 132; | ||
| 139 | pub const SYS_fchdir = 133; | ||
| 140 | pub const SYS_bdflush = 134; | ||
| 141 | pub const SYS_sysfs = 135; | ||
| 142 | pub const SYS_personality = 136; | ||
| 143 | pub const SYS_afs_syscall = 137; | ||
| 144 | pub const SYS_setfsuid = 138; | ||
| 145 | pub const SYS_setfsgid = 139; | ||
| 146 | pub const SYS__llseek = 140; | ||
| 147 | pub const SYS_getdents = 141; | ||
| 148 | pub const SYS__newselect = 142; | ||
| 149 | pub const SYS_flock = 143; | ||
| 150 | pub const SYS_msync = 144; | ||
| 151 | pub const SYS_readv = 145; | ||
| 152 | pub const SYS_writev = 146; | ||
| 153 | pub const SYS_getsid = 147; | ||
| 154 | pub const SYS_fdatasync = 148; | ||
| 155 | pub const SYS__sysctl = 149; | ||
| 156 | pub const SYS_mlock = 150; | ||
| 157 | pub const SYS_munlock = 151; | ||
| 158 | pub const SYS_mlockall = 152; | ||
| 159 | pub const SYS_munlockall = 153; | ||
| 160 | pub const SYS_sched_setparam = 154; | ||
| 161 | pub const SYS_sched_getparam = 155; | ||
| 162 | pub const SYS_sched_setscheduler = 156; | ||
| 163 | pub const SYS_sched_getscheduler = 157; | ||
| 164 | pub const SYS_sched_yield = 158; | ||
| 165 | pub const SYS_sched_get_priority_max = 159; | ||
| 166 | pub const SYS_sched_get_priority_min = 160; | ||
| 167 | pub const SYS_sched_rr_get_interval = 161; | ||
| 168 | pub const SYS_nanosleep = 162; | ||
| 169 | pub const SYS_mremap = 163; | ||
| 170 | pub const SYS_setresuid = 164; | ||
| 171 | pub const SYS_getresuid = 165; | ||
| 172 | pub const SYS_vm86 = 166; | ||
| 173 | pub const SYS_query_module = 167; | ||
| 174 | pub const SYS_poll = 168; | ||
| 175 | pub const SYS_nfsservctl = 169; | ||
| 176 | pub const SYS_setresgid = 170; | ||
| 177 | pub const SYS_getresgid = 171; | ||
| 178 | pub const SYS_prctl = 172; | ||
| 179 | pub const SYS_rt_sigreturn = 173; | ||
| 180 | pub const SYS_rt_sigaction = 174; | ||
| 181 | pub const SYS_rt_sigprocmask = 175; | ||
| 182 | pub const SYS_rt_sigpending = 176; | ||
| 183 | pub const SYS_rt_sigtimedwait = 177; | ||
| 184 | pub const SYS_rt_sigqueueinfo = 178; | ||
| 185 | pub const SYS_rt_sigsuspend = 179; | ||
| 186 | pub const SYS_pread64 = 180; | ||
| 187 | pub const SYS_pwrite64 = 181; | ||
| 188 | pub const SYS_chown = 182; | ||
| 189 | pub const SYS_getcwd = 183; | ||
| 190 | pub const SYS_capget = 184; | ||
| 191 | pub const SYS_capset = 185; | ||
| 192 | pub const SYS_sigaltstack = 186; | ||
| 193 | pub const SYS_sendfile = 187; | ||
| 194 | pub const SYS_getpmsg = 188; | ||
| 195 | pub const SYS_putpmsg = 189; | ||
| 196 | pub const SYS_vfork = 190; | ||
| 197 | pub const SYS_ugetrlimit = 191; | ||
| 198 | pub const SYS_mmap2 = 192; | ||
| 199 | pub const SYS_truncate64 = 193; | ||
| 200 | pub const SYS_ftruncate64 = 194; | ||
| 201 | pub const SYS_stat64 = 195; | ||
| 202 | pub const SYS_lstat64 = 196; | ||
| 203 | pub const SYS_fstat64 = 197; | ||
| 204 | pub const SYS_lchown32 = 198; | ||
| 205 | pub const SYS_getuid32 = 199; | ||
| 206 | pub const SYS_getgid32 = 200; | ||
| 207 | pub const SYS_geteuid32 = 201; | ||
| 208 | pub const SYS_getegid32 = 202; | ||
| 209 | pub const SYS_setreuid32 = 203; | ||
| 210 | pub const SYS_setregid32 = 204; | ||
| 211 | pub const SYS_getgroups32 = 205; | ||
| 212 | pub const SYS_setgroups32 = 206; | ||
| 213 | pub const SYS_fchown32 = 207; | ||
| 214 | pub const SYS_setresuid32 = 208; | ||
| 215 | pub const SYS_getresuid32 = 209; | ||
| 216 | pub const SYS_setresgid32 = 210; | ||
| 217 | pub const SYS_getresgid32 = 211; | ||
| 218 | pub const SYS_chown32 = 212; | ||
| 219 | pub const SYS_setuid32 = 213; | ||
| 220 | pub const SYS_setgid32 = 214; | ||
| 221 | pub const SYS_setfsuid32 = 215; | ||
| 222 | pub const SYS_setfsgid32 = 216; | ||
| 223 | pub const SYS_pivot_root = 217; | ||
| 224 | pub const SYS_mincore = 218; | ||
| 225 | pub const SYS_madvise = 219; | ||
| 226 | pub const SYS_madvise1 = 219; | ||
| 227 | pub const SYS_getdents64 = 220; | ||
| 228 | pub const SYS_fcntl64 = 221; | ||
| 229 | pub const SYS_gettid = 224; | ||
| 230 | pub const SYS_readahead = 225; | ||
| 231 | pub const SYS_setxattr = 226; | ||
| 232 | pub const SYS_lsetxattr = 227; | ||
| 233 | pub const SYS_fsetxattr = 228; | ||
| 234 | pub const SYS_getxattr = 229; | ||
| 235 | pub const SYS_lgetxattr = 230; | ||
| 236 | pub const SYS_fgetxattr = 231; | ||
| 237 | pub const SYS_listxattr = 232; | ||
| 238 | pub const SYS_llistxattr = 233; | ||
| 239 | pub const SYS_flistxattr = 234; | ||
| 240 | pub const SYS_removexattr = 235; | ||
| 241 | pub const SYS_lremovexattr = 236; | ||
| 242 | pub const SYS_fremovexattr = 237; | ||
| 243 | pub const SYS_tkill = 238; | ||
| 244 | pub const SYS_sendfile64 = 239; | ||
| 245 | pub const SYS_futex = 240; | ||
| 246 | pub const SYS_sched_setaffinity = 241; | ||
| 247 | pub const SYS_sched_getaffinity = 242; | ||
| 248 | pub const SYS_set_thread_area = 243; | ||
| 249 | pub const SYS_get_thread_area = 244; | ||
| 250 | pub const SYS_io_setup = 245; | ||
| 251 | pub const SYS_io_destroy = 246; | ||
| 252 | pub const SYS_io_getevents = 247; | ||
| 253 | pub const SYS_io_submit = 248; | ||
| 254 | pub const SYS_io_cancel = 249; | ||
| 255 | pub const SYS_fadvise64 = 250; | ||
| 256 | pub const SYS_exit_group = 252; | ||
| 257 | pub const SYS_lookup_dcookie = 253; | ||
| 258 | pub const SYS_epoll_create = 254; | ||
| 259 | pub const SYS_epoll_ctl = 255; | ||
| 260 | pub const SYS_epoll_wait = 256; | ||
| 261 | pub const SYS_remap_file_pages = 257; | ||
| 262 | pub const SYS_set_tid_address = 258; | ||
| 263 | pub const SYS_timer_create = 259; | ||
| 264 | pub const SYS_timer_settime = SYS_timer_create+1; | ||
| 265 | pub const SYS_timer_gettime = SYS_timer_create+2; | ||
| 266 | pub const SYS_timer_getoverrun = SYS_timer_create+3; | ||
| 267 | pub const SYS_timer_delete = SYS_timer_create+4; | ||
| 268 | pub const SYS_clock_settime = SYS_timer_create+5; | ||
| 269 | pub const SYS_clock_gettime = SYS_timer_create+6; | ||
| 270 | pub const SYS_clock_getres = SYS_timer_create+7; | ||
| 271 | pub const SYS_clock_nanosleep = SYS_timer_create+8; | ||
| 272 | pub const SYS_statfs64 = 268; | ||
| 273 | pub const SYS_fstatfs64 = 269; | ||
| 274 | pub const SYS_tgkill = 270; | ||
| 275 | pub const SYS_utimes = 271; | ||
| 276 | pub const SYS_fadvise64_64 = 272; | ||
| 277 | pub const SYS_vserver = 273; | ||
| 278 | pub const SYS_mbind = 274; | ||
| 279 | pub const SYS_get_mempolicy = 275; | ||
| 280 | pub const SYS_set_mempolicy = 276; | ||
| 281 | pub const SYS_mq_open = 277; | ||
| 282 | pub const SYS_mq_unlink = SYS_mq_open+1; | ||
| 283 | pub const SYS_mq_timedsend = SYS_mq_open+2; | ||
| 284 | pub const SYS_mq_timedreceive = SYS_mq_open+3; | ||
| 285 | pub const SYS_mq_notify = SYS_mq_open+4; | ||
| 286 | pub const SYS_mq_getsetattr = SYS_mq_open+5; | ||
| 287 | pub const SYS_kexec_load = 283; | ||
| 288 | pub const SYS_waitid = 284; | ||
| 289 | pub const SYS_add_key = 286; | ||
| 290 | pub const SYS_request_key = 287; | ||
| 291 | pub const SYS_keyctl = 288; | ||
| 292 | pub const SYS_ioprio_set = 289; | ||
| 293 | pub const SYS_ioprio_get = 290; | ||
| 294 | pub const SYS_inotify_init = 291; | ||
| 295 | pub const SYS_inotify_add_watch = 292; | ||
| 296 | pub const SYS_inotify_rm_watch = 293; | ||
| 297 | pub const SYS_migrate_pages = 294; | ||
| 298 | pub const SYS_openat = 295; | ||
| 299 | pub const SYS_mkdirat = 296; | ||
| 300 | pub const SYS_mknodat = 297; | ||
| 301 | pub const SYS_fchownat = 298; | ||
| 302 | pub const SYS_futimesat = 299; | ||
| 303 | pub const SYS_fstatat64 = 300; | ||
| 304 | pub const SYS_unlinkat = 301; | ||
| 305 | pub const SYS_renameat = 302; | ||
| 306 | pub const SYS_linkat = 303; | ||
| 307 | pub const SYS_symlinkat = 304; | ||
| 308 | pub const SYS_readlinkat = 305; | ||
| 309 | pub const SYS_fchmodat = 306; | ||
| 310 | pub const SYS_faccessat = 307; | ||
| 311 | pub const SYS_pselect6 = 308; | ||
| 312 | pub const SYS_ppoll = 309; | ||
| 313 | pub const SYS_unshare = 310; | ||
| 314 | pub const SYS_set_robust_list = 311; | ||
| 315 | pub const SYS_get_robust_list = 312; | ||
| 316 | pub const SYS_splice = 313; | ||
| 317 | pub const SYS_sync_file_range = 314; | ||
| 318 | pub const SYS_tee = 315; | ||
| 319 | pub const SYS_vmsplice = 316; | ||
| 320 | pub const SYS_move_pages = 317; | ||
| 321 | pub const SYS_getcpu = 318; | ||
| 322 | pub const SYS_epoll_pwait = 319; | ||
| 323 | pub const SYS_utimensat = 320; | ||
| 324 | pub const SYS_signalfd = 321; | ||
| 325 | pub const SYS_timerfd_create = 322; | ||
| 326 | pub const SYS_eventfd = 323; | ||
| 327 | pub const SYS_fallocate = 324; | ||
| 328 | pub const SYS_timerfd_settime = 325; | ||
| 329 | pub const SYS_timerfd_gettime = 326; | ||
| 330 | pub const SYS_signalfd4 = 327; | ||
| 331 | pub const SYS_eventfd2 = 328; | ||
| 332 | pub const SYS_epoll_create1 = 329; | ||
| 333 | pub const SYS_dup3 = 330; | ||
| 334 | pub const SYS_pipe2 = 331; | ||
| 335 | pub const SYS_inotify_init1 = 332; | ||
| 336 | pub const SYS_preadv = 333; | ||
| 337 | pub const SYS_pwritev = 334; | ||
| 338 | pub const SYS_rt_tgsigqueueinfo = 335; | ||
| 339 | pub const SYS_perf_event_open = 336; | ||
| 340 | pub const SYS_recvmmsg = 337; | ||
| 341 | pub const SYS_fanotify_init = 338; | ||
| 342 | pub const SYS_fanotify_mark = 339; | ||
| 343 | pub const SYS_prlimit64 = 340; | ||
| 344 | pub const SYS_name_to_handle_at = 341; | ||
| 345 | pub const SYS_open_by_handle_at = 342; | ||
| 346 | pub const SYS_clock_adjtime = 343; | ||
| 347 | pub const SYS_syncfs = 344; | ||
| 348 | pub const SYS_sendmmsg = 345; | ||
| 349 | pub const SYS_setns = 346; | ||
| 350 | pub const SYS_process_vm_readv = 347; | ||
| 351 | pub const SYS_process_vm_writev = 348; | ||
| 352 | pub const SYS_kcmp = 349; | ||
| 353 | pub const SYS_finit_module = 350; | ||
| 354 | pub const SYS_sched_setattr = 351; | ||
| 355 | pub const SYS_sched_getattr = 352; | ||
| 356 | pub const SYS_renameat2 = 353; | ||
| 357 | pub const SYS_seccomp = 354; | ||
| 358 | pub const SYS_getrandom = 355; | ||
| 359 | pub const SYS_memfd_create = 356; | ||
| 360 | pub const SYS_bpf = 357; | ||
| 361 | pub const SYS_execveat = 358; | ||
| 362 | pub const SYS_socket = 359; | ||
| 363 | pub const SYS_socketpair = 360; | ||
| 364 | pub const SYS_bind = 361; | ||
| 365 | pub const SYS_connect = 362; | ||
| 366 | pub const SYS_listen = 363; | ||
| 367 | pub const SYS_accept4 = 364; | ||
| 368 | pub const SYS_getsockopt = 365; | ||
| 369 | pub const SYS_setsockopt = 366; | ||
| 370 | pub const SYS_getsockname = 367; | ||
| 371 | pub const SYS_getpeername = 368; | ||
| 372 | pub const SYS_sendto = 369; | ||
| 373 | pub const SYS_sendmsg = 370; | ||
| 374 | pub const SYS_recvfrom = 371; | ||
| 375 | pub const SYS_recvmsg = 372; | ||
| 376 | pub const SYS_shutdown = 373; | ||
| 377 | pub const SYS_userfaultfd = 374; | ||
| 378 | pub const SYS_membarrier = 375; | ||
| 379 | pub const SYS_mlock2 = 376; | ||
| 380 | |||
| 381 | |||
| 382 | pub const O_CREAT = 0o100; | ||
| 383 | pub const O_EXCL = 0o200; | ||
| 384 | pub const O_NOCTTY = 0o400; | ||
| 385 | pub const O_TRUNC = 0o1000; | ||
| 386 | pub const O_APPEND = 0o2000; | ||
| 387 | pub const O_NONBLOCK = 0o4000; | ||
| 388 | pub const O_DSYNC = 0o10000; | ||
| 389 | pub const O_SYNC = 0o4010000; | ||
| 390 | pub const O_RSYNC = 0o4010000; | ||
| 391 | pub const O_DIRECTORY = 0o200000; | ||
| 392 | pub const O_NOFOLLOW = 0o400000; | ||
| 393 | pub const O_CLOEXEC = 0o2000000; | ||
| 394 | |||
| 395 | pub const O_ASYNC = 0o20000; | ||
| 396 | pub const O_DIRECT = 0o40000; | ||
| 397 | pub const O_LARGEFILE = 0o100000; | ||
| 398 | pub const O_NOATIME = 0o1000000; | ||
| 399 | pub const O_PATH = 0o10000000; | ||
| 400 | pub const O_TMPFILE = 0o20200000; | ||
| 401 | pub const O_NDELAY = O_NONBLOCK; | ||
| 402 | |||
| 403 | pub const F_DUPFD = 0; | ||
| 404 | pub const F_GETFD = 1; | ||
| 405 | pub const F_SETFD = 2; | ||
| 406 | pub const F_GETFL = 3; | ||
| 407 | pub const F_SETFL = 4; | ||
| 408 | |||
| 409 | pub const F_SETOWN = 8; | ||
| 410 | pub const F_GETOWN = 9; | ||
| 411 | pub const F_SETSIG = 10; | ||
| 412 | pub const F_GETSIG = 11; | ||
| 413 | |||
| 414 | pub const F_GETLK = 12; | ||
| 415 | pub const F_SETLK = 13; | ||
| 416 | pub const F_SETLKW = 14; | ||
| 417 | |||
| 418 | pub const F_SETOWN_EX = 15; | ||
| 419 | pub const F_GETOWN_EX = 16; | ||
| 420 | |||
| 421 | pub const F_GETOWNER_UIDS = 17; | ||
| 422 | |||
| 423 | pub inline fn syscall0(number: usize) usize { | ||
| 424 | asm volatile ("int $0x80" | ||
| 425 | : [ret] "={eax}" (-> usize) | ||
| 426 | : [number] "{eax}" (number)) | ||
| 427 | } | ||
| 428 | |||
| 429 | pub inline fn syscall1(number: usize, arg1: usize) usize { | ||
| 430 | asm volatile ("int $0x80" | ||
| 431 | : [ret] "={eax}" (-> usize) | ||
| 432 | : [number] "{eax}" (number), | ||
| 433 | [arg1] "{ebx}" (arg1)) | ||
| 434 | } | ||
| 435 | |||
| 436 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | ||
| 437 | asm volatile ("int $0x80" | ||
| 438 | : [ret] "={eax}" (-> usize) | ||
| 439 | : [number] "{eax}" (number), | ||
| 440 | [arg1] "{ebx}" (arg1), | ||
| 441 | [arg2] "{ecx}" (arg2)) | ||
| 442 | } | ||
| 443 | |||
| 444 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | ||
| 445 | asm volatile ("int $0x80" | ||
| 446 | : [ret] "={eax}" (-> usize) | ||
| 447 | : [number] "{eax}" (number), | ||
| 448 | [arg1] "{ebx}" (arg1), | ||
| 449 | [arg2] "{ecx}" (arg2), | ||
| 450 | [arg3] "{edx}" (arg3)) | ||
| 451 | } | ||
| 452 | |||
| 453 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | ||
| 454 | asm volatile ("int $0x80" | ||
| 455 | : [ret] "={eax}" (-> usize) | ||
| 456 | : [number] "{eax}" (number), | ||
| 457 | [arg1] "{ebx}" (arg1), | ||
| 458 | [arg2] "{ecx}" (arg2), | ||
| 459 | [arg3] "{edx}" (arg3), | ||
| 460 | [arg4] "{esi}" (arg4)) | ||
| 461 | } | ||
| 462 | |||
| 463 | pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, | ||
| 464 | arg4: usize, arg5: usize) -> usize | ||
| 465 | { | ||
| 466 | asm volatile ("int $0x80" | ||
| 467 | : [ret] "={eax}" (-> usize) | ||
| 468 | : [number] "{eax}" (number), | ||
| 469 | [arg1] "{ebx}" (arg1), | ||
| 470 | [arg2] "{ecx}" (arg2), | ||
| 471 | [arg3] "{edx}" (arg3), | ||
| 472 | [arg4] "{esi}" (arg4), | ||
| 473 | [arg5] "{edi}" (arg5)) | ||
| 474 | } | ||
| 475 | |||
| 476 | pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, | ||
| 477 | arg4: usize, arg5: usize, arg6: usize) -> usize | ||
| 478 | { | ||
| 479 | asm volatile ("int $0x80" | ||
| 480 | : [ret] "={eax}" (-> usize) | ||
| 481 | : [number] "{eax}" (number), | ||
| 482 | [arg1] "{ebx}" (arg1), | ||
| 483 | [arg2] "{ecx}" (arg2), | ||
| 484 | [arg3] "{edx}" (arg3), | ||
| 485 | [arg4] "{esi}" (arg4), | ||
| 486 | [arg5] "{edi}" (arg5), | ||
| 487 | [arg6] "{ebp}" (arg6)) | ||
| 488 | } | ||
| 489 | |||
| 490 | pub nakedcc fn restore() void { | ||
| 491 | asm volatile ( | ||
| 492 | \\popl %%eax | ||
| 493 | \\movl $119, %%eax | ||
| 494 | \\int $0x80 | ||
| 495 | : | ||
| 496 | : | ||
| 497 | : "rcx", "r11") | ||
| 498 | } | ||
| 499 | |||
| 500 | pub nakedcc fn restore_rt() void { | ||
| 501 | asm volatile ("int $0x80" | ||
| 502 | : | ||
| 503 | : [number] "{eax}" (usize(SYS_rt_sigreturn)) | ||
| 504 | : "rcx", "r11") | ||
| 505 | } | ||
std/os/linux/index.zig created+796| ... | @@ -0,0 +1,796 @@ | ||
| 1 | const std = @import("../../index.zig"); | ||
| 2 | const assert = std.debug.assert; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | const arch = switch (builtin.arch) { | ||
| 5 | builtin.Arch.x86_64 => @import("x86_64.zig"), | ||
| 6 | builtin.Arch.i386 => @import("i386.zig"), | ||
| 7 | else => @compileError("unsupported arch"), | ||
| 8 | }; | ||
| 9 | pub use @import("errno.zig"); | ||
| 10 | |||
| 11 | pub const PATH_MAX = 4096; | ||
| 12 | |||
| 13 | pub const STDIN_FILENO = 0; | ||
| 14 | pub const STDOUT_FILENO = 1; | ||
| 15 | pub const STDERR_FILENO = 2; | ||
| 16 | |||
| 17 | pub const PROT_NONE = 0; | ||
| 18 | pub const PROT_READ = 1; | ||
| 19 | pub const PROT_WRITE = 2; | ||
| 20 | pub const PROT_EXEC = 4; | ||
| 21 | pub const PROT_GROWSDOWN = 0x01000000; | ||
| 22 | pub const PROT_GROWSUP = 0x02000000; | ||
| 23 | |||
| 24 | pub const MAP_FAILED = @maxValue(usize); | ||
| 25 | pub const MAP_SHARED = 0x01; | ||
| 26 | pub const MAP_PRIVATE = 0x02; | ||
| 27 | pub const MAP_TYPE = 0x0f; | ||
| 28 | pub const MAP_FIXED = 0x10; | ||
| 29 | pub const MAP_ANONYMOUS = 0x20; | ||
| 30 | pub const MAP_NORESERVE = 0x4000; | ||
| 31 | pub const MAP_GROWSDOWN = 0x0100; | ||
| 32 | pub const MAP_DENYWRITE = 0x0800; | ||
| 33 | pub const MAP_EXECUTABLE = 0x1000; | ||
| 34 | pub const MAP_LOCKED = 0x2000; | ||
| 35 | pub const MAP_POPULATE = 0x8000; | ||
| 36 | pub const MAP_NONBLOCK = 0x10000; | ||
| 37 | pub const MAP_STACK = 0x20000; | ||
| 38 | pub const MAP_HUGETLB = 0x40000; | ||
| 39 | pub const MAP_FILE = 0; | ||
| 40 | |||
| 41 | pub const WNOHANG = 1; | ||
| 42 | pub const WUNTRACED = 2; | ||
| 43 | pub const WSTOPPED = 2; | ||
| 44 | pub const WEXITED = 4; | ||
| 45 | pub const WCONTINUED = 8; | ||
| 46 | pub const WNOWAIT = 0x1000000; | ||
| 47 | |||
| 48 | pub const SA_NOCLDSTOP = 1; | ||
| 49 | pub const SA_NOCLDWAIT = 2; | ||
| 50 | pub const SA_SIGINFO = 4; | ||
| 51 | pub const SA_ONSTACK = 0x08000000; | ||
| 52 | pub const SA_RESTART = 0x10000000; | ||
| 53 | pub const SA_NODEFER = 0x40000000; | ||
| 54 | pub const SA_RESETHAND = 0x80000000; | ||
| 55 | pub const SA_RESTORER = 0x04000000; | ||
| 56 | |||
| 57 | pub const SIGHUP = 1; | ||
| 58 | pub const SIGINT = 2; | ||
| 59 | pub const SIGQUIT = 3; | ||
| 60 | pub const SIGILL = 4; | ||
| 61 | pub const SIGTRAP = 5; | ||
| 62 | pub const SIGABRT = 6; | ||
| 63 | pub const SIGIOT = SIGABRT; | ||
| 64 | pub const SIGBUS = 7; | ||
| 65 | pub const SIGFPE = 8; | ||
| 66 | pub const SIGKILL = 9; | ||
| 67 | pub const SIGUSR1 = 10; | ||
| 68 | pub const SIGSEGV = 11; | ||
| 69 | pub const SIGUSR2 = 12; | ||
| 70 | pub const SIGPIPE = 13; | ||
| 71 | pub const SIGALRM = 14; | ||
| 72 | pub const SIGTERM = 15; | ||
| 73 | pub const SIGSTKFLT = 16; | ||
| 74 | pub const SIGCHLD = 17; | ||
| 75 | pub const SIGCONT = 18; | ||
| 76 | pub const SIGSTOP = 19; | ||
| 77 | pub const SIGTSTP = 20; | ||
| 78 | pub const SIGTTIN = 21; | ||
| 79 | pub const SIGTTOU = 22; | ||
| 80 | pub const SIGURG = 23; | ||
| 81 | pub const SIGXCPU = 24; | ||
| 82 | pub const SIGXFSZ = 25; | ||
| 83 | pub const SIGVTALRM = 26; | ||
| 84 | pub const SIGPROF = 27; | ||
| 85 | pub const SIGWINCH = 28; | ||
| 86 | pub const SIGIO = 29; | ||
| 87 | pub const SIGPOLL = 29; | ||
| 88 | pub const SIGPWR = 30; | ||
| 89 | pub const SIGSYS = 31; | ||
| 90 | pub const SIGUNUSED = SIGSYS; | ||
| 91 | |||
| 92 | pub const O_RDONLY = 0o0; | ||
| 93 | pub const O_WRONLY = 0o1; | ||
| 94 | pub const O_RDWR = 0o2; | ||
| 95 | |||
| 96 | pub const O_CREAT = arch.O_CREAT; | ||
| 97 | pub const O_EXCL = arch.O_EXCL; | ||
| 98 | pub const O_NOCTTY = arch.O_NOCTTY; | ||
| 99 | pub const O_TRUNC = arch.O_TRUNC; | ||
| 100 | pub const O_APPEND = arch.O_APPEND; | ||
| 101 | pub const O_NONBLOCK = arch.O_NONBLOCK; | ||
| 102 | pub const O_DSYNC = arch.O_DSYNC; | ||
| 103 | pub const O_SYNC = arch.O_SYNC; | ||
| 104 | pub const O_RSYNC = arch.O_RSYNC; | ||
| 105 | pub const O_DIRECTORY = arch.O_DIRECTORY; | ||
| 106 | pub const O_NOFOLLOW = arch.O_NOFOLLOW; | ||
| 107 | pub const O_CLOEXEC = arch.O_CLOEXEC; | ||
| 108 | |||
| 109 | pub const O_ASYNC = arch.O_ASYNC; | ||
| 110 | pub const O_DIRECT = arch.O_DIRECT; | ||
| 111 | pub const O_LARGEFILE = arch.O_LARGEFILE; | ||
| 112 | pub const O_NOATIME = arch.O_NOATIME; | ||
| 113 | pub const O_PATH = arch.O_PATH; | ||
| 114 | pub const O_TMPFILE = arch.O_TMPFILE; | ||
| 115 | pub const O_NDELAY = arch.O_NDELAY; | ||
| 116 | |||
| 117 | pub const SEEK_SET = 0; | ||
| 118 | pub const SEEK_CUR = 1; | ||
| 119 | pub const SEEK_END = 2; | ||
| 120 | |||
| 121 | pub const SIG_BLOCK = 0; | ||
| 122 | pub const SIG_UNBLOCK = 1; | ||
| 123 | pub const SIG_SETMASK = 2; | ||
| 124 | |||
| 125 | pub const SOCK_STREAM = 1; | ||
| 126 | pub const SOCK_DGRAM = 2; | ||
| 127 | pub const SOCK_RAW = 3; | ||
| 128 | pub const SOCK_RDM = 4; | ||
| 129 | pub const SOCK_SEQPACKET = 5; | ||
| 130 | pub const SOCK_DCCP = 6; | ||
| 131 | pub const SOCK_PACKET = 10; | ||
| 132 | pub const SOCK_CLOEXEC = 0o2000000; | ||
| 133 | pub const SOCK_NONBLOCK = 0o4000; | ||
| 134 | |||
| 135 | |||
| 136 | pub const PROTO_ip = 0o000; | ||
| 137 | pub const PROTO_icmp = 0o001; | ||
| 138 | pub const PROTO_igmp = 0o002; | ||
| 139 | pub const PROTO_ggp = 0o003; | ||
| 140 | pub const PROTO_ipencap = 0o004; | ||
| 141 | pub const PROTO_st = 0o005; | ||
| 142 | pub const PROTO_tcp = 0o006; | ||
| 143 | pub const PROTO_egp = 0o010; | ||
| 144 | pub const PROTO_pup = 0o014; | ||
| 145 | pub const PROTO_udp = 0o021; | ||
| 146 | pub const PROTO_hmp = 0o024; | ||
| 147 | pub const PROTO_xns_idp = 0o026; | ||
| 148 | pub const PROTO_rdp = 0o033; | ||
| 149 | pub const PROTO_iso_tp4 = 0o035; | ||
| 150 | pub const PROTO_xtp = 0o044; | ||
| 151 | pub const PROTO_ddp = 0o045; | ||
| 152 | pub const PROTO_idpr_cmtp = 0o046; | ||
| 153 | pub const PROTO_ipv6 = 0o051; | ||
| 154 | pub const PROTO_ipv6_route = 0o053; | ||
| 155 | pub const PROTO_ipv6_frag = 0o054; | ||
| 156 | pub const PROTO_idrp = 0o055; | ||
| 157 | pub const PROTO_rsvp = 0o056; | ||
| 158 | pub const PROTO_gre = 0o057; | ||
| 159 | pub const PROTO_esp = 0o062; | ||
| 160 | pub const PROTO_ah = 0o063; | ||
| 161 | pub const PROTO_skip = 0o071; | ||
| 162 | pub const PROTO_ipv6_icmp = 0o072; | ||
| 163 | pub const PROTO_ipv6_nonxt = 0o073; | ||
| 164 | pub const PROTO_ipv6_opts = 0o074; | ||
| 165 | pub const PROTO_rspf = 0o111; | ||
| 166 | pub const PROTO_vmtp = 0o121; | ||
| 167 | pub const PROTO_ospf = 0o131; | ||
| 168 | pub const PROTO_ipip = 0o136; | ||
| 169 | pub const PROTO_encap = 0o142; | ||
| 170 | pub const PROTO_pim = 0o147; | ||
| 171 | pub const PROTO_raw = 0o377; | ||
| 172 | |||
| 173 | pub const PF_UNSPEC = 0; | ||
| 174 | pub const PF_LOCAL = 1; | ||
| 175 | pub const PF_UNIX = PF_LOCAL; | ||
| 176 | pub const PF_FILE = PF_LOCAL; | ||
| 177 | pub const PF_INET = 2; | ||
| 178 | pub const PF_AX25 = 3; | ||
| 179 | pub const PF_IPX = 4; | ||
| 180 | pub const PF_APPLETALK = 5; | ||
| 181 | pub const PF_NETROM = 6; | ||
| 182 | pub const PF_BRIDGE = 7; | ||
| 183 | pub const PF_ATMPVC = 8; | ||
| 184 | pub const PF_X25 = 9; | ||
| 185 | pub const PF_INET6 = 10; | ||
| 186 | pub const PF_ROSE = 11; | ||
| 187 | pub const PF_DECnet = 12; | ||
| 188 | pub const PF_NETBEUI = 13; | ||
| 189 | pub const PF_SECURITY = 14; | ||
| 190 | pub const PF_KEY = 15; | ||
| 191 | pub const PF_NETLINK = 16; | ||
| 192 | pub const PF_ROUTE = PF_NETLINK; | ||
| 193 | pub const PF_PACKET = 17; | ||
| 194 | pub const PF_ASH = 18; | ||
| 195 | pub const PF_ECONET = 19; | ||
| 196 | pub const PF_ATMSVC = 20; | ||
| 197 | pub const PF_RDS = 21; | ||
| 198 | pub const PF_SNA = 22; | ||
| 199 | pub const PF_IRDA = 23; | ||
| 200 | pub const PF_PPPOX = 24; | ||
| 201 | pub const PF_WANPIPE = 25; | ||
| 202 | pub const PF_LLC = 26; | ||
| 203 | pub const PF_IB = 27; | ||
| 204 | pub const PF_MPLS = 28; | ||
| 205 | pub const PF_CAN = 29; | ||
| 206 | pub const PF_TIPC = 30; | ||
| 207 | pub const PF_BLUETOOTH = 31; | ||
| 208 | pub const PF_IUCV = 32; | ||
| 209 | pub const PF_RXRPC = 33; | ||
| 210 | pub const PF_ISDN = 34; | ||
| 211 | pub const PF_PHONET = 35; | ||
| 212 | pub const PF_IEEE802154 = 36; | ||
| 213 | pub const PF_CAIF = 37; | ||
| 214 | pub const PF_ALG = 38; | ||
| 215 | pub const PF_NFC = 39; | ||
| 216 | pub const PF_VSOCK = 40; | ||
| 217 | pub const PF_MAX = 41; | ||
| 218 | |||
| 219 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 220 | pub const AF_LOCAL = PF_LOCAL; | ||
| 221 | pub const AF_UNIX = AF_LOCAL; | ||
| 222 | pub const AF_FILE = AF_LOCAL; | ||
| 223 | pub const AF_INET = PF_INET; | ||
| 224 | pub const AF_AX25 = PF_AX25; | ||
| 225 | pub const AF_IPX = PF_IPX; | ||
| 226 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 227 | pub const AF_NETROM = PF_NETROM; | ||
| 228 | pub const AF_BRIDGE = PF_BRIDGE; | ||
| 229 | pub const AF_ATMPVC = PF_ATMPVC; | ||
| 230 | pub const AF_X25 = PF_X25; | ||
| 231 | pub const AF_INET6 = PF_INET6; | ||
| 232 | pub const AF_ROSE = PF_ROSE; | ||
| 233 | pub const AF_DECnet = PF_DECnet; | ||
| 234 | pub const AF_NETBEUI = PF_NETBEUI; | ||
| 235 | pub const AF_SECURITY = PF_SECURITY; | ||
| 236 | pub const AF_KEY = PF_KEY; | ||
| 237 | pub const AF_NETLINK = PF_NETLINK; | ||
| 238 | pub const AF_ROUTE = PF_ROUTE; | ||
| 239 | pub const AF_PACKET = PF_PACKET; | ||
| 240 | pub const AF_ASH = PF_ASH; | ||
| 241 | pub const AF_ECONET = PF_ECONET; | ||
| 242 | pub const AF_ATMSVC = PF_ATMSVC; | ||
| 243 | pub const AF_RDS = PF_RDS; | ||
| 244 | pub const AF_SNA = PF_SNA; | ||
| 245 | pub const AF_IRDA = PF_IRDA; | ||
| 246 | pub const AF_PPPOX = PF_PPPOX; | ||
| 247 | pub const AF_WANPIPE = PF_WANPIPE; | ||
| 248 | pub const AF_LLC = PF_LLC; | ||
| 249 | pub const AF_IB = PF_IB; | ||
| 250 | pub const AF_MPLS = PF_MPLS; | ||
| 251 | pub const AF_CAN = PF_CAN; | ||
| 252 | pub const AF_TIPC = PF_TIPC; | ||
| 253 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 254 | pub const AF_IUCV = PF_IUCV; | ||
| 255 | pub const AF_RXRPC = PF_RXRPC; | ||
| 256 | pub const AF_ISDN = PF_ISDN; | ||
| 257 | pub const AF_PHONET = PF_PHONET; | ||
| 258 | pub const AF_IEEE802154 = PF_IEEE802154; | ||
| 259 | pub const AF_CAIF = PF_CAIF; | ||
| 260 | pub const AF_ALG = PF_ALG; | ||
| 261 | pub const AF_NFC = PF_NFC; | ||
| 262 | pub const AF_VSOCK = PF_VSOCK; | ||
| 263 | pub const AF_MAX = PF_MAX; | ||
| 264 | |||
| 265 | pub const DT_UNKNOWN = 0; | ||
| 266 | pub const DT_FIFO = 1; | ||
| 267 | pub const DT_CHR = 2; | ||
| 268 | pub const DT_DIR = 4; | ||
| 269 | pub const DT_BLK = 6; | ||
| 270 | pub const DT_REG = 8; | ||
| 271 | pub const DT_LNK = 10; | ||
| 272 | pub const DT_SOCK = 12; | ||
| 273 | pub const DT_WHT = 14; | ||
| 274 | |||
| 275 | |||
| 276 | pub const TCGETS = 0x5401; | ||
| 277 | pub const TCSETS = 0x5402; | ||
| 278 | pub const TCSETSW = 0x5403; | ||
| 279 | pub const TCSETSF = 0x5404; | ||
| 280 | pub const TCGETA = 0x5405; | ||
| 281 | pub const TCSETA = 0x5406; | ||
| 282 | pub const TCSETAW = 0x5407; | ||
| 283 | pub const TCSETAF = 0x5408; | ||
| 284 | pub const TCSBRK = 0x5409; | ||
| 285 | pub const TCXONC = 0x540A; | ||
| 286 | pub const TCFLSH = 0x540B; | ||
| 287 | pub const TIOCEXCL = 0x540C; | ||
| 288 | pub const TIOCNXCL = 0x540D; | ||
| 289 | pub const TIOCSCTTY = 0x540E; | ||
| 290 | pub const TIOCGPGRP = 0x540F; | ||
| 291 | pub const TIOCSPGRP = 0x5410; | ||
| 292 | pub const TIOCOUTQ = 0x5411; | ||
| 293 | pub const TIOCSTI = 0x5412; | ||
| 294 | pub const TIOCGWINSZ = 0x5413; | ||
| 295 | pub const TIOCSWINSZ = 0x5414; | ||
| 296 | pub const TIOCMGET = 0x5415; | ||
| 297 | pub const TIOCMBIS = 0x5416; | ||
| 298 | pub const TIOCMBIC = 0x5417; | ||
| 299 | pub const TIOCMSET = 0x5418; | ||
| 300 | pub const TIOCGSOFTCAR = 0x5419; | ||
| 301 | pub const TIOCSSOFTCAR = 0x541A; | ||
| 302 | pub const FIONREAD = 0x541B; | ||
| 303 | pub const TIOCINQ = FIONREAD; | ||
| 304 | pub const TIOCLINUX = 0x541C; | ||
| 305 | pub const TIOCCONS = 0x541D; | ||
| 306 | pub const TIOCGSERIAL = 0x541E; | ||
| 307 | pub const TIOCSSERIAL = 0x541F; | ||
| 308 | pub const TIOCPKT = 0x5420; | ||
| 309 | pub const FIONBIO = 0x5421; | ||
| 310 | pub const TIOCNOTTY = 0x5422; | ||
| 311 | pub const TIOCSETD = 0x5423; | ||
| 312 | pub const TIOCGETD = 0x5424; | ||
| 313 | pub const TCSBRKP = 0x5425; | ||
| 314 | pub const TIOCSBRK = 0x5427; | ||
| 315 | pub const TIOCCBRK = 0x5428; | ||
| 316 | pub const TIOCGSID = 0x5429; | ||
| 317 | pub const TIOCGRS485 = 0x542E; | ||
| 318 | pub const TIOCSRS485 = 0x542F; | ||
| 319 | pub const TIOCGPTN = 0x80045430; | ||
| 320 | pub const TIOCSPTLCK = 0x40045431; | ||
| 321 | pub const TIOCGDEV = 0x80045432; | ||
| 322 | pub const TCGETX = 0x5432; | ||
| 323 | pub const TCSETX = 0x5433; | ||
| 324 | pub const TCSETXF = 0x5434; | ||
| 325 | pub const TCSETXW = 0x5435; | ||
| 326 | pub const TIOCSIG = 0x40045436; | ||
| 327 | pub const TIOCVHANGUP = 0x5437; | ||
| 328 | pub const TIOCGPKT = 0x80045438; | ||
| 329 | pub const TIOCGPTLCK = 0x80045439; | ||
| 330 | pub const TIOCGEXCL = 0x80045440; | ||
| 331 | |||
| 332 | pub const EPOLL_CTL_ADD = 1; | ||
| 333 | pub const EPOLL_CTL_DEL = 2; | ||
| 334 | pub const EPOLL_CTL_MOD = 3; | ||
| 335 | |||
| 336 | pub const EPOLLIN = 0x001; | ||
| 337 | pub const EPOLLPRI = 0x002; | ||
| 338 | pub const EPOLLOUT = 0x004; | ||
| 339 | pub const EPOLLRDNORM = 0x040; | ||
| 340 | pub const EPOLLRDBAND = 0x080; | ||
| 341 | pub const EPOLLWRNORM = 0x100; | ||
| 342 | pub const EPOLLWRBAND = 0x200; | ||
| 343 | pub const EPOLLMSG = 0x400; | ||
| 344 | pub const EPOLLERR = 0x008; | ||
| 345 | pub const EPOLLHUP = 0x010; | ||
| 346 | pub const EPOLLRDHUP = 0x2000; | ||
| 347 | pub const EPOLLEXCLUSIVE = (u32(1) << 28); | ||
| 348 | pub const EPOLLWAKEUP = (u32(1) << 29); | ||
| 349 | pub const EPOLLONESHOT = (u32(1) << 30); | ||
| 350 | pub const EPOLLET = (u32(1) << 31); | ||
| 351 | |||
| 352 | pub const CLOCK_REALTIME = 0; | ||
| 353 | pub const CLOCK_MONOTONIC = 1; | ||
| 354 | pub const CLOCK_PROCESS_CPUTIME_ID = 2; | ||
| 355 | pub const CLOCK_THREAD_CPUTIME_ID = 3; | ||
| 356 | pub const CLOCK_MONOTONIC_RAW = 4; | ||
| 357 | pub const CLOCK_REALTIME_COARSE = 5; | ||
| 358 | pub const CLOCK_MONOTONIC_COARSE = 6; | ||
| 359 | pub const CLOCK_BOOTTIME = 7; | ||
| 360 | pub const CLOCK_REALTIME_ALARM = 8; | ||
| 361 | pub const CLOCK_BOOTTIME_ALARM = 9; | ||
| 362 | pub const CLOCK_SGI_CYCLE = 10; | ||
| 363 | pub const CLOCK_TAI = 11; | ||
| 364 | |||
| 365 | pub const TFD_NONBLOCK = O_NONBLOCK; | ||
| 366 | pub const TFD_CLOEXEC = O_CLOEXEC; | ||
| 367 | |||
| 368 | pub const TFD_TIMER_ABSTIME = 1; | ||
| 369 | pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); | ||
| 370 | |||
| 371 | fn unsigned(s: i32) u32 { return @bitCast(u32, s); } | ||
| 372 | fn signed(s: u32) i32 { return @bitCast(i32, s); } | ||
| 373 | pub fn WEXITSTATUS(s: i32) i32 { return signed((unsigned(s) & 0xff00) >> 8); } | ||
| 374 | pub fn WTERMSIG(s: i32) i32 { return signed(unsigned(s) & 0x7f); } | ||
| 375 | pub fn WSTOPSIG(s: i32) i32 { return WEXITSTATUS(s); } | ||
| 376 | pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; } | ||
| 377 | pub fn WIFSTOPPED(s: i32) bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; } | ||
| 378 | pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s)&0xffff)-%1 < 0xff; } | ||
| 379 | |||
| 380 | |||
| 381 | pub const winsize = extern struct { | ||
| 382 | ws_row: u16, | ||
| 383 | ws_col: u16, | ||
| 384 | ws_xpixel: u16, | ||
| 385 | ws_ypixel: u16, | ||
| 386 | }; | ||
| 387 | |||
| 388 | /// Get the errno from a syscall return value, or 0 for no error. | ||
| 389 | pub fn getErrno(r: usize) usize { | ||
| 390 | const signed_r = @bitCast(isize, r); | ||
| 391 | return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0; | ||
| 392 | } | ||
| 393 | |||
| 394 | pub fn dup2(old: i32, new: i32) usize { | ||
| 395 | return arch.syscall2(arch.SYS_dup2, usize(old), usize(new)); | ||
| 396 | } | ||
| 397 | |||
| 398 | pub fn chdir(path: &const u8) usize { | ||
| 399 | return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); | ||
| 400 | } | ||
| 401 | |||
| 402 | pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize { | ||
| 403 | return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); | ||
| 404 | } | ||
| 405 | |||
| 406 | pub fn fork() usize { | ||
| 407 | return arch.syscall0(arch.SYS_fork); | ||
| 408 | } | ||
| 409 | |||
| 410 | pub fn getcwd(buf: &u8, size: usize) usize { | ||
| 411 | return arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size); | ||
| 412 | } | ||
| 413 | |||
| 414 | pub fn getdents(fd: i32, dirp: &u8, count: usize) usize { | ||
| 415 | return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count); | ||
| 416 | } | ||
| 417 | |||
| 418 | pub fn isatty(fd: i32) bool { | ||
| 419 | var wsz: winsize = undefined; | ||
| 420 | return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | ||
| 421 | } | ||
| 422 | |||
| 423 | pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize { | ||
| 424 | return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | ||
| 425 | } | ||
| 426 | |||
| 427 | pub fn mkdir(path: &const u8, mode: u32) usize { | ||
| 428 | return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode); | ||
| 429 | } | ||
| 430 | |||
| 431 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { | ||
| 432 | return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), | ||
| 433 | @bitCast(usize, offset)); | ||
| 434 | } | ||
| 435 | |||
| 436 | pub fn munmap(address: &u8, length: usize) usize { | ||
| 437 | return arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length); | ||
| 438 | } | ||
| 439 | |||
| 440 | pub fn read(fd: i32, buf: &u8, count: usize) usize { | ||
| 441 | return arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count); | ||
| 442 | } | ||
| 443 | |||
| 444 | pub fn rmdir(path: &const u8) usize { | ||
| 445 | return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); | ||
| 446 | } | ||
| 447 | |||
| 448 | pub fn symlink(existing: &const u8, new: &const u8) usize { | ||
| 449 | return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); | ||
| 450 | } | ||
| 451 | |||
| 452 | pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize { | ||
| 453 | return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset); | ||
| 454 | } | ||
| 455 | |||
| 456 | pub fn pipe(fd: &[2]i32) usize { | ||
| 457 | return pipe2(fd, 0); | ||
| 458 | } | ||
| 459 | |||
| 460 | pub fn pipe2(fd: &[2]i32, flags: usize) usize { | ||
| 461 | return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags); | ||
| 462 | } | ||
| 463 | |||
| 464 | pub fn write(fd: i32, buf: &const u8, count: usize) usize { | ||
| 465 | return arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count); | ||
| 466 | } | ||
| 467 | |||
| 468 | pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize { | ||
| 469 | return arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset); | ||
| 470 | } | ||
| 471 | |||
| 472 | pub fn rename(old: &const u8, new: &const u8) usize { | ||
| 473 | return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)); | ||
| 474 | } | ||
| 475 | |||
| 476 | pub fn open(path: &const u8, flags: u32, perm: usize) usize { | ||
| 477 | return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm); | ||
| 478 | } | ||
| 479 | |||
| 480 | pub fn create(path: &const u8, perm: usize) usize { | ||
| 481 | return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm); | ||
| 482 | } | ||
| 483 | |||
| 484 | pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize { | ||
| 485 | return arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode); | ||
| 486 | } | ||
| 487 | |||
| 488 | pub fn close(fd: i32) usize { | ||
| 489 | return arch.syscall1(arch.SYS_close, usize(fd)); | ||
| 490 | } | ||
| 491 | |||
| 492 | pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { | ||
| 493 | return arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos); | ||
| 494 | } | ||
| 495 | |||
| 496 | pub fn exit(status: i32) noreturn { | ||
| 497 | _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); | ||
| 498 | unreachable; | ||
| 499 | } | ||
| 500 | |||
| 501 | pub fn getrandom(buf: &u8, count: usize, flags: u32) usize { | ||
| 502 | return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags)); | ||
| 503 | } | ||
| 504 | |||
| 505 | pub fn kill(pid: i32, sig: i32) usize { | ||
| 506 | return arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig)); | ||
| 507 | } | ||
| 508 | |||
| 509 | pub fn unlink(path: &const u8) usize { | ||
| 510 | return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); | ||
| 511 | } | ||
| 512 | |||
| 513 | pub fn waitpid(pid: i32, status: &i32, options: i32) usize { | ||
| 514 | return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); | ||
| 515 | } | ||
| 516 | |||
| 517 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { | ||
| 518 | return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); | ||
| 519 | } | ||
| 520 | |||
| 521 | pub fn setuid(uid: u32) usize { | ||
| 522 | return arch.syscall1(arch.SYS_setuid, uid); | ||
| 523 | } | ||
| 524 | |||
| 525 | pub fn setgid(gid: u32) usize { | ||
| 526 | return arch.syscall1(arch.SYS_setgid, gid); | ||
| 527 | } | ||
| 528 | |||
| 529 | pub fn setreuid(ruid: u32, euid: u32) usize { | ||
| 530 | return arch.syscall2(arch.SYS_setreuid, ruid, euid); | ||
| 531 | } | ||
| 532 | |||
| 533 | pub fn setregid(rgid: u32, egid: u32) usize { | ||
| 534 | return arch.syscall2(arch.SYS_setregid, rgid, egid); | ||
| 535 | } | ||
| 536 | |||
| 537 | pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize { | ||
| 538 | return arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8); | ||
| 539 | } | ||
| 540 | |||
| 541 | pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize { | ||
| 542 | assert(sig >= 1); | ||
| 543 | assert(sig != SIGKILL); | ||
| 544 | assert(sig != SIGSTOP); | ||
| 545 | var ksa = k_sigaction { | ||
| 546 | .handler = act.handler, | ||
| 547 | .flags = act.flags | SA_RESTORER, | ||
| 548 | .mask = undefined, | ||
| 549 | .restorer = @ptrCast(extern fn()void, arch.restore_rt), | ||
| 550 | }; | ||
| 551 | var ksa_old: k_sigaction = undefined; | ||
| 552 | @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8); | ||
| 553 | const result = arch.syscall4(arch.SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask))); | ||
| 554 | const err = getErrno(result); | ||
| 555 | if (err != 0) { | ||
| 556 | return result; | ||
| 557 | } | ||
| 558 | if (oact) |old| { | ||
| 559 | old.handler = ksa_old.handler; | ||
| 560 | old.flags = @truncate(u32, ksa_old.flags); | ||
| 561 | @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask))); | ||
| 562 | } | ||
| 563 | return 0; | ||
| 564 | } | ||
| 565 | |||
| 566 | const NSIG = 65; | ||
| 567 | const sigset_t = [128 / @sizeOf(usize)]usize; | ||
| 568 | const all_mask = []usize{@maxValue(usize)}; | ||
| 569 | const app_mask = []usize{0xfffffffc7fffffff}; | ||
| 570 | |||
| 571 | const k_sigaction = extern struct { | ||
| 572 | handler: extern fn(i32)void, | ||
| 573 | flags: usize, | ||
| 574 | restorer: extern fn()void, | ||
| 575 | mask: [2]u32, | ||
| 576 | }; | ||
| 577 | |||
| 578 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 579 | pub const Sigaction = struct { | ||
| 580 | handler: extern fn(i32)void, | ||
| 581 | mask: sigset_t, | ||
| 582 | flags: u32, | ||
| 583 | }; | ||
| 584 | |||
| 585 | pub const SIG_ERR = @intToPtr(extern fn(i32)void, @maxValue(usize)); | ||
| 586 | pub const SIG_DFL = @intToPtr(extern fn(i32)void, 0); | ||
| 587 | pub const SIG_IGN = @intToPtr(extern fn(i32)void, 1); | ||
| 588 | pub const empty_sigset = []usize{0} ** sigset_t.len; | ||
| 589 | |||
| 590 | pub fn raise(sig: i32) usize { | ||
| 591 | var set: sigset_t = undefined; | ||
| 592 | blockAppSignals(&set); | ||
| 593 | const tid = i32(arch.syscall0(arch.SYS_gettid)); | ||
| 594 | const ret = arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig)); | ||
| 595 | restoreSignals(&set); | ||
| 596 | return ret; | ||
| 597 | } | ||
| 598 | |||
| 599 | fn blockAllSignals(set: &sigset_t) void { | ||
| 600 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8); | ||
| 601 | } | ||
| 602 | |||
| 603 | fn blockAppSignals(set: &sigset_t) void { | ||
| 604 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8); | ||
| 605 | } | ||
| 606 | |||
| 607 | fn restoreSignals(set: &sigset_t) void { | ||
| 608 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8); | ||
| 609 | } | ||
| 610 | |||
| 611 | pub fn sigaddset(set: &sigset_t, sig: u6) void { | ||
| 612 | const s = sig - 1; | ||
| 613 | (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); | ||
| 614 | } | ||
| 615 | |||
| 616 | pub fn sigismember(set: &const sigset_t, sig: u6) bool { | ||
| 617 | const s = sig - 1; | ||
| 618 | return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; | ||
| 619 | } | ||
| 620 | |||
| 621 | |||
| 622 | pub const sa_family_t = u16; | ||
| 623 | pub const socklen_t = u32; | ||
| 624 | pub const in_addr = u32; | ||
| 625 | pub const in6_addr = [16]u8; | ||
| 626 | |||
| 627 | pub const sockaddr = extern struct { | ||
| 628 | family: sa_family_t, | ||
| 629 | port: u16, | ||
| 630 | data: [12]u8, | ||
| 631 | }; | ||
| 632 | |||
| 633 | pub const sockaddr_in = extern struct { | ||
| 634 | family: sa_family_t, | ||
| 635 | port: u16, | ||
| 636 | addr: in_addr, | ||
| 637 | zero: [8]u8, | ||
| 638 | }; | ||
| 639 | |||
| 640 | pub const sockaddr_in6 = extern struct { | ||
| 641 | family: sa_family_t, | ||
| 642 | port: u16, | ||
| 643 | flowinfo: u32, | ||
| 644 | addr: in6_addr, | ||
| 645 | scope_id: u32, | ||
| 646 | }; | ||
| 647 | |||
| 648 | pub const iovec = extern struct { | ||
| 649 | iov_base: &u8, | ||
| 650 | iov_len: usize, | ||
| 651 | }; | ||
| 652 | |||
| 653 | pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { | ||
| 654 | return arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len)); | ||
| 655 | } | ||
| 656 | |||
| 657 | pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { | ||
| 658 | return arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len)); | ||
| 659 | } | ||
| 660 | |||
| 661 | pub fn socket(domain: i32, socket_type: i32, protocol: i32) usize { | ||
| 662 | return arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol)); | ||
| 663 | } | ||
| 664 | |||
| 665 | pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) usize { | ||
| 666 | return arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen)); | ||
| 667 | } | ||
| 668 | |||
| 669 | pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) usize { | ||
| 670 | return arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen)); | ||
| 671 | } | ||
| 672 | |||
| 673 | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) usize { | ||
| 674 | return arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags); | ||
| 675 | } | ||
| 676 | |||
| 677 | pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize { | ||
| 678 | return arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len)); | ||
| 679 | } | ||
| 680 | |||
| 681 | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) usize { | ||
| 682 | return arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags); | ||
| 683 | } | ||
| 684 | |||
| 685 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, | ||
| 686 | noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize | ||
| 687 | { | ||
| 688 | return arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); | ||
| 689 | } | ||
| 690 | |||
| 691 | pub fn shutdown(fd: i32, how: i32) usize { | ||
| 692 | return arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)); | ||
| 693 | } | ||
| 694 | |||
| 695 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize { | ||
| 696 | return arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len)); | ||
| 697 | } | ||
| 698 | |||
| 699 | pub fn listen(fd: i32, backlog: i32) usize { | ||
| 700 | return arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)); | ||
| 701 | } | ||
| 702 | |||
| 703 | pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize { | ||
| 704 | return arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen)); | ||
| 705 | } | ||
| 706 | |||
| 707 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { | ||
| 708 | return arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0])); | ||
| 709 | } | ||
| 710 | |||
| 711 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { | ||
| 712 | return accept4(fd, addr, len, 0); | ||
| 713 | } | ||
| 714 | |||
| 715 | pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize { | ||
| 716 | return arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags); | ||
| 717 | } | ||
| 718 | |||
| 719 | // error NameTooLong; | ||
| 720 | // error SystemResources; | ||
| 721 | // error Io; | ||
| 722 | // | ||
| 723 | // pub fn if_nametoindex(name: []u8) %u32 { | ||
| 724 | // var ifr: ifreq = undefined; | ||
| 725 | // | ||
| 726 | // if (name.len >= ifr.ifr_name.len) { | ||
| 727 | // return error.NameTooLong; | ||
| 728 | // } | ||
| 729 | // | ||
| 730 | // const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); | ||
| 731 | // const socket_err = getErrno(socket_ret); | ||
| 732 | // if (socket_err > 0) { | ||
| 733 | // return error.SystemResources; | ||
| 734 | // } | ||
| 735 | // const socket_fd = i32(socket_ret); | ||
| 736 | // @memcpy(&ifr.ifr_name[0], &name[0], name.len); | ||
| 737 | // ifr.ifr_name[name.len] = 0; | ||
| 738 | // const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr); | ||
| 739 | // close(socket_fd); | ||
| 740 | // const ioctl_err = getErrno(ioctl_ret); | ||
| 741 | // if (ioctl_err > 0) { | ||
| 742 | // return error.Io; | ||
| 743 | // } | ||
| 744 | // return ifr.ifr_ifindex; | ||
| 745 | // } | ||
| 746 | |||
| 747 | pub const Stat = arch.Stat; | ||
| 748 | pub const timespec = arch.timespec; | ||
| 749 | |||
| 750 | pub fn fstat(fd: i32, stat_buf: &Stat) usize { | ||
| 751 | return arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)); | ||
| 752 | } | ||
| 753 | |||
| 754 | pub const epoll_data = u64; | ||
| 755 | |||
| 756 | pub const epoll_event = extern struct { | ||
| 757 | events: u32, | ||
| 758 | data: epoll_data | ||
| 759 | }; | ||
| 760 | |||
| 761 | pub fn epoll_create() usize { | ||
| 762 | return arch.syscall1(arch.SYS_epoll_create, usize(1)); | ||
| 763 | } | ||
| 764 | |||
| 765 | pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) usize { | ||
| 766 | return arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev)); | ||
| 767 | } | ||
| 768 | |||
| 769 | pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) usize { | ||
| 770 | return arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout)); | ||
| 771 | } | ||
| 772 | |||
| 773 | pub fn timerfd_create(clockid: i32, flags: u32) usize { | ||
| 774 | return arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags)); | ||
| 775 | } | ||
| 776 | |||
| 777 | pub const itimerspec = extern struct { | ||
| 778 | it_interval: timespec, | ||
| 779 | it_value: timespec | ||
| 780 | }; | ||
| 781 | |||
| 782 | pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize { | ||
| 783 | return arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value)); | ||
| 784 | } | ||
| 785 | |||
| 786 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize { | ||
| 787 | return arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value)); | ||
| 788 | } | ||
| 789 | |||
| 790 | test "import linux test" { | ||
| 791 | // TODO lazy analysis should prevent this test from being compiled on windows, but | ||
| 792 | // it is still compiled on windows | ||
| 793 | if (builtin.os == builtin.Os.linux) { | ||
| 794 | _ = @import("test.zig"); | ||
| 795 | } | ||
| 796 | } | ||
std/os/linux/test.zig created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | const std = @import("../../index.zig"); | ||
| 2 | const linux = std.os.linux; | ||
| 3 | const assert = std.debug.assert; | ||
| 4 | |||
| 5 | test "timer" { | ||
| 6 | const epoll_fd = linux.epoll_create(); | ||
| 7 | var err = linux.getErrno(epoll_fd); | ||
| 8 | assert(err == 0); | ||
| 9 | |||
| 10 | const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0); | ||
| 11 | assert(linux.getErrno(timer_fd) == 0); | ||
| 12 | |||
| 13 | const time_interval = linux.timespec { | ||
| 14 | .tv_sec = 0, | ||
| 15 | .tv_nsec = 2000000 | ||
| 16 | }; | ||
| 17 | |||
| 18 | const new_time = linux.itimerspec { | ||
| 19 | .it_interval = time_interval, | ||
| 20 | .it_value = time_interval | ||
| 21 | }; | ||
| 22 | |||
| 23 | err = linux.timerfd_settime(i32(timer_fd), 0, &new_time, null); | ||
| 24 | assert(err == 0); | ||
| 25 | |||
| 26 | var event = linux.epoll_event { | ||
| 27 | .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET, | ||
| 28 | .data = 0 | ||
| 29 | }; | ||
| 30 | |||
| 31 | err = linux.epoll_ctl(i32(epoll_fd), linux.EPOLL_CTL_ADD, i32(timer_fd), &event); | ||
| 32 | assert(err == 0); | ||
| 33 | |||
| 34 | const events_one: linux.epoll_event = undefined; | ||
| 35 | var events = []linux.epoll_event{events_one} ** 8; | ||
| 36 | |||
| 37 | err = linux.epoll_wait(i32(epoll_fd), &events[0], 8, -1); | ||
| 38 | } | ||
std/os/linux/x86_64.zig created+490| ... | @@ -0,0 +1,490 @@ | ||
| 1 | const std = @import("../../index.zig"); | ||
| 2 | const linux = std.os.linux; | ||
| 3 | const socklen_t = linux.socklen_t; | ||
| 4 | const iovec = linux.iovec; | ||
| 5 | |||
| 6 | pub const SYS_read = 0; | ||
| 7 | pub const SYS_write = 1; | ||
| 8 | pub const SYS_open = 2; | ||
| 9 | pub const SYS_close = 3; | ||
| 10 | pub const SYS_stat = 4; | ||
| 11 | pub const SYS_fstat = 5; | ||
| 12 | pub const SYS_lstat = 6; | ||
| 13 | pub const SYS_poll = 7; | ||
| 14 | pub const SYS_lseek = 8; | ||
| 15 | pub const SYS_mmap = 9; | ||
| 16 | pub const SYS_mprotect = 10; | ||
| 17 | pub const SYS_munmap = 11; | ||
| 18 | pub const SYS_brk = 12; | ||
| 19 | pub const SYS_rt_sigaction = 13; | ||
| 20 | pub const SYS_rt_sigprocmask = 14; | ||
| 21 | pub const SYS_rt_sigreturn = 15; | ||
| 22 | pub const SYS_ioctl = 16; | ||
| 23 | pub const SYS_pread = 17; | ||
| 24 | pub const SYS_pwrite = 18; | ||
| 25 | pub const SYS_readv = 19; | ||
| 26 | pub const SYS_writev = 20; | ||
| 27 | pub const SYS_access = 21; | ||
| 28 | pub const SYS_pipe = 22; | ||
| 29 | pub const SYS_select = 23; | ||
| 30 | pub const SYS_sched_yield = 24; | ||
| 31 | pub const SYS_mremap = 25; | ||
| 32 | pub const SYS_msync = 26; | ||
| 33 | pub const SYS_mincore = 27; | ||
| 34 | pub const SYS_madvise = 28; | ||
| 35 | pub const SYS_shmget = 29; | ||
| 36 | pub const SYS_shmat = 30; | ||
| 37 | pub const SYS_shmctl = 31; | ||
| 38 | pub const SYS_dup = 32; | ||
| 39 | pub const SYS_dup2 = 33; | ||
| 40 | pub const SYS_pause = 34; | ||
| 41 | pub const SYS_nanosleep = 35; | ||
| 42 | pub const SYS_getitimer = 36; | ||
| 43 | pub const SYS_alarm = 37; | ||
| 44 | pub const SYS_setitimer = 38; | ||
| 45 | pub const SYS_getpid = 39; | ||
| 46 | pub const SYS_sendfile = 40; | ||
| 47 | pub const SYS_socket = 41; | ||
| 48 | pub const SYS_connect = 42; | ||
| 49 | pub const SYS_accept = 43; | ||
| 50 | pub const SYS_sendto = 44; | ||
| 51 | pub const SYS_recvfrom = 45; | ||
| 52 | pub const SYS_sendmsg = 46; | ||
| 53 | pub const SYS_recvmsg = 47; | ||
| 54 | pub const SYS_shutdown = 48; | ||
| 55 | pub const SYS_bind = 49; | ||
| 56 | pub const SYS_listen = 50; | ||
| 57 | pub const SYS_getsockname = 51; | ||
| 58 | pub const SYS_getpeername = 52; | ||
| 59 | pub const SYS_socketpair = 53; | ||
| 60 | pub const SYS_setsockopt = 54; | ||
| 61 | pub const SYS_getsockopt = 55; | ||
| 62 | pub const SYS_clone = 56; | ||
| 63 | pub const SYS_fork = 57; | ||
| 64 | pub const SYS_vfork = 58; | ||
| 65 | pub const SYS_execve = 59; | ||
| 66 | pub const SYS_exit = 60; | ||
| 67 | pub const SYS_wait4 = 61; | ||
| 68 | pub const SYS_kill = 62; | ||
| 69 | pub const SYS_uname = 63; | ||
| 70 | pub const SYS_semget = 64; | ||
| 71 | pub const SYS_semop = 65; | ||
| 72 | pub const SYS_semctl = 66; | ||
| 73 | pub const SYS_shmdt = 67; | ||
| 74 | pub const SYS_msgget = 68; | ||
| 75 | pub const SYS_msgsnd = 69; | ||
| 76 | pub const SYS_msgrcv = 70; | ||
| 77 | pub const SYS_msgctl = 71; | ||
| 78 | pub const SYS_fcntl = 72; | ||
| 79 | pub const SYS_flock = 73; | ||
| 80 | pub const SYS_fsync = 74; | ||
| 81 | pub const SYS_fdatasync = 75; | ||
| 82 | pub const SYS_truncate = 76; | ||
| 83 | pub const SYS_ftruncate = 77; | ||
| 84 | pub const SYS_getdents = 78; | ||
| 85 | pub const SYS_getcwd = 79; | ||
| 86 | pub const SYS_chdir = 80; | ||
| 87 | pub const SYS_fchdir = 81; | ||
| 88 | pub const SYS_rename = 82; | ||
| 89 | pub const SYS_mkdir = 83; | ||
| 90 | pub const SYS_rmdir = 84; | ||
| 91 | pub const SYS_creat = 85; | ||
| 92 | pub const SYS_link = 86; | ||
| 93 | pub const SYS_unlink = 87; | ||
| 94 | pub const SYS_symlink = 88; | ||
| 95 | pub const SYS_readlink = 89; | ||
| 96 | pub const SYS_chmod = 90; | ||
| 97 | pub const SYS_fchmod = 91; | ||
| 98 | pub const SYS_chown = 92; | ||
| 99 | pub const SYS_fchown = 93; | ||
| 100 | pub const SYS_lchown = 94; | ||
| 101 | pub const SYS_umask = 95; | ||
| 102 | pub const SYS_gettimeofday = 96; | ||
| 103 | pub const SYS_getrlimit = 97; | ||
| 104 | pub const SYS_getrusage = 98; | ||
| 105 | pub const SYS_sysinfo = 99; | ||
| 106 | pub const SYS_times = 100; | ||
| 107 | pub const SYS_ptrace = 101; | ||
| 108 | pub const SYS_getuid = 102; | ||
| 109 | pub const SYS_syslog = 103; | ||
| 110 | pub const SYS_getgid = 104; | ||
| 111 | pub const SYS_setuid = 105; | ||
| 112 | pub const SYS_setgid = 106; | ||
| 113 | pub const SYS_geteuid = 107; | ||
| 114 | pub const SYS_getegid = 108; | ||
| 115 | pub const SYS_setpgid = 109; | ||
| 116 | pub const SYS_getppid = 110; | ||
| 117 | pub const SYS_getpgrp = 111; | ||
| 118 | pub const SYS_setsid = 112; | ||
| 119 | pub const SYS_setreuid = 113; | ||
| 120 | pub const SYS_setregid = 114; | ||
| 121 | pub const SYS_getgroups = 115; | ||
| 122 | pub const SYS_setgroups = 116; | ||
| 123 | pub const SYS_setresuid = 117; | ||
| 124 | pub const SYS_getresuid = 118; | ||
| 125 | pub const SYS_setresgid = 119; | ||
| 126 | pub const SYS_getresgid = 120; | ||
| 127 | pub const SYS_getpgid = 121; | ||
| 128 | pub const SYS_setfsuid = 122; | ||
| 129 | pub const SYS_setfsgid = 123; | ||
| 130 | pub const SYS_getsid = 124; | ||
| 131 | pub const SYS_capget = 125; | ||
| 132 | pub const SYS_capset = 126; | ||
| 133 | pub const SYS_rt_sigpending = 127; | ||
| 134 | pub const SYS_rt_sigtimedwait = 128; | ||
| 135 | pub const SYS_rt_sigqueueinfo = 129; | ||
| 136 | pub const SYS_rt_sigsuspend = 130; | ||
| 137 | pub const SYS_sigaltstack = 131; | ||
| 138 | pub const SYS_utime = 132; | ||
| 139 | pub const SYS_mknod = 133; | ||
| 140 | pub const SYS_uselib = 134; | ||
| 141 | pub const SYS_personality = 135; | ||
| 142 | pub const SYS_ustat = 136; | ||
| 143 | pub const SYS_statfs = 137; | ||
| 144 | pub const SYS_fstatfs = 138; | ||
| 145 | pub const SYS_sysfs = 139; | ||
| 146 | pub const SYS_getpriority = 140; | ||
| 147 | pub const SYS_setpriority = 141; | ||
| 148 | pub const SYS_sched_setparam = 142; | ||
| 149 | pub const SYS_sched_getparam = 143; | ||
| 150 | pub const SYS_sched_setscheduler = 144; | ||
| 151 | pub const SYS_sched_getscheduler = 145; | ||
| 152 | pub const SYS_sched_get_priority_max = 146; | ||
| 153 | pub const SYS_sched_get_priority_min = 147; | ||
| 154 | pub const SYS_sched_rr_get_interval = 148; | ||
| 155 | pub const SYS_mlock = 149; | ||
| 156 | pub const SYS_munlock = 150; | ||
| 157 | pub const SYS_mlockall = 151; | ||
| 158 | pub const SYS_munlockall = 152; | ||
| 159 | pub const SYS_vhangup = 153; | ||
| 160 | pub const SYS_modify_ldt = 154; | ||
| 161 | pub const SYS_pivot_root = 155; | ||
| 162 | pub const SYS__sysctl = 156; | ||
| 163 | pub const SYS_prctl = 157; | ||
| 164 | pub const SYS_arch_prctl = 158; | ||
| 165 | pub const SYS_adjtimex = 159; | ||
| 166 | pub const SYS_setrlimit = 160; | ||
| 167 | pub const SYS_chroot = 161; | ||
| 168 | pub const SYS_sync = 162; | ||
| 169 | pub const SYS_acct = 163; | ||
| 170 | pub const SYS_settimeofday = 164; | ||
| 171 | pub const SYS_mount = 165; | ||
| 172 | pub const SYS_umount2 = 166; | ||
| 173 | pub const SYS_swapon = 167; | ||
| 174 | pub const SYS_swapoff = 168; | ||
| 175 | pub const SYS_reboot = 169; | ||
| 176 | pub const SYS_sethostname = 170; | ||
| 177 | pub const SYS_setdomainname = 171; | ||
| 178 | pub const SYS_iopl = 172; | ||
| 179 | pub const SYS_ioperm = 173; | ||
| 180 | pub const SYS_create_module = 174; | ||
| 181 | pub const SYS_init_module = 175; | ||
| 182 | pub const SYS_delete_module = 176; | ||
| 183 | pub const SYS_get_kernel_syms = 177; | ||
| 184 | pub const SYS_query_module = 178; | ||
| 185 | pub const SYS_quotactl = 179; | ||
| 186 | pub const SYS_nfsservctl = 180; | ||
| 187 | pub const SYS_getpmsg = 181; | ||
| 188 | pub const SYS_putpmsg = 182; | ||
| 189 | pub const SYS_afs_syscall = 183; | ||
| 190 | pub const SYS_tuxcall = 184; | ||
| 191 | pub const SYS_security = 185; | ||
| 192 | pub const SYS_gettid = 186; | ||
| 193 | pub const SYS_readahead = 187; | ||
| 194 | pub const SYS_setxattr = 188; | ||
| 195 | pub const SYS_lsetxattr = 189; | ||
| 196 | pub const SYS_fsetxattr = 190; | ||
| 197 | pub const SYS_getxattr = 191; | ||
| 198 | pub const SYS_lgetxattr = 192; | ||
| 199 | pub const SYS_fgetxattr = 193; | ||
| 200 | pub const SYS_listxattr = 194; | ||
| 201 | pub const SYS_llistxattr = 195; | ||
| 202 | pub const SYS_flistxattr = 196; | ||
| 203 | pub const SYS_removexattr = 197; | ||
| 204 | pub const SYS_lremovexattr = 198; | ||
| 205 | pub const SYS_fremovexattr = 199; | ||
| 206 | pub const SYS_tkill = 200; | ||
| 207 | pub const SYS_time = 201; | ||
| 208 | pub const SYS_futex = 202; | ||
| 209 | pub const SYS_sched_setaffinity = 203; | ||
| 210 | pub const SYS_sched_getaffinity = 204; | ||
| 211 | pub const SYS_set_thread_area = 205; | ||
| 212 | pub const SYS_io_setup = 206; | ||
| 213 | pub const SYS_io_destroy = 207; | ||
| 214 | pub const SYS_io_getevents = 208; | ||
| 215 | pub const SYS_io_submit = 209; | ||
| 216 | pub const SYS_io_cancel = 210; | ||
| 217 | pub const SYS_get_thread_area = 211; | ||
| 218 | pub const SYS_lookup_dcookie = 212; | ||
| 219 | pub const SYS_epoll_create = 213; | ||
| 220 | pub const SYS_epoll_ctl_old = 214; | ||
| 221 | pub const SYS_epoll_wait_old = 215; | ||
| 222 | pub const SYS_remap_file_pages = 216; | ||
| 223 | pub const SYS_getdents64 = 217; | ||
| 224 | pub const SYS_set_tid_address = 218; | ||
| 225 | pub const SYS_restart_syscall = 219; | ||
| 226 | pub const SYS_semtimedop = 220; | ||
| 227 | pub const SYS_fadvise64 = 221; | ||
| 228 | pub const SYS_timer_create = 222; | ||
| 229 | pub const SYS_timer_settime = 223; | ||
| 230 | pub const SYS_timer_gettime = 224; | ||
| 231 | pub const SYS_timer_getoverrun = 225; | ||
| 232 | pub const SYS_timer_delete = 226; | ||
| 233 | pub const SYS_clock_settime = 227; | ||
| 234 | pub const SYS_clock_gettime = 228; | ||
| 235 | pub const SYS_clock_getres = 229; | ||
| 236 | pub const SYS_clock_nanosleep = 230; | ||
| 237 | pub const SYS_exit_group = 231; | ||
| 238 | pub const SYS_epoll_wait = 232; | ||
| 239 | pub const SYS_epoll_ctl = 233; | ||
| 240 | pub const SYS_tgkill = 234; | ||
| 241 | pub const SYS_utimes = 235; | ||
| 242 | pub const SYS_vserver = 236; | ||
| 243 | pub const SYS_mbind = 237; | ||
| 244 | pub const SYS_set_mempolicy = 238; | ||
| 245 | pub const SYS_get_mempolicy = 239; | ||
| 246 | pub const SYS_mq_open = 240; | ||
| 247 | pub const SYS_mq_unlink = 241; | ||
| 248 | pub const SYS_mq_timedsend = 242; | ||
| 249 | pub const SYS_mq_timedreceive = 243; | ||
| 250 | pub const SYS_mq_notify = 244; | ||
| 251 | pub const SYS_mq_getsetattr = 245; | ||
| 252 | pub const SYS_kexec_load = 246; | ||
| 253 | pub const SYS_waitid = 247; | ||
| 254 | pub const SYS_add_key = 248; | ||
| 255 | pub const SYS_request_key = 249; | ||
| 256 | pub const SYS_keyctl = 250; | ||
| 257 | pub const SYS_ioprio_set = 251; | ||
| 258 | pub const SYS_ioprio_get = 252; | ||
| 259 | pub const SYS_inotify_init = 253; | ||
| 260 | pub const SYS_inotify_add_watch = 254; | ||
| 261 | pub const SYS_inotify_rm_watch = 255; | ||
| 262 | pub const SYS_migrate_pages = 256; | ||
| 263 | pub const SYS_openat = 257; | ||
| 264 | pub const SYS_mkdirat = 258; | ||
| 265 | pub const SYS_mknodat = 259; | ||
| 266 | pub const SYS_fchownat = 260; | ||
| 267 | pub const SYS_futimesat = 261; | ||
| 268 | pub const SYS_newfstatat = 262; | ||
| 269 | pub const SYS_unlinkat = 263; | ||
| 270 | pub const SYS_renameat = 264; | ||
| 271 | pub const SYS_linkat = 265; | ||
| 272 | pub const SYS_symlinkat = 266; | ||
| 273 | pub const SYS_readlinkat = 267; | ||
| 274 | pub const SYS_fchmodat = 268; | ||
| 275 | pub const SYS_faccessat = 269; | ||
| 276 | pub const SYS_pselect6 = 270; | ||
| 277 | pub const SYS_ppoll = 271; | ||
| 278 | pub const SYS_unshare = 272; | ||
| 279 | pub const SYS_set_robust_list = 273; | ||
| 280 | pub const SYS_get_robust_list = 274; | ||
| 281 | pub const SYS_splice = 275; | ||
| 282 | pub const SYS_tee = 276; | ||
| 283 | pub const SYS_sync_file_range = 277; | ||
| 284 | pub const SYS_vmsplice = 278; | ||
| 285 | pub const SYS_move_pages = 279; | ||
| 286 | pub const SYS_utimensat = 280; | ||
| 287 | pub const SYS_epoll_pwait = 281; | ||
| 288 | pub const SYS_signalfd = 282; | ||
| 289 | pub const SYS_timerfd_create = 283; | ||
| 290 | pub const SYS_eventfd = 284; | ||
| 291 | pub const SYS_fallocate = 285; | ||
| 292 | pub const SYS_timerfd_settime = 286; | ||
| 293 | pub const SYS_timerfd_gettime = 287; | ||
| 294 | pub const SYS_accept4 = 288; | ||
| 295 | pub const SYS_signalfd4 = 289; | ||
| 296 | pub const SYS_eventfd2 = 290; | ||
| 297 | pub const SYS_epoll_create1 = 291; | ||
| 298 | pub const SYS_dup3 = 292; | ||
| 299 | pub const SYS_pipe2 = 293; | ||
| 300 | pub const SYS_inotify_init1 = 294; | ||
| 301 | pub const SYS_preadv = 295; | ||
| 302 | pub const SYS_pwritev = 296; | ||
| 303 | pub const SYS_rt_tgsigqueueinfo = 297; | ||
| 304 | pub const SYS_perf_event_open = 298; | ||
| 305 | pub const SYS_recvmmsg = 299; | ||
| 306 | pub const SYS_fanotify_init = 300; | ||
| 307 | pub const SYS_fanotify_mark = 301; | ||
| 308 | pub const SYS_prlimit64 = 302; | ||
| 309 | pub const SYS_name_to_handle_at = 303; | ||
| 310 | pub const SYS_open_by_handle_at = 304; | ||
| 311 | pub const SYS_clock_adjtime = 305; | ||
| 312 | pub const SYS_syncfs = 306; | ||
| 313 | pub const SYS_sendmmsg = 307; | ||
| 314 | pub const SYS_setns = 308; | ||
| 315 | pub const SYS_getcpu = 309; | ||
| 316 | pub const SYS_process_vm_readv = 310; | ||
| 317 | pub const SYS_process_vm_writev = 311; | ||
| 318 | pub const SYS_kcmp = 312; | ||
| 319 | pub const SYS_finit_module = 313; | ||
| 320 | pub const SYS_sched_setattr = 314; | ||
| 321 | pub const SYS_sched_getattr = 315; | ||
| 322 | pub const SYS_renameat2 = 316; | ||
| 323 | pub const SYS_seccomp = 317; | ||
| 324 | pub const SYS_getrandom = 318; | ||
| 325 | pub const SYS_memfd_create = 319; | ||
| 326 | pub const SYS_kexec_file_load = 320; | ||
| 327 | pub const SYS_bpf = 321; | ||
| 328 | pub const SYS_execveat = 322; | ||
| 329 | pub const SYS_userfaultfd = 323; | ||
| 330 | pub const SYS_membarrier = 324; | ||
| 331 | pub const SYS_mlock2 = 325; | ||
| 332 | |||
| 333 | pub const O_CREAT = 0o100; | ||
| 334 | pub const O_EXCL = 0o200; | ||
| 335 | pub const O_NOCTTY = 0o400; | ||
| 336 | pub const O_TRUNC = 0o1000; | ||
| 337 | pub const O_APPEND = 0o2000; | ||
| 338 | pub const O_NONBLOCK = 0o4000; | ||
| 339 | pub const O_DSYNC = 0o10000; | ||
| 340 | pub const O_SYNC = 0o4010000; | ||
| 341 | pub const O_RSYNC = 0o4010000; | ||
| 342 | pub const O_DIRECTORY = 0o200000; | ||
| 343 | pub const O_NOFOLLOW = 0o400000; | ||
| 344 | pub const O_CLOEXEC = 0o2000000; | ||
| 345 | |||
| 346 | pub const O_ASYNC = 0o20000; | ||
| 347 | pub const O_DIRECT = 0o40000; | ||
| 348 | pub const O_LARGEFILE = 0; | ||
| 349 | pub const O_NOATIME = 0o1000000; | ||
| 350 | pub const O_PATH = 0o10000000; | ||
| 351 | pub const O_TMPFILE = 0o20200000; | ||
| 352 | pub const O_NDELAY = O_NONBLOCK; | ||
| 353 | |||
| 354 | pub const F_DUPFD = 0; | ||
| 355 | pub const F_GETFD = 1; | ||
| 356 | pub const F_SETFD = 2; | ||
| 357 | pub const F_GETFL = 3; | ||
| 358 | pub const F_SETFL = 4; | ||
| 359 | |||
| 360 | pub const F_SETOWN = 8; | ||
| 361 | pub const F_GETOWN = 9; | ||
| 362 | pub const F_SETSIG = 10; | ||
| 363 | pub const F_GETSIG = 11; | ||
| 364 | |||
| 365 | pub const F_GETLK = 5; | ||
| 366 | pub const F_SETLK = 6; | ||
| 367 | pub const F_SETLKW = 7; | ||
| 368 | |||
| 369 | pub const F_SETOWN_EX = 15; | ||
| 370 | pub const F_GETOWN_EX = 16; | ||
| 371 | |||
| 372 | pub const F_GETOWNER_UIDS = 17; | ||
| 373 | |||
| 374 | pub fn syscall0(number: usize) usize { | ||
| 375 | return asm volatile ("syscall" | ||
| 376 | : [ret] "={rax}" (-> usize) | ||
| 377 | : [number] "{rax}" (number) | ||
| 378 | : "rcx", "r11"); | ||
| 379 | } | ||
| 380 | |||
| 381 | pub fn syscall1(number: usize, arg1: usize) usize { | ||
| 382 | return asm volatile ("syscall" | ||
| 383 | : [ret] "={rax}" (-> usize) | ||
| 384 | : [number] "{rax}" (number), | ||
| 385 | [arg1] "{rdi}" (arg1) | ||
| 386 | : "rcx", "r11"); | ||
| 387 | } | ||
| 388 | |||
| 389 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | ||
| 390 | return asm volatile ("syscall" | ||
| 391 | : [ret] "={rax}" (-> usize) | ||
| 392 | : [number] "{rax}" (number), | ||
| 393 | [arg1] "{rdi}" (arg1), | ||
| 394 | [arg2] "{rsi}" (arg2) | ||
| 395 | : "rcx", "r11"); | ||
| 396 | } | ||
| 397 | |||
| 398 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | ||
| 399 | return asm volatile ("syscall" | ||
| 400 | : [ret] "={rax}" (-> usize) | ||
| 401 | : [number] "{rax}" (number), | ||
| 402 | [arg1] "{rdi}" (arg1), | ||
| 403 | [arg2] "{rsi}" (arg2), | ||
| 404 | [arg3] "{rdx}" (arg3) | ||
| 405 | : "rcx", "r11"); | ||
| 406 | } | ||
| 407 | |||
| 408 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | ||
| 409 | return asm volatile ("syscall" | ||
| 410 | : [ret] "={rax}" (-> usize) | ||
| 411 | : [number] "{rax}" (number), | ||
| 412 | [arg1] "{rdi}" (arg1), | ||
| 413 | [arg2] "{rsi}" (arg2), | ||
| 414 | [arg3] "{rdx}" (arg3), | ||
| 415 | [arg4] "{r10}" (arg4) | ||
| 416 | : "rcx", "r11"); | ||
| 417 | } | ||
| 418 | |||
| 419 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | ||
| 420 | return asm volatile ("syscall" | ||
| 421 | : [ret] "={rax}" (-> usize) | ||
| 422 | : [number] "{rax}" (number), | ||
| 423 | [arg1] "{rdi}" (arg1), | ||
| 424 | [arg2] "{rsi}" (arg2), | ||
| 425 | [arg3] "{rdx}" (arg3), | ||
| 426 | [arg4] "{r10}" (arg4), | ||
| 427 | [arg5] "{r8}" (arg5) | ||
| 428 | : "rcx", "r11"); | ||
| 429 | } | ||
| 430 | |||
| 431 | pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, | ||
| 432 | arg5: usize, arg6: usize) usize | ||
| 433 | { | ||
| 434 | return asm volatile ("syscall" | ||
| 435 | : [ret] "={rax}" (-> usize) | ||
| 436 | : [number] "{rax}" (number), | ||
| 437 | [arg1] "{rdi}" (arg1), | ||
| 438 | [arg2] "{rsi}" (arg2), | ||
| 439 | [arg3] "{rdx}" (arg3), | ||
| 440 | [arg4] "{r10}" (arg4), | ||
| 441 | [arg5] "{r8}" (arg5), | ||
| 442 | [arg6] "{r9}" (arg6) | ||
| 443 | : "rcx", "r11"); | ||
| 444 | } | ||
| 445 | |||
| 446 | pub nakedcc fn restore_rt() void { | ||
| 447 | return asm volatile ("syscall" | ||
| 448 | : | ||
| 449 | : [number] "{rax}" (usize(SYS_rt_sigreturn)) | ||
| 450 | : "rcx", "r11"); | ||
| 451 | } | ||
| 452 | |||
| 453 | |||
| 454 | pub const msghdr = extern struct { | ||
| 455 | msg_name: &u8, | ||
| 456 | msg_namelen: socklen_t, | ||
| 457 | msg_iov: &iovec, | ||
| 458 | msg_iovlen: i32, | ||
| 459 | __pad1: i32, | ||
| 460 | msg_control: &u8, | ||
| 461 | msg_controllen: socklen_t, | ||
| 462 | __pad2: socklen_t, | ||
| 463 | msg_flags: i32, | ||
| 464 | }; | ||
| 465 | |||
| 466 | /// Renamed to Stat to not conflict with the stat function. | ||
| 467 | pub const Stat = extern struct { | ||
| 468 | dev: u64, | ||
| 469 | ino: u64, | ||
| 470 | nlink: usize, | ||
| 471 | |||
| 472 | mode: u32, | ||
| 473 | uid: u32, | ||
| 474 | gid: u32, | ||
| 475 | __pad0: u32, | ||
| 476 | rdev: u64, | ||
| 477 | size: i64, | ||
| 478 | blksize: isize, | ||
| 479 | blocks: i64, | ||
| 480 | |||
| 481 | atim: timespec, | ||
| 482 | mtim: timespec, | ||
| 483 | ctim: timespec, | ||
| 484 | __unused: [3]isize, | ||
| 485 | }; | ||
| 486 | |||
| 487 | pub const timespec = extern struct { | ||
| 488 | tv_sec: isize, | ||
| 489 | tv_nsec: isize, | ||
| 490 | }; | ||
std/os/linux_errno.zig deleted-146| ... | @@ -1,146 +0,0 @@ | ||
| 1 | pub const EPERM = 1; /// Operation not permitted | ||
| 2 | pub const ENOENT = 2; /// No such file or directory | ||
| 3 | pub const ESRCH = 3; /// No such process | ||
| 4 | pub const EINTR = 4; /// Interrupted system call | ||
| 5 | pub const EIO = 5; /// I/O error | ||
| 6 | pub const ENXIO = 6; /// No such device or address | ||
| 7 | pub const E2BIG = 7; /// Arg list too long | ||
| 8 | pub const ENOEXEC = 8; /// Exec format error | ||
| 9 | pub const EBADF = 9; /// Bad file number | ||
| 10 | pub const ECHILD = 10; /// No child processes | ||
| 11 | pub const EAGAIN = 11; /// Try again | ||
| 12 | pub const ENOMEM = 12; /// Out of memory | ||
| 13 | pub const EACCES = 13; /// Permission denied | ||
| 14 | pub const EFAULT = 14; /// Bad address | ||
| 15 | pub const ENOTBLK = 15; /// Block device required | ||
| 16 | pub const EBUSY = 16; /// Device or resource busy | ||
| 17 | pub const EEXIST = 17; /// File exists | ||
| 18 | pub const EXDEV = 18; /// Cross-device link | ||
| 19 | pub const ENODEV = 19; /// No such device | ||
| 20 | pub const ENOTDIR = 20; /// Not a directory | ||
| 21 | pub const EISDIR = 21; /// Is a directory | ||
| 22 | pub const EINVAL = 22; /// Invalid argument | ||
| 23 | pub const ENFILE = 23; /// File table overflow | ||
| 24 | pub const EMFILE = 24; /// Too many open files | ||
| 25 | pub const ENOTTY = 25; /// Not a typewriter | ||
| 26 | pub const ETXTBSY = 26; /// Text file busy | ||
| 27 | pub const EFBIG = 27; /// File too large | ||
| 28 | pub const ENOSPC = 28; /// No space left on device | ||
| 29 | pub const ESPIPE = 29; /// Illegal seek | ||
| 30 | pub const EROFS = 30; /// Read-only file system | ||
| 31 | pub const EMLINK = 31; /// Too many links | ||
| 32 | pub const EPIPE = 32; /// Broken pipe | ||
| 33 | pub const EDOM = 33; /// Math argument out of domain of func | ||
| 34 | pub const ERANGE = 34; /// Math result not representable | ||
| 35 | pub const EDEADLK = 35; /// Resource deadlock would occur | ||
| 36 | pub const ENAMETOOLONG = 36; /// File name too long | ||
| 37 | pub const ENOLCK = 37; /// No record locks available | ||
| 38 | pub const ENOSYS = 38; /// Function not implemented | ||
| 39 | pub const ENOTEMPTY = 39; /// Directory not empty | ||
| 40 | pub const ELOOP = 40; /// Too many symbolic links encountered | ||
| 41 | pub const EWOULDBLOCK = EAGAIN; /// Operation would block | ||
| 42 | pub const ENOMSG = 42; /// No message of desired type | ||
| 43 | pub const EIDRM = 43; /// Identifier removed | ||
| 44 | pub const ECHRNG = 44; /// Channel number out of range | ||
| 45 | pub const EL2NSYNC = 45; /// Level 2 not synchronized | ||
| 46 | pub const EL3HLT = 46; /// Level 3 halted | ||
| 47 | pub const EL3RST = 47; /// Level 3 reset | ||
| 48 | pub const ELNRNG = 48; /// Link number out of range | ||
| 49 | pub const EUNATCH = 49; /// Protocol driver not attached | ||
| 50 | pub const ENOCSI = 50; /// No CSI structure available | ||
| 51 | pub const EL2HLT = 51; /// Level 2 halted | ||
| 52 | pub const EBADE = 52; /// Invalid exchange | ||
| 53 | pub const EBADR = 53; /// Invalid request descriptor | ||
| 54 | pub const EXFULL = 54; /// Exchange full | ||
| 55 | pub const ENOANO = 55; /// No anode | ||
| 56 | pub const EBADRQC = 56; /// Invalid request code | ||
| 57 | pub const EBADSLT = 57; /// Invalid slot | ||
| 58 | |||
| 59 | pub const EBFONT = 59; /// Bad font file format | ||
| 60 | pub const ENOSTR = 60; /// Device not a stream | ||
| 61 | pub const ENODATA = 61; /// No data available | ||
| 62 | pub const ETIME = 62; /// Timer expired | ||
| 63 | pub const ENOSR = 63; /// Out of streams resources | ||
| 64 | pub const ENONET = 64; /// Machine is not on the network | ||
| 65 | pub const ENOPKG = 65; /// Package not installed | ||
| 66 | pub const EREMOTE = 66; /// Object is remote | ||
| 67 | pub const ENOLINK = 67; /// Link has been severed | ||
| 68 | pub const EADV = 68; /// Advertise error | ||
| 69 | pub const ESRMNT = 69; /// Srmount error | ||
| 70 | pub const ECOMM = 70; /// Communication error on send | ||
| 71 | pub const EPROTO = 71; /// Protocol error | ||
| 72 | pub const EMULTIHOP = 72; /// Multihop attempted | ||
| 73 | pub const EDOTDOT = 73; /// RFS specific error | ||
| 74 | pub const EBADMSG = 74; /// Not a data message | ||
| 75 | pub const EOVERFLOW = 75; /// Value too large for defined data type | ||
| 76 | pub const ENOTUNIQ = 76; /// Name not unique on network | ||
| 77 | pub const EBADFD = 77; /// File descriptor in bad state | ||
| 78 | pub const EREMCHG = 78; /// Remote address changed | ||
| 79 | pub const ELIBACC = 79; /// Can not access a needed shared library | ||
| 80 | pub const ELIBBAD = 80; /// Accessing a corrupted shared library | ||
| 81 | pub const ELIBSCN = 81; /// .lib section in a.out corrupted | ||
| 82 | pub const ELIBMAX = 82; /// Attempting to link in too many shared libraries | ||
| 83 | pub const ELIBEXEC = 83; /// Cannot exec a shared library directly | ||
| 84 | pub const EILSEQ = 84; /// Illegal byte sequence | ||
| 85 | pub const ERESTART = 85; /// Interrupted system call should be restarted | ||
| 86 | pub const ESTRPIPE = 86; /// Streams pipe error | ||
| 87 | pub const EUSERS = 87; /// Too many users | ||
| 88 | pub const ENOTSOCK = 88; /// Socket operation on non-socket | ||
| 89 | pub const EDESTADDRREQ = 89; /// Destination address required | ||
| 90 | pub const EMSGSIZE = 90; /// Message too long | ||
| 91 | pub const EPROTOTYPE = 91; /// Protocol wrong type for socket | ||
| 92 | pub const ENOPROTOOPT = 92; /// Protocol not available | ||
| 93 | pub const EPROTONOSUPPORT = 93; /// Protocol not supported | ||
| 94 | pub const ESOCKTNOSUPPORT = 94; /// Socket type not supported | ||
| 95 | pub const EOPNOTSUPP = 95; /// Operation not supported on transport endpoint | ||
| 96 | pub const EPFNOSUPPORT = 96; /// Protocol family not supported | ||
| 97 | pub const EAFNOSUPPORT = 97; /// Address family not supported by protocol | ||
| 98 | pub const EADDRINUSE = 98; /// Address already in use | ||
| 99 | pub const EADDRNOTAVAIL = 99; /// Cannot assign requested address | ||
| 100 | pub const ENETDOWN = 100; /// Network is down | ||
| 101 | pub const ENETUNREACH = 101; /// Network is unreachable | ||
| 102 | pub const ENETRESET = 102; /// Network dropped connection because of reset | ||
| 103 | pub const ECONNABORTED = 103; /// Software caused connection abort | ||
| 104 | pub const ECONNRESET = 104; /// Connection reset by peer | ||
| 105 | pub const ENOBUFS = 105; /// No buffer space available | ||
| 106 | pub const EISCONN = 106; /// Transport endpoint is already connected | ||
| 107 | pub const ENOTCONN = 107; /// Transport endpoint is not connected | ||
| 108 | pub const ESHUTDOWN = 108; /// Cannot send after transport endpoint shutdown | ||
| 109 | pub const ETOOMANYREFS = 109; /// Too many references: cannot splice | ||
| 110 | pub const ETIMEDOUT = 110; /// Connection timed out | ||
| 111 | pub const ECONNREFUSED = 111; /// Connection refused | ||
| 112 | pub const EHOSTDOWN = 112; /// Host is down | ||
| 113 | pub const EHOSTUNREACH = 113; /// No route to host | ||
| 114 | pub const EALREADY = 114; /// Operation already in progress | ||
| 115 | pub const EINPROGRESS = 115; /// Operation now in progress | ||
| 116 | pub const ESTALE = 116; /// Stale NFS file handle | ||
| 117 | pub const EUCLEAN = 117; /// Structure needs cleaning | ||
| 118 | pub const ENOTNAM = 118; /// Not a XENIX named type file | ||
| 119 | pub const ENAVAIL = 119; /// No XENIX semaphores available | ||
| 120 | pub const EISNAM = 120; /// Is a named type file | ||
| 121 | pub const EREMOTEIO = 121; /// Remote I/O error | ||
| 122 | pub const EDQUOT = 122; /// Quota exceeded | ||
| 123 | |||
| 124 | pub const ENOMEDIUM = 123; /// No medium found | ||
| 125 | pub const EMEDIUMTYPE = 124; /// Wrong medium type | ||
| 126 | |||
| 127 | // nameserver query return codes | ||
| 128 | pub const ENSROK = 0; /// DNS server returned answer with no data | ||
| 129 | pub const ENSRNODATA = 160; /// DNS server returned answer with no data | ||
| 130 | pub const ENSRFORMERR = 161; /// DNS server claims query was misformatted | ||
| 131 | pub const ENSRSERVFAIL = 162; /// DNS server returned general failure | ||
| 132 | pub const ENSRNOTFOUND = 163; /// Domain name not found | ||
| 133 | pub const ENSRNOTIMP = 164; /// DNS server does not implement requested operation | ||
| 134 | pub const ENSRREFUSED = 165; /// DNS server refused query | ||
| 135 | pub const ENSRBADQUERY = 166; /// Misformatted DNS query | ||
| 136 | pub const ENSRBADNAME = 167; /// Misformatted domain name | ||
| 137 | pub const ENSRBADFAMILY = 168; /// Unsupported address family | ||
| 138 | pub const ENSRBADRESP = 169; /// Misformatted DNS reply | ||
| 139 | pub const ENSRCONNREFUSED = 170; /// Could not contact DNS servers | ||
| 140 | pub const ENSRTIMEOUT = 171; /// Timeout while contacting DNS servers | ||
| 141 | pub const ENSROF = 172; /// End of file | ||
| 142 | pub const ENSRFILE = 173; /// Error reading file | ||
| 143 | pub const ENSRNOMEM = 174; /// Out of memory | ||
| 144 | pub const ENSRDESTRUCTION = 175; /// Application terminated lookup | ||
| 145 | pub const ENSRQUERYDOMAINTOOLONG = 176; /// Domain name is too long | ||
| 146 | pub const ENSRCNAMELOOP = 177; /// Domain name is too long | ||
std/os/linux_i386.zig deleted-504| ... | @@ -1,504 +0,0 @@ | ||
| 1 | const linux = @import("linux.zig"); | ||
| 2 | const socklen_t = linux.socklen_t; | ||
| 3 | const iovec = linux.iovec; | ||
| 4 | |||
| 5 | pub const SYS_restart_syscall = 0; | ||
| 6 | pub const SYS_exit = 1; | ||
| 7 | pub const SYS_fork = 2; | ||
| 8 | pub const SYS_read = 3; | ||
| 9 | pub const SYS_write = 4; | ||
| 10 | pub const SYS_open = 5; | ||
| 11 | pub const SYS_close = 6; | ||
| 12 | pub const SYS_waitpid = 7; | ||
| 13 | pub const SYS_creat = 8; | ||
| 14 | pub const SYS_link = 9; | ||
| 15 | pub const SYS_unlink = 10; | ||
| 16 | pub const SYS_execve = 11; | ||
| 17 | pub const SYS_chdir = 12; | ||
| 18 | pub const SYS_time = 13; | ||
| 19 | pub const SYS_mknod = 14; | ||
| 20 | pub const SYS_chmod = 15; | ||
| 21 | pub const SYS_lchown = 16; | ||
| 22 | pub const SYS_break = 17; | ||
| 23 | pub const SYS_oldstat = 18; | ||
| 24 | pub const SYS_lseek = 19; | ||
| 25 | pub const SYS_getpid = 20; | ||
| 26 | pub const SYS_mount = 21; | ||
| 27 | pub const SYS_umount = 22; | ||
| 28 | pub const SYS_setuid = 23; | ||
| 29 | pub const SYS_getuid = 24; | ||
| 30 | pub const SYS_stime = 25; | ||
| 31 | pub const SYS_ptrace = 26; | ||
| 32 | pub const SYS_alarm = 27; | ||
| 33 | pub const SYS_oldfstat = 28; | ||
| 34 | pub const SYS_pause = 29; | ||
| 35 | pub const SYS_utime = 30; | ||
| 36 | pub const SYS_stty = 31; | ||
| 37 | pub const SYS_gtty = 32; | ||
| 38 | pub const SYS_access = 33; | ||
| 39 | pub const SYS_nice = 34; | ||
| 40 | pub const SYS_ftime = 35; | ||
| 41 | pub const SYS_sync = 36; | ||
| 42 | pub const SYS_kill = 37; | ||
| 43 | pub const SYS_rename = 38; | ||
| 44 | pub const SYS_mkdir = 39; | ||
| 45 | pub const SYS_rmdir = 40; | ||
| 46 | pub const SYS_dup = 41; | ||
| 47 | pub const SYS_pipe = 42; | ||
| 48 | pub const SYS_times = 43; | ||
| 49 | pub const SYS_prof = 44; | ||
| 50 | pub const SYS_brk = 45; | ||
| 51 | pub const SYS_setgid = 46; | ||
| 52 | pub const SYS_getgid = 47; | ||
| 53 | pub const SYS_signal = 48; | ||
| 54 | pub const SYS_geteuid = 49; | ||
| 55 | pub const SYS_getegid = 50; | ||
| 56 | pub const SYS_acct = 51; | ||
| 57 | pub const SYS_umount2 = 52; | ||
| 58 | pub const SYS_lock = 53; | ||
| 59 | pub const SYS_ioctl = 54; | ||
| 60 | pub const SYS_fcntl = 55; | ||
| 61 | pub const SYS_mpx = 56; | ||
| 62 | pub const SYS_setpgid = 57; | ||
| 63 | pub const SYS_ulimit = 58; | ||
| 64 | pub const SYS_oldolduname = 59; | ||
| 65 | pub const SYS_umask = 60; | ||
| 66 | pub const SYS_chroot = 61; | ||
| 67 | pub const SYS_ustat = 62; | ||
| 68 | pub const SYS_dup2 = 63; | ||
| 69 | pub const SYS_getppid = 64; | ||
| 70 | pub const SYS_getpgrp = 65; | ||
| 71 | pub const SYS_setsid = 66; | ||
| 72 | pub const SYS_sigaction = 67; | ||
| 73 | pub const SYS_sgetmask = 68; | ||
| 74 | pub const SYS_ssetmask = 69; | ||
| 75 | pub const SYS_setreuid = 70; | ||
| 76 | pub const SYS_setregid = 71; | ||
| 77 | pub const SYS_sigsuspend = 72; | ||
| 78 | pub const SYS_sigpending = 73; | ||
| 79 | pub const SYS_sethostname = 74; | ||
| 80 | pub const SYS_setrlimit = 75; | ||
| 81 | pub const SYS_getrlimit = 76; | ||
| 82 | pub const SYS_getrusage = 77; | ||
| 83 | pub const SYS_gettimeofday = 78; | ||
| 84 | pub const SYS_settimeofday = 79; | ||
| 85 | pub const SYS_getgroups = 80; | ||
| 86 | pub const SYS_setgroups = 81; | ||
| 87 | pub const SYS_select = 82; | ||
| 88 | pub const SYS_symlink = 83; | ||
| 89 | pub const SYS_oldlstat = 84; | ||
| 90 | pub const SYS_readlink = 85; | ||
| 91 | pub const SYS_uselib = 86; | ||
| 92 | pub const SYS_swapon = 87; | ||
| 93 | pub const SYS_reboot = 88; | ||
| 94 | pub const SYS_readdir = 89; | ||
| 95 | pub const SYS_mmap = 90; | ||
| 96 | pub const SYS_munmap = 91; | ||
| 97 | pub const SYS_truncate = 92; | ||
| 98 | pub const SYS_ftruncate = 93; | ||
| 99 | pub const SYS_fchmod = 94; | ||
| 100 | pub const SYS_fchown = 95; | ||
| 101 | pub const SYS_getpriority = 96; | ||
| 102 | pub const SYS_setpriority = 97; | ||
| 103 | pub const SYS_profil = 98; | ||
| 104 | pub const SYS_statfs = 99; | ||
| 105 | pub const SYS_fstatfs = 100; | ||
| 106 | pub const SYS_ioperm = 101; | ||
| 107 | pub const SYS_socketcall = 102; | ||
| 108 | pub const SYS_syslog = 103; | ||
| 109 | pub const SYS_setitimer = 104; | ||
| 110 | pub const SYS_getitimer = 105; | ||
| 111 | pub const SYS_stat = 106; | ||
| 112 | pub const SYS_lstat = 107; | ||
| 113 | pub const SYS_fstat = 108; | ||
| 114 | pub const SYS_olduname = 109; | ||
| 115 | pub const SYS_iopl = 110; | ||
| 116 | pub const SYS_vhangup = 111; | ||
| 117 | pub const SYS_idle = 112; | ||
| 118 | pub const SYS_vm86old = 113; | ||
| 119 | pub const SYS_wait4 = 114; | ||
| 120 | pub const SYS_swapoff = 115; | ||
| 121 | pub const SYS_sysinfo = 116; | ||
| 122 | pub const SYS_ipc = 117; | ||
| 123 | pub const SYS_fsync = 118; | ||
| 124 | pub const SYS_sigreturn = 119; | ||
| 125 | pub const SYS_clone = 120; | ||
| 126 | pub const SYS_setdomainname = 121; | ||
| 127 | pub const SYS_uname = 122; | ||
| 128 | pub const SYS_modify_ldt = 123; | ||
| 129 | pub const SYS_adjtimex = 124; | ||
| 130 | pub const SYS_mprotect = 125; | ||
| 131 | pub const SYS_sigprocmask = 126; | ||
| 132 | pub const SYS_create_module = 127; | ||
| 133 | pub const SYS_init_module = 128; | ||
| 134 | pub const SYS_delete_module = 129; | ||
| 135 | pub const SYS_get_kernel_syms = 130; | ||
| 136 | pub const SYS_quotactl = 131; | ||
| 137 | pub const SYS_getpgid = 132; | ||
| 138 | pub const SYS_fchdir = 133; | ||
| 139 | pub const SYS_bdflush = 134; | ||
| 140 | pub const SYS_sysfs = 135; | ||
| 141 | pub const SYS_personality = 136; | ||
| 142 | pub const SYS_afs_syscall = 137; | ||
| 143 | pub const SYS_setfsuid = 138; | ||
| 144 | pub const SYS_setfsgid = 139; | ||
| 145 | pub const SYS__llseek = 140; | ||
| 146 | pub const SYS_getdents = 141; | ||
| 147 | pub const SYS__newselect = 142; | ||
| 148 | pub const SYS_flock = 143; | ||
| 149 | pub const SYS_msync = 144; | ||
| 150 | pub const SYS_readv = 145; | ||
| 151 | pub const SYS_writev = 146; | ||
| 152 | pub const SYS_getsid = 147; | ||
| 153 | pub const SYS_fdatasync = 148; | ||
| 154 | pub const SYS__sysctl = 149; | ||
| 155 | pub const SYS_mlock = 150; | ||
| 156 | pub const SYS_munlock = 151; | ||
| 157 | pub const SYS_mlockall = 152; | ||
| 158 | pub const SYS_munlockall = 153; | ||
| 159 | pub const SYS_sched_setparam = 154; | ||
| 160 | pub const SYS_sched_getparam = 155; | ||
| 161 | pub const SYS_sched_setscheduler = 156; | ||
| 162 | pub const SYS_sched_getscheduler = 157; | ||
| 163 | pub const SYS_sched_yield = 158; | ||
| 164 | pub const SYS_sched_get_priority_max = 159; | ||
| 165 | pub const SYS_sched_get_priority_min = 160; | ||
| 166 | pub const SYS_sched_rr_get_interval = 161; | ||
| 167 | pub const SYS_nanosleep = 162; | ||
| 168 | pub const SYS_mremap = 163; | ||
| 169 | pub const SYS_setresuid = 164; | ||
| 170 | pub const SYS_getresuid = 165; | ||
| 171 | pub const SYS_vm86 = 166; | ||
| 172 | pub const SYS_query_module = 167; | ||
| 173 | pub const SYS_poll = 168; | ||
| 174 | pub const SYS_nfsservctl = 169; | ||
| 175 | pub const SYS_setresgid = 170; | ||
| 176 | pub const SYS_getresgid = 171; | ||
| 177 | pub const SYS_prctl = 172; | ||
| 178 | pub const SYS_rt_sigreturn = 173; | ||
| 179 | pub const SYS_rt_sigaction = 174; | ||
| 180 | pub const SYS_rt_sigprocmask = 175; | ||
| 181 | pub const SYS_rt_sigpending = 176; | ||
| 182 | pub const SYS_rt_sigtimedwait = 177; | ||
| 183 | pub const SYS_rt_sigqueueinfo = 178; | ||
| 184 | pub const SYS_rt_sigsuspend = 179; | ||
| 185 | pub const SYS_pread64 = 180; | ||
| 186 | pub const SYS_pwrite64 = 181; | ||
| 187 | pub const SYS_chown = 182; | ||
| 188 | pub const SYS_getcwd = 183; | ||
| 189 | pub const SYS_capget = 184; | ||
| 190 | pub const SYS_capset = 185; | ||
| 191 | pub const SYS_sigaltstack = 186; | ||
| 192 | pub const SYS_sendfile = 187; | ||
| 193 | pub const SYS_getpmsg = 188; | ||
| 194 | pub const SYS_putpmsg = 189; | ||
| 195 | pub const SYS_vfork = 190; | ||
| 196 | pub const SYS_ugetrlimit = 191; | ||
| 197 | pub const SYS_mmap2 = 192; | ||
| 198 | pub const SYS_truncate64 = 193; | ||
| 199 | pub const SYS_ftruncate64 = 194; | ||
| 200 | pub const SYS_stat64 = 195; | ||
| 201 | pub const SYS_lstat64 = 196; | ||
| 202 | pub const SYS_fstat64 = 197; | ||
| 203 | pub const SYS_lchown32 = 198; | ||
| 204 | pub const SYS_getuid32 = 199; | ||
| 205 | pub const SYS_getgid32 = 200; | ||
| 206 | pub const SYS_geteuid32 = 201; | ||
| 207 | pub const SYS_getegid32 = 202; | ||
| 208 | pub const SYS_setreuid32 = 203; | ||
| 209 | pub const SYS_setregid32 = 204; | ||
| 210 | pub const SYS_getgroups32 = 205; | ||
| 211 | pub const SYS_setgroups32 = 206; | ||
| 212 | pub const SYS_fchown32 = 207; | ||
| 213 | pub const SYS_setresuid32 = 208; | ||
| 214 | pub const SYS_getresuid32 = 209; | ||
| 215 | pub const SYS_setresgid32 = 210; | ||
| 216 | pub const SYS_getresgid32 = 211; | ||
| 217 | pub const SYS_chown32 = 212; | ||
| 218 | pub const SYS_setuid32 = 213; | ||
| 219 | pub const SYS_setgid32 = 214; | ||
| 220 | pub const SYS_setfsuid32 = 215; | ||
| 221 | pub const SYS_setfsgid32 = 216; | ||
| 222 | pub const SYS_pivot_root = 217; | ||
| 223 | pub const SYS_mincore = 218; | ||
| 224 | pub const SYS_madvise = 219; | ||
| 225 | pub const SYS_madvise1 = 219; | ||
| 226 | pub const SYS_getdents64 = 220; | ||
| 227 | pub const SYS_fcntl64 = 221; | ||
| 228 | pub const SYS_gettid = 224; | ||
| 229 | pub const SYS_readahead = 225; | ||
| 230 | pub const SYS_setxattr = 226; | ||
| 231 | pub const SYS_lsetxattr = 227; | ||
| 232 | pub const SYS_fsetxattr = 228; | ||
| 233 | pub const SYS_getxattr = 229; | ||
| 234 | pub const SYS_lgetxattr = 230; | ||
| 235 | pub const SYS_fgetxattr = 231; | ||
| 236 | pub const SYS_listxattr = 232; | ||
| 237 | pub const SYS_llistxattr = 233; | ||
| 238 | pub const SYS_flistxattr = 234; | ||
| 239 | pub const SYS_removexattr = 235; | ||
| 240 | pub const SYS_lremovexattr = 236; | ||
| 241 | pub const SYS_fremovexattr = 237; | ||
| 242 | pub const SYS_tkill = 238; | ||
| 243 | pub const SYS_sendfile64 = 239; | ||
| 244 | pub const SYS_futex = 240; | ||
| 245 | pub const SYS_sched_setaffinity = 241; | ||
| 246 | pub const SYS_sched_getaffinity = 242; | ||
| 247 | pub const SYS_set_thread_area = 243; | ||
| 248 | pub const SYS_get_thread_area = 244; | ||
| 249 | pub const SYS_io_setup = 245; | ||
| 250 | pub const SYS_io_destroy = 246; | ||
| 251 | pub const SYS_io_getevents = 247; | ||
| 252 | pub const SYS_io_submit = 248; | ||
| 253 | pub const SYS_io_cancel = 249; | ||
| 254 | pub const SYS_fadvise64 = 250; | ||
| 255 | pub const SYS_exit_group = 252; | ||
| 256 | pub const SYS_lookup_dcookie = 253; | ||
| 257 | pub const SYS_epoll_create = 254; | ||
| 258 | pub const SYS_epoll_ctl = 255; | ||
| 259 | pub const SYS_epoll_wait = 256; | ||
| 260 | pub const SYS_remap_file_pages = 257; | ||
| 261 | pub const SYS_set_tid_address = 258; | ||
| 262 | pub const SYS_timer_create = 259; | ||
| 263 | pub const SYS_timer_settime = SYS_timer_create+1; | ||
| 264 | pub const SYS_timer_gettime = SYS_timer_create+2; | ||
| 265 | pub const SYS_timer_getoverrun = SYS_timer_create+3; | ||
| 266 | pub const SYS_timer_delete = SYS_timer_create+4; | ||
| 267 | pub const SYS_clock_settime = SYS_timer_create+5; | ||
| 268 | pub const SYS_clock_gettime = SYS_timer_create+6; | ||
| 269 | pub const SYS_clock_getres = SYS_timer_create+7; | ||
| 270 | pub const SYS_clock_nanosleep = SYS_timer_create+8; | ||
| 271 | pub const SYS_statfs64 = 268; | ||
| 272 | pub const SYS_fstatfs64 = 269; | ||
| 273 | pub const SYS_tgkill = 270; | ||
| 274 | pub const SYS_utimes = 271; | ||
| 275 | pub const SYS_fadvise64_64 = 272; | ||
| 276 | pub const SYS_vserver = 273; | ||
| 277 | pub const SYS_mbind = 274; | ||
| 278 | pub const SYS_get_mempolicy = 275; | ||
| 279 | pub const SYS_set_mempolicy = 276; | ||
| 280 | pub const SYS_mq_open = 277; | ||
| 281 | pub const SYS_mq_unlink = SYS_mq_open+1; | ||
| 282 | pub const SYS_mq_timedsend = SYS_mq_open+2; | ||
| 283 | pub const SYS_mq_timedreceive = SYS_mq_open+3; | ||
| 284 | pub const SYS_mq_notify = SYS_mq_open+4; | ||
| 285 | pub const SYS_mq_getsetattr = SYS_mq_open+5; | ||
| 286 | pub const SYS_kexec_load = 283; | ||
| 287 | pub const SYS_waitid = 284; | ||
| 288 | pub const SYS_add_key = 286; | ||
| 289 | pub const SYS_request_key = 287; | ||
| 290 | pub const SYS_keyctl = 288; | ||
| 291 | pub const SYS_ioprio_set = 289; | ||
| 292 | pub const SYS_ioprio_get = 290; | ||
| 293 | pub const SYS_inotify_init = 291; | ||
| 294 | pub const SYS_inotify_add_watch = 292; | ||
| 295 | pub const SYS_inotify_rm_watch = 293; | ||
| 296 | pub const SYS_migrate_pages = 294; | ||
| 297 | pub const SYS_openat = 295; | ||
| 298 | pub const SYS_mkdirat = 296; | ||
| 299 | pub const SYS_mknodat = 297; | ||
| 300 | pub const SYS_fchownat = 298; | ||
| 301 | pub const SYS_futimesat = 299; | ||
| 302 | pub const SYS_fstatat64 = 300; | ||
| 303 | pub const SYS_unlinkat = 301; | ||
| 304 | pub const SYS_renameat = 302; | ||
| 305 | pub const SYS_linkat = 303; | ||
| 306 | pub const SYS_symlinkat = 304; | ||
| 307 | pub const SYS_readlinkat = 305; | ||
| 308 | pub const SYS_fchmodat = 306; | ||
| 309 | pub const SYS_faccessat = 307; | ||
| 310 | pub const SYS_pselect6 = 308; | ||
| 311 | pub const SYS_ppoll = 309; | ||
| 312 | pub const SYS_unshare = 310; | ||
| 313 | pub const SYS_set_robust_list = 311; | ||
| 314 | pub const SYS_get_robust_list = 312; | ||
| 315 | pub const SYS_splice = 313; | ||
| 316 | pub const SYS_sync_file_range = 314; | ||
| 317 | pub const SYS_tee = 315; | ||
| 318 | pub const SYS_vmsplice = 316; | ||
| 319 | pub const SYS_move_pages = 317; | ||
| 320 | pub const SYS_getcpu = 318; | ||
| 321 | pub const SYS_epoll_pwait = 319; | ||
| 322 | pub const SYS_utimensat = 320; | ||
| 323 | pub const SYS_signalfd = 321; | ||
| 324 | pub const SYS_timerfd_create = 322; | ||
| 325 | pub const SYS_eventfd = 323; | ||
| 326 | pub const SYS_fallocate = 324; | ||
| 327 | pub const SYS_timerfd_settime = 325; | ||
| 328 | pub const SYS_timerfd_gettime = 326; | ||
| 329 | pub const SYS_signalfd4 = 327; | ||
| 330 | pub const SYS_eventfd2 = 328; | ||
| 331 | pub const SYS_epoll_create1 = 329; | ||
| 332 | pub const SYS_dup3 = 330; | ||
| 333 | pub const SYS_pipe2 = 331; | ||
| 334 | pub const SYS_inotify_init1 = 332; | ||
| 335 | pub const SYS_preadv = 333; | ||
| 336 | pub const SYS_pwritev = 334; | ||
| 337 | pub const SYS_rt_tgsigqueueinfo = 335; | ||
| 338 | pub const SYS_perf_event_open = 336; | ||
| 339 | pub const SYS_recvmmsg = 337; | ||
| 340 | pub const SYS_fanotify_init = 338; | ||
| 341 | pub const SYS_fanotify_mark = 339; | ||
| 342 | pub const SYS_prlimit64 = 340; | ||
| 343 | pub const SYS_name_to_handle_at = 341; | ||
| 344 | pub const SYS_open_by_handle_at = 342; | ||
| 345 | pub const SYS_clock_adjtime = 343; | ||
| 346 | pub const SYS_syncfs = 344; | ||
| 347 | pub const SYS_sendmmsg = 345; | ||
| 348 | pub const SYS_setns = 346; | ||
| 349 | pub const SYS_process_vm_readv = 347; | ||
| 350 | pub const SYS_process_vm_writev = 348; | ||
| 351 | pub const SYS_kcmp = 349; | ||
| 352 | pub const SYS_finit_module = 350; | ||
| 353 | pub const SYS_sched_setattr = 351; | ||
| 354 | pub const SYS_sched_getattr = 352; | ||
| 355 | pub const SYS_renameat2 = 353; | ||
| 356 | pub const SYS_seccomp = 354; | ||
| 357 | pub const SYS_getrandom = 355; | ||
| 358 | pub const SYS_memfd_create = 356; | ||
| 359 | pub const SYS_bpf = 357; | ||
| 360 | pub const SYS_execveat = 358; | ||
| 361 | pub const SYS_socket = 359; | ||
| 362 | pub const SYS_socketpair = 360; | ||
| 363 | pub const SYS_bind = 361; | ||
| 364 | pub const SYS_connect = 362; | ||
| 365 | pub const SYS_listen = 363; | ||
| 366 | pub const SYS_accept4 = 364; | ||
| 367 | pub const SYS_getsockopt = 365; | ||
| 368 | pub const SYS_setsockopt = 366; | ||
| 369 | pub const SYS_getsockname = 367; | ||
| 370 | pub const SYS_getpeername = 368; | ||
| 371 | pub const SYS_sendto = 369; | ||
| 372 | pub const SYS_sendmsg = 370; | ||
| 373 | pub const SYS_recvfrom = 371; | ||
| 374 | pub const SYS_recvmsg = 372; | ||
| 375 | pub const SYS_shutdown = 373; | ||
| 376 | pub const SYS_userfaultfd = 374; | ||
| 377 | pub const SYS_membarrier = 375; | ||
| 378 | pub const SYS_mlock2 = 376; | ||
| 379 | |||
| 380 | |||
| 381 | pub const O_CREAT = 0o100; | ||
| 382 | pub const O_EXCL = 0o200; | ||
| 383 | pub const O_NOCTTY = 0o400; | ||
| 384 | pub const O_TRUNC = 0o1000; | ||
| 385 | pub const O_APPEND = 0o2000; | ||
| 386 | pub const O_NONBLOCK = 0o4000; | ||
| 387 | pub const O_DSYNC = 0o10000; | ||
| 388 | pub const O_SYNC = 0o4010000; | ||
| 389 | pub const O_RSYNC = 0o4010000; | ||
| 390 | pub const O_DIRECTORY = 0o200000; | ||
| 391 | pub const O_NOFOLLOW = 0o400000; | ||
| 392 | pub const O_CLOEXEC = 0o2000000; | ||
| 393 | |||
| 394 | pub const O_ASYNC = 0o20000; | ||
| 395 | pub const O_DIRECT = 0o40000; | ||
| 396 | pub const O_LARGEFILE = 0o100000; | ||
| 397 | pub const O_NOATIME = 0o1000000; | ||
| 398 | pub const O_PATH = 0o10000000; | ||
| 399 | pub const O_TMPFILE = 0o20200000; | ||
| 400 | pub const O_NDELAY = O_NONBLOCK; | ||
| 401 | |||
| 402 | pub const F_DUPFD = 0; | ||
| 403 | pub const F_GETFD = 1; | ||
| 404 | pub const F_SETFD = 2; | ||
| 405 | pub const F_GETFL = 3; | ||
| 406 | pub const F_SETFL = 4; | ||
| 407 | |||
| 408 | pub const F_SETOWN = 8; | ||
| 409 | pub const F_GETOWN = 9; | ||
| 410 | pub const F_SETSIG = 10; | ||
| 411 | pub const F_GETSIG = 11; | ||
| 412 | |||
| 413 | pub const F_GETLK = 12; | ||
| 414 | pub const F_SETLK = 13; | ||
| 415 | pub const F_SETLKW = 14; | ||
| 416 | |||
| 417 | pub const F_SETOWN_EX = 15; | ||
| 418 | pub const F_GETOWN_EX = 16; | ||
| 419 | |||
| 420 | pub const F_GETOWNER_UIDS = 17; | ||
| 421 | |||
| 422 | pub inline fn syscall0(number: usize) usize { | ||
| 423 | asm volatile ("int $0x80" | ||
| 424 | : [ret] "={eax}" (-> usize) | ||
| 425 | : [number] "{eax}" (number)) | ||
| 426 | } | ||
| 427 | |||
| 428 | pub inline fn syscall1(number: usize, arg1: usize) usize { | ||
| 429 | asm volatile ("int $0x80" | ||
| 430 | : [ret] "={eax}" (-> usize) | ||
| 431 | : [number] "{eax}" (number), | ||
| 432 | [arg1] "{ebx}" (arg1)) | ||
| 433 | } | ||
| 434 | |||
| 435 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | ||
| 436 | asm volatile ("int $0x80" | ||
| 437 | : [ret] "={eax}" (-> usize) | ||
| 438 | : [number] "{eax}" (number), | ||
| 439 | [arg1] "{ebx}" (arg1), | ||
| 440 | [arg2] "{ecx}" (arg2)) | ||
| 441 | } | ||
| 442 | |||
| 443 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | ||
| 444 | asm volatile ("int $0x80" | ||
| 445 | : [ret] "={eax}" (-> usize) | ||
| 446 | : [number] "{eax}" (number), | ||
| 447 | [arg1] "{ebx}" (arg1), | ||
| 448 | [arg2] "{ecx}" (arg2), | ||
| 449 | [arg3] "{edx}" (arg3)) | ||
| 450 | } | ||
| 451 | |||
| 452 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | ||
| 453 | asm volatile ("int $0x80" | ||
| 454 | : [ret] "={eax}" (-> usize) | ||
| 455 | : [number] "{eax}" (number), | ||
| 456 | [arg1] "{ebx}" (arg1), | ||
| 457 | [arg2] "{ecx}" (arg2), | ||
| 458 | [arg3] "{edx}" (arg3), | ||
| 459 | [arg4] "{esi}" (arg4)) | ||
| 460 | } | ||
| 461 | |||
| 462 | pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, | ||
| 463 | arg4: usize, arg5: usize) -> usize | ||
| 464 | { | ||
| 465 | asm volatile ("int $0x80" | ||
| 466 | : [ret] "={eax}" (-> usize) | ||
| 467 | : [number] "{eax}" (number), | ||
| 468 | [arg1] "{ebx}" (arg1), | ||
| 469 | [arg2] "{ecx}" (arg2), | ||
| 470 | [arg3] "{edx}" (arg3), | ||
| 471 | [arg4] "{esi}" (arg4), | ||
| 472 | [arg5] "{edi}" (arg5)) | ||
| 473 | } | ||
| 474 | |||
| 475 | pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, | ||
| 476 | arg4: usize, arg5: usize, arg6: usize) -> usize | ||
| 477 | { | ||
| 478 | asm volatile ("int $0x80" | ||
| 479 | : [ret] "={eax}" (-> usize) | ||
| 480 | : [number] "{eax}" (number), | ||
| 481 | [arg1] "{ebx}" (arg1), | ||
| 482 | [arg2] "{ecx}" (arg2), | ||
| 483 | [arg3] "{edx}" (arg3), | ||
| 484 | [arg4] "{esi}" (arg4), | ||
| 485 | [arg5] "{edi}" (arg5), | ||
| 486 | [arg6] "{ebp}" (arg6)) | ||
| 487 | } | ||
| 488 | |||
| 489 | pub nakedcc fn restore() void { | ||
| 490 | asm volatile ( | ||
| 491 | \\popl %%eax | ||
| 492 | \\movl $119, %%eax | ||
| 493 | \\int $0x80 | ||
| 494 | : | ||
| 495 | : | ||
| 496 | : "rcx", "r11") | ||
| 497 | } | ||
| 498 | |||
| 499 | pub nakedcc fn restore_rt() void { | ||
| 500 | asm volatile ("int $0x80" | ||
| 501 | : | ||
| 502 | : [number] "{eax}" (usize(SYS_rt_sigreturn)) | ||
| 503 | : "rcx", "r11") | ||
| 504 | } | ||
std/os/linux_random.zig deleted-246| ... | @@ -1,246 +0,0 @@ | ||
| 1 | const std = @import("../index.zig"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const assert = std.debug.assert; | ||
| 4 | const linux = std.os.linux; | ||
| 5 | const math = std.math; | ||
| 6 | const mem = std.mem; | ||
| 7 | const os = std.os; | ||
| 8 | |||
| 9 | use @import("linux_errno.zig"); | ||
| 10 | |||
| 11 | const arch = switch (builtin.arch) { | ||
| 12 | builtin.Arch.x86_64 => @import("linux_x86_64.zig"), | ||
| 13 | builtin.Arch.i386 => @import("linux_i386.zig"), | ||
| 14 | else => @compileError("unsupported arch"), | ||
| 15 | }; | ||
| 16 | |||
| 17 | const Method = enum { | ||
| 18 | Syscall, | ||
| 19 | Sysctl, | ||
| 20 | Urandom, | ||
| 21 | }; | ||
| 22 | |||
| 23 | const Callback = fn(&i32, []u8) usize; | ||
| 24 | |||
| 25 | const Context = struct { | ||
| 26 | syscall: Callback, | ||
| 27 | sysctl: Callback, | ||
| 28 | urandom: Callback, | ||
| 29 | }; | ||
| 30 | |||
| 31 | pub fn getRandomBytes(buf: []u8) usize { | ||
| 32 | const ctx = Context { | ||
| 33 | .syscall = syscall, | ||
| 34 | .sysctl = sysctl, | ||
| 35 | .urandom = urandom, | ||
| 36 | }; | ||
| 37 | return withContext(ctx, buf); | ||
| 38 | } | ||
| 39 | |||
| 40 | fn withContext(comptime ctx: Context, buf: []u8) usize { | ||
| 41 | if (buf.len == 0) return 0; | ||
| 42 | |||
| 43 | var fd: i32 = -1; | ||
| 44 | defer if (fd != -1) { | ||
| 45 | const _ = linux.close(fd); // Ignore errors, can't do anything sensible. | ||
| 46 | }; | ||
| 47 | |||
| 48 | // TODO(bnoordhuis) Remember the method across invocations so we don't make | ||
| 49 | // unnecessary system calls that are going to fail with ENOSYS anyway. | ||
| 50 | var method = Method.Syscall; | ||
| 51 | var i: usize = 0; | ||
| 52 | while (i < buf.len) { | ||
| 53 | const rc = switch (method) { | ||
| 54 | Method.Syscall => ctx.syscall(&fd, buf[i..]), | ||
| 55 | Method.Sysctl => ctx.sysctl(&fd, buf[i..]), | ||
| 56 | Method.Urandom => ctx.urandom(&fd, buf[i..]), | ||
| 57 | }; | ||
| 58 | if (rc == 0) return usize(-EIO); // Can't really happen. | ||
| 59 | if (!isErr(rc)) { | ||
| 60 | i += rc; | ||
| 61 | continue; | ||
| 62 | } | ||
| 63 | if (rc == usize(-EINTR)) continue; | ||
| 64 | if (rc == usize(-ENOSYS) and method == Method.Syscall) { | ||
| 65 | method = Method.Urandom; | ||
| 66 | continue; | ||
| 67 | } | ||
| 68 | if (method == Method.Urandom) { | ||
| 69 | method = Method.Sysctl; | ||
| 70 | continue; | ||
| 71 | } | ||
| 72 | return rc; // Unexpected error. | ||
| 73 | } | ||
| 74 | |||
| 75 | return i; | ||
| 76 | } | ||
| 77 | |||
| 78 | fn syscall(_: &i32, buf: []u8) usize { | ||
| 79 | return arch.syscall3(arch.SYS_getrandom, @ptrToInt(&buf[0]), buf.len, 0); | ||
| 80 | } | ||
| 81 | |||
| 82 | // Note: reads only 14 bytes at a time. | ||
| 83 | fn sysctl(_: &i32, buf: []u8) usize { | ||
| 84 | const __sysctl_args = extern struct { | ||
| 85 | name: &c_int, | ||
| 86 | nlen: c_int, | ||
| 87 | oldval: &u8, | ||
| 88 | oldlenp: &usize, | ||
| 89 | newval: ?&u8, | ||
| 90 | newlen: usize, | ||
| 91 | unused: [4]usize, | ||
| 92 | }; | ||
| 93 | |||
| 94 | var name = [3]c_int { 1, 40, 6 }; // { CTL_KERN, KERN_RANDOM, RANDOM_UUID } | ||
| 95 | var uuid: [16]u8 = undefined; | ||
| 96 | |||
| 97 | const expected: usize = @sizeOf(@typeOf(uuid)); | ||
| 98 | var len = expected; | ||
| 99 | |||
| 100 | var args = __sysctl_args { | ||
| 101 | .name = &name[0], | ||
| 102 | .nlen = c_int(name.len), | ||
| 103 | .oldval = &uuid[0], | ||
| 104 | .oldlenp = &len, | ||
| 105 | .newval = null, | ||
| 106 | .newlen = 0, | ||
| 107 | .unused = []usize {0} ** 4, | ||
| 108 | }; | ||
| 109 | |||
| 110 | const rc = arch.syscall1(arch.SYS__sysctl, @ptrToInt(&args)); | ||
| 111 | if (rc != 0) return rc; | ||
| 112 | if (len != expected) return 0; // Can't happen. | ||
| 113 | |||
| 114 | // uuid[] is now a type 4 UUID; bytes 6 and 8 (counting from zero) | ||
| 115 | // contain 4 and 5 bits of entropy, respectively. For ease of use, | ||
| 116 | // we skip those and only use 14 of the 16 bytes. | ||
| 117 | uuid[6] = uuid[14]; | ||
| 118 | uuid[8] = uuid[15]; | ||
| 119 | |||
| 120 | const n = math.min(buf.len, usize(14)); | ||
| 121 | @memcpy(&buf[0], &uuid[0], n); | ||
| 122 | return n; | ||
| 123 | } | ||
| 124 | |||
| 125 | fn urandom(fd: &i32, buf: []u8) usize { | ||
| 126 | if (*fd == -1) { | ||
| 127 | const flags = linux.O_CLOEXEC|linux.O_RDONLY; | ||
| 128 | const rc = linux.open(c"/dev/urandom", flags, 0); | ||
| 129 | if (isErr(rc)) return rc; | ||
| 130 | *fd = i32(rc); | ||
| 131 | } | ||
| 132 | // read() doesn't like reads > INT_MAX. | ||
| 133 | const n = math.min(buf.len, usize(0x7FFFFFFF)); | ||
| 134 | return linux.read(*fd, &buf[0], n); | ||
| 135 | } | ||
| 136 | |||
| 137 | fn isErr(rc: usize) bool { | ||
| 138 | return rc > usize(-4096); | ||
| 139 | } | ||
| 140 | |||
| 141 | test "os.linux.getRandomBytes" { | ||
| 142 | try check(42, getRandomBytesTrampoline); | ||
| 143 | } | ||
| 144 | |||
| 145 | test "os.linux.getRandomBytes syscall" { | ||
| 146 | try check(42, syscall); | ||
| 147 | } | ||
| 148 | |||
| 149 | test "os.linux.getRandomBytes sysctl" { | ||
| 150 | try check(14, sysctl); | ||
| 151 | } | ||
| 152 | |||
| 153 | test "os.linux.getRandomBytes /dev/urandom" { | ||
| 154 | try check(42, urandom); | ||
| 155 | } | ||
| 156 | |||
| 157 | test "os.linux.getRandomBytes state machine" { | ||
| 158 | const ctx = Context { | ||
| 159 | .syscall = fortytwo, | ||
| 160 | .urandom = fail, | ||
| 161 | .sysctl = fail, | ||
| 162 | }; | ||
| 163 | var buf = []u8 {0}; | ||
| 164 | assert(1 == withContext(ctx, buf[0..])); | ||
| 165 | assert(42 == buf[0]); | ||
| 166 | } | ||
| 167 | |||
| 168 | test "os.linux.getRandomBytes no-syscall state machine" { | ||
| 169 | const ctx = Context { | ||
| 170 | .syscall = enosys, | ||
| 171 | .urandom = fortytwo, | ||
| 172 | .sysctl = fail, | ||
| 173 | }; | ||
| 174 | var buf = []u8 {0}; | ||
| 175 | assert(1 == withContext(ctx, buf[0..])); | ||
| 176 | assert(42 == buf[0]); | ||
| 177 | } | ||
| 178 | |||
| 179 | test "os.linux.getRandomBytes no-urandom state machine" { | ||
| 180 | const ctx = Context { | ||
| 181 | .syscall = enosys, | ||
| 182 | .urandom = einval, | ||
| 183 | .sysctl = fortytwo, | ||
| 184 | }; | ||
| 185 | var buf = []u8 {0}; | ||
| 186 | assert(1 == withContext(ctx, buf[0..])); | ||
| 187 | assert(42 == buf[0]); | ||
| 188 | } | ||
| 189 | |||
| 190 | test "os.linux.getRandomBytes no-sysctl state machine" { | ||
| 191 | const ctx = Context { | ||
| 192 | .syscall = enosys, | ||
| 193 | .urandom = einval, | ||
| 194 | .sysctl = einval, | ||
| 195 | }; | ||
| 196 | var buf = []u8 {0}; | ||
| 197 | assert(usize(-EINVAL) == withContext(ctx, buf[0..])); | ||
| 198 | assert(0 == buf[0]); | ||
| 199 | } | ||
| 200 | |||
| 201 | fn einval(_: &i32, buf: []u8) usize { | ||
| 202 | return usize(-EINVAL); | ||
| 203 | } | ||
| 204 | |||
| 205 | fn enosys(_: &i32, buf: []u8) usize { | ||
| 206 | return usize(-ENOSYS); | ||
| 207 | } | ||
| 208 | |||
| 209 | fn fail(_: &i32, buf: []u8) usize { | ||
| 210 | os.abort(); | ||
| 211 | } | ||
| 212 | |||
| 213 | fn fortytwo(_: &i32, buf: []u8) usize { | ||
| 214 | assert(buf.len == 1); | ||
| 215 | buf[0] = 42; | ||
| 216 | return 1; | ||
| 217 | } | ||
| 218 | |||
| 219 | fn check(comptime N: usize, cb: Callback) %void { | ||
| 220 | if (builtin.os == builtin.Os.linux) { | ||
| 221 | var fd: i32 = -1; | ||
| 222 | defer if (fd != -1) { | ||
| 223 | const _ = linux.close(fd); // Ignore errors, can't do anything sensible. | ||
| 224 | }; | ||
| 225 | |||
| 226 | var bufs = [3][N]u8 { | ||
| 227 | []u8 {0} ** N, | ||
| 228 | []u8 {0} ** N, | ||
| 229 | []u8 {0} ** N, | ||
| 230 | }; | ||
| 231 | |||
| 232 | for (bufs) |*buf| { | ||
| 233 | const err = cb(&fd, (*buf)[0..]); | ||
| 234 | assert(err == N); | ||
| 235 | } | ||
| 236 | |||
| 237 | for (bufs) |*a| | ||
| 238 | for (bufs) |*b| | ||
| 239 | if (a != b) | ||
| 240 | assert(!mem.eql(u8, *a, *b)); | ||
| 241 | } | ||
| 242 | } | ||
| 243 | |||
| 244 | fn getRandomBytesTrampoline(_: &i32, buf: []u8) usize { | ||
| 245 | return getRandomBytes(buf); | ||
| 246 | } | ||
std/os/linux_test.zig deleted-38| ... | @@ -1,38 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const linux = std.os.linux; | ||
| 3 | const assert = std.debug.assert; | ||
| 4 | |||
| 5 | test "timer" { | ||
| 6 | const epoll_fd = linux.epoll_create(); | ||
| 7 | var err = linux.getErrno(epoll_fd); | ||
| 8 | assert(err == 0); | ||
| 9 | |||
| 10 | const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0); | ||
| 11 | assert(linux.getErrno(timer_fd) == 0); | ||
| 12 | |||
| 13 | const time_interval = linux.timespec { | ||
| 14 | .tv_sec = 0, | ||
| 15 | .tv_nsec = 2000000 | ||
| 16 | }; | ||
| 17 | |||
| 18 | const new_time = linux.itimerspec { | ||
| 19 | .it_interval = time_interval, | ||
| 20 | .it_value = time_interval | ||
| 21 | }; | ||
| 22 | |||
| 23 | err = linux.timerfd_settime(i32(timer_fd), 0, &new_time, null); | ||
| 24 | assert(err == 0); | ||
| 25 | |||
| 26 | var event = linux.epoll_event { | ||
| 27 | .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET, | ||
| 28 | .data = 0 | ||
| 29 | }; | ||
| 30 | |||
| 31 | err = linux.epoll_ctl(i32(epoll_fd), linux.EPOLL_CTL_ADD, i32(timer_fd), &event); | ||
| 32 | assert(err == 0); | ||
| 33 | |||
| 34 | const events_one: linux.epoll_event = undefined; | ||
| 35 | var events = []linux.epoll_event{events_one} ** 8; | ||
| 36 | |||
| 37 | err = linux.epoll_wait(i32(epoll_fd), &events[0], 8, -1); | ||
| 38 | } | ||
std/os/linux_x86_64.zig deleted-489| ... | @@ -1,489 +0,0 @@ | ||
| 1 | const linux = @import("linux.zig"); | ||
| 2 | const socklen_t = linux.socklen_t; | ||
| 3 | const iovec = linux.iovec; | ||
| 4 | |||
| 5 | pub const SYS_read = 0; | ||
| 6 | pub const SYS_write = 1; | ||
| 7 | pub const SYS_open = 2; | ||
| 8 | pub const SYS_close = 3; | ||
| 9 | pub const SYS_stat = 4; | ||
| 10 | pub const SYS_fstat = 5; | ||
| 11 | pub const SYS_lstat = 6; | ||
| 12 | pub const SYS_poll = 7; | ||
| 13 | pub const SYS_lseek = 8; | ||
| 14 | pub const SYS_mmap = 9; | ||
| 15 | pub const SYS_mprotect = 10; | ||
| 16 | pub const SYS_munmap = 11; | ||
| 17 | pub const SYS_brk = 12; | ||
| 18 | pub const SYS_rt_sigaction = 13; | ||
| 19 | pub const SYS_rt_sigprocmask = 14; | ||
| 20 | pub const SYS_rt_sigreturn = 15; | ||
| 21 | pub const SYS_ioctl = 16; | ||
| 22 | pub const SYS_pread = 17; | ||
| 23 | pub const SYS_pwrite = 18; | ||
| 24 | pub const SYS_readv = 19; | ||
| 25 | pub const SYS_writev = 20; | ||
| 26 | pub const SYS_access = 21; | ||
| 27 | pub const SYS_pipe = 22; | ||
| 28 | pub const SYS_select = 23; | ||
| 29 | pub const SYS_sched_yield = 24; | ||
| 30 | pub const SYS_mremap = 25; | ||
| 31 | pub const SYS_msync = 26; | ||
| 32 | pub const SYS_mincore = 27; | ||
| 33 | pub const SYS_madvise = 28; | ||
| 34 | pub const SYS_shmget = 29; | ||
| 35 | pub const SYS_shmat = 30; | ||
| 36 | pub const SYS_shmctl = 31; | ||
| 37 | pub const SYS_dup = 32; | ||
| 38 | pub const SYS_dup2 = 33; | ||
| 39 | pub const SYS_pause = 34; | ||
| 40 | pub const SYS_nanosleep = 35; | ||
| 41 | pub const SYS_getitimer = 36; | ||
| 42 | pub const SYS_alarm = 37; | ||
| 43 | pub const SYS_setitimer = 38; | ||
| 44 | pub const SYS_getpid = 39; | ||
| 45 | pub const SYS_sendfile = 40; | ||
| 46 | pub const SYS_socket = 41; | ||
| 47 | pub const SYS_connect = 42; | ||
| 48 | pub const SYS_accept = 43; | ||
| 49 | pub const SYS_sendto = 44; | ||
| 50 | pub const SYS_recvfrom = 45; | ||
| 51 | pub const SYS_sendmsg = 46; | ||
| 52 | pub const SYS_recvmsg = 47; | ||
| 53 | pub const SYS_shutdown = 48; | ||
| 54 | pub const SYS_bind = 49; | ||
| 55 | pub const SYS_listen = 50; | ||
| 56 | pub const SYS_getsockname = 51; | ||
| 57 | pub const SYS_getpeername = 52; | ||
| 58 | pub const SYS_socketpair = 53; | ||
| 59 | pub const SYS_setsockopt = 54; | ||
| 60 | pub const SYS_getsockopt = 55; | ||
| 61 | pub const SYS_clone = 56; | ||
| 62 | pub const SYS_fork = 57; | ||
| 63 | pub const SYS_vfork = 58; | ||
| 64 | pub const SYS_execve = 59; | ||
| 65 | pub const SYS_exit = 60; | ||
| 66 | pub const SYS_wait4 = 61; | ||
| 67 | pub const SYS_kill = 62; | ||
| 68 | pub const SYS_uname = 63; | ||
| 69 | pub const SYS_semget = 64; | ||
| 70 | pub const SYS_semop = 65; | ||
| 71 | pub const SYS_semctl = 66; | ||
| 72 | pub const SYS_shmdt = 67; | ||
| 73 | pub const SYS_msgget = 68; | ||
| 74 | pub const SYS_msgsnd = 69; | ||
| 75 | pub const SYS_msgrcv = 70; | ||
| 76 | pub const SYS_msgctl = 71; | ||
| 77 | pub const SYS_fcntl = 72; | ||
| 78 | pub const SYS_flock = 73; | ||
| 79 | pub const SYS_fsync = 74; | ||
| 80 | pub const SYS_fdatasync = 75; | ||
| 81 | pub const SYS_truncate = 76; | ||
| 82 | pub const SYS_ftruncate = 77; | ||
| 83 | pub const SYS_getdents = 78; | ||
| 84 | pub const SYS_getcwd = 79; | ||
| 85 | pub const SYS_chdir = 80; | ||
| 86 | pub const SYS_fchdir = 81; | ||
| 87 | pub const SYS_rename = 82; | ||
| 88 | pub const SYS_mkdir = 83; | ||
| 89 | pub const SYS_rmdir = 84; | ||
| 90 | pub const SYS_creat = 85; | ||
| 91 | pub const SYS_link = 86; | ||
| 92 | pub const SYS_unlink = 87; | ||
| 93 | pub const SYS_symlink = 88; | ||
| 94 | pub const SYS_readlink = 89; | ||
| 95 | pub const SYS_chmod = 90; | ||
| 96 | pub const SYS_fchmod = 91; | ||
| 97 | pub const SYS_chown = 92; | ||
| 98 | pub const SYS_fchown = 93; | ||
| 99 | pub const SYS_lchown = 94; | ||
| 100 | pub const SYS_umask = 95; | ||
| 101 | pub const SYS_gettimeofday = 96; | ||
| 102 | pub const SYS_getrlimit = 97; | ||
| 103 | pub const SYS_getrusage = 98; | ||
| 104 | pub const SYS_sysinfo = 99; | ||
| 105 | pub const SYS_times = 100; | ||
| 106 | pub const SYS_ptrace = 101; | ||
| 107 | pub const SYS_getuid = 102; | ||
| 108 | pub const SYS_syslog = 103; | ||
| 109 | pub const SYS_getgid = 104; | ||
| 110 | pub const SYS_setuid = 105; | ||
| 111 | pub const SYS_setgid = 106; | ||
| 112 | pub const SYS_geteuid = 107; | ||
| 113 | pub const SYS_getegid = 108; | ||
| 114 | pub const SYS_setpgid = 109; | ||
| 115 | pub const SYS_getppid = 110; | ||
| 116 | pub const SYS_getpgrp = 111; | ||
| 117 | pub const SYS_setsid = 112; | ||
| 118 | pub const SYS_setreuid = 113; | ||
| 119 | pub const SYS_setregid = 114; | ||
| 120 | pub const SYS_getgroups = 115; | ||
| 121 | pub const SYS_setgroups = 116; | ||
| 122 | pub const SYS_setresuid = 117; | ||
| 123 | pub const SYS_getresuid = 118; | ||
| 124 | pub const SYS_setresgid = 119; | ||
| 125 | pub const SYS_getresgid = 120; | ||
| 126 | pub const SYS_getpgid = 121; | ||
| 127 | pub const SYS_setfsuid = 122; | ||
| 128 | pub const SYS_setfsgid = 123; | ||
| 129 | pub const SYS_getsid = 124; | ||
| 130 | pub const SYS_capget = 125; | ||
| 131 | pub const SYS_capset = 126; | ||
| 132 | pub const SYS_rt_sigpending = 127; | ||
| 133 | pub const SYS_rt_sigtimedwait = 128; | ||
| 134 | pub const SYS_rt_sigqueueinfo = 129; | ||
| 135 | pub const SYS_rt_sigsuspend = 130; | ||
| 136 | pub const SYS_sigaltstack = 131; | ||
| 137 | pub const SYS_utime = 132; | ||
| 138 | pub const SYS_mknod = 133; | ||
| 139 | pub const SYS_uselib = 134; | ||
| 140 | pub const SYS_personality = 135; | ||
| 141 | pub const SYS_ustat = 136; | ||
| 142 | pub const SYS_statfs = 137; | ||
| 143 | pub const SYS_fstatfs = 138; | ||
| 144 | pub const SYS_sysfs = 139; | ||
| 145 | pub const SYS_getpriority = 140; | ||
| 146 | pub const SYS_setpriority = 141; | ||
| 147 | pub const SYS_sched_setparam = 142; | ||
| 148 | pub const SYS_sched_getparam = 143; | ||
| 149 | pub const SYS_sched_setscheduler = 144; | ||
| 150 | pub const SYS_sched_getscheduler = 145; | ||
| 151 | pub const SYS_sched_get_priority_max = 146; | ||
| 152 | pub const SYS_sched_get_priority_min = 147; | ||
| 153 | pub const SYS_sched_rr_get_interval = 148; | ||
| 154 | pub const SYS_mlock = 149; | ||
| 155 | pub const SYS_munlock = 150; | ||
| 156 | pub const SYS_mlockall = 151; | ||
| 157 | pub const SYS_munlockall = 152; | ||
| 158 | pub const SYS_vhangup = 153; | ||
| 159 | pub const SYS_modify_ldt = 154; | ||
| 160 | pub const SYS_pivot_root = 155; | ||
| 161 | pub const SYS__sysctl = 156; | ||
| 162 | pub const SYS_prctl = 157; | ||
| 163 | pub const SYS_arch_prctl = 158; | ||
| 164 | pub const SYS_adjtimex = 159; | ||
| 165 | pub const SYS_setrlimit = 160; | ||
| 166 | pub const SYS_chroot = 161; | ||
| 167 | pub const SYS_sync = 162; | ||
| 168 | pub const SYS_acct = 163; | ||
| 169 | pub const SYS_settimeofday = 164; | ||
| 170 | pub const SYS_mount = 165; | ||
| 171 | pub const SYS_umount2 = 166; | ||
| 172 | pub const SYS_swapon = 167; | ||
| 173 | pub const SYS_swapoff = 168; | ||
| 174 | pub const SYS_reboot = 169; | ||
| 175 | pub const SYS_sethostname = 170; | ||
| 176 | pub const SYS_setdomainname = 171; | ||
| 177 | pub const SYS_iopl = 172; | ||
| 178 | pub const SYS_ioperm = 173; | ||
| 179 | pub const SYS_create_module = 174; | ||
| 180 | pub const SYS_init_module = 175; | ||
| 181 | pub const SYS_delete_module = 176; | ||
| 182 | pub const SYS_get_kernel_syms = 177; | ||
| 183 | pub const SYS_query_module = 178; | ||
| 184 | pub const SYS_quotactl = 179; | ||
| 185 | pub const SYS_nfsservctl = 180; | ||
| 186 | pub const SYS_getpmsg = 181; | ||
| 187 | pub const SYS_putpmsg = 182; | ||
| 188 | pub const SYS_afs_syscall = 183; | ||
| 189 | pub const SYS_tuxcall = 184; | ||
| 190 | pub const SYS_security = 185; | ||
| 191 | pub const SYS_gettid = 186; | ||
| 192 | pub const SYS_readahead = 187; | ||
| 193 | pub const SYS_setxattr = 188; | ||
| 194 | pub const SYS_lsetxattr = 189; | ||
| 195 | pub const SYS_fsetxattr = 190; | ||
| 196 | pub const SYS_getxattr = 191; | ||
| 197 | pub const SYS_lgetxattr = 192; | ||
| 198 | pub const SYS_fgetxattr = 193; | ||
| 199 | pub const SYS_listxattr = 194; | ||
| 200 | pub const SYS_llistxattr = 195; | ||
| 201 | pub const SYS_flistxattr = 196; | ||
| 202 | pub const SYS_removexattr = 197; | ||
| 203 | pub const SYS_lremovexattr = 198; | ||
| 204 | pub const SYS_fremovexattr = 199; | ||
| 205 | pub const SYS_tkill = 200; | ||
| 206 | pub const SYS_time = 201; | ||
| 207 | pub const SYS_futex = 202; | ||
| 208 | pub const SYS_sched_setaffinity = 203; | ||
| 209 | pub const SYS_sched_getaffinity = 204; | ||
| 210 | pub const SYS_set_thread_area = 205; | ||
| 211 | pub const SYS_io_setup = 206; | ||
| 212 | pub const SYS_io_destroy = 207; | ||
| 213 | pub const SYS_io_getevents = 208; | ||
| 214 | pub const SYS_io_submit = 209; | ||
| 215 | pub const SYS_io_cancel = 210; | ||
| 216 | pub const SYS_get_thread_area = 211; | ||
| 217 | pub const SYS_lookup_dcookie = 212; | ||
| 218 | pub const SYS_epoll_create = 213; | ||
| 219 | pub const SYS_epoll_ctl_old = 214; | ||
| 220 | pub const SYS_epoll_wait_old = 215; | ||
| 221 | pub const SYS_remap_file_pages = 216; | ||
| 222 | pub const SYS_getdents64 = 217; | ||
| 223 | pub const SYS_set_tid_address = 218; | ||
| 224 | pub const SYS_restart_syscall = 219; | ||
| 225 | pub const SYS_semtimedop = 220; | ||
| 226 | pub const SYS_fadvise64 = 221; | ||
| 227 | pub const SYS_timer_create = 222; | ||
| 228 | pub const SYS_timer_settime = 223; | ||
| 229 | pub const SYS_timer_gettime = 224; | ||
| 230 | pub const SYS_timer_getoverrun = 225; | ||
| 231 | pub const SYS_timer_delete = 226; | ||
| 232 | pub const SYS_clock_settime = 227; | ||
| 233 | pub const SYS_clock_gettime = 228; | ||
| 234 | pub const SYS_clock_getres = 229; | ||
| 235 | pub const SYS_clock_nanosleep = 230; | ||
| 236 | pub const SYS_exit_group = 231; | ||
| 237 | pub const SYS_epoll_wait = 232; | ||
| 238 | pub const SYS_epoll_ctl = 233; | ||
| 239 | pub const SYS_tgkill = 234; | ||
| 240 | pub const SYS_utimes = 235; | ||
| 241 | pub const SYS_vserver = 236; | ||
| 242 | pub const SYS_mbind = 237; | ||
| 243 | pub const SYS_set_mempolicy = 238; | ||
| 244 | pub const SYS_get_mempolicy = 239; | ||
| 245 | pub const SYS_mq_open = 240; | ||
| 246 | pub const SYS_mq_unlink = 241; | ||
| 247 | pub const SYS_mq_timedsend = 242; | ||
| 248 | pub const SYS_mq_timedreceive = 243; | ||
| 249 | pub const SYS_mq_notify = 244; | ||
| 250 | pub const SYS_mq_getsetattr = 245; | ||
| 251 | pub const SYS_kexec_load = 246; | ||
| 252 | pub const SYS_waitid = 247; | ||
| 253 | pub const SYS_add_key = 248; | ||
| 254 | pub const SYS_request_key = 249; | ||
| 255 | pub const SYS_keyctl = 250; | ||
| 256 | pub const SYS_ioprio_set = 251; | ||
| 257 | pub const SYS_ioprio_get = 252; | ||
| 258 | pub const SYS_inotify_init = 253; | ||
| 259 | pub const SYS_inotify_add_watch = 254; | ||
| 260 | pub const SYS_inotify_rm_watch = 255; | ||
| 261 | pub const SYS_migrate_pages = 256; | ||
| 262 | pub const SYS_openat = 257; | ||
| 263 | pub const SYS_mkdirat = 258; | ||
| 264 | pub const SYS_mknodat = 259; | ||
| 265 | pub const SYS_fchownat = 260; | ||
| 266 | pub const SYS_futimesat = 261; | ||
| 267 | pub const SYS_newfstatat = 262; | ||
| 268 | pub const SYS_unlinkat = 263; | ||
| 269 | pub const SYS_renameat = 264; | ||
| 270 | pub const SYS_linkat = 265; | ||
| 271 | pub const SYS_symlinkat = 266; | ||
| 272 | pub const SYS_readlinkat = 267; | ||
| 273 | pub const SYS_fchmodat = 268; | ||
| 274 | pub const SYS_faccessat = 269; | ||
| 275 | pub const SYS_pselect6 = 270; | ||
| 276 | pub const SYS_ppoll = 271; | ||
| 277 | pub const SYS_unshare = 272; | ||
| 278 | pub const SYS_set_robust_list = 273; | ||
| 279 | pub const SYS_get_robust_list = 274; | ||
| 280 | pub const SYS_splice = 275; | ||
| 281 | pub const SYS_tee = 276; | ||
| 282 | pub const SYS_sync_file_range = 277; | ||
| 283 | pub const SYS_vmsplice = 278; | ||
| 284 | pub const SYS_move_pages = 279; | ||
| 285 | pub const SYS_utimensat = 280; | ||
| 286 | pub const SYS_epoll_pwait = 281; | ||
| 287 | pub const SYS_signalfd = 282; | ||
| 288 | pub const SYS_timerfd_create = 283; | ||
| 289 | pub const SYS_eventfd = 284; | ||
| 290 | pub const SYS_fallocate = 285; | ||
| 291 | pub const SYS_timerfd_settime = 286; | ||
| 292 | pub const SYS_timerfd_gettime = 287; | ||
| 293 | pub const SYS_accept4 = 288; | ||
| 294 | pub const SYS_signalfd4 = 289; | ||
| 295 | pub const SYS_eventfd2 = 290; | ||
| 296 | pub const SYS_epoll_create1 = 291; | ||
| 297 | pub const SYS_dup3 = 292; | ||
| 298 | pub const SYS_pipe2 = 293; | ||
| 299 | pub const SYS_inotify_init1 = 294; | ||
| 300 | pub const SYS_preadv = 295; | ||
| 301 | pub const SYS_pwritev = 296; | ||
| 302 | pub const SYS_rt_tgsigqueueinfo = 297; | ||
| 303 | pub const SYS_perf_event_open = 298; | ||
| 304 | pub const SYS_recvmmsg = 299; | ||
| 305 | pub const SYS_fanotify_init = 300; | ||
| 306 | pub const SYS_fanotify_mark = 301; | ||
| 307 | pub const SYS_prlimit64 = 302; | ||
| 308 | pub const SYS_name_to_handle_at = 303; | ||
| 309 | pub const SYS_open_by_handle_at = 304; | ||
| 310 | pub const SYS_clock_adjtime = 305; | ||
| 311 | pub const SYS_syncfs = 306; | ||
| 312 | pub const SYS_sendmmsg = 307; | ||
| 313 | pub const SYS_setns = 308; | ||
| 314 | pub const SYS_getcpu = 309; | ||
| 315 | pub const SYS_process_vm_readv = 310; | ||
| 316 | pub const SYS_process_vm_writev = 311; | ||
| 317 | pub const SYS_kcmp = 312; | ||
| 318 | pub const SYS_finit_module = 313; | ||
| 319 | pub const SYS_sched_setattr = 314; | ||
| 320 | pub const SYS_sched_getattr = 315; | ||
| 321 | pub const SYS_renameat2 = 316; | ||
| 322 | pub const SYS_seccomp = 317; | ||
| 323 | pub const SYS_getrandom = 318; | ||
| 324 | pub const SYS_memfd_create = 319; | ||
| 325 | pub const SYS_kexec_file_load = 320; | ||
| 326 | pub const SYS_bpf = 321; | ||
| 327 | pub const SYS_execveat = 322; | ||
| 328 | pub const SYS_userfaultfd = 323; | ||
| 329 | pub const SYS_membarrier = 324; | ||
| 330 | pub const SYS_mlock2 = 325; | ||
| 331 | |||
| 332 | pub const O_CREAT = 0o100; | ||
| 333 | pub const O_EXCL = 0o200; | ||
| 334 | pub const O_NOCTTY = 0o400; | ||
| 335 | pub const O_TRUNC = 0o1000; | ||
| 336 | pub const O_APPEND = 0o2000; | ||
| 337 | pub const O_NONBLOCK = 0o4000; | ||
| 338 | pub const O_DSYNC = 0o10000; | ||
| 339 | pub const O_SYNC = 0o4010000; | ||
| 340 | pub const O_RSYNC = 0o4010000; | ||
| 341 | pub const O_DIRECTORY = 0o200000; | ||
| 342 | pub const O_NOFOLLOW = 0o400000; | ||
| 343 | pub const O_CLOEXEC = 0o2000000; | ||
| 344 | |||
| 345 | pub const O_ASYNC = 0o20000; | ||
| 346 | pub const O_DIRECT = 0o40000; | ||
| 347 | pub const O_LARGEFILE = 0; | ||
| 348 | pub const O_NOATIME = 0o1000000; | ||
| 349 | pub const O_PATH = 0o10000000; | ||
| 350 | pub const O_TMPFILE = 0o20200000; | ||
| 351 | pub const O_NDELAY = O_NONBLOCK; | ||
| 352 | |||
| 353 | pub const F_DUPFD = 0; | ||
| 354 | pub const F_GETFD = 1; | ||
| 355 | pub const F_SETFD = 2; | ||
| 356 | pub const F_GETFL = 3; | ||
| 357 | pub const F_SETFL = 4; | ||
| 358 | |||
| 359 | pub const F_SETOWN = 8; | ||
| 360 | pub const F_GETOWN = 9; | ||
| 361 | pub const F_SETSIG = 10; | ||
| 362 | pub const F_GETSIG = 11; | ||
| 363 | |||
| 364 | pub const F_GETLK = 5; | ||
| 365 | pub const F_SETLK = 6; | ||
| 366 | pub const F_SETLKW = 7; | ||
| 367 | |||
| 368 | pub const F_SETOWN_EX = 15; | ||
| 369 | pub const F_GETOWN_EX = 16; | ||
| 370 | |||
| 371 | pub const F_GETOWNER_UIDS = 17; | ||
| 372 | |||
| 373 | pub fn syscall0(number: usize) usize { | ||
| 374 | return asm volatile ("syscall" | ||
| 375 | : [ret] "={rax}" (-> usize) | ||
| 376 | : [number] "{rax}" (number) | ||
| 377 | : "rcx", "r11"); | ||
| 378 | } | ||
| 379 | |||
| 380 | pub fn syscall1(number: usize, arg1: usize) usize { | ||
| 381 | return asm volatile ("syscall" | ||
| 382 | : [ret] "={rax}" (-> usize) | ||
| 383 | : [number] "{rax}" (number), | ||
| 384 | [arg1] "{rdi}" (arg1) | ||
| 385 | : "rcx", "r11"); | ||
| 386 | } | ||
| 387 | |||
| 388 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | ||
| 389 | return asm volatile ("syscall" | ||
| 390 | : [ret] "={rax}" (-> usize) | ||
| 391 | : [number] "{rax}" (number), | ||
| 392 | [arg1] "{rdi}" (arg1), | ||
| 393 | [arg2] "{rsi}" (arg2) | ||
| 394 | : "rcx", "r11"); | ||
| 395 | } | ||
| 396 | |||
| 397 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | ||
| 398 | return asm volatile ("syscall" | ||
| 399 | : [ret] "={rax}" (-> usize) | ||
| 400 | : [number] "{rax}" (number), | ||
| 401 | [arg1] "{rdi}" (arg1), | ||
| 402 | [arg2] "{rsi}" (arg2), | ||
| 403 | [arg3] "{rdx}" (arg3) | ||
| 404 | : "rcx", "r11"); | ||
| 405 | } | ||
| 406 | |||
| 407 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | ||
| 408 | return asm volatile ("syscall" | ||
| 409 | : [ret] "={rax}" (-> usize) | ||
| 410 | : [number] "{rax}" (number), | ||
| 411 | [arg1] "{rdi}" (arg1), | ||
| 412 | [arg2] "{rsi}" (arg2), | ||
| 413 | [arg3] "{rdx}" (arg3), | ||
| 414 | [arg4] "{r10}" (arg4) | ||
| 415 | : "rcx", "r11"); | ||
| 416 | } | ||
| 417 | |||
| 418 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | ||
| 419 | return asm volatile ("syscall" | ||
| 420 | : [ret] "={rax}" (-> usize) | ||
| 421 | : [number] "{rax}" (number), | ||
| 422 | [arg1] "{rdi}" (arg1), | ||
| 423 | [arg2] "{rsi}" (arg2), | ||
| 424 | [arg3] "{rdx}" (arg3), | ||
| 425 | [arg4] "{r10}" (arg4), | ||
| 426 | [arg5] "{r8}" (arg5) | ||
| 427 | : "rcx", "r11"); | ||
| 428 | } | ||
| 429 | |||
| 430 | pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, | ||
| 431 | arg5: usize, arg6: usize) usize | ||
| 432 | { | ||
| 433 | return asm volatile ("syscall" | ||
| 434 | : [ret] "={rax}" (-> usize) | ||
| 435 | : [number] "{rax}" (number), | ||
| 436 | [arg1] "{rdi}" (arg1), | ||
| 437 | [arg2] "{rsi}" (arg2), | ||
| 438 | [arg3] "{rdx}" (arg3), | ||
| 439 | [arg4] "{r10}" (arg4), | ||
| 440 | [arg5] "{r8}" (arg5), | ||
| 441 | [arg6] "{r9}" (arg6) | ||
| 442 | : "rcx", "r11"); | ||
| 443 | } | ||
| 444 | |||
| 445 | pub nakedcc fn restore_rt() void { | ||
| 446 | return asm volatile ("syscall" | ||
| 447 | : | ||
| 448 | : [number] "{rax}" (usize(SYS_rt_sigreturn)) | ||
| 449 | : "rcx", "r11"); | ||
| 450 | } | ||
| 451 | |||
| 452 | |||
| 453 | pub const msghdr = extern struct { | ||
| 454 | msg_name: &u8, | ||
| 455 | msg_namelen: socklen_t, | ||
| 456 | msg_iov: &iovec, | ||
| 457 | msg_iovlen: i32, | ||
| 458 | __pad1: i32, | ||
| 459 | msg_control: &u8, | ||
| 460 | msg_controllen: socklen_t, | ||
| 461 | __pad2: socklen_t, | ||
| 462 | msg_flags: i32, | ||
| 463 | }; | ||
| 464 | |||
| 465 | /// Renamed to Stat to not conflict with the stat function. | ||
| 466 | pub const Stat = extern struct { | ||
| 467 | dev: u64, | ||
| 468 | ino: u64, | ||
| 469 | nlink: usize, | ||
| 470 | |||
| 471 | mode: u32, | ||
| 472 | uid: u32, | ||
| 473 | gid: u32, | ||
| 474 | __pad0: u32, | ||
| 475 | rdev: u64, | ||
| 476 | size: i64, | ||
| 477 | blksize: isize, | ||
| 478 | blocks: i64, | ||
| 479 | |||
| 480 | atim: timespec, | ||
| 481 | mtim: timespec, | ||
| 482 | ctim: timespec, | ||
| 483 | __unused: [3]isize, | ||
| 484 | }; | ||
| 485 | |||
| 486 | pub const timespec = extern struct { | ||
| 487 | tv_sec: isize, | ||
| 488 | tv_nsec: isize, | ||
| 489 | }; | ||
test/compile_errors.zig+6| ... | @@ -1,6 +1,12 @@ | ... | @@ -1,6 +1,12 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: &tests.CompileErrorContext) void { | 3 | pub fn addCases(cases: &tests.CompileErrorContext) void { |
| 4 | cases.add("cast negative integer literal to usize", | ||
| 5 | \\export fn entry() void { | ||
| 6 | \\ const x = usize(-10); | ||
| 7 | \\} | ||
| 8 | , ".tmp_source.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'"); | ||
| 9 | |||
| 4 | cases.add("use invalid number literal as array index", | 10 | cases.add("use invalid number literal as array index", |
| 5 | \\var v = 25; | 11 | \\var v = 25; |
| 6 | \\export fn entry() void { | 12 | \\export fn entry() void { |