91 #include <sys/cdefs.h>
94 #include <sys/param.h>
95 #include <sys/systm.h>
97 #include <sys/fcntl.h>
99 #include <sys/filedesc.h>
100 #include <sys/filio.h>
101 #include <sys/kernel.h>
102 #include <sys/lock.h>
103 #include <sys/mutex.h>
104 #include <sys/ttycom.h>
105 #include <sys/stat.h>
106 #include <sys/malloc.h>
107 #include <sys/poll.h>
108 #include <sys/selinfo.h>
109 #include <sys/signalvar.h>
110 #include <sys/syscallsubr.h>
111 #include <sys/sysctl.h>
112 #include <sys/sysproto.h>
113 #include <sys/pipe.h>
114 #include <sys/proc.h>
115 #include <sys/vnode.h>
117 #include <sys/event.h>
119 #include <security/mac/mac_framework.h>
122 #include <vm/vm_param.h>
123 #include <vm/vm_object.h>
124 #include <vm/vm_kern.h>
125 #include <vm/vm_extern.h>
127 #include <vm/vm_map.h>
128 #include <vm/vm_page.h>
132 int do_pipe(
struct thread *td,
int fildes[2],
int flags);
164 .fo_flags = DFLAG_PASSABLE
188 #define MINPIPESIZE (PIPE_SIZE/3)
189 #define MAXPIPESIZE (2*PIPE_SIZE/3)
199 SYSCTL_LONG(_kern_ipc, OID_AUTO, pipekva, CTLFLAG_RD,
202 &
pipefragretry, 0,
"Pipe allocation retries due to fragmentation");
211 static void pipeclose(
struct pipe *cpipe);
213 static int pipe_create(
struct pipe *pipe,
int backing);
214 static __inline
int pipelock(
struct pipe *cpipe,
int catch);
215 static __inline
void pipeunlock(
struct pipe *cpipe);
217 #ifndef PIPE_NODIRECT
223 static int pipespace(
struct pipe *cpipe,
int size);
226 static int pipe_zone_ctor(
void *mem,
int size,
void *arg,
int flags);
240 pipe_zone = uma_zcreate(
"pipe",
sizeof(
struct pipepair),
243 KASSERT(
pipe_zone != NULL, (
"pipe_zone not initialized"));
245 KASSERT(pipeino_unr != NULL, (
"pipe fake inodes not initialized"));
247 KASSERT(
pipedev_ino > 0, (
"pipe dev inode not initialized"));
254 struct pipe *rpipe, *wpipe;
256 KASSERT(size ==
sizeof(*pp), (
"pipe_zone_ctor: wrong size"));
258 pp = (
struct pipepair *)mem;
265 rpipe = &pp->pp_rpipe;
266 bzero(rpipe,
sizeof(*rpipe));
268 rpipe->pipe_atime = rpipe->pipe_mtime = rpipe->pipe_ctime;
270 wpipe = &pp->pp_wpipe;
271 bzero(wpipe,
sizeof(*wpipe));
272 wpipe->pipe_ctime = rpipe->pipe_ctime;
273 wpipe->pipe_atime = wpipe->pipe_mtime = rpipe->pipe_ctime;
275 rpipe->pipe_peer = wpipe;
276 rpipe->pipe_pair = pp;
277 wpipe->pipe_peer = rpipe;
278 wpipe->pipe_pair = pp;
285 rpipe->pipe_present = PIPE_ACTIVE;
286 wpipe->pipe_present = PIPE_ACTIVE;
303 KASSERT(size ==
sizeof(*pp), (
"pipe_zone_init: wrong size"));
305 pp = (
struct pipepair *)mem;
307 mtx_init(&pp->pp_mtx,
"pipe mutex", NULL, MTX_DEF | MTX_RECURSE);
316 KASSERT(size ==
sizeof(*pp), (
"pipe_zone_fini: wrong size"));
318 pp = (
struct pipepair *)mem;
331 return (
do_pipe(td, fildes, 0));
335 do_pipe(
struct thread *td,
int fildes[2],
int flags)
337 struct filedesc *fdp = td->td_proc->p_fd;
338 struct file *rf, *wf;
340 struct pipe *rpipe, *wpipe;
341 int fd, fflags, error;
351 mac_pipe_create(td->td_ucred, pp);
353 rpipe = &pp->pp_rpipe;
354 wpipe = &pp->pp_wpipe;
367 rpipe->pipe_state |= PIPE_DIRECTOK;
368 wpipe->pipe_state |= PIPE_DIRECTOK;
370 error =
falloc(td, &rf, &fd, flags);
379 fflags = FREAD | FWRITE;
380 if ((flags & O_NONBLOCK) != 0)
390 error =
falloc(td, &wf, &fd, flags);
392 fdclose(fdp, rf, fildes[0], td);
418 td->td_retval[0] = fildes[0];
419 td->td_retval[1] = fildes[1];
436 int error, cnt, firstseg;
437 static int curfail = 0;
438 static struct timeval lastfail;
440 KASSERT(!mtx_owned(PIPE_MTX(cpipe)), (
"pipespace: pipe mutex locked"));
441 KASSERT(!(cpipe->pipe_state & PIPE_DIRECTW),
442 (
"pipespace: resize of direct writes not allowed"));
444 cnt = cpipe->pipe_buffer.cnt;
448 size = round_page(size);
449 buffer = (caddr_t) vm_map_min(pipe_map);
451 error = vm_map_find(pipe_map, NULL, 0,
452 (vm_offset_t *) &buffer, size, 1,
453 VM_PROT_ALL, VM_PROT_ALL, 0);
454 if (error != KERN_SUCCESS) {
455 if ((cpipe->pipe_buffer.buffer == NULL) &&
456 (size > SMALL_PIPE_SIZE)) {
457 size = SMALL_PIPE_SIZE;
461 if (cpipe->pipe_buffer.buffer == NULL) {
464 printf(
"kern.ipc.maxpipekva exceeded; see tuning(7)\n");
473 if (cpipe->pipe_buffer.in <= cpipe->pipe_buffer.out) {
474 firstseg = cpipe->pipe_buffer.size - cpipe->pipe_buffer.out;
475 bcopy(&cpipe->pipe_buffer.buffer[cpipe->pipe_buffer.out],
477 if ((cnt - firstseg) > 0)
478 bcopy(cpipe->pipe_buffer.buffer, &buffer[firstseg],
479 cpipe->pipe_buffer.in);
481 bcopy(&cpipe->pipe_buffer.buffer[cpipe->pipe_buffer.out],
486 cpipe->pipe_buffer.buffer = buffer;
487 cpipe->pipe_buffer.size = size;
488 cpipe->pipe_buffer.in = cnt;
489 cpipe->pipe_buffer.out = 0;
490 cpipe->pipe_buffer.cnt = cnt;
504 KASSERT(cpipe->pipe_state & PIPE_LOCKFL,
505 (
"Unlocked pipe passed to pipespace"));
519 PIPE_LOCK_ASSERT(cpipe, MA_OWNED);
520 while (cpipe->pipe_state & PIPE_LOCKFL) {
521 cpipe->pipe_state |= PIPE_LWANT;
522 error = msleep(cpipe, PIPE_MTX(cpipe),
523 catch ? (PRIBIO | PCATCH) : PRIBIO,
528 cpipe->pipe_state |= PIPE_LOCKFL;
540 PIPE_LOCK_ASSERT(cpipe, MA_OWNED);
541 KASSERT(cpipe->pipe_state & PIPE_LOCKFL,
542 (
"Unlocked pipe passed to pipeunlock"));
543 cpipe->pipe_state &= ~PIPE_LOCKFL;
544 if (cpipe->pipe_state & PIPE_LWANT) {
545 cpipe->pipe_state &= ~PIPE_LWANT;
555 PIPE_LOCK_ASSERT(cpipe, MA_OWNED);
556 if (cpipe->pipe_state & PIPE_SEL) {
558 if (!SEL_WAITING(&cpipe->pipe_sel))
559 cpipe->pipe_state &= ~PIPE_SEL;
561 if ((cpipe->pipe_state & PIPE_ASYNC) && cpipe->pipe_sigio)
562 pgsigio(&cpipe->pipe_sigio, SIGIO, 0);
563 KNOTE_LOCKED(&cpipe->pipe_sel.si_note, 0);
595 struct ucred *active_cred;
599 struct pipe *rpipe = fp->f_data;
611 error = mac_pipe_check_read(active_cred, rpipe->pipe_pair);
616 if (!(rpipe->pipe_state & PIPE_DIRECTW) &&
617 (rpipe->pipe_buffer.size > SMALL_PIPE_SIZE) &&
618 (rpipe->pipe_buffer.cnt <= SMALL_PIPE_SIZE) &&
626 while (uio->uio_resid) {
630 if (rpipe->pipe_buffer.cnt > 0) {
631 size = rpipe->pipe_buffer.size - rpipe->pipe_buffer.out;
632 if (size > rpipe->pipe_buffer.cnt)
633 size = rpipe->pipe_buffer.cnt;
634 if (size > uio->uio_resid)
635 size = uio->uio_resid;
639 &rpipe->pipe_buffer.buffer[rpipe->pipe_buffer.out],
645 rpipe->pipe_buffer.out += size;
646 if (rpipe->pipe_buffer.out >= rpipe->pipe_buffer.size)
647 rpipe->pipe_buffer.out = 0;
649 rpipe->pipe_buffer.cnt -= size;
656 if (rpipe->pipe_buffer.cnt == 0) {
657 rpipe->pipe_buffer.in = 0;
658 rpipe->pipe_buffer.out = 0;
661 #ifndef PIPE_NODIRECT
665 }
else if ((size = rpipe->pipe_map.cnt) &&
666 (rpipe->pipe_state & PIPE_DIRECTW)) {
667 if (size > uio->uio_resid)
668 size = (u_int) uio->uio_resid;
671 error = uiomove_fromphys(rpipe->pipe_map.ms,
672 rpipe->pipe_map.pos, size, uio);
677 rpipe->pipe_map.pos += size;
678 rpipe->pipe_map.cnt -= size;
679 if (rpipe->pipe_map.cnt == 0) {
680 rpipe->pipe_state &= ~PIPE_DIRECTW;
689 if (rpipe->pipe_state & PIPE_EOF)
695 if (rpipe->pipe_state & PIPE_WANTW) {
696 rpipe->pipe_state &= ~PIPE_WANTW;
717 if (fp->f_flag & FNONBLOCK) {
720 rpipe->pipe_state |= PIPE_WANTR;
721 if ((error = msleep(rpipe, PIPE_MTX(rpipe),
744 if ((rpipe->pipe_busy == 0) && (rpipe->pipe_state & PIPE_WANT)) {
745 rpipe->pipe_state &= ~(PIPE_WANT|PIPE_WANTW);
751 if (rpipe->pipe_state & PIPE_WANTW) {
752 rpipe->pipe_state &= ~PIPE_WANTW;
757 if ((rpipe->pipe_buffer.size - rpipe->pipe_buffer.cnt) >= PIPE_BUF)
764 #ifndef PIPE_NODIRECT
777 PIPE_LOCK_ASSERT(wpipe, MA_NOTOWNED);
778 KASSERT(wpipe->pipe_state & PIPE_DIRECTW,
779 (
"Clone attempt on non-direct write pipe!"));
781 if (uio->uio_iov->iov_len > wpipe->pipe_buffer.size)
782 size = wpipe->pipe_buffer.size;
784 size = uio->uio_iov->iov_len;
786 if ((i = vm_fault_quick_hold_pages(&curproc->p_vmspace->vm_map,
787 (vm_offset_t)uio->uio_iov->iov_base, size, VM_PROT_READ,
788 wpipe->pipe_map.ms, PIPENPAGES)) < 0)
794 wpipe->pipe_map.npages = i;
795 wpipe->pipe_map.pos =
796 ((vm_offset_t) uio->uio_iov->iov_base) & PAGE_MASK;
797 wpipe->pipe_map.cnt = size;
803 uio->uio_iov->iov_len -= size;
804 uio->uio_iov->iov_base = (
char *)uio->uio_iov->iov_base + size;
805 if (uio->uio_iov->iov_len == 0)
807 uio->uio_resid -= size;
808 uio->uio_offset += size;
820 PIPE_LOCK_ASSERT(wpipe, MA_OWNED);
821 vm_page_unhold_pages(wpipe->pipe_map.ms, wpipe->pipe_map.npages);
822 wpipe->pipe_map.npages = 0;
839 PIPE_LOCK_ASSERT(wpipe, MA_OWNED);
840 size = wpipe->pipe_map.cnt;
841 pos = wpipe->pipe_map.pos;
843 wpipe->pipe_buffer.in = size;
844 wpipe->pipe_buffer.out = 0;
845 wpipe->pipe_buffer.cnt = size;
846 wpipe->pipe_state &= ~PIPE_DIRECTW;
849 iov.iov_base = wpipe->pipe_buffer.buffer;
854 uio.uio_resid = size;
855 uio.uio_segflg = UIO_SYSSPACE;
856 uio.uio_rw = UIO_READ;
857 uio.uio_td = curthread;
858 uiomove_fromphys(wpipe->pipe_map.ms, pos, size, &uio);
878 PIPE_LOCK_ASSERT(wpipe, MA_OWNED);
880 if (wpipe->pipe_state & PIPE_EOF)
886 while (wpipe->pipe_state & PIPE_DIRECTW) {
887 if (wpipe->pipe_state & PIPE_WANTR) {
888 wpipe->pipe_state &= ~PIPE_WANTR;
892 wpipe->pipe_state |= PIPE_WANTW;
894 error = msleep(wpipe, PIPE_MTX(wpipe),
895 PRIBIO | PCATCH,
"pipdww", 0);
901 wpipe->pipe_map.cnt = 0;
902 if (wpipe->pipe_buffer.cnt > 0) {
903 if (wpipe->pipe_state & PIPE_WANTR) {
904 wpipe->pipe_state &= ~PIPE_WANTR;
908 wpipe->pipe_state |= PIPE_WANTW;
910 error = msleep(wpipe, PIPE_MTX(wpipe),
911 PRIBIO | PCATCH,
"pipdwc", 0);
918 wpipe->pipe_state |= PIPE_DIRECTW;
924 wpipe->pipe_state &= ~PIPE_DIRECTW;
930 while (!error && (wpipe->pipe_state & PIPE_DIRECTW)) {
931 if (wpipe->pipe_state & PIPE_EOF) {
938 if (wpipe->pipe_state & PIPE_WANTR) {
939 wpipe->pipe_state &= ~PIPE_WANTR;
944 error = msleep(wpipe, PIPE_MTX(wpipe), PRIBIO | PCATCH,
949 if (wpipe->pipe_state & PIPE_EOF)
951 if (wpipe->pipe_state & PIPE_DIRECTW) {
973 struct ucred *active_cred;
980 struct pipe *wpipe, *rpipe;
983 wpipe = rpipe->pipe_peer;
994 if (wpipe->pipe_present != PIPE_ACTIVE ||
995 (wpipe->pipe_state & PIPE_EOF)) {
1001 error = mac_pipe_check_write(active_cred, wpipe->pipe_pair);
1011 desiredsize = max(SMALL_PIPE_SIZE, wpipe->pipe_buffer.size);
1012 while (desiredsize < wpipe->pipe_buffer.cnt + uio->uio_resid) {
1017 if (desiredsize == BIG_PIPE_SIZE)
1019 desiredsize = desiredsize * 2;
1024 (wpipe->pipe_buffer.size > SMALL_PIPE_SIZE) &&
1025 (wpipe->pipe_buffer.cnt <= SMALL_PIPE_SIZE) &&
1027 desiredsize = SMALL_PIPE_SIZE;
1030 if ((desiredsize != wpipe->pipe_buffer.size) &&
1031 ((wpipe->pipe_state & PIPE_DIRECTW) == 0)) {
1036 if (wpipe->pipe_buffer.size == 0) {
1050 orig_resid = uio->uio_resid;
1052 while (uio->uio_resid) {
1056 if (wpipe->pipe_state & PIPE_EOF) {
1061 #ifndef PIPE_NODIRECT
1071 if (uio->uio_segflg == UIO_USERSPACE &&
1072 uio->uio_iov->iov_len >= PIPE_MINDIRECT &&
1073 wpipe->pipe_buffer.size >= PIPE_MINDIRECT &&
1074 (fp->f_flag & FNONBLOCK) == 0) {
1090 if (wpipe->pipe_state & PIPE_DIRECTW) {
1091 if (wpipe->pipe_state & PIPE_WANTR) {
1092 wpipe->pipe_state &= ~PIPE_WANTR;
1096 wpipe->pipe_state |= PIPE_WANTW;
1098 error = msleep(wpipe, PIPE_MTX(rpipe), PRIBIO | PCATCH,
1106 space = wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt;
1109 if ((space < uio->uio_resid) && (orig_resid <= PIPE_BUF))
1120 if (space > uio->uio_resid)
1121 size = uio->uio_resid;
1131 segsize = wpipe->pipe_buffer.size -
1132 wpipe->pipe_buffer.in;
1139 error =
uiomove(&wpipe->pipe_buffer.buffer[wpipe->pipe_buffer.in],
1143 if (error == 0 && segsize < size) {
1144 KASSERT(wpipe->pipe_buffer.in + segsize ==
1145 wpipe->pipe_buffer.size,
1146 (
"Pipe buffer wraparound disappeared"));
1155 &wpipe->pipe_buffer.buffer[0],
1156 size - segsize, uio);
1160 wpipe->pipe_buffer.in += size;
1161 if (wpipe->pipe_buffer.in >=
1162 wpipe->pipe_buffer.size) {
1163 KASSERT(wpipe->pipe_buffer.in ==
1165 wpipe->pipe_buffer.size,
1166 (
"Expected wraparound bad"));
1167 wpipe->pipe_buffer.in = size - segsize;
1170 wpipe->pipe_buffer.cnt += size;
1171 KASSERT(wpipe->pipe_buffer.cnt <=
1172 wpipe->pipe_buffer.size,
1173 (
"Pipe buffer overflow"));
1182 if (wpipe->pipe_state & PIPE_WANTR) {
1183 wpipe->pipe_state &= ~PIPE_WANTR;
1190 if (fp->f_flag & FNONBLOCK) {
1202 wpipe->pipe_state |= PIPE_WANTW;
1204 error = msleep(wpipe, PIPE_MTX(rpipe),
1205 PRIBIO | PCATCH,
"pipewr", 0);
1214 if ((wpipe->pipe_busy == 0) && (wpipe->pipe_state & PIPE_WANT)) {
1215 wpipe->pipe_state &= ~(PIPE_WANT | PIPE_WANTR);
1217 }
else if (wpipe->pipe_buffer.cnt > 0) {
1222 if (wpipe->pipe_state & PIPE_WANTR) {
1223 wpipe->pipe_state &= ~PIPE_WANTR;
1231 if ((wpipe->pipe_buffer.cnt == 0) &&
1232 (uio->uio_resid == 0) &&
1244 if (wpipe->pipe_buffer.cnt)
1257 struct ucred *active_cred;
1272 struct ucred *active_cred;
1275 struct pipe *mpipe = fp->f_data;
1281 error = mac_pipe_check_ioctl(active_cred, mpipe->pipe_pair, cmd, data);
1296 mpipe->pipe_state |= PIPE_ASYNC;
1298 mpipe->pipe_state &= ~PIPE_ASYNC;
1303 if (mpipe->pipe_state & PIPE_DIRECTW)
1304 *(
int *)data = mpipe->pipe_map.cnt;
1306 *(
int *)data = mpipe->pipe_buffer.cnt;
1311 error =
fsetown(*(
int *)data, &mpipe->pipe_sigio);
1315 *(
int *)data =
fgetown(&mpipe->pipe_sigio);
1321 error =
fsetown(-(*(
int *)data), &mpipe->pipe_sigio);
1326 *(
int *)data = -
fgetown(&mpipe->pipe_sigio);
1342 struct ucred *active_cred;
1345 struct pipe *rpipe = fp->f_data;
1352 wpipe = rpipe->pipe_peer;
1355 error = mac_pipe_check_poll(active_cred, rpipe->pipe_pair);
1359 if (events & (POLLIN | POLLRDNORM))
1360 if ((rpipe->pipe_state & PIPE_DIRECTW) ||
1361 (rpipe->pipe_buffer.cnt > 0))
1362 revents |= events & (POLLIN | POLLRDNORM);
1364 if (events & (POLLOUT | POLLWRNORM))
1365 if (wpipe->pipe_present != PIPE_ACTIVE ||
1366 (wpipe->pipe_state & PIPE_EOF) ||
1367 (((wpipe->pipe_state & PIPE_DIRECTW) == 0) &&
1368 ((wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) >= PIPE_BUF ||
1369 wpipe->pipe_buffer.size == 0)))
1370 revents |= events & (POLLOUT | POLLWRNORM);
1372 if ((events & POLLINIGNEOF) == 0) {
1373 if (rpipe->pipe_state & PIPE_EOF) {
1374 revents |= (events & (POLLIN | POLLRDNORM));
1375 if (wpipe->pipe_present != PIPE_ACTIVE ||
1376 (wpipe->pipe_state & PIPE_EOF))
1382 if (events & (POLLIN | POLLRDNORM)) {
1384 if (SEL_WAITING(&rpipe->pipe_sel))
1385 rpipe->pipe_state |= PIPE_SEL;
1388 if (events & (POLLOUT | POLLWRNORM)) {
1390 if (SEL_WAITING(&wpipe->pipe_sel))
1391 wpipe->pipe_state |= PIPE_SEL;
1410 struct ucred *active_cred;
1422 error = mac_pipe_check_stat(active_cred, pipe->pipe_pair);
1438 if (pipe->pipe_ino == (ino_t)-1) {
1447 bzero(ub,
sizeof(*ub));
1448 ub->st_mode = S_IFIFO;
1449 ub->st_blksize = PAGE_SIZE;
1450 if (pipe->pipe_state & PIPE_DIRECTW)
1451 ub->st_size = pipe->pipe_map.cnt;
1453 ub->st_size = pipe->pipe_buffer.cnt;
1454 ub->st_blocks = (ub->st_size + ub->st_blksize - 1) / ub->st_blksize;
1455 ub->st_atim = pipe->pipe_atime;
1456 ub->st_mtim = pipe->pipe_mtime;
1457 ub->st_ctim = pipe->pipe_ctime;
1458 ub->st_uid = fp->f_cred->cr_uid;
1459 ub->st_gid = fp->f_cred->cr_gid;
1461 ub->st_ino = pipe->pipe_ino;
1474 struct pipe *cpipe = fp->f_data;
1488 KASSERT(!mtx_owned(PIPE_MTX(cpipe)),
1489 (
"pipe_free_kmem: pipe mutex locked"));
1491 if (cpipe->pipe_buffer.buffer != NULL) {
1492 atomic_subtract_long(&
amountpipekva, cpipe->pipe_buffer.size);
1493 vm_map_remove(pipe_map,
1494 (vm_offset_t)cpipe->pipe_buffer.buffer,
1495 (vm_offset_t)cpipe->pipe_buffer.buffer + cpipe->pipe_buffer.size);
1496 cpipe->pipe_buffer.buffer = NULL;
1498 #ifndef PIPE_NODIRECT
1500 cpipe->pipe_map.cnt = 0;
1501 cpipe->pipe_map.pos = 0;
1502 cpipe->pipe_map.npages = 0;
1514 struct pipepair *pp;
1518 KASSERT(cpipe != NULL, (
"pipeclose: cpipe == NULL"));
1522 pp = cpipe->pipe_pair;
1530 cpipe->pipe_state |= PIPE_EOF;
1531 while (cpipe->pipe_busy) {
1533 cpipe->pipe_state |= PIPE_WANT;
1535 msleep(cpipe, PIPE_MTX(cpipe), PRIBIO,
"pipecl", 0);
1543 ppipe = cpipe->pipe_peer;
1544 if (ppipe->pipe_present == PIPE_ACTIVE) {
1547 ppipe->pipe_state |= PIPE_EOF;
1549 KNOTE_LOCKED(&ppipe->pipe_sel.si_note, 0);
1561 cpipe->pipe_present = PIPE_CLOSING;
1569 knlist_clear(&cpipe->pipe_sel.si_note, 1);
1570 cpipe->pipe_present = PIPE_FINALIZED;
1578 ino = cpipe->pipe_ino;
1584 if (ppipe->pipe_present == PIPE_FINALIZED) {
1587 mac_pipe_destroy(pp);
1593 if (ino != 0 && ino != (ino_t)-1)
1603 cpipe = kn->kn_fp->f_data;
1605 switch (kn->kn_filter) {
1611 if (cpipe->pipe_peer->pipe_present != PIPE_ACTIVE) {
1616 cpipe = cpipe->pipe_peer;
1631 struct pipe *cpipe = (
struct pipe *)kn->kn_fp->f_data;
1634 if (kn->kn_filter == EVFILT_WRITE)
1635 cpipe = cpipe->pipe_peer;
1644 struct pipe *rpipe = kn->kn_fp->f_data;
1645 struct pipe *wpipe = rpipe->pipe_peer;
1649 kn->kn_data = rpipe->pipe_buffer.cnt;
1650 if ((kn->kn_data == 0) && (rpipe->pipe_state & PIPE_DIRECTW))
1651 kn->kn_data = rpipe->pipe_map.cnt;
1653 if ((rpipe->pipe_state & PIPE_EOF) ||
1654 wpipe->pipe_present != PIPE_ACTIVE ||
1655 (wpipe->pipe_state & PIPE_EOF)) {
1656 kn->kn_flags |= EV_EOF;
1660 ret = kn->kn_data > 0;
1669 struct pipe *rpipe = kn->kn_fp->f_data;
1670 struct pipe *wpipe = rpipe->pipe_peer;
1673 if (wpipe->pipe_present != PIPE_ACTIVE ||
1674 (wpipe->pipe_state & PIPE_EOF)) {
1676 kn->kn_flags |= EV_EOF;
1680 kn->kn_data = (wpipe->pipe_buffer.size > 0) ?
1681 (wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) : PIPE_BUF;
1682 if (wpipe->pipe_state & PIPE_DIRECTW)
1686 return (kn->kn_data >= PIPE_BUF);
static struct unrhdr * pipeino_unr
pid_t fgetown(struct sigio **sigiop)
int fsetown(pid_t pgid, struct sigio **sigiop)
static struct fileops pipeops
static fo_kqfilter_t pipe_kqfilter
static __inline void * new_unr(struct unrhdr *uh, void **p1, void **p2)
int invfo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred, struct thread *td)
int ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps)
static void pipe_free_kmem(struct pipe *cpipe)
static int pipe_zone_ctor(void *mem, int size, void *arg, int flags)
static uma_zone_t pipe_zone
void selrecord(struct thread *selector, struct selinfo *sip)
static fo_rdwr_t pipe_read
SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_ANY, pipeinit, NULL)
int do_pipe(struct thread *td, int fildes[2], int flags)
static int pipe_create(struct pipe *pipe, int backing)
void knote(struct knlist *list, long hint, int lockflags)
void selwakeuppri(struct selinfo *sip, int pri)
int alloc_unr(struct unrhdr *uh)
int falloc(struct thread *td, struct file **resultfp, int *resultfd, int flags)
static void filt_pipedetach(struct knote *kn)
void knlist_destroy(struct knlist *knl)
static fo_poll_t pipe_poll
int kern_pipe(struct thread *td, int fildes[2])
int invfo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred, struct thread *td)
void funsetown(struct sigio **sigiop)
static __inline void pipeselwakeup(struct pipe *cpipe)
void vfs_timestamp(struct timespec *tsp)
static int pipe_zone_init(void *mem, int size, int flags)
static __inline int pipelock(struct pipe *cpipe, int catch)
static int pipespace(struct pipe *cpipe, int size)
static void pipe_clone_write_buffer(struct pipe *wpipe)
static void pipe_destroy_write_buffer(struct pipe *wpipe)
int sys_pipe(struct thread *td, struct pipe_args *uap)
void knlist_remove(struct knlist *knl, struct knote *kn, int islocked)
static int piperesizefail
static struct filterops pipe_rfiltops
static int filt_pipewrite(struct knote *kn, long hint)
static int pipe_build_write_buffer(struct pipe *wpipe, struct uio *uio)
void seldrain(struct selinfo *sip)
static fo_ioctl_t pipe_ioctl
static void pipe_zone_fini(void *mem, int size)
SYSCTL_LONG(_kern_ipc, OID_AUTO, maxpipekva, CTLFLAG_RDTUN,&maxpipekva, 0,"Pipe KVA limit")
void knlist_add(struct knlist *knl, struct knote *kn, int islocked)
struct unrhdr * new_unrhdr(int low, int high, struct mtx *mutex)
void fdclose(struct filedesc *fdp, struct file *fp, int idx, struct thread *td)
static void pipeclose(struct pipe *cpipe)
int uiomove(void *cp, int n, struct uio *uio)
static int pipespace_new(struct pipe *cpipe, int size)
int printf(const char *fmt,...)
static long amountpipekva
static int pipe_direct_write(struct pipe *wpipe, struct uio *uio)
static fo_stat_t pipe_stat
SYSCTL_INT(_kern_ipc, OID_AUTO, pipefragretry, CTLFLAG_RD,&pipefragretry, 0,"Pipe allocation retries due to fragmentation")
void finit(struct file *fp, u_int flag, short type, void *data, struct fileops *ops)
void mtx_init(struct mtx *m, const char *name, const char *type, int opts)
static int piperesizeallowed
static struct filterops pipe_wfiltops
void mtx_destroy(struct mtx *m)
static fo_rdwr_t pipe_write
static void pipeinit(void *dummy __unused)
void free_unr(struct unrhdr *uh, u_int item)
static __inline void pipeunlock(struct pipe *cpipe)
void knlist_init_mtx(struct knlist *knl, struct mtx *lock)
void pgsigio(struct sigio **sigiop, int sig, int checkctty)
static int filt_piperead(struct knote *kn, long hint)
static fo_truncate_t pipe_truncate
struct fileops badfileops
static fo_close_t pipe_close