| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | const std = @import("../../index.zig"); |
| 2 | 2 | const assert = std.debug.assert; |
| 3 | 3 | const builtin = @import("builtin"); |
| 4 | | const arch = switch (builtin.arch) { |
| 4 | pub use switch (builtin.arch) { |
| 5 | 5 | builtin.Arch.x86_64 => @import("x86_64.zig"), |
| 6 | 6 | builtin.Arch.i386 => @import("i386.zig"), |
| 7 | 7 | else => @compileError("unsupported arch"), |
| ... | ... | @@ -93,27 +93,6 @@ pub const O_RDONLY = 0o0; |
| 93 | 93 | pub const O_WRONLY = 0o1; |
| 94 | 94 | pub const O_RDWR = 0o2; |
| 95 | 95 | |
| 96 | | pub const O_CREAT = arch.O_CREAT; |
| 97 | | pub const O_EXCL = arch.O_EXCL; |
| 98 | | pub const O_NOCTTY = arch.O_NOCTTY; |
| 99 | | pub const O_TRUNC = arch.O_TRUNC; |
| 100 | | pub const O_APPEND = arch.O_APPEND; |
| 101 | | pub const O_NONBLOCK = arch.O_NONBLOCK; |
| 102 | | pub const O_DSYNC = arch.O_DSYNC; |
| 103 | | pub const O_SYNC = arch.O_SYNC; |
| 104 | | pub const O_RSYNC = arch.O_RSYNC; |
| 105 | | pub const O_DIRECTORY = arch.O_DIRECTORY; |
| 106 | | pub const O_NOFOLLOW = arch.O_NOFOLLOW; |
| 107 | | pub const O_CLOEXEC = arch.O_CLOEXEC; |
| 108 | | |
| 109 | | pub const O_ASYNC = arch.O_ASYNC; |
| 110 | | pub const O_DIRECT = arch.O_DIRECT; |
| 111 | | pub const O_LARGEFILE = arch.O_LARGEFILE; |
| 112 | | pub const O_NOATIME = arch.O_NOATIME; |
| 113 | | pub const O_PATH = arch.O_PATH; |
| 114 | | pub const O_TMPFILE = arch.O_TMPFILE; |
| 115 | | pub const O_NDELAY = arch.O_NDELAY; |
| 116 | | |
| 117 | 96 | pub const SEEK_SET = 0; |
| 118 | 97 | pub const SEEK_CUR = 1; |
| 119 | 98 | pub const SEEK_END = 2; |
| ... | ... | @@ -394,65 +373,65 @@ pub fn getErrno(r: usize) usize { |
| 394 | 373 | } |
| 395 | 374 | |
| 396 | 375 | pub 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 | } |
| 399 | 378 | |
| 400 | 379 | pub fn chdir(path: &const u8) usize { |
| 401 | | return arch.syscall1(arch.SYS_chdir, @ptrToInt(path)); |
| 380 | return syscall1(SYS_chdir, @ptrToInt(path)); |
| 402 | 381 | } |
| 403 | 382 | |
| 404 | 383 | pub 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 | } |
| 407 | 386 | |
| 408 | 387 | pub fn fork() usize { |
| 409 | | return arch.syscall0(arch.SYS_fork); |
| 388 | return syscall0(SYS_fork); |
| 410 | 389 | } |
| 411 | 390 | |
| 412 | 391 | pub 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 | } |
| 415 | 394 | |
| 416 | 395 | pub 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 | } |
| 419 | 398 | |
| 420 | 399 | pub fn isatty(fd: i32) bool { |
| 421 | 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 | } |
| 424 | 403 | |
| 425 | 404 | pub 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 | } |
| 428 | 407 | |
| 429 | 408 | pub 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 | } |
| 432 | 411 | |
| 433 | 412 | pub 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 | 414 | @bitCast(usize, offset)); |
| 436 | 415 | } |
| 437 | 416 | |
| 438 | 417 | pub 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 | } |
| 441 | 420 | |
| 442 | 421 | pub 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 | } |
| 445 | 424 | |
| 446 | 425 | pub fn rmdir(path: &const u8) usize { |
| 447 | | return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)); |
| 426 | return syscall1(SYS_rmdir, @ptrToInt(path)); |
| 448 | 427 | } |
| 449 | 428 | |
| 450 | 429 | pub 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 | } |
| 453 | 432 | |
| 454 | 433 | pub 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 | } |
| 457 | 436 | |
| 458 | 437 | pub fn pipe(fd: &[2]i32) usize { |
| ... | ... | @@ -460,84 +439,84 @@ pub fn pipe(fd: &[2]i32) usize { |
| 460 | 439 | } |
| 461 | 440 | |
| 462 | 441 | pub 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 | } |
| 465 | 444 | |
| 466 | 445 | pub 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 | } |
| 469 | 448 | |
| 470 | 449 | pub 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 | } |
| 473 | 452 | |
| 474 | 453 | pub 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 | } |
| 477 | 456 | |
| 478 | 457 | pub 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 | } |
| 481 | 460 | |
| 482 | 461 | pub 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 | } |
| 485 | 464 | |
| 486 | 465 | pub 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 | } |
| 489 | 468 | |
| 490 | 469 | pub fn close(fd: i32) usize { |
| 491 | | return arch.syscall1(arch.SYS_close, usize(fd)); |
| 470 | return syscall1(SYS_close, usize(fd)); |
| 492 | 471 | } |
| 493 | 472 | |
| 494 | 473 | pub 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 | } |
| 497 | 476 | |
| 498 | 477 | pub fn exit(status: i32) noreturn { |
| 499 | | _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status))); |
| 478 | _ = syscall1(SYS_exit, @bitCast(usize, isize(status))); |
| 500 | 479 | unreachable; |
| 501 | 480 | } |
| 502 | 481 | |
| 503 | 482 | pub 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 | } |
| 506 | 485 | |
| 507 | 486 | pub 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 | } |
| 510 | 489 | |
| 511 | 490 | pub fn unlink(path: &const u8) usize { |
| 512 | | return arch.syscall1(arch.SYS_unlink, @ptrToInt(path)); |
| 491 | return syscall1(SYS_unlink, @ptrToInt(path)); |
| 513 | 492 | } |
| 514 | 493 | |
| 515 | 494 | pub 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 | } |
| 518 | 497 | |
| 519 | 498 | pub 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 | } |
| 522 | 501 | |
| 523 | 502 | pub fn setuid(uid: u32) usize { |
| 524 | | return arch.syscall1(arch.SYS_setuid, uid); |
| 503 | return syscall1(SYS_setuid, uid); |
| 525 | 504 | } |
| 526 | 505 | |
| 527 | 506 | pub fn setgid(gid: u32) usize { |
| 528 | | return arch.syscall1(arch.SYS_setgid, gid); |
| 507 | return syscall1(SYS_setgid, gid); |
| 529 | 508 | } |
| 530 | 509 | |
| 531 | 510 | pub 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 | } |
| 534 | 513 | |
| 535 | 514 | pub 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 | } |
| 538 | 517 | |
| 539 | 518 | pub 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 | } |
| 542 | 521 | |
| 543 | 522 | pub 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 | 527 | .handler = act.handler, |
| 549 | 528 | .flags = act.flags | SA_RESTORER, |
| 550 | 529 | .mask = undefined, |
| 551 | | .restorer = @ptrCast(extern fn()void, arch.restore_rt), |
| 530 | .restorer = @ptrCast(extern fn()void, restore_rt), |
| 552 | 531 | }; |
| 553 | 532 | var ksa_old: k_sigaction = undefined; |
| 554 | 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 | 535 | const err = getErrno(result); |
| 557 | 536 | if (err != 0) { |
| 558 | 537 | return result; |
| ... | ... | @@ -592,22 +571,22 @@ pub const empty_sigset = []usize{0} ** sigset_t.len; |
| 592 | 571 | pub fn raise(sig: i32) usize { |
| 593 | 572 | var set: sigset_t = undefined; |
| 594 | 573 | blockAppSignals(&set); |
| 595 | | const tid = i32(arch.syscall0(arch.SYS_gettid)); |
| 596 | | const ret = arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig)); |
| 574 | const tid = i32(syscall0(SYS_gettid)); |
| 575 | const ret = syscall2(SYS_tkill, usize(tid), usize(sig)); |
| 597 | 576 | restoreSignals(&set); |
| 598 | 577 | return ret; |
| 599 | 578 | } |
| 600 | 579 | |
| 601 | 580 | fn 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 | } |
| 604 | 583 | |
| 605 | 584 | fn 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 | } |
| 608 | 587 | |
| 609 | 588 | fn 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 | } |
| 612 | 591 | |
| 613 | 592 | pub fn sigaddset(set: &sigset_t, sig: u6) void { |
| ... | ... | @@ -653,61 +632,61 @@ pub const iovec = extern struct { |
| 653 | 632 | }; |
| 654 | 633 | |
| 655 | 634 | pub 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 | } |
| 658 | 637 | |
| 659 | 638 | pub 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 | } |
| 662 | 641 | |
| 663 | 642 | pub 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 | } |
| 666 | 645 | |
| 667 | 646 | pub 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 | } |
| 670 | 649 | |
| 671 | 650 | pub 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 | } |
| 674 | 653 | |
| 675 | | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) usize { |
| 676 | | return arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags); |
| 654 | pub fn sendmsg(fd: i32, msg: &const msghdr, flags: u32) usize { |
| 655 | return syscall3(SYS_sendmsg, usize(fd), @ptrToInt(msg), flags); |
| 677 | 656 | } |
| 678 | 657 | |
| 679 | 658 | pub 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 | } |
| 682 | 661 | |
| 683 | | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) usize { |
| 684 | | return arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags); |
| 662 | pub fn recvmsg(fd: i32, msg: &msghdr, flags: u32) usize { |
| 663 | return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags); |
| 685 | 664 | } |
| 686 | 665 | |
| 687 | 666 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, |
| 688 | 667 | 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 | } |
| 692 | 671 | |
| 693 | 672 | pub 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 | } |
| 696 | 675 | |
| 697 | 676 | pub 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 | } |
| 700 | 679 | |
| 701 | 680 | pub 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 | } |
| 704 | 683 | |
| 705 | 684 | pub 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 | } |
| 708 | 687 | |
| 709 | 688 | pub 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 | } |
| 712 | 691 | |
| 713 | 692 | 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 | } |
| 716 | 695 | |
| 717 | 696 | pub 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 | } |
| 720 | 699 | |
| 721 | 700 | // error NameTooLong; |
| ... | ... | @@ -746,11 +725,8 @@ pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: |
| 746 | 725 | // return ifr.ifr_ifindex; |
| 747 | 726 | // } |
| 748 | 727 | |
| 749 | | pub const Stat = arch.Stat; |
| 750 | | pub const timespec = arch.timespec; |
| 751 | | |
| 752 | 728 | pub 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 | } |
| 755 | 731 | |
| 756 | 732 | pub const epoll_data = extern union { |
| ... | ... | @@ -770,19 +746,19 @@ pub fn epoll_create() usize { |
| 770 | 746 | } |
| 771 | 747 | |
| 772 | 748 | pub fn epoll_create1(flags: usize) usize { |
| 773 | | return arch.syscall1(arch.SYS_epoll_create1, flags); |
| 749 | return syscall1(SYS_epoll_create1, flags); |
| 774 | 750 | } |
| 775 | 751 | |
| 776 | 752 | pub 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 | } |
| 779 | 755 | |
| 780 | 756 | pub 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 | } |
| 783 | 759 | |
| 784 | 760 | pub 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 | } |
| 787 | 763 | |
| 788 | 764 | pub const itimerspec = extern struct { |
| ... | ... | @@ -791,11 +767,11 @@ pub const itimerspec = extern struct { |
| 791 | 767 | }; |
| 792 | 768 | |
| 793 | 769 | pub 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 | } |
| 796 | 772 | |
| 797 | 773 | pub 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 | } |
| 800 | 776 | |
| 801 | 777 | test "import linux test" { |