authorgravatar for greg@unrelenting.technologyGreg V <greg@unrelenting.technology> 2018-10-17 18:00:22+03:00
committergravatar for greg@unrelenting.technologyGreg V <greg@unrelenting.technology> 2018-10-20 15:15:01+03:00
log1829c093032764ef397a02d0d7512254f5bb4ad0
tree4c379ce394993fc72da16058978d0ce98e74b7da
parent19659c3bd347471d3d55597bdc1c141e9e4a1ae1

Fix os/freebsd files


8 files changed, 1346 insertions(+), 1957 deletions(-)

CMakeLists.txt+3
......@@ -580,6 +580,9 @@ set(ZIG_STD_FILES
580580 "os/linux/vdso.zig"
581581 "os/linux/x86_64.zig"
582582 "os/linux/arm64.zig"
583 "os/freebsd/errno.zig"
584 "os/freebsd/index.zig"
585 "os/freebsd/x86_64.zig"
583586 "os/path.zig"
584587 "os/time.zig"
585588 "os/windows/advapi32.zig"
std/os/freebsd.zig deleted-572
......@@ -1,572 +0,0 @@
1const c = @import("../c/index.zig");
2const assert = @import("../debug.zig").assert;
3const builtin = @import("builtin");
4const arch = switch (builtin.arch) {
5 builtin.Arch.x86_64 => @import("x86_64.zig"),
6 else => @compileError("unsupported arch"),
7};
8pub use @import("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;
30pub const MAP_NORESERVE = 0;
31
32pub const MAP_GUARD = 0x00002000;
33pub const MAP_EXCL = 0x00004000;
34pub const MAP_NOCORE = 0x00020000;
35pub const MAP_PREFAULT_READ = 0x00040000;
36pub const MAP_32BIT = 0x00080000;
37
38pub const WNOHANG = 1;
39pub const WUNTRACED = 2;
40pub const WSTOPPED = WUNTRACED;
41pub const WCONTINUED = 4;
42pub const WNOWAIT = 8;
43pub const WEXITED = 16;
44pub const WTRAPPED = 32;
45
46pub const SA_ONSTACK = 0x0001;
47pub const SA_RESTART = 0x0002;
48pub const SA_RESETHAND = 0x0004;
49pub const SA_NOCLDSTOP = 0x0008;
50pub const SA_NODEFER = 0x0010;
51pub const SA_NOCLDWAIT = 0x0020;
52pub const SA_SIGINFO = 0x0040;
53
54pub const SIGHUP = 1;
55pub const SIGINT = 2;
56pub const SIGQUIT = 3;
57pub const SIGILL = 4;
58pub const SIGTRAP = 5;
59pub const SIGABRT = 6;
60pub const SIGIOT = SIGABRT;
61pub const SIGEMT = 7;
62pub const SIGFPE = 8;
63pub const SIGKILL = 9;
64pub const SIGBUS = 10;
65pub const SIGSEGV = 11;
66pub const SIGSYS = 12;
67pub const SIGPIPE = 13;
68pub const SIGALRM = 14;
69pub const SIGTERM = 15;
70pub const SIGURG = 16;
71pub const SIGSTOP = 17;
72pub const SIGTSTP = 18;
73pub const SIGCONT = 19;
74pub const SIGCHLD = 20;
75pub const SIGTTIN = 21;
76pub const SIGTTOU = 22;
77pub const SIGIO = 23;
78pub const SIGXCPU = 24;
79pub const SIGXFSZ = 25;
80pub const SIGVTALRM = 26;
81pub const SIGPROF = 27;
82pub const SIGWINCH = 28;
83pub const SIGINFO = 29;
84pub const SIGUSR1 = 30;
85pub const SIGUSR2 = 31;
86pub const SIGTHR = 32;
87pub const SIGLWP = SIGTHR;
88pub const SIGLIBRT = 33;
89
90pub const SIGRTMIN = 65;
91pub const SIGRTMAX = 126;
92
93pub const O_RDONLY = 0o0;
94pub const O_WRONLY = 0o1;
95pub const O_RDWR = 0o2;
96pub const O_ACCMODE = 0o3;
97
98pub const O_CREAT = arch.O_CREAT;
99pub const O_EXCL = arch.O_EXCL;
100pub const O_NOCTTY = arch.O_NOCTTY;
101pub const O_TRUNC = arch.O_TRUNC;
102pub const O_APPEND = arch.O_APPEND;
103pub const O_NONBLOCK = arch.O_NONBLOCK;
104pub const O_DSYNC = arch.O_DSYNC;
105pub const O_SYNC = arch.O_SYNC;
106pub const O_RSYNC = arch.O_RSYNC;
107pub const O_DIRECTORY = arch.O_DIRECTORY;
108pub const O_NOFOLLOW = arch.O_NOFOLLOW;
109pub const O_CLOEXEC = arch.O_CLOEXEC;
110
111pub const O_ASYNC = arch.O_ASYNC;
112pub const O_DIRECT = arch.O_DIRECT;
113pub const O_LARGEFILE = arch.O_LARGEFILE;
114pub const O_NOATIME = arch.O_NOATIME;
115pub const O_PATH = arch.O_PATH;
116pub const O_TMPFILE = arch.O_TMPFILE;
117pub const O_NDELAY = arch.O_NDELAY;
118
119pub const SEEK_SET = 0;
120pub const SEEK_CUR = 1;
121pub const SEEK_END = 2;
122
123pub const SIG_BLOCK = 1;
124pub const SIG_UNBLOCK = 2;
125pub const SIG_SETMASK = 3;
126
127pub const SOCK_STREAM = 1;
128pub const SOCK_DGRAM = 2;
129pub const SOCK_RAW = 3;
130pub const SOCK_RDM = 4;
131pub const SOCK_SEQPACKET = 5;
132
133pub const SOCK_CLOEXEC = 0x10000000;
134pub const SOCK_NONBLOCK = 0x20000000;
135
136// TODO: From here
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
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 {
333 return @bitCast(u32, s);
334}
335fn signed(s: u32) i32 {
336 return @bitCast(i32, s);
337}
338pub fn WEXITSTATUS(s: i32) i32 {
339 return signed((unsigned(s) & 0xff00) >> 8);
340}
341pub fn WTERMSIG(s: i32) i32 {
342 return signed(unsigned(s) & 0x7f);
343}
344pub fn WSTOPSIG(s: i32) i32 {
345 return WEXITSTATUS(s);
346}
347pub fn WIFEXITED(s: i32) bool {
348 return WTERMSIG(s) == 0;
349}
350pub fn WIFSTOPPED(s: i32) bool {
351 return @intCast(u16, ((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
352}
353pub fn WIFSIGNALED(s: i32) bool {
354 return (unsigned(s) & 0xffff) -% 1 < 0xff;
355}
356
357pub const winsize = extern struct {
358 ws_row: u16,
359 ws_col: u16,
360 ws_xpixel: u16,
361 ws_ypixel: u16,
362};
363
364/// Get the errno from a syscall return value, or 0 for no error.
365pub fn getErrno(r: usize) usize {
366 const signed_r = @bitCast(isize, r);
367 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
368}
369
370pub fn dup2(old: i32, new: i32) usize {
371 return arch.syscall2(arch.SYS_dup2, @intCast(usize, old), @intCast(usize, new));
372}
373
374pub fn chdir(path: [*]const u8) usize {
375 return arch.syscall1(arch.SYS_chdir, @ptrToInt(path));
376}
377
378pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
379 return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
380}
381
382pub fn fork() usize {
383 return arch.syscall0(arch.SYS_fork);
384}
385
386pub fn getcwd(buf: [*]u8, size: usize) usize {
387 return arch.syscall2(arch.SYS___getcwd, @ptrToInt(buf), size);
388}
389
390pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
391 return arch.syscall3(arch.SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count);
392}
393
394pub fn isatty(fd: i32) bool {
395 var wsz: winsize = undefined;
396 return arch.syscall3(arch.SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
397}
398
399pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
400 return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
401}
402
403pub fn mkdir(path: [*]const u8, mode: u32) usize {
404 return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode);
405}
406
407pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {
408 return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset));
409}
410
411pub fn munmap(address: usize, length: usize) usize {
412 return arch.syscall2(arch.SYS_munmap, address, length);
413}
414
415pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
416 return arch.syscall3(arch.SYS_read, @intCast(usize, fd), @ptrToInt(buf), count);
417}
418
419pub fn rmdir(path: [*]const u8) usize {
420 return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path));
421}
422
423pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
424 return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
425}
426
427pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
428 return arch.syscall4(arch.SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset);
429}
430
431pub fn pipe(fd: *[2]i32) usize {
432 return pipe2(fd, 0);
433}
434
435pub fn pipe2(fd: *[2]i32, flags: usize) usize {
436 return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags);
437}
438
439pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
440 return arch.syscall3(arch.SYS_write, @intCast(usize, fd), @ptrToInt(buf), count);
441}
442
443pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
444 return arch.syscall4(arch.SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset);
445}
446
447pub fn rename(old: [*]const u8, new: [*]const u8) usize {
448 return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new));
449}
450
451pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
452 return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm);
453}
454
455pub fn create(path: [*]const u8, perm: usize) usize {
456 return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm);
457}
458
459pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
460 return arch.syscall4(arch.SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode);
461}
462
463pub fn close(fd: i32) usize {
464 return arch.syscall1(arch.SYS_close, @intCast(usize, fd));
465}
466
467pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {
468 return arch.syscall3(arch.SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos);
469}
470
471pub fn exit(status: i32) noreturn {
472 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
473 unreachable;
474}
475
476pub fn getrandom(buf: &u8, count: usize, flags: u32) usize {
477 return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, @bitCast(usize, flags));
478}
479
480pub fn kill(pid: i32, sig: i32) usize {
481 return arch.syscall2(arch.SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig));
482}
483
484pub fn unlink(path: [*]const u8) usize {
485 return arch.syscall1(arch.SYS_unlink, @ptrToInt(path));
486}
487
488pub fn waitpid(pid: i32, status: *i32, options: i32) usize {
489 return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
490}
491
492pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
493 return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
494}
495
496pub fn setuid(uid: u32) usize {
497 return arch.syscall1(arch.SYS_setuid, uid);
498}
499
500pub fn setgid(gid: u32) usize {
501 return arch.syscall1(arch.SYS_setgid, gid);
502}
503
504pub fn setreuid(ruid: u32, euid: u32) usize {
505 return arch.syscall2(arch.SYS_setreuid, ruid, euid);
506}
507
508pub fn setregid(rgid: u32, egid: u32) usize {
509 return arch.syscall2(arch.SYS_setregid, rgid, egid);
510}
511
512pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
513 // TODO: Implement
514 return 0;
515}
516
517pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
518 // TODO: Implement
519 return 0;
520}
521
522const NSIG = 65;
523const sigset_t = [128 / @sizeOf(usize)]usize;
524const all_mask = []usize{@maxValue(usize)};
525const app_mask = []usize{0xfffffffc7fffffff};
526
527/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
528pub const Sigaction = struct {
529 // TODO: Adjust to use freebsd struct layout
530 handler: extern fn (i32) void,
531 mask: sigset_t,
532 flags: u32,
533};
534
535pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize));
536pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
537pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
538pub const empty_sigset = []usize{0} ** sigset_t.len;
539
540pub fn raise(sig: i32) usize {
541 // TODO implement, see linux equivalent for what we want to try and do
542 return 0;
543}
544
545fn blockAllSignals(set: *sigset_t) void {
546 // TODO implement
547}
548
549fn blockAppSignals(set: *sigset_t) void {
550 // TODO implement
551}
552
553fn restoreSignals(set: *sigset_t) void {
554 // TODO implement
555}
556
557pub fn sigaddset(set: *sigset_t, sig: u6) void {
558 const s = sig - 1;
559 (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
560}
561
562pub fn sigismember(set: *const sigset_t, sig: u6) bool {
563 const s = sig - 1;
564 return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
565}
566
567pub const Stat = arch.Stat;
568pub const timespec = arch.timespec;
569
570pub fn fstat(fd: i32, stat_buf: *Stat) usize {
571 return arch.syscall2(arch.SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf));
572}
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/index.zig created+571
......@@ -0,0 +1,571 @@
1const assert = @import("../debug.zig").assert;
2const builtin = @import("builtin");
3const arch = switch (builtin.arch) {
4 builtin.Arch.x86_64 => @import("x86_64.zig"),
5 else => @compileError("unsupported arch"),
6};
7pub use @import("errno.zig");
8
9pub const PATH_MAX = 1024;
10
11pub const STDIN_FILENO = 0;
12pub const STDOUT_FILENO = 1;
13pub const STDERR_FILENO = 2;
14
15pub const PROT_NONE = 0;
16pub const PROT_READ = 1;
17pub const PROT_WRITE = 2;
18pub const PROT_EXEC = 4;
19
20pub const MAP_FAILED = @maxValue(usize);
21pub const MAP_SHARED = 0x0001;
22pub const MAP_PRIVATE = 0x0002;
23pub const MAP_FIXED = 0x0010;
24pub const MAP_STACK = 0x0400;
25pub const MAP_NOSYNC = 0x0800;
26pub const MAP_ANON = 0x1000;
27pub const MAP_ANONYMOUS = MAP_ANON;
28pub const MAP_FILE = 0;
29pub const MAP_NORESERVE = 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
275pub const TCGETS = 0x5401;
276pub const TCSETS = 0x5402;
277pub const TCSETSW = 0x5403;
278pub const TCSETSF = 0x5404;
279pub const TCGETA = 0x5405;
280pub const TCSETA = 0x5406;
281pub const TCSETAW = 0x5407;
282pub const TCSETAF = 0x5408;
283pub const TCSBRK = 0x5409;
284pub const TCXONC = 0x540A;
285pub const TCFLSH = 0x540B;
286pub const TIOCEXCL = 0x540C;
287pub const TIOCNXCL = 0x540D;
288pub const TIOCSCTTY = 0x540E;
289pub const TIOCGPGRP = 0x540F;
290pub const TIOCSPGRP = 0x5410;
291pub const TIOCOUTQ = 0x5411;
292pub const TIOCSTI = 0x5412;
293pub const TIOCGWINSZ = 0x5413;
294pub const TIOCSWINSZ = 0x5414;
295pub const TIOCMGET = 0x5415;
296pub const TIOCMBIS = 0x5416;
297pub const TIOCMBIC = 0x5417;
298pub const TIOCMSET = 0x5418;
299pub const TIOCGSOFTCAR = 0x5419;
300pub const TIOCSSOFTCAR = 0x541A;
301pub const FIONREAD = 0x541B;
302pub const TIOCINQ = FIONREAD;
303pub const TIOCLINUX = 0x541C;
304pub const TIOCCONS = 0x541D;
305pub const TIOCGSERIAL = 0x541E;
306pub const TIOCSSERIAL = 0x541F;
307pub const TIOCPKT = 0x5420;
308pub const FIONBIO = 0x5421;
309pub const TIOCNOTTY = 0x5422;
310pub const TIOCSETD = 0x5423;
311pub const TIOCGETD = 0x5424;
312pub const TCSBRKP = 0x5425;
313pub const TIOCSBRK = 0x5427;
314pub const TIOCCBRK = 0x5428;
315pub const TIOCGSID = 0x5429;
316pub const TIOCGRS485 = 0x542E;
317pub const TIOCSRS485 = 0x542F;
318pub const TIOCGPTN = 0x80045430;
319pub const TIOCSPTLCK = 0x40045431;
320pub const TIOCGDEV = 0x80045432;
321pub const TCGETX = 0x5432;
322pub const TCSETX = 0x5433;
323pub const TCSETXF = 0x5434;
324pub const TCSETXW = 0x5435;
325pub const TIOCSIG = 0x40045436;
326pub const TIOCVHANGUP = 0x5437;
327pub const TIOCGPKT = 0x80045438;
328pub const TIOCGPTLCK = 0x80045439;
329pub const TIOCGEXCL = 0x80045440;
330
331fn unsigned(s: i32) u32 {
332 return @bitCast(u32, s);
333}
334fn signed(s: u32) i32 {
335 return @bitCast(i32, s);
336}
337pub fn WEXITSTATUS(s: i32) i32 {
338 return signed((unsigned(s) & 0xff00) >> 8);
339}
340pub fn WTERMSIG(s: i32) i32 {
341 return signed(unsigned(s) & 0x7f);
342}
343pub fn WSTOPSIG(s: i32) i32 {
344 return WEXITSTATUS(s);
345}
346pub fn WIFEXITED(s: i32) bool {
347 return WTERMSIG(s) == 0;
348}
349pub fn WIFSTOPPED(s: i32) bool {
350 return @intCast(u16, (((unsigned(s) & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
351}
352pub fn WIFSIGNALED(s: i32) bool {
353 return (unsigned(s) & 0xffff) -% 1 < 0xff;
354}
355
356pub const winsize = extern struct.{
357 ws_row: u16,
358 ws_col: u16,
359 ws_xpixel: u16,
360 ws_ypixel: u16,
361};
362
363/// Get the errno from a syscall return value, or 0 for no error.
364pub fn getErrno(r: usize) usize {
365 const signed_r = @bitCast(isize, r);
366 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
367}
368
369pub fn dup2(old: i32, new: i32) usize {
370 return arch.syscall2(arch.SYS_dup2, @intCast(usize, old), @intCast(usize, new));
371}
372
373pub fn chdir(path: [*]const u8) usize {
374 return arch.syscall1(arch.SYS_chdir, @ptrToInt(path));
375}
376
377pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
378 return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
379}
380
381pub fn fork() usize {
382 return arch.syscall0(arch.SYS_fork);
383}
384
385pub fn getcwd(buf: [*]u8, size: usize) usize {
386 return arch.syscall2(arch.SYS___getcwd, @ptrToInt(buf), size);
387}
388
389pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
390 return arch.syscall3(arch.SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count);
391}
392
393pub fn isatty(fd: i32) bool {
394 var wsz: winsize = undefined;
395 return arch.syscall3(arch.SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
396}
397
398pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
399 return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
400}
401
402pub fn mkdir(path: [*]const u8, mode: u32) usize {
403 return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode);
404}
405
406pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {
407 return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset));
408}
409
410pub fn munmap(address: usize, length: usize) usize {
411 return arch.syscall2(arch.SYS_munmap, address, length);
412}
413
414pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
415 return arch.syscall3(arch.SYS_read, @intCast(usize, fd), @ptrToInt(buf), count);
416}
417
418pub fn rmdir(path: [*]const u8) usize {
419 return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path));
420}
421
422pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
423 return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
424}
425
426pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
427 return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
428}
429
430pub fn pipe(fd: *[2]i32) usize {
431 return pipe2(fd, 0);
432}
433
434pub fn pipe2(fd: *[2]i32, flags: usize) usize {
435 return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags);
436}
437
438pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
439 return arch.syscall3(arch.SYS_write, @intCast(usize, fd), @ptrToInt(buf), count);
440}
441
442pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
443 return arch.syscall4(arch.SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset);
444}
445
446pub fn rename(old: [*]const u8, new: [*]const u8) usize {
447 return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new));
448}
449
450pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
451 return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm);
452}
453
454pub fn create(path: [*]const u8, perm: usize) usize {
455 return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm);
456}
457
458pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
459 return arch.syscall4(arch.SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode);
460}
461
462pub fn close(fd: i32) usize {
463 return arch.syscall1(arch.SYS_close, @intCast(usize, fd));
464}
465
466pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {
467 return arch.syscall3(arch.SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos);
468}
469
470pub fn exit(status: i32) noreturn {
471 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
472 unreachable;
473}
474
475pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
476 return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags));
477}
478
479pub fn kill(pid: i32, sig: i32) usize {
480 return arch.syscall2(arch.SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig));
481}
482
483pub fn unlink(path: [*]const u8) usize {
484 return arch.syscall1(arch.SYS_unlink, @ptrToInt(path));
485}
486
487pub fn waitpid(pid: i32, status: *i32, options: i32) usize {
488 return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
489}
490
491pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
492 return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
493}
494
495pub fn setuid(uid: u32) usize {
496 return arch.syscall1(arch.SYS_setuid, uid);
497}
498
499pub fn setgid(gid: u32) usize {
500 return arch.syscall1(arch.SYS_setgid, gid);
501}
502
503pub fn setreuid(ruid: u32, euid: u32) usize {
504 return arch.syscall2(arch.SYS_setreuid, ruid, euid);
505}
506
507pub fn setregid(rgid: u32, egid: u32) usize {
508 return arch.syscall2(arch.SYS_setregid, rgid, egid);
509}
510
511pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
512 // TODO: Implement
513 return 0;
514}
515
516pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
517 // TODO: Implement
518 return 0;
519}
520
521const NSIG = 65;
522const sigset_t = [128 / @sizeOf(usize)]usize;
523const all_mask = []usize.{@maxValue(usize)};
524const app_mask = []usize.{0xfffffffc7fffffff};
525
526/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
527pub const Sigaction = struct.{
528 // TODO: Adjust to use freebsd struct layout
529 handler: extern fn (i32) void,
530 mask: sigset_t,
531 flags: u32,
532};
533
534pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize));
535pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
536pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
537pub const empty_sigset = []usize.{0} ** sigset_t.len;
538
539pub fn raise(sig: i32) usize {
540 // TODO implement, see linux equivalent for what we want to try and do
541 return 0;
542}
543
544fn blockAllSignals(set: *sigset_t) void {
545 // TODO implement
546}
547
548fn blockAppSignals(set: *sigset_t) void {
549 // TODO implement
550}
551
552fn restoreSignals(set: *sigset_t) void {
553 // TODO implement
554}
555
556pub fn sigaddset(set: *sigset_t, sig: u6) void {
557 const s = sig - 1;
558 (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
559}
560
561pub fn sigismember(set: *const sigset_t, sig: u6) bool {
562 const s = sig - 1;
563 return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
564}
565
566pub const Stat = arch.Stat;
567pub const timespec = arch.timespec;
568
569pub fn fstat(fd: i32, stat_buf: *Stat) usize {
570 return arch.syscall2(arch.SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf));
571}
std/os/freebsd/x86_64.zig created+651
......@@ -0,0 +1,651 @@
1const freebsd = @import("index.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;
479pub const SYS_getrandom = 563;
480
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 = 0;
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 = 5;
514pub const F_SETLK = 6;
515pub const F_SETLKW = 7;
516
517pub const F_SETOWN_EX = 15;
518pub const F_GETOWN_EX = 16;
519
520pub const F_GETOWNER_UIDS = 17;
521
522pub fn syscall0(number: usize) usize {
523 return asm volatile ("syscall"
524 : [ret] "={rax}" (-> usize)
525 : [number] "{rax}" (number)
526 : "rcx", "r11"
527 );
528}
529
530pub fn syscall1(number: usize, arg1: usize) usize {
531 return asm volatile ("syscall"
532 : [ret] "={rax}" (-> usize)
533 : [number] "{rax}" (number),
534 [arg1] "{rdi}" (arg1)
535 : "rcx", "r11"
536 );
537}
538
539pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
540 return asm volatile ("syscall"
541 : [ret] "={rax}" (-> usize)
542 : [number] "{rax}" (number),
543 [arg1] "{rdi}" (arg1),
544 [arg2] "{rsi}" (arg2)
545 : "rcx", "r11"
546 );
547}
548
549pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
550 return asm volatile ("syscall"
551 : [ret] "={rax}" (-> usize)
552 : [number] "{rax}" (number),
553 [arg1] "{rdi}" (arg1),
554 [arg2] "{rsi}" (arg2),
555 [arg3] "{rdx}" (arg3)
556 : "rcx", "r11"
557 );
558}
559
560pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
561 return asm volatile ("syscall"
562 : [ret] "={rax}" (-> usize)
563 : [number] "{rax}" (number),
564 [arg1] "{rdi}" (arg1),
565 [arg2] "{rsi}" (arg2),
566 [arg3] "{rdx}" (arg3),
567 [arg4] "{r10}" (arg4)
568 : "rcx", "r11"
569 );
570}
571
572pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
573 return asm volatile ("syscall"
574 : [ret] "={rax}" (-> usize)
575 : [number] "{rax}" (number),
576 [arg1] "{rdi}" (arg1),
577 [arg2] "{rsi}" (arg2),
578 [arg3] "{rdx}" (arg3),
579 [arg4] "{r10}" (arg4),
580 [arg5] "{r8}" (arg5)
581 : "rcx", "r11"
582 );
583}
584
585pub fn syscall6(
586 number: usize,
587 arg1: usize,
588 arg2: usize,
589 arg3: usize,
590 arg4: usize,
591 arg5: usize,
592 arg6: usize,
593) usize {
594 return asm volatile ("syscall"
595 : [ret] "={rax}" (-> usize)
596 : [number] "{rax}" (number),
597 [arg1] "{rdi}" (arg1),
598 [arg2] "{rsi}" (arg2),
599 [arg3] "{rdx}" (arg3),
600 [arg4] "{r10}" (arg4),
601 [arg5] "{r8}" (arg5),
602 [arg6] "{r9}" (arg6)
603 : "rcx", "r11"
604 );
605}
606
607pub nakedcc fn restore_rt() void {
608 asm volatile ("syscall"
609 :
610 : [number] "{rax}" (usize(SYS_rt_sigreturn))
611 : "rcx", "r11"
612 );
613}
614
615pub const msghdr = extern struct.{
616 msg_name: &u8,
617 msg_namelen: socklen_t,
618 msg_iov: &iovec,
619 msg_iovlen: i32,
620 __pad1: i32,
621 msg_control: &u8,
622 msg_controllen: socklen_t,
623 __pad2: socklen_t,
624 msg_flags: i32,
625};
626
627/// Renamed to Stat to not conflict with the stat function.
628pub const Stat = extern struct.{
629 dev: u64,
630 ino: u64,
631 nlink: usize,
632
633 mode: u32,
634 uid: u32,
635 gid: u32,
636 __pad0: u32,
637 rdev: u64,
638 size: i64,
639 blksize: isize,
640 blocks: i64,
641
642 atim: timespec,
643 mtim: timespec,
644 ctim: timespec,
645 __unused: [3]isize,
646};
647
648pub const timespec = extern struct.{
649 tv_sec: isize,
650 tv_nsec: isize,
651};
std/os/freebsd_errno.zig deleted-121
......@@ -1,121 +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; // 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 deleted-614
......@@ -1,614 +0,0 @@
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 deleted-650
......@@ -1,650 +0,0 @@
1const freebsd = @import("index.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 return asm volatile ("syscall"
523 : [ret] "={rax}" (-> usize)
524 : [number] "{rax}" (number)
525 : "rcx", "r11"
526 );
527}
528
529pub fn syscall1(number: usize, arg1: usize) usize {
530 return asm volatile ("syscall"
531 : [ret] "={rax}" (-> usize)
532 : [number] "{rax}" (number),
533 [arg1] "{rdi}" (arg1)
534 : "rcx", "r11"
535 );
536}
537
538pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
539 return asm volatile ("syscall"
540 : [ret] "={rax}" (-> usize)
541 : [number] "{rax}" (number),
542 [arg1] "{rdi}" (arg1),
543 [arg2] "{rsi}" (arg2)
544 : "rcx", "r11"
545 );
546}
547
548pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
549 return asm volatile ("syscall"
550 : [ret] "={rax}" (-> usize)
551 : [number] "{rax}" (number),
552 [arg1] "{rdi}" (arg1),
553 [arg2] "{rsi}" (arg2),
554 [arg3] "{rdx}" (arg3)
555 : "rcx", "r11"
556 );
557}
558
559pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
560 return asm volatile ("syscall"
561 : [ret] "={rax}" (-> usize)
562 : [number] "{rax}" (number),
563 [arg1] "{rdi}" (arg1),
564 [arg2] "{rsi}" (arg2),
565 [arg3] "{rdx}" (arg3),
566 [arg4] "{r10}" (arg4)
567 : "rcx", "r11"
568 );
569}
570
571pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
572 return asm volatile ("syscall"
573 : [ret] "={rax}" (-> usize)
574 : [number] "{rax}" (number),
575 [arg1] "{rdi}" (arg1),
576 [arg2] "{rsi}" (arg2),
577 [arg3] "{rdx}" (arg3),
578 [arg4] "{r10}" (arg4),
579 [arg5] "{r8}" (arg5)
580 : "rcx", "r11"
581 );
582}
583
584pub fn syscall6(
585 number: usize,
586 arg1: usize,
587 arg2: usize,
588 arg3: usize,
589 arg4: usize,
590 arg5: usize,
591 arg6: usize,
592) usize {
593 return asm volatile ("syscall"
594 : [ret] "={rax}" (-> usize)
595 : [number] "{rax}" (number),
596 [arg1] "{rdi}" (arg1),
597 [arg2] "{rsi}" (arg2),
598 [arg3] "{rdx}" (arg3),
599 [arg4] "{r10}" (arg4),
600 [arg5] "{r8}" (arg5),
601 [arg6] "{r9}" (arg6)
602 : "rcx", "r11"
603 );
604}
605
606pub nakedcc fn restore_rt() void {
607 asm volatile ("syscall"
608 :
609 : [number] "{rax}" (usize(SYS_rt_sigreturn))
610 : "rcx", "r11"
611 );
612}
613
614pub const msghdr = extern struct {
615 msg_name: &u8,
616 msg_namelen: socklen_t,
617 msg_iov: &iovec,
618 msg_iovlen: i32,
619 __pad1: i32,
620 msg_control: &u8,
621 msg_controllen: socklen_t,
622 __pad2: socklen_t,
623 msg_flags: i32,
624};
625
626/// Renamed to Stat to not conflict with the stat function.
627pub const Stat = extern struct {
628 dev: u64,
629 ino: u64,
630 nlink: usize,
631
632 mode: u32,
633 uid: u32,
634 gid: u32,
635 __pad0: u32,
636 rdev: u64,
637 size: i64,
638 blksize: isize,
639 blocks: i64,
640
641 atim: timespec,
642 mtim: timespec,
643 ctim: timespec,
644 __unused: [3]isize,
645};
646
647pub const timespec = extern struct {
648 tv_sec: isize,
649 tv_nsec: isize,
650};