diff options
author | jhb <jhb@FreeBSD.org> | 2004-08-24 20:21:21 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2004-08-24 20:21:21 +0000 |
commit | cc23ea84d0ad17e7d69a1539947fdc50a38c6af0 (patch) | |
tree | 2adb2b3e0072e186b55581dbf999abee2995639a /sys/compat | |
parent | 1ec5d22c32622b609088a0218cc5e25ef0352c34 (diff) | |
download | FreeBSD-src-cc23ea84d0ad17e7d69a1539947fdc50a38c6af0.zip FreeBSD-src-cc23ea84d0ad17e7d69a1539947fdc50a38c6af0.tar.gz |
Fix the ABI wrappers to use kern_fcntl() rather than calling fcntl()
directly. This removes a few more users of the stackgap and also marks
the syscalls using these wrappers MP safe where appropriate.
Tested on: i386 with linux acroread5
Compiled on: i386, alpha LINT
Diffstat (limited to 'sys/compat')
-rw-r--r-- | sys/compat/linux/linux_socket.c | 15 | ||||
-rw-r--r-- | sys/compat/svr4/svr4_fcntl.c | 104 | ||||
-rw-r--r-- | sys/compat/svr4/svr4_stream.c | 23 | ||||
-rw-r--r-- | sys/compat/svr4/syscalls.master | 2 |
4 files changed, 56 insertions, 88 deletions
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 47cf5d6..8233db1 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -674,12 +674,7 @@ linux_accept(struct thread *td, struct linux_accept_args *args) struct close_args /* { int fd; } */ c_args; - struct fcntl_args /* { - int fd; - int cmd; - long arg; - } */ f_args; - int error; + int error, fd; if ((error = copyin(args, &linux_args, sizeof(linux_args)))) return (error); @@ -705,11 +700,9 @@ linux_accept(struct thread *td, struct linux_accept_args *args) * accepted one, so we must clear the flags in the new descriptor. * Ignore any errors, because we already have an open fd. */ - f_args.fd = td->td_retval[0]; - f_args.cmd = F_SETFL; - f_args.arg = 0; - (void)fcntl(td, &f_args); - td->td_retval[0] = f_args.fd; + fd = td->td_retval[0]; + (void)kern_fcntl(td, fd, F_SETFL, 0); + td->td_retval[0] = fd; return (0); } diff --git a/sys/compat/svr4/svr4_fcntl.c b/sys/compat/svr4/svr4_fcntl.c index 7a01b15..0c592c3 100644 --- a/sys/compat/svr4/svr4_fcntl.c +++ b/sys/compat/svr4/svr4_fcntl.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include <sys/namei.h> #include <sys/proc.h> #include <sys/stat.h> +#include <sys/syscallsubr.h> #include <sys/unistd.h> #include <sys/vnode.h> @@ -580,29 +581,24 @@ svr4_sys_fcntl(td, uap) register struct thread *td; struct svr4_sys_fcntl_args *uap; { - int error; - struct fcntl_args fa; - int *retval; + int cmd, error, *retval; retval = td->td_retval; - fa.fd = uap->fd; - fa.cmd = svr4_to_bsd_cmd(uap->cmd); + cmd = svr4_to_bsd_cmd(uap->cmd); - switch (fa.cmd) { + switch (cmd) { case F_DUPFD: case F_GETFD: case F_SETFD: - fa.arg = (long) uap->arg; - return fcntl(td, &fa); + return (kern_fcntl(td, uap->fd, cmd, (intptr_t)uap->arg)); case F_GETFL: - fa.arg = (long) uap->arg; - error = fcntl(td, &fa); + error = kern_fcntl(td, uap->fd, cmd, (intptr_t)uap->arg); if (error) - return error; + return (error); *retval = bsd_to_svr4_flags(*retval); - return error; + return (error); case F_SETFL: { @@ -610,55 +606,39 @@ svr4_sys_fcntl(td, uap) * we must save the O_ASYNC flag, as that is * handled by ioctl(_, I_SETSIG, _) emulation. */ - long cmd; int flags; DPRINTF(("Setting flags %p\n", uap->arg)); - cmd = fa.cmd; /* save it for a while */ - fa.cmd = F_GETFL; - if ((error = fcntl(td, &fa)) != 0) - return error; + error = kern_fcntl(td, uap->fd, F_GETFL, 0); + if (error) + return (error); flags = *retval; flags &= O_ASYNC; flags |= svr4_to_bsd_flags((u_long) uap->arg); - fa.cmd = cmd; - fa.arg = (long) flags; - return fcntl(td, &fa); + return (kern_fcntl(td, uap->fd, F_SETFL, flags)); } case F_GETLK: case F_SETLK: case F_SETLKW: { - struct svr4_flock ifl; - struct flock *flp, fl; - caddr_t sg = stackgap_init(); - - flp = stackgap_alloc(&sg, sizeof(struct flock)); - fa.arg = (long) flp; + struct svr4_flock ifl; + struct flock fl; - error = copyin(uap->arg, &ifl, sizeof ifl); + error = copyin(uap->arg, &ifl, sizeof (ifl)); if (error) - return error; + return (error); svr4_to_bsd_flock(&ifl, &fl); - error = copyout(&fl, flp, sizeof fl); - if (error) - return error; - - error = fcntl(td, &fa); - if (error || fa.cmd != F_GETLK) - return error; - - error = copyin(flp, &fl, sizeof fl); - if (error) - return error; + error = kern_fcntl(td, uap->fd, cmd, (intptr_t)&fl); + if (error || cmd != F_GETLK) + return (error); bsd_to_svr4_flock(&fl, &ifl); - return copyout(&ifl, uap->arg, sizeof ifl); + return (copyout(&ifl, uap->arg, sizeof (ifl))); } case -1: switch (uap->cmd) { @@ -692,36 +672,36 @@ svr4_sys_fcntl(td, uap) case SVR4_F_SETLK64: case SVR4_F_SETLKW64: { - struct svr4_flock64 ifl; - struct flock *flp, fl; - caddr_t sg = stackgap_init(); - - flp = stackgap_alloc(&sg, sizeof(struct flock)); - fa.arg = (long) flp; - + struct svr4_flock64 ifl; + struct flock fl; + + switch (uap->cmd) { + case SVR4_F_GETLK64: + cmd = F_GETLK; + break; + case SVR4_F_SETLK64: + cmd = F_SETLK; + break; + case SVR4_F_SETLKW64: + cmd = F_SETLKW; + break; + } error = copyin(uap->arg, &ifl, - sizeof ifl); + sizeof (ifl)); if (error) - return error; + return (error); svr4_to_bsd_flock64(&ifl, &fl); - error = copyout(&fl, flp, sizeof fl); - if (error) - return error; - - error = fcntl(td, &fa); - if (error || fa.cmd != F_GETLK) - return error; - - error = copyin(flp, &fl, sizeof fl); - if (error) - return error; + error = kern_fcntl(td, uap->fd, cmd, + (intptr_t)&fl); + if (error || cmd != F_GETLK) + return (error); bsd_to_svr4_flock64(&fl, &ifl); - return copyout(&ifl, uap->arg, - sizeof ifl); + return (copyout(&ifl, uap->arg, + sizeof (ifl))); } case SVR4_F_FREESP64: diff --git a/sys/compat/svr4/svr4_stream.c b/sys/compat/svr4/svr4_stream.c index d91c185..0e708f6 100644 --- a/sys/compat/svr4/svr4_stream.c +++ b/sys/compat/svr4/svr4_stream.c @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/stat.h> +#include <sys/syscallsubr.h> #include <sys/sysproto.h> #include <sys/uio.h> #include <sys/ktrace.h> /* Must come after sys/uio.h */ @@ -1473,7 +1474,6 @@ i_setsig(fp, td, retval, fd, cmd, dat) * We alse have to fix the O_ASYNC fcntl bit, so the * process will get SIGPOLLs. */ - struct fcntl_args fa; int error; register_t oflags, flags; struct svr4_strm *st = svr4_stream_get(fp); @@ -1483,10 +1483,9 @@ i_setsig(fp, td, retval, fd, cmd, dat) return EINVAL; } /* get old status flags */ - fa.fd = fd; - fa.cmd = F_GETFL; - if ((error = fcntl(td, &fa)) != 0) - return error; + error = kern_fcntl(td, fd, F_GETFL, 0); + if (error) + return (error); oflags = td->td_retval[0]; @@ -1512,19 +1511,15 @@ i_setsig(fp, td, retval, fd, cmd, dat) /* set the new flags, if changed */ if (flags != oflags) { - fa.cmd = F_SETFL; - fa.arg = (long) flags; - if ((error = fcntl(td, &fa)) != 0) - return error; + error = kern_fcntl(td, fd, F_SETFL, flags); + if (error) + return (error); flags = td->td_retval[0]; } /* set up SIGIO receiver if needed */ - if (dat != NULL) { - fa.cmd = F_SETOWN; - fa.arg = (long) td->td_proc->p_pid; - return fcntl(td, &fa); - } + if (dat != NULL) + return (kern_fcntl(td, fd, F_SETOWN, td->td_proc->p_pid)); return 0; } diff --git a/sys/compat/svr4/syscalls.master b/sys/compat/svr4/syscalls.master index 277fbdc..6343597 100644 --- a/sys/compat/svr4/syscalls.master +++ b/sys/compat/svr4/syscalls.master @@ -100,7 +100,7 @@ 59 STD { int svr4_sys_execve(char *path, char **argp, char **envp); } 60 MNOPROTO { int umask(int newmask); } 61 NOPROTO { int chroot(char *path); } -62 STD { int svr4_sys_fcntl(int fd, int cmd, char *arg); } +62 MSTD { int svr4_sys_fcntl(int fd, int cmd, char *arg); } 63 MSTD { int svr4_sys_ulimit(int cmd, long newlimit); } 64 UNIMPL reserved 65 UNIMPL reserved |