2019-05-27 06:55:01 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2011-03-31 01:57:33 +00:00
|
|
|
* include/linux/eventpoll.h ( Efficient event polling implementation )
|
2006-06-25 12:48:14 +00:00
|
|
|
* Copyright (C) 2001,...,2006 Davide Libenzi
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Davide Libenzi <davidel@xmailserver.org>
|
|
|
|
*/
|
|
|
|
#ifndef _LINUX_EVENTPOLL_H
|
|
|
|
#define _LINUX_EVENTPOLL_H
|
|
|
|
|
2012-10-13 09:46:48 +00:00
|
|
|
#include <uapi/linux/eventpoll.h>
|
2017-07-12 21:34:28 +00:00
|
|
|
#include <uapi/linux/kcmp.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Forward declarations to avoid compiler errors */
|
|
|
|
struct file;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_EPOLL
|
|
|
|
|
2021-02-05 22:00:12 +00:00
|
|
|
#ifdef CONFIG_KCMP
|
2017-07-12 21:34:28 +00:00
|
|
|
struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, unsigned long toff);
|
2017-07-12 21:34:31 +00:00
|
|
|
#endif
|
2017-07-12 21:34:28 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Used to release the epoll bits inside the "struct file" */
|
|
|
|
void eventpoll_release_file(struct file *file);
|
|
|
|
|
2025-02-19 17:22:26 +00:00
|
|
|
/* Copy ready events to userspace */
|
|
|
|
int epoll_sendevents(struct file *file, struct epoll_event __user *events,
|
|
|
|
int maxevents);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* This is called from inside fs/file_table.c:__fput() to unlink files
|
|
|
|
* from the eventpoll interface. We need to have this facility to cleanup
|
|
|
|
* correctly files that are closed without being removed from the eventpoll
|
|
|
|
* interface.
|
|
|
|
*/
|
|
|
|
static inline void eventpoll_release(struct file *file)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fast check to avoid the get/release of the semaphore. Since
|
|
|
|
* we're doing this outside the semaphore lock, it might return
|
|
|
|
* false negatives, but we don't care. It'll help in 99.99% of cases
|
|
|
|
* to avoid the semaphore lock. False positives simply cannot happen
|
|
|
|
* because the file in on the way to be removed and nobody ( but
|
|
|
|
* eventpoll ) has still a reference to this file.
|
|
|
|
*/
|
2024-09-25 09:05:16 +00:00
|
|
|
if (likely(!READ_ONCE(file->f_ep)))
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The file is being closed while it is still linked to an epoll
|
|
|
|
* descriptor. We need to handle this by correctly unlinking it
|
|
|
|
* from its containers.
|
|
|
|
*/
|
|
|
|
eventpoll_release_file(file);
|
|
|
|
}
|
|
|
|
|
2020-01-08 22:05:37 +00:00
|
|
|
int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
|
|
|
|
bool nonblock);
|
|
|
|
|
|
|
|
/* Tells if the epoll_ctl(2) operation needs an event copy from userspace */
|
|
|
|
static inline int ep_op_has_event(int op)
|
|
|
|
{
|
|
|
|
return op != EPOLL_CTL_DEL;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline void eventpoll_release(struct file *file) {}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-08-11 07:30:22 +00:00
|
|
|
#if defined(CONFIG_ARM) && defined(CONFIG_OABI_COMPAT)
|
|
|
|
/* ARM OABI has an incompatible struct layout and needs a special handler */
|
|
|
|
extern struct epoll_event __user *
|
|
|
|
epoll_put_uevent(__poll_t revents, __u64 data,
|
|
|
|
struct epoll_event __user *uevent);
|
|
|
|
#else
|
|
|
|
static inline struct epoll_event __user *
|
|
|
|
epoll_put_uevent(__poll_t revents, __u64 data,
|
|
|
|
struct epoll_event __user *uevent)
|
|
|
|
{
|
|
|
|
if (__put_user(revents, &uevent->events) ||
|
|
|
|
__put_user(data, &uevent->data))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return uevent+1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* #ifndef _LINUX_EVENTPOLL_H */
|