Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
linux: add epoll syscalls
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Jun 22, 2012
1 parent e132075 commit f91e6be
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
108 changes: 108 additions & 0 deletions src/unix/linux/syscalls.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions src/unix/linux/syscalls.h
Expand Up @@ -25,6 +25,7 @@
#undef _GNU_SOURCE
#define _GNU_SOURCE

#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/types.h>
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit f91e6be

Please sign in to comment.