diff options
author | iedowse <iedowse@FreeBSD.org> | 2002-09-02 22:46:05 +0000 |
---|---|---|
committer | iedowse <iedowse@FreeBSD.org> | 2002-09-02 22:46:05 +0000 |
commit | 2271d6f41de319213a0112b7b564b815dbb9fdf5 (patch) | |
tree | 82aca958ad2fdf3a9eee6f726702a835dea3fc19 /sys/compat | |
parent | 2fe13c1c207b2f1063622b4a976dcc3d362fb414 (diff) | |
download | FreeBSD-src-2271d6f41de319213a0112b7b564b815dbb9fdf5.zip FreeBSD-src-2271d6f41de319213a0112b7b564b815dbb9fdf5.tar.gz |
Use the new kern_*() functions to avoid using the stack gap in
linux_fcntl*() and linux_getcwd().
Diffstat (limited to 'sys/compat')
-rw-r--r-- | sys/compat/linux/linux_file.c | 102 | ||||
-rw-r--r-- | sys/compat/linux/linux_getcwd.c | 37 |
2 files changed, 49 insertions, 90 deletions
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index cf57d62..76dba79 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -931,30 +931,22 @@ bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock) static int fcntl_common(struct thread *td, struct linux_fcntl64_args *args) { - struct fcntl_args fcntl_args; struct file *fp; + long arg; int error, result; - fcntl_args.fd = args->fd; - switch (args->cmd) { case LINUX_F_DUPFD: - fcntl_args.cmd = F_DUPFD; - fcntl_args.arg = args->arg; - return (fcntl(td, &fcntl_args)); + return (kern_fcntl(td, args->fd, F_DUPFD, args->arg)); case LINUX_F_GETFD: - fcntl_args.cmd = F_GETFD; - return (fcntl(td, &fcntl_args)); + return (kern_fcntl(td, args->fd, F_GETFD, 0)); case LINUX_F_SETFD: - fcntl_args.cmd = F_SETFD; - fcntl_args.arg = args->arg; - return (fcntl(td, &fcntl_args)); + return (kern_fcntl(td, args->fd, F_SETFD, args->arg)); case LINUX_F_GETFL: - fcntl_args.cmd = F_GETFL; - error = fcntl(td, &fcntl_args); + error = kern_fcntl(td, args->fd, F_GETFL, 0); result = td->td_retval[0]; td->td_retval[0] = 0; if (result & O_RDONLY) @@ -974,21 +966,19 @@ fcntl_common(struct thread *td, struct linux_fcntl64_args *args) return (error); case LINUX_F_SETFL: - fcntl_args.arg = 0; + arg = 0; if (args->arg & LINUX_O_NDELAY) - fcntl_args.arg |= O_NONBLOCK; + arg |= O_NONBLOCK; if (args->arg & LINUX_O_APPEND) - fcntl_args.arg |= O_APPEND; + arg |= O_APPEND; if (args->arg & LINUX_O_SYNC) - fcntl_args.arg |= O_FSYNC; + arg |= O_FSYNC; if (args->arg & LINUX_FASYNC) - fcntl_args.arg |= O_ASYNC; - fcntl_args.cmd = F_SETFL; - return (fcntl(td, &fcntl_args)); + arg |= O_ASYNC; + return (kern_fcntl(td, args->fd, F_SETFL, arg)); case LINUX_F_GETOWN: - fcntl_args.cmd = F_GETOWN; - return (fcntl(td, &fcntl_args)); + return (kern_fcntl(td, args->fd, F_GETOWN, 0)); case LINUX_F_SETOWN: /* @@ -1005,9 +995,7 @@ fcntl_common(struct thread *td, struct linux_fcntl64_args *args) } fdrop(fp, td); - fcntl_args.cmd = F_SETOWN; - fcntl_args.arg = args->arg; - return (fcntl(td, &fcntl_args)); + return (kern_fcntl(td, args->fd, F_SETOWN, args->arg)); } return (EINVAL); @@ -1017,14 +1005,9 @@ int linux_fcntl(struct thread *td, struct linux_fcntl_args *args) { struct linux_fcntl64_args args64; - struct fcntl_args fcntl_args; struct l_flock linux_flock; - struct flock *bsd_flock; + struct flock bsd_flock; int error; - caddr_t sg; - - sg = stackgap_init(); - bsd_flock = (struct flock *)stackgap_alloc(&sg, sizeof(bsd_flock)); #ifdef DEBUG if (ldebug(fcntl)) @@ -1037,14 +1020,11 @@ linux_fcntl(struct thread *td, struct linux_fcntl_args *args) sizeof(linux_flock)); if (error) return (error); - linux_to_bsd_flock(&linux_flock, bsd_flock); - fcntl_args.fd = args->fd; - fcntl_args.cmd = F_GETLK; - fcntl_args.arg = (long)bsd_flock; - error = fcntl(td, &fcntl_args); + linux_to_bsd_flock(&linux_flock, &bsd_flock); + error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock); if (error) return (error); - bsd_to_linux_flock(bsd_flock, &linux_flock); + bsd_to_linux_flock(&bsd_flock, &linux_flock); return (copyout(&linux_flock, (caddr_t)args->arg, sizeof(linux_flock))); @@ -1053,22 +1033,18 @@ linux_fcntl(struct thread *td, struct linux_fcntl_args *args) sizeof(linux_flock)); if (error) return (error); - linux_to_bsd_flock(&linux_flock, bsd_flock); - fcntl_args.fd = args->fd; - fcntl_args.cmd = F_SETLK; - fcntl_args.arg = (long)bsd_flock; - return (fcntl(td, &fcntl_args)); + linux_to_bsd_flock(&linux_flock, &bsd_flock); + return (kern_fcntl(td, args->fd, F_SETLK, + (intptr_t)&bsd_flock)); case LINUX_F_SETLKW: error = copyin((caddr_t)args->arg, &linux_flock, sizeof(linux_flock)); if (error) return (error); - linux_to_bsd_flock(&linux_flock, bsd_flock); - fcntl_args.fd = args->fd; - fcntl_args.cmd = F_SETLKW; - fcntl_args.arg = (long)bsd_flock; - return (fcntl(td, &fcntl_args)); + linux_to_bsd_flock(&linux_flock, &bsd_flock); + return (kern_fcntl(td, args->fd, F_SETLKW, + (intptr_t)&bsd_flock)); } args64.fd = args->fd; @@ -1081,14 +1057,9 @@ linux_fcntl(struct thread *td, struct linux_fcntl_args *args) int linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args) { - struct fcntl_args fcntl_args; struct l_flock64 linux_flock; - struct flock *bsd_flock; + struct flock bsd_flock; int error; - caddr_t sg; - - sg = stackgap_init(); - bsd_flock = (struct flock *)stackgap_alloc(&sg, sizeof(bsd_flock)); #ifdef DEBUG if (ldebug(fcntl64)) @@ -1102,14 +1073,11 @@ linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args) sizeof(linux_flock)); if (error) return (error); - linux_to_bsd_flock64(&linux_flock, bsd_flock); - fcntl_args.fd = args->fd; - fcntl_args.cmd = F_GETLK; - fcntl_args.arg = (long)bsd_flock; - error = fcntl(td, &fcntl_args); + linux_to_bsd_flock64(&linux_flock, &bsd_flock); + error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock); if (error) return (error); - bsd_to_linux_flock64(bsd_flock, &linux_flock); + bsd_to_linux_flock64(&bsd_flock, &linux_flock); return (copyout(&linux_flock, (caddr_t)args->arg, sizeof(linux_flock))); @@ -1119,11 +1087,9 @@ linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args) sizeof(linux_flock)); if (error) return (error); - linux_to_bsd_flock64(&linux_flock, bsd_flock); - fcntl_args.fd = args->fd; - fcntl_args.cmd = F_SETLK; - fcntl_args.arg = (long)bsd_flock; - return (fcntl(td, &fcntl_args)); + linux_to_bsd_flock64(&linux_flock, &bsd_flock); + return (kern_fcntl(td, args->fd, F_SETLK, + (intptr_t)&bsd_flock)); case LINUX_F_SETLKW: case LINUX_F_SETLKW64: @@ -1131,11 +1097,9 @@ linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args) sizeof(linux_flock)); if (error) return (error); - linux_to_bsd_flock64(&linux_flock, bsd_flock); - fcntl_args.fd = args->fd; - fcntl_args.cmd = F_SETLKW; - fcntl_args.arg = (long)bsd_flock; - return (fcntl(td, &fcntl_args)); + linux_to_bsd_flock64(&linux_flock, &bsd_flock); + return (kern_fcntl(td, args->fd, F_SETLKW, + (intptr_t)&bsd_flock)); } return (fcntl_common(td, args)); diff --git a/sys/compat/linux/linux_getcwd.c b/sys/compat/linux/linux_getcwd.c index 2773562..bb1c28f 100644 --- a/sys/compat/linux/linux_getcwd.c +++ b/sys/compat/linux/linux_getcwd.c @@ -42,12 +42,12 @@ #include <sys/param.h> #include <sys/systm.h> -#include <sys/sysproto.h> #include <sys/namei.h> #include <sys/filedesc.h> #include <sys/kernel.h> #include <sys/file.h> #include <sys/stat.h> +#include <sys/syscallsubr.h> #include <sys/vnode.h> #include <sys/mount.h> #include <sys/proc.h> @@ -414,8 +414,7 @@ out: int linux_getcwd(struct thread *td, struct linux_getcwd_args *args) { - struct __getcwd_args bsd; - caddr_t sg, bp, bend, path; + caddr_t bp, bend, path; int error, len, lenused; #ifdef DEBUG @@ -423,28 +422,25 @@ linux_getcwd(struct thread *td, struct linux_getcwd_args *args) args->buf, (long)args->bufsize); #endif - sg = stackgap_init(); - bsd.buf = stackgap_alloc(&sg, SPARE_USRSPACE); - bsd.buflen = SPARE_USRSPACE; - error = __getcwd(td, &bsd); + len = args->bufsize; + + if (len > MAXPATHLEN*4) + len = MAXPATHLEN*4; + else if (len < 2) + return ERANGE; + + path = (char *)malloc(len, M_TEMP, M_WAITOK); + + error = kern___getcwd(td, path, UIO_SYSSPACE, len); if (!error) { - lenused = strlen(bsd.buf) + 1; + lenused = strlen(path) + 1; if (lenused <= args->bufsize) { td->td_retval[0] = lenused; - error = copyout(bsd.buf, args->buf, lenused); + error = copyout(path, args->buf, lenused); } else error = ERANGE; } else { - len = args->bufsize; - - if (len > MAXPATHLEN*4) - len = MAXPATHLEN*4; - else if (len < 2) - return ERANGE; - - path = (char *)malloc(len, M_TEMP, M_WAITOK); - bp = &path[len]; bend = bp; *(--bp) = '\0'; @@ -464,10 +460,9 @@ linux_getcwd(struct thread *td, struct linux_getcwd_args *args) td->td_retval[0] = lenused; /* put the result into user buffer */ error = copyout(bp, args->buf, lenused); - -out: - free(path, M_TEMP); } +out: + free(path, M_TEMP); return (error); } |