| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | const std = @import("../../index.zig"); | 1 | const std = @import("../../index.zig"); |
| 2 | const assert = std.debug.assert; | 2 | const assert = std.debug.assert; |
| 3 | const builtin = @import("builtin"); | 3 | const builtin = @import("builtin"); |
| 4 | const arch = switch (builtin.arch) { | 4 | pub 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; |
| 93 | pub const O_WRONLY = 0o1; | 93 | pub const O_WRONLY = 0o1; |
| 94 | pub const O_RDWR = 0o2; | 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 | pub const SEEK_SET = 0; | 96 | pub const SEEK_SET = 0; |
| 118 | pub const SEEK_CUR = 1; | 97 | pub const SEEK_CUR = 1; |
| 119 | pub const SEEK_END = 2; | 98 | pub 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 | } |
| 395 | | 374 | |
| 396 | pub fn dup2(old: i32, new: i32) usize { | 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 | pub fn chdir(path: &const u8) usize { | 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 | pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) usize { | 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 | pub fn fork() usize { | 387 | pub fn fork() usize { |
| 409 | return arch.syscall0(arch.SYS_fork); | 388 | return syscall0(SYS_fork); |
| 410 | } | 389 | } |
| 411 | | 390 | |
| 412 | pub fn getcwd(buf: &u8, size: usize) usize { | 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 | pub fn getdents(fd: i32, dirp: &u8, count: usize) usize { | 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 | pub fn isatty(fd: i32) bool { | 399 | pub 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 | } |
| 424 | | 403 | |
| 425 | pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) usize { | 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 | pub fn mkdir(path: &const u8, mode: u32) usize { | 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 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { | 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 | @bitCast(usize, offset)); | 414 | @bitCast(usize, offset)); |
| 436 | } | 415 | } |
| 437 | | 416 | |
| 438 | pub fn munmap(address: &u8, length: usize) usize { | 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 | pub fn read(fd: i32, buf: &u8, count: usize) usize { | 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 | pub fn rmdir(path: &const u8) usize { | 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 | pub fn symlink(existing: &const u8, new: &const u8) usize { | 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 | pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) usize { | 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 | pub fn pipe(fd: &[2]i32) usize { | 437 | pub 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 | } |
| 461 | | 440 | |
| 462 | pub fn pipe2(fd: &[2]i32, flags: usize) usize { | 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 | pub fn write(fd: i32, buf: &const u8, count: usize) usize { | 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 | pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) usize { | 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 | pub fn rename(old: &const u8, new: &const u8) usize { | 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 | pub fn open(path: &const u8, flags: u32, perm: usize) usize { | 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 | pub fn create(path: &const u8, perm: usize) usize { | 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 | pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) usize { | 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 | pub fn close(fd: i32) usize { | 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 | pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { | 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 | pub fn exit(status: i32) noreturn { | 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 | unreachable; | 479 | unreachable; |
| 501 | } | 480 | } |
| 502 | | 481 | |
| 503 | pub fn getrandom(buf: &u8, count: usize, flags: u32) usize { | 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 | pub fn kill(pid: i32, sig: i32) usize { | 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 | pub fn unlink(path: &const u8) usize { | 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 | pub fn waitpid(pid: i32, status: &i32, options: i32) usize { | 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 | pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize { | 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 | pub fn setuid(uid: u32) usize { | 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 | pub fn setgid(gid: u32) usize { | 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 | pub fn setreuid(ruid: u32, euid: u32) usize { | 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 | pub fn setregid(rgid: u32, egid: u32) usize { | 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 | pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize { | 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 | pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize { | 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,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; |
| 592 | pub fn raise(sig: i32) usize { | 571 | pub 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 | } |
| 600 | | 579 | |
| 601 | fn blockAllSignals(set: &sigset_t) void { | 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 | fn blockAppSignals(set: &sigset_t) void { | 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 | fn restoreSignals(set: &sigset_t) void { | 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 | pub fn sigaddset(set: &sigset_t, sig: u6) void { | 592 | pub 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 | }; |
| 654 | | 633 | |
| 655 | pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { | 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 | pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { | 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 | pub fn socket(domain: i32, socket_type: i32, protocol: i32) usize { | 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 | pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) usize { | 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 | pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) usize { | 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 { | 654 | pub 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 | } |
| 678 | | 657 | |
| 679 | pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) usize { | 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 { | 662 | pub 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 | } |
| 686 | | 665 | |
| 687 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, | 666 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, |
| 688 | noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize | 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 | pub fn shutdown(fd: i32, how: i32) usize { | 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 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) usize { | 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 | pub fn listen(fd: i32, backlog: i32) usize { | 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 | pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) usize { | 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 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usize { | 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 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { | 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,7 +694,7 @@ pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) usize { |
| 715 | } | 694 | } |
| 716 | | 695 | |
| 717 | pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) usize { | 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 | // 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 | // } |
| 748 | | 727 | |
| 749 | pub const Stat = arch.Stat; | | |
| 750 | pub const timespec = arch.timespec; | | |
| 751 | | | |
| 752 | pub fn fstat(fd: i32, stat_buf: &Stat) usize { | 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 | pub const epoll_data = extern union { | 732 | pub 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 | } |
| 771 | | 747 | |
| 772 | pub fn epoll_create1(flags: usize) usize { | 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 | pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) usize { | 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 | pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: u32, timeout: i32) usize { | 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 | pub fn timerfd_create(clockid: i32, flags: u32) usize { | 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 | pub const itimerspec = extern struct { | 764 | pub const itimerspec = extern struct { |
| ... | @@ -791,11 +767,11 @@ pub const itimerspec = extern struct { | ... | @@ -791,11 +767,11 @@ pub const itimerspec = extern struct { |
| 791 | }; | 767 | }; |
| 792 | | 768 | |
| 793 | pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize { | 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 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) usize { | 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 | test "import linux test" { | 777 | test "import linux test" { |