authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2017-10-20 06:16:56+00:00
committergravatar for greg@unrelenting.technologyGreg V <greg@unrelenting.technology> 2018-10-20 15:15:01+03:00
loge2b9c153bdfa2c5e4005d5957062e0eaf3b339a2
tree24bf2b5a7283d37868026997712410eb0357438f
parent9a541c12140e8768fabbbd8834cd0e1570df344b

Add initial freebsd stdlib functionality

Trivial program now compiles with now warnings.

8 files changed, 2113 insertions(+), 6 deletions(-)

src/target.cpp+1-1
...@@ -738,6 +738,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -738,6 +738,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
738 case OsLinux:738 case OsLinux:
739 case OsMacOSX:739 case OsMacOSX:
740 case OsZen:740 case OsZen:
741 case OsFreeBSD:
741 case OsOpenBSD:742 case OsOpenBSD:
742 switch (id) {743 switch (id) {
743 case CIntTypeShort:744 case CIntTypeShort:
...@@ -774,7 +775,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {...@@ -774,7 +775,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
774 case OsAnanas:775 case OsAnanas:
775 case OsCloudABI:776 case OsCloudABI:
776 case OsDragonFly:777 case OsDragonFly:
777 case OsFreeBSD:
778 case OsIOS:778 case OsIOS:
779 case OsKFreeBSD:779 case OsKFreeBSD:
780 case OsLv2:780 case OsLv2:
std/os/freebsd.zig created+733
...@@ -0,0 +1,733 @@
1const assert = @import("../debug.zig").assert;
2const builtin = @import("builtin");
3const arch = switch (builtin.arch) {
4 builtin.Arch.x86_64 => @import("freebsd_x86_64.zig"),
5 builtin.Arch.i386 => @import("freebsd_i386.zig"),
6 else => @compileError("unsupported arch"),
7};
8pub use @import("freebsd_errno.zig");
9
10pub const PATH_MAX = 1024;
11
12pub const STDIN_FILENO = 0;
13pub const STDOUT_FILENO = 1;
14pub const STDERR_FILENO = 2;
15
16pub const PROT_NONE = 0;
17pub const PROT_READ = 1;
18pub const PROT_WRITE = 2;
19pub const PROT_EXEC = 4;
20
21pub const MAP_FAILED = @maxValue(usize);
22pub const MAP_SHARED = 0x0001;
23pub const MAP_PRIVATE = 0x0002;
24pub const MAP_FIXED = 0x0010;
25pub const MAP_STACK = 0x0400;
26pub const MAP_NOSYNC = 0x0800;
27pub const MAP_ANON = 0x1000;
28pub const MAP_ANONYMOUS = MAP_ANON;
29pub const MAP_FILE = 0;
30
31pub const MAP_GUARD = 0x00002000;
32pub const MAP_EXCL = 0x00004000;
33pub const MAP_NOCORE = 0x00020000;
34pub const MAP_PREFAULT_READ = 0x00040000;
35pub const MAP_32BIT = 0x00080000;
36
37pub const WNOHANG = 1;
38pub const WUNTRACED = 2;
39pub const WSTOPPED = WUNTRACED;
40pub const WCONTINUED = 4;
41pub const WNOWAIT = 8;
42pub const WEXITED = 16;
43pub const WTRAPPED = 32;
44
45pub const SA_ONSTACK = 0x0001;
46pub const SA_RESTART = 0x0002;
47pub const SA_RESETHAND = 0x0004;
48pub const SA_NOCLDSTOP = 0x0008;
49pub const SA_NODEFER = 0x0010;
50pub const SA_NOCLDWAIT = 0x0020;
51pub const SA_SIGINFO = 0x0040;
52
53pub const SIGHUP = 1;
54pub const SIGINT = 2;
55pub const SIGQUIT = 3;
56pub const SIGILL = 4;
57pub const SIGTRAP = 5;
58pub const SIGABRT = 6;
59pub const SIGIOT = SIGABRT;
60pub const SIGEMT = 7;
61pub const SIGFPE = 8;
62pub const SIGKILL = 9;
63pub const SIGBUS = 10;
64pub const SIGSEGV = 11;
65pub const SIGSYS = 12;
66pub const SIGPIPE = 13;
67pub const SIGALRM = 14;
68pub const SIGTERM = 15;
69pub const SIGURG = 16;
70pub const SIGSTOP = 17;
71pub const SIGTSTP = 18;
72pub const SIGCONT = 19;
73pub const SIGCHLD = 20;
74pub const SIGTTIN = 21;
75pub const SIGTTOU = 22;
76pub const SIGIO = 23;
77pub const SIGXCPU = 24;
78pub const SIGXFSZ = 25;
79pub const SIGVTALRM = 26;
80pub const SIGPROF = 27;
81pub const SIGWINCH = 28;
82pub const SIGINFO = 29;
83pub const SIGUSR1 = 30;
84pub const SIGUSR2 = 31;
85pub const SIGTHR = 32;
86pub const SIGLWP = SIGTHR;
87pub const SIGLIBRT = 33;
88
89pub const SIGRTMIN = 65;
90pub const SIGRTMAX = 126;
91
92pub const O_RDONLY = 0o0;
93pub const O_WRONLY = 0o1;
94pub const O_RDWR = 0o2;
95pub const O_ACCMODE = 0o3;
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 = 1;
123pub const SIG_UNBLOCK = 2;
124pub const SIG_SETMASK = 3;
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;
131
132pub const SOCK_CLOEXEC = 0x10000000;
133pub const SOCK_NONBLOCK = 0x20000000;
134
135// TODO: From here
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
332fn unsigned(s: i32) -> u32 { @bitCast(u32, s) }
333fn signed(s: u32) -> i32 { @bitCast(i32, s) }
334pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) }
335pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) }
336pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) }
337pub fn WIFEXITED(s: i32) -> bool { WTERMSIG(s) == 0 }
338pub fn WIFSTOPPED(s: i32) -> bool { (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00 }
339pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff }
340
341
342pub const winsize = extern struct {
343 ws_row: u16,
344 ws_col: u16,
345 ws_xpixel: u16,
346 ws_ypixel: u16,
347};
348
349/// Get the errno from a syscall return value, or 0 for no error.
350pub fn getErrno(r: usize) -> usize {
351 const signed_r = @bitCast(isize, r);
352 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
353}
354
355pub fn dup2(old: i32, new: i32) -> usize {
356 arch.syscall2(arch.SYS_dup2, usize(old), usize(new))
357}
358
359pub fn chdir(path: &const u8) -> usize {
360 arch.syscall1(arch.SYS_chdir, @ptrToInt(path))
361}
362
363pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize {
364 arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp))
365}
366
367pub fn fork() -> usize {
368 arch.syscall0(arch.SYS_fork)
369}
370
371pub fn getcwd(buf: &u8, size: usize) -> usize {
372 arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size)
373}
374
375pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize {
376 arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count)
377}
378
379pub fn isatty(fd: i32) -> bool {
380 var wsz: winsize = undefined;
381 return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
382}
383
384pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {
385 arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len)
386}
387
388pub fn mkdir(path: &const u8, mode: u32) -> usize {
389 arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode)
390}
391
392pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize)
393 -> usize
394{
395 arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
396 @bitCast(usize, offset))
397}
398
399pub fn munmap(address: &u8, length: usize) -> usize {
400 arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length)
401}
402
403pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
404 arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count)
405}
406
407pub fn rmdir(path: &const u8) -> usize {
408 arch.syscall1(arch.SYS_rmdir, @ptrToInt(path))
409}
410
411pub fn symlink(existing: &const u8, new: &const u8) -> usize {
412 arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new))
413}
414
415pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {
416 arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset)
417}
418
419pub fn pipe(fd: &[2]i32) -> usize {
420 pipe2(fd, 0)
421}
422
423pub fn pipe2(fd: &[2]i32, flags: usize) -> usize {
424 arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags)
425}
426
427pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
428 arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count)
429}
430
431pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {
432 arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset)
433}
434
435pub fn rename(old: &const u8, new: &const u8) -> usize {
436 arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new))
437}
438
439pub fn open(path: &const u8, flags: u32, perm: usize) -> usize {
440 arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm)
441}
442
443pub fn create(path: &const u8, perm: usize) -> usize {
444 arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm)
445}
446
447pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {
448 arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode)
449}
450
451pub fn close(fd: i32) -> usize {
452 arch.syscall1(arch.SYS_close, usize(fd))
453}
454
455pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize {
456 arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos)
457}
458
459pub fn exit(status: i32) -> noreturn {
460 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
461 unreachable
462}
463
464pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
465 arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags))
466}
467
468pub fn kill(pid: i32, sig: i32) -> usize {
469 arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig))
470}
471
472pub fn unlink(path: &const u8) -> usize {
473 arch.syscall1(arch.SYS_unlink, @ptrToInt(path))
474}
475
476pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize {
477 arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0)
478}
479
480pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {
481 arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem))
482}
483
484pub fn setuid(uid: u32) -> usize {
485 arch.syscall1(arch.SYS_setuid, uid)
486}
487
488pub fn setgid(gid: u32) -> usize {
489 arch.syscall1(arch.SYS_setgid, gid)
490}
491
492pub fn setreuid(ruid: u32, euid: u32) -> usize {
493 arch.syscall2(arch.SYS_setreuid, ruid, euid)
494}
495
496pub fn setregid(rgid: u32, egid: u32) -> usize {
497 arch.syscall2(arch.SYS_setregid, rgid, egid)
498}
499
500pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {
501 arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8)
502}
503
504pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
505 assert(sig >= 1);
506 assert(sig != SIGKILL);
507 assert(sig != SIGSTOP);
508 var ksa = k_sigaction {
509 .handler = act.handler,
510 .flags = act.flags | SA_RESTORER,
511 .mask = undefined,
512 .restorer = @ptrCast(extern fn(), arch.restore_rt),
513 };
514 var ksa_old: k_sigaction = undefined;
515 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
516 const result = arch.syscall4(arch.SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask)));
517 const err = getErrno(result);
518 if (err != 0) {
519 return result;
520 }
521 if (oact) |old| {
522 old.handler = ksa_old.handler;
523 old.flags = @truncate(u32, ksa_old.flags);
524 @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));
525 }
526 return 0;
527}
528
529const NSIG = 65;
530const sigset_t = [128 / @sizeOf(usize)]usize;
531const all_mask = []usize{@maxValue(usize)};
532const app_mask = []usize{0xfffffffc7fffffff};
533
534const k_sigaction = extern struct {
535 handler: extern fn(i32),
536 flags: usize,
537 restorer: extern fn(),
538 mask: [2]u32,
539};
540
541/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
542pub const Sigaction = struct {
543 handler: extern fn(i32),
544 mask: sigset_t,
545 flags: u32,
546};
547
548pub const SIG_ERR = @intToPtr(extern fn(i32), @maxValue(usize));
549pub const SIG_DFL = @intToPtr(extern fn(i32), 0);
550pub const SIG_IGN = @intToPtr(extern fn(i32), 1);
551pub const empty_sigset = []usize{0} ** sigset_t.len;
552
553pub fn raise(sig: i32) -> usize {
554 // TODO implement, see linux equivalent for what we want to try and do
555 return 0;
556}
557
558fn blockAllSignals(set: &sigset_t) {
559 // TODO implement
560}
561
562fn blockAppSignals(set: &sigset_t) {
563 // TODO implement
564}
565
566fn restoreSignals(set: &sigset_t) {
567 // TODO implement
568}
569
570pub fn sigaddset(set: &sigset_t, sig: u6) {
571 const s = sig - 1;
572 (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
573}
574
575pub fn sigismember(set: &const sigset_t, sig: u6) -> bool {
576 const s = sig - 1;
577 return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
578}
579
580
581pub const sa_family_t = u16;
582pub const socklen_t = u32;
583pub const in_addr = u32;
584pub const in6_addr = [16]u8;
585
586pub const sockaddr = extern struct {
587 family: sa_family_t,
588 port: u16,
589 data: [12]u8,
590};
591
592pub const sockaddr_in = extern struct {
593 family: sa_family_t,
594 port: u16,
595 addr: in_addr,
596 zero: [8]u8,
597};
598
599pub const sockaddr_in6 = extern struct {
600 family: sa_family_t,
601 port: u16,
602 flowinfo: u32,
603 addr: in6_addr,
604 scope_id: u32,
605};
606
607pub const iovec = extern struct {
608 iov_base: &u8,
609 iov_len: usize,
610};
611
612//
613//const IF_NAMESIZE = 16;
614//
615//export struct ifreq {
616// ifrn_name: [IF_NAMESIZE]u8,
617// union {
618// ifru_addr: sockaddr,
619// ifru_dstaddr: sockaddr,
620// ifru_broadaddr: sockaddr,
621// ifru_netmask: sockaddr,
622// ifru_hwaddr: sockaddr,
623// ifru_flags: i16,
624// ifru_ivalue: i32,
625// ifru_mtu: i32,
626// ifru_map: ifmap,
627// ifru_slave: [IF_NAMESIZE]u8,
628// ifru_newname: [IF_NAMESIZE]u8,
629// ifru_data: &u8,
630// } ifr_ifru;
631//}
632//
633
634pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
635 arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len))
636}
637
638pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
639 arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len))
640}
641
642pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize {
643 arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol))
644}
645
646pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize {
647 arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen))
648}
649
650pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize {
651 arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen))
652}
653
654pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {
655 arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags)
656}
657
658pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
659 arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len))
660}
661
662pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {
663 arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags)
664}
665
666pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
667 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize
668{
669 arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen))
670}
671
672pub fn shutdown(fd: i32, how: i32) -> usize {
673 arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how))
674}
675
676pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
677 arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len))
678}
679
680pub fn listen(fd: i32, backlog: i32) -> usize {
681 arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog))
682}
683
684pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize {
685 arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen))
686}
687
688pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize {
689 arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0]))
690}
691
692pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
693 accept4(fd, addr, len, 0)
694}
695
696pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize {
697 arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags)
698}
699
700// error NameTooLong;
701// error SystemResources;
702// error Io;
703//
704// pub fn if_nametoindex(name: []u8) -> %u32 {
705// var ifr: ifreq = undefined;
706//
707// if (name.len >= ifr.ifr_name.len) {
708// return error.NameTooLong;
709// }
710//
711// const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
712// const socket_err = getErrno(socket_ret);
713// if (socket_err > 0) {
714// return error.SystemResources;
715// }
716// const socket_fd = i32(socket_ret);
717// @memcpy(&ifr.ifr_name[0], &name[0], name.len);
718// ifr.ifr_name[name.len] = 0;
719// const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr);
720// close(socket_fd);
721// const ioctl_err = getErrno(ioctl_ret);
722// if (ioctl_err > 0) {
723// return error.Io;
724// }
725// return ifr.ifr_ifindex;
726// }
727
728pub const Stat = arch.Stat;
729pub const timespec = arch.timespec;
730
731pub fn fstat(fd: i32, stat_buf: &Stat) -> usize {
732 arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf))
733}
std/os/freebsd_errno.zig created+121
...@@ -0,0 +1,121 @@
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; // Input/output error
6pub const ENXIO = 6; // Device not configured
7pub const E2BIG = 7; // Argument list too long
8pub const ENOEXEC = 8; // Exec format error
9pub const EBADF = 9; // Bad file descriptor
10pub const ECHILD = 10; // No child processes
11pub const EDEADLK = 11; // Resource deadlock avoided
12 // 11 was EAGAIN
13pub const ENOMEM = 12; // Cannot allocate memory
14pub const EACCES = 13; // Permission denied
15pub const EFAULT = 14; // Bad address
16pub const ENOTBLK = 15; // Block device required
17pub const EBUSY = 16; // Device busy
18pub const EEXIST = 17; // File exists
19pub const EXDEV = 18; // Cross-device link
20pub const ENODEV = 19; // Operation not supported by device
21pub const ENOTDIR = 20; // Not a directory
22pub const EISDIR = 21; // Is a directory
23pub const EINVAL = 22; // Invalid argument
24pub const ENFILE = 23; // Too many open files in system
25pub const EMFILE = 24; // Too many open files
26pub const ENOTTY = 25; // Inappropriate ioctl for device
27pub const ETXTBSY = 26; // Text file busy
28pub const EFBIG = 27; // File too large
29pub const ENOSPC = 28; // No space left on device
30pub const ESPIPE = 29; // Illegal seek
31pub const EROFS = 30; // Read-only filesystem
32pub const EMLINK = 31; // Too many links
33pub const EPIPE = 32; // Broken pipe
34
35// math software
36pub const EDOM = 33; // Numerical argument out of domain
37pub const ERANGE = 34; // Result too large
38
39// non-blocking and interrupt i/o
40pub const EAGAIN = 35; // Resource temporarily unavailable
41pub const EWOULDBLOCK = EAGAIN; // Operation would block
42pub const EINPROGRESS = 36; // Operation now in progress
43pub const EALREADY = 37; // Operation already in progress
44
45// ipc/network software -- argument errors
46pub const ENOTSOCK = 38; // Socket operation on non-socket
47pub const EDESTADDRREQ = 39; // Destination address required
48pub const EMSGSIZE = 40; // Message too long
49pub const EPROTOTYPE = 41; // Protocol wrong type for socket
50pub const ENOPROTOOPT = 42; // Protocol not available
51pub const EPROTONOSUPPORT = 43; // Protocol not supported
52pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
53pub const EOPNOTSUPP = 45; // Operation not supported
54pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
55pub const EPFNOSUPPORT = 46; // Protocol family not supported
56pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
57pub const EADDRINUSE = 48; // Address already in use
58pub const EADDRNOTAVAIL = 49; // Can't assign requested address
59
60// ipc/network software -- operational errors
61pub const ENETDOWN = 50; // Network is down
62pub const ENETUNREACH = 51; // Network is unreachable
63pub const ENETRESET = 52; // Network dropped connection on reset
64pub const ECONNABORTED = 53; // Software caused connection abort
65pub const ECONNRESET = 54; // Connection reset by peer
66pub const ENOBUFS = 55; // No buffer space available
67pub const EISCONN = 56; // Socket is already connected
68pub const ENOTCONN = 57; // Socket is not connected
69pub const ESHUTDOWN = 58; // Can't send after socket shutdown
70pub const ETOOMANYREFS = 59; // Too many references: can't splice
71pub const ETIMEDOUT = 60; // Operation timed out
72pub const ECONNREFUSED = 61; // Connection refused
73
74pub const ELOOP = 62; // Too many levels of symbolic links
75pub const ENAMETOOLONG = 63; // File name too long
76
77// should be rearranged
78pub const EHOSTDOWN = 64; // Host is down
79pub const EHOSTUNREACH = 65; // No route to host
80pub const ENOTEMPTY = 66; // Directory not empty
81
82// quotas & mush
83pub const EPROCLIM = 67; // Too many processes
84pub const EUSERS = 68; // Too many users
85pub const EDQUOT = 69; // Disc quota exceeded
86
87// Network File System
88pub const ESTALE = 70; // Stale NFS file handle
89pub const EREMOTE = 71; // Too many levels of remote in path
90pub const EBADRPC = 72; // RPC struct is bad
91pub const ERPCMISMATCH = 73; // RPC version wrong
92pub const EPROGUNAVAIL = 74; // RPC prog. not avail
93pub const EPROGMISMATCH = 75; // Program version wrong
94pub const EPROCUNAVAIL = 76; // Bad procedure for program
95
96pub const ENOLCK = 77; // No locks available
97pub const ENOSYS = 78; // Function not implemented
98
99pub const EFTYPE = 79; // Inappropriate file type or format
100pub const EAUTH = 80; // Authentication error
101pub const ENEEDAUTH = 81; // Need authenticator
102pub const EIDRM = 82; // Identifier removed
103pub const ENOMSG = 83; // No message of desired type
104pub const EOVERFLOW = 84; // Value too large to be stored in data type
105pub const ECANCELED = 85; // Operation canceled
106pub const EILSEQ = 86; // Illegal byte sequence
107pub const ENOATTR = 87; // Attribute not found
108
109pub const EDOOFUS = 88; // Programming error
110
111pub const EBADMSG = 89; // Bad message
112pub const EMULTIHOP = 90; // Multihop attempted
113pub const ENOLINK = 91; // Link has been severed
114pub const EPROTO = 92; // Protocol error
115
116pub const ENOTCAPABLE = 93; // Capabilities insufficient
117pub const ECAPMODE = 94; // Not permitted in capability mode
118pub const ENOTRECOVERABLE = 95; // State not recoverable
119pub const EOWNERDEAD = 96; // Previous owner died
120
121pub const ELAST = 96; // Must be equal largest errno
std/os/freebsd_i386.zig created+614
...@@ -0,0 +1,614 @@
1const freebsd = @import("freebsd.zig");
2const socklen_t = freebsd.socklen_t;
3const iovec = freebsd.iovec;
4
5pub const SYS_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_wait4 = 7;
13// 8 is old creat
14pub const SYS_link = 9;
15pub const SYS_unlink = 10;
16// 11 is obsolete execv
17pub const SYS_chdir = 12;
18pub const SYS_fchdir = 13;
19pub const SYS_freebsd11_mknod = 14;
20pub const SYS_chmod = 15;
21pub const SYS_chown = 16;
22pub const SYS_break = 17;
23// 18 is freebsd4 getfsstat
24// 19 is old lseek
25pub const SYS_getpid = 20;
26pub const SYS_mount = 21;
27pub const SYS_unmount = 22;
28pub const SYS_setuid = 23;
29pub const SYS_getuid = 24;
30pub const SYS_geteuid = 25;
31pub const SYS_ptrace = 26;
32pub const SYS_recvmsg = 27;
33pub const SYS_sendmsg = 28;
34pub const SYS_recvfrom = 29;
35pub const SYS_accept = 30;
36pub const SYS_getpeername = 31;
37pub const SYS_getsockname = 32;
38pub const SYS_access = 33;
39pub const SYS_chflags = 34;
40pub const SYS_fchflags = 35;
41pub const SYS_sync = 36;
42pub const SYS_kill = 37;
43// 38 is old stat
44pub const SYS_getppid = 39;
45// 40 is old lstat
46pub const SYS_dup = 41;
47pub const SYS_freebsd10_pipe = 42;
48pub const SYS_getegid = 43;
49pub const SYS_profil = 44;
50pub const SYS_ktrace = 45;
51// 46 is old sigaction
52pub const SYS_getgid = 47;
53// 48 is old sigprocmask
54pub const SYS_getlogin = 49;
55pub const SYS_setlogin = 50;
56pub const SYS_acct = 51;
57// 52 is old sigpending
58pub const SYS_sigaltstack = 53;
59pub const SYS_ioctl = 54;
60pub const SYS_reboot = 55;
61pub const SYS_revoke = 56;
62pub const SYS_symlink = 57;
63pub const SYS_readlink = 58;
64pub const SYS_execve = 59;
65pub const SYS_umask = 60;
66pub const SYS_chroot = 61;
67// 62 is old fstat
68// 63 is old getkerninfo
69// 64 is old getpagesize
70pub const SYS_msync = 65;
71pub const SYS_vfork = 66;
72// 67 is obsolete vread
73// 68 is obsolete vwrite
74pub const SYS_sbrk = 69;
75pub const SYS_sstk = 70;
76// 71 is old mmap
77pub const SYS_vadvise = 72;
78pub const SYS_munmap = 73;
79pub const SYS_mprotect = 74;
80pub const SYS_madvise = 75;
81// 76 is obsolete vhangup
82// 77 is obsolete vlimit
83pub const SYS_mincore = 78;
84pub const SYS_getgroups = 79;
85pub const SYS_setgroups = 80;
86pub const SYS_getpgrp = 81;
87pub const SYS_setpgid = 82;
88pub const SYS_setitimer = 83;
89// 84 is old wait
90pub const SYS_swapon = 85;
91pub const SYS_getitimer = 86;
92// 87 is old gethostname
93// 88 is old sethostname
94pub const SYS_getdtablesize = 89;
95pub const SYS_dup2 = 90;
96pub const SYS_fcntl = 92;
97pub const SYS_select = 93;
98pub const SYS_fsync = 95;
99pub const SYS_setpriority = 96;
100pub const SYS_socket = 97;
101pub const SYS_connect = 98;
102// 99 is old accept
103pub const SYS_getpriority = 100;
104// 101 is old send
105// 102 is old recv
106// 103 is old sigreturn
107pub const SYS_bind = 104;
108pub const SYS_setsockopt = 105;
109pub const SYS_listen = 106;
110// 107 is obsolete vtimes
111// 108 is old sigvec
112// 109 is old sigblock
113// 110 is old sigsetmask
114// 111 is old sigsuspend
115// 112 is old sigstack
116// 113 is old recvmsg
117// 114 is old sendmsg
118// 115 is obsolete vtrace
119pub const SYS_gettimeofday = 116;
120pub const SYS_getrusage = 117;
121pub const SYS_getsockopt = 118;
122pub const SYS_readv = 120;
123pub const SYS_writev = 121;
124pub const SYS_settimeofday = 122;
125pub const SYS_fchown = 123;
126pub const SYS_fchmod = 124;
127// 125 is old recvfrom
128pub const SYS_setreuid = 126;
129pub const SYS_setregid = 127;
130pub const SYS_rename = 128;
131// 129 is old truncate
132// 130 is old ftruncate
133pub const SYS_flock = 131;
134pub const SYS_mkfifo = 132;
135pub const SYS_sendto = 133;
136pub const SYS_shutdown = 134;
137pub const SYS_socketpair = 135;
138pub const SYS_mkdir = 136;
139pub const SYS_rmdir = 137;
140pub const SYS_utimes = 138;
141// 139 is obsolete 4.2 sigreturn
142pub const SYS_adjtime = 140;
143// 141 is old getpeername
144// 142 is old gethostid
145// 143 is old sethostid
146// 144 is old getrlimit
147// 145 is old setrlimit
148// 146 is old killpg
149pub const SYS_setsid = 147;
150pub const SYS_quotactl = 148;
151// 149 is old quota
152// 150 is old getsockname
153pub const SYS_nlm_syscall = 154;
154pub const SYS_nfssvc = 155;
155// 156 is old getdirentries
156// 157 is freebsd4 statfs
157// 158 is freebsd4 fstatfs
158pub const SYS_lgetfh = 160;
159pub const SYS_getfh = 161;
160// 162 is freebsd4 getdomainname
161// 163 is freebsd4 setdomainname
162// 164 is freebsd4 uname
163pub const SYS_sysarch = 165;
164pub const SYS_rtprio = 166;
165pub const SYS_semsys = 169;
166pub const SYS_msgsys = 170;
167pub const SYS_shmsys = 171;
168// 173 is freebsd6 pread
169// 174 is freebsd6 pwrite
170pub const SYS_setfib = 175;
171pub const SYS_ntp_adjtime = 176;
172pub const SYS_setgid = 181;
173pub const SYS_setegid = 182;
174pub const SYS_seteuid = 183;
175pub const SYS_freebsd11_stat = 188;
176pub const SYS_freebsd11_fstat = 189;
177pub const SYS_freebsd11_lstat = 190;
178pub const SYS_pathconf = 191;
179pub const SYS_fpathconf = 192;
180pub const SYS_getrlimit = 194;
181pub const SYS_setrlimit = 195;
182pub const SYS_freebsd11_getdirentries = 196;
183// 197 is freebsd6 mmap
184pub const SYS___syscall = 198;
185// 199 is freebsd6 lseek
186// 200 is freebsd6 truncate
187// 201 is freebsd6 ftruncate
188pub const SYS___sysctl = 202;
189pub const SYS_mlock = 203;
190pub const SYS_munlock = 204;
191pub const SYS_undelete = 205;
192pub const SYS_futimes = 206;
193pub const SYS_getpgid = 207;
194pub const SYS_poll = 209;
195pub const SYS_freebsd7___semctl = 220;
196pub const SYS_semget = 221;
197pub const SYS_semop = 222;
198pub const SYS_freebsd7_msgctl = 224;
199pub const SYS_msgget = 225;
200pub const SYS_msgsnd = 226;
201pub const SYS_msgrcv = 227;
202pub const SYS_shmat = 228;
203pub const SYS_freebsd7_shmctl = 229;
204pub const SYS_shmdt = 230;
205pub const SYS_shmget = 231;
206pub const SYS_clock_gettime = 232;
207pub const SYS_clock_settime = 233;
208pub const SYS_clock_getres = 234;
209pub const SYS_ktimer_create = 235;
210pub const SYS_ktimer_delete = 236;
211pub const SYS_ktimer_settime = 237;
212pub const SYS_ktimer_gettime = 238;
213pub const SYS_ktimer_getoverrun = 239;
214pub const SYS_nanosleep = 240;
215pub const SYS_ffclock_getcounter = 241;
216pub const SYS_ffclock_setestimate = 242;
217pub const SYS_ffclock_getestimate = 243;
218pub const SYS_clock_nanosleep = 244;
219pub const SYS_clock_getcpuclockid2 = 247;
220pub const SYS_ntp_gettime = 248;
221pub const SYS_minherit = 250;
222pub const SYS_rfork = 251;
223// 252 is obsolete openbsd_poll
224pub const SYS_issetugid = 253;
225pub const SYS_lchown = 254;
226pub const SYS_aio_read = 255;
227pub const SYS_aio_write = 256;
228pub const SYS_lio_listio = 257;
229pub const SYS_freebsd11_getdents = 272;
230pub const SYS_lchmod = 274;
231pub const SYS_netbsd_lchown = 275;
232pub const SYS_lutimes = 276;
233pub const SYS_netbsd_msync = 277;
234pub const SYS_freebsd11_nstat = 278;
235pub const SYS_freebsd11_nfstat = 279;
236pub const SYS_freebsd11_nlstat = 280;
237pub const SYS_preadv = 289;
238pub const SYS_pwritev = 290;
239// 297 is freebsd4 fhstatfs
240pub const SYS_fhopen = 298;
241pub const SYS_freebsd11_fhstat = 299;
242pub const SYS_modnext = 300;
243pub const SYS_modstat = 301;
244pub const SYS_modfnext = 302;
245pub const SYS_modfind = 303;
246pub const SYS_kldload = 304;
247pub const SYS_kldunload = 305;
248pub const SYS_kldfind = 306;
249pub const SYS_kldnext = 307;
250pub const SYS_kldstat = 308;
251pub const SYS_kldfirstmod = 309;
252pub const SYS_getsid = 310;
253pub const SYS_setresuid = 311;
254pub const SYS_setresgid = 312;
255// 313 is obsolete signanosleep
256pub const SYS_aio_return = 314;
257pub const SYS_aio_suspend = 315;
258pub const SYS_aio_cancel = 316;
259pub const SYS_aio_error = 317;
260// 318 is freebsd6 aio_read
261// 319 is freebsd6 aio_write
262// 320 is freebsd6 lio_listio
263pub const SYS_yield = 321;
264// 322 is obsolete thr_sleep
265// 323 is obsolete thr_wakeup
266pub const SYS_mlockall = 324;
267pub const SYS_munlockall = 325;
268pub const SYS___getcwd = 326;
269pub const SYS_sched_setparam = 327;
270pub const SYS_sched_getparam = 328;
271pub const SYS_sched_setscheduler = 329;
272pub const SYS_sched_getscheduler = 330;
273pub const SYS_sched_yield = 331;
274pub const SYS_sched_get_priority_max = 332;
275pub const SYS_sched_get_priority_min = 333;
276pub const SYS_sched_rr_get_interval = 334;
277pub const SYS_utrace = 335;
278// 336 is freebsd4 sendfile
279pub const SYS_kldsym = 337;
280pub const SYS_jail = 338;
281pub const SYS_nnpfs_syscall = 339;
282pub const SYS_sigprocmask = 340;
283pub const SYS_sigsuspend = 341;
284// 342 is freebsd4 sigaction
285pub const SYS_sigpending = 343;
286// 344 is freebsd4 sigreturn
287pub const SYS_sigtimedwait = 345;
288pub const SYS_sigwaitinfo = 346;
289pub const SYS___acl_get_file = 347;
290pub const SYS___acl_set_file = 348;
291pub const SYS___acl_get_fd = 349;
292pub const SYS___acl_set_fd = 350;
293pub const SYS___acl_delete_file = 351;
294pub const SYS___acl_delete_fd = 352;
295pub const SYS___acl_aclcheck_file = 353;
296pub const SYS___acl_aclcheck_fd = 354;
297pub const SYS_extattrctl = 355;
298pub const SYS_extattr_set_file = 356;
299pub const SYS_extattr_get_file = 357;
300pub const SYS_extattr_delete_file = 358;
301pub const SYS_aio_waitcomplete = 359;
302pub const SYS_getresuid = 360;
303pub const SYS_getresgid = 361;
304pub const SYS_kqueue = 362;
305pub const SYS_freebsd11_kevent = 363;
306pub const SYS_extattr_set_fd = 371;
307pub const SYS_extattr_get_fd = 372;
308pub const SYS_extattr_delete_fd = 373;
309pub const SYS___setugid = 374;
310pub const SYS_eaccess = 376;
311pub const SYS_afs3_syscall = 377;
312pub const SYS_nmount = 378;
313pub const SYS___mac_get_proc = 384;
314pub const SYS___mac_set_proc = 385;
315pub const SYS___mac_get_fd = 386;
316pub const SYS___mac_get_file = 387;
317pub const SYS___mac_set_fd = 388;
318pub const SYS___mac_set_file = 389;
319pub const SYS_kenv = 390;
320pub const SYS_lchflags = 391;
321pub const SYS_uuidgen = 392;
322pub const SYS_sendfile = 393;
323pub const SYS_mac_syscall = 394;
324pub const SYS_freebsd11_getfsstat = 395;
325pub const SYS_freebsd11_statfs = 396;
326pub const SYS_freebsd11_fstatfs = 397;
327pub const SYS_freebsd11_fhstatfs = 398;
328pub const SYS_ksem_close = 400;
329pub const SYS_ksem_post = 401;
330pub const SYS_ksem_wait = 402;
331pub const SYS_ksem_trywait = 403;
332pub const SYS_ksem_init = 404;
333pub const SYS_ksem_open = 405;
334pub const SYS_ksem_unlink = 406;
335pub const SYS_ksem_getvalue = 407;
336pub const SYS_ksem_destroy = 408;
337pub const SYS___mac_get_pid = 409;
338pub const SYS___mac_get_link = 410;
339pub const SYS___mac_set_link = 411;
340pub const SYS_extattr_set_link = 412;
341pub const SYS_extattr_get_link = 413;
342pub const SYS_extattr_delete_link = 414;
343pub const SYS___mac_execve = 415;
344pub const SYS_sigaction = 416;
345pub const SYS_sigreturn = 417;
346pub const SYS_getcontext = 421;
347pub const SYS_setcontext = 422;
348pub const SYS_swapcontext = 423;
349pub const SYS_swapoff = 424;
350pub const SYS___acl_get_link = 425;
351pub const SYS___acl_set_link = 426;
352pub const SYS___acl_delete_link = 427;
353pub const SYS___acl_aclcheck_link = 428;
354pub const SYS_sigwait = 429;
355pub const SYS_thr_create = 430;
356pub const SYS_thr_exit = 431;
357pub const SYS_thr_self = 432;
358pub const SYS_thr_kill = 433;
359pub const SYS_jail_attach = 436;
360pub const SYS_extattr_list_fd = 437;
361pub const SYS_extattr_list_file = 438;
362pub const SYS_extattr_list_link = 439;
363pub const SYS_ksem_timedwait = 441;
364pub const SYS_thr_suspend = 442;
365pub const SYS_thr_wake = 443;
366pub const SYS_kldunloadf = 444;
367pub const SYS_audit = 445;
368pub const SYS_auditon = 446;
369pub const SYS_getauid = 447;
370pub const SYS_setauid = 448;
371pub const SYS_getaudit = 449;
372pub const SYS_setaudit = 450;
373pub const SYS_getaudit_addr = 451;
374pub const SYS_setaudit_addr = 452;
375pub const SYS_auditctl = 453;
376pub const SYS__umtx_op = 454;
377pub const SYS_thr_new = 455;
378pub const SYS_sigqueue = 456;
379pub const SYS_kmq_open = 457;
380pub const SYS_kmq_setattr = 458;
381pub const SYS_kmq_timedreceive = 459;
382pub const SYS_kmq_timedsend = 460;
383pub const SYS_kmq_notify = 461;
384pub const SYS_kmq_unlink = 462;
385pub const SYS_abort2 = 463;
386pub const SYS_thr_set_name = 464;
387pub const SYS_aio_fsync = 465;
388pub const SYS_rtprio_thread = 466;
389pub const SYS_sctp_peeloff = 471;
390pub const SYS_sctp_generic_sendmsg = 472;
391pub const SYS_sctp_generic_sendmsg_iov = 473;
392pub const SYS_sctp_generic_recvmsg = 474;
393pub const SYS_pread = 475;
394pub const SYS_pwrite = 476;
395pub const SYS_mmap = 477;
396pub const SYS_lseek = 478;
397pub const SYS_truncate = 479;
398pub const SYS_ftruncate = 480;
399pub const SYS_thr_kill2 = 481;
400pub const SYS_shm_open = 482;
401pub const SYS_shm_unlink = 483;
402pub const SYS_cpuset = 484;
403pub const SYS_cpuset_setid = 485;
404pub const SYS_cpuset_getid = 486;
405pub const SYS_cpuset_getaffinity = 487;
406pub const SYS_cpuset_setaffinity = 488;
407pub const SYS_faccessat = 489;
408pub const SYS_fchmodat = 490;
409pub const SYS_fchownat = 491;
410pub const SYS_fexecve = 492;
411pub const SYS_freebsd11_fstatat = 493;
412pub const SYS_futimesat = 494;
413pub const SYS_linkat = 495;
414pub const SYS_mkdirat = 496;
415pub const SYS_mkfifoat = 497;
416pub const SYS_freebsd11_mknodat = 498;
417pub const SYS_openat = 499;
418pub const SYS_readlinkat = 500;
419pub const SYS_renameat = 501;
420pub const SYS_symlinkat = 502;
421pub const SYS_unlinkat = 503;
422pub const SYS_posix_openpt = 504;
423pub const SYS_gssd_syscall = 505;
424pub const SYS_jail_get = 506;
425pub const SYS_jail_set = 507;
426pub const SYS_jail_remove = 508;
427pub const SYS_closefrom = 509;
428pub const SYS___semctl = 510;
429pub const SYS_msgctl = 511;
430pub const SYS_shmctl = 512;
431pub const SYS_lpathconf = 513;
432// 514 is obsolete cap_new
433pub const SYS___cap_rights_get = 515;
434pub const SYS_cap_enter = 516;
435pub const SYS_cap_getmode = 517;
436pub const SYS_pdfork = 518;
437pub const SYS_pdkill = 519;
438pub const SYS_pdgetpid = 520;
439pub const SYS_pselect = 522;
440pub const SYS_getloginclass = 523;
441pub const SYS_setloginclass = 524;
442pub const SYS_rctl_get_racct = 525;
443pub const SYS_rctl_get_rules = 526;
444pub const SYS_rctl_get_limits = 527;
445pub const SYS_rctl_add_rule = 528;
446pub const SYS_rctl_remove_rule = 529;
447pub const SYS_posix_fallocate = 530;
448pub const SYS_posix_fadvise = 531;
449pub const SYS_wait6 = 532;
450pub const SYS_cap_rights_limit = 533;
451pub const SYS_cap_ioctls_limit = 534;
452pub const SYS_cap_ioctls_get = 535;
453pub const SYS_cap_fcntls_limit = 536;
454pub const SYS_cap_fcntls_get = 537;
455pub const SYS_bindat = 538;
456pub const SYS_connectat = 539;
457pub const SYS_chflagsat = 540;
458pub const SYS_accept4 = 541;
459pub const SYS_pipe2 = 542;
460pub const SYS_aio_mlock = 543;
461pub const SYS_procctl = 544;
462pub const SYS_ppoll = 545;
463pub const SYS_futimens = 546;
464pub const SYS_utimensat = 547;
465pub const SYS_numa_getaffinity = 548;
466pub const SYS_numa_setaffinity = 549;
467pub const SYS_fdatasync = 550;
468pub const SYS_fstat = 551;
469pub const SYS_fstatat = 552;
470pub const SYS_fhstat = 553;
471pub const SYS_getdirentries = 554;
472pub const SYS_statfs = 555;
473pub const SYS_fstatfs = 556;
474pub const SYS_getfsstat = 557;
475pub const SYS_fhstatfs = 558;
476pub const SYS_mknodat = 559;
477pub const SYS_kevent = 560;
478pub const SYS_MAXSYSCALL = 561;
479
480// From here
481pub const O_CREAT = 0o100;
482pub const O_EXCL = 0o200;
483pub const O_NOCTTY = 0o400;
484pub const O_TRUNC = 0o1000;
485pub const O_APPEND = 0o2000;
486pub const O_NONBLOCK = 0o4000;
487pub const O_DSYNC = 0o10000;
488pub const O_SYNC = 0o4010000;
489pub const O_RSYNC = 0o4010000;
490pub const O_DIRECTORY = 0o200000;
491pub const O_NOFOLLOW = 0o400000;
492pub const O_CLOEXEC = 0o2000000;
493
494pub const O_ASYNC = 0o20000;
495pub const O_DIRECT = 0o40000;
496pub const O_LARGEFILE = 0o100000;
497pub const O_NOATIME = 0o1000000;
498pub const O_PATH = 0o10000000;
499pub const O_TMPFILE = 0o20200000;
500pub const O_NDELAY = O_NONBLOCK;
501
502pub const F_DUPFD = 0;
503pub const F_GETFD = 1;
504pub const F_SETFD = 2;
505pub const F_GETFL = 3;
506pub const F_SETFL = 4;
507
508pub const F_SETOWN = 8;
509pub const F_GETOWN = 9;
510pub const F_SETSIG = 10;
511pub const F_GETSIG = 11;
512
513pub const F_GETLK = 12;
514pub const F_SETLK = 13;
515pub const F_SETLKW = 14;
516
517pub const F_SETOWN_EX = 15;
518pub const F_GETOWN_EX = 16;
519
520pub const F_GETOWNER_UIDS = 17;
521
522pub inline fn syscall0(number: usize) -> usize {
523 asm volatile ("int $0x80"
524 : [ret] "={eax}" (-> usize)
525 : [number] "{eax}" (number))
526}
527
528pub inline fn syscall1(number: usize, arg1: usize) -> usize {
529 asm volatile ("int $0x80"
530 : [ret] "={eax}" (-> usize)
531 : [number] "{eax}" (number),
532 [arg1] "{ebx}" (arg1))
533}
534
535pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
536 asm volatile ("int $0x80"
537 : [ret] "={eax}" (-> usize)
538 : [number] "{eax}" (number),
539 [arg1] "{ebx}" (arg1),
540 [arg2] "{ecx}" (arg2))
541}
542
543pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
544 asm volatile ("int $0x80"
545 : [ret] "={eax}" (-> usize)
546 : [number] "{eax}" (number),
547 [arg1] "{ebx}" (arg1),
548 [arg2] "{ecx}" (arg2),
549 [arg3] "{edx}" (arg3))
550}
551
552pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
553 asm volatile ("int $0x80"
554 : [ret] "={eax}" (-> usize)
555 : [number] "{eax}" (number),
556 [arg1] "{ebx}" (arg1),
557 [arg2] "{ecx}" (arg2),
558 [arg3] "{edx}" (arg3),
559 [arg4] "{esi}" (arg4))
560}
561
562pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
563 arg4: usize, arg5: usize) -> usize
564{
565 asm volatile ("int $0x80"
566 : [ret] "={eax}" (-> usize)
567 : [number] "{eax}" (number),
568 [arg1] "{ebx}" (arg1),
569 [arg2] "{ecx}" (arg2),
570 [arg3] "{edx}" (arg3),
571 [arg4] "{esi}" (arg4),
572 [arg5] "{edi}" (arg5))
573}
574
575pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
576 arg4: usize, arg5: usize, arg6: usize) -> usize
577{
578 asm volatile ("int $0x80"
579 : [ret] "={eax}" (-> usize)
580 : [number] "{eax}" (number),
581 [arg1] "{ebx}" (arg1),
582 [arg2] "{ecx}" (arg2),
583 [arg3] "{edx}" (arg3),
584 [arg4] "{esi}" (arg4),
585 [arg5] "{edi}" (arg5),
586 [arg6] "{ebp}" (arg6))
587}
588
589pub nakedcc fn restore() {
590 asm volatile (
591 \\popl %%eax
592 \\movl $119, %%eax
593 \\int $0x80
594 :
595 :
596 : "rcx", "r11")
597}
598
599pub nakedcc fn restore_rt() {
600 asm volatile ("int $0x80"
601 :
602 : [number] "{eax}" (usize(SYS_rt_sigreturn))
603 : "rcx", "r11")
604}
605
606export struct msghdr {
607 msg_name: &u8,
608 msg_namelen: socklen_t,
609 msg_iov: &iovec,
610 msg_iovlen: i32,
611 msg_control: &u8,
612 msg_controllen: socklen_t,
613 msg_flags: i32,
614}
std/os/freebsd_x86_64.zig created+637
...@@ -0,0 +1,637 @@
1const freebsd = @import("freebsd.zig");
2const socklen_t = freebsd.socklen_t;
3const iovec = freebsd.iovec;
4
5pub const SYS_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_wait4 = 7;
13// 8 is old creat
14pub const SYS_link = 9;
15pub const SYS_unlink = 10;
16// 11 is obsolete execv
17pub const SYS_chdir = 12;
18pub const SYS_fchdir = 13;
19pub const SYS_freebsd11_mknod = 14;
20pub const SYS_chmod = 15;
21pub const SYS_chown = 16;
22pub const SYS_break = 17;
23// 18 is freebsd4 getfsstat
24// 19 is old lseek
25pub const SYS_getpid = 20;
26pub const SYS_mount = 21;
27pub const SYS_unmount = 22;
28pub const SYS_setuid = 23;
29pub const SYS_getuid = 24;
30pub const SYS_geteuid = 25;
31pub const SYS_ptrace = 26;
32pub const SYS_recvmsg = 27;
33pub const SYS_sendmsg = 28;
34pub const SYS_recvfrom = 29;
35pub const SYS_accept = 30;
36pub const SYS_getpeername = 31;
37pub const SYS_getsockname = 32;
38pub const SYS_access = 33;
39pub const SYS_chflags = 34;
40pub const SYS_fchflags = 35;
41pub const SYS_sync = 36;
42pub const SYS_kill = 37;
43// 38 is old stat
44pub const SYS_getppid = 39;
45// 40 is old lstat
46pub const SYS_dup = 41;
47pub const SYS_freebsd10_pipe = 42;
48pub const SYS_getegid = 43;
49pub const SYS_profil = 44;
50pub const SYS_ktrace = 45;
51// 46 is old sigaction
52pub const SYS_getgid = 47;
53// 48 is old sigprocmask
54pub const SYS_getlogin = 49;
55pub const SYS_setlogin = 50;
56pub const SYS_acct = 51;
57// 52 is old sigpending
58pub const SYS_sigaltstack = 53;
59pub const SYS_ioctl = 54;
60pub const SYS_reboot = 55;
61pub const SYS_revoke = 56;
62pub const SYS_symlink = 57;
63pub const SYS_readlink = 58;
64pub const SYS_execve = 59;
65pub const SYS_umask = 60;
66pub const SYS_chroot = 61;
67// 62 is old fstat
68// 63 is old getkerninfo
69// 64 is old getpagesize
70pub const SYS_msync = 65;
71pub const SYS_vfork = 66;
72// 67 is obsolete vread
73// 68 is obsolete vwrite
74pub const SYS_sbrk = 69;
75pub const SYS_sstk = 70;
76// 71 is old mmap
77pub const SYS_vadvise = 72;
78pub const SYS_munmap = 73;
79pub const SYS_mprotect = 74;
80pub const SYS_madvise = 75;
81// 76 is obsolete vhangup
82// 77 is obsolete vlimit
83pub const SYS_mincore = 78;
84pub const SYS_getgroups = 79;
85pub const SYS_setgroups = 80;
86pub const SYS_getpgrp = 81;
87pub const SYS_setpgid = 82;
88pub const SYS_setitimer = 83;
89// 84 is old wait
90pub const SYS_swapon = 85;
91pub const SYS_getitimer = 86;
92// 87 is old gethostname
93// 88 is old sethostname
94pub const SYS_getdtablesize = 89;
95pub const SYS_dup2 = 90;
96pub const SYS_fcntl = 92;
97pub const SYS_select = 93;
98pub const SYS_fsync = 95;
99pub const SYS_setpriority = 96;
100pub const SYS_socket = 97;
101pub const SYS_connect = 98;
102// 99 is old accept
103pub const SYS_getpriority = 100;
104// 101 is old send
105// 102 is old recv
106// 103 is old sigreturn
107pub const SYS_bind = 104;
108pub const SYS_setsockopt = 105;
109pub const SYS_listen = 106;
110// 107 is obsolete vtimes
111// 108 is old sigvec
112// 109 is old sigblock
113// 110 is old sigsetmask
114// 111 is old sigsuspend
115// 112 is old sigstack
116// 113 is old recvmsg
117// 114 is old sendmsg
118// 115 is obsolete vtrace
119pub const SYS_gettimeofday = 116;
120pub const SYS_getrusage = 117;
121pub const SYS_getsockopt = 118;
122pub const SYS_readv = 120;
123pub const SYS_writev = 121;
124pub const SYS_settimeofday = 122;
125pub const SYS_fchown = 123;
126pub const SYS_fchmod = 124;
127// 125 is old recvfrom
128pub const SYS_setreuid = 126;
129pub const SYS_setregid = 127;
130pub const SYS_rename = 128;
131// 129 is old truncate
132// 130 is old ftruncate
133pub const SYS_flock = 131;
134pub const SYS_mkfifo = 132;
135pub const SYS_sendto = 133;
136pub const SYS_shutdown = 134;
137pub const SYS_socketpair = 135;
138pub const SYS_mkdir = 136;
139pub const SYS_rmdir = 137;
140pub const SYS_utimes = 138;
141// 139 is obsolete 4.2 sigreturn
142pub const SYS_adjtime = 140;
143// 141 is old getpeername
144// 142 is old gethostid
145// 143 is old sethostid
146// 144 is old getrlimit
147// 145 is old setrlimit
148// 146 is old killpg
149pub const SYS_setsid = 147;
150pub const SYS_quotactl = 148;
151// 149 is old quota
152// 150 is old getsockname
153pub const SYS_nlm_syscall = 154;
154pub const SYS_nfssvc = 155;
155// 156 is old getdirentries
156// 157 is freebsd4 statfs
157// 158 is freebsd4 fstatfs
158pub const SYS_lgetfh = 160;
159pub const SYS_getfh = 161;
160// 162 is freebsd4 getdomainname
161// 163 is freebsd4 setdomainname
162// 164 is freebsd4 uname
163pub const SYS_sysarch = 165;
164pub const SYS_rtprio = 166;
165pub const SYS_semsys = 169;
166pub const SYS_msgsys = 170;
167pub const SYS_shmsys = 171;
168// 173 is freebsd6 pread
169// 174 is freebsd6 pwrite
170pub const SYS_setfib = 175;
171pub const SYS_ntp_adjtime = 176;
172pub const SYS_setgid = 181;
173pub const SYS_setegid = 182;
174pub const SYS_seteuid = 183;
175pub const SYS_freebsd11_stat = 188;
176pub const SYS_freebsd11_fstat = 189;
177pub const SYS_freebsd11_lstat = 190;
178pub const SYS_pathconf = 191;
179pub const SYS_fpathconf = 192;
180pub const SYS_getrlimit = 194;
181pub const SYS_setrlimit = 195;
182pub const SYS_freebsd11_getdirentries = 196;
183// 197 is freebsd6 mmap
184pub const SYS___syscall = 198;
185// 199 is freebsd6 lseek
186// 200 is freebsd6 truncate
187// 201 is freebsd6 ftruncate
188pub const SYS___sysctl = 202;
189pub const SYS_mlock = 203;
190pub const SYS_munlock = 204;
191pub const SYS_undelete = 205;
192pub const SYS_futimes = 206;
193pub const SYS_getpgid = 207;
194pub const SYS_poll = 209;
195pub const SYS_freebsd7___semctl = 220;
196pub const SYS_semget = 221;
197pub const SYS_semop = 222;
198pub const SYS_freebsd7_msgctl = 224;
199pub const SYS_msgget = 225;
200pub const SYS_msgsnd = 226;
201pub const SYS_msgrcv = 227;
202pub const SYS_shmat = 228;
203pub const SYS_freebsd7_shmctl = 229;
204pub const SYS_shmdt = 230;
205pub const SYS_shmget = 231;
206pub const SYS_clock_gettime = 232;
207pub const SYS_clock_settime = 233;
208pub const SYS_clock_getres = 234;
209pub const SYS_ktimer_create = 235;
210pub const SYS_ktimer_delete = 236;
211pub const SYS_ktimer_settime = 237;
212pub const SYS_ktimer_gettime = 238;
213pub const SYS_ktimer_getoverrun = 239;
214pub const SYS_nanosleep = 240;
215pub const SYS_ffclock_getcounter = 241;
216pub const SYS_ffclock_setestimate = 242;
217pub const SYS_ffclock_getestimate = 243;
218pub const SYS_clock_nanosleep = 244;
219pub const SYS_clock_getcpuclockid2 = 247;
220pub const SYS_ntp_gettime = 248;
221pub const SYS_minherit = 250;
222pub const SYS_rfork = 251;
223// 252 is obsolete openbsd_poll
224pub const SYS_issetugid = 253;
225pub const SYS_lchown = 254;
226pub const SYS_aio_read = 255;
227pub const SYS_aio_write = 256;
228pub const SYS_lio_listio = 257;
229pub const SYS_freebsd11_getdents = 272;
230pub const SYS_lchmod = 274;
231pub const SYS_netbsd_lchown = 275;
232pub const SYS_lutimes = 276;
233pub const SYS_netbsd_msync = 277;
234pub const SYS_freebsd11_nstat = 278;
235pub const SYS_freebsd11_nfstat = 279;
236pub const SYS_freebsd11_nlstat = 280;
237pub const SYS_preadv = 289;
238pub const SYS_pwritev = 290;
239// 297 is freebsd4 fhstatfs
240pub const SYS_fhopen = 298;
241pub const SYS_freebsd11_fhstat = 299;
242pub const SYS_modnext = 300;
243pub const SYS_modstat = 301;
244pub const SYS_modfnext = 302;
245pub const SYS_modfind = 303;
246pub const SYS_kldload = 304;
247pub const SYS_kldunload = 305;
248pub const SYS_kldfind = 306;
249pub const SYS_kldnext = 307;
250pub const SYS_kldstat = 308;
251pub const SYS_kldfirstmod = 309;
252pub const SYS_getsid = 310;
253pub const SYS_setresuid = 311;
254pub const SYS_setresgid = 312;
255// 313 is obsolete signanosleep
256pub const SYS_aio_return = 314;
257pub const SYS_aio_suspend = 315;
258pub const SYS_aio_cancel = 316;
259pub const SYS_aio_error = 317;
260// 318 is freebsd6 aio_read
261// 319 is freebsd6 aio_write
262// 320 is freebsd6 lio_listio
263pub const SYS_yield = 321;
264// 322 is obsolete thr_sleep
265// 323 is obsolete thr_wakeup
266pub const SYS_mlockall = 324;
267pub const SYS_munlockall = 325;
268pub const SYS___getcwd = 326;
269pub const SYS_sched_setparam = 327;
270pub const SYS_sched_getparam = 328;
271pub const SYS_sched_setscheduler = 329;
272pub const SYS_sched_getscheduler = 330;
273pub const SYS_sched_yield = 331;
274pub const SYS_sched_get_priority_max = 332;
275pub const SYS_sched_get_priority_min = 333;
276pub const SYS_sched_rr_get_interval = 334;
277pub const SYS_utrace = 335;
278// 336 is freebsd4 sendfile
279pub const SYS_kldsym = 337;
280pub const SYS_jail = 338;
281pub const SYS_nnpfs_syscall = 339;
282pub const SYS_sigprocmask = 340;
283pub const SYS_sigsuspend = 341;
284// 342 is freebsd4 sigaction
285pub const SYS_sigpending = 343;
286// 344 is freebsd4 sigreturn
287pub const SYS_sigtimedwait = 345;
288pub const SYS_sigwaitinfo = 346;
289pub const SYS___acl_get_file = 347;
290pub const SYS___acl_set_file = 348;
291pub const SYS___acl_get_fd = 349;
292pub const SYS___acl_set_fd = 350;
293pub const SYS___acl_delete_file = 351;
294pub const SYS___acl_delete_fd = 352;
295pub const SYS___acl_aclcheck_file = 353;
296pub const SYS___acl_aclcheck_fd = 354;
297pub const SYS_extattrctl = 355;
298pub const SYS_extattr_set_file = 356;
299pub const SYS_extattr_get_file = 357;
300pub const SYS_extattr_delete_file = 358;
301pub const SYS_aio_waitcomplete = 359;
302pub const SYS_getresuid = 360;
303pub const SYS_getresgid = 361;
304pub const SYS_kqueue = 362;
305pub const SYS_freebsd11_kevent = 363;
306pub const SYS_extattr_set_fd = 371;
307pub const SYS_extattr_get_fd = 372;
308pub const SYS_extattr_delete_fd = 373;
309pub const SYS___setugid = 374;
310pub const SYS_eaccess = 376;
311pub const SYS_afs3_syscall = 377;
312pub const SYS_nmount = 378;
313pub const SYS___mac_get_proc = 384;
314pub const SYS___mac_set_proc = 385;
315pub const SYS___mac_get_fd = 386;
316pub const SYS___mac_get_file = 387;
317pub const SYS___mac_set_fd = 388;
318pub const SYS___mac_set_file = 389;
319pub const SYS_kenv = 390;
320pub const SYS_lchflags = 391;
321pub const SYS_uuidgen = 392;
322pub const SYS_sendfile = 393;
323pub const SYS_mac_syscall = 394;
324pub const SYS_freebsd11_getfsstat = 395;
325pub const SYS_freebsd11_statfs = 396;
326pub const SYS_freebsd11_fstatfs = 397;
327pub const SYS_freebsd11_fhstatfs = 398;
328pub const SYS_ksem_close = 400;
329pub const SYS_ksem_post = 401;
330pub const SYS_ksem_wait = 402;
331pub const SYS_ksem_trywait = 403;
332pub const SYS_ksem_init = 404;
333pub const SYS_ksem_open = 405;
334pub const SYS_ksem_unlink = 406;
335pub const SYS_ksem_getvalue = 407;
336pub const SYS_ksem_destroy = 408;
337pub const SYS___mac_get_pid = 409;
338pub const SYS___mac_get_link = 410;
339pub const SYS___mac_set_link = 411;
340pub const SYS_extattr_set_link = 412;
341pub const SYS_extattr_get_link = 413;
342pub const SYS_extattr_delete_link = 414;
343pub const SYS___mac_execve = 415;
344pub const SYS_sigaction = 416;
345pub const SYS_sigreturn = 417;
346pub const SYS_getcontext = 421;
347pub const SYS_setcontext = 422;
348pub const SYS_swapcontext = 423;
349pub const SYS_swapoff = 424;
350pub const SYS___acl_get_link = 425;
351pub const SYS___acl_set_link = 426;
352pub const SYS___acl_delete_link = 427;
353pub const SYS___acl_aclcheck_link = 428;
354pub const SYS_sigwait = 429;
355pub const SYS_thr_create = 430;
356pub const SYS_thr_exit = 431;
357pub const SYS_thr_self = 432;
358pub const SYS_thr_kill = 433;
359pub const SYS_jail_attach = 436;
360pub const SYS_extattr_list_fd = 437;
361pub const SYS_extattr_list_file = 438;
362pub const SYS_extattr_list_link = 439;
363pub const SYS_ksem_timedwait = 441;
364pub const SYS_thr_suspend = 442;
365pub const SYS_thr_wake = 443;
366pub const SYS_kldunloadf = 444;
367pub const SYS_audit = 445;
368pub const SYS_auditon = 446;
369pub const SYS_getauid = 447;
370pub const SYS_setauid = 448;
371pub const SYS_getaudit = 449;
372pub const SYS_setaudit = 450;
373pub const SYS_getaudit_addr = 451;
374pub const SYS_setaudit_addr = 452;
375pub const SYS_auditctl = 453;
376pub const SYS__umtx_op = 454;
377pub const SYS_thr_new = 455;
378pub const SYS_sigqueue = 456;
379pub const SYS_kmq_open = 457;
380pub const SYS_kmq_setattr = 458;
381pub const SYS_kmq_timedreceive = 459;
382pub const SYS_kmq_timedsend = 460;
383pub const SYS_kmq_notify = 461;
384pub const SYS_kmq_unlink = 462;
385pub const SYS_abort2 = 463;
386pub const SYS_thr_set_name = 464;
387pub const SYS_aio_fsync = 465;
388pub const SYS_rtprio_thread = 466;
389pub const SYS_sctp_peeloff = 471;
390pub const SYS_sctp_generic_sendmsg = 472;
391pub const SYS_sctp_generic_sendmsg_iov = 473;
392pub const SYS_sctp_generic_recvmsg = 474;
393pub const SYS_pread = 475;
394pub const SYS_pwrite = 476;
395pub const SYS_mmap = 477;
396pub const SYS_lseek = 478;
397pub const SYS_truncate = 479;
398pub const SYS_ftruncate = 480;
399pub const SYS_thr_kill2 = 481;
400pub const SYS_shm_open = 482;
401pub const SYS_shm_unlink = 483;
402pub const SYS_cpuset = 484;
403pub const SYS_cpuset_setid = 485;
404pub const SYS_cpuset_getid = 486;
405pub const SYS_cpuset_getaffinity = 487;
406pub const SYS_cpuset_setaffinity = 488;
407pub const SYS_faccessat = 489;
408pub const SYS_fchmodat = 490;
409pub const SYS_fchownat = 491;
410pub const SYS_fexecve = 492;
411pub const SYS_freebsd11_fstatat = 493;
412pub const SYS_futimesat = 494;
413pub const SYS_linkat = 495;
414pub const SYS_mkdirat = 496;
415pub const SYS_mkfifoat = 497;
416pub const SYS_freebsd11_mknodat = 498;
417pub const SYS_openat = 499;
418pub const SYS_readlinkat = 500;
419pub const SYS_renameat = 501;
420pub const SYS_symlinkat = 502;
421pub const SYS_unlinkat = 503;
422pub const SYS_posix_openpt = 504;
423pub const SYS_gssd_syscall = 505;
424pub const SYS_jail_get = 506;
425pub const SYS_jail_set = 507;
426pub const SYS_jail_remove = 508;
427pub const SYS_closefrom = 509;
428pub const SYS___semctl = 510;
429pub const SYS_msgctl = 511;
430pub const SYS_shmctl = 512;
431pub const SYS_lpathconf = 513;
432// 514 is obsolete cap_new
433pub const SYS___cap_rights_get = 515;
434pub const SYS_cap_enter = 516;
435pub const SYS_cap_getmode = 517;
436pub const SYS_pdfork = 518;
437pub const SYS_pdkill = 519;
438pub const SYS_pdgetpid = 520;
439pub const SYS_pselect = 522;
440pub const SYS_getloginclass = 523;
441pub const SYS_setloginclass = 524;
442pub const SYS_rctl_get_racct = 525;
443pub const SYS_rctl_get_rules = 526;
444pub const SYS_rctl_get_limits = 527;
445pub const SYS_rctl_add_rule = 528;
446pub const SYS_rctl_remove_rule = 529;
447pub const SYS_posix_fallocate = 530;
448pub const SYS_posix_fadvise = 531;
449pub const SYS_wait6 = 532;
450pub const SYS_cap_rights_limit = 533;
451pub const SYS_cap_ioctls_limit = 534;
452pub const SYS_cap_ioctls_get = 535;
453pub const SYS_cap_fcntls_limit = 536;
454pub const SYS_cap_fcntls_get = 537;
455pub const SYS_bindat = 538;
456pub const SYS_connectat = 539;
457pub const SYS_chflagsat = 540;
458pub const SYS_accept4 = 541;
459pub const SYS_pipe2 = 542;
460pub const SYS_aio_mlock = 543;
461pub const SYS_procctl = 544;
462pub const SYS_ppoll = 545;
463pub const SYS_futimens = 546;
464pub const SYS_utimensat = 547;
465pub const SYS_numa_getaffinity = 548;
466pub const SYS_numa_setaffinity = 549;
467pub const SYS_fdatasync = 550;
468pub const SYS_fstat = 551;
469pub const SYS_fstatat = 552;
470pub const SYS_fhstat = 553;
471pub const SYS_getdirentries = 554;
472pub const SYS_statfs = 555;
473pub const SYS_fstatfs = 556;
474pub const SYS_getfsstat = 557;
475pub const SYS_fhstatfs = 558;
476pub const SYS_mknodat = 559;
477pub const SYS_kevent = 560;
478pub const SYS_MAXSYSCALL = 561;
479
480pub const O_CREAT = 0o100;
481pub const O_EXCL = 0o200;
482pub const O_NOCTTY = 0o400;
483pub const O_TRUNC = 0o1000;
484pub const O_APPEND = 0o2000;
485pub const O_NONBLOCK = 0o4000;
486pub const O_DSYNC = 0o10000;
487pub const O_SYNC = 0o4010000;
488pub const O_RSYNC = 0o4010000;
489pub const O_DIRECTORY = 0o200000;
490pub const O_NOFOLLOW = 0o400000;
491pub const O_CLOEXEC = 0o2000000;
492
493pub const O_ASYNC = 0o20000;
494pub const O_DIRECT = 0o40000;
495pub const O_LARGEFILE = 0;
496pub const O_NOATIME = 0o1000000;
497pub const O_PATH = 0o10000000;
498pub const O_TMPFILE = 0o20200000;
499pub const O_NDELAY = O_NONBLOCK;
500
501pub const F_DUPFD = 0;
502pub const F_GETFD = 1;
503pub const F_SETFD = 2;
504pub const F_GETFL = 3;
505pub const F_SETFL = 4;
506
507pub const F_SETOWN = 8;
508pub const F_GETOWN = 9;
509pub const F_SETSIG = 10;
510pub const F_GETSIG = 11;
511
512pub const F_GETLK = 5;
513pub const F_SETLK = 6;
514pub const F_SETLKW = 7;
515
516pub const F_SETOWN_EX = 15;
517pub const F_GETOWN_EX = 16;
518
519pub const F_GETOWNER_UIDS = 17;
520
521pub fn syscall0(number: usize) -> usize {
522 asm volatile ("syscall"
523 : [ret] "={rax}" (-> usize)
524 : [number] "{rax}" (number)
525 : "rcx", "r11")
526}
527
528pub fn syscall1(number: usize, arg1: usize) -> usize {
529 asm volatile ("syscall"
530 : [ret] "={rax}" (-> usize)
531 : [number] "{rax}" (number),
532 [arg1] "{rdi}" (arg1)
533 : "rcx", "r11")
534}
535
536pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
537 asm volatile ("syscall"
538 : [ret] "={rax}" (-> usize)
539 : [number] "{rax}" (number),
540 [arg1] "{rdi}" (arg1),
541 [arg2] "{rsi}" (arg2)
542 : "rcx", "r11")
543}
544
545pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
546 asm volatile ("syscall"
547 : [ret] "={rax}" (-> usize)
548 : [number] "{rax}" (number),
549 [arg1] "{rdi}" (arg1),
550 [arg2] "{rsi}" (arg2),
551 [arg3] "{rdx}" (arg3)
552 : "rcx", "r11")
553}
554
555pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
556 asm volatile ("syscall"
557 : [ret] "={rax}" (-> usize)
558 : [number] "{rax}" (number),
559 [arg1] "{rdi}" (arg1),
560 [arg2] "{rsi}" (arg2),
561 [arg3] "{rdx}" (arg3),
562 [arg4] "{r10}" (arg4)
563 : "rcx", "r11")
564}
565
566pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
567 asm volatile ("syscall"
568 : [ret] "={rax}" (-> usize)
569 : [number] "{rax}" (number),
570 [arg1] "{rdi}" (arg1),
571 [arg2] "{rsi}" (arg2),
572 [arg3] "{rdx}" (arg3),
573 [arg4] "{r10}" (arg4),
574 [arg5] "{r8}" (arg5)
575 : "rcx", "r11")
576}
577
578pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
579 arg5: usize, arg6: usize) -> usize
580{
581 asm volatile ("syscall"
582 : [ret] "={rax}" (-> usize)
583 : [number] "{rax}" (number),
584 [arg1] "{rdi}" (arg1),
585 [arg2] "{rsi}" (arg2),
586 [arg3] "{rdx}" (arg3),
587 [arg4] "{r10}" (arg4),
588 [arg5] "{r8}" (arg5),
589 [arg6] "{r9}" (arg6)
590 : "rcx", "r11")
591}
592
593pub nakedcc fn restore_rt() {
594 asm volatile ("syscall"
595 :
596 : [number] "{rax}" (usize(SYS_rt_sigreturn))
597 : "rcx", "r11")
598}
599
600
601pub const msghdr = extern struct {
602 msg_name: &u8,
603 msg_namelen: socklen_t,
604 msg_iov: &iovec,
605 msg_iovlen: i32,
606 __pad1: i32,
607 msg_control: &u8,
608 msg_controllen: socklen_t,
609 __pad2: socklen_t,
610 msg_flags: i32,
611};
612
613/// Renamed to Stat to not conflict with the stat function.
614pub const Stat = extern struct {
615 dev: u64,
616 ino: u64,
617 nlink: usize,
618
619 mode: u32,
620 uid: u32,
621 gid: u32,
622 __pad0: u32,
623 rdev: u64,
624 size: i64,
625 blksize: isize,
626 blocks: i64,
627
628 atim: timespec,
629 mtim: timespec,
630 ctim: timespec,
631 __unused: [3]isize,
632};
633
634pub const timespec = extern struct {
635 tv_sec: isize,
636 tv_nsec: isize,
637};
std/os/get_user_id.zig+1-1
...@@ -11,7 +11,7 @@ pub const UserInfo = struct.{...@@ -11,7 +11,7 @@ pub const UserInfo = struct.{
11/// POSIX function which gets a uid from username.11/// POSIX function which gets a uid from username.
12pub fn getUserInfo(name: []const u8) !UserInfo {12pub fn getUserInfo(name: []const u8) !UserInfo {
13 return switch (builtin.os) {13 return switch (builtin.os) {
14 Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name),14 Os.linux, Os.macosx, Os.ios, Os.freebsd => posixGetUserInfo(name),
15 else => @compileError("Unsupported OS"),15 else => @compileError("Unsupported OS"),
16 };16 };
17}17}
std/os/index.zig+4-2
...@@ -24,10 +24,12 @@ test "std.os" {...@@ -24,10 +24,12 @@ test "std.os" {
24pub const windows = @import("windows/index.zig");24pub const windows = @import("windows/index.zig");
25pub const darwin = @import("darwin.zig");25pub const darwin = @import("darwin.zig");
26pub const linux = @import("linux/index.zig");26pub const linux = @import("linux/index.zig");
27pub const freebsd = @import("freebsd.zig");
27pub const zen = @import("zen.zig");28pub const zen = @import("zen.zig");
28pub const posix = switch (builtin.os) {29pub const posix = switch (builtin.os) {
29 Os.linux => linux,30 Os.linux => linux,
30 Os.macosx, Os.ios => darwin,31 Os.macosx, Os.ios => darwin,
32 Os.freebsd => freebsd,
31 Os.zen => zen,33 Os.zen => zen,
32 else => @compileError("Unsupported OS"),34 else => @compileError("Unsupported OS"),
33};35};
...@@ -174,7 +176,7 @@ pub fn abort() noreturn {...@@ -174,7 +176,7 @@ pub fn abort() noreturn {
174 c.abort();176 c.abort();
175 }177 }
176 switch (builtin.os) {178 switch (builtin.os) {
177 Os.linux, Os.macosx, Os.ios => {179 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
178 _ = posix.raise(posix.SIGABRT);180 _ = posix.raise(posix.SIGABRT);
179 _ = posix.raise(posix.SIGKILL);181 _ = posix.raise(posix.SIGKILL);
180 while (true) {}182 while (true) {}
...@@ -196,7 +198,7 @@ pub fn exit(status: u8) noreturn {...@@ -196,7 +198,7 @@ pub fn exit(status: u8) noreturn {
196 c.exit(status);198 c.exit(status);
197 }199 }
198 switch (builtin.os) {200 switch (builtin.os) {
199 Os.linux, Os.macosx, Os.ios => {201 Os.linux, Os.macosx, Os.ios, Os.freebsd => {
200 posix.exit(status);202 posix.exit(status);
201 },203 },
202 Os.windows => {204 Os.windows => {
std/os/path.zig+2-2
...@@ -1161,7 +1161,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro...@@ -1161,7 +1161,7 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro
1161 const pathname_w = try windows_util.cStrToPrefixedFileW(pathname);1161 const pathname_w = try windows_util.cStrToPrefixedFileW(pathname);
1162 return realW(out_buffer, pathname_w);1162 return realW(out_buffer, pathname_w);
1163 },1163 },
1164 Os.macosx, Os.ios => {1164 Os.macosx, Os.ios, Os.freebsd => {
1165 // TODO instead of calling the libc function here, port the implementation to Zig1165 // TODO instead of calling the libc function here, port the implementation to Zig
1166 const err = posix.getErrno(posix.realpath(pathname, out_buffer));1166 const err = posix.getErrno(posix.realpath(pathname, out_buffer));
1167 switch (err) {1167 switch (err) {
...@@ -1202,7 +1202,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError!...@@ -1202,7 +1202,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError!
1202 const pathname_w = try windows_util.sliceToPrefixedFileW(pathname);1202 const pathname_w = try windows_util.sliceToPrefixedFileW(pathname);
1203 return realW(out_buffer, &pathname_w);1203 return realW(out_buffer, &pathname_w);
1204 },1204 },
1205 Os.macosx, Os.ios, Os.linux => {1205 Os.macosx, Os.ios, Os.linux, Os.freebsd => {
1206 const pathname_c = try os.toPosixPath(pathname);1206 const pathname_c = try os.toPosixPath(pathname);
1207 return realC(out_buffer, &pathname_c);1207 return realC(out_buffer, &pathname_c);
1208 },1208 },