xref: /illumos-gate/usr/src/uts/common/sys/epoll.h (revision bbf21555)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright (c) 2014, Joyent, Inc.  All rights reserved.
14  * Copyright 2020 Oxide Computer Company
15  */
16 
17 #ifndef _SYS_EPOLL_H
18 #define	_SYS_EPOLL_H
19 
20 #include <sys/types.h>
21 #include <sys/poll.h>
22 
23 #ifdef	__cplusplus
24 extern "C" {
25 #endif
26 
27 typedef union epoll_data {
28 	void		*ptr;
29 	int		fd;
30 	uint32_t	u32;
31 	uint64_t	u64;
32 } epoll_data_t;
33 
34 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
35 #pragma pack(4)
36 #endif
37 
38 typedef struct epoll_event {
39 	uint32_t	events;		/* events */
40 	epoll_data_t	data;		/* user-specified data */
41 } epoll_event_t;
42 
43 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
44 #pragma pack()
45 #endif
46 
47 /*
48  * Define the EPOLL* constants in terms of their poll(2)/poll(4D) equivalents.
49  * Note that the values match the equivalents in Linux to allow for any binary
50  * compatibility layers to not need to translate them.
51  */
52 #define	EPOLLIN		0x0001
53 #define	EPOLLPRI	0x0002
54 #define	EPOLLOUT	0x0004
55 #define	EPOLLRDNORM	0x0040
56 #define	EPOLLRDBAND	0x0080
57 #define	EPOLLWRNORM	0x0100
58 #define	EPOLLWRBAND	0x0200
59 #define	EPOLLMSG	0x0400		/* not used */
60 #define	EPOLLERR	0x0008
61 #define	EPOLLHUP	0x0010
62 #define	EPOLLRDHUP	0x2000
63 
64 #define	EPOLLEXCLUSIVE	(1UL << 28)	/* sets exclusive wake-up mode */
65 #define	EPOLLWAKEUP	(1UL << 29)	/* no meaning; silently ignored */
66 #define	EPOLLONESHOT	(1UL << 30)	/* translated to POLLONESHOT */
67 #define	EPOLLET		(1UL << 31)	/* translated to POLLET */
68 
69 #define	EPOLL_CTL_ADD	1
70 #define	EPOLL_CTL_DEL	2
71 #define	EPOLL_CTL_MOD	3
72 
73 #define	EPOLL_CLOEXEC	02000000
74 
75 #if !defined(_KERNEL)
76 
77 extern int epoll_create(int size);
78 extern int epoll_create1(int flags);
79 extern int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
80 extern int epoll_wait(int epfd, struct epoll_event *events,
81     int maxevents, int timeout);
82 extern int epoll_pwait(int epfd, struct epoll_event *events,
83     int maxevents, int timeout, const sigset_t *sigmask);
84 
85 #endif /* !_KERNEL */
86 
87 #ifdef	__cplusplus
88 }
89 #endif
90 
91 #endif	/* _SYS_EPOLL_H */
92