| ... | @@ -328,6 +328,45 @@ pub const TIOCGPKT = 0x80045438; | ... | @@ -328,6 +328,45 @@ pub const TIOCGPKT = 0x80045438; |
| 328 | pub const TIOCGPTLCK = 0x80045439; | 328 | pub const TIOCGPTLCK = 0x80045439; |
| 329 | pub const TIOCGEXCL = 0x80045440; | 329 | pub const TIOCGEXCL = 0x80045440; |
| 330 | | 330 | |
| | 331 | pub const EPOLL_CTL_ADD = 1; |
| | 332 | pub const EPOLL_CTL_DEL = 2; |
| | 333 | pub const EPOLL_CTL_MOD = 3; |
| | 334 | |
| | 335 | pub const EPOLLIN = 0x001; |
| | 336 | pub const EPOLLPRI = 0x002; |
| | 337 | pub const EPOLLOUT = 0x004; |
| | 338 | pub const EPOLLRDNORM = 0x040; |
| | 339 | pub const EPOLLRDBAND = 0x080; |
| | 340 | pub const EPOLLWRNORM = 0x100; |
| | 341 | pub const EPOLLWRBAND = 0x200; |
| | 342 | pub const EPOLLMSG = 0x400; |
| | 343 | pub const EPOLLERR = 0x008; |
| | 344 | pub const EPOLLHUP = 0x010; |
| | 345 | pub const EPOLLRDHUP = 0x2000; |
| | 346 | pub const EPOLLEXCLUSIVE = (u32(1) << 28); |
| | 347 | pub const EPOLLWAKEUP = (u32(1) << 29); |
| | 348 | pub const EPOLLONESHOT = (u32(1) << 30); |
| | 349 | pub const EPOLLET = (u32(1) << 31); |
| | 350 | |
| | 351 | pub const CLOCK_REALTIME = 0; |
| | 352 | pub const CLOCK_MONOTONIC = 1; |
| | 353 | pub const CLOCK_PROCESS_CPUTIME_ID = 2; |
| | 354 | pub const CLOCK_THREAD_CPUTIME_ID = 3; |
| | 355 | pub const CLOCK_MONOTONIC_RAW = 4; |
| | 356 | pub const CLOCK_REALTIME_COARSE = 5; |
| | 357 | pub const CLOCK_MONOTONIC_COARSE = 6; |
| | 358 | pub const CLOCK_BOOTTIME = 7; |
| | 359 | pub const CLOCK_REALTIME_ALARM = 8; |
| | 360 | pub const CLOCK_BOOTTIME_ALARM = 9; |
| | 361 | pub const CLOCK_SGI_CYCLE = 10; |
| | 362 | pub const CLOCK_TAI = 11; |
| | 363 | |
| | 364 | pub const TFD_NONBLOCK = O_NONBLOCK; |
| | 365 | pub const TFD_CLOEXEC = O_CLOEXEC; |
| | 366 | |
| | 367 | pub const TFD_TIMER_ABSTIME = 1; |
| | 368 | pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); |
| | 369 | |
| 331 | fn unsigned(s: i32) -> u32 { @bitCast(u32, s) } | 370 | fn unsigned(s: i32) -> u32 { @bitCast(u32, s) } |
| 332 | fn signed(s: u32) -> i32 { @bitCast(i32, s) } | 371 | fn signed(s: u32) -> i32 { @bitCast(i32, s) } |
| 333 | pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) } | 372 | pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) } |
| ... | @@ -734,3 +773,43 @@ pub const timespec = arch.timespec; | ... | @@ -734,3 +773,43 @@ pub const timespec = arch.timespec; |
| 734 | pub fn fstat(fd: i32, stat_buf: &Stat) -> usize { | 773 | pub fn fstat(fd: i32, stat_buf: &Stat) -> usize { |
| 735 | arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)) | 774 | arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)) |
| 736 | } | 775 | } |
| | 776 | |
| | 777 | pub const epoll_data = u64; |
| | 778 | |
| | 779 | pub const epoll_event = extern struct { |
| | 780 | events: u32, |
| | 781 | data: epoll_data |
| | 782 | }; |
| | 783 | |
| | 784 | pub fn epoll_create() -> usize { |
| | 785 | arch.syscall1(arch.SYS_epoll_create, usize(1)) |
| | 786 | } |
| | 787 | |
| | 788 | pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) -> usize { |
| | 789 | arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev)) |
| | 790 | } |
| | 791 | |
| | 792 | pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) -> usize { |
| | 793 | arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout)) |
| | 794 | } |
| | 795 | |
| | 796 | pub fn timerfd_create(clockid: i32, flags: u32) -> usize { |
| | 797 | arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags)) |
| | 798 | } |
| | 799 | |
| | 800 | pub const itimerspec = extern struct { |
| | 801 | it_interval: timespec, |
| | 802 | it_value: timespec |
| | 803 | }; |
| | 804 | |
| | 805 | pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) -> usize { |
| | 806 | arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value)) |
| | 807 | } |
| | 808 | |
| | 809 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) -> usize { |
| | 810 | arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value)) |
| | 811 | } |
| | 812 | |
| | 813 | test "import linux_test" { |
| | 814 | _ = @import("linux_test.zig"); |
| | 815 | } |