Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  include/linux/eventpoll.h ( Efficient event polling implementation )
0004  *  Copyright (C) 2001,...,2006  Davide Libenzi
0005  *
0006  *  Davide Libenzi <davidel@xmailserver.org>
0007  */
0008 #ifndef _LINUX_EVENTPOLL_H
0009 #define _LINUX_EVENTPOLL_H
0010 
0011 #include <uapi/linux/eventpoll.h>
0012 #include <uapi/linux/kcmp.h>
0013 
0014 
0015 /* Forward declarations to avoid compiler errors */
0016 struct file;
0017 
0018 
0019 #ifdef CONFIG_EPOLL
0020 
0021 #ifdef CONFIG_KCMP
0022 struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, unsigned long toff);
0023 #endif
0024 
0025 /* Used to release the epoll bits inside the "struct file" */
0026 void eventpoll_release_file(struct file *file);
0027 
0028 /*
0029  * This is called from inside fs/file_table.c:__fput() to unlink files
0030  * from the eventpoll interface. We need to have this facility to cleanup
0031  * correctly files that are closed without being removed from the eventpoll
0032  * interface.
0033  */
0034 static inline void eventpoll_release(struct file *file)
0035 {
0036 
0037     /*
0038      * Fast check to avoid the get/release of the semaphore. Since
0039      * we're doing this outside the semaphore lock, it might return
0040      * false negatives, but we don't care. It'll help in 99.99% of cases
0041      * to avoid the semaphore lock. False positives simply cannot happen
0042      * because the file in on the way to be removed and nobody ( but
0043      * eventpoll ) has still a reference to this file.
0044      */
0045     if (likely(!file->f_ep))
0046         return;
0047 
0048     /*
0049      * The file is being closed while it is still linked to an epoll
0050      * descriptor. We need to handle this by correctly unlinking it
0051      * from its containers.
0052      */
0053     eventpoll_release_file(file);
0054 }
0055 
0056 int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,
0057          bool nonblock);
0058 
0059 /* Tells if the epoll_ctl(2) operation needs an event copy from userspace */
0060 static inline int ep_op_has_event(int op)
0061 {
0062     return op != EPOLL_CTL_DEL;
0063 }
0064 
0065 #else
0066 
0067 static inline void eventpoll_release(struct file *file) {}
0068 
0069 #endif
0070 
0071 #if defined(CONFIG_ARM) && defined(CONFIG_OABI_COMPAT)
0072 /* ARM OABI has an incompatible struct layout and needs a special handler */
0073 extern struct epoll_event __user *
0074 epoll_put_uevent(__poll_t revents, __u64 data,
0075          struct epoll_event __user *uevent);
0076 #else
0077 static inline struct epoll_event __user *
0078 epoll_put_uevent(__poll_t revents, __u64 data,
0079          struct epoll_event __user *uevent)
0080 {
0081     if (__put_user(revents, &uevent->events) ||
0082         __put_user(data, &uevent->data))
0083         return NULL;
0084 
0085     return uevent+1;
0086 }
0087 #endif
0088 
0089 #endif /* #ifndef _LINUX_EVENTPOLL_H */