xref: /OK3568_Linux_fs/kernel/include/linux/eventpoll.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  include/linux/eventpoll.h ( Efficient event polling implementation )
4*4882a593Smuzhiyun  *  Copyright (C) 2001,...,2006	 Davide Libenzi
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  *  Davide Libenzi <davidel@xmailserver.org>
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun #ifndef _LINUX_EVENTPOLL_H
9*4882a593Smuzhiyun #define _LINUX_EVENTPOLL_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <uapi/linux/eventpoll.h>
12*4882a593Smuzhiyun #include <uapi/linux/kcmp.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /* Forward declarations to avoid compiler errors */
16*4882a593Smuzhiyun struct file;
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #ifdef CONFIG_EPOLL
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #ifdef CONFIG_KCMP
22*4882a593Smuzhiyun struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, unsigned long toff);
23*4882a593Smuzhiyun #endif
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* Used to initialize the epoll bits inside the "struct file" */
eventpoll_init_file(struct file * file)26*4882a593Smuzhiyun static inline void eventpoll_init_file(struct file *file)
27*4882a593Smuzhiyun {
28*4882a593Smuzhiyun 	INIT_LIST_HEAD(&file->f_ep_links);
29*4882a593Smuzhiyun 	INIT_LIST_HEAD(&file->f_tfile_llink);
30*4882a593Smuzhiyun }
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /* Used to release the epoll bits inside the "struct file" */
34*4882a593Smuzhiyun void eventpoll_release_file(struct file *file);
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /*
37*4882a593Smuzhiyun  * This is called from inside fs/file_table.c:__fput() to unlink files
38*4882a593Smuzhiyun  * from the eventpoll interface. We need to have this facility to cleanup
39*4882a593Smuzhiyun  * correctly files that are closed without being removed from the eventpoll
40*4882a593Smuzhiyun  * interface.
41*4882a593Smuzhiyun  */
eventpoll_release(struct file * file)42*4882a593Smuzhiyun static inline void eventpoll_release(struct file *file)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	/*
46*4882a593Smuzhiyun 	 * Fast check to avoid the get/release of the semaphore. Since
47*4882a593Smuzhiyun 	 * we're doing this outside the semaphore lock, it might return
48*4882a593Smuzhiyun 	 * false negatives, but we don't care. It'll help in 99.99% of cases
49*4882a593Smuzhiyun 	 * to avoid the semaphore lock. False positives simply cannot happen
50*4882a593Smuzhiyun 	 * because the file in on the way to be removed and nobody ( but
51*4882a593Smuzhiyun 	 * eventpoll ) has still a reference to this file.
52*4882a593Smuzhiyun 	 */
53*4882a593Smuzhiyun 	if (likely(list_empty(&file->f_ep_links)))
54*4882a593Smuzhiyun 		return;
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	/*
57*4882a593Smuzhiyun 	 * The file is being closed while it is still linked to an epoll
58*4882a593Smuzhiyun 	 * descriptor. We need to handle this by correctly unlinking it
59*4882a593Smuzhiyun 	 * from its containers.
60*4882a593Smuzhiyun 	 */
61*4882a593Smuzhiyun 	eventpoll_release_file(file);
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
65*4882a593Smuzhiyun 		 bool nonblock);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun /* Tells if the epoll_ctl(2) operation needs an event copy from userspace */
ep_op_has_event(int op)68*4882a593Smuzhiyun static inline int ep_op_has_event(int op)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun 	return op != EPOLL_CTL_DEL;
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #else
74*4882a593Smuzhiyun 
eventpoll_init_file(struct file * file)75*4882a593Smuzhiyun static inline void eventpoll_init_file(struct file *file) {}
eventpoll_release(struct file * file)76*4882a593Smuzhiyun static inline void eventpoll_release(struct file *file) {}
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun #endif
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun #endif /* #ifndef _LINUX_EVENTPOLL_H */
81