diff --git a/src/unix/linux/syscalls.c b/src/unix/linux/syscalls.c index 5eb826b7..793cb6c4 100644 --- a/src/unix/linux/syscalls.c +++ b/src/unix/linux/syscalls.c @@ -69,6 +69,56 @@ # endif #endif /* __NR_eventfd2 */ +#ifndef __NR_epoll_create +# if __x86_64__ +# define __NR_epoll_create 213 +# elif __i386__ +# define __NR_epoll_create 254 +# elif __arm__ +# define __NR_epoll_create (UV_SYSCALL_BASE + 250) +# endif +#endif /* __NR_epoll_create */ + +#ifndef __NR_epoll_create1 +# if __x86_64__ +# define __NR_epoll_create1 291 +# elif __i386__ +# define __NR_epoll_create1 329 +# elif __arm__ +# define __NR_epoll_create1 (UV_SYSCALL_BASE + 357) +# endif +#endif /* __NR_epoll_create1 */ + +#ifndef __NR_epoll_ctl +# if __x86_64__ +# define __NR_epoll_ctl 233 /* used to be 214 */ +# elif __i386__ +# define __NR_epoll_ctl 255 +# elif __arm__ +# define __NR_epoll_ctl (UV_SYSCALL_BASE + 251) +# endif +#endif /* __NR_epoll_ctl */ + +#ifndef __NR_epoll_wait +# if __x86_64__ +# define __NR_epoll_wait 232 /* used to be 215 */ +# elif __i386__ +# define __NR_epoll_wait 256 +# elif __arm__ +# define __NR_epoll_wait (UV_SYSCALL_BASE + 252) +# endif +#endif /* __NR_epoll_wait */ + +#ifndef __NR_epoll_pwait +# if __x86_64__ +# define __NR_epoll_pwait 281 +# elif __i386__ +# define __NR_epoll_pwait 319 +# elif __arm__ +# define __NR_epoll_pwait (UV_SYSCALL_BASE + 346) +# endif +#endif /* __NR_epoll_pwait */ + #ifndef __NR_inotify_init # if __x86_64__ # define __NR_inotify_init 253 @@ -185,6 +235,64 @@ int uv__eventfd2(unsigned int count, int flags) { } +int uv__epoll_create(void) { +#if __NR_epoll_create + return syscall(__NR_epoll_create); +#else + return errno = ENOSYS, -1; +#endif +} + + +int uv__epoll_create1(int flags) { +#if __NR_epoll_create1 + return syscall(__NR_epoll_create1, flags); +#else + return errno = ENOSYS, -1; +#endif +} + + +int uv__epoll_ctl(int epfd, int op, int fd, struct uv__epoll_event* events) { +#if __NR_epoll_ctl + return syscall(__NR_epoll_ctl, epfd, op, fd, events); +#else + return errno = ENOSYS, -1; +#endif +} + + +int uv__epoll_wait(int epfd, + struct uv__epoll_event* events, + int nevents, + int timeout) { +#if __NR_epoll_wait + return syscall(__NR_epoll_wait, epfd, events, nevents, timeout); +#else + return errno = ENOSYS, -1; +#endif +} + + +int uv__epoll_pwait(int epfd, + struct uv__epoll_event* events, + int nevents, + int timeout, + const sigset_t* sigmask) { +#if __NR_epoll_pwait + return syscall(__NR_epoll_pwait, + epfd, + events, + nevents, + timeout, + sigmask, + sizeof(*sigmask)); +#else + return errno = ENOSYS, -1; +#endif +} + + int uv__inotify_init(void) { #if __NR_inotify_init return syscall(__NR_inotify_init); diff --git a/src/unix/linux/syscalls.h b/src/unix/linux/syscalls.h index ec70fd96..527d8c57 100644 --- a/src/unix/linux/syscalls.h +++ b/src/unix/linux/syscalls.h @@ -25,6 +25,7 @@ #undef _GNU_SOURCE #define _GNU_SOURCE +#include #include #include #include @@ -41,6 +42,19 @@ #define UV__SOCK_CLOEXEC UV__O_CLOEXEC #define UV__SOCK_NONBLOCK UV__O_NONBLOCK +/* epoll flags */ +#define UV__EPOLL_CLOEXEC UV__O_CLOEXEC +#define UV__EPOLL_CTL_ADD 1 +#define UV__EPOLL_CTL_DEL 2 +#define UV__EPOLL_CTL_MOD 3 + +#define UV__EPOLLIN 1 +#define UV__EPOLLOUT 4 +#define UV__EPOLLERR 8 +#define UV__EPOLLHUP 16 +#define UV__EPOLLONESHOT 0x40000000 +#define UV__EPOLLET 0x80000000 + /* inotify flags */ #define UV__IN_ACCESS 0x001 #define UV__IN_MODIFY 0x002 @@ -55,6 +69,11 @@ #define UV__IN_DELETE_SELF 0x400 #define UV__IN_MOVE_SELF 0x800 +struct uv__epoll_event { + __u32 events; + __u64 data; +} __attribute__((packed)); + struct uv__inotify_event { __s32 wd; __u32 mask; @@ -70,6 +89,18 @@ struct uv__mmsghdr { int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags); int uv__eventfd(unsigned int count); +int uv__epoll_create(void); +int uv__epoll_create1(int flags); +int uv__epoll_ctl(int epfd, int op, int fd, struct uv__epoll_event *ev); +int uv__epoll_wait(int epfd, + struct uv__epoll_event* events, + int nevents, + int timeout); +int uv__epoll_pwait(int epfd, + struct uv__epoll_event* events, + int nevents, + int timeout, + const sigset_t* sigmask); int uv__eventfd2(unsigned int count, int flags); int uv__inotify_init(void); int uv__inotify_init1(int flags);