FreeBSD kernel kern code
sys_pipe.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/filio.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/ttycom.h>
#include <sys/stat.h>
#include <sys/malloc.h>
#include <sys/poll.h>
#include <sys/selinfo.h>
#include <sys/signalvar.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/pipe.h>
#include <sys/proc.h>
#include <sys/vnode.h>
#include <sys/uio.h>
#include <sys/event.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/vm_object.h>
#include <vm/vm_kern.h>
#include <vm/vm_extern.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <vm/vm_page.h>
#include <vm/uma.h>
Include dependency graph for sys_pipe.c:

Go to the source code of this file.

Macros

#define MINPIPESIZE   (PIPE_SIZE/3)
 
#define MAXPIPESIZE   (2*PIPE_SIZE/3)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
int do_pipe (struct thread *td, int fildes[2], int flags)
 
static void filt_pipedetach (struct knote *kn)
 
static int filt_piperead (struct knote *kn, long hint)
 
static int filt_pipewrite (struct knote *kn, long hint)
 
 SYSCTL_LONG (_kern_ipc, OID_AUTO, maxpipekva, CTLFLAG_RDTUN,&maxpipekva, 0,"Pipe KVA limit")
 
 SYSCTL_LONG (_kern_ipc, OID_AUTO, pipekva, CTLFLAG_RD,&amountpipekva, 0,"Pipe KVA usage")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, pipefragretry, CTLFLAG_RD,&pipefragretry, 0,"Pipe allocation retries due to fragmentation")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, pipeallocfail, CTLFLAG_RD,&pipeallocfail, 0,"Pipe allocation failures")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, piperesizefail, CTLFLAG_RD,&piperesizefail, 0,"Pipe resize failures")
 
 SYSCTL_INT (_kern_ipc, OID_AUTO, piperesizeallowed, CTLFLAG_RW,&piperesizeallowed, 0,"Pipe resizing allowed")
 
static void pipeinit (void *dummy __unused)
 
static void pipeclose (struct pipe *cpipe)
 
static void pipe_free_kmem (struct pipe *cpipe)
 
static int pipe_create (struct pipe *pipe, int backing)
 
static __inline int pipelock (struct pipe *cpipe, int catch)
 
static __inline void pipeunlock (struct pipe *cpipe)
 
static __inline void pipeselwakeup (struct pipe *cpipe)
 
static int pipe_build_write_buffer (struct pipe *wpipe, struct uio *uio)
 
static void pipe_destroy_write_buffer (struct pipe *wpipe)
 
static int pipe_direct_write (struct pipe *wpipe, struct uio *uio)
 
static void pipe_clone_write_buffer (struct pipe *wpipe)
 
static int pipespace (struct pipe *cpipe, int size)
 
static int pipespace_new (struct pipe *cpipe, int size)
 
static int pipe_zone_ctor (void *mem, int size, void *arg, int flags)
 
static int pipe_zone_init (void *mem, int size, int flags)
 
static void pipe_zone_fini (void *mem, int size)
 
 SYSINIT (vfs, SI_SUB_VFS, SI_ORDER_ANY, pipeinit, NULL)
 
int kern_pipe (struct thread *td, int fildes[2])
 
int sys_pipe (struct thread *td, struct pipe_args *uap)
 
