master
  1/* Copyright (C) 2002-2025 Free Software Foundation, Inc.
  2   This file is part of the GNU C Library.
  3
  4   The GNU C Library is free software; you can redistribute it and/or
  5   modify it under the terms of the GNU Lesser General Public
  6   License as published by the Free Software Foundation; either
  7   version 2.1 of the License, or (at your option) any later version.
  8
  9   The GNU C Library is distributed in the hope that it will be useful,
 10   but WITHOUT ANY WARRANTY; without even the implied warranty of
 11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12   Lesser General Public License for more details.
 13
 14   You should have received a copy of the GNU Lesser General Public
 15   License along with the GNU C Library; if not, see
 16   <https://www.gnu.org/licenses/>.  */
 17
 18#ifndef	_SYS_EPOLL_H
 19#define	_SYS_EPOLL_H	1
 20
 21#include <stdint.h>
 22#include <sys/ioctl.h>
 23#include <sys/types.h>
 24
 25#include <bits/types/sigset_t.h>
 26#include <bits/types/struct_timespec.h>
 27
 28/* Get the platform-dependent flags.  */
 29#include <bits/epoll.h>
 30
 31#ifndef __EPOLL_PACKED
 32# define __EPOLL_PACKED
 33#endif
 34
 35
 36enum EPOLL_EVENTS
 37  {
 38    EPOLLIN = 0x001,
 39#define EPOLLIN EPOLLIN
 40    EPOLLPRI = 0x002,
 41#define EPOLLPRI EPOLLPRI
 42    EPOLLOUT = 0x004,
 43#define EPOLLOUT EPOLLOUT
 44    EPOLLRDNORM = 0x040,
 45#define EPOLLRDNORM EPOLLRDNORM
 46    EPOLLRDBAND = 0x080,
 47#define EPOLLRDBAND EPOLLRDBAND
 48    EPOLLWRNORM = 0x100,
 49#define EPOLLWRNORM EPOLLWRNORM
 50    EPOLLWRBAND = 0x200,
 51#define EPOLLWRBAND EPOLLWRBAND
 52    EPOLLMSG = 0x400,
 53#define EPOLLMSG EPOLLMSG
 54    EPOLLERR = 0x008,
 55#define EPOLLERR EPOLLERR
 56    EPOLLHUP = 0x010,
 57#define EPOLLHUP EPOLLHUP
 58    EPOLLRDHUP = 0x2000,
 59#define EPOLLRDHUP EPOLLRDHUP
 60    EPOLLEXCLUSIVE = 1u << 28,
 61#define EPOLLEXCLUSIVE EPOLLEXCLUSIVE
 62    EPOLLWAKEUP = 1u << 29,
 63#define EPOLLWAKEUP EPOLLWAKEUP
 64    EPOLLONESHOT = 1u << 30,
 65#define EPOLLONESHOT EPOLLONESHOT
 66    EPOLLET = 1u << 31
 67#define EPOLLET EPOLLET
 68  };
 69
 70
 71/* Valid opcodes ( "op" parameter ) to issue to epoll_ctl().  */
 72#define EPOLL_CTL_ADD 1	/* Add a file descriptor to the interface.  */
 73#define EPOLL_CTL_DEL 2	/* Remove a file descriptor from the interface.  */
 74#define EPOLL_CTL_MOD 3	/* Change file descriptor epoll_event structure.  */
 75
 76
 77typedef union epoll_data
 78{
 79  void *ptr;
 80  int fd;
 81  uint32_t u32;
 82  uint64_t u64;
 83} epoll_data_t;
 84
 85struct epoll_event
 86{
 87  uint32_t events;	/* Epoll events */
 88  epoll_data_t data;	/* User data variable */
 89} __EPOLL_PACKED;
 90
 91struct epoll_params
 92{
 93  uint32_t busy_poll_usecs;
 94  uint16_t busy_poll_budget;
 95  uint8_t prefer_busy_poll;
 96
 97  /* pad the struct to a multiple of 64bits */
 98  uint8_t __pad;
 99};
100
101#define EPOLL_IOC_TYPE 0x8A
102#define EPIOCSPARAMS _IOW(EPOLL_IOC_TYPE, 0x01, struct epoll_params)
103#define EPIOCGPARAMS _IOR(EPOLL_IOC_TYPE, 0x02, struct epoll_params)
104
105__BEGIN_DECLS
106
107/* Creates an epoll instance.  Returns an fd for the new instance.
108   The "size" parameter is a hint specifying the number of file
109   descriptors to be associated with the new instance.  The fd
110   returned by epoll_create() should be closed with close().  */
111extern int epoll_create (int __size) __THROW;
112
113/* Same as epoll_create but with an FLAGS parameter.  The unused SIZE
114   parameter has been dropped.  */
115extern int epoll_create1 (int __flags) __THROW;
116
117
118/* Manipulate an epoll instance "epfd". Returns 0 in case of success,
119   -1 in case of error ( the "errno" variable will contain the
120   specific error code ) The "op" parameter is one of the EPOLL_CTL_*
121   constants defined above. The "fd" parameter is the target of the
122   operation. The "event" parameter describes which events the caller
123   is interested in and any associated user data.  */
124extern int epoll_ctl (int __epfd, int __op, int __fd,
125		      struct epoll_event *__event) __THROW;
126
127
128/* Wait for events on an epoll instance "epfd". Returns the number of
129   triggered events returned in "events" buffer. Or -1 in case of
130   error with the "errno" variable set to the specific error code. The
131   "events" parameter is a buffer that will contain triggered
132   events. The "maxevents" is the maximum number of events to be
133   returned ( usually size of "events" ). The "timeout" parameter
134   specifies the maximum wait time in milliseconds (-1 == infinite).
135
136   This function is a cancellation point and therefore not marked with
137   __THROW.  */
138extern int epoll_wait (int __epfd, struct epoll_event *__events,
139		       int __maxevents, int __timeout)
140	__attr_access ((__write_only__, 2, 3)) __nonnull ((2));
141
142
143/* Same as epoll_wait, but the thread's signal mask is temporarily
144   and atomically replaced with the one provided as parameter.
145
146   This function is a cancellation point and therefore not marked with
147   __THROW.  */
148extern int epoll_pwait (int __epfd, struct epoll_event *__events,
149			int __maxevents, int __timeout,
150			const __sigset_t *__ss)
151	__attr_access ((__write_only__, 2, 3)) __nonnull ((2));
152
153/* Same as epoll_pwait, but the timeout as a timespec.
154
155   This function is a cancellation point and therefore not marked with
156   __THROW.  */
157#ifndef __USE_TIME64_REDIRECTS
158extern int epoll_pwait2 (int __epfd, struct epoll_event *__events,
159			 int __maxevents, const struct timespec *__timeout,
160			 const __sigset_t *__ss)
161	__attr_access ((__write_only__, 2, 3)) __nonnull ((2));
162#else
163# ifdef __REDIRECT
164extern int __REDIRECT (epoll_pwait2, (int __epfd, struct epoll_event *__ev,
165				      int __maxevs,
166				      const struct timespec *__timeout,
167				      const __sigset_t *__ss),
168		       __epoll_pwait2_time64)
169	__attr_access ((__write_only__, 2, 3)) __nonnull ((2));
170# else
171#  define epoll_pwait2 __epoll_pwait2_time64
172# endif
173#endif
174
175__END_DECLS
176
177#endif /* sys/epoll.h */