diff options
author | ed <ed@FreeBSD.org> | 2008-11-11 14:55:59 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2008-11-11 14:55:59 +0000 |
commit | 8d12469978678c211dcedcae430fb7091bd504b6 (patch) | |
tree | ecda9024889970adebb651c82cfc5ec015d4a7e5 /sys/kern/sys_pipe.c | |
parent | 5b802b524bc0cd8e922224203f9cbeb05b7e8308 (diff) | |
download | FreeBSD-src-8d12469978678c211dcedcae430fb7091bd504b6.zip FreeBSD-src-8d12469978678c211dcedcae430fb7091bd504b6.tar.gz |
Several cleanups related to pipe(2).
- Use `fildes[2]' instead of `*fildes' to make more clear that pipe(2)
fills an array with two descriptors.
- Remove EFAULT from the manual page. Because of the current calling
convention, pipe(2) raises a segmentation fault when an invalid
address is passed.
- Introduce kern_pipe() to make it easier for binary emulations to
implement pipe(2).
- Make Linux binary emulation use kern_pipe(), which means we don't have
to recover td_retval after calling the FreeBSD system call.
Approved by: rdivacky
Discussed on: arch
Diffstat (limited to 'sys/kern/sys_pipe.c')
-rw-r--r-- | sys/kern/sys_pipe.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index b8c1dfe..9b343fe 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -108,6 +108,7 @@ __FBSDID("$FreeBSD$"); #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> @@ -307,13 +308,8 @@ pipe_zone_fini(void *mem, int size) * The pipe system call for the DTYPE_PIPE type of pipes. If we fail, let * the zone pick up the pieces via pipeclose(). */ -/* ARGSUSED */ int -pipe(td, uap) - struct thread *td; - struct pipe_args /* { - int dummy; - } */ *uap; +kern_pipe(struct thread *td, int fildes[2]) { struct filedesc *fdp = td->td_proc->p_fd; struct file *rf, *wf; @@ -357,7 +353,7 @@ pipe(td, uap) return (error); } /* An extra reference on `rf' has been held for us by falloc(). */ - td->td_retval[0] = fd; + fildes[0] = fd; /* * Warning: once we've gotten past allocation of the fd for the @@ -368,7 +364,7 @@ pipe(td, uap) finit(rf, FREAD | FWRITE, DTYPE_PIPE, rpipe, &pipeops); error = falloc(td, &wf, &fd); if (error) { - fdclose(fdp, rf, td->td_retval[0], td); + fdclose(fdp, rf, fildes[0], td); fdrop(rf, td); /* rpipe has been closed by fdrop(). */ pipeclose(wpipe); @@ -377,12 +373,29 @@ pipe(td, uap) /* An extra reference on `wf' has been held for us by falloc(). */ finit(wf, FREAD | FWRITE, DTYPE_PIPE, wpipe, &pipeops); fdrop(wf, td); - td->td_retval[1] = fd; + fildes[1] = fd; fdrop(rf, td); return (0); } +/* ARGSUSED */ +int +pipe(struct thread *td, struct pipe_args *uap) +{ + int error; + int fildes[2]; + + error = kern_pipe(td, fildes); + if (error) + return (error); + + td->td_retval[0] = fildes[0]; + td->td_retval[1] = fildes[1]; + + return (0); +} + /* * Allocate kva for pipe circular buffer, the space is pageable * This routine will 'realloc' the size of a pipe safely, if it fails |