1 /*        $NetBSD: epoll.h,v 1.3 2024/10/30 15:56:12 riastradh Exp $  */
2 
3 /*-
4  * Copyright (c) 2007 Roman Divacky
5  * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef _SYS_EPOLL_H_
32 #define   _SYS_EPOLL_H_
33 
34 #include <sys/fcntl.h>                            /* for O_CLOEXEC */
35 #include <sys/featuretest.h>
36 #include <sys/sigtypes.h>               /* for sigset_t */
37 #include <sys/types.h>                            /* for uint32_t, uint64_t */
38 
39 struct timespec;
40 
41 #define   EPOLL_CLOEXEC       O_CLOEXEC
42 
43 #define   EPOLLIN             0x00000001
44 #define   EPOLLPRI  0x00000002
45 #define   EPOLLOUT  0x00000004
46 #define   EPOLLERR  0x00000008
47 #define   EPOLLHUP  0x00000010
48 #define   EPOLLRDNORM         0x00000040
49 #define   EPOLLRDBAND         0x00000080
50 #define   EPOLLWRNORM         0x00000100
51 #define   EPOLLWRBAND         0x00000200
52 #define   EPOLLMSG  0x00000400
53 #define   EPOLLRDHUP          0x00002000
54 #define   EPOLLWAKEUP         0x20000000
55 #define   EPOLLONESHOT        0x40000000
56 #define   EPOLLET             0x80000000
57 
58 #define   EPOLL_CTL_ADD       1
59 #define   EPOLL_CTL_DEL       2
60 #define   EPOLL_CTL_MOD       3
61 
62 #ifdef _KERNEL
63 #define   EPOLL_MAX_EVENTS    (4 * 1024 * 1024)
64 typedef uint64_t              epoll_data_t;
65 #else
66 union epoll_data {
67           void                *ptr;
68           int                 fd;
69           uint32_t  u32;
70           uint64_t  u64;
71 };
72 
73 typedef union epoll_data      epoll_data_t;
74 #endif
75 
76 struct epoll_event {
77           uint32_t  events;
78           epoll_data_t        data;
79 };
80 
81 #ifdef _KERNEL
82 int       epoll_ctl_common(struct lwp *l, register_t *retval, int epfd, int op,
83               int fd, struct epoll_event *event);
84 int       epoll_wait_common(struct lwp *l, register_t *retval, int epfd,
85               struct epoll_event *events, int maxevents, struct timespec *tsp,
86               const sigset_t *nss);
87 #else     /* !_KERNEL */
88 __BEGIN_DECLS
89 #ifdef _NETBSD_SOURCE
90 int       epoll_create(int size);
91 int       epoll_create1(int flags);
92 int       epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
93 int       epoll_wait(int epfd, struct epoll_event *events, int maxevents,
94               int timeout);
95 int       epoll_pwait(int epfd, struct epoll_event *events, int maxevents,
96               int timeout, const sigset_t *sigmask);
97 int       epoll_pwait2(int epfd, struct epoll_event *events, int maxevents,
98               const struct timespec *timeout, const sigset_t *sigmask);
99 #endif    /* _NETBSD_SOURCE */
100 __END_DECLS
101 #endif    /* !_KERNEL */
102 
103 #endif    /* !_SYS_EPOLL_H_ */
104