authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-05 09:26:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-05 09:26:39-05:00
log44d8d654a0ba463a1d4cf34d435c8422bfcd1c81
tree8ef92e3af15a5daf359163d46404171695ae89a1
parentec59f765266749a29d5ba1804f4ab5afdcabee1d

fix test failure, organize code, add new compile error


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