Lines Matching +full:sync +full:- +full:update +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0
14 * Changed sys_poll()/do_poll() to use PAGE_SIZE chunk-based allocation
58 if (tv->tv_sec < 0) in __estimate_accuracy()
64 if (tv->tv_sec > MAX_SLACK / (NSEC_PER_SEC/divfactor)) in __estimate_accuracy()
67 slack = tv->tv_nsec / divfactor; in __estimate_accuracy()
68 slack += tv->tv_sec * (NSEC_PER_SEC/divfactor); in __estimate_accuracy()
80 u64 slack = current->timer_slack_ns; in select_estimate_accuracy()
102 ((unsigned long)((table)->entry+1) > PAGE_SIZE + (unsigned long)(table))
107 * follow, but it should be free of race-conditions, and it's practical. If you
112 * work. poll_wait() is an inline-function defined in <linux/poll.h>,
121 init_poll_funcptr(&pwq->pt, __pollwait); in poll_initwait()
122 pwq->polling_task = current; in poll_initwait()
123 pwq->triggered = 0; in poll_initwait()
124 pwq->error = 0; in poll_initwait()
125 pwq->table = NULL; in poll_initwait()
126 pwq->inline_index = 0; in poll_initwait()
132 remove_wait_queue(entry->wait_address, &entry->wait); in free_poll_entry()
133 fput(entry->filp); in free_poll_entry()
138 struct poll_table_page * p = pwq->table; in poll_freewait()
140 for (i = 0; i < pwq->inline_index; i++) in poll_freewait()
141 free_poll_entry(pwq->inline_entries + i); in poll_freewait()
146 entry = p->entry; in poll_freewait()
148 entry--; in poll_freewait()
150 } while (entry > p->entries); in poll_freewait()
152 p = p->next; in poll_freewait()
160 struct poll_table_page *table = p->table; in poll_get_entry()
162 if (p->inline_index < N_INLINE_POLL_ENTRIES) in poll_get_entry()
163 return p->inline_entries + p->inline_index++; in poll_get_entry()
170 p->error = -ENOMEM; in poll_get_entry()
173 new_table->entry = new_table->entries; in poll_get_entry()
174 new_table->next = table; in poll_get_entry()
175 p->table = new_table; in poll_get_entry()
179 return table->entry++; in poll_get_entry()
182 static int __pollwake(wait_queue_entry_t *wait, unsigned mode, int sync, void *key) in __pollwake() argument
184 struct poll_wqueues *pwq = wait->private; in __pollwake()
185 DECLARE_WAITQUEUE(dummy_wait, pwq->polling_task); in __pollwake()
195 WRITE_ONCE(pwq->triggered, 1); in __pollwake()
202 * pass in @sync. @sync is scheduled to be removed and once in __pollwake()
205 return default_wake_function(&dummy_wait, mode, sync, key); in __pollwake()
208 static int pollwake(wait_queue_entry_t *wait, unsigned mode, int sync, void *key) in pollwake() argument
213 if (key && !(key_to_poll(key) & entry->key)) in pollwake()
215 return __pollwake(wait, mode, sync, key); in pollwake()
226 entry->filp = get_file(filp); in __pollwait()
227 entry->wait_address = wait_address; in __pollwait()
228 entry->key = p->_key; in __pollwait()
229 init_waitqueue_func_entry(&entry->wait, pollwake); in __pollwait()
230 entry->wait.private = pwq; in __pollwait()
231 add_wait_queue(wait_address, &entry->wait); in __pollwait()
237 int rc = -EINTR; in poll_schedule_timeout()
240 if (!READ_ONCE(pwq->triggered)) in poll_schedule_timeout()
255 smp_store_mb(pwq->triggered, 0); in poll_schedule_timeout()
261 * poll_select_set_timeout - helper function to setup the timeout value
269 * Returns -EINVAL if sec/nsec are not normalized. Otherwise 0.
276 return -EINVAL; in poll_select_set_timeout()
280 to->tv_sec = to->tv_nsec = 0; in poll_select_set_timeout()
301 restore_saved_sigmask_unless(ret == -ERESTARTNOHAND); in poll_select_finish()
306 if (current->personality & STICKY_TIMEOUTS) in poll_select_finish()
309 /* No update for zero timeout */ in poll_select_finish()
310 if (!end_time->tv_sec && !end_time->tv_nsec) in poll_select_finish()
354 * If an application puts its timeval in read-only memory, we in poll_select_finish()
355 * don't want the Linux-specific update to the timeval to in poll_select_finish()
362 if (ret == -ERESTARTNOHAND) in poll_select_finish()
363 ret = -EINTR; in poll_select_finish()
380 #define FDS_LONGS(nr) (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG)
384 * Use "unsigned long" accesses to let user-mode fd_set's be long-aligned.
391 return copy_from_user(fdset, ufdset, nr) ? -EFAULT : 0; in get_fd_set()
411 #define FDS_IN(fds, n) (fds->in + n)
412 #define FDS_OUT(fds, n) (fds->out + n)
413 #define FDS_EX(fds, n) (fds->ex + n)
424 /* handle last in-complete long-word first */ in max_select_fd()
425 set = ~(~0UL << (n & (BITS_PER_LONG-1))); in max_select_fd()
427 fdt = files_fdtable(current->files); in max_select_fd()
428 open_fds = fdt->open_fds + n; in max_select_fd()
435 return -EBADF; in max_select_fd()
439 open_fds--; in max_select_fd()
440 n--; in max_select_fd()
445 return -EBADF; in max_select_fd()
474 wait->_key = POLLEX_SET | ll_flag; in select_poll_one()
476 wait->_key |= POLLIN_SET; in select_poll_one()
478 wait->_key |= POLLOUT_SET; in select_poll_one()
503 if (end_time && !end_time->tv_sec && !end_time->tv_nsec) { in do_select()
504 wait->_qproc = NULL; in do_select()
516 inp = fds->in; outp = fds->out; exp = fds->ex; in do_select()
517 rinp = fds->res_in; routp = fds->res_out; rexp = fds->res_ex; in do_select()
522 __poll_t mask; in do_select() local
536 mask = select_poll_one(i, wait, in, out, bit, in do_select()
538 if ((mask & POLLIN_SET) && (in & bit)) { in do_select()
541 wait->_qproc = NULL; in do_select()
543 if ((mask & POLLOUT_SET) && (out & bit)) { in do_select()
546 wait->_qproc = NULL; in do_select()
548 if ((mask & POLLEX_SET) && (ex & bit)) { in do_select()
551 wait->_qproc = NULL; in do_select()
562 } else if (busy_flag & mask) in do_select()
574 wait->_qproc = NULL; in do_select()
618 * Update: ERESTARTSYS breaks at least the xview clock binary, so
632 ret = -EINVAL; in core_sys_select()
638 fdt = files_fdtable(current->files); in core_sys_select()
639 max_fds = fdt->max_fds; in core_sys_select()
647 * long-words. in core_sys_select()
652 /* Not enough space in on-stack array; must use kmalloc */ in core_sys_select()
653 ret = -ENOMEM; in core_sys_select()
682 ret = -ERESTARTNOHAND; in core_sys_select()
691 ret = -EFAULT; in core_sys_select()
709 return -EFAULT; in kern_select()
715 return -EINVAL; in kern_select()
740 return -EFAULT; in do_pselect()
744 return -EFAULT; in do_pselect()
752 return -EINVAL; in do_pselect()
764 * Most architectures can't handle 7-argument syscalls. So we provide a
765 * 6-argument version where the sixth argument is a pointer to a structure
782 return -EFAULT; in get_sigset_argpack()
783 unsafe_get_user(to->p, &from->p, Efault); in get_sigset_argpack()
784 unsafe_get_user(to->size, &from->size, Efault); in get_sigset_argpack()
790 return -EFAULT; in get_sigset_argpack()
800 return -EFAULT; in SYSCALL_DEFINE6()
814 return -EFAULT; in SYSCALL_DEFINE6()
833 return -EFAULT; in SYSCALL_DEFINE1()
844 #define POLLFD_PER_PAGE ((PAGE_SIZE-sizeof(struct poll_list)) / sizeof(struct pollfd))
847 * Fish for pollable events on the pollfd->fd file descriptor. We're only
848 * interested in events matching the pollfd->events mask, and the result
849 * matching that mask is both recorded in pollfd->revents and returned. The
850 * pwait poll_table will be used by the fd-provided poll handler for waiting,
851 * if pwait->_qproc is non-NULL.
857 int fd = pollfd->fd; in do_pollfd()
858 __poll_t mask, filter; in do_pollfd() local
867 /* userland u16 ->events contains POLL... bitmap */ in do_pollfd()
868 filter = demangle_poll(pollfd->events) | EPOLLERR | EPOLLHUP; in do_pollfd()
869 pwait->_key = filter | busy_flag; in do_pollfd()
870 mask = vfs_poll(fd_file(f), pwait); in do_pollfd()
871 if (mask & busy_flag) in do_pollfd()
873 return mask & filter; /* Mask out unneeded events. */ in do_pollfd()
879 poll_table* pt = &wait->pt; in do_poll()
886 /* Optimise the no-wait case */ in do_poll()
887 if (end_time && !end_time->tv_sec && !end_time->tv_nsec) { in do_poll()
888 pt->_qproc = NULL; in do_poll()
899 for (walk = list; walk != NULL; walk = walk->next) { in do_poll()
902 pfd = walk->entries; in do_poll()
903 pfd_end = pfd + walk->len; in do_poll()
905 __poll_t mask; in do_poll() local
908 * and kill poll_table->_qproc, so we don't in do_poll()
913 mask = do_pollfd(pfd, pt, &can_busy_loop, busy_flag); in do_poll()
914 pfd->revents = mangle_poll(mask); in do_poll()
915 if (mask) { in do_poll()
917 pt->_qproc = NULL; in do_poll()
926 * a poll_table->_qproc to them on the next loop iteration. in do_poll()
928 pt->_qproc = NULL; in do_poll()
930 count = wait->error; in do_poll()
932 count = -ERESTARTNOHAND; in do_poll()
964 #define N_STACK_PPS ((sizeof(stack_pps) - sizeof(struct poll_list)) / \
971 int err = -EFAULT, fdcount; in do_sys_poll()
973 faster - use long to make sure the buffer is aligned properly in do_sys_poll()
982 return -EINVAL; in do_sys_poll()
986 walk->next = NULL; in do_sys_poll()
987 walk->len = len; in do_sys_poll()
991 if (copy_from_user(walk->entries, ufds + nfds-todo, in do_sys_poll()
992 sizeof(struct pollfd) * walk->len)) in do_sys_poll()
995 if (walk->len >= todo) in do_sys_poll()
997 todo -= walk->len; in do_sys_poll()
1000 walk = walk->next = kmalloc(struct_size(walk, entries, len), in do_sys_poll()
1003 err = -ENOMEM; in do_sys_poll()
1015 for (walk = head; walk; walk = walk->next) { in do_sys_poll()
1016 struct pollfd *fds = walk->entries; in do_sys_poll()
1019 for (j = walk->len; j; fds++, ufds++, j--) in do_sys_poll()
1020 unsafe_put_user(fds->revents, &ufds->revents, Efault); in do_sys_poll()
1026 walk = head->next; in do_sys_poll()
1029 walk = walk->next; in do_sys_poll()
1037 err = -EFAULT; in do_sys_poll()
1043 struct pollfd __user *ufds = restart_block->poll.ufds; in do_restart_poll()
1044 int nfds = restart_block->poll.nfds; in do_restart_poll()
1048 if (restart_block->poll.has_timeout) { in do_restart_poll()
1049 end_time.tv_sec = restart_block->poll.tv_sec; in do_restart_poll()
1050 end_time.tv_nsec = restart_block->poll.tv_nsec; in do_restart_poll()
1056 if (ret == -ERESTARTNOHAND) in do_restart_poll()
1076 if (ret == -ERESTARTNOHAND) { in SYSCALL_DEFINE3()
1079 restart_block = &current->restart_block; in SYSCALL_DEFINE3()
1080 restart_block->poll.ufds = ufds; in SYSCALL_DEFINE3()
1081 restart_block->poll.nfds = nfds; in SYSCALL_DEFINE3()
1084 restart_block->poll.tv_sec = end_time.tv_sec; in SYSCALL_DEFINE3()
1085 restart_block->poll.tv_nsec = end_time.tv_nsec; in SYSCALL_DEFINE3()
1086 restart_block->poll.has_timeout = 1; in SYSCALL_DEFINE3()
1088 restart_block->poll.has_timeout = 0; in SYSCALL_DEFINE3()
1104 return -EFAULT; in SYSCALL_DEFINE5()
1108 return -EINVAL; in SYSCALL_DEFINE5()
1130 return -EFAULT; in SYSCALL_DEFINE5()
1134 return -EINVAL; in SYSCALL_DEFINE5()
1150 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
1151 * 64-bit unsigned longs.
1185 * Update: ERESTARTSYS breaks at least the xview clock binary, so
1194 int size, max_fds, ret = -EINVAL; in compat_core_sys_select()
1203 fdt = files_fdtable(current->files); in compat_core_sys_select()
1204 max_fds = fdt->max_fds; in compat_core_sys_select()
1212 * long-words. in compat_core_sys_select()
1218 ret = -ENOMEM; in compat_core_sys_select()
1242 ret = -ERESTARTNOHAND; in compat_core_sys_select()
1251 ret = -EFAULT; in compat_core_sys_select()
1269 return -EFAULT; in do_compat_select()
1275 return -EINVAL; in do_compat_select()
1302 return -EFAULT; in COMPAT_SYSCALL_DEFINE1()
1319 return -EFAULT; in do_compat_pselect()
1323 return -EFAULT; in do_compat_pselect()
1331 return -EINVAL; in do_compat_pselect()
1351 return -EFAULT; in get_compat_sigset_argpack()
1352 unsafe_get_user(to->p, &from->p, Efault); in get_compat_sigset_argpack()
1353 unsafe_get_user(to->size, &from->size, Efault); in get_compat_sigset_argpack()
1359 return -EFAULT; in get_compat_sigset_argpack()
1369 return -EFAULT; in COMPAT_SYSCALL_DEFINE6()
1384 return -EFAULT; in COMPAT_SYSCALL_DEFINE6()
1402 return -EFAULT; in COMPAT_SYSCALL_DEFINE5()
1406 return -EINVAL; in COMPAT_SYSCALL_DEFINE5()
1428 return -EFAULT; in COMPAT_SYSCALL_DEFINE5()
1432 return -EINVAL; in COMPAT_SYSCALL_DEFINE5()