2002-07-20 02:56:12 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 Doug Rabson
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-07-25 21:19:19 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-10-09 22:27:24 +00:00
|
|
|
#include "opt_compat.h"
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/exec.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/filedesc.h>
|
2003-12-23 03:20:49 +00:00
|
|
|
#include <sys/namei.h>
|
2002-07-20 02:56:12 +00:00
|
|
|
#include <sys/imgact.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/file.h> /* Must come after sys/malloc.h */
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/selinfo.h>
|
2005-06-03 23:15:01 +00:00
|
|
|
#include <sys/eventvar.h> /* Must come after sys/selinfo.h */
|
2002-07-20 02:56:12 +00:00
|
|
|
#include <sys/pipe.h> /* Must come after sys/selinfo.h */
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/stat.h>
|
2003-04-22 18:23:49 +00:00
|
|
|
#include <sys/syscallsubr.h>
|
2002-07-20 02:56:12 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/sysent.h>
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sys/vnode.h>
|
2004-03-17 20:00:00 +00:00
|
|
|
#include <sys/wait.h>
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
#include <vm/vm_map.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
2003-08-22 23:07:28 +00:00
|
|
|
#include <compat/freebsd32/freebsd32_util.h>
|
|
|
|
#include <compat/freebsd32/freebsd32.h>
|
|
|
|
#include <compat/freebsd32/freebsd32_proto.h>
|
|
|
|
|
2003-10-30 02:40:30 +00:00
|
|
|
CTASSERT(sizeof(struct timeval32) == 8);
|
|
|
|
CTASSERT(sizeof(struct timespec32) == 8);
|
|
|
|
CTASSERT(sizeof(struct statfs32) == 256);
|
|
|
|
CTASSERT(sizeof(struct rusage32) == 72);
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2004-03-17 20:00:00 +00:00
|
|
|
int error, status;
|
|
|
|
struct rusage32 ru32;
|
2004-10-05 18:51:11 +00:00
|
|
|
struct rusage ru, *rup;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2004-10-05 18:51:11 +00:00
|
|
|
if (uap->rusage != NULL)
|
|
|
|
rup = &ru;
|
|
|
|
else
|
|
|
|
rup = NULL;
|
|
|
|
error = kern_wait(td, uap->pid, &status, uap->options, rup);
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2004-03-17 20:00:00 +00:00
|
|
|
if (uap->status != NULL)
|
|
|
|
error = copyout(&status, uap->status, sizeof(status));
|
|
|
|
if (uap->rusage != NULL && error == 0) {
|
2002-07-20 02:56:12 +00:00
|
|
|
TV_CP(ru, ru32, ru_utime);
|
|
|
|
TV_CP(ru, ru32, ru_stime);
|
|
|
|
CP(ru, ru32, ru_maxrss);
|
|
|
|
CP(ru, ru32, ru_ixrss);
|
|
|
|
CP(ru, ru32, ru_idrss);
|
|
|
|
CP(ru, ru32, ru_isrss);
|
|
|
|
CP(ru, ru32, ru_minflt);
|
|
|
|
CP(ru, ru32, ru_majflt);
|
|
|
|
CP(ru, ru32, ru_nswap);
|
|
|
|
CP(ru, ru32, ru_inblock);
|
|
|
|
CP(ru, ru32, ru_oublock);
|
|
|
|
CP(ru, ru32, ru_msgsnd);
|
|
|
|
CP(ru, ru32, ru_msgrcv);
|
|
|
|
CP(ru, ru32, ru_nsignals);
|
|
|
|
CP(ru, ru32, ru_nvcsw);
|
|
|
|
CP(ru, ru32, ru_nivcsw);
|
2004-03-17 20:00:00 +00:00
|
|
|
error = copyout(&ru32, uap->rusage, sizeof(ru32));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-04-24 04:31:59 +00:00
|
|
|
#ifdef COMPAT_FREEBSD4
|
2002-07-20 02:56:12 +00:00
|
|
|
static void
|
|
|
|
copy_statfs(struct statfs *in, struct statfs32 *out)
|
|
|
|
{
|
|
|
|
CP(*in, *out, f_bsize);
|
|
|
|
CP(*in, *out, f_iosize);
|
|
|
|
CP(*in, *out, f_blocks);
|
|
|
|
CP(*in, *out, f_bfree);
|
|
|
|
CP(*in, *out, f_bavail);
|
|
|
|
CP(*in, *out, f_files);
|
|
|
|
CP(*in, *out, f_ffree);
|
|
|
|
CP(*in, *out, f_fsid);
|
|
|
|
CP(*in, *out, f_owner);
|
|
|
|
CP(*in, *out, f_type);
|
|
|
|
CP(*in, *out, f_flags);
|
|
|
|
CP(*in, *out, f_flags);
|
|
|
|
CP(*in, *out, f_syncwrites);
|
|
|
|
CP(*in, *out, f_asyncwrites);
|
|
|
|
bcopy(in->f_fstypename,
|
|
|
|
out->f_fstypename, MFSNAMELEN);
|
|
|
|
bcopy(in->f_mntonname,
|
2004-04-14 23:17:37 +00:00
|
|
|
out->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
|
2002-07-20 02:56:12 +00:00
|
|
|
CP(*in, *out, f_syncreads);
|
|
|
|
CP(*in, *out, f_asyncreads);
|
|
|
|
bcopy(in->f_mntfromname,
|
2004-04-14 23:17:37 +00:00
|
|
|
out->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
2004-04-24 04:31:59 +00:00
|
|
|
#endif
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2004-04-24 04:31:59 +00:00
|
|
|
#ifdef COMPAT_FREEBSD4
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2004-04-14 23:17:37 +00:00
|
|
|
freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2005-06-09 17:44:46 +00:00
|
|
|
struct statfs *buf, *sp;
|
|
|
|
struct statfs32 stat32;
|
|
|
|
size_t count, size;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
2005-06-09 17:44:46 +00:00
|
|
|
count = uap->bufsize / sizeof(struct statfs32);
|
|
|
|
size = count * sizeof(struct statfs);
|
2005-06-11 14:58:20 +00:00
|
|
|
error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags);
|
|
|
|
if (size > 0) {
|
2002-07-20 02:56:12 +00:00
|
|
|
count = td->td_retval[0];
|
2005-06-09 17:44:46 +00:00
|
|
|
sp = buf;
|
|
|
|
while (count > 0 && error == 0) {
|
|
|
|
copy_statfs(sp, &stat32);
|
|
|
|
error = copyout(&stat32, uap->buf, sizeof(stat32));
|
|
|
|
sp++;
|
|
|
|
uap->buf++;
|
|
|
|
count--;
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
2005-06-09 17:44:46 +00:00
|
|
|
free(buf, M_TEMP);
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
2004-04-24 04:31:59 +00:00
|
|
|
#endif
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
struct sigaltstack32 {
|
|
|
|
u_int32_t ss_sp;
|
|
|
|
u_int32_t ss_size;
|
|
|
|
int ss_flags;
|
|
|
|
};
|
|
|
|
|
2003-10-30 02:40:30 +00:00
|
|
|
CTASSERT(sizeof(struct sigaltstack32) == 12);
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_sigaltstack(struct thread *td,
|
|
|
|
struct freebsd32_sigaltstack_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2003-04-22 18:23:49 +00:00
|
|
|
struct sigaltstack32 s32;
|
|
|
|
struct sigaltstack ss, oss, *ssp;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
2003-04-22 18:23:49 +00:00
|
|
|
if (uap->ss != NULL) {
|
|
|
|
error = copyin(uap->ss, &s32, sizeof(s32));
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2003-04-22 18:23:49 +00:00
|
|
|
PTRIN_CP(s32, ss, ss_sp);
|
|
|
|
CP(s32, ss, ss_size);
|
|
|
|
CP(s32, ss, ss_flags);
|
|
|
|
ssp = &ss;
|
|
|
|
} else
|
|
|
|
ssp = NULL;
|
|
|
|
error = kern_sigaltstack(td, ssp, &oss);
|
|
|
|
if (error == 0 && uap->oss != NULL) {
|
|
|
|
PTROUT_CP(oss, s32, ss_sp);
|
|
|
|
CP(oss, s32, ss_size);
|
|
|
|
CP(oss, s32, ss_flags);
|
|
|
|
error = copyout(&s32, uap->oss, sizeof(s32));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
/*
|
|
|
|
* Custom version of exec_copyin_args() so that we can translate
|
|
|
|
* the pointers.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
freebsd32_exec_copyin_args(struct image_args *args, char *fname,
|
|
|
|
enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
char *argp, *envp;
|
2002-07-20 02:56:12 +00:00
|
|
|
u_int32_t *p32, arg;
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
size_t length;
|
|
|
|
int error;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
bzero(args, sizeof(*args));
|
|
|
|
if (argv == NULL)
|
|
|
|
return (EFAULT);
|
2002-07-20 02:56:12 +00:00
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
/*
|
|
|
|
* Allocate temporary demand zeroed space for argument and
|
|
|
|
* environment strings
|
|
|
|
*/
|
2005-06-24 17:41:28 +00:00
|
|
|
args->buf = (char *) kmem_alloc_wait(exec_map,
|
|
|
|
PATH_MAX + ARG_MAX + MAXSHELLCMDLEN);
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
if (args->buf == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
args->begin_argv = args->buf;
|
|
|
|
args->endp = args->begin_argv;
|
|
|
|
args->stringspace = ARG_MAX;
|
|
|
|
|
|
|
|
args->fname = args->buf + ARG_MAX;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the file name.
|
|
|
|
*/
|
|
|
|
error = (segflg == UIO_SYSSPACE) ?
|
|
|
|
copystr(fname, args->fname, PATH_MAX, &length) :
|
|
|
|
copyinstr(fname, args->fname, PATH_MAX, &length);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* extract arguments first
|
|
|
|
*/
|
|
|
|
p32 = argv;
|
|
|
|
for (;;) {
|
|
|
|
error = copyin(p32++, &arg, sizeof(arg));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
if (arg == 0)
|
|
|
|
break;
|
|
|
|
argp = PTRIN(arg);
|
|
|
|
error = copyinstr(argp, args->endp, args->stringspace, &length);
|
|
|
|
if (error) {
|
|
|
|
if (error == ENAMETOOLONG)
|
|
|
|
return (E2BIG);
|
|
|
|
else
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
args->stringspace -= length;
|
|
|
|
args->endp += length;
|
|
|
|
args->argc++;
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
|
|
|
|
args->begin_envv = args->endp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* extract environment strings
|
|
|
|
*/
|
|
|
|
if (envv) {
|
|
|
|
p32 = envv;
|
|
|
|
for (;;) {
|
2002-07-20 02:56:12 +00:00
|
|
|
error = copyin(p32++, &arg, sizeof(arg));
|
|
|
|
if (error)
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
return (error);
|
|
|
|
if (arg == 0)
|
|
|
|
break;
|
|
|
|
envp = PTRIN(arg);
|
|
|
|
error = copyinstr(envp, args->endp, args->stringspace,
|
|
|
|
&length);
|
|
|
|
if (error) {
|
|
|
|
if (error == ENAMETOOLONG)
|
|
|
|
return (E2BIG);
|
|
|
|
else
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
args->stringspace -= length;
|
|
|
|
args->endp += length;
|
|
|
|
args->envc++;
|
|
|
|
}
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
|
|
|
|
{
|
|
|
|
struct image_args eargs;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
|
|
|
|
uap->argv, uap->envv);
|
|
|
|
if (error == 0)
|
|
|
|
error = kern_execve(td, &eargs, NULL);
|
|
|
|
exec_free_args(&eargs);
|
|
|
|
return (error);
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-14 04:10:49 +00:00
|
|
|
#ifdef __ia64__
|
2002-07-20 02:56:12 +00:00
|
|
|
static int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
|
|
|
|
int prot, int fd, off_t pos)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
vm_map_t map;
|
|
|
|
vm_map_entry_t entry;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
map = &td->td_proc->p_vmspace->vm_map;
|
|
|
|
if (fd != -1)
|
|
|
|
prot |= VM_PROT_WRITE;
|
|
|
|
|
|
|
|
if (vm_map_lookup_entry(map, start, &entry)) {
|
|
|
|
if ((entry->protection & prot) != prot) {
|
|
|
|
rv = vm_map_protect(map,
|
|
|
|
trunc_page(start),
|
|
|
|
round_page(end),
|
|
|
|
entry->protection | prot,
|
|
|
|
FALSE);
|
|
|
|
if (rv != KERN_SUCCESS)
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vm_offset_t addr = trunc_page(start);
|
|
|
|
rv = vm_map_find(map, 0, 0,
|
|
|
|
&addr, PAGE_SIZE, FALSE, prot,
|
|
|
|
VM_PROT_ALL, 0);
|
|
|
|
if (rv != KERN_SUCCESS)
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd != -1) {
|
|
|
|
struct pread_args r;
|
2002-12-14 01:56:26 +00:00
|
|
|
r.fd = fd;
|
|
|
|
r.buf = (void *) start;
|
|
|
|
r.nbyte = end - start;
|
|
|
|
r.offset = pos;
|
2002-07-20 02:56:12 +00:00
|
|
|
return (pread(td, &r));
|
|
|
|
} else {
|
|
|
|
while (start < end) {
|
|
|
|
subyte((void *) start, 0);
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2003-05-14 04:10:49 +00:00
|
|
|
#endif
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
struct mmap_args ap;
|
2002-12-14 01:56:26 +00:00
|
|
|
vm_offset_t addr = (vm_offset_t) uap->addr;
|
|
|
|
vm_size_t len = uap->len;
|
|
|
|
int prot = uap->prot;
|
|
|
|
int flags = uap->flags;
|
|
|
|
int fd = uap->fd;
|
|
|
|
off_t pos = (uap->poslo
|
|
|
|
| ((off_t)uap->poshi << 32));
|
2003-05-14 04:10:49 +00:00
|
|
|
#ifdef __ia64__
|
2002-07-20 02:56:12 +00:00
|
|
|
vm_size_t pageoff;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to handle page size hassles.
|
|
|
|
*/
|
|
|
|
pageoff = (pos & PAGE_MASK);
|
|
|
|
if (flags & MAP_FIXED) {
|
|
|
|
vm_offset_t start, end;
|
|
|
|
start = addr;
|
|
|
|
end = addr + len;
|
|
|
|
|
|
|
|
if (start != trunc_page(start)) {
|
2003-08-22 23:07:28 +00:00
|
|
|
error = freebsd32_mmap_partial(td, start,
|
|
|
|
round_page(start), prot,
|
|
|
|
fd, pos);
|
2002-07-20 02:56:12 +00:00
|
|
|
if (fd != -1)
|
|
|
|
pos += round_page(start) - start;
|
|
|
|
start = round_page(start);
|
|
|
|
}
|
|
|
|
if (end != round_page(end)) {
|
|
|
|
vm_offset_t t = trunc_page(end);
|
2003-08-22 23:07:28 +00:00
|
|
|
error = freebsd32_mmap_partial(td, t, end,
|
2002-07-20 02:56:12 +00:00
|
|
|
prot, fd,
|
|
|
|
pos + t - start);
|
|
|
|
end = trunc_page(end);
|
|
|
|
}
|
|
|
|
if (end > start && fd != -1 && (pos & PAGE_MASK)) {
|
|
|
|
/*
|
|
|
|
* We can't map this region at all. The specified
|
|
|
|
* address doesn't have the same alignment as the file
|
|
|
|
* position. Fake the mapping by simply reading the
|
|
|
|
* entire region into memory. First we need to make
|
|
|
|
* sure the region exists.
|
|
|
|
*/
|
|
|
|
vm_map_t map;
|
|
|
|
struct pread_args r;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
prot |= VM_PROT_WRITE;
|
|
|
|
map = &td->td_proc->p_vmspace->vm_map;
|
|
|
|
rv = vm_map_remove(map, start, end);
|
|
|
|
if (rv != KERN_SUCCESS)
|
|
|
|
return (EINVAL);
|
|
|
|
rv = vm_map_find(map, 0, 0,
|
|
|
|
&start, end - start, FALSE,
|
|
|
|
prot, VM_PROT_ALL, 0);
|
|
|
|
if (rv != KERN_SUCCESS)
|
|
|
|
return (EINVAL);
|
2002-12-14 01:56:26 +00:00
|
|
|
r.fd = fd;
|
|
|
|
r.buf = (void *) start;
|
|
|
|
r.nbyte = end - start;
|
|
|
|
r.offset = pos;
|
2002-07-20 02:56:12 +00:00
|
|
|
error = pread(td, &r);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
td->td_retval[0] = addr;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (end == start) {
|
|
|
|
/*
|
|
|
|
* After dealing with the ragged ends, there
|
|
|
|
* might be none left.
|
|
|
|
*/
|
|
|
|
td->td_retval[0] = addr;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
addr = start;
|
|
|
|
len = end - start;
|
|
|
|
}
|
2003-05-14 04:10:49 +00:00
|
|
|
#endif
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.addr = (void *) addr;
|
|
|
|
ap.len = len;
|
|
|
|
ap.prot = prot;
|
|
|
|
ap.flags = flags;
|
|
|
|
ap.fd = fd;
|
|
|
|
ap.pos = pos;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
return (mmap(td, &ap));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct itimerval32 {
|
|
|
|
struct timeval32 it_interval;
|
|
|
|
struct timeval32 it_value;
|
|
|
|
};
|
|
|
|
|
2003-10-30 02:40:30 +00:00
|
|
|
CTASSERT(sizeof(struct itimerval32) == 16);
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
struct itimerval itv, oitv, *itvp;
|
|
|
|
struct itimerval32 i32;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
if (uap->itv != NULL) {
|
|
|
|
error = copyin(uap->itv, &i32, sizeof(i32));
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
TV_CP(i32, itv, it_interval);
|
|
|
|
TV_CP(i32, itv, it_value);
|
|
|
|
itvp = &itv;
|
|
|
|
} else
|
|
|
|
itvp = NULL;
|
|
|
|
error = kern_setitimer(td, uap->which, itvp, &oitv);
|
|
|
|
if (error || uap->oitv == NULL)
|
2002-07-20 02:56:12 +00:00
|
|
|
return (error);
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
TV_CP(oitv, i32, it_interval);
|
|
|
|
TV_CP(oitv, i32, it_value);
|
|
|
|
return (copyout(&i32, uap->oitv, sizeof(i32)));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
2004-01-28 23:45:48 +00:00
|
|
|
int
|
|
|
|
freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
|
|
|
|
{
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
struct itimerval itv;
|
|
|
|
struct itimerval32 i32;
|
2004-01-28 23:45:48 +00:00
|
|
|
int error;
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
error = kern_getitimer(td, uap->which, &itv);
|
|
|
|
if (error || uap->itv == NULL)
|
2004-01-28 23:45:48 +00:00
|
|
|
return (error);
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
TV_CP(itv, i32, it_interval);
|
|
|
|
TV_CP(itv, i32, it_value);
|
|
|
|
return (copyout(&i32, uap->itv, sizeof(i32)));
|
2004-01-28 23:45:48 +00:00
|
|
|
}
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
struct timeval32 tv32;
|
|
|
|
struct timeval tv, *tvp;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
if (uap->tv != NULL) {
|
|
|
|
error = copyin(uap->tv, &tv32, sizeof(tv32));
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
CP(tv32, tv, tv_sec);
|
|
|
|
CP(tv32, tv, tv_usec);
|
|
|
|
tvp = &tv;
|
|
|
|
} else
|
|
|
|
tvp = NULL;
|
2002-07-20 02:56:12 +00:00
|
|
|
/*
|
|
|
|
* XXX big-endian needs to convert the fd_sets too.
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
* XXX Do pointers need PTRIN()?
|
2002-07-20 02:56:12 +00:00
|
|
|
*/
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
2003-05-14 04:10:49 +00:00
|
|
|
struct kevent32 {
|
|
|
|
u_int32_t ident; /* identifier for this event */
|
|
|
|
short filter; /* filter for event */
|
|
|
|
u_short flags;
|
|
|
|
u_int fflags;
|
|
|
|
int32_t data;
|
|
|
|
u_int32_t udata; /* opaque user data identifier */
|
|
|
|
};
|
|
|
|
|
2003-10-30 02:40:30 +00:00
|
|
|
CTASSERT(sizeof(struct kevent32) == 20);
|
2005-06-03 23:15:01 +00:00
|
|
|
static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
|
|
|
|
static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy 'count' items into the destination list pointed to by uap->eventlist.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
|
|
|
|
{
|
|
|
|
struct freebsd32_kevent_args *uap;
|
|
|
|
struct kevent32 ks32[KQ_NEVENTS];
|
|
|
|
int i, error = 0;
|
|
|
|
|
|
|
|
KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
|
|
|
|
uap = (struct freebsd32_kevent_args *)arg;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
CP(kevp[i], ks32[i], ident);
|
|
|
|
CP(kevp[i], ks32[i], filter);
|
|
|
|
CP(kevp[i], ks32[i], flags);
|
|
|
|
CP(kevp[i], ks32[i], fflags);
|
|
|
|
CP(kevp[i], ks32[i], data);
|
|
|
|
PTROUT_CP(kevp[i], ks32[i], udata);
|
|
|
|
}
|
|
|
|
error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
|
|
|
|
if (error == 0)
|
|
|
|
uap->eventlist += count;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy 'count' items from the list pointed to by uap->changelist.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
|
|
|
|
{
|
|
|
|
struct freebsd32_kevent_args *uap;
|
|
|
|
struct kevent32 ks32[KQ_NEVENTS];
|
|
|
|
int i, error = 0;
|
|
|
|
|
|
|
|
KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
|
|
|
|
uap = (struct freebsd32_kevent_args *)arg;
|
|
|
|
|
|
|
|
error = copyin(uap->changelist, ks32, count * sizeof *ks32);
|
|
|
|
if (error)
|
|
|
|
goto done;
|
|
|
|
uap->changelist += count;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
CP(ks32[i], kevp[i], ident);
|
|
|
|
CP(ks32[i], kevp[i], filter);
|
|
|
|
CP(ks32[i], kevp[i], flags);
|
|
|
|
CP(ks32[i], kevp[i], fflags);
|
|
|
|
CP(ks32[i], kevp[i], data);
|
|
|
|
PTRIN_CP(ks32[i], kevp[i], udata);
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
return (error);
|
|
|
|
}
|
2003-10-30 02:40:30 +00:00
|
|
|
|
2003-05-14 04:10:49 +00:00
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
|
2003-05-14 04:10:49 +00:00
|
|
|
{
|
|
|
|
struct timespec32 ts32;
|
2005-03-01 17:45:55 +00:00
|
|
|
struct timespec ts, *tsp;
|
2005-06-03 23:15:01 +00:00
|
|
|
struct kevent_copyops k_ops = { uap,
|
|
|
|
freebsd32_kevent_copyout,
|
|
|
|
freebsd32_kevent_copyin};
|
|
|
|
int error;
|
2003-05-14 04:10:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (uap->timeout) {
|
|
|
|
error = copyin(uap->timeout, &ts32, sizeof(ts32));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
CP(ts32, ts, tv_sec);
|
|
|
|
CP(ts32, ts, tv_nsec);
|
2005-03-01 17:45:55 +00:00
|
|
|
tsp = &ts;
|
|
|
|
} else
|
|
|
|
tsp = NULL;
|
2005-06-03 23:15:01 +00:00
|
|
|
error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
|
|
|
|
&k_ops, tsp);
|
2005-03-01 17:45:55 +00:00
|
|
|
return (error);
|
2003-05-14 04:10:49 +00:00
|
|
|
}
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_gettimeofday(struct thread *td,
|
|
|
|
struct freebsd32_gettimeofday_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2003-12-11 02:34:49 +00:00
|
|
|
struct timeval atv;
|
|
|
|
struct timeval32 atv32;
|
|
|
|
struct timezone rtz;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if (uap->tp) {
|
|
|
|
microtime(&atv);
|
|
|
|
CP(atv, atv32, tv_sec);
|
|
|
|
CP(atv, atv32, tv_usec);
|
|
|
|
error = copyout(&atv32, uap->tp, sizeof (atv32));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
2003-12-11 02:34:49 +00:00
|
|
|
if (error == 0 && uap->tzp != NULL) {
|
|
|
|
rtz.tz_minuteswest = tz_minuteswest;
|
|
|
|
rtz.tz_dsttime = tz_dsttime;
|
|
|
|
error = copyout(&rtz, uap->tzp, sizeof (rtz));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2004-10-05 18:51:11 +00:00
|
|
|
struct rusage32 s32;
|
|
|
|
struct rusage s;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
2004-10-05 18:51:11 +00:00
|
|
|
error = kern_getrusage(td, uap->who, &s);
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2004-10-05 18:51:11 +00:00
|
|
|
if (uap->rusage != NULL) {
|
2002-07-20 02:56:12 +00:00
|
|
|
TV_CP(s, s32, ru_utime);
|
|
|
|
TV_CP(s, s32, ru_stime);
|
|
|
|
CP(s, s32, ru_maxrss);
|
|
|
|
CP(s, s32, ru_ixrss);
|
|
|
|
CP(s, s32, ru_idrss);
|
|
|
|
CP(s, s32, ru_isrss);
|
|
|
|
CP(s, s32, ru_minflt);
|
|
|
|
CP(s, s32, ru_majflt);
|
|
|
|
CP(s, s32, ru_nswap);
|
|
|
|
CP(s, s32, ru_inblock);
|
|
|
|
CP(s, s32, ru_oublock);
|
|
|
|
CP(s, s32, ru_msgsnd);
|
|
|
|
CP(s, s32, ru_msgrcv);
|
|
|
|
CP(s, s32, ru_nsignals);
|
|
|
|
CP(s, s32, ru_nvcsw);
|
|
|
|
CP(s, s32, ru_nivcsw);
|
2004-10-05 18:51:11 +00:00
|
|
|
error = copyout(&s32, uap->rusage, sizeof(s32));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct iovec32 {
|
|
|
|
u_int32_t iov_base;
|
|
|
|
int iov_len;
|
|
|
|
};
|
|
|
|
|
2003-10-30 02:40:30 +00:00
|
|
|
CTASSERT(sizeof(struct iovec32) == 8);
|
|
|
|
|
2005-03-31 22:58:13 +00:00
|
|
|
static int
|
|
|
|
freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2005-03-31 22:58:13 +00:00
|
|
|
struct iovec32 iov32;
|
|
|
|
struct iovec *iov;
|
|
|
|
struct uio *uio;
|
|
|
|
u_int iovlen;
|
|
|
|
int error, i;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2005-03-31 22:58:13 +00:00
|
|
|
*uiop = NULL;
|
|
|
|
if (iovcnt > UIO_MAXIOV)
|
2002-07-20 02:56:12 +00:00
|
|
|
return (EINVAL);
|
2005-03-31 22:58:13 +00:00
|
|
|
iovlen = iovcnt * sizeof(struct iovec);
|
|
|
|
uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
|
|
|
|
iov = (struct iovec *)(uio + 1);
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
|
|
|
|
if (error) {
|
|
|
|
free(uio, M_IOV);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
iov[i].iov_base = PTRIN(iov32.iov_base);
|
|
|
|
iov[i].iov_len = iov32.iov_len;
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
2005-03-31 22:58:13 +00:00
|
|
|
uio->uio_iov = iov;
|
|
|
|
uio->uio_iovcnt = iovcnt;
|
|
|
|
uio->uio_segflg = UIO_USERSPACE;
|
|
|
|
uio->uio_offset = -1;
|
|
|
|
uio->uio_resid = 0;
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
if (iov->iov_len > INT_MAX - uio->uio_resid) {
|
|
|
|
free(uio, M_IOV);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
uio->uio_resid += iov->iov_len;
|
|
|
|
iov++;
|
|
|
|
}
|
|
|
|
*uiop = uio;
|
|
|
|
return (0);
|
|
|
|
}
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2005-03-31 22:58:13 +00:00
|
|
|
int
|
|
|
|
freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
|
|
|
|
{
|
|
|
|
struct uio *auio;
|
|
|
|
int error;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2005-03-31 22:58:13 +00:00
|
|
|
error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
error = kern_readv(td, uap->fd, auio);
|
|
|
|
free(auio, M_IOV);
|
2002-07-20 02:56:12 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2005-03-31 22:58:13 +00:00
|
|
|
struct uio *auio;
|
|
|
|
int error;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2005-03-31 22:58:13 +00:00
|
|
|
error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
error = kern_writev(td, uap->fd, auio);
|
|
|
|
free(auio, M_IOV);
|
2002-07-20 02:56:12 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_settimeofday(struct thread *td,
|
|
|
|
struct freebsd32_settimeofday_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2005-03-31 22:58:13 +00:00
|
|
|
struct timeval32 tv32;
|
|
|
|
struct timeval tv, *tvp;
|
|
|
|
struct timezone tz, *tzp;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
2005-03-31 22:58:13 +00:00
|
|
|
if (uap->tv) {
|
|
|
|
error = copyin(uap->tv, &tv32, sizeof(tv32));
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2005-03-31 22:58:13 +00:00
|
|
|
CP(tv32, tv, tv_sec);
|
|
|
|
CP(tv32, tv, tv_usec);
|
|
|
|
tvp = &tv;
|
|
|
|
} else
|
|
|
|
tvp = NULL;
|
|
|
|
if (uap->tzp) {
|
|
|
|
error = copyin(uap->tzp, &tz, sizeof(tz));
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2005-03-31 22:58:13 +00:00
|
|
|
tzp = &tz;
|
|
|
|
} else
|
|
|
|
tzp = NULL;
|
|
|
|
return (kern_settimeofday(td, tvp, tzp));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
struct timeval32 s32[2];
|
|
|
|
struct timeval s[2], *sp;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
if (uap->tptr != NULL) {
|
|
|
|
error = copyin(uap->tptr, s32, sizeof(s32));
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
CP(s32[0], s[0], tv_sec);
|
|
|
|
CP(s32[0], s[0], tv_usec);
|
|
|
|
CP(s32[1], s[1], tv_sec);
|
|
|
|
CP(s32[1], s[1], tv_usec);
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
sp = s;
|
|
|
|
} else
|
|
|
|
sp = NULL;
|
|
|
|
return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2005-03-31 22:58:13 +00:00
|
|
|
struct timeval32 tv32;
|
|
|
|
struct timeval delta, olddelta, *deltap;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
2005-03-31 22:58:13 +00:00
|
|
|
if (uap->delta) {
|
|
|
|
error = copyin(uap->delta, &tv32, sizeof(tv32));
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2005-03-31 22:58:13 +00:00
|
|
|
CP(tv32, delta, tv_sec);
|
|
|
|
CP(tv32, delta, tv_usec);
|
|
|
|
deltap = δ
|
|
|
|
} else
|
|
|
|
deltap = NULL;
|
|
|
|
error = kern_adjtime(td, deltap, &olddelta);
|
|
|
|
if (uap->olddelta && error == 0) {
|
|
|
|
CP(olddelta, tv32, tv_sec);
|
|
|
|
CP(olddelta, tv32, tv_usec);
|
|
|
|
error = copyout(&tv32, uap->olddelta, sizeof(tv32));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-04-24 04:31:59 +00:00
|
|
|
#ifdef COMPAT_FREEBSD4
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2004-04-14 23:17:37 +00:00
|
|
|
freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
struct statfs32 s32;
|
|
|
|
struct statfs s;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
copy_statfs(&s, &s32);
|
|
|
|
return (copyout(&s32, uap->buf, sizeof(s32)));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
2004-04-24 04:31:59 +00:00
|
|
|
#endif
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2004-04-24 04:31:59 +00:00
|
|
|
#ifdef COMPAT_FREEBSD4
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2004-04-14 23:17:37 +00:00
|
|
|
freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
struct statfs32 s32;
|
|
|
|
struct statfs s;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
error = kern_fstatfs(td, uap->fd, &s);
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
copy_statfs(&s, &s32);
|
|
|
|
return (copyout(&s32, uap->buf, sizeof(s32)));
|
2004-04-14 23:17:37 +00:00
|
|
|
}
|
2004-04-24 04:31:59 +00:00
|
|
|
#endif
|
2004-04-14 23:17:37 +00:00
|
|
|
|
2004-04-24 04:31:59 +00:00
|
|
|
#ifdef COMPAT_FREEBSD4
|
2004-04-14 23:17:37 +00:00
|
|
|
int
|
|
|
|
freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
|
|
|
|
{
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
struct statfs32 s32;
|
|
|
|
struct statfs s;
|
|
|
|
fhandle_t fh;
|
2004-04-14 23:17:37 +00:00
|
|
|
int error;
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
|
|
|
|
return (error);
|
|
|
|
error = kern_fhstatfs(td, fh, &s);
|
2004-04-14 23:17:37 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
copy_statfs(&s, &s32);
|
|
|
|
return (copyout(&s32, uap->buf, sizeof(s32)));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
2004-04-24 04:31:59 +00:00
|
|
|
#endif
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_semsys(struct thread *td, struct freebsd32_semsys_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Vector through to semsys if it is loaded.
|
|
|
|
*/
|
|
|
|
return sysent[169].sy_call(td, uap);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_msgsys(struct thread *td, struct freebsd32_msgsys_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Vector through to msgsys if it is loaded.
|
|
|
|
*/
|
|
|
|
return sysent[170].sy_call(td, uap);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_shmsys(struct thread *td, struct freebsd32_shmsys_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Vector through to shmsys if it is loaded.
|
|
|
|
*/
|
|
|
|
return sysent[171].sy_call(td, uap);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
struct pread_args ap;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.fd = uap->fd;
|
|
|
|
ap.buf = uap->buf;
|
|
|
|
ap.nbyte = uap->nbyte;
|
2003-08-22 23:07:28 +00:00
|
|
|
ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
|
2002-07-20 02:56:12 +00:00
|
|
|
return (pread(td, &ap));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
struct pwrite_args ap;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.fd = uap->fd;
|
|
|
|
ap.buf = uap->buf;
|
|
|
|
ap.nbyte = uap->nbyte;
|
2003-08-22 23:07:28 +00:00
|
|
|
ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
|
2002-07-20 02:56:12 +00:00
|
|
|
return (pwrite(td, &ap));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct lseek_args ap;
|
|
|
|
off_t pos;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.fd = uap->fd;
|
2003-08-22 23:07:28 +00:00
|
|
|
ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.whence = uap->whence;
|
2002-07-20 02:56:12 +00:00
|
|
|
error = lseek(td, &ap);
|
|
|
|
/* Expand the quad return into two parts for eax and edx */
|
|
|
|
pos = *(off_t *)(td->td_retval);
|
|
|
|
td->td_retval[0] = pos & 0xffffffff; /* %eax */
|
|
|
|
td->td_retval[1] = pos >> 32; /* %edx */
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
struct truncate_args ap;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.path = uap->path;
|
2003-08-22 23:07:28 +00:00
|
|
|
ap.length = (uap->lengthlo | ((off_t)uap->lengthhi << 32));
|
2002-07-20 02:56:12 +00:00
|
|
|
return (truncate(td, &ap));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
struct ftruncate_args ap;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.fd = uap->fd;
|
2003-08-22 23:07:28 +00:00
|
|
|
ap.length = (uap->lengthlo | ((off_t)uap->lengthhi << 32));
|
2002-07-20 02:56:12 +00:00
|
|
|
return (ftruncate(td, &ap));
|
|
|
|
}
|
|
|
|
|
2002-10-09 22:27:24 +00:00
|
|
|
#ifdef COMPAT_FREEBSD4
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd4_freebsd32_sendfile(struct thread *td,
|
|
|
|
struct freebsd4_freebsd32_sendfile_args *uap)
|
2002-10-09 22:27:24 +00:00
|
|
|
{
|
|
|
|
struct freebsd4_sendfile_args ap;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.fd = uap->fd;
|
|
|
|
ap.s = uap->s;
|
2003-08-22 23:07:28 +00:00
|
|
|
ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.nbytes = uap->nbytes; /* XXX check */
|
|
|
|
ap.hdtr = uap->hdtr; /* XXX check */
|
|
|
|
ap.sbytes = uap->sbytes; /* XXX FIXME!! */
|
|
|
|
ap.flags = uap->flags;
|
2002-10-09 22:27:24 +00:00
|
|
|
return (freebsd4_sendfile(td, &ap));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
struct sendfile_args ap;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.fd = uap->fd;
|
|
|
|
ap.s = uap->s;
|
2003-08-22 23:07:28 +00:00
|
|
|
ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
|
2002-12-14 01:56:26 +00:00
|
|
|
ap.nbytes = uap->nbytes; /* XXX check */
|
|
|
|
ap.hdtr = uap->hdtr; /* XXX check */
|
|
|
|
ap.sbytes = uap->sbytes; /* XXX FIXME!! */
|
|
|
|
ap.flags = uap->flags;
|
2002-07-20 02:56:12 +00:00
|
|
|
return (sendfile(td, &ap));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stat32 {
|
2004-06-17 17:16:53 +00:00
|
|
|
dev_t st_dev;
|
2002-07-20 02:56:12 +00:00
|
|
|
ino_t st_ino;
|
|
|
|
mode_t st_mode;
|
|
|
|
nlink_t st_nlink;
|
|
|
|
uid_t st_uid;
|
|
|
|
gid_t st_gid;
|
2004-06-17 17:16:53 +00:00
|
|
|
dev_t st_rdev;
|
2002-07-20 02:56:12 +00:00
|
|
|
struct timespec32 st_atimespec;
|
|
|
|
struct timespec32 st_mtimespec;
|
|
|
|
struct timespec32 st_ctimespec;
|
|
|
|
off_t st_size;
|
|
|
|
int64_t st_blocks;
|
|
|
|
u_int32_t st_blksize;
|
|
|
|
u_int32_t st_flags;
|
|
|
|
u_int32_t st_gen;
|
2003-10-30 02:40:30 +00:00
|
|
|
struct timespec32 st_birthtimespec;
|
|
|
|
unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32));
|
|
|
|
unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32));
|
2002-07-20 02:56:12 +00:00
|
|
|
};
|
|
|
|
|
2003-10-30 02:40:30 +00:00
|
|
|
|
|
|
|
CTASSERT(sizeof(struct stat32) == 96);
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
static void
|
|
|
|
copy_stat( struct stat *in, struct stat32 *out)
|
|
|
|
{
|
|
|
|
CP(*in, *out, st_dev);
|
|
|
|
CP(*in, *out, st_ino);
|
|
|
|
CP(*in, *out, st_mode);
|
|
|
|
CP(*in, *out, st_nlink);
|
|
|
|
CP(*in, *out, st_uid);
|
|
|
|
CP(*in, *out, st_gid);
|
|
|
|
CP(*in, *out, st_rdev);
|
|
|
|
TS_CP(*in, *out, st_atimespec);
|
|
|
|
TS_CP(*in, *out, st_mtimespec);
|
|
|
|
TS_CP(*in, *out, st_ctimespec);
|
|
|
|
CP(*in, *out, st_size);
|
|
|
|
CP(*in, *out, st_blocks);
|
|
|
|
CP(*in, *out, st_blksize);
|
|
|
|
CP(*in, *out, st_flags);
|
|
|
|
CP(*in, *out, st_gen);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2003-12-23 03:20:49 +00:00
|
|
|
struct stat sb;
|
|
|
|
struct stat32 sb32;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
|
|
|
|
error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2003-12-23 03:20:49 +00:00
|
|
|
copy_stat(&sb, &sb32);
|
|
|
|
error = copyout(&sb32, uap->ub, sizeof (sb32));
|
2002-07-20 02:56:12 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2003-12-23 03:20:49 +00:00
|
|
|
struct stat ub;
|
|
|
|
struct stat32 ub32;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
error = kern_fstat(td, uap->fd, &ub);
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2003-12-23 03:20:49 +00:00
|
|
|
copy_stat(&ub, &ub32);
|
|
|
|
error = copyout(&ub32, uap->ub, sizeof(ub32));
|
2002-07-20 02:56:12 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2003-12-23 03:20:49 +00:00
|
|
|
struct stat sb;
|
|
|
|
struct stat32 sb32;
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
int error;
|
2003-12-23 03:20:49 +00:00
|
|
|
|
- Add a custom version of exec_copyin_args() to deal with the 32-bit
pointers in argv and envv in userland and use that together with
kern_execve() and exec_free_args() to implement freebsd32_execve()
without using the stackgap.
- Fix freebsd32_adjtime() to call adjtime() rather than utimes(). Still
uses stackgap for now.
- Use kern_setitimer(), kern_getitimer(), kern_select(), kern_utimes(),
kern_statfs(), kern_fstatfs(), kern_fhstatfs(), kern_stat(),
kern_fstat(), and kern_lstat().
Tested by: cokane (amd64)
Silence on: amd64, ia64
2005-02-18 18:56:04 +00:00
|
|
|
error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2003-12-23 03:20:49 +00:00
|
|
|
copy_stat(&sb, &sb32);
|
|
|
|
error = copyout(&sb32, uap->ub, sizeof (sb32));
|
2002-07-20 02:56:12 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MPSAFE
|
|
|
|
*/
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
int error, name[CTL_MAXNAME];
|
|
|
|
size_t j, oldlen;
|
|
|
|
|
|
|
|
if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
|
|
|
|
return (EINVAL);
|
2004-10-11 22:04:16 +00:00
|
|
|
error = copyin(uap->name, name, uap->namelen * sizeof(int));
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
if (uap->oldlenp)
|
|
|
|
oldlen = fuword32(uap->oldlenp);
|
|
|
|
else
|
|
|
|
oldlen = 0;
|
|
|
|
error = userland_sysctl(td, name, uap->namelen,
|
|
|
|
uap->old, &oldlen, 1,
|
2004-10-11 22:04:16 +00:00
|
|
|
uap->new, uap->newlen, &j, SCTL_MASK32);
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error && error != ENOMEM)
|
|
|
|
goto done2;
|
2004-10-11 22:04:16 +00:00
|
|
|
if (uap->oldlenp)
|
2002-07-20 02:56:12 +00:00
|
|
|
suword32(uap->oldlenp, j);
|
|
|
|
done2:
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sigaction32 {
|
|
|
|
u_int32_t sa_u;
|
|
|
|
int sa_flags;
|
|
|
|
sigset_t sa_mask;
|
|
|
|
};
|
|
|
|
|
2003-10-30 02:40:30 +00:00
|
|
|
CTASSERT(sizeof(struct sigaction32) == 24);
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2003-04-22 18:23:49 +00:00
|
|
|
struct sigaction32 s32;
|
|
|
|
struct sigaction sa, osa, *sap;
|
2002-07-20 02:56:12 +00:00
|
|
|
int error;
|
|
|
|
|
2003-04-22 18:23:49 +00:00
|
|
|
if (uap->act) {
|
|
|
|
error = copyin(uap->act, &s32, sizeof(s32));
|
2002-07-20 02:56:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2003-04-22 18:23:49 +00:00
|
|
|
sa.sa_handler = PTRIN(s32.sa_u);
|
|
|
|
CP(s32, sa, sa_flags);
|
|
|
|
CP(s32, sa, sa_mask);
|
|
|
|
sap = &sa;
|
|
|
|
} else
|
|
|
|
sap = NULL;
|
|
|
|
error = kern_sigaction(td, uap->sig, sap, &osa, 0);
|
2005-05-24 17:52:14 +00:00
|
|
|
if (error == 0 && uap->oact != NULL) {
|
2003-04-22 18:23:49 +00:00
|
|
|
s32.sa_u = PTROUT(osa.sa_handler);
|
|
|
|
CP(osa, s32, sa_flags);
|
|
|
|
CP(osa, s32, sa_mask);
|
|
|
|
error = copyout(&s32, uap->oact, sizeof(s32));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2003-05-14 04:10:49 +00:00
|
|
|
#ifdef COMPAT_FREEBSD4
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd4_freebsd32_sigaction(struct thread *td,
|
|
|
|
struct freebsd4_freebsd32_sigaction_args *uap)
|
2003-05-14 04:10:49 +00:00
|
|
|
{
|
|
|
|
struct sigaction32 s32;
|
|
|
|
struct sigaction sa, osa, *sap;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (uap->act) {
|
|
|
|
error = copyin(uap->act, &s32, sizeof(s32));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
sa.sa_handler = PTRIN(s32.sa_u);
|
|
|
|
CP(s32, sa, sa_flags);
|
|
|
|
CP(s32, sa, sa_mask);
|
|
|
|
sap = &sa;
|
|
|
|
} else
|
|
|
|
sap = NULL;
|
|
|
|
error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
|
2005-05-24 17:52:14 +00:00
|
|
|
if (error == 0 && uap->oact != NULL) {
|
2003-05-14 04:10:49 +00:00
|
|
|
s32.sa_u = PTROUT(osa.sa_handler);
|
|
|
|
CP(osa, s32, sa_flags);
|
|
|
|
CP(osa, s32, sa_mask);
|
|
|
|
error = copyout(&s32, uap->oact, sizeof(s32));
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-01-19 17:44:59 +00:00
|
|
|
int
|
|
|
|
freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
|
|
|
|
{
|
|
|
|
struct timespec32 rmt32, rqt32;
|
|
|
|
struct timespec rmt, rqt;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = copyin(uap->rqtp, &rqt32, sizeof(rqt));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
CP(rqt32, rqt, tv_sec);
|
|
|
|
CP(rqt32, rqt, tv_nsec);
|
|
|
|
|
|
|
|
if (uap->rmtp &&
|
|
|
|
!useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
|
|
|
|
return (EFAULT);
|
|
|
|
error = kern_nanosleep(td, &rqt, &rmt);
|
|
|
|
if (error && uap->rmtp) {
|
|
|
|
int error2;
|
|
|
|
|
|
|
|
CP(rmt, rmt32, tv_sec);
|
|
|
|
CP(rmt, rmt32, tv_nsec);
|
|
|
|
|
|
|
|
error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt));
|
|
|
|
if (error2)
|
|
|
|
error = error2;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
#if 0
|
|
|
|
|
|
|
|
int
|
2003-08-22 23:07:28 +00:00
|
|
|
freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
caddr_t sg;
|
|
|
|
struct yyy32 *p32, s32;
|
|
|
|
struct yyy *p = NULL, s;
|
|
|
|
|
2002-12-14 01:56:26 +00:00
|
|
|
p32 = uap->zzz;
|
2002-07-20 02:56:12 +00:00
|
|
|
if (p32) {
|
|
|
|
sg = stackgap_init();
|
|
|
|
p = stackgap_alloc(&sg, sizeof(struct yyy));
|
2002-12-14 01:56:26 +00:00
|
|
|
uap->zzz = (struct yyy32 *)p;
|
2002-07-20 02:56:12 +00:00
|
|
|
error = copyin(p32, &s32, sizeof(s32));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
/* translate in */
|
|
|
|
error = copyout(&s, p, sizeof(s));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = xxx(td, (struct xxx_args *) uap);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
if (p32) {
|
|
|
|
error = copyin(p, &s, sizeof(s));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
/* translate out */
|
|
|
|
error = copyout(&s32, p32, sizeof(s32));
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|