epoll.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <bits/types.h>
  2. #include <bits/signal.h>
  3. #include <syscall.h>
  4. #define EPOLLIN (1<<0)
  5. #define EPOLLPRI (1<<1)
  6. #define EPOLLOUT (1<<2)
  7. #define EPOLLERR (1<<3)
  8. #define EPOLLHUP (1<<4)
  9. #define EPOLLNVAL (1<<5)
  10. #define EPOLLRDNORM (1<<6)
  11. #define EPOLLRDBAND (1<<7)
  12. #define EPOLLWRNORM (1<<8)
  13. #define EPOLLWRBAND (1<<9)
  14. #define EPOLLMSG (1<<10)
  15. #define EPOLLRDHUP (1<<13)
  16. #define EPOLLEXCLUSIVE (1<<28)
  17. #define EPOLLWAKEUP (1<<29)
  18. #define EPOLLONESHOT (1<<30)
  19. #define EPOLLET (1<<31)
  20. #define EPOLL_CTL_ADD 1
  21. #define EPOLL_CTL_DEL 2
  22. #define EPOLL_CTL_MOD 3
  23. struct epoll_event {
  24. uint32_t events;
  25. union {
  26. void *ptr;
  27. int fd;
  28. uint32_t u32;
  29. uint64_t u64;
  30. } data;
  31. } __attribute__((packed));
  32. static inline int sys_epoll_create(void)
  33. {
  34. return syscall1(NR_epoll_create, 1);
  35. }
  36. static inline int sys_epoll_create1(int flags)
  37. {
  38. return syscall1(NR_epoll_create1, flags);
  39. }
  40. static inline int sys_epoll_ctl(int epfd, int op, int fd, struct epoll_event* ev)
  41. {
  42. return syscall4(NR_epoll_ctl, epfd, op, fd, (long)ev);
  43. }
  44. static inline int sys_epoll_wait(int epfd, struct epoll_event* out, int cnt, int tmo)
  45. {
  46. return syscall4(NR_epoll_wait, epfd, (long)out, cnt, tmo);
  47. }
  48. static inline int sys_epoll_pwait(int epfd, struct epoll_event* out, int cnt, int tmo,
  49. const struct sigset* mask)
  50. {
  51. const int ssz = sizeof(struct sigset);
  52. return syscall6(NR_epoll_pwait, epfd, (long)out, cnt, tmo,
  53. (long)mask, ssz);
  54. }