aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linux
diff options
context:
space:
mode:
authorIan Dowse <iedowse@FreeBSD.org>2002-09-01 22:30:27 +0000
committerIan Dowse <iedowse@FreeBSD.org>2002-09-01 22:30:27 +0000
commit206a5d3a0ce66d27e8f2f378ea0f1db89c324950 (patch)
treee78cb9954f69b7a52ffd80f19aed803a61801325 /sys/compat/linux
parent4982af4aa749183aa5fc954d9cafc8c956db9d88 (diff)
Notes
Diffstat (limited to 'sys/compat/linux')
-rw-r--r--sys/compat/linux/linux_file.c309
-rw-r--r--sys/compat/linux/linux_misc.c147
-rw-r--r--sys/compat/linux/linux_signal.c26
-rw-r--r--sys/compat/linux/linux_stats.c55
-rw-r--r--sys/compat/linux/linux_sysctl.c15
-rw-r--r--sys/compat/linux/linux_uid16.c40
6 files changed, 264 insertions, 328 deletions
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index fc634ba3adfd3..cf57d62ba8d7c 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -44,6 +44,7 @@
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
#include <sys/tty.h>
#include <sys/vnode.h>
@@ -60,82 +61,68 @@
int
linux_creat(struct thread *td, struct linux_creat_args *args)
{
- struct open_args /* {
- char *path;
- int flags;
- int mode;
- } */ bsd_open_args;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTCREAT(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(creat))
- printf(ARGS(creat, "%s, %d"), args->path, args->mode);
+ printf(ARGS(creat, "%s, %d"), path, args->mode);
#endif
- bsd_open_args.path = args->path;
- bsd_open_args.mode = args->mode;
- bsd_open_args.flags = O_WRONLY | O_CREAT | O_TRUNC;
- return open(td, &bsd_open_args);
+ error = kern_open(td, path, UIO_SYSSPACE, O_WRONLY | O_CREAT | O_TRUNC,
+ args->mode);
+ LFREEPATH(path);
+ return (error);
}
#endif /*!__alpha__*/
int
linux_open(struct thread *td, struct linux_open_args *args)
{
- struct open_args /* {
- char *path;
- int flags;
- int mode;
- } */ bsd_open_args;
struct proc *p = td->td_proc;
- int error;
- caddr_t sg;
+ char *path;
+ int bsd_flags, error;
- sg = stackgap_init();
-
if (args->flags & LINUX_O_CREAT)
- CHECKALTCREAT(td, &sg, args->path);
+ LCONVPATHCREAT(td, args->path, &path);
else
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(open))
printf(ARGS(open, "%s, 0x%x, 0x%x"),
- args->path, args->flags, args->mode);
+ path, args->flags, args->mode);
#endif
- bsd_open_args.flags = 0;
+ bsd_flags = 0;
if (args->flags & LINUX_O_RDONLY)
- bsd_open_args.flags |= O_RDONLY;
+ bsd_flags |= O_RDONLY;
if (args->flags & LINUX_O_WRONLY)
- bsd_open_args.flags |= O_WRONLY;
+ bsd_flags |= O_WRONLY;
if (args->flags & LINUX_O_RDWR)
- bsd_open_args.flags |= O_RDWR;
+ bsd_flags |= O_RDWR;
if (args->flags & LINUX_O_NDELAY)
- bsd_open_args.flags |= O_NONBLOCK;
+ bsd_flags |= O_NONBLOCK;
if (args->flags & LINUX_O_APPEND)
- bsd_open_args.flags |= O_APPEND;
+ bsd_flags |= O_APPEND;
if (args->flags & LINUX_O_SYNC)
- bsd_open_args.flags |= O_FSYNC;
+ bsd_flags |= O_FSYNC;
if (args->flags & LINUX_O_NONBLOCK)
- bsd_open_args.flags |= O_NONBLOCK;
+ bsd_flags |= O_NONBLOCK;
if (args->flags & LINUX_FASYNC)
- bsd_open_args.flags |= O_ASYNC;
+ bsd_flags |= O_ASYNC;
if (args->flags & LINUX_O_CREAT)
- bsd_open_args.flags |= O_CREAT;
+ bsd_flags |= O_CREAT;
if (args->flags & LINUX_O_TRUNC)
- bsd_open_args.flags |= O_TRUNC;
+ bsd_flags |= O_TRUNC;
if (args->flags & LINUX_O_EXCL)
- bsd_open_args.flags |= O_EXCL;
+ bsd_flags |= O_EXCL;
if (args->flags & LINUX_O_NOCTTY)
- bsd_open_args.flags |= O_NOCTTY;
- bsd_open_args.path = args->path;
- bsd_open_args.mode = args->mode;
+ bsd_flags |= O_NOCTTY;
- error = open(td, &bsd_open_args);
+ error = kern_open(td, path, UIO_SYSSPACE, bsd_flags, args->mode);
PROC_LOCK(p);
- if (!error && !(bsd_open_args.flags & O_NOCTTY) &&
+ if (!error && !(bsd_flags & O_NOCTTY) &&
SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
struct file *fp;
@@ -154,6 +141,7 @@ linux_open(struct thread *td, struct linux_open_args *args)
printf(LMSG("open returns error %d"), error);
#endif
}
+ LFREEPATH(path);
return error;
}
@@ -493,214 +481,213 @@ linux_getdents64(struct thread *td, struct linux_getdents64_args *args)
int
linux_access(struct thread *td, struct linux_access_args *args)
{
- struct access_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(access))
- printf(ARGS(access, "%s, %d"), args->path, args->flags);
+ printf(ARGS(access, "%s, %d"), path, args->flags);
#endif
- bsd.path = args->path;
- bsd.flags = args->flags;
-
- return access(td, &bsd);
+ error = kern_access(td, path, UIO_SYSSPACE, args->flags);
+ LFREEPATH(path);
+ return (error);
}
int
linux_unlink(struct thread *td, struct linux_unlink_args *args)
{
- struct unlink_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(unlink))
- printf(ARGS(unlink, "%s"), args->path);
+ printf(ARGS(unlink, "%s"), path);
#endif
- bsd.path = args->path;
- return unlink(td, &bsd);
+ error = kern_unlink(td, path, UIO_SYSSPACE);
+ LFREEPATH(path);
+ return (error);
}
int
linux_chdir(struct thread *td, struct linux_chdir_args *args)
{
- struct chdir_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(chdir))
- printf(ARGS(chdir, "%s"), args->path);
+ printf(ARGS(chdir, "%s"), path);
#endif
- bsd.path = args->path;
-
- return chdir(td, &bsd);
+ error = kern_chdir(td, path, UIO_SYSSPACE);
+ LFREEPATH(path);
+ return (error);
}
int
linux_chmod(struct thread *td, struct linux_chmod_args *args)
{
- struct chmod_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(chmod))
- printf(ARGS(chmod, "%s, %d"), args->path, args->mode);
+ printf(ARGS(chmod, "%s, %d"), path, args->mode);
#endif
- bsd.path = args->path;
- bsd.mode = args->mode;
-
- return chmod(td, &bsd);
+ error = kern_chmod(td, path, UIO_SYSSPACE, args->mode);
+ LFREEPATH(path);
+ return (error);
}
int
linux_mkdir(struct thread *td, struct linux_mkdir_args *args)
{
- struct mkdir_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTCREAT(td, &sg, args->path);
+ LCONVPATHCREAT(td, args->path, &path);
#ifdef DEBUG
if (ldebug(mkdir))
- printf(ARGS(mkdir, "%s, %d"), args->path, args->mode);
+ printf(ARGS(mkdir, "%s, %d"), path, args->mode);
#endif
- bsd.path = args->path;
- bsd.mode = args->mode;
-
- return mkdir(td, &bsd);
+ error = kern_mkdir(td, path, UIO_SYSSPACE, args->mode);
+ LFREEPATH(path);
+ return (error);
}
int
linux_rmdir(struct thread *td, struct linux_rmdir_args *args)
{
- struct rmdir_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(rmdir))
- printf(ARGS(rmdir, "%s"), args->path);
+ printf(ARGS(rmdir, "%s"), path);
#endif
- bsd.path = args->path;
-
- return rmdir(td, &bsd);
+ error = kern_rmdir(td, path, UIO_SYSSPACE);
+ LFREEPATH(path);
+ return (error);
}
int
linux_rename(struct thread *td, struct linux_rename_args *args)
{
- struct rename_args bsd;
- caddr_t sg;
+ char *from, *to;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->from);
- CHECKALTCREAT(td, &sg, args->to);
+ LCONVPATHEXIST(td, args->from, &from);
+ /* Expand LCONVPATHCREATE so that `from' can be freed on errors */
+ error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1);
+ if (to == NULL) {
+ LFREEPATH(from);
+ return (error);
+ }
#ifdef DEBUG
if (ldebug(rename))
- printf(ARGS(rename, "%s, %s"), args->from, args->to);
+ printf(ARGS(rename, "%s, %s"), from, to);
#endif
- bsd.from = args->from;
- bsd.to = args->to;
-
- return rename(td, &bsd);
+ error = kern_rename(td, from, to, UIO_SYSSPACE);
+ LFREEPATH(from);
+ LFREEPATH(to);
+ return (error);
}
int
linux_symlink(struct thread *td, struct linux_symlink_args *args)
{
- struct symlink_args bsd;
- caddr_t sg;
+ char *path, *to;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
- CHECKALTCREAT(td, &sg, args->to);
+ LCONVPATHEXIST(td, args->path, &path);
+ /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
+ error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1);
+ if (to == NULL) {
+ LFREEPATH(path);
+ return (error);
+ }
#ifdef DEBUG
if (ldebug(symlink))
- printf(ARGS(symlink, "%s, %s"), args->path, args->to);
+ printf(ARGS(symlink, "%s, %s"), path, to);
#endif
- bsd.path = args->path;
- bsd.link = args->to;
-
- return symlink(td, &bsd);
+ error = kern_symlink(td, path, to, UIO_SYSSPACE);
+ LFREEPATH(path);
+ LFREEPATH(to);
+ return (error);
}
int
linux_readlink(struct thread *td, struct linux_readlink_args *args)
{
- struct readlink_args bsd;
- caddr_t sg;
+ char *name;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->name);
+ LCONVPATHEXIST(td, args->name, &name);
#ifdef DEBUG
if (ldebug(readlink))
- printf(ARGS(readlink, "%s, %p, %d"),
- args->name, (void *)args->buf, args->count);
+ printf(ARGS(readlink, "%s, %p, %d"), name, (void *)args->buf,
+ args->count);
#endif
- bsd.path = args->name;
- bsd.buf = args->buf;
- bsd.count = args->count;
-
- return readlink(td, &bsd);
+ error = kern_readlink(td, name, UIO_SYSSPACE, args->buf, UIO_USERSPACE,
+ args->count);
+ LFREEPATH(name);
+ return (error);
}
int
linux_truncate(struct thread *td, struct linux_truncate_args *args)
{
- struct truncate_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(truncate))
- printf(ARGS(truncate, "%s, %ld"), args->path,
- (long)args->length);
+ printf(ARGS(truncate, "%s, %ld"), path, (long)args->length);
#endif
- bsd.path = args->path;
- bsd.length = args->length;
- return truncate(td, &bsd);
+ error = kern_truncate(td, path, UIO_SYSSPACE, args->length);
+ LFREEPATH(path);
+ return (error);
}
int
linux_link(struct thread *td, struct linux_link_args *args)
{
- struct link_args bsd;
- caddr_t sg;
+ char *path, *to;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
- CHECKALTCREAT(td, &sg, args->to);
+ LCONVPATHEXIST(td, args->path, &path);
+ /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
+ error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1);
+ if (to == NULL) {
+ LFREEPATH(path);
+ return (error);
+ }
#ifdef DEBUG
if (ldebug(link))
- printf(ARGS(link, "%s, %s"), args->path, args->to);
+ printf(ARGS(link, "%s, %s"), path, to);
#endif
-
- bsd.path = args->path;
- bsd.link = args->to;
-
- return link(td, &bsd);
+ error = kern_link(td, path, to, UIO_SYSSPACE);
+ LFREEPATH(path);
+ LFREEPATH(to);
+ return (error);
}
#ifndef __alpha__
@@ -1158,41 +1145,33 @@ linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args)
int
linux_chown(struct thread *td, struct linux_chown_args *args)
{
- struct chown_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(chown))
- printf(ARGS(chown, "%s, %d, %d"), args->path, args->uid,
- args->gid);
+ printf(ARGS(chown, "%s, %d, %d"), path, args->uid, args->gid);
#endif
-
- bsd.path = args->path;
- bsd.uid = args->uid;
- bsd.gid = args->gid;
- return (chown(td, &bsd));
+ error = kern_chown(td, path, UIO_SYSSPACE, args->uid, args->gid);
+ LFREEPATH(path);
+ return (error);
}
int
linux_lchown(struct thread *td, struct linux_lchown_args *args)
{
- struct lchown_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(lchown))
- printf(ARGS(lchown, "%s, %d, %d"), args->path, args->uid,
- args->gid);
+ printf(ARGS(lchown, "%s, %d, %d"), path, args->uid, args->gid);
#endif
-
- bsd.path = args->path;
- bsd.uid = args->uid;
- bsd.gid = args->gid;
- return (lchown(td, &bsd));
+ error = kern_lchown(td, path, UIO_SYSSPACE, args->uid, args->gid);
+ LFREEPATH(path);
+ return (error);
}
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index d6259bc868f03..8c39153ebf9ad 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -50,6 +50,7 @@
#include <sys/resourcevar.h>
#include <sys/signalvar.h>
#include <sys/stat.h>
+#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/time.h>
@@ -235,16 +236,15 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args)
unsigned long file_offset;
vm_offset_t buffer;
unsigned long bss_size;
+ char *library;
int error;
- caddr_t sg;
int locked;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->library);
+ LCONVPATHEXIST(td, args->library, &library);
#ifdef DEBUG
if (ldebug(uselib))
- printf(ARGS(uselib, "%s"), args->library);
+ printf(ARGS(uselib, "%s"), library);
#endif
a_out = NULL;
@@ -255,8 +255,9 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args)
* XXX: This code should make use of vn_open(), rather than doing
* all this stuff itself.
*/
- NDINIT(&ni, LOOKUP, FOLLOW|LOCKLEAF, UIO_USERSPACE, args->library, td);
+ NDINIT(&ni, LOOKUP, FOLLOW|LOCKLEAF, UIO_SYSSPACE, library, td);
error = namei(&ni);
+ LFREEPATH(library);
if (error)
goto cleanup;
@@ -476,9 +477,7 @@ cleanup:
int
linux_select(struct thread *td, struct linux_select_args *args)
{
- struct select_args bsa;
struct timeval tv0, tv1, utv, *tvp;
- caddr_t sg;
int error;
#ifdef DEBUG
@@ -488,13 +487,6 @@ linux_select(struct thread *td, struct linux_select_args *args)
(void *)args->exceptfds, (void *)args->timeout);
#endif
- error = 0;
- bsa.nd = args->nfds;
- bsa.in = args->readfds;
- bsa.ou = args->writefds;
- bsa.ex = args->exceptfds;
- bsa.tv = (struct timeval *)args->timeout;
-
/*
* Store current time for computation of the amount of
* time left.
@@ -514,8 +506,6 @@ linux_select(struct thread *td, struct linux_select_args *args)
* The timeval was invalid. Convert it to something
* valid that will act as it does under Linux.
*/
- sg = stackgap_init();
- tvp = stackgap_alloc(&sg, sizeof(utv));
utv.tv_sec += utv.tv_usec / 1000000;
utv.tv_usec %= 1000000;
if (utv.tv_usec < 0) {
@@ -524,14 +514,15 @@ linux_select(struct thread *td, struct linux_select_args *args)
}
if (utv.tv_sec < 0)
timevalclear(&utv);
- if ((error = copyout(&utv, tvp, sizeof(utv))))
- goto select_out;
- bsa.tv = tvp;
}
microtime(&tv0);
- }
+ tvp = &utv;
+ } else
+ tvp = NULL;
+
+ error = kern_select(td, args->nfds, args->readfds, args->writefds,
+ args->exceptfds, tvp);
- error = select(td, &bsa);
#ifdef DEBUG
if (ldebug(select))
printf(LMSG("real select returns %d"), error);
@@ -729,42 +720,34 @@ struct l_utimbuf {
int
linux_utime(struct thread *td, struct linux_utime_args *args)
{
- struct utimes_args /* {
- char *path;
- struct timeval *tptr;
- } */ bsdutimes;
struct timeval tv[2], *tvp;
struct l_utimbuf lut;
+ char *fname;
int error;
- caddr_t sg;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->fname);
+ LCONVPATHEXIST(td, args->fname, &fname);
#ifdef DEBUG
if (ldebug(utime))
- printf(ARGS(utime, "%s, *"), args->fname);
+ printf(ARGS(utime, "%s, *"), fname);
#endif
if (args->times) {
- if ((error = copyin((caddr_t)args->times, &lut, sizeof lut)))
+ if ((error = copyin((caddr_t)args->times, &lut, sizeof lut))) {
+ LFREEPATH(fname);
return error;
+ }
tv[0].tv_sec = lut.l_actime;
tv[0].tv_usec = 0;
tv[1].tv_sec = lut.l_modtime;
tv[1].tv_usec = 0;
- /* so that utimes can copyin */
- tvp = (struct timeval *)stackgap_alloc(&sg, sizeof(tv));
- if (tvp == NULL)
- return (ENAMETOOLONG);
- if ((error = copyout(tv, tvp, sizeof(tv))))
- return error;
- bsdutimes.tptr = tvp;
+ tvp = tv;
} else
- bsdutimes.tptr = NULL;
+ tvp = NULL;
- bsdutimes.path = args->fname;
- return utimes(td, &bsdutimes);
+ error = kern_utimes(td, fname, UIO_SYSSPACE, tvp, UIO_SYSSPACE);
+ LFREEPATH(fname);
+ return (error);
}
#endif /* __i386__ */
@@ -868,30 +851,23 @@ linux_wait4(struct thread *td, struct linux_wait4_args *args)
int
linux_mknod(struct thread *td, struct linux_mknod_args *args)
{
- caddr_t sg;
- struct mknod_args bsd_mknod;
- struct mkfifo_args bsd_mkfifo;
-
- sg = stackgap_init();
+ char *path;
+ int error;
- CHECKALTCREAT(td, &sg, args->path);
+ LCONVPATHCREAT(td, args->path, &path);
#ifdef DEBUG
if (ldebug(mknod))
- printf(ARGS(mknod, "%s, %d, %d"),
- args->path, args->mode, args->dev);
+ printf(ARGS(mknod, "%s, %d, %d"), path, args->mode, args->dev);
#endif
- if (args->mode & S_IFIFO) {
- bsd_mkfifo.path = args->path;
- bsd_mkfifo.mode = args->mode;
- return mkfifo(td, &bsd_mkfifo);
- } else {
- bsd_mknod.path = args->path;
- bsd_mknod.mode = args->mode;
- bsd_mknod.dev = args->dev;
- return mknod(td, &bsd_mknod);
- }
+ if (args->mode & S_IFIFO)
+ error = kern_mkfifo(td, path, UIO_SYSSPACE, args->mode);
+ else
+ error = kern_mknod(td, path, UIO_SYSSPACE, args->mode,
+ args->dev);
+ LFREEPATH(path);
+ return (error);
}
/*
@@ -1071,10 +1047,10 @@ linux_getgroups(struct thread *td, struct linux_getgroups_args *args)
int
linux_setrlimit(struct thread *td, struct linux_setrlimit_args *args)
{
- struct __setrlimit_args bsd;
+ struct rlimit bsd_rlim;
struct l_rlimit rlim;
+ u_int which;
int error;
- caddr_t sg = stackgap_init();
#ifdef DEBUG
if (ldebug(setrlimit))
@@ -1085,27 +1061,26 @@ linux_setrlimit(struct thread *td, struct linux_setrlimit_args *args)
if (args->resource >= LINUX_RLIM_NLIMITS)
return (EINVAL);
- bsd.which = linux_to_bsd_resource[args->resource];
- if (bsd.which == -1)
+ which = linux_to_bsd_resource[args->resource];
+ if (which == -1)
return (EINVAL);
error = copyin((caddr_t)args->rlim, &rlim, sizeof(rlim));
if (error)
return (error);
- bsd.rlp = stackgap_alloc(&sg, sizeof(struct rlimit));
- bsd.rlp->rlim_cur = (rlim_t)rlim.rlim_cur;
- bsd.rlp->rlim_max = (rlim_t)rlim.rlim_max;
- return (setrlimit(td, &bsd));
+ bsd_rlim.rlim_cur = (rlim_t)rlim.rlim_cur;
+ bsd_rlim.rlim_max = (rlim_t)rlim.rlim_max;
+ return (dosetrlimit(td, which, &bsd_rlim));
}
int
linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
{
- struct __getrlimit_args bsd;
struct l_rlimit rlim;
- int error;
- caddr_t sg = stackgap_init();
+ struct proc *p = td->td_proc;
+ struct rlimit *bsd_rlp;
+ u_int which;
#ifdef DEBUG
if (ldebug(old_getrlimit))
@@ -1116,19 +1091,15 @@ linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
if (args->resource >= LINUX_RLIM_NLIMITS)
return (EINVAL);
- bsd.which = linux_to_bsd_resource[args->resource];
- if (bsd.which == -1)
+ which = linux_to_bsd_resource[args->resource];
+ if (which == -1)
return (EINVAL);
+ bsd_rlp = &p->p_rlimit[which];
- bsd.rlp = stackgap_alloc(&sg, sizeof(struct rlimit));
- error = getrlimit(td, &bsd);
- if (error)
- return (error);
-
- rlim.rlim_cur = (unsigned long)bsd.rlp->rlim_cur;
+ rlim.rlim_cur = (unsigned long)bsd_rlp->rlim_cur;
if (rlim.rlim_cur == ULONG_MAX)
rlim.rlim_cur = LONG_MAX;
- rlim.rlim_max = (unsigned long)bsd.rlp->rlim_max;
+ rlim.rlim_max = (unsigned long)bsd_rlp->rlim_max;
if (rlim.rlim_max == ULONG_MAX)
rlim.rlim_max = LONG_MAX;
return (copyout(&rlim, (caddr_t)args->rlim, sizeof(rlim)));
@@ -1137,10 +1108,10 @@ linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
int
linux_getrlimit(struct thread *td, struct linux_getrlimit_args *args)
{
- struct __getrlimit_args bsd;
struct l_rlimit rlim;
- int error;
- caddr_t sg = stackgap_init();
+ struct proc *p = td->td_proc;
+ struct rlimit *bsd_rlp;
+ u_int which;
#ifdef DEBUG
if (ldebug(getrlimit))
@@ -1151,17 +1122,13 @@ linux_getrlimit(struct thread *td, struct linux_getrlimit_args *args)
if (args->resource >= LINUX_RLIM_NLIMITS)
return (EINVAL);
- bsd.which = linux_to_bsd_resource[args->resource];
- if (bsd.which == -1)
+ which = linux_to_bsd_resource[args->resource];
+ if (which == -1)
return (EINVAL);
+ bsd_rlp = &p->p_rlimit[which];
- bsd.rlp = stackgap_alloc(&sg, sizeof(struct rlimit));
- error = getrlimit(td, &bsd);
- if (error)
- return (error);
-
- rlim.rlim_cur = (l_ulong)bsd.rlp->rlim_cur;
- rlim.rlim_max = (l_ulong)bsd.rlp->rlim_max;
+ rlim.rlim_cur = (l_ulong)bsd_rlp->rlim_cur;
+ rlim.rlim_max = (l_ulong)bsd_rlp->rlim_max;
return (copyout(&rlim, (caddr_t)args->rlim, sizeof(rlim)));
}
#endif /*!__alpha__*/
diff --git a/sys/compat/linux/linux_signal.c b/sys/compat/linux/linux_signal.c
index 61fc98c87fffe..532fb81a678a7 100644
--- a/sys/compat/linux/linux_signal.c
+++ b/sys/compat/linux/linux_signal.c
@@ -34,6 +34,7 @@
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/signalvar.h>
+#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
#include <machine/../linux/linux.h>
@@ -134,36 +135,27 @@ int
linux_do_sigaction(struct thread *td, int linux_sig, l_sigaction_t *linux_nsa,
l_sigaction_t *linux_osa)
{
- struct sigaction *nsa, *osa;
- struct sigaction_args sa_args;
- int error;
- caddr_t sg = stackgap_init();
+ struct sigaction act, oact, *nsa, *osa;
+ int error, sig;
if (linux_sig <= 0 || linux_sig > LINUX_NSIG)
return (EINVAL);
- if (linux_osa != NULL)
- osa = stackgap_alloc(&sg, sizeof(struct sigaction));
- else
- osa = NULL;
-
+ osa = (linux_osa != NULL) ? &oact : NULL;
if (linux_nsa != NULL) {
- nsa = stackgap_alloc(&sg, sizeof(struct sigaction));
+ nsa = &act;
linux_to_bsd_sigaction(linux_nsa, nsa);
- }
- else
+ } else
nsa = NULL;
#ifndef __alpha__
if (linux_sig <= LINUX_SIGTBLSZ)
- sa_args.sig = linux_to_bsd_signal[_SIG_IDX(linux_sig)];
+ sig = linux_to_bsd_signal[_SIG_IDX(linux_sig)];
else
#endif
- sa_args.sig = linux_sig;
+ sig = linux_sig;
- sa_args.act = nsa;
- sa_args.oact = osa;
- error = sigaction(td, &sa_args);
+ error = kern_sigaction(td, sig, nsa, osa, 0);
if (error)
return (error);
diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c
index ad90ffc298732..485253aaf387e 100644
--- a/sys/compat/linux/linux_stats.c
+++ b/sys/compat/linux/linux_stats.c
@@ -94,20 +94,19 @@ linux_newstat(struct thread *td, struct linux_newstat_args *args)
{
struct stat buf;
struct nameidata nd;
+ char *path;
int error;
- caddr_t sg;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(newstat))
- printf(ARGS(newstat, "%s, *"), args->path);
+ printf(ARGS(newstat, "%s, *"), path);
#endif
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- args->path, td);
+ NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_SYSSPACE, path, td);
error = namei(&nd);
+ LFREEPATH(path);
if (error)
return (error);
NDFREE(&nd, NDF_ONLY_PNBUF);
@@ -126,19 +125,19 @@ linux_newlstat(struct thread *td, struct linux_newlstat_args *args)
int error;
struct stat sb;
struct nameidata nd;
- caddr_t sg;
+ char *path;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(newlstat))
- printf(ARGS(newlstat, "%s, *"), args->path);
+ printf(ARGS(newlstat, "%s, *"), path);
#endif
- NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- args->path, td);
+ NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | NOOBJ, UIO_SYSSPACE, path,
+ td);
error = namei(&nd);
+ LFREEPATH(path);
if (error)
return (error);
NDFREE(&nd, NDF_ONLY_PNBUF);
@@ -231,19 +230,19 @@ linux_statfs(struct thread *td, struct linux_statfs_args *args)
struct statfs *bsd_statfs;
struct nameidata nd;
struct l_statfs linux_statfs;
+ char *path;
int error;
- caddr_t sg;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(statfs))
- printf(ARGS(statfs, "%s, *"), args->path);
+ printf(ARGS(statfs, "%s, *"), path);
#endif
ndp = &nd;
- NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args->path, curthread);
+ NDINIT(ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, path, td);
error = namei(ndp);
+ LFREEPATH(path);
if (error)
return error;
NDFREE(ndp, NDF_ONLY_PNBUF);
@@ -416,19 +415,19 @@ linux_stat64(struct thread *td, struct linux_stat64_args *args)
struct stat buf;
struct nameidata nd;
int error;
- caddr_t sg;
+ char *filename;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->filename);
+ LCONVPATHEXIST(td, args->filename, &filename);
#ifdef DEBUG
if (ldebug(stat64))
- printf(ARGS(stat64, "%s, *"), args->filename);
+ printf(ARGS(stat64, "%s, *"), filename);
#endif
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- args->filename, td);
+ NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NOOBJ, UIO_SYSSPACE, filename,
+ td);
error = namei(&nd);
+ LFREEPATH(filename);
if (error)
return (error);
NDFREE(&nd, NDF_ONLY_PNBUF);
@@ -447,19 +446,19 @@ linux_lstat64(struct thread *td, struct linux_lstat64_args *args)
int error;
struct stat sb;
struct nameidata nd;
- caddr_t sg;
+ char *filename;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->filename);
+ LCONVPATHEXIST(td, args->filename, &filename);
#ifdef DEBUG
if (ldebug(lstat64))
printf(ARGS(lstat64, "%s, *"), args->filename);
#endif
- NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | NOOBJ, UIO_USERSPACE,
- args->filename, td);
+ NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | NOOBJ, UIO_SYSSPACE, filename,
+ td);
error = namei(&nd);
+ LFREEPATH(filename);
if (error)
return (error);
NDFREE(&nd, NDF_ONLY_PNBUF);
diff --git a/sys/compat/linux/linux_sysctl.c b/sys/compat/linux/linux_sysctl.c
index 98dab20bfe319..d1f6996ba8c4a 100644
--- a/sys/compat/linux/linux_sysctl.c
+++ b/sys/compat/linux/linux_sysctl.c
@@ -80,20 +80,20 @@ linux_sysctl(struct thread *td, struct linux_sysctl_args *args)
struct l___sysctl_args la;
l_int *mib;
int error, i;
- caddr_t sg;
error = copyin((caddr_t)args->args, &la, sizeof(la));
if (error)
return (error);
- if (la.nlen == 0 || la.nlen > LINUX_CTL_MAXNAME)
+ if (la.nlen <= 0 || la.nlen > LINUX_CTL_MAXNAME)
return (ENOTDIR);
- sg = stackgap_init();
- mib = stackgap_alloc(&sg, la.nlen * sizeof(l_int));
+ mib = malloc(la.nlen * sizeof(l_int), M_TEMP, M_WAITOK);
error = copyin(la.name, mib, la.nlen * sizeof(l_int));
- if (error)
+ if (error) {
+ free(mib, M_TEMP);
return (error);
+ }
switch (mib[0]) {
case LINUX_CTL_KERN:
@@ -102,7 +102,9 @@ linux_sysctl(struct thread *td, struct linux_sysctl_args *args)
switch (mib[1]) {
case LINUX_KERN_VERSION:
- return (handle_string(&la, version));
+ error = handle_string(&la, version);
+ free(mib, M_TEMP);
+ return (error);
default:
break;
}
@@ -116,5 +118,6 @@ linux_sysctl(struct thread *td, struct linux_sysctl_args *args)
printf("%c%d", (i) ? ',' : '{', mib[i]);
printf("}\n");
+ free(mib, M_TEMP);
return (ENOTDIR);
}
diff --git a/sys/compat/linux/linux_uid16.c b/sys/compat/linux/linux_uid16.c
index ee39025354f5a..538c118f7ce45 100644
--- a/sys/compat/linux/linux_uid16.c
+++ b/sys/compat/linux/linux_uid16.c
@@ -33,6 +33,7 @@
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
#include <machine/../linux/linux.h>
@@ -44,48 +45,43 @@ DUMMY(setfsgid16);
DUMMY(getresuid16);
DUMMY(getresgid16);
-#define CAST_NOCHG(x) (x == 0xFFFF) ? -1 : x;
+#define CAST_NOCHG(x) ((x == 0xFFFF) ? -1 : x)
int
linux_chown16(struct thread *td, struct linux_chown16_args *args)
{
- struct chown_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(chown16))
- printf(ARGS(chown16, "%s, %d, %d"), args->path, args->uid,
- args->gid);
+ printf(ARGS(chown16, "%s, %d, %d"), path, args->uid, args->gid);
#endif
-
- bsd.path = args->path;
- bsd.uid = CAST_NOCHG(args->uid);
- bsd.gid = CAST_NOCHG(args->gid);
- return (chown(td, &bsd));
+ error = kern_chown(td, path, UIO_SYSSPACE, CAST_NOCHG(args->uid),
+ CAST_NOCHG(args->gid));
+ LFREEPATH(path);
+ return (error);
}
int
linux_lchown16(struct thread *td, struct linux_lchown16_args *args)
{
- struct lchown_args bsd;
- caddr_t sg;
+ char *path;
+ int error;
- sg = stackgap_init();
- CHECKALTEXIST(td, &sg, args->path);
+ LCONVPATHEXIST(td, args->path, &path);
#ifdef DEBUG
if (ldebug(lchown16))
- printf(ARGS(lchown16, "%s, %d, %d"), args->path, args->uid,
+ printf(ARGS(lchown16, "%s, %d, %d"), path, args->uid,
args->gid);
#endif
-
- bsd.path = args->path;
- bsd.uid = CAST_NOCHG(args->uid);
- bsd.gid = CAST_NOCHG(args->gid);
- return (lchown(td, &bsd));
+ error = kern_lchown(td, path, UIO_SYSSPACE, CAST_NOCHG(args->uid),
+ CAST_NOCHG(args->gid));
+ LFREEPATH(path);
+ return (error);
}
int