FreeBSD kernel kern code
|
#include <sys/cdefs.h>
#include "opt_capsicum.h"
#include "opt_ktrace.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/capsicum.h>
#include <sys/filedesc.h>
#include <sys/filio.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/lock.h>
#include <sys/proc.h>
#include <sys/signalvar.h>
#include <sys/socketvar.h>
#include <sys/uio.h>
#include <sys/eventfd.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/limits.h>
#include <sys/malloc.h>
#include <sys/poll.h>
#include <sys/resourcevar.h>
#include <sys/selinfo.h>
#include <sys/sleepqueue.h>
#include <sys/specialfd.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/vnode.h>
#include <sys/bio.h>
#include <sys/buf.h>
#include <sys/condvar.h>
#include <security/audit/audit.h>
Go to the source code of this file.
Data Structures | |
struct | seltd |
struct | selfd |
struct | read_args |
struct | pread_args |
struct | readv_args |
struct | preadv_args |
struct | write_args |
struct | pwrite_args |
struct | writev_args |
struct | pwritev_args |
struct | ftruncate_args |
struct | ioctl_args |
struct | select_args |
Macros | |
#define | SYS_IOCTL_SMALL_SIZE 128 /* bytes */ |
#define | SYS_IOCTL_SMALL_ALIGN 8 /* bytes */ |
#define | SELTD_PENDING 0x0001 /* We have pending events. */ |
#define | SELTD_RESCAN 0x0002 /* Doing a rescan. */ |
#define | getbits(name, x) |
#define | swizzle_fdset(bits) |
#define | putbits(name, x) |
Functions | |
__FBSDID ("$FreeBSD$") | |
CTASSERT (sizeof(register_t) >=sizeof(size_t)) | |
static | MALLOC_DEFINE (M_IOCTLOPS, "ioctlops", "ioctl data buffer") |
static | MALLOC_DEFINE (M_SELECT, "select", "select() buffer") |
MALLOC_DEFINE (M_IOV, "iov", "large iov's") | |
static int | pollout (struct thread *, struct pollfd *, struct pollfd *, u_int) |
static int | pollscan (struct thread *, struct pollfd *, u_int) |
static int | pollrescan (struct thread *) |
static int | selscan (struct thread *, fd_mask **, fd_mask **, int) |
static int | selrescan (struct thread *, fd_mask **, fd_mask **) |
static void | selfdalloc (struct thread *, void *) |
static void | selfdfree (struct seltd *, struct selfd *) |
static int | dofileread (struct thread *, int, struct file *, struct uio *, off_t, int) |
static int | dofilewrite (struct thread *, int, struct file *, struct uio *, off_t, int) |
static void | doselwakeup (struct selinfo *, int) |
static void | seltdinit (struct thread *) |
static int | seltdwait (struct thread *, sbintime_t, sbintime_t) |
static void | seltdclear (struct thread *) |
MALLOC_DEFINE (M_SELFD, "selfd", "selfd") | |
int | sys_read (struct thread *td, struct read_args *uap) |
int | sys_pread (struct thread *td, struct pread_args *uap) |
int | kern_pread (struct thread *td, int fd, void *buf, size_t nbyte, off_t offset) |
int | sys_readv (struct thread *td, struct readv_args *uap) |
int | kern_readv (struct thread *td, int fd, struct uio *auio) |
int | sys_preadv (struct thread *td, struct preadv_args *uap) |
int | kern_preadv (struct thread *td, int fd, struct uio *auio, off_t offset) |
int | sys_write (struct thread *td, struct write_args *uap) |
int | sys_pwrite (struct thread *td, struct pwrite_args *uap) |
int | kern_pwrite (struct thread *td, int fd, const void *buf, size_t nbyte, off_t offset) |
int | sys_writev (struct thread *td, struct writev_args *uap) |
int | kern_writev (struct thread *td, int fd, struct uio *auio) |
int | sys_pwritev (struct thread *td, struct pwritev_args *uap) |
int | kern_pwritev (struct thread *td, int fd, struct uio *auio, off_t offset) |
int | kern_ftruncate (struct thread *td, int fd, off_t length) |
int | sys_ftruncate (struct thread *td, struct ftruncate_args *uap) |
int | sys_ioctl (struct thread *td, struct ioctl_args *uap) |
int | kern_ioctl (struct thread *td, int fd, u_long com, caddr_t data) |
int | sys_posix_fallocate (struct thread *td, struct posix_fallocate_args *uap) |
int | kern_posix_fallocate (struct thread *td, int fd, off_t offset, off_t len) |
int | sys_fspacectl (struct thread *td, struct fspacectl_args *uap) |
int | kern_fspacectl (struct thread *td, int fd, int cmd, const struct spacectl_range *rqsr, int flags, struct spacectl_range *rmsrp) |
int | kern_specialfd (struct thread *td, int type, void *arg) |
int | sys___specialfd (struct thread *td, struct __specialfd_args *args) |
int | poll_no_poll (int events) |
int | sys_pselect (struct thread *td, struct pselect_args *uap) |
int | kern_pselect (struct thread *td, int nd, fd_set *in, fd_set *ou, fd_set *ex, struct timeval *tvp, sigset_t *uset, int abi_nfdbits) |
int | sys_select (struct thread *td, struct select_args *uap) |
static int | select_check_badfd (fd_set *fd_in, int nd, int ndu, int abi_nfdbits) |
int | kern_select (struct thread *td, int nd, fd_set *fd_in, fd_set *fd_ou, fd_set *fd_ex, struct timeval *tvp, int abi_nfdbits) |
static __inline int | selflags (fd_mask **ibits, int idx, fd_mask bit) |
static __inline int | selsetbits (fd_mask **ibits, fd_mask **obits, int idx, fd_mask bit, int events) |
int | sys_poll (struct thread *td, struct poll_args *uap) |
int | kern_poll_kfds (struct thread *td, struct pollfd *kfds, u_int nfds, struct timespec *tsp, sigset_t *uset) |
int | sys_ppoll (struct thread *td, struct ppoll_args *uap) |
int | kern_poll (struct thread *td, struct pollfd *ufds, u_int nfds, struct timespec *tsp, sigset_t *set) |
bool | kern_poll_maxfds (u_int nfds) |
int | selsocket (struct socket *so, int events, struct timeval *tvp, struct thread *td) |
void | seldrain (struct selinfo *sip) |
void | selrecord (struct thread *selector, struct selinfo *sip) |
void | selwakeup (struct selinfo *sip) |
void | selwakeuppri (struct selinfo *sip, int pri) |
void | seltdfini (struct thread *td) |
static void | selectinit (void *) |
SYSINIT (select, SI_SUB_SYSCALLS, SI_ORDER_ANY, selectinit, NULL) | |
static void | selectinit (void *dummy __unused) |
int | kern_posix_error (struct thread *td, int error) |
Variables | |
static struct mtx_pool * | mtxpool_select |
static const int | select_flags [3] |
#define getbits | ( | name, | |
x | |||
) |
#define putbits | ( | name, | |
x | |||
) |
#define SELTD_PENDING 0x0001 /* We have pending events. */ |
Definition at line 147 of file sys_generic.c.
#define SELTD_RESCAN 0x0002 /* Doing a rescan. */ |
Definition at line 148 of file sys_generic.c.
#define swizzle_fdset | ( | bits | ) |
#define SYS_IOCTL_SMALL_ALIGN 8 /* bytes */ |
Definition at line 93 of file sys_generic.c.
#define SYS_IOCTL_SMALL_SIZE 128 /* bytes */ |
Definition at line 92 of file sys_generic.c.
__FBSDID | ( | "$FreeBSD$" | ) |
CTASSERT | ( | sizeof(register_t) >=sizeof(size_t) | ) |
|
static |
Definition at line 345 of file sys_generic.c.
References cloneuio(), fd, and flags.
Referenced by kern_preadv(), and kern_readv().
|
static |
Definition at line 547 of file sys_generic.c.
References cloneuio(), fd, flags, and tdsignal().
Referenced by kern_pwritev(), and kern_writev().
|
static |
Definition at line 1933 of file sys_generic.c.
References cv_broadcastpri(), and SELTD_PENDING.
Referenced by seldrain(), selwakeup(), and selwakeuppri().
int kern_fspacectl | ( | struct thread * | td, |
int | fd, | ||
int | cmd, | ||
const struct spacectl_range * | rqsr, | ||
int | flags, | ||
struct spacectl_range * | rmsrp | ||
) |
Definition at line 885 of file sys_generic.c.
References cap_pwrite_rights, fd, fget_write(), and flags.
Referenced by sys_fspacectl().
int kern_ftruncate | ( | struct thread * | td, |
int | fd, | ||
off_t | length | ||
) |
Definition at line 594 of file sys_generic.c.
References cap_ftruncate_rights, fd, and fget().
Referenced by sys_ftruncate().
int kern_ioctl | ( | struct thread * | td, |
int | fd, | ||
u_long | com, | ||
caddr_t | data | ||
) |
Definition at line 723 of file sys_generic.c.
References cap_ioctl_rights, data, fd, and fget().
Referenced by parse_dir_md(), and sys_ioctl().
int kern_poll | ( | struct thread * | td, |
struct pollfd * | ufds, | ||
u_int | nfds, | ||
struct timespec * | tsp, | ||
sigset_t * | set | ||
) |
Definition at line 1594 of file sys_generic.c.
References free(), kern_poll_kfds(), kern_poll_maxfds(), mallocarray(), pollout(), and set.
Referenced by sys_poll(), and sys_ppoll().
int kern_poll_kfds | ( | struct thread * | td, |
struct pollfd * | kfds, | ||
u_int | nfds, | ||
struct timespec * | tsp, | ||
sigset_t * | uset | ||
) |
Definition at line 1494 of file sys_generic.c.
References kern_sigprocmask(), pollrescan(), pollscan(), seltdclear(), seltdinit(), seltdwait(), tc_precexp, tc_tick_sbt, and ts.
Referenced by kern_poll().
bool kern_poll_maxfds | ( | u_int | nfds | ) |
Definition at line 1622 of file sys_generic.c.
References maxfilesperproc.
Referenced by kern_poll().
int kern_posix_error | ( | struct thread * | td, |
int | error | ||
) |
Definition at line 2070 of file sys_generic.c.
Referenced by sys_clock_nanosleep(), sys_posix_fadvise(), and sys_posix_fallocate().
int kern_posix_fallocate | ( | struct thread * | td, |
int | fd, | ||
off_t | offset, | ||
off_t | len | ||
) |
Definition at line 833 of file sys_generic.c.
References cap_pwrite_rights, fd, and fget().
Referenced by sys_posix_fallocate().
int kern_pread | ( | struct thread * | td, |
int | fd, | ||
void * | buf, | ||
size_t | nbyte, | ||
off_t | offset | ||
) |
Definition at line 230 of file sys_generic.c.
References buf, fd, and kern_preadv().
Referenced by sys_pread().
int kern_preadv | ( | struct thread * | td, |
int | fd, | ||
struct uio * | auio, | ||
off_t | offset | ||
) |
Definition at line 321 of file sys_generic.c.
References cap_pread_rights, dofileread(), fd, and fget_read().
Referenced by kern_pread(), and sys_preadv().
int kern_pselect | ( | struct thread * | td, |
int | nd, | ||
fd_set * | in, | ||
fd_set * | ou, | ||
fd_set * | ex, | ||
struct timeval * | tvp, | ||
sigset_t * | uset, | ||
int | abi_nfdbits | ||
) |
Definition at line 1039 of file sys_generic.c.
References kern_select(), and kern_sigprocmask().
Referenced by sys_pselect().
int kern_pwrite | ( | struct thread * | td, |
int | fd, | ||
const void * | buf, | ||
size_t | nbyte, | ||
off_t | offset | ||
) |
Definition at line 431 of file sys_generic.c.
References buf, fd, and kern_pwritev().
Referenced by sys_pwrite().
int kern_pwritev | ( | struct thread * | td, |
int | fd, | ||
struct uio * | auio, | ||
off_t | offset | ||
) |
Definition at line 523 of file sys_generic.c.
References cap_pwrite_rights, dofilewrite(), fd, and fget_write().
Referenced by kern_pwrite(), and sys_pwritev().
int kern_readv | ( | struct thread * | td, |
int | fd, | ||
struct uio * | auio | ||
) |
Definition at line 282 of file sys_generic.c.
References cap_read_rights, dofileread(), fd, and fget_read().
Referenced by sys_read(), and sys_readv().
int kern_select | ( | struct thread * | td, |
int | nd, | ||
fd_set * | fd_in, | ||
fd_set * | fd_ou, | ||
fd_set * | fd_ex, | ||
struct timeval * | tvp, | ||
int | abi_nfdbits | ||
) |
Definition at line 1137 of file sys_generic.c.
References free(), getbits, malloc(), putbits, select_check_badfd(), selrescan(), selscan(), seltdclear(), seltdinit(), seltdwait(), swizzle_fdset, tc_precexp, and tc_tick_sbt.
Referenced by kern_pselect(), and sys_select().
int kern_specialfd | ( | struct thread * | td, |
int | type, | ||
void * | arg | ||
) |
Definition at line 935 of file sys_generic.c.
References eventfd_create_file(), fd, finstall(), and type.
Referenced by sys___specialfd().
int kern_writev | ( | struct thread * | td, |
int | fd, | ||
struct uio * | auio | ||
) |
Definition at line 484 of file sys_generic.c.
References cap_write_rights, dofilewrite(), fd, and fget_write().
Referenced by sys_write(), sys_writev(), and vn_sendfile().
|
static |
MALLOC_DEFINE | ( | M_IOV | , |
"iov" | , | ||
"large iov's" | |||
) |
|
static |
MALLOC_DEFINE | ( | M_SELFD | , |
"selfd" | , | ||
"selfd" | |||
) |
int poll_no_poll | ( | int | events | ) |
Definition at line 996 of file sys_generic.c.
Referenced by invfo_poll(), and no_poll().
|
static |
Definition at line 1686 of file sys_generic.c.
Referenced by kern_poll().
|
static |
Definition at line 1636 of file sys_generic.c.
References cap_event_rights, fd, fget_only_user(), fget_unlocked(), and selfdfree().
Referenced by kern_poll_kfds().
|
static |
Definition at line 1707 of file sys_generic.c.
References cap_event_rights, fget_only_user(), fget_unlocked(), and selfdalloc().
Referenced by kern_poll_kfds().
void seldrain | ( | struct selinfo * | sip | ) |
Definition at line 1851 of file sys_generic.c.
References doselwakeup().
Referenced by destroy_vpollinfo(), eventfd_close(), kqueue_destroy(), mqueue_free(), pipeclose(), ptsdrv_free(), sofree(), and tty_dealloc().
|
static |
Definition at line 1098 of file sys_generic.c.
Referenced by kern_select().
|
static |
|
static |
Definition at line 2059 of file sys_generic.c.
References mtx_pool_create(), and mtxpool_select.
|
static |
Definition at line 1817 of file sys_generic.c.
References malloc().
Referenced by pollscan(), selscan(), and selsocket().
Definition at line 1833 of file sys_generic.c.
References free().
Referenced by pollrescan(), selrescan(), and seltdclear().
|
static |
Definition at line 1328 of file sys_generic.c.
References flags, and select_flags.
Referenced by selrescan(), and selscan().
void selrecord | ( | struct thread * | selector, |
struct selinfo * | sip | ||
) |
Definition at line 1869 of file sys_generic.c.
References mtx, mtx_pool_find(), mtxpool_select, panic(), and SELTD_RESCAN.
Referenced by devpoll(), eventfd_poll(), kqueue_poll(), logpoll(), mqf_poll(), pipe_poll(), procdesc_poll(), ptsdev_poll(), sopoll_generic(), ttydev_poll(), and vn_pollrecord().
|
static |
Definition at line 1382 of file sys_generic.c.
References cap_event_rights, ev, fd, fget_only_user(), fget_unlocked(), selfdfree(), selflags(), and selsetbits().
Referenced by kern_select().
|
static |
Definition at line 1432 of file sys_generic.c.
References cap_event_rights, ev, fd, fget_only_user(), fget_unlocked(), flags, selfdalloc(), selflags(), and selsetbits().
Referenced by kern_select().
|
static |
Definition at line 1349 of file sys_generic.c.
References select_flags.
Referenced by selrescan(), and selscan().
int selsocket | ( | struct socket * | so, |
int | events, | ||
struct timeval * | tvp, | ||
struct thread * | td | ||
) |
Definition at line 1763 of file sys_generic.c.
References selfdalloc(), seltdclear(), seltdinit(), seltdwait(), sopoll(), tc_precexp, and tc_tick_sbt.
|
static |
Definition at line 2044 of file sys_generic.c.
References selfdfree().
Referenced by kern_poll_kfds(), kern_select(), and selsocket().
void seltdfini | ( | struct thread * | td | ) |
Definition at line 2020 of file sys_generic.c.
References cv_destroy(), and free().
Referenced by exit1(), and thread_dtor().
|
static |
Definition at line 1969 of file sys_generic.c.
References cv_init(), and malloc().
Referenced by kern_poll_kfds(), kern_select(), and selsocket().
|
static |
Definition at line 1988 of file sys_generic.c.
References SELTD_PENDING, and SELTD_RESCAN.
Referenced by kern_poll_kfds(), kern_select(), and selsocket().
void selwakeup | ( | struct selinfo * | sip | ) |
Definition at line 1917 of file sys_generic.c.
References doselwakeup().
Referenced by _mqueue_recv(), _mqueue_send(), devctl_queue(), eventfd_read(), eventfd_write(), mqueue_fdclose(), procdesc_exit(), ptsdrv_inwakeup(), ptsdrv_outwakeup(), and tty_wakeup().
void selwakeuppri | ( | struct selinfo * | sip, |
int | pri | ||
) |
Definition at line 1924 of file sys_generic.c.
References doselwakeup().
Referenced by kqueue_drain(), kqueue_wakeup(), logtimeout(), pipeselwakeup(), sohasoutofband(), solisten_wakeup(), and sowakeup().
int sys___specialfd | ( | struct thread * | td, |
struct __specialfd_args * | args | ||
) |
Definition at line 967 of file sys_generic.c.
References kern_specialfd().
int sys_fspacectl | ( | struct thread * | td, |
struct fspacectl_args * | uap | ||
) |
Definition at line 865 of file sys_generic.c.
References kern_fspacectl().
int sys_ftruncate | ( | struct thread * | td, |
struct ftruncate_args * | uap | ||
) |
Definition at line 623 of file sys_generic.c.
References ftruncate_args::fd, kern_ftruncate(), and ftruncate_args::length.
int sys_ioctl | ( | struct thread * | td, |
struct ioctl_args * | uap | ||
) |
Definition at line 653 of file sys_generic.c.
References __aligned, ioctl_args::com, data, ioctl_args::data, ioctl_args::fd, free(), kern_ioctl(), malloc(), printf(), SYS_IOCTL_SMALL_ALIGN, and SYS_IOCTL_SMALL_SIZE.
int sys_poll | ( | struct thread * | td, |
struct poll_args * | uap | ||
) |
Definition at line 1474 of file sys_generic.c.
References kern_poll(), and ts.
int sys_posix_fallocate | ( | struct thread * | td, |
struct posix_fallocate_args * | uap | ||
) |
Definition at line 824 of file sys_generic.c.
References kern_posix_error(), and kern_posix_fallocate().
int sys_ppoll | ( | struct thread * | td, |
struct ppoll_args * | uap | ||
) |
Definition at line 1567 of file sys_generic.c.
References kern_poll(), set, and ts.
int sys_pread | ( | struct thread * | td, |
struct pread_args * | uap | ||
) |
Definition at line 223 of file sys_generic.c.
References pread_args::buf, pread_args::fd, kern_pread(), pread_args::nbyte, and pread_args::offset.
int sys_preadv | ( | struct thread * | td, |
struct preadv_args * | uap | ||
) |
Definition at line 307 of file sys_generic.c.
References copyinuio(), preadv_args::fd, free(), preadv_args::iovcnt, preadv_args::iovp, kern_preadv(), and preadv_args::offset.
int sys_pselect | ( | struct thread * | td, |
struct pselect_args * | uap | ||
) |
Definition at line 1012 of file sys_generic.c.
References kern_pselect(), set, and ts.
int sys_pwrite | ( | struct thread * | td, |
struct pwrite_args * | uap | ||
) |
Definition at line 424 of file sys_generic.c.
References pwrite_args::buf, pwrite_args::fd, kern_pwrite(), pwrite_args::nbyte, and pwrite_args::offset.
int sys_pwritev | ( | struct thread * | td, |
struct pwritev_args * | uap | ||
) |
Definition at line 509 of file sys_generic.c.
References copyinuio(), pwritev_args::fd, free(), pwritev_args::iovcnt, pwritev_args::iovp, kern_pwritev(), and pwritev_args::offset.
int sys_read | ( | struct thread * | td, |
struct read_args * | uap | ||
) |
Definition at line 192 of file sys_generic.c.
References read_args::buf, read_args::fd, kern_readv(), and read_args::nbyte.
int sys_readv | ( | struct thread * | td, |
struct readv_args * | uap | ||
) |
Definition at line 268 of file sys_generic.c.
References copyinuio(), readv_args::fd, free(), readv_args::iovcnt, readv_args::iovp, and kern_readv().
int sys_select | ( | struct thread * | td, |
struct select_args * | uap | ||
) |
Definition at line 1071 of file sys_generic.c.
References select_args::ex, select_args::in, kern_select(), select_args::nd, select_args::ou, and select_args::tv.
int sys_write | ( | struct thread * | td, |
struct write_args * | uap | ||
) |
Definition at line 393 of file sys_generic.c.
References write_args::buf, write_args::fd, kern_writev(), and write_args::nbyte.
int sys_writev | ( | struct thread * | td, |
struct writev_args * | uap | ||
) |
Definition at line 470 of file sys_generic.c.
References copyinuio(), writev_args::fd, free(), writev_args::iovcnt, writev_args::iovp, and kern_writev().
SYSINIT | ( | select | , |
SI_SUB_SYSCALLS | , | ||
SI_ORDER_ANY | , | ||
selectinit | , | ||
NULL | |||
) |
|
static |
Definition at line 164 of file sys_generic.c.
Referenced by selectinit(), and selrecord().
|
static |
Definition at line 1317 of file sys_generic.c.
Referenced by selflags(), and selsetbits().