hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 7d7decca68ba1b0f3b252d2868d7b857df115973
parent 6f308f1bd2edcc184473a840b9c30644763f7aa4
Author: Mykyta Holubakha <hilobakho@gmail.com>
Date:   Sun, 14 Mar 2021 00:55:45 +0200

rt: epoll syscalls

Diffstat:
Mrt/+linux/syscalls.ha | 40++++++++++++++++++++++++++++++++++++++++
Mrt/+linux/types.ha | 36++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -308,6 +308,46 @@ export fn poll(fds: *pollfd, nfds: nfds_t, timeout: int) (int | errno) = { fds: uintptr: u64, nfds: u64, timeout: u64))?: int; }; +export fn epoll_create1(flags: int) (int | errno) = { + return wrap_return(syscall1(SYS_epoll_create1, flags: u64))?: int; +}; + +export fn epoll_create(size_: int) (int | errno) = { + return epoll_create1(0); +}; + +export fn epoll_ctl( + epfd: int, + op: int, + fd: int, + event: nullable *epoll_event +) (int | errno) = { + return wrap_return(syscall4(SYS_epoll_ctl, + epfd: u64, op: u64, fd: u64, event: uintptr: u64))?: int; +}; + +export fn epoll_pwait( + epfd: int, + events: *epoll_event, + maxevents: int, + timeout: int, + sigmask: nullable *sigset +) (int | errno) = { + return wrap_return(syscall6(SYS_epoll_pwait, + epfd: u64, events: uintptr: u64, + maxevents: u64, timeout: u64, + sigmask: uintptr: u64, size(sigset): u64))?: int; +}; + +export fn epoll_wait( + epfd: int, + events: *epoll_event, + maxevents: int, + timeout: int, +) (int | errno) = { + return epoll_pwait(epfd, events, maxevents, timeout, null); +}; + export fn timerfd_create(clock_id: int, flags: int) (int | errno) = { return wrap_return(syscall2(SYS_timerfd_create, clock_id: u64, flags: u64))?: int; diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha @@ -334,6 +334,42 @@ export type pollfd = struct { revents: i16, }; +export def EPOLL_CLOEXEC: int = O_CLOEXEC; + +// Valid opcodes to issue to sys_epoll_ctl() +export def EPOLL_CTL_ADD: int = 1; +export def EPOLL_CTL_DEL: int = 2; +export def EPOLL_CTL_MOD: int = 3; + +// Epoll event masks +export def EPOLLIN: u32 = 0x00000001; +export def EPOLLPRI: u32 = 0x00000002; +export def EPOLLOUT: u32 = 0x00000004; +export def EPOLLERR: u32 = 0x00000008; +export def EPOLLHUP: u32 = 0x00000010; +export def EPOLLNVAL: u32 = 0x00000020; +export def EPOLLRDNORM: u32 = 0x00000040; +export def EPOLLRDBAND: u32 = 0x00000080; +export def EPOLLWRNORM: u32 = 0x00000100; +export def EPOLLWRBAND: u32 = 0x00000200; +export def EPOLLMSG: u32 = 0x00000400; +export def EPOLLRDHUP: u32 = 0x00002000; +export def EPOLLWAKEUP: u32 = 1 << 29; +export def EPOLLONESHOT: u32 = 1 << 30; +export def EPOLLET: u32 = 1 << 31; + +export type epoll_data = union { + ptr: *void, + fd: int, + u32_: u32, + u64_: u64, +}; + +export type epoll_event = struct { + events: u32, + data: epoll_data, +}; + export def TFD_TIMER_ABSTIME: int = 1; export def TFD_TIMER_CANCEL_ON_SET: int = 2;