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 @@
1const c = @import("../c/index.zig");
12const assert = @import("../debug.zig").assert;
23const builtin = @import("builtin");
34const arch = switch (builtin.arch) {
4 builtin.Arch.x86_64 => @import("freebsd_x86_64.zig"),
5 builtin.Arch.i386 => @import("freebsd_i386.zig"),
5 builtin.Arch.x86_64 => @import("x86_64.zig"),
66 else => @compileError("unsupported arch"),
77};
8pub use @import("freebsd_errno.zig");
8pub use @import("errno.zig");
99
1010pub const PATH_MAX = 1024;
1111
......@@ -13,85 +13,86 @@ pub const STDIN_FILENO = 0;
1313pub const STDOUT_FILENO = 1;
1414pub const STDERR_FILENO = 2;
1515
16pub const PROT_NONE = 0;
17pub const PROT_READ = 1;
18pub const PROT_WRITE = 2;
19pub const PROT_EXEC = 4;
20
21pub const MAP_FAILED = @maxValue(usize);
22pub const MAP_SHARED = 0x0001;
23pub const MAP_PRIVATE = 0x0002;
24pub const MAP_FIXED = 0x0010;
25pub const MAP_STACK = 0x0400;
26pub const MAP_NOSYNC = 0x0800;
27pub const MAP_ANON = 0x1000;
28pub const MAP_ANONYMOUS = MAP_ANON;
29pub const MAP_FILE = 0;
30
31pub const MAP_GUARD = 0x00002000;
32pub const MAP_EXCL = 0x00004000;
33pub const MAP_NOCORE = 0x00020000;
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;
3435pub const MAP_PREFAULT_READ = 0x00040000;
35pub const MAP_32BIT = 0x00080000;
36pub const MAP_32BIT = 0x00080000;
3637
37pub const WNOHANG = 1;
38pub const WUNTRACED = 2;
39pub const WSTOPPED = WUNTRACED;
38pub const WNOHANG = 1;
39pub const WUNTRACED = 2;
40pub const WSTOPPED = WUNTRACED;
4041pub const WCONTINUED = 4;
41pub const WNOWAIT = 8;
42pub const WEXITED = 16;
43pub const WTRAPPED = 32;
42pub const WNOWAIT = 8;
43pub const WEXITED = 16;
44pub const WTRAPPED = 32;
4445
45pub const SA_ONSTACK = 0x0001;
46pub const SA_RESTART = 0x0002;
46pub const SA_ONSTACK = 0x0001;
47pub const SA_RESTART = 0x0002;
4748pub const SA_RESETHAND = 0x0004;
4849pub const SA_NOCLDSTOP = 0x0008;
49pub const SA_NODEFER = 0x0010;
50pub const SA_NODEFER = 0x0010;
5051pub 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;
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;
7980pub 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;
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;
9192
9293pub const O_RDONLY = 0o0;
9394pub const O_WRONLY = 0o1;
94pub const O_RDWR = 0o2;
95pub const O_RDWR = 0o2;
9596pub const O_ACCMODE = 0o3;
9697
9798pub const O_CREAT = arch.O_CREAT;
......@@ -119,7 +120,7 @@ pub const SEEK_SET = 0;
119120pub const SEEK_CUR = 1;
120121pub const SEEK_END = 2;
121122
122pub const SIG_BLOCK = 1;
123pub const SIG_BLOCK = 1;
123124pub const SIG_UNBLOCK = 2;
124125pub const SIG_SETMASK = 3;
125126
......@@ -272,7 +273,6 @@ pub const DT_LNK = 10;
272273pub const DT_SOCK = 12;
273274pub const DT_WHT = 14;
274275
275
276276pub const TCGETS = 0x5401;
277277pub const TCSETS = 0x5402;
278278pub const TCSETSW = 0x5403;
......@@ -329,15 +329,30 @@ pub const TIOCGPKT = 0x80045438;
329329pub const TIOCGPTLCK = 0x80045439;
330330pub const TIOCGEXCL = 0x80045440;
331331
332fn unsigned(s: i32) -> u32 { @bitCast(u32, s) }
333fn signed(s: u32) -> i32 { @bitCast(i32, s) }
334pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) }
335pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) }
336pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) }
337pub fn WIFEXITED(s: i32) -> bool { WTERMSIG(s) == 0 }
338pub fn WIFSTOPPED(s: i32) -> bool { (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00 }
339pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff }
340
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 (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
352}
353pub fn WIFSIGNALED(s: i32) bool {
354 return (unsigned(s) & 0xffff) -% 1 < 0xff;
355}
341356
342357pub const winsize = extern struct {
343358 ws_row: u16,
......@@ -347,182 +362,160 @@ pub const winsize = extern struct {
347362};
348363
349364/// 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 {
351366 const signed_r = @bitCast(isize, r);
352 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
367 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
353368}
354369
355pub fn dup2(old: i32, new: i32) -> usize {
356 arch.syscall2(arch.SYS_dup2, usize(old), usize(new))
370pub fn dup2(old: i32, new: i32) usize {
371 return arch.syscall2(arch.SYS_dup2, usize(old), usize(new));
357372}
358373
359pub fn chdir(path: &const u8) -> usize {
360 arch.syscall1(arch.SYS_chdir, @ptrToInt(path))
374pub fn chdir(path: [*]const u8) usize {
375 return arch.syscall1(arch.SYS_chdir, @ptrToInt(path));
361376}
362377
363pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize {
364 arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp))
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));
365380}
366381
367pub fn fork() -> usize {
368 arch.syscall0(arch.SYS_fork)
382pub fn fork() usize {
383 return arch.syscall0(arch.SYS_fork);
369384}
370385
371pub fn getcwd(buf: &u8, size: usize) -> usize {
372 arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size)
386pub fn getcwd(buf: [*]u8, size: usize) usize {
387 return arch.syscall2(arch.SYS___getcwd, @ptrToInt(buf), size);
373388}
374389
375pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize {
376 arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count)
390pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize {
391 return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count);
377392}
378393
379pub fn isatty(fd: i32) -> bool {
394pub fn isatty(fd: i32) bool {
380395 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;
382397}
383398
384pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {
385 arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len)
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);
386401}
387402
388pub fn mkdir(path: &const u8, mode: u32) -> usize {
389 arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode)
403pub fn mkdir(path: [*]const u8, mode: u32) usize {
404 return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode);
390405}
391406
392pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize)
393 -> usize
394{
395 arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
396 @bitCast(usize, offset))
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));
397409}
398410
399pub fn munmap(address: &u8, length: usize) -> usize {
400 arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length)
411pub fn munmap(address: usize, length: usize) usize {
412 return arch.syscall2(arch.SYS_munmap, address, length);
401413}
402414
403pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
404 arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count)
415pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
416 return arch.syscall3(arch.SYS_read, @intCast(usize, fd), @ptrToInt(buf), count);
405417}
406418
407pub fn rmdir(path: &const u8) -> usize {
408 arch.syscall1(arch.SYS_rmdir, @ptrToInt(path))
419pub fn rmdir(path: [*]const u8) usize {
420 return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path));
409421}
410422
411pub fn symlink(existing: &const u8, new: &const u8) -> usize {
412 arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new))
423pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
424 return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
413425}
414426
415pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {
416 arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset)
427pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
428 return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
417429}
418430
419pub fn pipe(fd: &[2]i32) -> usize {
420 pipe2(fd, 0)
431pub fn pipe(fd: *[2]i32) usize {
432 return pipe2(fd, 0);
421433}
422434
423pub fn pipe2(fd: &[2]i32, flags: usize) -> usize {
424 arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags)
435pub fn pipe2(fd: *[2]i32, flags: usize) usize {
436 return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags);
425437}
426438
427pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
428 arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count)
439pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
440 return arch.syscall3(arch.SYS_write, @intCast(usize, fd), @ptrToInt(buf), count);
429441}
430442
431pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {
432 arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset)
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);
433445}
434446
435pub fn rename(old: &const u8, new: &const u8) -> usize {
436 arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new))
447pub fn rename(old: [*]const u8, new: [*]const u8) usize {
448 return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new));
437449}
438450
439pub fn open(path: &const u8, flags: u32, perm: usize) -> usize {
440 arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm)
451pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
452 return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm);
441453}
442454
443pub fn create(path: &const u8, perm: usize) -> usize {
444 arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm)
455pub fn create(path: [*]const u8, perm: usize) usize {
456 return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm);
445457}
446458
447pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {
448 arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode)
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);
449461}
450462
451pub fn close(fd: i32) -> usize {
452 arch.syscall1(arch.SYS_close, usize(fd))
463pub fn close(fd: i32) usize {
464 return arch.syscall1(arch.SYS_close, @intCast(usize, fd));
453465}
454466
455pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize {
456 arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos)
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);
457469}
458470
459pub fn exit(status: i32) -> noreturn {
471pub fn exit(status: i32) noreturn {
460472 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
461 unreachable
473 unreachable;
462474}
463475
464pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
465 arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags))
476pub fn getrandom(buf: &u8, count: usize, flags: u32) usize {
477 return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, @bitCast(usize, flags));
466478}
467479
468pub fn kill(pid: i32, sig: i32) -> usize {
469 arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig))
480pub fn kill(pid: i32, sig: i32) usize {
481 return arch.syscall2(arch.SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig));
470482}
471483
472pub fn unlink(path: &const u8) -> usize {
473 arch.syscall1(arch.SYS_unlink, @ptrToInt(path))
484pub fn unlink(path: [*]const u8) usize {
485 return arch.syscall1(arch.SYS_unlink, @ptrToInt(path));
474486}
475487
476pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize {
477 arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0)
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);
478490}
479491
480pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {
481 arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem))
492pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
493 return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
482494}
483495
484pub fn setuid(uid: u32) -> usize {
485 arch.syscall1(arch.SYS_setuid, uid)
496pub fn setuid(uid: u32) usize {
497 return arch.syscall1(arch.SYS_setuid, uid);
486498}
487499
488pub fn setgid(gid: u32) -> usize {
489 arch.syscall1(arch.SYS_setgid, gid)
500pub fn setgid(gid: u32) usize {
501 return arch.syscall1(arch.SYS_setgid, gid);
490502}
491503
492pub fn setreuid(ruid: u32, euid: u32) -> usize {
493 arch.syscall2(arch.SYS_setreuid, ruid, euid)
504pub fn setreuid(ruid: u32, euid: u32) usize {
505 return arch.syscall2(arch.SYS_setreuid, ruid, euid);
494506}
495507
496pub fn setregid(rgid: u32, egid: u32) -> usize {
497 arch.syscall2(arch.SYS_setregid, rgid, egid)
508pub fn setregid(rgid: u32, egid: u32) usize {
509 return arch.syscall2(arch.SYS_setregid, rgid, egid);
498510}
499511
500pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {
501 arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8)
512pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize {
513 // TODO: Implement
514 return 0;
502515}
503516
504pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
505 assert(sig >= 1);
506 assert(sig != SIGKILL);
507 assert(sig != SIGSTOP);
508 var ksa = k_sigaction {
509 .handler = act.handler,
510 .flags = act.flags | SA_RESTORER,
511 .mask = undefined,
512 .restorer = @ptrCast(extern fn(), arch.restore_rt),
513 };
514 var ksa_old: k_sigaction = undefined;
515 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
516 const result = arch.syscall4(arch.SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask)));
517 const err = getErrno(result);
518 if (err != 0) {
519 return result;
520 }
521 if (oact) |old| {
522 old.handler = ksa_old.handler;
523 old.flags = @truncate(u32, ksa_old.flags);
524 @memcpy(@ptrCast(&u8, &old.mask), @ptrCast(&const u8, &ksa_old.mask), @sizeOf(@typeOf(ksa_old.mask)));
525 }
517pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
518 // TODO: Implement
526519 return 0;
527520}
528521
......@@ -531,203 +524,49 @@ const sigset_t = [128 / @sizeOf(usize)]usize;
531524const all_mask = []usize{@maxValue(usize)};
532525const 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
541527/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
542528pub const Sigaction = struct {
543 handler: extern fn(i32),
529 // TODO: Adjust to use freebsd struct layout
530 handler: extern fn (i32) void,
544531 mask: sigset_t,
545532 flags: u32,
546533};
547534
548pub const SIG_ERR = @intToPtr(extern fn(i32), @maxValue(usize));
549pub const SIG_DFL = @intToPtr(extern fn(i32), 0);
550pub const SIG_IGN = @intToPtr(extern fn(i32), 1);
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);
551538pub const empty_sigset = []usize{0} ** sigset_t.len;
552539
553pub fn raise(sig: i32) -> usize {
540pub fn raise(sig: i32) usize {
554541 // TODO implement, see linux equivalent for what we want to try and do
555542 return 0;
556543}
557544
558fn blockAllSignals(set: &sigset_t) {
545fn blockAllSignals(set: *sigset_t) void {
559546 // TODO implement
560547}
561548
562fn blockAppSignals(set: &sigset_t) {
549fn blockAppSignals(set: *sigset_t) void {
563550 // TODO implement
564551}
565552
566fn restoreSignals(set: &sigset_t) {
553fn restoreSignals(set: *sigset_t) void {
567554 // TODO implement
568555}
569556
570pub fn sigaddset(set: &sigset_t, sig: u6) {
557pub fn sigaddset(set: *sigset_t, sig: u6) void {
571558 const s = sig - 1;
572559 (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
573560}
574561
575pub fn sigismember(set: &const sigset_t, sig: u6) -> bool {
562pub fn sigismember(set: *const sigset_t, sig: u6) bool {
576563 const s = sig - 1;
577564 return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
578565}
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
728567pub const Stat = arch.Stat;
729568pub const timespec = arch.timespec;
730569
731pub fn fstat(fd: i32, stat_buf: &Stat) -> usize {
732 arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf))
570pub fn fstat(fd: i32, stat_buf: *Stat) usize {
571 return arch.syscall2(arch.SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf));
733572}
std/os/freebsd_errno.zig+100-100
......@@ -1,121 +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
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
3434
3535// math software
36pub const EDOM = 33; // Numerical argument out of domain
37pub const ERANGE = 34; // Result too large
36pub const EDOM = 33; // Numerical argument out of domain
37pub const ERANGE = 34; // Result too large
3838
3939// 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
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
4444
4545// 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
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
5959
6060// 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
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
7373
74pub const ELOOP = 62; // Too many levels of symbolic links
75pub const ENAMETOOLONG = 63; // File name too long
74pub const ELOOP = 62; // Too many levels of symbolic links
75pub const ENAMETOOLONG = 63; // File name too long
7676
7777// 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
78pub const EHOSTDOWN = 64; // Host is down
79pub const EHOSTUNREACH = 65; // No route to host
80pub const ENOTEMPTY = 66; // Directory not empty
8181
8282// quotas & mush
83pub const EPROCLIM = 67; // Too many processes
84pub const EUSERS = 68; // Too many users
85pub const EDQUOT = 69; // Disc quota exceeded
83pub const EPROCLIM = 67; // Too many processes
84pub const EUSERS = 68; // Too many users
85pub const EDQUOT = 69; // Disc quota exceeded
8686
8787// 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
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
9595
96pub const ENOLCK = 77; // No locks available
97pub const ENOSYS = 78; // Function not implemented
96pub const ENOLCK = 77; // No locks available
97pub const ENOSYS = 78; // Function not implemented
9898
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
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
108108
109pub const EDOOFUS = 88; // Programming error
109pub const EDOOFUS = 88; // Programming error
110110
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
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
115115
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
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
120120
121pub const ELAST = 96; // Must be equal largest errno
121pub const ELAST = 96; // Must be equal largest errno
std/os/freebsd_x86_64.zig+78-65
......@@ -1,4 +1,4 @@
1const freebsd = @import("freebsd.zig");
1const freebsd = @import("index.zig");
22const socklen_t = freebsd.socklen_t;
33const iovec = freebsd.iovec;
44
......@@ -477,26 +477,26 @@ pub const SYS_mknodat = 559;
477477pub const SYS_kevent = 560;
478478pub const SYS_MAXSYSCALL = 561;
479479
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;
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;
489489pub const O_DIRECTORY = 0o200000;
490pub const O_NOFOLLOW = 0o400000;
491pub const O_CLOEXEC = 0o2000000;
490pub const O_NOFOLLOW = 0o400000;
491pub const O_CLOEXEC = 0o2000000;
492492
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;
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;
498498pub const O_TMPFILE = 0o20200000;
499pub const O_NDELAY = O_NONBLOCK;
499pub const O_NDELAY = O_NONBLOCK;
500500
501501pub const F_DUPFD = 0;
502502pub const F_GETFD = 1;
......@@ -518,86 +518,99 @@ pub const F_GETOWN_EX = 16;
518518
519519pub const F_GETOWNER_UIDS = 17;
520520
521pub fn syscall0(number: usize) -> usize {
522 asm volatile ("syscall"
521pub fn syscall0(number: usize) usize {
522 return asm volatile ("syscall"
523523 : [ret] "={rax}" (-> usize)
524524 : [number] "{rax}" (number)
525 : "rcx", "r11")
525 : "rcx", "r11"
526 );
526527}
527528
528pub fn syscall1(number: usize, arg1: usize) -> usize {
529 asm volatile ("syscall"
529pub fn syscall1(number: usize, arg1: usize) usize {
530 return asm volatile ("syscall"
530531 : [ret] "={rax}" (-> usize)
531532 : [number] "{rax}" (number),
532 [arg1] "{rdi}" (arg1)
533 : "rcx", "r11")
533 [arg1] "{rdi}" (arg1)
534 : "rcx", "r11"
535 );
534536}
535537
536pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
537 asm volatile ("syscall"
538pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
539 return asm volatile ("syscall"
538540 : [ret] "={rax}" (-> usize)
539541 : [number] "{rax}" (number),
540 [arg1] "{rdi}" (arg1),
541 [arg2] "{rsi}" (arg2)
542 : "rcx", "r11")
542 [arg1] "{rdi}" (arg1),
543 [arg2] "{rsi}" (arg2)
544 : "rcx", "r11"
545 );
543546}
544547
545pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
546 asm volatile ("syscall"
548pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
549 return asm volatile ("syscall"
547550 : [ret] "={rax}" (-> usize)
548551 : [number] "{rax}" (number),
549 [arg1] "{rdi}" (arg1),
550 [arg2] "{rsi}" (arg2),
551 [arg3] "{rdx}" (arg3)
552 : "rcx", "r11")
552 [arg1] "{rdi}" (arg1),
553 [arg2] "{rsi}" (arg2),
554 [arg3] "{rdx}" (arg3)
555 : "rcx", "r11"
556 );
553557}
554558
555pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
556 asm volatile ("syscall"
559pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
560 return asm volatile ("syscall"
557561 : [ret] "={rax}" (-> usize)
558562 : [number] "{rax}" (number),
559 [arg1] "{rdi}" (arg1),
560 [arg2] "{rsi}" (arg2),
561 [arg3] "{rdx}" (arg3),
562 [arg4] "{r10}" (arg4)
563 : "rcx", "r11")
563 [arg1] "{rdi}" (arg1),
564 [arg2] "{rsi}" (arg2),
565 [arg3] "{rdx}" (arg3),
566 [arg4] "{r10}" (arg4)
567 : "rcx", "r11"
568 );
564569}
565570
566pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
567 asm volatile ("syscall"
571pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
572 return asm volatile ("syscall"
568573 : [ret] "={rax}" (-> usize)
569574 : [number] "{rax}" (number),
570 [arg1] "{rdi}" (arg1),
571 [arg2] "{rsi}" (arg2),
572 [arg3] "{rdx}" (arg3),
573 [arg4] "{r10}" (arg4),
574 [arg5] "{r8}" (arg5)
575 : "rcx", "r11")
575 [arg1] "{rdi}" (arg1),
576 [arg2] "{rsi}" (arg2),
577 [arg3] "{rdx}" (arg3),
578 [arg4] "{r10}" (arg4),
579 [arg5] "{r8}" (arg5)
580 : "rcx", "r11"
581 );
576582}
577583
578pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
579 arg5: usize, arg6: usize) -> usize
580{
581 asm volatile ("syscall"
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"
582594 : [ret] "={rax}" (-> usize)
583595 : [number] "{rax}" (number),
584 [arg1] "{rdi}" (arg1),
585 [arg2] "{rsi}" (arg2),
586 [arg3] "{rdx}" (arg3),
587 [arg4] "{r10}" (arg4),
588 [arg5] "{r8}" (arg5),
589 [arg6] "{r9}" (arg6)
590 : "rcx", "r11")
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 );
591604}
592605
593pub nakedcc fn restore_rt() {
606pub nakedcc fn restore_rt() void {
594607 asm volatile ("syscall"
595608 :
596609 : [number] "{rax}" (usize(SYS_rt_sigreturn))
597 : "rcx", "r11")
610 : "rcx", "r11"
611 );
598612}
599613
600
601614pub const msghdr = extern struct {
602615 msg_name: &u8,
603616 msg_namelen: socklen_t,
std/os/index.zig+1-1
......@@ -24,7 +24,7 @@ test "std.os" {
2424pub const windows = @import("windows/index.zig");
2525pub const darwin = @import("darwin.zig");
2626pub const linux = @import("linux/index.zig");
27pub const freebsd = @import("freebsd.zig");
27pub const freebsd = @import("freebsd/index.zig");
2828pub const zen = @import("zen.zig");
2929pub const posix = switch (builtin.os) {
3030 Os.linux => linux,