static int pipe_read (struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
 
static int pipe_write (struct file *fp, struct uio *uio, struct ucred *active_cred, int flags, struct thread *td)
 
static int pipe_truncate (struct file *fp, off_t length, struct ucred *active_cred, struct thread *td)
 
static int pipe_ioctl (struct file *fp, u_long cmd, void *data, struct ucred *active_cred, struct thread *td)
 
static int pipe_poll (struct file *fp, int events, struct ucred *active_cred, struct thread *td)
 
static int pipe_stat (struct file *fp, struct stat *ub, struct ucred *active_cred, struct thread *td)
 
static int pipe_close (struct file *fp, struct thread *td)
 
static int pipe_kqfilter (struct file *fp, struct knote *kn)
 

Variables

static fo_rdwr_t pipe_read
 
static fo_rdwr_t pipe_write
 
static fo_truncate_t pipe_truncate
 
static fo_ioctl_t pipe_ioctl
 
static fo_poll_t pipe_poll
 
static fo_kqfilter_t pipe_kqfilter
 
static fo_stat_t pipe_stat
 
static fo_close_t pipe_close
 
static struct fileops pipeops
 
static struct filterops pipe_rfiltops
 
static struct filterops pipe_wfiltops
 
static long amountpipekva
 
static int pipefragretry
 
static int pipeallocfail
 
static int piperesizefail
 
static int piperesizeallowed = 1
 
static uma_zone_t pipe_zone
 
static struct unrhdrpipeino_unr
 
static dev_t pipedev_ino
 

Macro Definition Documentation

#define MAXPIPESIZE   (2*PIPE_SIZE/3)

Definition at line 189 of file sys_pipe.c.

#define MINPIPESIZE   (PIPE_SIZE/3)

Definition at line 188 of file sys_pipe.c.

Referenced by pipe_read().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
int do_pipe ( struct thread *  td,
int  fildes[2],
int  flags 
)

Definition at line 335 of file sys_pipe.c.

References falloc(), fd, fdclose(), finit(), knlist_init_mtx(), pipe_create(), pipe_zone, pipeclose(), and pipeops.

Referenced by kern_pipe().

Here is the call graph for this function:

Here is the caller graph for this function:

static void filt_pipedetach ( struct knote kn)
static

Definition at line 1629 of file sys_pipe.c.

References knlist_remove().

Here is the call graph for this function:

static int filt_piperead ( struct knote kn,
long  hint 
)
static

Definition at line 1642 of file sys_pipe.c.

static int filt_pipewrite ( struct knote kn,
long  hint 
)
static

Definition at line 1667 of file sys_pipe.c.

int kern_pipe ( struct thread *  td,
int  fildes[2] 
)

Definition at line 328 of file sys_pipe.c.

References do_pipe().

Referenced by sys_pipe().

Here is the call graph for this function:

Here is the caller graph for this function:

static int pipe_build_write_buffer ( struct pipe *  wpipe,
struct uio *  uio 
)
static

Definition at line 770 of file sys_pipe.c.

Referenced by pipe_direct_write().

Here is the caller graph for this function:

static void pipe_clone_write_buffer ( struct pipe *  wpipe)
static

Definition at line 831 of file sys_pipe.c.

References pipe_destroy_write_buffer().

Referenced by pipe_direct_write().

Here is the call graph for this function:

Here is the caller graph for this function:

static int pipe_close ( struct file *  fp,
struct thread *  td 
)
static

Definition at line 1470 of file sys_pipe.c.

References badfileops, funsetown(), and pipeclose().

Here is the call graph for this function:

static int pipe_create ( struct pipe *  pipe,
int  backing 
)
static

Definition at line 571 of file sys_pipe.c.

References amountpipekva, maxpipekva, and pipespace_new().

Referenced by do_pipe().

Here is the call graph for this function:

Here is the caller graph for this function:

static void pipe_destroy_write_buffer ( struct pipe *  wpipe)
static

Definition at line 816 of file sys_pipe.c.

Referenced by pipe_clone_write_buffer(), and pipe_direct_write().

Here is the caller graph for this function:

static int pipe_direct_write ( struct pipe *  wpipe,
struct uio *  uio 
)
static

Definition at line 871 of file sys_pipe.c.

References pipe_build_write_buffer(), pipe_clone_write_buffer(), pipe_destroy_write_buffer(), pipelock(), pipeselwakeup(), pipeunlock(), and wakeup().

Referenced by pipe_write().

Here is the call graph for this function:

Here is the caller graph for this function:

static void pipe_free_kmem ( struct pipe *  cpipe)
static

Definition at line 1484 of file sys_pipe.c.

References amountpipekva.

Referenced by pipeclose(), and pipespace_new().

Here is the caller graph for this function:

static int pipe_ioctl ( struct file *  fp,
u_long  cmd,
void *  data,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 1268 of file sys_pipe.c.

References fgetown(), and fsetown().

Here is the call graph for this function:

static int pipe_kqfilter ( struct file *  fp,
struct knote kn 
)
static

Definition at line 1599 of file sys_pipe.c.

References knlist_add(), pipe_rfiltops, and pipe_wfiltops.

Here is the call graph for this function:

static int pipe_poll ( struct file *  fp,
int  events,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 1339 of file sys_pipe.c.

References selrecord().

Here is the call graph for this function:

static int pipe_read ( struct file *  fp,
struct uio *  uio,
struct ucred *  active_cred,
int  flags,
struct thread *  td 
)
static

Definition at line 592 of file sys_pipe.c.

References amountpipekva, maxpipekva, MINPIPESIZE, pipelock(), piperesizeallowed, pipeselwakeup(), pipespace(), pipeunlock(), uiomove(), vfs_timestamp(), and wakeup().

Here is the call graph for this function:

static int pipe_stat ( struct file *  fp,
struct stat *  ub,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 1407 of file sys_pipe.c.

References alloc_unr(), new_unr(), and pipedev_ino.

Here is the call graph for this function:

static int pipe_truncate ( struct file *  fp,
off_t  length,
struct ucred *  active_cred,
struct thread *  td 
)
static

Definition at line 1254 of file sys_pipe.c.

static int pipe_write ( struct file *  fp,
struct uio *  uio,
struct ucred *  active_cred,
int  flags,
struct thread *  td 
)
static

Definition at line 970 of file sys_pipe.c.

References amountpipekva, maxpipekva, pipe_direct_write(), pipelock(), piperesizeallowed, pipeselwakeup(), pipespace(), pipeunlock(), uiomove(), vfs_timestamp(), and wakeup().

Here is the call graph for this function:

static int pipe_zone_ctor ( void *  mem,
int  size,
void *  arg,
int  flags 
)
static

Definition at line 251 of file sys_pipe.c.

References vfs_timestamp().

Referenced by pipeinit().

Here is the call graph for this function:

Here is the caller graph for this function:

static void pipe_zone_fini ( void *  mem,
int  size 
)
static

Definition at line 312 of file sys_pipe.c.

References mtx_destroy().

Referenced by pipeinit().

Here is the call graph for this function:

Here is the caller graph for this function:

static int pipe_zone_init ( void *  mem,
int  size,
int  flags 
)
static

Definition at line 299 of file sys_pipe.c.

References mtx_init().

Referenced by pipeinit().

Here is the call graph for this function:

Here is the caller graph for this function:

static void pipeclose ( struct pipe *  cpipe)
static

Definition at line 1511 of file sys_pipe.c.

References free_unr(), knlist_destroy(), pipe_free_kmem(), pipe_zone, pipelock(), pipeselwakeup(), pipeunlock(), seldrain(), and wakeup().

Referenced by do_pipe(), and pipe_close().

Here is the call graph for this function:

Here is the caller graph for this function:

static void pipeinit ( void *dummy  __unused)
static

Definition at line 237 of file sys_pipe.c.

References new_unrhdr(), pipe_zone, pipe_zone_ctor(), pipe_zone_fini(), pipe_zone_init(), and pipedev_ino.

Here is the call graph for this function:

static __inline int pipelock ( struct pipe *  cpipe,
int  catch 
)
static

Definition at line 513 of file sys_pipe.c.

Referenced by pipe_direct_write(), pipe_read(), pipe_write(), and pipeclose().

Here is the caller graph for this function:

static __inline void pipeselwakeup ( struct pipe *  cpipe)
static

Definition at line 551 of file sys_pipe.c.

References pgsigio(), and selwakeuppri().

Referenced by pipe_direct_write(), pipe_read(), pipe_write(), and pipeclose().

Here is the call graph for this function:

Here is the caller graph for this function:

static int pipespace ( struct pipe *  cpipe,
int  size 
)
static

Definition at line 499 of file sys_pipe.c.

References pipespace_new().

Referenced by pipe_read(), and pipe_write().

Here is the call graph for this function:

Here is the caller graph for this function:

static int pipespace_new ( struct pipe *  cpipe,
int  size 
)
static

Definition at line 431 of file sys_pipe.c.

References amountpipekva, pipe_free_kmem(), pipeallocfail, pipefragretry, piperesizefail, ppsratecheck(), and printf().

Referenced by pipe_create(), and pipespace().

Here is the call graph for this function:

Here is the caller graph for this function:

static __inline void pipeunlock ( struct pipe *  cpipe)
static

Definition at line 536 of file sys_pipe.c.

References wakeup().

Referenced by pipe_direct_write(), pipe_read(), pipe_write(), and pipeclose().

Here is the call graph for this function:

Here is the caller graph for this function:

int sys_pipe ( struct thread *  td,
struct pipe_args *  uap 
)

Definition at line 409 of file sys_pipe.c.

References kern_pipe().

Here is the call graph for this function:

SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
pipefragretry  ,
CTLFLAG_RD  ,
pipefragretry,
,
"Pipe allocation retries due to fragmentation"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
pipeallocfail  ,
CTLFLAG_RD  ,
pipeallocfail,
,
"Pipe allocation failures"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
piperesizefail  ,
CTLFLAG_RD  ,
piperesizefail,
,
"Pipe resize failures"   
)
SYSCTL_INT ( _kern_ipc  ,
OID_AUTO  ,
piperesizeallowed  ,
CTLFLAG_RW  ,
piperesizeallowed,
,
"Pipe resizing allowed"   
)
SYSCTL_LONG ( _kern_ipc  ,
OID_AUTO  ,
maxpipekva  ,
CTLFLAG_RDTUN  ,
maxpipekva,
,
"Pipe KVA limit"   
)
SYSCTL_LONG ( _kern_ipc  ,
OID_AUTO  ,
pipekva  ,
CTLFLAG_RD  ,
amountpipekva,
,
"Pipe KVA usage"   
)
SYSINIT ( vfs  ,
SI_SUB_VFS  ,
SI_ORDER_ANY  ,
pipeinit  ,
NULL   
)

Variable Documentation

long amountpipekva
static

Definition at line 191 of file sys_pipe.c.

Referenced by pipe_create(), pipe_free_kmem(), pipe_read(), pipe_write(), and pipespace_new().

fo_close_t pipe_close
static

Definition at line 151 of file sys_pipe.c.

fo_ioctl_t pipe_ioctl
static

Definition at line 147 of file sys_pipe.c.

fo_kqfilter_t pipe_kqfilter
static

Definition at line 149 of file sys_pipe.c.

fo_poll_t pipe_poll
static

Definition at line 148 of file sys_pipe.c.

fo_rdwr_t pipe_read
static

Definition at line 144 of file sys_pipe.c.

struct filterops pipe_rfiltops
static
Initial value:
= {
.f_isfd = 1,
.f_detach = filt_pipedetach,
.f_event = filt_piperead
}
static void filt_pipedetach(struct knote *kn)
Definition: sys_pipe.c:1629
static int filt_piperead(struct knote *kn, long hint)
Definition: sys_pipe.c:1642

Definition at line 171 of file sys_pipe.c.

Referenced by pipe_kqfilter().

fo_stat_t pipe_stat
static

Definition at line 150 of file sys_pipe.c.

fo_truncate_t pipe_truncate
static

Definition at line 146 of file sys_pipe.c.

struct filterops pipe_wfiltops
static
Initial value:
= {
.f_isfd = 1,
.f_detach = filt_pipedetach,
.f_event = filt_pipewrite
}
static void filt_pipedetach(struct knote *kn)
Definition: sys_pipe.c:1629
static int filt_pipewrite(struct knote *kn, long hint)
Definition: sys_pipe.c:1667

Definition at line 176 of file sys_pipe.c.

Referenced by pipe_kqfilter().

fo_rdwr_t pipe_write
static

Definition at line 145 of file sys_pipe.c.

uma_zone_t pipe_zone
static

Definition at line 230 of file sys_pipe.c.

Referenced by do_pipe(), pipeclose(), and pipeinit().

int pipeallocfail
static

Definition at line 193 of file sys_pipe.c.

Referenced by pipespace_new().

dev_t pipedev_ino
static

Definition at line 232 of file sys_pipe.c.

Referenced by pipe_stat(), and pipeinit().

int pipefragretry
static

Definition at line 192 of file sys_pipe.c.

Referenced by pipespace_new().

struct unrhdr* pipeino_unr
static

Definition at line 231 of file sys_pipe.c.

struct fileops pipeops
static
Initial value:
= {
.fo_read = pipe_read,
.fo_write = pipe_write,
.fo_truncate = pipe_truncate,
.fo_ioctl = pipe_ioctl,
.fo_poll = pipe_poll,
.fo_kqfilter = pipe_kqfilter,
.fo_stat = pipe_stat,
.fo_close = pipe_close,
.fo_chmod = invfo_chmod,
.fo_chown = invfo_chown,
.fo_flags = DFLAG_PASSABLE
}
static fo_kqfilter_t pipe_kqfilter
Definition: sys_pipe.c:149
int invfo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
static fo_rdwr_t pipe_read
Definition: sys_pipe.c:144
static fo_poll_t pipe_poll
Definition: sys_pipe.c:148
int invfo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td)
static fo_ioctl_t pipe_ioctl
Definition: sys_pipe.c:147
static fo_stat_t pipe_stat
Definition: sys_pipe.c:150
static fo_rdwr_t pipe_write
Definition: sys_pipe.c:145
static fo_truncate_t pipe_truncate
Definition: sys_pipe.c:146
static fo_close_t pipe_close
Definition: sys_pipe.c:151

Definition at line 153 of file sys_pipe.c.

Referenced by do_pipe().

int piperesizeallowed = 1
static

Definition at line 195 of file sys_pipe.c.

Referenced by pipe_read(), and pipe_write().

int piperesizefail
static

Definition at line 194 of file sys_pipe.c.

Referenced by pipespace_new().