fs/select.c
Source file repositories/reference/linux-study-clean/fs/select.c
File Facts
- System
- Linux kernel
- Corpus path
fs/select.c- Extension
.c- Size
- 35573 bytes
- Lines
- 1439
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/compat.hlinux/kernel.hlinux/sched/signal.hlinux/sched/rt.hlinux/syscalls.hlinux/export.hlinux/slab.hlinux/poll.hlinux/personality.hlinux/file.hlinux/fdtable.hlinux/fs.hlinux/rcupdate.hlinux/hrtimer.hlinux/freezer.hnet/busy_poll.hlinux/vmalloc.hlinux/uaccess.h
Detected Declarations
syscall selectsyscall pselect6syscall pselect6_time32syscall old_selectsyscall pollsyscall ppollsyscall ppoll_time32struct poll_table_pagestruct sigset_argpackstruct sel_arg_structstruct poll_liststruct compat_sel_arg_structstruct compat_sigset_argpackenum poll_time_typefunction sys_pollfunction select_estimate_accuracyfunction poll_initwaitfunction free_poll_entryfunction poll_freewaitfunction __pollwakefunction pollwakefunction __pollwaitfunction poll_schedule_timeoutfunction poll_select_set_timeoutfunction poll_select_finishfunction get_fd_setfunction set_fd_setfunction zero_fd_setfunction max_select_fdfunction select_poll_onefunction do_selectfunction core_sys_selectfunction kern_selectfunction do_pselectfunction get_sigset_argpackfunction do_pollfdfunction do_pollfunction scoped_user_write_access_sizefunction do_restart_pollfunction compat_get_fd_setfunction compat_set_fd_setfunction compat_core_sys_selectfunction do_compat_selectfunction do_compat_pselectfunction get_compat_sigset_argpackexport poll_initwaitexport poll_freewait
Annotated Snippet
SYSCALL_DEFINE5(select, int, n, fd_set __user *, inp, fd_set __user *, outp,
fd_set __user *, exp, struct __kernel_old_timeval __user *, tvp)
{
return kern_select(n, inp, outp, exp, tvp);
}
static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp,
fd_set __user *exp, void __user *tsp,
const sigset_t __user *sigmask, size_t sigsetsize,
enum poll_time_type type)
{
struct timespec64 ts, end_time, *to = NULL;
int ret;
if (tsp) {
switch (type) {
case PT_TIMESPEC:
if (get_timespec64(&ts, tsp))
return -EFAULT;
break;
case PT_OLD_TIMESPEC:
if (get_old_timespec32(&ts, tsp))
return -EFAULT;
break;
default:
BUG();
}
to = &end_time;
if (poll_select_set_timeout(to, ts.tv_sec, ts.tv_nsec))
return -EINVAL;
}
ret = set_user_sigmask(sigmask, sigsetsize);
if (ret)
return ret;
ret = core_sys_select(n, inp, outp, exp, to);
return poll_select_finish(&end_time, tsp, type, ret);
}
/*
* Most architectures can't handle 7-argument syscalls. So we provide a
* 6-argument version where the sixth argument is a pointer to a structure
* which has a pointer to the sigset_t itself followed by a size_t containing
* the sigset size.
*/
struct sigset_argpack {
sigset_t __user *p;
size_t size;
};
static inline int get_sigset_argpack(struct sigset_argpack *to,
struct sigset_argpack __user *from)
{
// the path is hot enough for overhead of copy_from_user() to matter
if (from) {
scoped_user_read_access(from, Efault) {
unsafe_get_user(to->p, &from->p, Efault);
unsafe_get_user(to->size, &from->size, Efault);
}
}
return 0;
Efault:
return -EFAULT;
}
SYSCALL_DEFINE6(pselect6, int, n, fd_set __user *, inp, fd_set __user *, outp,
fd_set __user *, exp, struct __kernel_timespec __user *, tsp,
void __user *, sig)
{
struct sigset_argpack x = {NULL, 0};
if (get_sigset_argpack(&x, sig))
return -EFAULT;
return do_pselect(n, inp, outp, exp, tsp, x.p, x.size, PT_TIMESPEC);
}
#if defined(CONFIG_COMPAT_32BIT_TIME) && !defined(CONFIG_64BIT)
SYSCALL_DEFINE6(pselect6_time32, int, n, fd_set __user *, inp, fd_set __user *, outp,
fd_set __user *, exp, struct old_timespec32 __user *, tsp,
void __user *, sig)
{
struct sigset_argpack x = {NULL, 0};
if (get_sigset_argpack(&x, sig))
return -EFAULT;
Annotation
- Immediate include surface: `linux/compat.h`, `linux/kernel.h`, `linux/sched/signal.h`, `linux/sched/rt.h`, `linux/syscalls.h`, `linux/export.h`, `linux/slab.h`, `linux/poll.h`.
- Detected declarations: `syscall select`, `syscall pselect6`, `syscall pselect6_time32`, `syscall old_select`, `syscall poll`, `syscall ppoll`, `syscall ppoll_time32`, `struct poll_table_page`, `struct sigset_argpack`, `struct sel_arg_struct`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.