diff options
Diffstat (limited to 'include/linux/poll.h')
| -rw-r--r-- | include/linux/poll.h | 135 |
1 files changed, 56 insertions, 79 deletions
diff --git a/include/linux/poll.h b/include/linux/poll.h index c08386fb3e08..12bb18e8b978 100644 --- a/include/linux/poll.h +++ b/include/linux/poll.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _LINUX_POLL_H #define _LINUX_POLL_H @@ -7,11 +8,10 @@ #include <linux/wait.h> #include <linux/string.h> #include <linux/fs.h> -#include <linux/sysctl.h> -#include <asm/uaccess.h> +#include <linux/uaccess.h> #include <uapi/linux/poll.h> +#include <uapi/linux/eventpoll.h> -extern struct ctl_table epoll_table[]; /* for sysctl */ /* ~832 bytes of stack space used max in sys_select/sys_poll before allocating additional memory. */ #define MAX_STACK_ALLOC 832 @@ -21,38 +21,36 @@ extern struct ctl_table epoll_table[]; /* for sysctl */ #define WQUEUES_STACK_ALLOC (MAX_STACK_ALLOC - FRONTEND_STACK_ALLOC) #define N_INLINE_POLL_ENTRIES (WQUEUES_STACK_ALLOC / sizeof(struct poll_table_entry)) -#define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM) +#define DEFAULT_POLLMASK (EPOLLIN | EPOLLOUT | EPOLLRDNORM | EPOLLWRNORM) struct poll_table_struct; -/* +/* * structures and helpers for f_op->poll implementations */ typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *); /* - * Do not touch the structure directly, use the access functions - * poll_does_not_wait() and poll_requested_events() instead. + * Do not touch the structure directly, use the access function + * poll_requested_events() instead. */ typedef struct poll_table_struct { poll_queue_proc _qproc; - unsigned long _key; + __poll_t _key; } poll_table; static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p) { - if (p && p->_qproc && wait_address) + if (p && p->_qproc) { p->_qproc(filp, wait_address, p); -} - -/* - * Return true if it is guaranteed that poll will not wait. This is the case - * if the poll() of another file descriptor in the set got an event, so there - * is no need for waiting. - */ -static inline bool poll_does_not_wait(const poll_table *p) -{ - return p == NULL || p->_qproc == NULL; + /* + * This memory barrier is paired in the wq_has_sleeper(). + * See the comment above prepare_to_wait(), we need to + * ensure that subsequent tests in this thread can't be + * reordered with __add_wait_queue() in _qproc() paths. + */ + smp_mb(); + } } /* @@ -61,21 +59,33 @@ static inline bool poll_does_not_wait(const poll_table *p) * to be started implicitly on poll(). You typically only want to do that * if the application is actually polling for POLLIN and/or POLLOUT. */ -static inline unsigned long poll_requested_events(const poll_table *p) +static inline __poll_t poll_requested_events(const poll_table *p) { - return p ? p->_key : ~0UL; + return p ? p->_key : ~(__poll_t)0; } static inline void init_poll_funcptr(poll_table *pt, poll_queue_proc qproc) { pt->_qproc = qproc; - pt->_key = ~0UL; /* all events enabled */ + pt->_key = ~(__poll_t)0; /* all events enabled */ +} + +static inline bool file_can_poll(struct file *file) +{ + return file->f_op->poll; +} + +static inline __poll_t vfs_poll(struct file *file, struct poll_table_struct *pt) +{ + if (unlikely(!file->f_op->poll)) + return DEFAULT_POLLMASK; + return file->f_op->poll(file, pt); } struct poll_table_entry { struct file *filp; - unsigned long key; - wait_queue_t wait; + __poll_t key; + wait_queue_entry_t wait; wait_queue_head_t *wait_address; }; @@ -94,71 +104,38 @@ struct poll_wqueues { extern void poll_initwait(struct poll_wqueues *pwq); extern void poll_freewait(struct poll_wqueues *pwq); -extern int poll_schedule_timeout(struct poll_wqueues *pwq, int state, - ktime_t *expires, unsigned long slack); -extern long select_estimate_accuracy(struct timespec *tv); - - -static inline int poll_schedule(struct poll_wqueues *pwq, int state) -{ - return poll_schedule_timeout(pwq, state, NULL, 0); -} +extern u64 select_estimate_accuracy(struct timespec64 *tv); -/* - * Scalable version of the fd_set. - */ +#define MAX_INT64_SECONDS (((s64)(~((u64)0)>>1)/HZ)-1) -typedef struct { - unsigned long *in, *out, *ex; - unsigned long *res_in, *res_out, *res_ex; -} fd_set_bits; +extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp, + fd_set __user *exp, struct timespec64 *end_time); -/* - * How many longwords for "nr" bits? - */ -#define FDS_BITPERLONG (8*sizeof(long)) -#define FDS_LONGS(nr) (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG) -#define FDS_BYTES(nr) (FDS_LONGS(nr)*sizeof(long)) +extern int poll_select_set_timeout(struct timespec64 *to, time64_t sec, + long nsec); -/* - * We do a VERIFY_WRITE here even though we are only reading this time: - * we'll write to it eventually.. - * - * Use "unsigned long" accesses to let user-mode fd_set's be long-aligned. - */ -static inline -int get_fd_set(unsigned long nr, void __user *ufdset, unsigned long *fdset) -{ - nr = FDS_BYTES(nr); - if (ufdset) - return copy_from_user(fdset, ufdset, nr) ? -EFAULT : 0; - - memset(fdset, 0, nr); - return 0; -} +#define __MAP(v, from, to) \ + (from < to ? (v & from) * (to/from) : (v & from) / (from/to)) -static inline unsigned long __must_check -set_fd_set(unsigned long nr, void __user *ufdset, unsigned long *fdset) +static inline __u16 mangle_poll(__poll_t val) { - if (ufdset) - return __copy_to_user(ufdset, fdset, FDS_BYTES(nr)); - return 0; + __u16 v = (__force __u16)val; +#define M(X) __MAP(v, (__force __u16)EPOLL##X, POLL##X) + return M(IN) | M(OUT) | M(PRI) | M(ERR) | M(NVAL) | + M(RDNORM) | M(RDBAND) | M(WRNORM) | M(WRBAND) | + M(HUP) | M(RDHUP) | M(MSG); +#undef M } -static inline -void zero_fd_set(unsigned long nr, unsigned long *fdset) +static inline __poll_t demangle_poll(u16 val) { - memset(fdset, 0, FDS_BYTES(nr)); +#define M(X) (__force __poll_t)__MAP(val, POLL##X, (__force __u16)EPOLL##X) + return M(IN) | M(OUT) | M(PRI) | M(ERR) | M(NVAL) | + M(RDNORM) | M(RDBAND) | M(WRNORM) | M(WRBAND) | + M(HUP) | M(RDHUP) | M(MSG); +#undef M } +#undef __MAP -#define MAX_INT64_SECONDS (((s64)(~((u64)0)>>1)/HZ)-1) - -extern int do_select(int n, fd_set_bits *fds, struct timespec *end_time); -extern int do_sys_poll(struct pollfd __user * ufds, unsigned int nfds, - struct timespec *end_time); -extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp, - fd_set __user *exp, struct timespec *end_time); - -extern int poll_select_set_timeout(struct timespec *to, long sec, long nsec); #endif /* _LINUX_POLL_H */ |
