Lines Matching +full:poll +full:- +full:only

1 // SPDX-License-Identifier: GPL-2.0
3 * This file contains the procedures for the handling of select and poll
14 * Changed sys_poll()/do_poll() to use PAGE_SIZE chunk-based allocation
24 #include <linux/poll.h>
57 if (tv->tv_sec < 0) in __estimate_accuracy()
63 if (tv->tv_sec > MAX_SLACK / (NSEC_PER_SEC/divfactor)) in __estimate_accuracy()
66 slack = tv->tv_nsec / divfactor; in __estimate_accuracy()
67 slack += tv->tv_sec * (NSEC_PER_SEC/divfactor); in __estimate_accuracy()
90 if (ret < current->timer_slack_ns) in select_estimate_accuracy()
91 return current->timer_slack_ns; in select_estimate_accuracy()
104 ((unsigned long)((table)->entry+1) > PAGE_SIZE + (unsigned long)(table))
109 * follow, but it should be free of race-conditions, and it's practical. If you
114 * work. poll_wait() is an inline-function defined in <linux/poll.h>,
115 * as all select/poll functions have to call it to add an entry to the
116 * poll table.
123 init_poll_funcptr(&pwq->pt, __pollwait); in poll_initwait()
124 pwq->polling_task = current; in poll_initwait()
125 pwq->triggered = 0; in poll_initwait()
126 pwq->error = 0; in poll_initwait()
127 pwq->table = NULL; in poll_initwait()
128 pwq->inline_index = 0; in poll_initwait()
134 remove_wait_queue(entry->wait_address, &entry->wait); in free_poll_entry()
135 fput(entry->filp); in free_poll_entry()
140 struct poll_table_page * p = pwq->table; in poll_freewait()
142 for (i = 0; i < pwq->inline_index; i++) in poll_freewait()
143 free_poll_entry(pwq->inline_entries + i); in poll_freewait()
148 entry = p->entry; in poll_freewait()
150 entry--; in poll_freewait()
152 } while (entry > p->entries); in poll_freewait()
154 p = p->next; in poll_freewait()
162 struct poll_table_page *table = p->table; in poll_get_entry()
164 if (p->inline_index < N_INLINE_POLL_ENTRIES) in poll_get_entry()
165 return p->inline_entries + p->inline_index++; in poll_get_entry()
172 p->error = -ENOMEM; in poll_get_entry()
175 new_table->entry = new_table->entries; in poll_get_entry()
176 new_table->next = table; in poll_get_entry()
177 p->table = new_table; in poll_get_entry()
181 return table->entry++; in poll_get_entry()
186 struct poll_wqueues *pwq = wait->private; in __pollwake()
187 DECLARE_WAITQUEUE(dummy_wait, pwq->polling_task); in __pollwake()
197 pwq->triggered = 1; in __pollwake()
215 if (key && !(key_to_poll(key) & entry->key)) in pollwake()
228 entry->filp = get_file(filp); in __pollwait()
229 entry->wait_address = wait_address; in __pollwait()
230 entry->key = p->_key; in __pollwait()
231 init_waitqueue_func_entry(&entry->wait, pollwake); in __pollwait()
232 entry->wait.private = pwq; in __pollwait()
233 add_wait_queue(wait_address, &entry->wait); in __pollwait()
239 int rc = -EINTR; in poll_schedule_timeout()
242 if (!pwq->triggered) in poll_schedule_timeout()
257 smp_store_mb(pwq->triggered, 0); in poll_schedule_timeout()
263 * poll_select_set_timeout - helper function to setup the timeout value
271 * Returns -EINVAL if sec/nsec are not normalized. Otherwise 0.
278 return -EINVAL; in poll_select_set_timeout()
282 to->tv_sec = to->tv_nsec = 0; in poll_select_set_timeout()
303 restore_saved_sigmask_unless(ret == -ERESTARTNOHAND); in poll_select_finish()
308 if (current->personality & STICKY_TIMEOUTS) in poll_select_finish()
312 if (!end_time->tv_sec && !end_time->tv_nsec) in poll_select_finish()
356 * If an application puts its timeval in read-only memory, we in poll_select_finish()
357 * don't want the Linux-specific update to the timeval to in poll_select_finish()
364 if (ret == -ERESTARTNOHAND) in poll_select_finish()
365 ret = -EINTR; in poll_select_finish()
382 #define FDS_LONGS(nr) (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG)
386 * Use "unsigned long" accesses to let user-mode fd_set's be long-aligned.
393 return copy_from_user(fdset, ufdset, nr) ? -EFAULT : 0; in get_fd_set()
413 #define FDS_IN(fds, n) (fds->in + n)
414 #define FDS_OUT(fds, n) (fds->out + n)
415 #define FDS_EX(fds, n) (fds->ex + n)
426 /* handle last in-complete long-word first */ in max_select_fd()
427 set = ~(~0UL << (n & (BITS_PER_LONG-1))); in max_select_fd()
429 fdt = files_fdtable(current->files); in max_select_fd()
430 open_fds = fdt->open_fds + n; in max_select_fd()
437 return -EBADF; in max_select_fd()
441 open_fds--; in max_select_fd()
442 n--; in max_select_fd()
447 return -EBADF; in max_select_fd()
471 wait->_key = POLLEX_SET | ll_flag; in wait_key_set()
473 wait->_key |= POLLIN_SET; in wait_key_set()
475 wait->_key |= POLLOUT_SET; in wait_key_set()
498 if (end_time && !end_time->tv_sec && !end_time->tv_nsec) { in do_select()
499 wait->_qproc = NULL; in do_select()
511 inp = fds->in; outp = fds->out; exp = fds->ex; in do_select()
512 rinp = fds->res_in; routp = fds->res_out; rexp = fds->res_ex; in do_select()
544 wait->_qproc = NULL; in do_select()
549 wait->_qproc = NULL; in do_select()
554 wait->_qproc = NULL; in do_select()
562 * only remember a returned in do_select()
577 wait->_qproc = NULL; in do_select()
585 /* only if found POLL_BUSY_LOOP sockets && not out of time */ in do_select()
622 * I'm trying ERESTARTNOHAND which restart only when you want to.
635 ret = -EINVAL; in core_sys_select()
641 fdt = files_fdtable(current->files); in core_sys_select()
642 max_fds = fdt->max_fds; in core_sys_select()
650 * long-words. in core_sys_select()
655 /* Not enough space in on-stack array; must use kmalloc */ in core_sys_select()
656 ret = -ENOMEM; in core_sys_select()
685 ret = -ERESTARTNOHAND; in core_sys_select()
694 ret = -EFAULT; in core_sys_select()
712 return -EFAULT; in kern_select()
718 return -EINVAL; in kern_select()
743 return -EFAULT; in do_pselect()
747 return -EFAULT; in do_pselect()
755 return -EINVAL; in do_pselect()
767 * Most architectures can't handle 7-argument syscalls. So we provide a
768 * 6-argument version where the sixth argument is a pointer to a structure
783 return -EFAULT; in get_sigset_argpack()
784 unsafe_get_user(to->p, &from->p, Efault); in get_sigset_argpack()
785 unsafe_get_user(to->size, &from->size, Efault); in get_sigset_argpack()
791 return -EFAULT; in get_sigset_argpack()
801 return -EFAULT; in SYSCALL_DEFINE6()
815 return -EFAULT; in SYSCALL_DEFINE6()
834 return -EFAULT; in SYSCALL_DEFINE1()
845 #define POLLFD_PER_PAGE ((PAGE_SIZE-sizeof(struct poll_list)) / sizeof(struct pollfd))
848 * Fish for pollable events on the pollfd->fd file descriptor. We're only
849 * interested in events matching the pollfd->events mask, and the result
850 * matching that mask is both recorded in pollfd->revents and returned. The
851 * pwait poll_table will be used by the fd-provided poll handler for waiting,
852 * if pwait->_qproc is non-NULL.
858 int fd = pollfd->fd; in do_pollfd()
869 /* userland u16 ->events contains POLL... bitmap */ in do_pollfd()
870 filter = demangle_poll(pollfd->events) | EPOLLERR | EPOLLHUP; in do_pollfd()
871 pwait->_key = filter | busy_flag; in do_pollfd()
879 /* ... and so does ->revents */ in do_pollfd()
880 pollfd->revents = mangle_poll(mask); in do_pollfd()
887 poll_table* pt = &wait->pt; in do_poll()
894 /* Optimise the no-wait case */ in do_poll()
895 if (end_time && !end_time->tv_sec && !end_time->tv_nsec) { in do_poll()
896 pt->_qproc = NULL; in do_poll()
907 for (walk = list; walk != NULL; walk = walk->next) { in do_poll()
910 pfd = walk->entries; in do_poll()
911 pfd_end = pfd + walk->len; in do_poll()
915 * and kill poll_table->_qproc, so we don't in do_poll()
923 pt->_qproc = NULL; in do_poll()
932 * a poll_table->_qproc to them on the next loop iteration. in do_poll()
934 pt->_qproc = NULL; in do_poll()
936 count = wait->error; in do_poll()
938 count = -ERESTARTNOHAND; in do_poll()
943 /* only if found POLL_BUSY_LOOP sockets && not out of time */ in do_poll()
970 #define N_STACK_PPS ((sizeof(stack_pps) - sizeof(struct poll_list)) / \
977 int err = -EFAULT, fdcount, len; in do_sys_poll()
979 faster - use long to make sure the buffer is aligned properly in do_sys_poll()
987 return -EINVAL; in do_sys_poll()
991 walk->next = NULL; in do_sys_poll()
992 walk->len = len; in do_sys_poll()
996 if (copy_from_user(walk->entries, ufds + nfds-todo, in do_sys_poll()
997 sizeof(struct pollfd) * walk->len)) in do_sys_poll()
1000 todo -= walk->len; in do_sys_poll()
1005 walk = walk->next = kmalloc(struct_size(walk, entries, len), in do_sys_poll()
1008 err = -ENOMEM; in do_sys_poll()
1020 for (walk = head; walk; walk = walk->next) { in do_sys_poll()
1021 struct pollfd *fds = walk->entries; in do_sys_poll()
1024 for (j = walk->len; j; fds++, ufds++, j--) in do_sys_poll()
1025 unsafe_put_user(fds->revents, &ufds->revents, Efault); in do_sys_poll()
1031 walk = head->next; in do_sys_poll()
1034 walk = walk->next; in do_sys_poll()
1042 err = -EFAULT; in do_sys_poll()
1048 struct pollfd __user *ufds = restart_block->poll.ufds; in do_restart_poll()
1049 int nfds = restart_block->poll.nfds; in do_restart_poll()
1053 if (restart_block->poll.has_timeout) { in do_restart_poll()
1054 end_time.tv_sec = restart_block->poll.tv_sec; in do_restart_poll()
1055 end_time.tv_nsec = restart_block->poll.tv_nsec; in do_restart_poll()
1061 if (ret == -ERESTARTNOHAND) in do_restart_poll()
1067 SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds, in SYSCALL_DEFINE3() argument
1081 if (ret == -ERESTARTNOHAND) { in SYSCALL_DEFINE3()
1084 restart_block = &current->restart_block; in SYSCALL_DEFINE3()
1085 restart_block->poll.ufds = ufds; in SYSCALL_DEFINE3()
1086 restart_block->poll.nfds = nfds; in SYSCALL_DEFINE3()
1089 restart_block->poll.tv_sec = end_time.tv_sec; in SYSCALL_DEFINE3()
1090 restart_block->poll.tv_nsec = end_time.tv_nsec; in SYSCALL_DEFINE3()
1091 restart_block->poll.has_timeout = 1; in SYSCALL_DEFINE3()
1093 restart_block->poll.has_timeout = 0; in SYSCALL_DEFINE3()
1109 return -EFAULT; in SYSCALL_DEFINE5()
1113 return -EINVAL; in SYSCALL_DEFINE5()
1135 return -EFAULT; in SYSCALL_DEFINE5()
1139 return -EINVAL; in SYSCALL_DEFINE5()
1155 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1156 * 64-bit unsigned longs.
1191 * I'm trying ERESTARTNOHAND which restart only when you want to.
1199 int size, max_fds, ret = -EINVAL; in compat_core_sys_select()
1208 fdt = files_fdtable(current->files); in compat_core_sys_select()
1209 max_fds = fdt->max_fds; in compat_core_sys_select()
1217 * long-words. in compat_core_sys_select()
1223 ret = -ENOMEM; in compat_core_sys_select()
1247 ret = -ERESTARTNOHAND; in compat_core_sys_select()
1256 ret = -EFAULT; in compat_core_sys_select()
1274 return -EFAULT; in do_compat_select()
1280 return -EINVAL; in do_compat_select()
1307 return -EFAULT; in COMPAT_SYSCALL_DEFINE1()
1324 return -EFAULT; in do_compat_pselect()
1328 return -EFAULT; in do_compat_pselect()
1336 return -EINVAL; in do_compat_pselect()
1356 return -EFAULT; in get_compat_sigset_argpack()
1357 unsafe_get_user(to->p, &from->p, Efault); in get_compat_sigset_argpack()
1358 unsafe_get_user(to->size, &from->size, Efault); in get_compat_sigset_argpack()
1364 return -EFAULT; in get_compat_sigset_argpack()
1374 return -EFAULT; in COMPAT_SYSCALL_DEFINE6()
1389 return -EFAULT; in COMPAT_SYSCALL_DEFINE6()
1407 return -EFAULT; in COMPAT_SYSCALL_DEFINE5()
1411 return -EINVAL; in COMPAT_SYSCALL_DEFINE5()
1433 return -EFAULT; in COMPAT_SYSCALL_DEFINE5()
1437 return -EINVAL; in COMPAT_SYSCALL_DEFINE5()