authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-07-09 20:54:36+12:00
committergravatar for greg@unrelenting.technologyGreg V <greg@unrelenting.technology> 2018-10-20 15:15:01+03:00
log102cb61e401ba2266938882d8a7d751a31a49ab2
tree6b5f2c66df1b69ee9c4d83cc44404318be91d162
parent264dd2eb579e78471c639baf698f7665ea016349

Get freebsd std compiling again


4 files changed, 366 insertions(+), 514 deletions(-)

std/os/freebsd.zig+187-348
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1const c = @import("../c/index.zig");
1const assert = @import("../debug.zig").assert;2const assert = @import("../debug.zig").assert;
2const builtin = @import("builtin");3const builtin = @import("builtin");
3const arch = switch (builtin.arch) {4const arch = switch (builtin.arch) {
4 builtin.Arch.x86_64 => @import("freebsd_x86_64.zig"),5 builtin.Arch.x86_64 => @import("x86_64.zig"),
5 builtin.Arch.i386 => @import("freebsd_i386.zig"),
6 else => @compileError("unsupported arch"),6 else => @compileError("unsupported arch"),
7};7};
8pub use @import("freebsd_errno.zig");8pub use @import("errno.zig");
99
10pub const PATH_MAX = 1024;10pub const PATH_MAX = 1024;
1111
...@@ -13,85 +13,86 @@ pub const STDIN_FILENO = 0;...@@ -13,85 +13,86 @@ pub const STDIN_FILENO = 0;
13pub const STDOUT_FILENO = 1;13pub const STDOUT_FILENO = 1;
14pub const STDERR_FILENO = 2;14pub const STDERR_FILENO = 2;
1515
16pub const PROT_NONE = 0;16pub const PROT_NONE = 0;
17pub const PROT_READ = 1;17pub const PROT_READ = 1;
18pub const PROT_WRITE = 2;18pub const PROT_WRITE = 2;
19pub const PROT_EXEC = 4;19pub const PROT_EXEC = 4;
2020
21pub const MAP_FAILED = @maxValue(usize);21pub const MAP_FAILED = @maxValue(usize);
22pub const MAP_SHARED = 0x0001;22pub const MAP_SHARED = 0x0001;
23pub const MAP_PRIVATE = 0x0002;23pub const MAP_PRIVATE = 0x0002;
24pub const MAP_FIXED = 0x0010;24pub const MAP_FIXED = 0x0010;
25pub const MAP_STACK = 0x0400;25pub const MAP_STACK = 0x0400;
26pub const MAP_NOSYNC = 0x0800;26pub const MAP_NOSYNC = 0x0800;
27pub const MAP_ANON = 0x1000;27pub const MAP_ANON = 0x1000;
28pub const MAP_ANONYMOUS = MAP_ANON;28pub const MAP_ANONYMOUS = MAP_ANON;
29pub const MAP_FILE = 0;29pub const MAP_FILE = 0;
3030pub const MAP_NORESERVE = 0;
31pub const MAP_GUARD = 0x00002000;31
32pub const MAP_EXCL = 0x00004000;32pub const MAP_GUARD = 0x00002000;
33pub const MAP_NOCORE = 0x00020000;33pub const MAP_EXCL = 0x00004000;
34pub const MAP_NOCORE = 0x00020000;
34pub const MAP_PREFAULT_READ = 0x00040000;35pub const MAP_PREFAULT_READ = 0x00040000;
35pub const MAP_32BIT = 0x00080000;36pub const MAP_32BIT = 0x00080000;
3637
37pub const WNOHANG = 1;38pub const WNOHANG = 1;
38pub const WUNTRACED = 2;39pub const WUNTRACED = 2;
39pub const WSTOPPED = WUNTRACED;40pub const WSTOPPED = WUNTRACED;
40pub const WCONTINUED = 4;41pub const WCONTINUED = 4;
41pub const WNOWAIT = 8;42pub const WNOWAIT = 8;
42pub const WEXITED = 16;43pub const WEXITED = 16;
43pub const WTRAPPED = 32;44pub const WTRAPPED = 32;
4445
45pub const SA_ONSTACK = 0x0001;46pub const SA_ONSTACK = 0x0001;
46pub const SA_RESTART = 0x0002;47pub const SA_RESTART = 0x0002;
47pub const SA_RESETHAND = 0x0004;48pub const SA_RESETHAND = 0x0004;
48pub const SA_NOCLDSTOP = 0x0008;49pub const SA_NOCLDSTOP = 0x0008;
49pub const SA_NODEFER = 0x0010;50pub const SA_NODEFER = 0x0010;
50pub const SA_NOCLDWAIT = 0x0020;51pub const SA_NOCLDWAIT = 0x0020;
51pub const SA_SIGINFO = 0x0040;52pub const SA_SIGINFO = 0x0040;
5253
53pub const SIGHUP = 1;54pub const SIGHUP = 1;
54pub const SIGINT = 2;55pub const SIGINT = 2;
55pub const SIGQUIT = 3;56pub const SIGQUIT = 3;
56pub const SIGILL = 4;57pub const SIGILL = 4;
57pub const SIGTRAP = 5;58pub const SIGTRAP = 5;
58pub const SIGABRT = 6;59pub const SIGABRT = 6;
59pub const SIGIOT = SIGABRT;60pub const SIGIOT = SIGABRT;
60pub const SIGEMT = 7;61pub const SIGEMT = 7;
61pub const SIGFPE = 8;62pub const SIGFPE = 8;
62pub const SIGKILL = 9;63pub const SIGKILL = 9;
63pub const SIGBUS = 10;64pub const SIGBUS = 10;
64pub const SIGSEGV = 11;65pub const SIGSEGV = 11;
65pub const SIGSYS = 12;66pub const SIGSYS = 12;
66pub const SIGPIPE = 13;67pub const SIGPIPE = 13;
67pub const SIGALRM = 14;68pub const SIGALRM = 14;
68pub const SIGTERM = 15;69pub const SIGTERM = 15;
69pub const SIGURG = 16;70pub const SIGURG = 16;
70pub const SIGSTOP = 17;71pub const SIGSTOP = 17;
71pub const SIGTSTP = 18;72pub const SIGTSTP = 18;
72pub const SIGCONT = 19;73pub const SIGCONT = 19;
73pub const SIGCHLD = 20;74pub const SIGCHLD = 20;
74pub const SIGTTIN = 21;75pub const SIGTTIN = 21;
75pub const SIGTTOU = 22;76pub const SIGTTOU = 22;
76pub const SIGIO = 23;77pub const SIGIO = 23;
77pub const SIGXCPU = 24;78pub const SIGXCPU = 24;
78pub const SIGXFSZ = 25;79pub const SIGXFSZ = 25;
79pub const SIGVTALRM = 26;80pub const SIGVTALRM = 26;
80pub const SIGPROF = 27;81pub const SIGPROF = 27;
81pub const SIGWINCH = 28;82pub const SIGWINCH = 28;
82pub const SIGINFO = 29;83pub const SIGINFO = 29;
83pub const SIGUSR1 = 30;84pub const SIGUSR1 = 30;
84pub const SIGUSR2 = 31;85pub const SIGUSR2 = 31;
85pub const SIGTHR = 32;86pub const SIGTHR = 32;
86pub const SIGLWP = SIGTHR;87pub const SIGLWP = SIGTHR;
87pub const SIGLIBRT = 33;88pub const SIGLIBRT = 33;
8889
89pub const SIGRTMIN = 65;90pub const SIGRTMIN = 65;
90pub const SIGRTMAX = 126;91pub const SIGRTMAX = 126;
9192
92pub const O_RDONLY = 0o0;93pub const O_RDONLY = 0o0;
93pub const O_WRONLY = 0o1;94pub const O_WRONLY = 0o1;
94pub const O_RDWR = 0o2;95pub const O_RDWR = 0o2;
95pub const O_ACCMODE = 0o3;96pub const O_ACCMODE = 0o3;
9697
97pub const O_CREAT = arch.O_CREAT;98pub const O_CREAT = arch.O_CREAT;
...@@ -119,7 +120,7 @@ pub const SEEK_SET = 0;...@@ -119,7 +120,7 @@ pub const SEEK_SET = 0;
119pub const SEEK_CUR = 1;120pub const SEEK_CUR = 1;
120pub const SEEK_END = 2;121pub const SEEK_END = 2;
121122
122pub const SIG_BLOCK = 1;123pub const SIG_BLOCK = 1;
123pub const SIG_UNBLOCK = 2;124pub const SIG_UNBLOCK = 2;
124pub const SIG_SETMASK = 3;125pub const SIG_SETMASK = 3;
125126
...@@ -272,7 +273,6 @@ pub const DT_LNK = 10;...@@ -272,7 +273,6 @@ pub const DT_LNK = 10;
272pub const DT_SOCK = 12;273pub const DT_SOCK = 12;
273pub const DT_WHT = 14;274pub const DT_WHT = 14;
274275
275
276pub const TCGETS = 0x5401;276pub const TCGETS = 0x5401;
277pub const TCSETS = 0x5402;277pub const TCSETS = 0x5402;
278pub const TCSETSW = 0x5403;278pub const TCSETSW = 0x5403;
...@@ -329,15 +329,30 @@ pub const TIOCGPKT = 0x80045438;...@@ -329,15 +329,30 @@ pub const TIOCGPKT = 0x80045438;
329pub const TIOCGPTLCK = 0x80045439;329pub const TIOCGPTLCK = 0x80045439;
330pub const TIOCGEXCL = 0x80045440;330pub const TIOCGEXCL = 0x80045440;
331331
332fn unsigned(s: i32) -> u32 { @bitCast(u32, s) }332fn unsigned(s: i32) u32 {
333fn signed(s: u32) -> i32 { @bitCast(i32, s) }333 return @bitCast(u32, s);
334pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) }334}
335pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) }335fn signed(s: u32) i32 {
336pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) }336 return @bitCast(i32, s);
337pub fn WIFEXITED(s: i32) -> bool { WTERMSIG(s) == 0 }337}
338pub fn WIFSTOPPED(s: i32) -> bool { (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00 }338pub fn WEXITSTATUS(s: i32) i32 {
339pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff }339 return signed((unsigned(s) & 0xff00) >> 8);
340340}
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 (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
352}
353pub fn WIFSIGNALED(s: i32) bool {
354 return (unsigned(s) & 0xffff) -% 1 < 0xff;
355}
341356
342pub const winsize = extern struct {357pub const winsize = extern struct {
343 ws_row: u16,358 ws_row: u16,
...@@ -347,182 +362,160 @@ pub const winsize = extern struct {...@@ -347,182 +362,160 @@ pub const winsize = extern struct {
347};362};
348363
349/// Get the errno from a syscall return value, or 0 for no error.364/// Get the errno from a syscall return value, or 0 for no error.
350pub fn getErrno(r: usize) -> usize {365pub fn getErrno(r: usize) usize {
351 const signed_r = @bitCast(isize, r);366 const signed_r = @bitCast(isize, r);
352 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0367 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
353}368}
354369
355pub fn dup2(old: i32, new: i32) -> usize {370pub fn dup2(old: i32, new: i32) usize {
356 arch.syscall2(arch.SYS_dup2, usize(old), usize(new))371 return arch.syscall2(arch.SYS_dup2, usize(old), usize(new));
357}372}
358373
359pub fn chdir(path: &const u8) -> usize {374pub fn chdir(path: [*]const u8) usize {
360 arch.syscall1(arch.SYS_chdir, @ptrToInt(path))375 return arch.syscall1(arch.SYS_chdir, @ptrToInt(path));
361}376}
362377
363pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize {378pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize {
364 arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp))379 return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
365}380}
366381
367pub fn fork() -> usize {382pub fn fork() usize {
368 arch.syscall0(arch.SYS_fork)383 return arch.syscall0(arch.SYS_fork);
369}384}
370385
371pub fn getcwd(buf: &u8, size: usize) -> usize {386pub fn getcwd(buf: [*]u8, size: usize) usize {
372 arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size)387 return arch.syscall2(arch.SYS___getcwd, @ptrToInt(buf), size);
373}388}
374389
375pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize {390pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
376 arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count)391 return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count);
377}392}
378393
379pub fn isatty(fd: i32) -> bool {394pub fn isatty(fd: i32) bool {
380 var wsz: winsize = undefined;395 var wsz: winsize = undefined;
381 return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;396 return arch.syscall3(arch.SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
382}397}
383398
384pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {399pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
385 arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len)400 return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
386}401}
387402
388pub fn mkdir(path: &const u8, mode: u32) -> usize {403pub fn mkdir(path: [*]const u8, mode: u32) usize {
389 arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode)404 return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode);
390}405}
391406
392pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize)407pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {
393 -> usize408 return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset));
394{
395 arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
396 @bitCast(usize, offset))
397}409}
398410
399pub fn munmap(address: &u8, length: usize) -> usize {411pub fn munmap(address: usize, length: usize) usize {
400 arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length)412 return arch.syscall2(arch.SYS_munmap, address, length);
401}413}
402414
403pub fn read(fd: i32, buf: &u8, count: usize) -> usize {415pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
404 arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count)416 return arch.syscall3(arch.SYS_read, @intCast(usize, fd), @ptrToInt(buf), count);
405}417}
406418
407pub fn rmdir(path: &const u8) -> usize {419pub fn rmdir(path: [*]const u8) usize {
408 arch.syscall1(arch.SYS_rmdir, @ptrToInt(path))420 return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path));
409}421}
410422
411pub fn symlink(existing: &const u8, new: &const u8) -> usize {423pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
412 arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new))424 return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
413}425}
414426
415pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {427pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
416 arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset)428 return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
417}429}
418430
419pub fn pipe(fd: &[2]i32) -> usize {431pub fn pipe(fd: *[2]i32) usize {
420 pipe2(fd, 0)432 return pipe2(fd, 0);
421}433}
422434
423pub fn pipe2(fd: &[2]i32, flags: usize) -> usize {435pub fn pipe2(fd: *[2]i32, flags: usize) usize {
424 arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags)436 return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags);
425}437}
426438
427pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {439pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
428 arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count)440 return arch.syscall3(arch.SYS_write, @intCast(usize, fd), @ptrToInt(buf), count);
429}441}
430442
431pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {443pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
432 arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset)444 return arch.syscall4(arch.SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset);
433}445}
434446
435pub fn rename(old: &const u8, new: &const u8) -> usize {447pub fn rename(old: [*]const u8, new: [*]const u8) usize {
436 arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new))448 return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new));
437}449}
438450
439pub fn open(path: &const u8, flags: u32, perm: usize) -> usize {451pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
440 arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm)452 return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm);
441}453}
442454
443pub fn create(path: &const u8, perm: usize) -> usize {455pub fn create(path: [*]const u8, perm: usize) usize {
444 arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm)456 return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm);
445}457}
446458
447pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {459pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize {
448 arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode)460 return arch.syscall4(arch.SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode);
449}461}
450462
451pub fn close(fd: i32) -> usize {463pub fn close(fd: i32) usize {
452 arch.syscall1(arch.SYS_close, usize(fd))464 return arch.syscall1(arch.SYS_close, @intCast(usize, fd));
453}465}
454466
455pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize {467pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {
456 arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos)468 return arch.syscall3(arch.SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos);
457}469}
458470
459pub fn exit(status: i32) -> noreturn {471pub fn exit(status: i32) noreturn {
460 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));472 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
461 unreachable473 unreachable;
462}474}
463475
464pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {476pub fn getrandom(buf: &u8, count: usize, flags: u32) usize {
465 arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags))477 return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, @bitCast(usize, flags));
466}478}
467479
468pub fn kill(pid: i32, sig: i32) -> usize {480pub fn kill(pid: i32, sig: i32) usize {
469 arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig))481 return arch.syscall2(arch.SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig));
470}482}
471483
472pub fn unlink(path: &const u8) -> usize {484pub fn unlink(path: [*]const u8) usize {
473 arch.syscall1(arch.SYS_unlink, @ptrToInt(path))485 return arch.syscall1(arch.SYS_unlink, @ptrToInt(path));
474}486}
475487
476pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize {488pub fn waitpid(pid: i32, status: *i32, options: i32) usize {
477 arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0)489 return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
478}490}
479491
480pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {492pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
481 arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem))493 return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
482}494}
483495
484pub fn setuid(uid: u32) -> usize {496pub fn setuid(uid: u32) usize {
485 arch.syscall1(arch.SYS_setuid, uid)497 return arch.syscall1(arch.SYS_setuid, uid);
486}498}
487499
488pub fn setgid(gid: u32) -> usize {500pub fn setgid(gid: u32) usize {
489 arch.syscall1(arch.SYS_setgid, gid)501 return arch.syscall1(arch.SYS_setgid, gid);
490}502}
491503
492pub fn setreuid(ruid: u32, euid: u32) -> usize {504pub fn setreuid(ruid: u32, euid: u32) usize {
493 arch.syscall2(arch.SYS_setreuid, ruid, euid)505 return arch.syscall2(arch.SYS_setreuid, ruid, euid);
494}506}
495507
496pub fn setregid(rgid: u32, egid: u32) -> usize {508pub fn setregid(rgid: u32, egid: u32) usize {
497 arch.syscall2(arch.SYS_setregid, rgid, egid)509 return arch.syscall2(arch.SYS_setregid, rgid, egid);
498}510}
499511
500pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {512pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
501 arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8)513 // TODO: Implement
514 return 0;
502}515}
503516
504pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {517pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
505 assert(sig >= 1);518 // TODO: Implement
506 assert(sig != SIGKILL);
507 assert(sig != SIGSTOP);
508 var ksa = k_sigaction {
509 .handler = act.handler,
510 .flags = act.flags | SA_RESTORER,
511 .mask = undefined,
512 .restorer = @ptrCast(extern fn(), arch.restore_rt),
513 };
514 var ksa_old: k_sigaction = undefined;
515 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
516 const result = arch.syscall4(arch.SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask)));
517 const err = getErrno(result);
518 if (err != 0) {
519 return result;
520 }
521 if (oact) |old| {
522 old.handler = ksa_old.handler;
523 old.flags = @truncate(u32, ksa_old.flags);
524 @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));
525 }
526 return 0;519 return 0;
527}520}
528521
...@@ -531,203 +524,49 @@ const sigset_t = [128 / @sizeOf(usize)]usize;...@@ -531,203 +524,49 @@ const sigset_t = [128 / @sizeOf(usize)]usize;
531const all_mask = []usize{@maxValue(usize)};524const all_mask = []usize{@maxValue(usize)};
532const app_mask = []usize{0xfffffffc7fffffff};525const app_mask = []usize{0xfffffffc7fffffff};
533526
534const k_sigaction = extern struct {
535 handler: extern fn(i32),
536 flags: usize,
537 restorer: extern fn(),
538 mask: [2]u32,
539};
540
541/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.527/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
542pub const Sigaction = struct {528pub const Sigaction = struct {
543 handler: extern fn(i32),529 // TODO: Adjust to use freebsd struct layout
530 handler: extern fn (i32) void,
544 mask: sigset_t,531 mask: sigset_t,
545 flags: u32,532 flags: u32,
546};533};
547534
548pub const SIG_ERR = @intToPtr(extern fn(i32), @maxValue(usize));535pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize));
549pub const SIG_DFL = @intToPtr(extern fn(i32), 0);536pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
550pub const SIG_IGN = @intToPtr(extern fn(i32), 1);537pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
551pub const empty_sigset = []usize{0} ** sigset_t.len;538pub const empty_sigset = []usize{0} ** sigset_t.len;
552539
553pub fn raise(sig: i32) -> usize {540pub fn raise(sig: i32) usize {
554 // TODO implement, see linux equivalent for what we want to try and do541 // TODO implement, see linux equivalent for what we want to try and do
555 return 0;542 return 0;
556}543}
557544
558fn blockAllSignals(set: &sigset_t) {545fn blockAllSignals(set: *sigset_t) void {
559 // TODO implement546 // TODO implement
560}547}
561548
562fn blockAppSignals(set: &sigset_t) {549fn blockAppSignals(set: *sigset_t) void {
563 // TODO implement550 // TODO implement
564}551}
565552
566fn restoreSignals(set: &sigset_t) {553fn restoreSignals(set: *sigset_t) void {
567 // TODO implement554 // TODO implement
568}555}
569556
570pub fn sigaddset(set: &sigset_t, sig: u6) {557pub fn sigaddset(set: *sigset_t, sig: u6) void {
571 const s = sig - 1;558 const s = sig - 1;
572 (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));559 (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
573}560}
574561
575pub fn sigismember(set: &const sigset_t, sig: u6) -> bool {562pub fn sigismember(set: *const sigset_t, sig: u6) bool {
576 const s = sig - 1;563 const s = sig - 1;
577 return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;564 return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
578}565}
579566
580
581pub const sa_family_t = u16;
582pub const socklen_t = u32;
583pub const in_addr = u32;
584pub const in6_addr = [16]u8;
585
586pub const sockaddr = extern struct {
587 family: sa_family_t,
588 port: u16,
589 data: [12]u8,
590};
591
592pub const sockaddr_in = extern struct {
593 family: sa_family_t,
594 port: u16,
595 addr: in_addr,
596 zero: [8]u8,
597};
598
599pub const sockaddr_in6 = extern struct {
600 family: sa_family_t,
601 port: u16,
602 flowinfo: u32,
603 addr: in6_addr,
604 scope_id: u32,
605};
606
607pub const iovec = extern struct {
608 iov_base: &u8,
609 iov_len: usize,
610};
611
612//
613//const IF_NAMESIZE = 16;
614//
615//export struct ifreq {
616// ifrn_name: [IF_NAMESIZE]u8,
617// union {
618// ifru_addr: sockaddr,
619// ifru_dstaddr: sockaddr,
620// ifru_broadaddr: sockaddr,
621// ifru_netmask: sockaddr,
622// ifru_hwaddr: sockaddr,
623// ifru_flags: i16,
624// ifru_ivalue: i32,
625// ifru_mtu: i32,
626// ifru_map: ifmap,
627// ifru_slave: [IF_NAMESIZE]u8,
628// ifru_newname: [IF_NAMESIZE]u8,
629// ifru_data: &u8,
630// } ifr_ifru;
631//}
632//
633
634pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
635 arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len))
636}
637
638pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
639 arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len))
640}
641
642pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize {
643 arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol))
644}
645
646pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize {
647 arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen))
648}
649
650pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize {
651 arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen))
652}
653
654pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {
655 arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags)
656}
657
658pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
659 arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len))
660}
661
662pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {
663 arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags)
664}
665
666pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
667 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize
668{
669 arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen))
670}
671
672pub fn shutdown(fd: i32, how: i32) -> usize {
673 arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how))
674}
675
676pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
677 arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len))
678}
679
680pub fn listen(fd: i32, backlog: i32) -> usize {
681 arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog))
682}
683
684pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize {
685 arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen))
686}
687
688pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize {
689 arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0]))
690}
691
692pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
693 accept4(fd, addr, len, 0)
694}
695
696pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize {
697 arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags)
698}
699
700// error NameTooLong;
701// error SystemResources;
702// error Io;
703//
704// pub fn if_nametoindex(name: []u8) -> %u32 {
705// var ifr: ifreq = undefined;
706//
707// if (name.len >= ifr.ifr_name.len) {
708// return error.NameTooLong;
709// }
710//
711// const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
712// const socket_err = getErrno(socket_ret);
713// if (socket_err > 0) {
714// return error.SystemResources;
715// }
716// const socket_fd = i32(socket_ret);
717// @memcpy(&ifr.ifr_name[0], &name[0], name.len);
718// ifr.ifr_name[name.len] = 0;
719// const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr);
720// close(socket_fd);
721// const ioctl_err = getErrno(ioctl_ret);
722// if (ioctl_err > 0) {
723// return error.Io;
724// }
725// return ifr.ifr_ifindex;
726// }
727
728pub const Stat = arch.Stat;567pub const Stat = arch.Stat;
729pub const timespec = arch.timespec;568pub const timespec = arch.timespec;
730569
731pub fn fstat(fd: i32, stat_buf: &Stat) -> usize {570pub fn fstat(fd: i32, stat_buf: *Stat) usize {
732 arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf))571 return arch.syscall2(arch.SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf));
733}572}
std/os/freebsd_errno.zig+100-100
...@@ -1,121 +1,121 @@...@@ -1,121 +1,121 @@
1pub const EPERM = 1; // Operation not permitted1pub const EPERM = 1; // Operation not permitted
2pub const ENOENT = 2; // No such file or directory2pub const ENOENT = 2; // No such file or directory
3pub const ESRCH = 3; // No such process3pub const ESRCH = 3; // No such process
4pub const EINTR = 4; // Interrupted system call4pub const EINTR = 4; // Interrupted system call
5pub const EIO = 5; // Input/output error5pub const EIO = 5; // Input/output error
6pub const ENXIO = 6; // Device not configured6pub const ENXIO = 6; // Device not configured
7pub const E2BIG = 7; // Argument list too long7pub const E2BIG = 7; // Argument list too long
8pub const ENOEXEC = 8; // Exec format error8pub const ENOEXEC = 8; // Exec format error
9pub const EBADF = 9; // Bad file descriptor9pub const EBADF = 9; // Bad file descriptor
10pub const ECHILD = 10; // No child processes10pub const ECHILD = 10; // No child processes
11pub const EDEADLK = 11; // Resource deadlock avoided11pub const EDEADLK = 11; // Resource deadlock avoided
12 // 11 was EAGAIN12// 11 was EAGAIN
13pub const ENOMEM = 12; // Cannot allocate memory13pub const ENOMEM = 12; // Cannot allocate memory
14pub const EACCES = 13; // Permission denied14pub const EACCES = 13; // Permission denied
15pub const EFAULT = 14; // Bad address15pub const EFAULT = 14; // Bad address
16pub const ENOTBLK = 15; // Block device required16pub const ENOTBLK = 15; // Block device required
17pub const EBUSY = 16; // Device busy17pub const EBUSY = 16; // Device busy
18pub const EEXIST = 17; // File exists18pub const EEXIST = 17; // File exists
19pub const EXDEV = 18; // Cross-device link19pub const EXDEV = 18; // Cross-device link
20pub const ENODEV = 19; // Operation not supported by device20pub const ENODEV = 19; // Operation not supported by device
21pub const ENOTDIR = 20; // Not a directory21pub const ENOTDIR = 20; // Not a directory
22pub const EISDIR = 21; // Is a directory22pub const EISDIR = 21; // Is a directory
23pub const EINVAL = 22; // Invalid argument23pub const EINVAL = 22; // Invalid argument
24pub const ENFILE = 23; // Too many open files in system24pub const ENFILE = 23; // Too many open files in system
25pub const EMFILE = 24; // Too many open files25pub const EMFILE = 24; // Too many open files
26pub const ENOTTY = 25; // Inappropriate ioctl for device26pub const ENOTTY = 25; // Inappropriate ioctl for device
27pub const ETXTBSY = 26; // Text file busy27pub const ETXTBSY = 26; // Text file busy
28pub const EFBIG = 27; // File too large28pub const EFBIG = 27; // File too large
29pub const ENOSPC = 28; // No space left on device29pub const ENOSPC = 28; // No space left on device
30pub const ESPIPE = 29; // Illegal seek30pub const ESPIPE = 29; // Illegal seek
31pub const EROFS = 30; // Read-only filesystem31pub const EROFS = 30; // Read-only filesystem
32pub const EMLINK = 31; // Too many links32pub const EMLINK = 31; // Too many links
33pub const EPIPE = 32; // Broken pipe33pub const EPIPE = 32; // Broken pipe
3434
35// math software35// math software
36pub const EDOM = 33; // Numerical argument out of domain36pub const EDOM = 33; // Numerical argument out of domain
37pub const ERANGE = 34; // Result too large37pub const ERANGE = 34; // Result too large
3838
39// non-blocking and interrupt i/o39// non-blocking and interrupt i/o
40pub const EAGAIN = 35; // Resource temporarily unavailable40pub const EAGAIN = 35; // Resource temporarily unavailable
41pub const EWOULDBLOCK = EAGAIN; // Operation would block41pub const EWOULDBLOCK = EAGAIN; // Operation would block
42pub const EINPROGRESS = 36; // Operation now in progress42pub const EINPROGRESS = 36; // Operation now in progress
43pub const EALREADY = 37; // Operation already in progress43pub const EALREADY = 37; // Operation already in progress
4444
45// ipc/network software -- argument errors45// ipc/network software -- argument errors
46pub const ENOTSOCK = 38; // Socket operation on non-socket46pub const ENOTSOCK = 38; // Socket operation on non-socket
47pub const EDESTADDRREQ = 39; // Destination address required47pub const EDESTADDRREQ = 39; // Destination address required
48pub const EMSGSIZE = 40; // Message too long48pub const EMSGSIZE = 40; // Message too long
49pub const EPROTOTYPE = 41; // Protocol wrong type for socket49pub const EPROTOTYPE = 41; // Protocol wrong type for socket
50pub const ENOPROTOOPT = 42; // Protocol not available50pub const ENOPROTOOPT = 42; // Protocol not available
51pub const EPROTONOSUPPORT = 43; // Protocol not supported51pub const EPROTONOSUPPORT = 43; // Protocol not supported
52pub const ESOCKTNOSUPPORT = 44; // Socket type not supported52pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
53pub const EOPNOTSUPP = 45; // Operation not supported53pub const EOPNOTSUPP = 45; // Operation not supported
54pub const ENOTSUP = EOPNOTSUPP; // Operation not supported54pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
55pub const EPFNOSUPPORT = 46; // Protocol family not supported55pub const EPFNOSUPPORT = 46; // Protocol family not supported
56pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family56pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
57pub const EADDRINUSE = 48; // Address already in use57pub const EADDRINUSE = 48; // Address already in use
58pub const EADDRNOTAVAIL = 49; // Can't assign requested address58pub const EADDRNOTAVAIL = 49; // Can't assign requested address
5959
60// ipc/network software -- operational errors60// ipc/network software -- operational errors
61pub const ENETDOWN = 50; // Network is down61pub const ENETDOWN = 50; // Network is down
62pub const ENETUNREACH = 51; // Network is unreachable62pub const ENETUNREACH = 51; // Network is unreachable
63pub const ENETRESET = 52; // Network dropped connection on reset63pub const ENETRESET = 52; // Network dropped connection on reset
64pub const ECONNABORTED = 53; // Software caused connection abort64pub const ECONNABORTED = 53; // Software caused connection abort
65pub const ECONNRESET = 54; // Connection reset by peer65pub const ECONNRESET = 54; // Connection reset by peer
66pub const ENOBUFS = 55; // No buffer space available66pub const ENOBUFS = 55; // No buffer space available
67pub const EISCONN = 56; // Socket is already connected67pub const EISCONN = 56; // Socket is already connected
68pub const ENOTCONN = 57; // Socket is not connected68pub const ENOTCONN = 57; // Socket is not connected
69pub const ESHUTDOWN = 58; // Can't send after socket shutdown69pub const ESHUTDOWN = 58; // Can't send after socket shutdown
70pub const ETOOMANYREFS = 59; // Too many references: can't splice70pub const ETOOMANYREFS = 59; // Too many references: can't splice
71pub const ETIMEDOUT = 60; // Operation timed out71pub const ETIMEDOUT = 60; // Operation timed out
72pub const ECONNREFUSED = 61; // Connection refused72pub const ECONNREFUSED = 61; // Connection refused
7373
74pub const ELOOP = 62; // Too many levels of symbolic links74pub const ELOOP = 62; // Too many levels of symbolic links
75pub const ENAMETOOLONG = 63; // File name too long75pub const ENAMETOOLONG = 63; // File name too long
7676
77// should be rearranged77// should be rearranged
78pub const EHOSTDOWN = 64; // Host is down78pub const EHOSTDOWN = 64; // Host is down
79pub const EHOSTUNREACH = 65; // No route to host79pub const EHOSTUNREACH = 65; // No route to host
80pub const ENOTEMPTY = 66; // Directory not empty80pub const ENOTEMPTY = 66; // Directory not empty
8181
82// quotas & mush82// quotas & mush
83pub const EPROCLIM = 67; // Too many processes83pub const EPROCLIM = 67; // Too many processes
84pub const EUSERS = 68; // Too many users84pub const EUSERS = 68; // Too many users
85pub const EDQUOT = 69; // Disc quota exceeded85pub const EDQUOT = 69; // Disc quota exceeded
8686
87// Network File System87// Network File System
88pub const ESTALE = 70; // Stale NFS file handle88pub const ESTALE = 70; // Stale NFS file handle
89pub const EREMOTE = 71; // Too many levels of remote in path89pub const EREMOTE = 71; // Too many levels of remote in path
90pub const EBADRPC = 72; // RPC struct is bad90pub const EBADRPC = 72; // RPC struct is bad
91pub const ERPCMISMATCH = 73; // RPC version wrong91pub const ERPCMISMATCH = 73; // RPC version wrong
92pub const EPROGUNAVAIL = 74; // RPC prog. not avail92pub const EPROGUNAVAIL = 74; // RPC prog. not avail
93pub const EPROGMISMATCH = 75; // Program version wrong93pub const EPROGMISMATCH = 75; // Program version wrong
94pub const EPROCUNAVAIL = 76; // Bad procedure for program94pub const EPROCUNAVAIL = 76; // Bad procedure for program
9595
96pub const ENOLCK = 77; // No locks available96pub const ENOLCK = 77; // No locks available
97pub const ENOSYS = 78; // Function not implemented97pub const ENOSYS = 78; // Function not implemented
9898
99pub const EFTYPE = 79; // Inappropriate file type or format99pub const EFTYPE = 79; // Inappropriate file type or format
100pub const EAUTH = 80; // Authentication error100pub const EAUTH = 80; // Authentication error
101pub const ENEEDAUTH = 81; // Need authenticator101pub const ENEEDAUTH = 81; // Need authenticator
102pub const EIDRM = 82; // Identifier removed102pub const EIDRM = 82; // Identifier removed
103pub const ENOMSG = 83; // No message of desired type103pub const ENOMSG = 83; // No message of desired type
104pub const EOVERFLOW = 84; // Value too large to be stored in data type104pub const EOVERFLOW = 84; // Value too large to be stored in data type
105pub const ECANCELED = 85; // Operation canceled105pub const ECANCELED = 85; // Operation canceled
106pub const EILSEQ = 86; // Illegal byte sequence106pub const EILSEQ = 86; // Illegal byte sequence
107pub const ENOATTR = 87; // Attribute not found107pub const ENOATTR = 87; // Attribute not found
108108
109pub const EDOOFUS = 88; // Programming error109pub const EDOOFUS = 88; // Programming error
110110
111pub const EBADMSG = 89; // Bad message111pub const EBADMSG = 89; // Bad message
112pub const EMULTIHOP = 90; // Multihop attempted112pub const EMULTIHOP = 90; // Multihop attempted
113pub const ENOLINK = 91; // Link has been severed113pub const ENOLINK = 91; // Link has been severed
114pub const EPROTO = 92; // Protocol error114pub const EPROTO = 92; // Protocol error
115115
116pub const ENOTCAPABLE = 93; // Capabilities insufficient116pub const ENOTCAPABLE = 93; // Capabilities insufficient
117pub const ECAPMODE = 94; // Not permitted in capability mode117pub const ECAPMODE = 94; // Not permitted in capability mode
118pub const ENOTRECOVERABLE = 95; // State not recoverable118pub const ENOTRECOVERABLE = 95; // State not recoverable
119pub const EOWNERDEAD = 96; // Previous owner died119pub const EOWNERDEAD = 96; // Previous owner died
120120
121pub const ELAST = 96; // Must be equal largest errno121pub const ELAST = 96; // Must be equal largest errno
std/os/freebsd_x86_64.zig+78-65
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const freebsd = @import("freebsd.zig");1const freebsd = @import("index.zig");
2const socklen_t = freebsd.socklen_t;2const socklen_t = freebsd.socklen_t;
3const iovec = freebsd.iovec;3const iovec = freebsd.iovec;
44
...@@ -477,26 +477,26 @@ pub const SYS_mknodat = 559;...@@ -477,26 +477,26 @@ pub const SYS_mknodat = 559;
477pub const SYS_kevent = 560;477pub const SYS_kevent = 560;
478pub const SYS_MAXSYSCALL = 561;478pub const SYS_MAXSYSCALL = 561;
479479
480pub const O_CREAT = 0o100;480pub const O_CREAT = 0o100;
481pub const O_EXCL = 0o200;481pub const O_EXCL = 0o200;
482pub const O_NOCTTY = 0o400;482pub const O_NOCTTY = 0o400;
483pub const O_TRUNC = 0o1000;483pub const O_TRUNC = 0o1000;
484pub const O_APPEND = 0o2000;484pub const O_APPEND = 0o2000;
485pub const O_NONBLOCK = 0o4000;485pub const O_NONBLOCK = 0o4000;
486pub const O_DSYNC = 0o10000;486pub const O_DSYNC = 0o10000;
487pub const O_SYNC = 0o4010000;487pub const O_SYNC = 0o4010000;
488pub const O_RSYNC = 0o4010000;488pub const O_RSYNC = 0o4010000;
489pub const O_DIRECTORY = 0o200000;489pub const O_DIRECTORY = 0o200000;
490pub const O_NOFOLLOW = 0o400000;490pub const O_NOFOLLOW = 0o400000;
491pub const O_CLOEXEC = 0o2000000;491pub const O_CLOEXEC = 0o2000000;
492492
493pub const O_ASYNC = 0o20000;493pub const O_ASYNC = 0o20000;
494pub const O_DIRECT = 0o40000;494pub const O_DIRECT = 0o40000;
495pub const O_LARGEFILE = 0;495pub const O_LARGEFILE = 0;
496pub const O_NOATIME = 0o1000000;496pub const O_NOATIME = 0o1000000;
497pub const O_PATH = 0o10000000;497pub const O_PATH = 0o10000000;
498pub const O_TMPFILE = 0o20200000;498pub const O_TMPFILE = 0o20200000;
499pub const O_NDELAY = O_NONBLOCK;499pub const O_NDELAY = O_NONBLOCK;
500500
501pub const F_DUPFD = 0;501pub const F_DUPFD = 0;
502pub const F_GETFD = 1;502pub const F_GETFD = 1;
...@@ -518,86 +518,99 @@ pub const F_GETOWN_EX = 16;...@@ -518,86 +518,99 @@ pub const F_GETOWN_EX = 16;
518518
519pub const F_GETOWNER_UIDS = 17;519pub const F_GETOWNER_UIDS = 17;
520520
521pub fn syscall0(number: usize) -> usize {521pub fn syscall0(number: usize) usize {
522 asm volatile ("syscall"522 return asm volatile ("syscall"
523 : [ret] "={rax}" (-> usize)523 : [ret] "={rax}" (-> usize)
524 : [number] "{rax}" (number)524 : [number] "{rax}" (number)
525 : "rcx", "r11")525 : "rcx", "r11"
526 );
526}527}
527528
528pub fn syscall1(number: usize, arg1: usize) -> usize {529pub fn syscall1(number: usize, arg1: usize) usize {
529 asm volatile ("syscall"530 return asm volatile ("syscall"
530 : [ret] "={rax}" (-> usize)531 : [ret] "={rax}" (-> usize)
531 : [number] "{rax}" (number),532 : [number] "{rax}" (number),
532 [arg1] "{rdi}" (arg1)533 [arg1] "{rdi}" (arg1)
533 : "rcx", "r11")534 : "rcx", "r11"
535 );
534}536}
535537
536pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {538pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
537 asm volatile ("syscall"539 return asm volatile ("syscall"
538 : [ret] "={rax}" (-> usize)540 : [ret] "={rax}" (-> usize)
539 : [number] "{rax}" (number),541 : [number] "{rax}" (number),
540 [arg1] "{rdi}" (arg1),542 [arg1] "{rdi}" (arg1),
541 [arg2] "{rsi}" (arg2)543 [arg2] "{rsi}" (arg2)
542 : "rcx", "r11")544 : "rcx", "r11"
545 );
543}546}
544547
545pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {548pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
546 asm volatile ("syscall"549 return asm volatile ("syscall"
547 : [ret] "={rax}" (-> usize)550 : [ret] "={rax}" (-> usize)
548 : [number] "{rax}" (number),551 : [number] "{rax}" (number),
549 [arg1] "{rdi}" (arg1),552 [arg1] "{rdi}" (arg1),
550 [arg2] "{rsi}" (arg2),553 [arg2] "{rsi}" (arg2),
551 [arg3] "{rdx}" (arg3)554 [arg3] "{rdx}" (arg3)
552 : "rcx", "r11")555 : "rcx", "r11"
556 );
553}557}
554558
555pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {559pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
556 asm volatile ("syscall"560 return asm volatile ("syscall"
557 : [ret] "={rax}" (-> usize)561 : [ret] "={rax}" (-> usize)
558 : [number] "{rax}" (number),562 : [number] "{rax}" (number),
559 [arg1] "{rdi}" (arg1),563 [arg1] "{rdi}" (arg1),
560 [arg2] "{rsi}" (arg2),564 [arg2] "{rsi}" (arg2),
561 [arg3] "{rdx}" (arg3),565 [arg3] "{rdx}" (arg3),
562 [arg4] "{r10}" (arg4)566 [arg4] "{r10}" (arg4)
563 : "rcx", "r11")567 : "rcx", "r11"
568 );
564}569}
565570
566pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {571pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
567 asm volatile ("syscall"572 return asm volatile ("syscall"
568 : [ret] "={rax}" (-> usize)573 : [ret] "={rax}" (-> usize)
569 : [number] "{rax}" (number),574 : [number] "{rax}" (number),
570 [arg1] "{rdi}" (arg1),575 [arg1] "{rdi}" (arg1),
571 [arg2] "{rsi}" (arg2),576 [arg2] "{rsi}" (arg2),
572 [arg3] "{rdx}" (arg3),577 [arg3] "{rdx}" (arg3),
573 [arg4] "{r10}" (arg4),578 [arg4] "{r10}" (arg4),
574 [arg5] "{r8}" (arg5)579 [arg5] "{r8}" (arg5)
575 : "rcx", "r11")580 : "rcx", "r11"
581 );
576}582}
577583
578pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,584pub fn syscall6(
579 arg5: usize, arg6: usize) -> usize585 number: usize,
580{586 arg1: usize,
581 asm volatile ("syscall"587 arg2: usize,
588 arg3: usize,
589 arg4: usize,
590 arg5: usize,
591 arg6: usize,
592) usize {
593 return asm volatile ("syscall"
582 : [ret] "={rax}" (-> usize)594 : [ret] "={rax}" (-> usize)
583 : [number] "{rax}" (number),595 : [number] "{rax}" (number),
584 [arg1] "{rdi}" (arg1),596 [arg1] "{rdi}" (arg1),
585 [arg2] "{rsi}" (arg2),597 [arg2] "{rsi}" (arg2),
586 [arg3] "{rdx}" (arg3),598 [arg3] "{rdx}" (arg3),
587 [arg4] "{r10}" (arg4),599 [arg4] "{r10}" (arg4),
588 [arg5] "{r8}" (arg5),600 [arg5] "{r8}" (arg5),
589 [arg6] "{r9}" (arg6)601 [arg6] "{r9}" (arg6)
590 : "rcx", "r11")602 : "rcx", "r11"
603 );
591}604}
592605
593pub nakedcc fn restore_rt() {606pub nakedcc fn restore_rt() void {
594 asm volatile ("syscall"607 asm volatile ("syscall"
595 :608 :
596 : [number] "{rax}" (usize(SYS_rt_sigreturn))609 : [number] "{rax}" (usize(SYS_rt_sigreturn))
597 : "rcx", "r11")610 : "rcx", "r11"
611 );
598}612}
599613
600
601pub const msghdr = extern struct {614pub const msghdr = extern struct {
602 msg_name: &u8,615 msg_name: &u8,
603 msg_namelen: socklen_t,616 msg_namelen: socklen_t,
std/os/index.zig+1-1
...@@ -24,7 +24,7 @@ test "std.os" {...@@ -24,7 +24,7 @@ test "std.os" {
24pub const windows = @import("windows/index.zig");24pub const windows = @import("windows/index.zig");
25pub const darwin = @import("darwin.zig");25pub const darwin = @import("darwin.zig");
26pub const linux = @import("linux/index.zig");26pub const linux = @import("linux/index.zig");
27pub const freebsd = @import("freebsd.zig");27pub const freebsd = @import("freebsd/index.zig");
28pub const zen = @import("zen.zig");28pub const zen = @import("zen.zig");
29pub const posix = switch (builtin.os) {29pub const posix = switch (builtin.os) {
30 Os.linux => linux,30 Os.linux => linux,