authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-24 15:57:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-24 15:57:36-04:00
log2cff31937f6008769ad1034f9451d136d03c06bb
treebcf445bcafb79d9166146727af806ae9c7362e38
parent7350181a4a778f9d03186e5123beffdf80f58606

std.os.linux exposes syscall functions and syscall numbers


1 files changed, 67 insertions(+), 91 deletions(-)

std/os/linux/index.zig+67-91
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const std = @import("../../index.zig");1const std = @import("../../index.zig");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const arch = switch (builtin.arch) {4pub use switch (builtin.arch) {
5 builtin.Arch.x86_64 => @import("x86_64.zig"),5 builtin.Arch.x86_64 => @import("x86_64.zig"),
6 builtin.Arch.i386 => @import("i386.zig"),6 builtin.Arch.i386 => @import("i386.zig"),
7 else => @compileError("unsupported arch"),7 else => @compileError("unsupported arch"),
...@@ -93,27 +93,6 @@ pub const O_RDONLY = 0o0;...@@ -93,27 +93,6 @@ pub const O_RDONLY = 0o0;
93pub const O_WRONLY = 0o1;93pub const O_WRONLY = 0o1;
94pub const O_RDWR = 0o2;94pub const O_RDWR = 0o2;
9595
96pub const O_CREAT = arch.O_CREAT;
97pub const O_EXCL = arch.O_EXCL;
98pub const O_NOCTTY = arch.O_NOCTTY;
99pub const O_TRUNC = arch.O_TRUNC;
100pub const O_APPEND = arch.O_APPEND;
101pub const O_NONBLOCK = arch.O_NONBLOCK;
102pub const O_DSYNC = arch.O_DSYNC;
103pub const O_SYNC = arch.O_SYNC;
104pub const O_RSYNC = arch.O_RSYNC;
105pub const O_DIRECTORY = arch.O_DIRECTORY;
106pub const O_NOFOLLOW = arch.O_NOFOLLOW;
107pub const O_CLOEXEC = arch.O_CLOEXEC;
108
109pub const O_ASYNC = arch.O_ASYNC;
110pub const O_DIRECT = arch.O_DIRECT;
111pub const O_LARGEFILE = arch.O_LARGEFILE;
112pub const O_NOATIME = arch.O_NOATIME;
113pub const O_PATH = arch.O_PATH;
114pub const O_TMPFILE = arch.O_TMPFILE;
115pub const O_NDELAY = arch.O_NDELAY;
116
117pub const SEEK_SET = 0;96pub const SEEK_SET = 0;
118pub const SEEK_CUR = 1;97pub const SEEK_CUR = 1;
119pub const SEEK_END = 2;98pub const SEEK_END = 2;
...@@ -394,65 +373,65 @@ pub fn getErrno(r: usize) usize {...@@ -394,65 +373,65 @@ pub fn getErrno(r: usize) usize {
394}373}
395374
396pub fn dup2(old: i32, new: i32) usize {375pub fn dup2(old: i32, new: i32) usize {
397 return arch.syscall2(arch.SYS_dup2, usize(old), usize(new));376 return syscall2(SYS_dup2, usize(old), usize(new));
398}377}
399378
400pub fn chdir(path: &const u8) usize {379pub fn chdir(path: &const u8) usize {
401 return arch.syscall1(arch.SYS_chdir, @ptrToInt(path));380 return syscall1(SYS_chdir, @ptrToInt(path));
402}381}
403382
404pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {383pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize {
405 return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));384 return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
406}385}
407386
408pub fn fork() usize {387pub fn fork() usize {
409 return arch.syscall0(arch.SYS_fork);388 return syscall0(SYS_fork);
410}389}
411390
412pub fn getcwd(buf: &u8, size: usize) usize {391pub fn getcwd(buf: &u8, size: usize) usize {
413 return arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size);392 return syscall2(SYS_getcwd, @ptrToInt(buf), size);
414}393}
415394
416pub fn getdents(fd: i32, dirp: &u8, count: usize) usize {395pub fn getdents(fd: i32, dirp: &u8, count: usize) usize {
417 return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count);396 return syscall3(SYS_getdents, usize(fd), @ptrToInt(dirp), count);
418}397}
419398
420pub fn isatty(fd: i32) bool {399pub fn isatty(fd: i32) bool {
421 var wsz: winsize = undefined;400 var wsz: winsize = undefined;
422 return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;401 return syscall3(SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
423}402}
424403
425pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {404pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize {
426 return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);405 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
427}406}
428407
429pub fn mkdir(path: &const u8, mode: u32) usize {408pub fn mkdir(path: &const u8, mode: u32) usize {
430 return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode);409 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
431}410}
432411
433pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {412pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize {
434 return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),413 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
435 @bitCast(usize, offset));414 @bitCast(usize, offset));
436}415}
437416
438pub fn munmap(address: &u8, length: usize) usize {417pub fn munmap(address: &u8, length: usize) usize {
439 return arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length);418 return syscall2(SYS_munmap, @ptrToInt(address), length);
440}419}
441420
442pub fn read(fd: i32, buf: &u8, count: usize) usize {421pub fn read(fd: i32, buf: &u8, count: usize) usize {
443 return arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count);422 return syscall3(SYS_read, usize(fd), @ptrToInt(buf), count);
444}423}
445424
446pub fn rmdir(path: &const u8) usize {425pub fn rmdir(path: &const u8) usize {
447 return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path));426 return syscall1(SYS_rmdir, @ptrToInt(path));
448}427}
449428
450pub fn symlink(existing: &const u8, new: &const u8) usize {429pub fn symlink(existing: &const u8, new: &const u8) usize {
451 return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new));430 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
452}431}
453432
454pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize {433pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize {
455 return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset);434 return syscall4(SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
456}435}
457436
458pub fn pipe(fd: &[2]i32) usize {437pub fn pipe(fd: &[2]i32) usize {
...@@ -460,84 +439,84 @@ pub fn pipe(fd: &[2]i32) usize {...@@ -460,84 +439,84 @@ pub fn pipe(fd: &[2]i32) usize {
460}439}
461440
462pub fn pipe2(fd: &[2]i32, flags: usize) usize {441pub fn pipe2(fd: &[2]i32, flags: usize) usize {
463 return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags);442 return syscall2(SYS_pipe2, @ptrToInt(fd), flags);
464}443}
465444
466pub fn write(fd: i32, buf: &const u8, count: usize) usize {445pub fn write(fd: i32, buf: &const u8, count: usize) usize {
467 return arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count);446 return syscall3(SYS_write, usize(fd), @ptrToInt(buf), count);
468}447}
469448
470pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize {449pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize {
471 return arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset);450 return syscall4(SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset);
472}451}
473452
474pub fn rename(old: &const u8, new: &const u8) usize {453pub fn rename(old: &const u8, new: &const u8) usize {
475 return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new));454 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
476}455}
477456
478pub fn open(path: &const u8, flags: u32, perm: usize) usize {457pub fn open(path: &const u8, flags: u32, perm: usize) usize {
479 return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm);458 return syscall3(SYS_open, @ptrToInt(path), flags, perm);
480}459}
481460
482pub fn create(path: &const u8, perm: usize) usize {461pub fn create(path: &const u8, perm: usize) usize {
483 return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm);462 return syscall2(SYS_creat, @ptrToInt(path), perm);
484}463}
485464
486pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize {465pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize {
487 return arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode);466 return syscall4(SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode);
488}467}
489468
490pub fn close(fd: i32) usize {469pub fn close(fd: i32) usize {
491 return arch.syscall1(arch.SYS_close, usize(fd));470 return syscall1(SYS_close, usize(fd));
492}471}
493472
494pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {473pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize {
495 return arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos);474 return syscall3(SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos);
496}475}
497476
498pub fn exit(status: i32) noreturn {477pub fn exit(status: i32) noreturn {
499 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));478 _ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
500 unreachable;479 unreachable;
501}480}
502481
503pub fn getrandom(buf: &u8, count: usize, flags: u32) usize {482pub fn getrandom(buf: &u8, count: usize, flags: u32) usize {
504 return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags));483 return syscall3(SYS_getrandom, @ptrToInt(buf), count, usize(flags));
505}484}
506485
507pub fn kill(pid: i32, sig: i32) usize {486pub fn kill(pid: i32, sig: i32) usize {
508 return arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig));487 return syscall2(SYS_kill, @bitCast(usize, isize(pid)), usize(sig));
509}488}
510489
511pub fn unlink(path: &const u8) usize {490pub fn unlink(path: &const u8) usize {
512 return arch.syscall1(arch.SYS_unlink, @ptrToInt(path));491 return syscall1(SYS_unlink, @ptrToInt(path));
513}492}
514493
515pub fn waitpid(pid: i32, status: &i32, options: i32) usize {494pub fn waitpid(pid: i32, status: &i32, options: i32) usize {
516 return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);495 return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
517}496}
518497
519pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {498pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {
520 return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));499 return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
521}500}
522501
523pub fn setuid(uid: u32) usize {502pub fn setuid(uid: u32) usize {
524 return arch.syscall1(arch.SYS_setuid, uid);503 return syscall1(SYS_setuid, uid);
525}504}
526505
527pub fn setgid(gid: u32) usize {506pub fn setgid(gid: u32) usize {
528 return arch.syscall1(arch.SYS_setgid, gid);507 return syscall1(SYS_setgid, gid);
529}508}
530509
531pub fn setreuid(ruid: u32, euid: u32) usize {510pub fn setreuid(ruid: u32, euid: u32) usize {
532 return arch.syscall2(arch.SYS_setreuid, ruid, euid);511 return syscall2(SYS_setreuid, ruid, euid);
533}512}
534513
535pub fn setregid(rgid: u32, egid: u32) usize {514pub fn setregid(rgid: u32, egid: u32) usize {
536 return arch.syscall2(arch.SYS_setregid, rgid, egid);515 return syscall2(SYS_setregid, rgid, egid);
537}516}
538517
539pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {518pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
540 return arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8);519 return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8);
541}520}
542521
543pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {522pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
...@@ -548,11 +527,11 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti...@@ -548,11 +527,11 @@ pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigacti
548 .handler = act.handler,527 .handler = act.handler,
549 .flags = act.flags | SA_RESTORER,528 .flags = act.flags | SA_RESTORER,
550 .mask = undefined,529 .mask = undefined,
551 .restorer = @ptrCast(extern fn()void, arch.restore_rt),530 .restorer = @ptrCast(extern fn()void, restore_rt),
552 };531 };
553 var ksa_old: k_sigaction = undefined;532 var ksa_old: k_sigaction = undefined;
554 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);533 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
555 const result = arch.syscall4(arch.SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask)));534 const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), @sizeOf(@typeOf(ksa.mask)));
556 const err = getErrno(result);535 const err = getErrno(result);
557 if (err != 0) {536 if (err != 0) {
558 return result;537 return result;
...@@ -592,22 +571,22 @@ pub const empty_sigset = []usize{0} ** sigset_t.len;...@@ -592,22 +571,22 @@ pub const empty_sigset = []usize{0} ** sigset_t.len;
592pub fn raise(sig: i32) usize {571pub fn raise(sig: i32) usize {
593 var set: sigset_t = undefined;572 var set: sigset_t = undefined;
594 blockAppSignals(&set);573 blockAppSignals(&set);
595 const tid = i32(arch.syscall0(arch.SYS_gettid));574 const tid = i32(syscall0(SYS_gettid));
596 const ret = arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig));575 const ret = syscall2(SYS_tkill, usize(tid), usize(sig));
597 restoreSignals(&set);576 restoreSignals(&set);
598 return ret;577 return ret;
599}578}
600579
601fn blockAllSignals(set: &sigset_t) void {580fn blockAllSignals(set: &sigset_t) void {
602 _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8);581 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8);
603}582}
604583
605fn blockAppSignals(set: &sigset_t) void {584fn blockAppSignals(set: &sigset_t) void {
606 _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8);585 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8);
607}586}
608587
609fn restoreSignals(set: &sigset_t) void {588fn restoreSignals(set: &sigset_t) void {
610 _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8);589 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8);
611}590}
612591
613pub fn sigaddset(set: &sigset_t, sig: u6) void {592pub fn sigaddset(set: &sigset_t, sig: u6) void {
...@@ -653,61 +632,61 @@ pub const iovec = extern struct {...@@ -653,61 +632,61 @@ pub const iovec = extern struct {
653};632};
654633
655pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {634pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
656 return arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len));635 return syscall3(SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len));
657}636}
658637
659pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {638pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
660 return arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len));639 return syscall3(SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len));
661}640}
662641
663pub fn socket(domain: i32, socket_type: i32, protocol: i32) usize {642pub fn socket(domain: i32, socket_type: i32, protocol: i32) usize {
664 return arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol));643 return syscall3(SYS_socket, usize(domain), usize(socket_type), usize(protocol));
665}644}
666645
667pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) usize {646pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) usize {
668 return arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen));647 return syscall5(SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen));
669}648}
670649
671pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) usize {650pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) usize {
672 return arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen));651 return syscall5(SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen));
673}652}
674653
675pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) usize {654pub fn sendmsg(fd: i32, msg: &const msghdr, flags: u32) usize {
676 return arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags);655 return syscall3(SYS_sendmsg, usize(fd), @ptrToInt(msg), flags);
677}656}
678657
679pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize {658pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize {
680 return arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len));659 return syscall3(SYS_connect, usize(fd), @ptrToInt(addr), usize(len));
681}660}
682661
683pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) usize {662pub fn recvmsg(fd: i32, msg: &msghdr, flags: u32) usize {
684 return arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);663 return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);
685}664}
686665
687pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,666pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
688 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize667 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize
689{668{
690 return arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));669 return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
691}670}
692671
693pub fn shutdown(fd: i32, how: i32) usize {672pub fn shutdown(fd: i32, how: i32) usize {
694 return arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how));673 return syscall2(SYS_shutdown, usize(fd), usize(how));
695}674}
696675
697pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize {676pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize {
698 return arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len));677 return syscall3(SYS_bind, usize(fd), @ptrToInt(addr), usize(len));
699}678}
700679
701pub fn listen(fd: i32, backlog: i32) usize {680pub fn listen(fd: i32, backlog: i32) usize {
702 return arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog));681 return syscall2(SYS_listen, usize(fd), usize(backlog));
703}682}
704683
705pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize {684pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize {
706 return arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen));685 return syscall6(SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen));
707}686}
708687
709pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {688pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize {
710 return arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0]));689 return syscall4(SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0]));
711}690}
712691
713pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {692pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
...@@ -715,7 +694,7 @@ pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {...@@ -715,7 +694,7 @@ pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize {
715}694}
716695
717pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize {696pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize {
718 return arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags);697 return syscall4(SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags);
719}698}
720699
721// error NameTooLong;700// error NameTooLong;
...@@ -746,11 +725,8 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags:...@@ -746,11 +725,8 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags:
746// return ifr.ifr_ifindex;725// return ifr.ifr_ifindex;
747// }726// }
748727
749pub const Stat = arch.Stat;
750pub const timespec = arch.timespec;
751
752pub fn fstat(fd: i32, stat_buf: &Stat) usize {728pub fn fstat(fd: i32, stat_buf: &Stat) usize {
753 return arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf));729 return syscall2(SYS_fstat, usize(fd), @ptrToInt(stat_buf));
754}730}
755731
756pub const epoll_data = extern union {732pub const epoll_data = extern union {
...@@ -770,19 +746,19 @@ pub fn epoll_create() usize {...@@ -770,19 +746,19 @@ pub fn epoll_create() usize {
770}746}
771747
772pub fn epoll_create1(flags: usize) usize {748pub fn epoll_create1(flags: usize) usize {
773 return arch.syscall1(arch.SYS_epoll_create1, flags);749 return syscall1(SYS_epoll_create1, flags);
774}750}
775751
776pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) usize {752pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) usize {
777 return arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));753 return syscall4(SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));
778}754}
779755
780pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: u32, timeout: i32) usize {756pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: u32, timeout: i32) usize {
781 return arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));757 return syscall4(SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));
782}758}
783759
784pub fn timerfd_create(clockid: i32, flags: u32) usize {760pub fn timerfd_create(clockid: i32, flags: u32) usize {
785 return arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags));761 return syscall2(SYS_timerfd_create, usize(clockid), usize(flags));
786}762}
787763
788pub const itimerspec = extern struct {764pub const itimerspec = extern struct {
...@@ -791,11 +767,11 @@ pub const itimerspec = extern struct {...@@ -791,11 +767,11 @@ pub const itimerspec = extern struct {
791};767};
792768
793pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize {769pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize {
794 return arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value));770 return syscall2(SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value));
795}771}
796772
797pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize {773pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize {
798 return arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value));774 return syscall4(SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value));
799}775}
800776
801test "import linux test" {777test "import linux test" {