split up netbsd32_netbsd.c into 9 new files, leaving only those syscalls that
have no special interpretations besides simple syscall args conversion.
This commit is contained in:
parent
128dae5e7b
commit
da9e4bd3a1
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: files.netbsd32,v 1.8 2001/02/07 13:13:01 mrg Exp $
|
||||
# $NetBSD: files.netbsd32,v 1.9 2001/02/08 13:19:33 mrg Exp $
|
||||
#
|
||||
# config file description for machine-independent netbsd32 compat code.
|
||||
# included by ports that need it.
|
||||
|
@ -9,7 +9,16 @@
|
|||
file compat/netbsd32/netbsd32_exec_elf32.c compat_netbsd32 & exec_elf32
|
||||
file compat/netbsd32/netbsd32_exec_aout.c compat_netbsd32 & exec_aout
|
||||
file compat/netbsd32/netbsd32_netbsd.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_execve.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_fs.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_ioctl.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_ipc.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_select.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_signal.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_socket.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_sysctl.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_time.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_wait.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_sysent.c compat_netbsd32
|
||||
file compat/netbsd32/netbsd32_compat_09.c compat_netbsd32 & (compat_09 | compat_sunos)
|
||||
file compat/netbsd32/netbsd32_compat_10.c compat_netbsd32 & compat_10
|
||||
|
|
|
@ -0,0 +1,491 @@
|
|||
/* $NetBSD: netbsd32_execve.c,v 1.1 2001/02/08 13:19:33 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
#if defined(_KERNEL) && !defined(_LKM)
|
||||
#include "opt_ktrace.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ktrace.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/namei.h>
|
||||
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
||||
#include <sys/syscallargs.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/acct.h>
|
||||
#include <sys/exec.h>
|
||||
|
||||
#include <compat/netbsd32/netbsd32.h>
|
||||
#include <compat/netbsd32/netbsd32_syscall.h>
|
||||
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
||||
|
||||
/* this is provided by kern/kern_exec.c */
|
||||
extern int exec_maxhdrsz;
|
||||
extern struct lock exec_lock;
|
||||
|
||||
/*
|
||||
* Need to completly reimplement this syscall due to argument copying.
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
netbsd32_execve(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_execve_args /* {
|
||||
syscallarg(const netbsd32_charp) path;
|
||||
syscallarg(netbsd32_charpp) argp;
|
||||
syscallarg(netbsd32_charpp) envp;
|
||||
} */ *uap = v;
|
||||
struct sys_execve_args ua;
|
||||
caddr_t sg;
|
||||
|
||||
NETBSD32TOP_UAP(path, const char);
|
||||
NETBSD32TOP_UAP(argp, char *);
|
||||
NETBSD32TOP_UAP(envp, char *);
|
||||
sg = stackgap_init(p->p_emul);
|
||||
CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
|
||||
|
||||
return netbsd32_execve2(p, &ua, retval);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_execve2(p, uap, retval)
|
||||
struct proc *p;
|
||||
struct sys_execve_args *uap;
|
||||
register_t *retval;
|
||||
{
|
||||
/* Function args */
|
||||
int error, i;
|
||||
struct exec_package pack;
|
||||
struct nameidata nid;
|
||||
struct vattr attr;
|
||||
struct ucred *cred = p->p_ucred;
|
||||
char *argp;
|
||||
netbsd32_charp const *cpp;
|
||||
char *dp;
|
||||
netbsd32_charp sp;
|
||||
long argc, envc;
|
||||
size_t len;
|
||||
char *stack;
|
||||
struct ps_strings arginfo;
|
||||
struct vmspace *vm;
|
||||
char **tmpfap;
|
||||
int szsigcode;
|
||||
struct exec_vmcmd *base_vcp = NULL;
|
||||
|
||||
/*
|
||||
* Init the namei data to point the file user's program name.
|
||||
* This is done here rather than in check_exec(), so that it's
|
||||
* possible to override this settings if any of makecmd/probe
|
||||
* functions call check_exec() recursively - for example,
|
||||
* see exec_script_makecmds().
|
||||
*/
|
||||
NDINIT(&nid, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
|
||||
|
||||
/*
|
||||
* initialize the fields of the exec package.
|
||||
*/
|
||||
pack.ep_name = SCARG(uap, path);
|
||||
pack.ep_hdr = malloc(exec_maxhdrsz, M_EXEC, M_WAITOK);
|
||||
pack.ep_hdrlen = exec_maxhdrsz;
|
||||
pack.ep_hdrvalid = 0;
|
||||
pack.ep_ndp = &nid;
|
||||
pack.ep_emul_arg = NULL;
|
||||
pack.ep_vmcmds.evs_cnt = 0;
|
||||
pack.ep_vmcmds.evs_used = 0;
|
||||
pack.ep_vap = &attr;
|
||||
pack.ep_flags = 0;
|
||||
|
||||
lockmgr(&exec_lock, LK_SHARED, NULL);
|
||||
|
||||
/* see if we can run it. */
|
||||
if ((error = check_exec(p, &pack)) != 0)
|
||||
goto freehdr;
|
||||
|
||||
/* XXX -- THE FOLLOWING SECTION NEEDS MAJOR CLEANUP */
|
||||
|
||||
/* allocate an argument buffer */
|
||||
argp = (char *) uvm_km_valloc_wait(exec_map, NCARGS);
|
||||
#ifdef DIAGNOSTIC
|
||||
if (argp == (vaddr_t) 0)
|
||||
panic("netbsd32_execve: argp == NULL");
|
||||
#endif
|
||||
dp = argp;
|
||||
argc = 0;
|
||||
|
||||
/* copy the fake args list, if there's one, freeing it as we go */
|
||||
if (pack.ep_flags & EXEC_HASARGL) {
|
||||
tmpfap = pack.ep_fa;
|
||||
while (*tmpfap != NULL) {
|
||||
char *cp;
|
||||
|
||||
cp = *tmpfap;
|
||||
while (*cp)
|
||||
*dp++ = *cp++;
|
||||
dp++;
|
||||
|
||||
FREE(*tmpfap, M_EXEC);
|
||||
tmpfap++; argc++;
|
||||
}
|
||||
FREE(pack.ep_fa, M_EXEC);
|
||||
pack.ep_flags &= ~EXEC_HASARGL;
|
||||
}
|
||||
|
||||
/* Now get argv & environment */
|
||||
if (!(cpp = (netbsd32_charp *)SCARG(uap, argp))) {
|
||||
error = EINVAL;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (pack.ep_flags & EXEC_SKIPARG)
|
||||
cpp++;
|
||||
|
||||
while (1) {
|
||||
len = argp + ARG_MAX - dp;
|
||||
if ((error = copyin(cpp, &sp, sizeof(sp))) != 0)
|
||||
goto bad;
|
||||
if (!sp)
|
||||
break;
|
||||
if ((error = copyinstr((char *)(u_long)sp, dp,
|
||||
len, &len)) != 0) {
|
||||
if (error == ENAMETOOLONG)
|
||||
error = E2BIG;
|
||||
goto bad;
|
||||
}
|
||||
dp += len;
|
||||
cpp++;
|
||||
argc++;
|
||||
}
|
||||
|
||||
envc = 0;
|
||||
/* environment need not be there */
|
||||
if ((cpp = (netbsd32_charp *)SCARG(uap, envp)) != NULL ) {
|
||||
while (1) {
|
||||
len = argp + ARG_MAX - dp;
|
||||
if ((error = copyin(cpp, &sp, sizeof(sp))) != 0)
|
||||
goto bad;
|
||||
if (!sp)
|
||||
break;
|
||||
if ((error = copyinstr((char *)(u_long)sp,
|
||||
dp, len, &len)) != 0) {
|
||||
if (error == ENAMETOOLONG)
|
||||
error = E2BIG;
|
||||
goto bad;
|
||||
}
|
||||
dp += len;
|
||||
cpp++;
|
||||
envc++;
|
||||
}
|
||||
}
|
||||
|
||||
dp = (char *) ALIGN(dp);
|
||||
|
||||
szsigcode = pack.ep_es->es_emul->e_esigcode -
|
||||
pack.ep_es->es_emul->e_sigcode;
|
||||
|
||||
/* Now check if args & environ fit into new stack */
|
||||
if (pack.ep_flags & EXEC_32)
|
||||
len = ((argc + envc + 2 + pack.ep_es->es_arglen) *
|
||||
sizeof(int) + sizeof(int) + dp + STACKGAPLEN +
|
||||
szsigcode + sizeof(struct ps_strings)) - argp;
|
||||
else
|
||||
len = ((argc + envc + 2 + pack.ep_es->es_arglen) *
|
||||
sizeof(char *) + sizeof(int) + dp + STACKGAPLEN +
|
||||
szsigcode + sizeof(struct ps_strings)) - argp;
|
||||
|
||||
len = ALIGN(len); /* make the stack "safely" aligned */
|
||||
|
||||
if (len > pack.ep_ssize) { /* in effect, compare to initial limit */
|
||||
error = ENOMEM;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/* adjust "active stack depth" for process VSZ */
|
||||
pack.ep_ssize = len; /* maybe should go elsewhere, but... */
|
||||
|
||||
/*
|
||||
* Do whatever is necessary to prepare the address space
|
||||
* for remapping. Note that this might replace the current
|
||||
* vmspace with another!
|
||||
*/
|
||||
uvmspace_exec(p, VM_MIN_ADDRESS, (vaddr_t)pack.ep_minsaddr);
|
||||
|
||||
/* Now map address space */
|
||||
vm = p->p_vmspace;
|
||||
vm->vm_taddr = (char *) pack.ep_taddr;
|
||||
vm->vm_tsize = btoc(pack.ep_tsize);
|
||||
vm->vm_daddr = (char *) pack.ep_daddr;
|
||||
vm->vm_dsize = btoc(pack.ep_dsize);
|
||||
vm->vm_ssize = btoc(pack.ep_ssize);
|
||||
vm->vm_maxsaddr = (char *) pack.ep_maxsaddr;
|
||||
vm->vm_minsaddr = (char *) pack.ep_minsaddr;
|
||||
|
||||
/* create the new process's VM space by running the vmcmds */
|
||||
#ifdef DIAGNOSTIC
|
||||
if (pack.ep_vmcmds.evs_used == 0)
|
||||
panic("netbsd32_execve: no vmcmds");
|
||||
#endif
|
||||
for (i = 0; i < pack.ep_vmcmds.evs_used && !error; i++) {
|
||||
struct exec_vmcmd *vcp;
|
||||
|
||||
vcp = &pack.ep_vmcmds.evs_cmds[i];
|
||||
if (vcp->ev_flags & VMCMD_RELATIVE) {
|
||||
#ifdef DIAGNOSTIC
|
||||
if (base_vcp == NULL)
|
||||
panic("netbsd32_execve: relative vmcmd with no base");
|
||||
if (vcp->ev_flags & VMCMD_BASE)
|
||||
panic("netbsd32_execve: illegal base & relative vmcmd");
|
||||
#endif
|
||||
vcp->ev_addr += base_vcp->ev_addr;
|
||||
}
|
||||
error = (*vcp->ev_proc)(p, vcp);
|
||||
#ifdef DEBUG
|
||||
if (error) {
|
||||
if (i > 0)
|
||||
printf("vmcmd[%d] = %#lx/%#lx @ %#lx\n", i-1,
|
||||
vcp[-1].ev_addr, vcp[-1].ev_len,
|
||||
vcp[-1].ev_offset);
|
||||
printf("vmcmd[%d] = %#lx/%#lx @ %#lx\n", i,
|
||||
vcp->ev_addr, vcp->ev_len, vcp->ev_offset);
|
||||
}
|
||||
#endif
|
||||
if (vcp->ev_flags & VMCMD_BASE)
|
||||
base_vcp = vcp;
|
||||
}
|
||||
|
||||
/* free the vmspace-creation commands, and release their references */
|
||||
kill_vmcmds(&pack.ep_vmcmds);
|
||||
|
||||
/* if an error happened, deallocate and punt */
|
||||
if (error) {
|
||||
#ifdef DEBUG
|
||||
printf("netbsd32_execve: vmcmd %i failed: %d\n", i-1, error);
|
||||
#endif
|
||||
goto exec_abort;
|
||||
}
|
||||
|
||||
/* remember information about the process */
|
||||
arginfo.ps_nargvstr = argc;
|
||||
arginfo.ps_nenvstr = envc;
|
||||
|
||||
stack = (char *) (vm->vm_minsaddr - len);
|
||||
/* Now copy argc, args & environ to new stack */
|
||||
if (!(*pack.ep_es->es_copyargs)(&pack, &arginfo, stack, argp)) {
|
||||
#ifdef DEBUG
|
||||
printf("netbsd32_execve: copyargs failed\n");
|
||||
#endif
|
||||
goto exec_abort;
|
||||
}
|
||||
|
||||
/* fill process ps_strings info */
|
||||
p->p_psstr = (struct ps_strings *)(stack - sizeof(struct ps_strings));
|
||||
p->p_psargv = offsetof(struct ps_strings, ps_argvstr);
|
||||
p->p_psnargv = offsetof(struct ps_strings, ps_nargvstr);
|
||||
p->p_psenv = offsetof(struct ps_strings, ps_envstr);
|
||||
p->p_psnenv = offsetof(struct ps_strings, ps_nenvstr);
|
||||
|
||||
/* copy out the process's ps_strings structure */
|
||||
if (copyout(&arginfo, (char *)p->p_psstr, sizeof(arginfo))) {
|
||||
#ifdef DEBUG
|
||||
printf("netbsd32_execve: ps_strings copyout failed\n");
|
||||
#endif
|
||||
goto exec_abort;
|
||||
}
|
||||
|
||||
/* copy out the process's signal trapoline code */
|
||||
if (szsigcode) {
|
||||
if (copyout((char *)pack.ep_es->es_emul->e_sigcode,
|
||||
p->p_sigctx.ps_sigcode = (char *)p->p_psstr - szsigcode,
|
||||
szsigcode)) {
|
||||
#ifdef DEBUG
|
||||
printf("netbsd32_execve: sig trampoline copyout failed\n");
|
||||
#endif
|
||||
goto exec_abort;
|
||||
}
|
||||
#ifdef PMAP_NEED_PROCWR
|
||||
/* This is code. Let the pmap do what is needed. */
|
||||
pmap_procwr(p, (vaddr_t)p->p_sigacts->ps_sigcode, szsigcode);
|
||||
#endif
|
||||
}
|
||||
|
||||
stopprofclock(p); /* stop profiling */
|
||||
fdcloseexec(p); /* handle close on exec */
|
||||
execsigs(p); /* reset catched signals */
|
||||
p->p_ctxlink = NULL; /* reset ucontext link */
|
||||
|
||||
/* set command name & other accounting info */
|
||||
len = min(nid.ni_cnd.cn_namelen, MAXCOMLEN);
|
||||
memcpy(p->p_comm, nid.ni_cnd.cn_nameptr, len);
|
||||
p->p_comm[len] = 0;
|
||||
p->p_acflag &= ~AFORK;
|
||||
|
||||
/* record proc's vnode, for use by procfs and others */
|
||||
if (p->p_textvp)
|
||||
vrele(p->p_textvp);
|
||||
VREF(pack.ep_vp);
|
||||
p->p_textvp = pack.ep_vp;
|
||||
|
||||
p->p_flag |= P_EXEC;
|
||||
if (p->p_flag & P_PPWAIT) {
|
||||
p->p_flag &= ~P_PPWAIT;
|
||||
wakeup((caddr_t) p->p_pptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* deal with set[ug]id.
|
||||
* MNT_NOSUID and P_TRACED have already been used to disable s[ug]id.
|
||||
*/
|
||||
if (((attr.va_mode & S_ISUID) != 0 && p->p_ucred->cr_uid != attr.va_uid)
|
||||
|| ((attr.va_mode & S_ISGID) != 0 && p->p_ucred->cr_gid != attr.va_gid)){
|
||||
p->p_ucred = crcopy(cred);
|
||||
#ifdef KTRACE
|
||||
/*
|
||||
* If process is being ktraced, turn off - unless
|
||||
* root set it.
|
||||
*/
|
||||
if (p->p_tracep && !(p->p_traceflag & KTRFAC_ROOT))
|
||||
ktrderef(p);
|
||||
#endif
|
||||
if (attr.va_mode & S_ISUID)
|
||||
p->p_ucred->cr_uid = attr.va_uid;
|
||||
if (attr.va_mode & S_ISGID)
|
||||
p->p_ucred->cr_gid = attr.va_gid;
|
||||
p_sugid(p);
|
||||
} else
|
||||
p->p_flag &= ~P_SUGID;
|
||||
p->p_cred->p_svuid = p->p_ucred->cr_uid;
|
||||
p->p_cred->p_svgid = p->p_ucred->cr_gid;
|
||||
|
||||
doexechooks(p);
|
||||
|
||||
uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
|
||||
|
||||
PNBUF_PUT(nid.ni_cnd.cn_pnbuf);
|
||||
vn_lock(pack.ep_vp, LK_EXCLUSIVE | LK_RETRY);
|
||||
VOP_CLOSE(pack.ep_vp, FREAD, cred, p);
|
||||
vput(pack.ep_vp);
|
||||
|
||||
/* setup new registers and do misc. setup. */
|
||||
(*pack.ep_es->es_setregs)(p, &pack, (u_long) stack);
|
||||
|
||||
if (p->p_flag & P_TRACED)
|
||||
psignal(p, SIGTRAP);
|
||||
|
||||
free(pack.ep_hdr, M_EXEC);
|
||||
|
||||
/*
|
||||
* Call emulation specific exec hook. This can setup setup per-process
|
||||
* p->p_emuldata or do any other per-process stuff an emulation needs.
|
||||
*
|
||||
* If we are executing process of different emulation than the
|
||||
* original forked process, call e_proc_exit() of the old emulation
|
||||
* first, then e_proc_exec() of new emulation. If the emulation is
|
||||
* same, the exec hook code should deallocate any old emulation
|
||||
* resources held previously by this process.
|
||||
*/
|
||||
if (p->p_emul && p->p_emul->e_proc_exit
|
||||
&& p->p_emul != pack.ep_es->es_emul)
|
||||
(*p->p_emul->e_proc_exit)(p);
|
||||
|
||||
/*
|
||||
* Call exec hook. Emulation code may NOT store reference to anything
|
||||
* from &pack.
|
||||
*/
|
||||
if (pack.ep_es->es_emul->e_proc_exec)
|
||||
(*pack.ep_es->es_emul->e_proc_exec)(p, &pack);
|
||||
|
||||
/* update p_emul, the old value is no longer needed */
|
||||
p->p_emul = pack.ep_es->es_emul;
|
||||
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(p, KTR_EMUL))
|
||||
ktremul(p);
|
||||
#endif
|
||||
|
||||
lockmgr(&exec_lock, LK_RELEASE, NULL);
|
||||
|
||||
return (EJUSTRETURN);
|
||||
|
||||
bad:
|
||||
/* free the vmspace-creation commands, and release their references */
|
||||
kill_vmcmds(&pack.ep_vmcmds);
|
||||
/* kill any opened file descriptor, if necessary */
|
||||
if (pack.ep_flags & EXEC_HASFD) {
|
||||
pack.ep_flags &= ~EXEC_HASFD;
|
||||
(void) fdrelease(p, pack.ep_fd);
|
||||
}
|
||||
/* close and put the exec'd file */
|
||||
vn_lock(pack.ep_vp, LK_EXCLUSIVE | LK_RETRY);
|
||||
VOP_CLOSE(pack.ep_vp, FREAD, cred, p);
|
||||
vput(pack.ep_vp);
|
||||
PNBUF_PUT(nid.ni_cnd.cn_pnbuf);
|
||||
uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
|
||||
|
||||
freehdr:
|
||||
lockmgr(&exec_lock, LK_RELEASE, NULL);
|
||||
|
||||
free(pack.ep_hdr, M_EXEC);
|
||||
return error;
|
||||
|
||||
exec_abort:
|
||||
lockmgr(&exec_lock, LK_RELEASE, NULL);
|
||||
|
||||
/*
|
||||
* the old process doesn't exist anymore. exit gracefully.
|
||||
* get rid of the (new) address space we have created, if any, get rid
|
||||
* of our namei data and vnode, and exit noting failure
|
||||
*/
|
||||
uvm_deallocate(&vm->vm_map, VM_MIN_ADDRESS,
|
||||
VM_MAXUSER_ADDRESS - VM_MIN_ADDRESS);
|
||||
if (pack.ep_emul_arg)
|
||||
FREE(pack.ep_emul_arg, M_TEMP);
|
||||
PNBUF_PUT(nid.ni_cnd.cn_pnbuf);
|
||||
vn_lock(pack.ep_vp, LK_EXCLUSIVE | LK_RETRY);
|
||||
VOP_CLOSE(pack.ep_vp, FREAD, cred, p);
|
||||
vput(pack.ep_vp);
|
||||
uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
|
||||
free(pack.ep_hdr, M_EXEC);
|
||||
exit1(p, W_EXITCODE(0, SIGABRT));
|
||||
exit1(p, -1);
|
||||
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,799 @@
|
|||
/* $NetBSD: netbsd32_fs.c,v 1.1 2001/02/08 13:19:33 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
#if defined(_KERNEL) && !defined(_LKM)
|
||||
#include "opt_ktrace.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ktrace.h>
|
||||
#include <sys/resourcevar.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/namei.h>
|
||||
#include <sys/syscallargs.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <compat/netbsd32/netbsd32.h>
|
||||
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
||||
#include <compat/netbsd32/netbsd32_conv.h>
|
||||
|
||||
|
||||
static int dofilereadv32 __P((struct proc *, int, struct file *, struct netbsd32_iovec *,
|
||||
int, off_t *, int, register_t *));
|
||||
static int dofilewritev32 __P((struct proc *, int, struct file *, struct netbsd32_iovec *,
|
||||
int, off_t *, int, register_t *));
|
||||
static int change_utimes32 __P((struct vnode *, netbsd32_timevalp_t, struct proc *));
|
||||
|
||||
int
|
||||
netbsd32_getfsstat(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_getfsstat_args /* {
|
||||
syscallarg(netbsd32_statfsp_t) buf;
|
||||
syscallarg(netbsd32_long) bufsize;
|
||||
syscallarg(int) flags;
|
||||
} */ *uap = v;
|
||||
struct mount *mp, *nmp;
|
||||
struct statfs *sp;
|
||||
struct netbsd32_statfs sb32;
|
||||
caddr_t sfsp;
|
||||
long count, maxcount, error;
|
||||
|
||||
maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statfs);
|
||||
sfsp = (caddr_t)(u_long)SCARG(uap, buf);
|
||||
simple_lock(&mountlist_slock);
|
||||
count = 0;
|
||||
for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
|
||||
nmp = mp->mnt_list.cqe_next;
|
||||
continue;
|
||||
}
|
||||
if (sfsp && count < maxcount) {
|
||||
sp = &mp->mnt_stat;
|
||||
/*
|
||||
* If MNT_NOWAIT or MNT_LAZY is specified, do not
|
||||
* refresh the fsstat cache. MNT_WAIT or MNT_LAXY
|
||||
* overrides MNT_NOWAIT.
|
||||
*/
|
||||
if (SCARG(uap, flags) != MNT_NOWAIT &&
|
||||
SCARG(uap, flags) != MNT_LAZY &&
|
||||
(SCARG(uap, flags) == MNT_WAIT ||
|
||||
SCARG(uap, flags) == 0) &&
|
||||
(error = VFS_STATFS(mp, sp, p)) != 0) {
|
||||
simple_lock(&mountlist_slock);
|
||||
nmp = mp->mnt_list.cqe_next;
|
||||
vfs_unbusy(mp);
|
||||
continue;
|
||||
}
|
||||
sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
|
||||
sp->f_oflags = sp->f_flags & 0xffff;
|
||||
netbsd32_from_statfs(sp, &sb32);
|
||||
error = copyout(&sb32, sfsp, sizeof(sb32));
|
||||
if (error) {
|
||||
vfs_unbusy(mp);
|
||||
return (error);
|
||||
}
|
||||
sfsp += sizeof(sb32);
|
||||
}
|
||||
count++;
|
||||
simple_lock(&mountlist_slock);
|
||||
nmp = mp->mnt_list.cqe_next;
|
||||
vfs_unbusy(mp);
|
||||
}
|
||||
simple_unlock(&mountlist_slock);
|
||||
if (sfsp && count > maxcount)
|
||||
*retval = maxcount;
|
||||
else
|
||||
*retval = count;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_readv(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_readv_args /* {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(const netbsd32_iovecp_t) iovp;
|
||||
syscallarg(int) iovcnt;
|
||||
} */ *uap = v;
|
||||
int fd = SCARG(uap, fd);
|
||||
struct file *fp;
|
||||
struct filedesc *fdp = p->p_fd;
|
||||
|
||||
if ((u_int)fd >= fdp->fd_nfiles ||
|
||||
(fp = fdp->fd_ofiles[fd]) == NULL ||
|
||||
(fp->f_flag & FREAD) == 0)
|
||||
return (EBADF);
|
||||
|
||||
return (dofilereadv32(p, fd, fp, (struct netbsd32_iovec *)(u_long)SCARG(uap, iovp),
|
||||
SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
|
||||
}
|
||||
|
||||
/* Damn thing copies in the iovec! */
|
||||
int
|
||||
dofilereadv32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
|
||||
struct proc *p;
|
||||
int fd;
|
||||
struct file *fp;
|
||||
struct netbsd32_iovec *iovp;
|
||||
int iovcnt;
|
||||
off_t *offset;
|
||||
int flags;
|
||||
register_t *retval;
|
||||
{
|
||||
struct uio auio;
|
||||
struct iovec *iov;
|
||||
struct iovec *needfree;
|
||||
struct iovec aiov[UIO_SMALLIOV];
|
||||
long i, cnt, error = 0;
|
||||
u_int iovlen;
|
||||
#ifdef KTRACE
|
||||
struct iovec *ktriov = NULL;
|
||||
#endif
|
||||
|
||||
/* note: can't use iovlen until iovcnt is validated */
|
||||
iovlen = iovcnt * sizeof(struct iovec);
|
||||
if ((u_int)iovcnt > UIO_SMALLIOV) {
|
||||
if ((u_int)iovcnt > IOV_MAX)
|
||||
return (EINVAL);
|
||||
MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK);
|
||||
needfree = iov;
|
||||
} else if ((u_int)iovcnt > 0) {
|
||||
iov = aiov;
|
||||
needfree = NULL;
|
||||
} else
|
||||
return (EINVAL);
|
||||
|
||||
auio.uio_iov = iov;
|
||||
auio.uio_iovcnt = iovcnt;
|
||||
auio.uio_rw = UIO_READ;
|
||||
auio.uio_segflg = UIO_USERSPACE;
|
||||
auio.uio_procp = p;
|
||||
error = netbsd32_to_iovecin(iovp, iov, iovcnt);
|
||||
if (error)
|
||||
goto done;
|
||||
auio.uio_resid = 0;
|
||||
for (i = 0; i < iovcnt; i++) {
|
||||
auio.uio_resid += iov->iov_len;
|
||||
/*
|
||||
* Reads return ssize_t because -1 is returned on error.
|
||||
* Therefore we must restrict the length to SSIZE_MAX to
|
||||
* avoid garbage return values.
|
||||
*/
|
||||
if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
|
||||
error = EINVAL;
|
||||
goto done;
|
||||
}
|
||||
iov++;
|
||||
}
|
||||
#ifdef KTRACE
|
||||
/*
|
||||
* if tracing, save a copy of iovec
|
||||
*/
|
||||
if (KTRPOINT(p, KTR_GENIO)) {
|
||||
MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
|
||||
memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
|
||||
}
|
||||
#endif
|
||||
cnt = auio.uio_resid;
|
||||
error = (*fp->f_ops->fo_read)(fp, offset, &auio, fp->f_cred, flags);
|
||||
if (error)
|
||||
if (auio.uio_resid != cnt && (error == ERESTART ||
|
||||
error == EINTR || error == EWOULDBLOCK))
|
||||
error = 0;
|
||||
cnt -= auio.uio_resid;
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(p, KTR_GENIO))
|
||||
if (error == 0) {
|
||||
ktrgenio(p, fd, UIO_READ, ktriov, cnt,
|
||||
error);
|
||||
FREE(ktriov, M_TEMP);
|
||||
}
|
||||
#endif
|
||||
*retval = cnt;
|
||||
done:
|
||||
if (needfree)
|
||||
FREE(needfree, M_IOV);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_writev(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_writev_args /* {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(const netbsd32_iovecp_t) iovp;
|
||||
syscallarg(int) iovcnt;
|
||||
} */ *uap = v;
|
||||
int fd = SCARG(uap, fd);
|
||||
struct file *fp;
|
||||
struct filedesc *fdp = p->p_fd;
|
||||
|
||||
if ((u_int)fd >= fdp->fd_nfiles ||
|
||||
(fp = fdp->fd_ofiles[fd]) == NULL ||
|
||||
(fp->f_flag & FWRITE) == 0)
|
||||
return (EBADF);
|
||||
|
||||
return (dofilewritev32(p, fd, fp, (struct netbsd32_iovec *)(u_long)SCARG(uap, iovp),
|
||||
SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
|
||||
}
|
||||
|
||||
int
|
||||
dofilewritev32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
|
||||
struct proc *p;
|
||||
int fd;
|
||||
struct file *fp;
|
||||
struct netbsd32_iovec *iovp;
|
||||
int iovcnt;
|
||||
off_t *offset;
|
||||
int flags;
|
||||
register_t *retval;
|
||||
{
|
||||
struct uio auio;
|
||||
struct iovec *iov;
|
||||
struct iovec *needfree;
|
||||
struct iovec aiov[UIO_SMALLIOV];
|
||||
long i, cnt, error = 0;
|
||||
u_int iovlen;
|
||||
#ifdef KTRACE
|
||||
struct iovec *ktriov = NULL;
|
||||
#endif
|
||||
|
||||
/* note: can't use iovlen until iovcnt is validated */
|
||||
iovlen = iovcnt * sizeof(struct iovec);
|
||||
if ((u_int)iovcnt > UIO_SMALLIOV) {
|
||||
if ((u_int)iovcnt > IOV_MAX)
|
||||
return (EINVAL);
|
||||
MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK);
|
||||
needfree = iov;
|
||||
} else if ((u_int)iovcnt > 0) {
|
||||
iov = aiov;
|
||||
needfree = NULL;
|
||||
} else
|
||||
return (EINVAL);
|
||||
|
||||
auio.uio_iov = iov;
|
||||
auio.uio_iovcnt = iovcnt;
|
||||
auio.uio_rw = UIO_WRITE;
|
||||
auio.uio_segflg = UIO_USERSPACE;
|
||||
auio.uio_procp = p;
|
||||
error = netbsd32_to_iovecin(iovp, iov, iovcnt);
|
||||
if (error)
|
||||
goto done;
|
||||
auio.uio_resid = 0;
|
||||
for (i = 0; i < iovcnt; i++) {
|
||||
auio.uio_resid += iov->iov_len;
|
||||
/*
|
||||
* Writes return ssize_t because -1 is returned on error.
|
||||
* Therefore we must restrict the length to SSIZE_MAX to
|
||||
* avoid garbage return values.
|
||||
*/
|
||||
if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
|
||||
error = EINVAL;
|
||||
goto done;
|
||||
}
|
||||
iov++;
|
||||
}
|
||||
#ifdef KTRACE
|
||||
/*
|
||||
* if tracing, save a copy of iovec
|
||||
*/
|
||||
if (KTRPOINT(p, KTR_GENIO)) {
|
||||
MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
|
||||
memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
|
||||
}
|
||||
#endif
|
||||
cnt = auio.uio_resid;
|
||||
error = (*fp->f_ops->fo_write)(fp, offset, &auio, fp->f_cred, flags);
|
||||
if (error) {
|
||||
if (auio.uio_resid != cnt && (error == ERESTART ||
|
||||
error == EINTR || error == EWOULDBLOCK))
|
||||
error = 0;
|
||||
if (error == EPIPE)
|
||||
psignal(p, SIGPIPE);
|
||||
}
|
||||
cnt -= auio.uio_resid;
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(p, KTR_GENIO))
|
||||
if (error == 0) {
|
||||
ktrgenio(p, fd, UIO_WRITE, ktriov, cnt,
|
||||
error);
|
||||
FREE(ktriov, M_TEMP);
|
||||
}
|
||||
#endif
|
||||
*retval = cnt;
|
||||
done:
|
||||
if (needfree)
|
||||
FREE(needfree, M_IOV);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_utimes(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_utimes_args /* {
|
||||
syscallarg(const netbsd32_charp) path;
|
||||
syscallarg(const netbsd32_timevalp_t) tptr;
|
||||
} */ *uap = v;
|
||||
int error;
|
||||
struct nameidata nd;
|
||||
|
||||
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, (char *)(u_long)SCARG(uap, path), p);
|
||||
if ((error = namei(&nd)) != 0)
|
||||
return (error);
|
||||
|
||||
error = change_utimes32(nd.ni_vp, SCARG(uap, tptr), p);
|
||||
|
||||
vrele(nd.ni_vp);
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Common routine to set access and modification times given a vnode.
|
||||
*/
|
||||
static int
|
||||
change_utimes32(vp, tptr, p)
|
||||
struct vnode *vp;
|
||||
netbsd32_timevalp_t tptr;
|
||||
struct proc *p;
|
||||
{
|
||||
struct netbsd32_timeval tv32[2];
|
||||
struct timeval tv[2];
|
||||
struct vattr vattr;
|
||||
int error;
|
||||
|
||||
VATTR_NULL(&vattr);
|
||||
if (tptr == NULL) {
|
||||
microtime(&tv[0]);
|
||||
tv[1] = tv[0];
|
||||
vattr.va_vaflags |= VA_UTIMES_NULL;
|
||||
} else {
|
||||
error = copyin((caddr_t)(u_long)tptr, tv32, sizeof(tv32));
|
||||
if (error)
|
||||
return (error);
|
||||
netbsd32_to_timeval(&tv32[0], &tv[0]);
|
||||
netbsd32_to_timeval(&tv32[1], &tv[1]);
|
||||
}
|
||||
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
||||
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
||||
vattr.va_atime.tv_sec = tv[0].tv_sec;
|
||||
vattr.va_atime.tv_nsec = tv[0].tv_usec * 1000;
|
||||
vattr.va_mtime.tv_sec = tv[1].tv_sec;
|
||||
vattr.va_mtime.tv_nsec = tv[1].tv_usec * 1000;
|
||||
error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
|
||||
VOP_UNLOCK(vp, 0);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_statfs(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_statfs_args /* {
|
||||
syscallarg(const netbsd32_charp) path;
|
||||
syscallarg(netbsd32_statfsp_t) buf;
|
||||
} */ *uap = v;
|
||||
struct mount *mp;
|
||||
struct statfs *sp;
|
||||
struct netbsd32_statfs s32;
|
||||
int error;
|
||||
struct nameidata nd;
|
||||
|
||||
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, (char *)(u_long)SCARG(uap, path), p);
|
||||
if ((error = namei(&nd)) != 0)
|
||||
return (error);
|
||||
mp = nd.ni_vp->v_mount;
|
||||
sp = &mp->mnt_stat;
|
||||
vrele(nd.ni_vp);
|
||||
if ((error = VFS_STATFS(mp, sp, p)) != 0)
|
||||
return (error);
|
||||
sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
|
||||
netbsd32_from_statfs(sp, &s32);
|
||||
return (copyout(&s32, (caddr_t)(u_long)SCARG(uap, buf), sizeof(s32)));
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_fstatfs(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_fstatfs_args /* {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(netbsd32_statfsp_t) buf;
|
||||
} */ *uap = v;
|
||||
struct file *fp;
|
||||
struct mount *mp;
|
||||
struct statfs *sp;
|
||||
struct netbsd32_statfs s32;
|
||||
int error;
|
||||
|
||||
/* getvnode() will use the descriptor for us */
|
||||
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
|
||||
return (error);
|
||||
mp = ((struct vnode *)fp->f_data)->v_mount;
|
||||
sp = &mp->mnt_stat;
|
||||
if ((error = VFS_STATFS(mp, sp, p)) != 0)
|
||||
goto out;
|
||||
sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
|
||||
netbsd32_from_statfs(sp, &s32);
|
||||
error = copyout(&s32, (caddr_t)(u_long)SCARG(uap, buf), sizeof(s32));
|
||||
out:
|
||||
FILE_UNUSE(fp, p);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_futimes(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_futimes_args /* {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(const netbsd32_timevalp_t) tptr;
|
||||
} */ *uap = v;
|
||||
int error;
|
||||
struct file *fp;
|
||||
|
||||
/* getvnode() will use the descriptor for us */
|
||||
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
|
||||
return (error);
|
||||
|
||||
error = change_utimes32((struct vnode *)fp->f_data,
|
||||
SCARG(uap, tptr), p);
|
||||
FILE_UNUSE(fp, p);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_getdents(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_getdents_args /* {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(netbsd32_charp) buf;
|
||||
syscallarg(netbsd32_size_t) count;
|
||||
} */ *uap = v;
|
||||
struct file *fp;
|
||||
int error, done;
|
||||
|
||||
/* getvnode() will use the descriptor for us */
|
||||
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
|
||||
return (error);
|
||||
if ((fp->f_flag & FREAD) == 0) {
|
||||
error = EBADF;
|
||||
goto out;
|
||||
}
|
||||
error = vn_readdir(fp, (caddr_t)(u_long)SCARG(uap, buf), UIO_USERSPACE,
|
||||
SCARG(uap, count), &done, p, 0, 0);
|
||||
*retval = done;
|
||||
out:
|
||||
FILE_UNUSE(fp, p);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_lutimes(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_lutimes_args /* {
|
||||
syscallarg(const netbsd32_charp) path;
|
||||
syscallarg(const netbsd32_timevalp_t) tptr;
|
||||
} */ *uap = v;
|
||||
int error;
|
||||
struct nameidata nd;
|
||||
|
||||
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, (caddr_t)(u_long)SCARG(uap, path), p);
|
||||
if ((error = namei(&nd)) != 0)
|
||||
return (error);
|
||||
|
||||
error = change_utimes32(nd.ni_vp, SCARG(uap, tptr), p);
|
||||
|
||||
vrele(nd.ni_vp);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32___stat13(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32___stat13_args /* {
|
||||
syscallarg(const netbsd32_charp) path;
|
||||
syscallarg(netbsd32_statp_t) ub;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_stat sb32;
|
||||
struct stat sb;
|
||||
int error;
|
||||
struct nameidata nd;
|
||||
caddr_t sg;
|
||||
const char *path;
|
||||
|
||||
path = (char *)(u_long)SCARG(uap, path);
|
||||
sg = stackgap_init(p->p_emul);
|
||||
CHECK_ALT_EXIST(p, &sg, path);
|
||||
|
||||
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
|
||||
if ((error = namei(&nd)) != 0)
|
||||
return (error);
|
||||
error = vn_stat(nd.ni_vp, &sb, p);
|
||||
vput(nd.ni_vp);
|
||||
if (error)
|
||||
return (error);
|
||||
netbsd32_from___stat13(&sb, &sb32);
|
||||
error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof(sb32));
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32___fstat13(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32___fstat13_args /* {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(netbsd32_statp_t) sb;
|
||||
} */ *uap = v;
|
||||
int fd = SCARG(uap, fd);
|
||||
struct filedesc *fdp = p->p_fd;
|
||||
struct file *fp;
|
||||
struct netbsd32_stat sb32;
|
||||
struct stat ub;
|
||||
int error = 0;
|
||||
|
||||
if ((u_int)fd >= fdp->fd_nfiles ||
|
||||
(fp = fdp->fd_ofiles[fd]) == NULL)
|
||||
return (EBADF);
|
||||
switch (fp->f_type) {
|
||||
|
||||
case DTYPE_VNODE:
|
||||
error = vn_stat((struct vnode *)fp->f_data, &ub, p);
|
||||
break;
|
||||
|
||||
case DTYPE_SOCKET:
|
||||
error = soo_stat((struct socket *)fp->f_data, &ub);
|
||||
break;
|
||||
|
||||
default:
|
||||
panic("fstat");
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
if (error == 0) {
|
||||
netbsd32_from___stat13(&ub, &sb32);
|
||||
error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, sb), sizeof(sb32));
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32___lstat13(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32___lstat13_args /* {
|
||||
syscallarg(const netbsd32_charp) path;
|
||||
syscallarg(netbsd32_statp_t) ub;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_stat sb32;
|
||||
struct stat sb;
|
||||
int error;
|
||||
struct nameidata nd;
|
||||
caddr_t sg;
|
||||
const char *path;
|
||||
|
||||
path = (char *)(u_long)SCARG(uap, path);
|
||||
sg = stackgap_init(p->p_emul);
|
||||
CHECK_ALT_EXIST(p, &sg, path);
|
||||
|
||||
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
|
||||
if ((error = namei(&nd)) != 0)
|
||||
return (error);
|
||||
error = vn_stat(nd.ni_vp, &sb, p);
|
||||
vput(nd.ni_vp);
|
||||
if (error)
|
||||
return (error);
|
||||
netbsd32_from___stat13(&sb, &sb32);
|
||||
error = copyout(&sb32, (caddr_t)(u_long)SCARG(uap, ub), sizeof(sb32));
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_preadv(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_preadv_args /* {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(const netbsd32_iovecp_t) iovp;
|
||||
syscallarg(int) iovcnt;
|
||||
syscallarg(int) pad;
|
||||
syscallarg(off_t) offset;
|
||||
} */ *uap = v;
|
||||
struct filedesc *fdp = p->p_fd;
|
||||
struct file *fp;
|
||||
struct vnode *vp;
|
||||
off_t offset;
|
||||
int error, fd = SCARG(uap, fd);
|
||||
|
||||
if ((u_int)fd >= fdp->fd_nfiles ||
|
||||
(fp = fdp->fd_ofiles[fd]) == NULL ||
|
||||
(fp->f_flag & FREAD) == 0)
|
||||
return (EBADF);
|
||||
|
||||
vp = (struct vnode *)fp->f_data;
|
||||
if (fp->f_type != DTYPE_VNODE
|
||||
|| vp->v_type == VFIFO)
|
||||
return (ESPIPE);
|
||||
|
||||
offset = SCARG(uap, offset);
|
||||
|
||||
/*
|
||||
* XXX This works because no file systems actually
|
||||
* XXX take any action on the seek operation.
|
||||
*/
|
||||
if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
|
||||
return (error);
|
||||
|
||||
return (dofilereadv32(p, fd, fp, (struct netbsd32_iovec *)(u_long)SCARG(uap, iovp), SCARG(uap, iovcnt),
|
||||
&offset, 0, retval));
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_pwritev(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_pwritev_args /* {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(const netbsd32_iovecp_t) iovp;
|
||||
syscallarg(int) iovcnt;
|
||||
syscallarg(int) pad;
|
||||
syscallarg(off_t) offset;
|
||||
} */ *uap = v;
|
||||
struct filedesc *fdp = p->p_fd;
|
||||
struct file *fp;
|
||||
struct vnode *vp;
|
||||
off_t offset;
|
||||
int error, fd = SCARG(uap, fd);
|
||||
|
||||
if ((u_int)fd >= fdp->fd_nfiles ||
|
||||
(fp = fdp->fd_ofiles[fd]) == NULL ||
|
||||
(fp->f_flag & FWRITE) == 0)
|
||||
return (EBADF);
|
||||
|
||||
vp = (struct vnode *)fp->f_data;
|
||||
if (fp->f_type != DTYPE_VNODE
|
||||
|| vp->v_type == VFIFO)
|
||||
return (ESPIPE);
|
||||
|
||||
offset = SCARG(uap, offset);
|
||||
|
||||
/*
|
||||
* XXX This works because no file systems actually
|
||||
* XXX take any action on the seek operation.
|
||||
*/
|
||||
if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
|
||||
return (error);
|
||||
|
||||
return (dofilewritev32(p, fd, fp, (struct netbsd32_iovec *)(u_long)SCARG(uap, iovp), SCARG(uap, iovcnt),
|
||||
&offset, 0, retval));
|
||||
}
|
||||
|
||||
/*
|
||||
* Find pathname of process's current directory.
|
||||
*
|
||||
* Use vfs vnode-to-name reverse cache; if that fails, fall back
|
||||
* to reading directory contents.
|
||||
*/
|
||||
int
|
||||
getcwd_common __P((struct vnode *, struct vnode *,
|
||||
char **, char *, int, int, struct proc *));
|
||||
|
||||
int netbsd32___getcwd(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32___getcwd_args /* {
|
||||
syscallarg(char *) bufp;
|
||||
syscallarg(size_t) length;
|
||||
} */ *uap = v;
|
||||
|
||||
int error;
|
||||
char *path;
|
||||
char *bp, *bend;
|
||||
int len = (int)SCARG(uap, length);
|
||||
int lenused;
|
||||
|
||||
if (len > MAXPATHLEN*4)
|
||||
len = MAXPATHLEN*4;
|
||||
else if (len < 2)
|
||||
return ERANGE;
|
||||
|
||||
path = (char *)malloc(len, M_TEMP, M_WAITOK);
|
||||
if (!path)
|
||||
return ENOMEM;
|
||||
|
||||
bp = &path[len];
|
||||
bend = bp;
|
||||
*(--bp) = '\0';
|
||||
|
||||
/*
|
||||
* 5th argument here is "max number of vnodes to traverse".
|
||||
* Since each entry takes up at least 2 bytes in the output buffer,
|
||||
* limit it to N/2 vnodes for an N byte buffer.
|
||||
*/
|
||||
#define GETCWD_CHECK_ACCESS 0x0001
|
||||
error = getcwd_common (p->p_cwdi->cwdi_cdir, NULL, &bp, path, len/2,
|
||||
GETCWD_CHECK_ACCESS, p);
|
||||
|
||||
if (error)
|
||||
goto out;
|
||||
lenused = bend - bp;
|
||||
*retval = lenused;
|
||||
/* put the result into user buffer */
|
||||
error = copyout(bp, (caddr_t)(u_long)SCARG(uap, bufp), lenused);
|
||||
|
||||
out:
|
||||
free(path, M_TEMP);
|
||||
return error;
|
||||
}
|
|
@ -0,0 +1,503 @@
|
|||
/* $NetBSD: netbsd32_ipc.c,v 1.1 2001/02/08 13:19:33 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
#if defined(_KERNEL) && !defined(_LKM)
|
||||
#include "opt_sysv.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
#include <sys/sem.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <sys/syscallargs.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <compat/netbsd32/netbsd32.h>
|
||||
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
||||
#include <compat/netbsd32/netbsd32_conv.h>
|
||||
|
||||
#if defined(SYSVSEM)
|
||||
/*
|
||||
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
*
|
||||
* This is BSD. We won't support System V IPC.
|
||||
* Too much work.
|
||||
*
|
||||
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
*/
|
||||
int
|
||||
netbsd32___semctl14(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
#if 0
|
||||
struct netbsd32___semctl_args /* {
|
||||
syscallarg(int) semid;
|
||||
syscallarg(int) semnum;
|
||||
syscallarg(int) cmd;
|
||||
syscallarg(netbsd32_semunu_t *) arg;
|
||||
} */ *uap = v;
|
||||
union netbsd32_semun sem32;
|
||||
int semid = SCARG(uap, semid);
|
||||
int semnum = SCARG(uap, semnum);
|
||||
int cmd = SCARG(uap, cmd);
|
||||
union netbsd32_semun *arg = (void*)(u_long)SCARG(uap, arg);
|
||||
union netbsd32_semun real_arg;
|
||||
struct ucred *cred = p->p_ucred;
|
||||
int i, rval, eval;
|
||||
struct netbsd32_semid_ds sbuf;
|
||||
struct semid_ds *semaptr;
|
||||
|
||||
semlock(p);
|
||||
|
||||
semid = IPCID_TO_IX(semid);
|
||||
if (semid < 0 || semid >= seminfo.semmsl)
|
||||
return(EINVAL);
|
||||
|
||||
semaptr = &sema[semid];
|
||||
if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 ||
|
||||
semaptr->sem_perm.seq != IPCID_TO_SEQ(SCARG(uap, semid)))
|
||||
return(EINVAL);
|
||||
|
||||
eval = 0;
|
||||
rval = 0;
|
||||
|
||||
switch (cmd) {
|
||||
case IPC_RMID:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)) != 0)
|
||||
return(eval);
|
||||
semaptr->sem_perm.cuid = cred->cr_uid;
|
||||
semaptr->sem_perm.uid = cred->cr_uid;
|
||||
semtot -= semaptr->sem_nsems;
|
||||
for (i = semaptr->_sem_base - sem; i < semtot; i++)
|
||||
sem[i] = sem[i + semaptr->sem_nsems];
|
||||
for (i = 0; i < seminfo.semmni; i++) {
|
||||
if ((sema[i].sem_perm.mode & SEM_ALLOC) &&
|
||||
sema[i]._sem_base > semaptr->_sem_base)
|
||||
sema[i]._sem_base -= semaptr->sem_nsems;
|
||||
}
|
||||
semaptr->sem_perm.mode = 0;
|
||||
semundo_clear(semid, -1);
|
||||
wakeup((caddr_t)semaptr);
|
||||
break;
|
||||
|
||||
case IPC_SET:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)))
|
||||
return(eval);
|
||||
if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
|
||||
return(eval);
|
||||
if ((eval = copyin((caddr_t)(u_long)real_arg.buf, (caddr_t)&sbuf,
|
||||
sizeof(sbuf))) != 0)
|
||||
return(eval);
|
||||
semaptr->sem_perm.uid = sbuf.sem_perm.uid;
|
||||
semaptr->sem_perm.gid = sbuf.sem_perm.gid;
|
||||
semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) |
|
||||
(sbuf.sem_perm.mode & 0777);
|
||||
semaptr->sem_ctime = time.tv_sec;
|
||||
break;
|
||||
|
||||
case IPC_STAT:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
|
||||
return(eval);
|
||||
if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
|
||||
return(eval);
|
||||
eval = copyout((caddr_t)semaptr, (caddr_t)(u_long)real_arg.buf,
|
||||
sizeof(struct semid_ds));
|
||||
break;
|
||||
|
||||
case GETNCNT:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
|
||||
return(eval);
|
||||
if (semnum < 0 || semnum >= semaptr->sem_nsems)
|
||||
return(EINVAL);
|
||||
rval = semaptr->_sem_base[semnum].semncnt;
|
||||
break;
|
||||
|
||||
case GETPID:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
|
||||
return(eval);
|
||||
if (semnum < 0 || semnum >= semaptr->sem_nsems)
|
||||
return(EINVAL);
|
||||
rval = semaptr->_sem_base[semnum].sempid;
|
||||
break;
|
||||
|
||||
case GETVAL:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
|
||||
return(eval);
|
||||
if (semnum < 0 || semnum >= semaptr->sem_nsems)
|
||||
return(EINVAL);
|
||||
rval = semaptr->_sem_base[semnum].semval;
|
||||
break;
|
||||
|
||||
case GETALL:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
|
||||
return(eval);
|
||||
if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
|
||||
return(eval);
|
||||
for (i = 0; i < semaptr->sem_nsems; i++) {
|
||||
eval = copyout((caddr_t)&semaptr->_sem_base[i].semval,
|
||||
&real_arg.array[i], sizeof(real_arg.array[0]));
|
||||
if (eval != 0)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case GETZCNT:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_R)))
|
||||
return(eval);
|
||||
if (semnum < 0 || semnum >= semaptr->sem_nsems)
|
||||
return(EINVAL);
|
||||
rval = semaptr->_sem_base[semnum].semzcnt;
|
||||
break;
|
||||
|
||||
case SETVAL:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
|
||||
return(eval);
|
||||
if (semnum < 0 || semnum >= semaptr->sem_nsems)
|
||||
return(EINVAL);
|
||||
if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
|
||||
return(eval);
|
||||
semaptr->_sem_base[semnum].semval = real_arg.val;
|
||||
semundo_clear(semid, semnum);
|
||||
wakeup((caddr_t)semaptr);
|
||||
break;
|
||||
|
||||
case SETALL:
|
||||
if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_W)))
|
||||
return(eval);
|
||||
if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
|
||||
return(eval);
|
||||
for (i = 0; i < semaptr->sem_nsems; i++) {
|
||||
eval = copyin(&real_arg.array[i],
|
||||
(caddr_t)&semaptr->_sem_base[i].semval,
|
||||
sizeof(real_arg.array[0]));
|
||||
if (eval != 0)
|
||||
break;
|
||||
}
|
||||
semundo_clear(semid, -1);
|
||||
wakeup((caddr_t)semaptr);
|
||||
break;
|
||||
|
||||
default:
|
||||
return(EINVAL);
|
||||
}
|
||||
|
||||
if (eval == 0)
|
||||
*retval = rval;
|
||||
return(eval);
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_semget(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_semget_args /* {
|
||||
syscallarg(netbsd32_key_t) key;
|
||||
syscallarg(int) nsems;
|
||||
syscallarg(int) semflg;
|
||||
} */ *uap = v;
|
||||
struct sys_semget_args ua;
|
||||
|
||||
NETBSD32TOX_UAP(key, key_t);
|
||||
NETBSD32TO64_UAP(nsems);
|
||||
NETBSD32TO64_UAP(semflg);
|
||||
return (sys_semget(p, &ua, retval));
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_semop(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_semop_args /* {
|
||||
syscallarg(int) semid;
|
||||
syscallarg(netbsd32_sembufp_t) sops;
|
||||
syscallarg(netbsd32_size_t) nsops;
|
||||
} */ *uap = v;
|
||||
struct sys_semop_args ua;
|
||||
|
||||
NETBSD32TO64_UAP(semid);
|
||||
NETBSD32TOP_UAP(sops, struct sembuf);
|
||||
NETBSD32TOX_UAP(nsops, size_t);
|
||||
return (sys_semop(p, &ua, retval));
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_semconfig(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_semconfig_args /* {
|
||||
syscallarg(int) flag;
|
||||
} */ *uap = v;
|
||||
struct sys_semconfig_args ua;
|
||||
|
||||
NETBSD32TO64_UAP(flag);
|
||||
return (sys_semconfig(p, &ua, retval));
|
||||
}
|
||||
#endif /* SYSVSEM */
|
||||
|
||||
#if defined(SYSVMSG)
|
||||
|
||||
int
|
||||
netbsd32___msgctl13(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
#if 0
|
||||
struct netbsd32_msgctl_args /* {
|
||||
syscallarg(int) msqid;
|
||||
syscallarg(int) cmd;
|
||||
syscallarg(netbsd32_msqid_dsp_t) buf;
|
||||
} */ *uap = v;
|
||||
struct sys_msgctl_args ua;
|
||||
struct msqid_ds ds;
|
||||
struct netbsd32_msqid_ds *ds32p;
|
||||
int error;
|
||||
|
||||
NETBSD32TO64_UAP(msqid);
|
||||
NETBSD32TO64_UAP(cmd);
|
||||
ds32p = (struct netbsd32_msqid_ds *)(u_long)SCARG(uap, buf);
|
||||
if (ds32p) {
|
||||
SCARG(&ua, buf) = NULL;
|
||||
netbsd32_to_msqid_ds(ds32p, &ds);
|
||||
} else
|
||||
SCARG(&ua, buf) = NULL;
|
||||
error = sys_msgctl(p, &ua, retval);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
if (ds32p)
|
||||
netbsd32_from_msqid_ds(&ds, ds32p);
|
||||
return (0);
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_msgget(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
#if 0
|
||||
struct netbsd32_msgget_args /* {
|
||||
syscallarg(netbsd32_key_t) key;
|
||||
syscallarg(int) msgflg;
|
||||
} */ *uap = v;
|
||||
struct sys_msgget_args ua;
|
||||
|
||||
NETBSD32TOX_UAP(key, key_t);
|
||||
NETBSD32TO64_UAP(msgflg);
|
||||
return (sys_msgget(p, &ua, retval));
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_msgsnd(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
#if 0
|
||||
struct netbsd32_msgsnd_args /* {
|
||||
syscallarg(int) msqid;
|
||||
syscallarg(const netbsd32_voidp) msgp;
|
||||
syscallarg(netbsd32_size_t) msgsz;
|
||||
syscallarg(int) msgflg;
|
||||
} */ *uap = v;
|
||||
struct sys_msgsnd_args ua;
|
||||
|
||||
NETBSD32TO64_UAP(msqid);
|
||||
NETBSD32TOP_UAP(msgp, void);
|
||||
NETBSD32TOX_UAP(msgsz, size_t);
|
||||
NETBSD32TO64_UAP(msgflg);
|
||||
return (sys_msgsnd(p, &ua, retval));
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_msgrcv(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
#if 0
|
||||
struct netbsd32_msgrcv_args /* {
|
||||
syscallarg(int) msqid;
|
||||
syscallarg(netbsd32_voidp) msgp;
|
||||
syscallarg(netbsd32_size_t) msgsz;
|
||||
syscallarg(netbsd32_long) msgtyp;
|
||||
syscallarg(int) msgflg;
|
||||
} */ *uap = v;
|
||||
struct sys_msgrcv_args ua;
|
||||
ssize_t rt;
|
||||
int error;
|
||||
|
||||
NETBSD32TO64_UAP(msqid);
|
||||
NETBSD32TOP_UAP(msgp, void);
|
||||
NETBSD32TOX_UAP(msgsz, size_t);
|
||||
NETBSD32TOX_UAP(msgtyp, long);
|
||||
NETBSD32TO64_UAP(msgflg);
|
||||
error = sys_msgrcv(p, &ua, (register_t *)&rt);
|
||||
*retval = rt;
|
||||
return (error);
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
#endif /* SYSVMSG */
|
||||
|
||||
#if defined(SYSVSHM)
|
||||
|
||||
int
|
||||
netbsd32_shmat(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
#if 0
|
||||
struct netbsd32_shmat_args /* {
|
||||
syscallarg(int) shmid;
|
||||
syscallarg(const netbsd32_voidp) shmaddr;
|
||||
syscallarg(int) shmflg;
|
||||
} */ *uap = v;
|
||||
struct sys_shmat_args ua;
|
||||
void *rt;
|
||||
int error;
|
||||
|
||||
NETBSD32TO64_UAP(shmid);
|
||||
NETBSD32TOP_UAP(shmaddr, void);
|
||||
NETBSD32TO64_UAP(shmflg);
|
||||
error = sys_shmat(p, &ua, (register_t *)&rt);
|
||||
*retval = rt;
|
||||
return (error);
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32___shmctl13(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
#if 0
|
||||
struct netbsd32_shmctl_args /* {
|
||||
syscallarg(int) shmid;
|
||||
syscallarg(int) cmd;
|
||||
syscallarg(netbsd32_shmid_dsp_t) buf;
|
||||
} */ *uap = v;
|
||||
struct sys_shmctl_args ua;
|
||||
struct shmid_ds ds;
|
||||
struct netbsd32_shmid_ds *ds32p;
|
||||
int error;
|
||||
|
||||
NETBSD32TO64_UAP(shmid);
|
||||
NETBSD32TO64_UAP(cmd);
|
||||
ds32p = (struct netbsd32_shmid_ds *)(u_long)SCARG(uap, buf);
|
||||
if (ds32p) {
|
||||
SCARG(&ua, buf) = NULL;
|
||||
netbsd32_to_shmid_ds(ds32p, &ds);
|
||||
} else
|
||||
SCARG(&ua, buf) = NULL;
|
||||
error = sys_shmctl(p, &ua, retval);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
if (ds32p)
|
||||
netbsd32_from_shmid_ds(&ds, ds32p);
|
||||
return (0);
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_shmdt(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
#if 0
|
||||
struct netbsd32_shmdt_args /* {
|
||||
syscallarg(const netbsd32_voidp) shmaddr;
|
||||
} */ *uap = v;
|
||||
struct sys_shmdt_args ua;
|
||||
|
||||
NETBSD32TOP_UAP(shmaddr, const char);
|
||||
return (sys_shmdt(p, &ua, retval));
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_shmget(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
#if 0
|
||||
struct netbsd32_shmget_args /* {
|
||||
syscallarg(netbsd32_key_t) key;
|
||||
syscallarg(netbsd32_size_t) size;
|
||||
syscallarg(int) shmflg;
|
||||
} */ *uap = v;
|
||||
struct sys_shmget_args ua;
|
||||
|
||||
NETBSD32TOX_UAP(key, key_t)
|
||||
NETBSD32TOX_UAP(size, size_t)
|
||||
NETBSD32TO64_UAP(shmflg);
|
||||
return (sys_shmget(p, &ua, retval));
|
||||
#else
|
||||
return (ENOSYS);
|
||||
#endif
|
||||
}
|
||||
#endif /* SYSVSHM */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,159 @@
|
|||
/* $NetBSD: netbsd32_select.c,v 1.1 2001/02/08 13:19:34 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/filedesc.h>
|
||||
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <net/if.h>
|
||||
|
||||
#include <compat/netbsd32/netbsd32.h>
|
||||
#include <compat/netbsd32/netbsd32_syscall.h>
|
||||
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
||||
#include <compat/netbsd32/netbsd32_conv.h>
|
||||
|
||||
int
|
||||
netbsd32_select(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_select_args /* {
|
||||
syscallarg(int) nd;
|
||||
syscallarg(netbsd32_fd_setp_t) in;
|
||||
syscallarg(netbsd32_fd_setp_t) ou;
|
||||
syscallarg(netbsd32_fd_setp_t) ex;
|
||||
syscallarg(netbsd32_timevalp_t) tv;
|
||||
} */ *uap = v;
|
||||
/* This one must be done in-line 'cause of the timeval */
|
||||
struct netbsd32_timeval tv32;
|
||||
caddr_t bits;
|
||||
char smallbits[howmany(FD_SETSIZE, NFDBITS) * sizeof(fd_mask) * 6];
|
||||
struct timeval atv;
|
||||
int s, ncoll, error = 0, timo;
|
||||
size_t ni;
|
||||
extern int selwait, nselcoll;
|
||||
extern int selscan __P((struct proc *, fd_mask *, fd_mask *, int, register_t *));
|
||||
|
||||
if (SCARG(uap, nd) < 0)
|
||||
return (EINVAL);
|
||||
if (SCARG(uap, nd) > p->p_fd->fd_nfiles) {
|
||||
/* forgiving; slightly wrong */
|
||||
SCARG(uap, nd) = p->p_fd->fd_nfiles;
|
||||
}
|
||||
ni = howmany(SCARG(uap, nd), NFDBITS) * sizeof(fd_mask);
|
||||
if (ni * 6 > sizeof(smallbits))
|
||||
bits = malloc(ni * 6, M_TEMP, M_WAITOK);
|
||||
else
|
||||
bits = smallbits;
|
||||
|
||||
#define getbits(name, x) \
|
||||
if (SCARG(uap, name)) { \
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, name), bits + ni * x, ni); \
|
||||
if (error) \
|
||||
goto done; \
|
||||
} else \
|
||||
memset(bits + ni * x, 0, ni);
|
||||
getbits(in, 0);
|
||||
getbits(ou, 1);
|
||||
getbits(ex, 2);
|
||||
#undef getbits
|
||||
|
||||
if (SCARG(uap, tv)) {
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, tv), (caddr_t)&tv32,
|
||||
sizeof(tv32));
|
||||
if (error)
|
||||
goto done;
|
||||
netbsd32_to_timeval(&tv32, &atv);
|
||||
if (itimerfix(&atv)) {
|
||||
error = EINVAL;
|
||||
goto done;
|
||||
}
|
||||
s = splclock();
|
||||
timeradd(&atv, &time, &atv);
|
||||
splx(s);
|
||||
} else
|
||||
timo = 0;
|
||||
retry:
|
||||
ncoll = nselcoll;
|
||||
p->p_flag |= P_SELECT;
|
||||
error = selscan(p, (fd_mask *)(bits + ni * 0),
|
||||
(fd_mask *)(bits + ni * 3), SCARG(uap, nd), retval);
|
||||
if (error || *retval)
|
||||
goto done;
|
||||
if (SCARG(uap, tv)) {
|
||||
/*
|
||||
* We have to recalculate the timeout on every retry.
|
||||
*/
|
||||
timo = hzto(&atv);
|
||||
if (timo <= 0)
|
||||
goto done;
|
||||
}
|
||||
s = splhigh();
|
||||
if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) {
|
||||
splx(s);
|
||||
goto retry;
|
||||
}
|
||||
p->p_flag &= ~P_SELECT;
|
||||
error = tsleep((caddr_t)&selwait, PSOCK | PCATCH, "select", timo);
|
||||
splx(s);
|
||||
if (error == 0)
|
||||
goto retry;
|
||||
done:
|
||||
p->p_flag &= ~P_SELECT;
|
||||
/* select is not restarted after signals... */
|
||||
if (error == ERESTART)
|
||||
error = EINTR;
|
||||
if (error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
if (error == 0) {
|
||||
#define putbits(name, x) \
|
||||
if (SCARG(uap, name)) { \
|
||||
error = copyout(bits + ni * x, (caddr_t)(u_long)SCARG(uap, name), ni); \
|
||||
if (error) \
|
||||
goto out; \
|
||||
}
|
||||
putbits(in, 3);
|
||||
putbits(ou, 4);
|
||||
putbits(ex, 5);
|
||||
#undef putbits
|
||||
}
|
||||
out:
|
||||
if (ni * 6 > sizeof(smallbits))
|
||||
free(bits, M_TEMP);
|
||||
return (error);
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
/* $NetBSD: netbsd32_signal.c,v 1.1 2001/02/08 13:19:34 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <compat/netbsd32/netbsd32.h>
|
||||
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
||||
|
||||
int
|
||||
netbsd32_sigaction(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_sigaction_args /* {
|
||||
syscallarg(int) signum;
|
||||
syscallarg(const netbsd32_sigactionp_t) nsa;
|
||||
syscallarg(netbsd32_sigactionp_t) osa;
|
||||
} */ *uap = v;
|
||||
struct sigaction nsa, osa;
|
||||
struct netbsd32_sigaction *sa32p, sa32;
|
||||
int error;
|
||||
|
||||
if (SCARG(uap, nsa)) {
|
||||
sa32p = (struct netbsd32_sigaction *)(u_long)SCARG(uap, nsa);
|
||||
if (copyin(sa32p, &sa32, sizeof(sa32)))
|
||||
return EFAULT;
|
||||
nsa.sa_handler = (void *)(u_long)sa32.sa_handler;
|
||||
nsa.sa_mask = sa32.sa_mask;
|
||||
nsa.sa_flags = sa32.sa_flags;
|
||||
}
|
||||
error = sigaction1(p, SCARG(uap, signum),
|
||||
SCARG(uap, nsa) ? &nsa : 0,
|
||||
SCARG(uap, osa) ? &osa : 0);
|
||||
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
if (SCARG(uap, osa)) {
|
||||
sa32.sa_handler = (netbsd32_sigactionp_t)(u_long)osa.sa_handler;
|
||||
sa32.sa_mask = osa.sa_mask;
|
||||
sa32.sa_flags = osa.sa_flags;
|
||||
sa32p = (struct netbsd32_sigaction *)(u_long)SCARG(uap, osa);
|
||||
if (copyout(&sa32, sa32p, sizeof(sa32)))
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32___sigaltstack14(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32___sigaltstack14_args /* {
|
||||
syscallarg(const netbsd32_sigaltstackp_t) nss;
|
||||
syscallarg(netbsd32_sigaltstackp_t) oss;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_sigaltstack s32;
|
||||
struct sigaltstack nss, oss;
|
||||
int error;
|
||||
|
||||
if (SCARG(uap, nss)) {
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, nss), &s32, sizeof(s32));
|
||||
if (error)
|
||||
return (error);
|
||||
nss.ss_sp = (void *)(u_long)s32.ss_sp;
|
||||
nss.ss_size = (size_t)s32.ss_size;
|
||||
nss.ss_flags = s32.ss_flags;
|
||||
}
|
||||
error = sigaltstack1(p,
|
||||
SCARG(uap, nss) ? &nss : 0, SCARG(uap, oss) ? &oss : 0);
|
||||
if (error)
|
||||
return (error);
|
||||
if (SCARG(uap, oss)) {
|
||||
s32.ss_sp = (netbsd32_voidp)(u_long)oss.ss_sp;
|
||||
s32.ss_size = (netbsd32_size_t)oss.ss_size;
|
||||
s32.ss_flags = oss.ss_flags;
|
||||
error = copyout(&s32, (caddr_t)(u_long)SCARG(uap, oss), sizeof(s32));
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
netbsd32___sigaction14(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32___sigaction14_args /* {
|
||||
syscallarg(int) signum;
|
||||
syscallarg(const struct sigaction *) nsa;
|
||||
syscallarg(struct sigaction *) osa;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_sigaction sa32;
|
||||
struct sigaction nsa, osa;
|
||||
int error;
|
||||
|
||||
if (SCARG(uap, nsa)) {
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, nsa),
|
||||
&sa32, sizeof(sa32));
|
||||
if (error)
|
||||
return (error);
|
||||
nsa.sa_handler = (void *)(u_long)sa32.sa_handler;
|
||||
nsa.sa_mask = sa32.sa_mask;
|
||||
nsa.sa_flags = sa32.sa_flags;
|
||||
}
|
||||
error = sigaction1(p, SCARG(uap, signum),
|
||||
SCARG(uap, nsa) ? &nsa : 0, SCARG(uap, osa) ? &osa : 0);
|
||||
if (error)
|
||||
return (error);
|
||||
if (SCARG(uap, osa)) {
|
||||
sa32.sa_handler = (netbsd32_voidp)(u_long)osa.sa_handler;
|
||||
sa32.sa_mask = osa.sa_mask;
|
||||
sa32.sa_flags = osa.sa_flags;
|
||||
error = copyout(&sa32, (caddr_t)(u_long)SCARG(uap, osa), sizeof(sa32));
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
return (0);
|
||||
}
|
|
@ -0,0 +1,389 @@
|
|||
/* $NetBSD: netbsd32_socket.c,v 1.1 2001/02/08 13:19:34 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
#if defined(_KERNEL) && !defined(_LKM)
|
||||
#include "opt_ktrace.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Though COMPAT_OLDSOCK is needed only for COMPAT_43, SunOS, Linux,
|
||||
* HP-UX, FreeBSD, Ultrix, OSF1, we define it unconditionally so that
|
||||
* this would be LKM-safe.
|
||||
*/
|
||||
#define COMPAT_OLDSOCK /* used by <sys/socket.h> */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#define msg __msg /* Don't ask me! */
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/ktrace.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/syscallargs.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <compat/netbsd32/netbsd32.h>
|
||||
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
||||
#include <compat/netbsd32/netbsd32_conv.h>
|
||||
|
||||
/* note that the netbsd32_msghdr's iov really points to a struct iovec, not a netbsd32_iovec. */
|
||||
static int recvit32 __P((struct proc *, int, struct netbsd32_msghdr *, struct iovec *, caddr_t,
|
||||
register_t *));
|
||||
|
||||
int
|
||||
netbsd32_recvmsg(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_recvmsg_args /* {
|
||||
syscallarg(int) s;
|
||||
syscallarg(netbsd32_msghdrp_t) msg;
|
||||
syscallarg(int) flags;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_msghdr msg;
|
||||
struct iovec aiov[UIO_SMALLIOV], *uiov, *iov;
|
||||
int error;
|
||||
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, msg), (caddr_t)&msg,
|
||||
sizeof(msg));
|
||||
/* netbsd32_msghdr needs the iov pre-allocated */
|
||||
if (error)
|
||||
return (error);
|
||||
if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
|
||||
if ((u_int)msg.msg_iovlen > IOV_MAX)
|
||||
return (EMSGSIZE);
|
||||
MALLOC(iov, struct iovec *,
|
||||
sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
|
||||
M_WAITOK);
|
||||
} else if ((u_int)msg.msg_iovlen > 0)
|
||||
iov = aiov;
|
||||
else
|
||||
return (EMSGSIZE);
|
||||
#ifdef COMPAT_OLDSOCK
|
||||
msg.msg_flags = SCARG(uap, flags) &~ MSG_COMPAT;
|
||||
#else
|
||||
msg.msg_flags = SCARG(uap, flags);
|
||||
#endif
|
||||
uiov = (struct iovec *)(u_long)msg.msg_iov;
|
||||
error = netbsd32_to_iovecin((struct netbsd32_iovec *)uiov,
|
||||
iov, msg.msg_iovlen);
|
||||
if (error)
|
||||
goto done;
|
||||
if ((error = recvit32(p, SCARG(uap, s), &msg, iov, (caddr_t)0, retval)) == 0) {
|
||||
error = copyout((caddr_t)&msg, (caddr_t)(u_long)SCARG(uap, msg),
|
||||
sizeof(msg));
|
||||
}
|
||||
done:
|
||||
if (iov != aiov)
|
||||
FREE(iov, M_IOV);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
recvit32(p, s, mp, iov, namelenp, retsize)
|
||||
struct proc *p;
|
||||
int s;
|
||||
struct netbsd32_msghdr *mp;
|
||||
struct iovec *iov;
|
||||
caddr_t namelenp;
|
||||
register_t *retsize;
|
||||
{
|
||||
struct file *fp;
|
||||
struct uio auio;
|
||||
int i;
|
||||
int len, error;
|
||||
struct mbuf *from = 0, *control = 0;
|
||||
struct socket *so;
|
||||
#ifdef KTRACE
|
||||
struct iovec *ktriov = NULL;
|
||||
#endif
|
||||
|
||||
/* getsock() will use the descriptor for us */
|
||||
if ((error = getsock(p->p_fd, s, &fp)) != 0)
|
||||
return (error);
|
||||
auio.uio_iov = iov;
|
||||
auio.uio_iovcnt = mp->msg_iovlen;
|
||||
auio.uio_segflg = UIO_USERSPACE;
|
||||
auio.uio_rw = UIO_READ;
|
||||
auio.uio_procp = p;
|
||||
auio.uio_offset = 0; /* XXX */
|
||||
auio.uio_resid = 0;
|
||||
for (i = 0; i < mp->msg_iovlen; i++, iov++) {
|
||||
#if 0
|
||||
/* cannot happen iov_len is unsigned */
|
||||
if (iov->iov_len < 0) {
|
||||
error = EINVAL;
|
||||
goto out1;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Reads return ssize_t because -1 is returned on error.
|
||||
* Therefore we must restrict the length to SSIZE_MAX to
|
||||
* avoid garbage return values.
|
||||
*/
|
||||
auio.uio_resid += iov->iov_len;
|
||||
if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
|
||||
error = EINVAL;
|
||||
goto out1;
|
||||
}
|
||||
}
|
||||
#ifdef KTRACE
|
||||
if (KTRPOINT(p, KTR_GENIO)) {
|
||||
int iovlen = auio.uio_iovcnt * sizeof(struct iovec);
|
||||
|
||||
MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
|
||||
memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
|
||||
}
|
||||
#endif
|
||||
len = auio.uio_resid;
|
||||
so = (struct socket *)fp->f_data;
|
||||
error = (*so->so_receive)(so, &from, &auio, NULL,
|
||||
mp->msg_control ? &control : NULL, &mp->msg_flags);
|
||||
if (error) {
|
||||
if (auio.uio_resid != len && (error == ERESTART ||
|
||||
error == EINTR || error == EWOULDBLOCK))
|
||||
error = 0;
|
||||
}
|
||||
#ifdef KTRACE
|
||||
if (ktriov != NULL) {
|
||||
if (error == 0)
|
||||
ktrgenio(p, s, UIO_READ, ktriov,
|
||||
len - auio.uio_resid, error);
|
||||
FREE(ktriov, M_TEMP);
|
||||
}
|
||||
#endif
|
||||
if (error)
|
||||
goto out;
|
||||
*retsize = len - auio.uio_resid;
|
||||
if (mp->msg_name) {
|
||||
len = mp->msg_namelen;
|
||||
if (len <= 0 || from == 0)
|
||||
len = 0;
|
||||
else {
|
||||
#ifdef COMPAT_OLDSOCK
|
||||
if (mp->msg_flags & MSG_COMPAT)
|
||||
mtod(from, struct osockaddr *)->sa_family =
|
||||
mtod(from, struct sockaddr *)->sa_family;
|
||||
#endif
|
||||
if (len > from->m_len)
|
||||
len = from->m_len;
|
||||
/* else if len < from->m_len ??? */
|
||||
error = copyout(mtod(from, caddr_t),
|
||||
(caddr_t)(u_long)mp->msg_name, (unsigned)len);
|
||||
if (error)
|
||||
goto out;
|
||||
}
|
||||
mp->msg_namelen = len;
|
||||
if (namelenp &&
|
||||
(error = copyout((caddr_t)&len, namelenp, sizeof(int)))) {
|
||||
#ifdef COMPAT_OLDSOCK
|
||||
if (mp->msg_flags & MSG_COMPAT)
|
||||
error = 0; /* old recvfrom didn't check */
|
||||
else
|
||||
#endif
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
if (mp->msg_control) {
|
||||
#ifdef COMPAT_OLDSOCK
|
||||
/*
|
||||
* We assume that old recvmsg calls won't receive access
|
||||
* rights and other control info, esp. as control info
|
||||
* is always optional and those options didn't exist in 4.3.
|
||||
* If we receive rights, trim the cmsghdr; anything else
|
||||
* is tossed.
|
||||
*/
|
||||
if (control && mp->msg_flags & MSG_COMPAT) {
|
||||
if (mtod(control, struct cmsghdr *)->cmsg_level !=
|
||||
SOL_SOCKET ||
|
||||
mtod(control, struct cmsghdr *)->cmsg_type !=
|
||||
SCM_RIGHTS) {
|
||||
mp->msg_controllen = 0;
|
||||
goto out;
|
||||
}
|
||||
control->m_len -= sizeof(struct cmsghdr);
|
||||
control->m_data += sizeof(struct cmsghdr);
|
||||
}
|
||||
#endif
|
||||
len = mp->msg_controllen;
|
||||
if (len <= 0 || control == 0)
|
||||
len = 0;
|
||||
else {
|
||||
struct mbuf *m = control;
|
||||
caddr_t p = (caddr_t)(u_long)mp->msg_control;
|
||||
|
||||
do {
|
||||
i = m->m_len;
|
||||
if (len < i) {
|
||||
mp->msg_flags |= MSG_CTRUNC;
|
||||
i = len;
|
||||
}
|
||||
error = copyout(mtod(m, caddr_t), p,
|
||||
(unsigned)i);
|
||||
if (m->m_next)
|
||||
i = ALIGN(i);
|
||||
p += i;
|
||||
len -= i;
|
||||
if (error != 0 || len <= 0)
|
||||
break;
|
||||
} while ((m = m->m_next) != NULL);
|
||||
len = p - (caddr_t)(u_long)mp->msg_control;
|
||||
}
|
||||
mp->msg_controllen = len;
|
||||
}
|
||||
out:
|
||||
if (from)
|
||||
m_freem(from);
|
||||
if (control)
|
||||
m_freem(control);
|
||||
out1:
|
||||
FILE_UNUSE(fp, p);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_sendmsg(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_sendmsg_args /* {
|
||||
syscallarg(int) s;
|
||||
syscallarg(const netbsd32_msghdrp_t) msg;
|
||||
syscallarg(int) flags;
|
||||
} */ *uap = v;
|
||||
struct msghdr msg;
|
||||
struct netbsd32_msghdr msg32;
|
||||
struct iovec aiov[UIO_SMALLIOV], *iov;
|
||||
int error;
|
||||
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, msg),
|
||||
(caddr_t)&msg32, sizeof(msg32));
|
||||
if (error)
|
||||
return (error);
|
||||
netbsd32_to_msghdr(&msg32, &msg);
|
||||
if ((u_int)msg.msg_iovlen > UIO_SMALLIOV) {
|
||||
if ((u_int)msg.msg_iovlen > IOV_MAX)
|
||||
return (EMSGSIZE);
|
||||
MALLOC(iov, struct iovec *,
|
||||
sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
|
||||
M_WAITOK);
|
||||
} else if ((u_int)msg.msg_iovlen > 0)
|
||||
iov = aiov;
|
||||
else
|
||||
return (EMSGSIZE);
|
||||
error = netbsd32_to_iovecin((struct netbsd32_iovec *)msg.msg_iov,
|
||||
iov, msg.msg_iovlen);
|
||||
if (error)
|
||||
goto done;
|
||||
msg.msg_iov = iov;
|
||||
#ifdef COMPAT_OLDSOCK
|
||||
msg.msg_flags = 0;
|
||||
#endif
|
||||
/* Luckily we can use this directly */
|
||||
error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
|
||||
done:
|
||||
if (iov != aiov)
|
||||
FREE(iov, M_IOV);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_recvfrom(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_recvfrom_args /* {
|
||||
syscallarg(int) s;
|
||||
syscallarg(netbsd32_voidp) buf;
|
||||
syscallarg(netbsd32_size_t) len;
|
||||
syscallarg(int) flags;
|
||||
syscallarg(netbsd32_sockaddrp_t) from;
|
||||
syscallarg(netbsd32_intp) fromlenaddr;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_msghdr msg;
|
||||
struct iovec aiov;
|
||||
int error;
|
||||
|
||||
if (SCARG(uap, fromlenaddr)) {
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, fromlenaddr),
|
||||
(caddr_t)&msg.msg_namelen,
|
||||
sizeof(msg.msg_namelen));
|
||||
if (error)
|
||||
return (error);
|
||||
} else
|
||||
msg.msg_namelen = 0;
|
||||
msg.msg_name = SCARG(uap, from);
|
||||
msg.msg_iov = NULL; /* ignored in recvit32(), uses iov */
|
||||
msg.msg_iovlen = 1;
|
||||
aiov.iov_base = (caddr_t)(u_long)SCARG(uap, buf);
|
||||
aiov.iov_len = (u_long)SCARG(uap, len);
|
||||
msg.msg_control = 0;
|
||||
msg.msg_flags = SCARG(uap, flags);
|
||||
return (recvit32(p, SCARG(uap, s), &msg, &aiov,
|
||||
(caddr_t)(u_long)SCARG(uap, fromlenaddr), retval));
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_sendto(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_sendto_args /* {
|
||||
syscallarg(int) s;
|
||||
syscallarg(const netbsd32_voidp) buf;
|
||||
syscallarg(netbsd32_size_t) len;
|
||||
syscallarg(int) flags;
|
||||
syscallarg(const netbsd32_sockaddrp_t) to;
|
||||
syscallarg(int) tolen;
|
||||
} */ *uap = v;
|
||||
struct msghdr msg;
|
||||
struct iovec aiov;
|
||||
|
||||
msg.msg_name = (caddr_t)(u_long)SCARG(uap, to); /* XXX kills const */
|
||||
msg.msg_namelen = SCARG(uap, tolen);
|
||||
msg.msg_iov = &aiov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = 0;
|
||||
#ifdef COMPAT_OLDSOCK
|
||||
msg.msg_flags = 0;
|
||||
#endif
|
||||
aiov.iov_base = (char *)(u_long)SCARG(uap, buf); /* XXX kills const */
|
||||
aiov.iov_len = SCARG(uap, len);
|
||||
return (sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval));
|
||||
}
|
|
@ -0,0 +1,266 @@
|
|||
/* $NetBSD: netbsd32_sysctl.c,v 1.1 2001/02/08 13:19:34 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
#if defined(_KERNEL) && !defined(_LKM)
|
||||
#include "opt_ddb.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/syscallargs.h>
|
||||
#include <sys/proc.h>
|
||||
#define __SYSCTL_PRIVATE
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
||||
#include <compat/netbsd32/netbsd32.h>
|
||||
#include <compat/netbsd32/netbsd32_syscall.h>
|
||||
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
||||
#include <compat/netbsd32/netbsd32_conv.h>
|
||||
|
||||
#if defined(DDB)
|
||||
#include <ddb/ddbvar.h>
|
||||
#endif
|
||||
|
||||
int uvm_sysctl32(int *, u_int, void *, size_t *, void *, size_t, struct proc *);
|
||||
int kern_sysctl32(int *, u_int, void *, size_t *, void *, size_t, struct proc *);
|
||||
|
||||
/*
|
||||
* uvm_sysctl32: sysctl hook into UVM system, handling special 32-bit
|
||||
* sensitive calls.
|
||||
*/
|
||||
int
|
||||
uvm_sysctl32(name, namelen, oldp, oldlenp, newp, newlen, p)
|
||||
int *name;
|
||||
u_int namelen;
|
||||
void *oldp;
|
||||
size_t *oldlenp;
|
||||
void *newp;
|
||||
size_t newlen;
|
||||
struct proc *p;
|
||||
{
|
||||
struct netbsd32_loadavg av32;
|
||||
|
||||
/* all sysctl names at this level are terminal */
|
||||
if (namelen != 1)
|
||||
return (ENOTDIR); /* overloaded */
|
||||
|
||||
switch (name[0]) {
|
||||
case VM_LOADAVG:
|
||||
netbsd32_from_loadavg(&av32, &averunnable);
|
||||
return (sysctl_rdstruct(oldp, oldlenp, newp, &av32,
|
||||
sizeof(av32)));
|
||||
|
||||
default:
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/*
|
||||
* kern_sysctl32: sysctl hook into KERN system, handling special 32-bit
|
||||
* sensitive calls.
|
||||
*/
|
||||
int
|
||||
kern_sysctl32(name, namelen, oldp, oldlenp, newp, newlen, p)
|
||||
int *name;
|
||||
u_int namelen;
|
||||
void *oldp;
|
||||
size_t *oldlenp;
|
||||
void *newp;
|
||||
size_t newlen;
|
||||
struct proc *p;
|
||||
{
|
||||
struct netbsd32_timeval bt32;
|
||||
|
||||
/* All sysctl names at this level, except for a few, are terminal. */
|
||||
switch (name[0]) {
|
||||
#if 0
|
||||
case KERN_PROC:
|
||||
case KERN_PROC2:
|
||||
case KERN_PROF:
|
||||
case KERN_MBUF:
|
||||
case KERN_PROC_ARGS:
|
||||
case KERN_SYSVIPC_INFO:
|
||||
/* Not terminal. */
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
if (namelen != 1)
|
||||
return (ENOTDIR); /* overloaded */
|
||||
}
|
||||
|
||||
switch (name[0]) {
|
||||
case KERN_BOOTTIME:
|
||||
netbsd32_from_timeval(&boottime, &bt32);
|
||||
return (sysctl_rdstruct(oldp, oldlenp, newp, &bt32,
|
||||
sizeof(struct netbsd32_timeval)));
|
||||
|
||||
default:
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32___sysctl(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32___sysctl_args /* {
|
||||
syscallarg(netbsd32_intp) name;
|
||||
syscallarg(u_int) namelen;
|
||||
syscallarg(netbsd32_voidp) old;
|
||||
syscallarg(netbsd32_size_tp) oldlenp;
|
||||
syscallarg(netbsd32_voidp) new;
|
||||
syscallarg(netbsd32_size_t) newlen;
|
||||
} */ *uap = v;
|
||||
int error;
|
||||
netbsd32_size_t savelen = 0;
|
||||
size_t oldlen = 0;
|
||||
sysctlfn *fn;
|
||||
int name[CTL_MAXNAME];
|
||||
|
||||
/*
|
||||
* Some of these sysctl functions do their own copyin/copyout.
|
||||
* We need to disable or emulate the ones that need their
|
||||
* arguments converted.
|
||||
*/
|
||||
|
||||
if (SCARG(uap, new) != NULL &&
|
||||
(error = suser(p->p_ucred, &p->p_acflag)))
|
||||
return (error);
|
||||
/*
|
||||
* all top-level sysctl names are non-terminal
|
||||
*/
|
||||
if (SCARG(uap, namelen) > CTL_MAXNAME || SCARG(uap, namelen) < 2)
|
||||
return (EINVAL);
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, name), &name,
|
||||
SCARG(uap, namelen) * sizeof(int));
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
switch (name[0]) {
|
||||
case CTL_KERN:
|
||||
switch (name[1]) {
|
||||
#if 0
|
||||
case KERN_FILE:
|
||||
case KERN_NTPTIME:
|
||||
case KERN_SYSVIPC_INFO:
|
||||
#endif
|
||||
case KERN_BOOTTIME:
|
||||
fn = kern_sysctl32;
|
||||
break;
|
||||
default:
|
||||
fn = kern_sysctl;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CTL_HW:
|
||||
fn = hw_sysctl;
|
||||
break;
|
||||
case CTL_VM:
|
||||
switch (name[1]) {
|
||||
case VM_LOADAVG:
|
||||
fn = uvm_sysctl32; /* need to convert a `long' */
|
||||
break;
|
||||
default:
|
||||
fn = uvm_sysctl;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CTL_NET:
|
||||
fn = net_sysctl;
|
||||
break;
|
||||
case CTL_VFS:
|
||||
fn = vfs_sysctl;
|
||||
break;
|
||||
case CTL_MACHDEP:
|
||||
fn = cpu_sysctl;
|
||||
break;
|
||||
#ifdef DEBUG
|
||||
case CTL_DEBUG:
|
||||
fn = debug_sysctl;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DDB
|
||||
case CTL_DDB:
|
||||
fn = ddb_sysctl;
|
||||
break;
|
||||
#endif
|
||||
case CTL_PROC:
|
||||
fn = proc_sysctl;
|
||||
break;
|
||||
default:
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX Hey, we wire `old', but what about `new'?
|
||||
*/
|
||||
|
||||
if (SCARG(uap, oldlenp) &&
|
||||
(error = copyin((caddr_t)(u_long)SCARG(uap, oldlenp), &savelen,
|
||||
sizeof(savelen))))
|
||||
return (error);
|
||||
if (SCARG(uap, old) != NULL) {
|
||||
error = lockmgr(&sysctl_memlock, LK_EXCLUSIVE, NULL);
|
||||
if (error)
|
||||
return (error);
|
||||
if (uvm_vslock(p, (void *)(u_long)SCARG(uap, old), savelen,
|
||||
VM_PROT_READ|VM_PROT_WRITE) != KERN_SUCCESS) {
|
||||
(void) lockmgr(&sysctl_memlock, LK_RELEASE, NULL);
|
||||
return (EFAULT);
|
||||
}
|
||||
oldlen = savelen;
|
||||
}
|
||||
error = (*fn)(name + 1, SCARG(uap, namelen) - 1,
|
||||
(void *)(u_long)SCARG(uap, old), &oldlen,
|
||||
(void *)(u_long)SCARG(uap, new), SCARG(uap, newlen), p);
|
||||
if (SCARG(uap, old) != NULL) {
|
||||
uvm_vsunlock(p, (void *)(u_long)SCARG(uap, old), savelen);
|
||||
(void) lockmgr(&sysctl_memlock, LK_RELEASE, NULL);
|
||||
}
|
||||
savelen = oldlen;
|
||||
if (error)
|
||||
return (error);
|
||||
if (SCARG(uap, oldlenp))
|
||||
error = copyout(&savelen,
|
||||
(caddr_t)(u_long)SCARG(uap, oldlenp), sizeof(savelen));
|
||||
return (error);
|
||||
}
|
|
@ -0,0 +1,644 @@
|
|||
/* $NetBSD: netbsd32_time.c,v 1.1 2001/02/08 13:19:34 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
#if defined(_KERNEL) && !defined(_LKM)
|
||||
#include "opt_ntp.h"
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/resourcevar.h>
|
||||
|
||||
#include <compat/netbsd32/netbsd32.h>
|
||||
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
||||
#include <compat/netbsd32/netbsd32_conv.h>
|
||||
|
||||
#ifdef NTP
|
||||
int
|
||||
netbsd32_ntp_gettime(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_ntp_gettime_args /* {
|
||||
syscallarg(netbsd32_ntptimevalp_t) ntvp;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_ntptimeval ntv32;
|
||||
struct timeval atv;
|
||||
struct ntptimeval ntv;
|
||||
int error = 0;
|
||||
int s;
|
||||
|
||||
/* The following are NTP variables */
|
||||
extern long time_maxerror;
|
||||
extern long time_esterror;
|
||||
extern int time_status;
|
||||
extern int time_state; /* clock state */
|
||||
extern int time_status; /* clock status bits */
|
||||
|
||||
if (SCARG(uap, ntvp)) {
|
||||
s = splclock();
|
||||
#ifdef EXT_CLOCK
|
||||
/*
|
||||
* The microtime() external clock routine returns a
|
||||
* status code. If less than zero, we declare an error
|
||||
* in the clock status word and return the kernel
|
||||
* (software) time variable. While there are other
|
||||
* places that call microtime(), this is the only place
|
||||
* that matters from an application point of view.
|
||||
*/
|
||||
if (microtime(&atv) < 0) {
|
||||
time_status |= STA_CLOCKERR;
|
||||
ntv.time = time;
|
||||
} else
|
||||
time_status &= ~STA_CLOCKERR;
|
||||
#else /* EXT_CLOCK */
|
||||
microtime(&atv);
|
||||
#endif /* EXT_CLOCK */
|
||||
ntv.time = atv;
|
||||
ntv.maxerror = time_maxerror;
|
||||
ntv.esterror = time_esterror;
|
||||
(void) splx(s);
|
||||
|
||||
netbsd32_from_timeval(&ntv.time, &ntv32.time);
|
||||
ntv32.maxerror = (netbsd32_long)ntv.maxerror;
|
||||
ntv32.esterror = (netbsd32_long)ntv.esterror;
|
||||
error = copyout((caddr_t)&ntv32, (caddr_t)(u_long)SCARG(uap, ntvp),
|
||||
sizeof(ntv32));
|
||||
}
|
||||
if (!error) {
|
||||
|
||||
/*
|
||||
* Status word error decode. If any of these conditions
|
||||
* occur, an error is returned, instead of the status
|
||||
* word. Most applications will care only about the fact
|
||||
* the system clock may not be trusted, not about the
|
||||
* details.
|
||||
*
|
||||
* Hardware or software error
|
||||
*/
|
||||
if ((time_status & (STA_UNSYNC | STA_CLOCKERR)) ||
|
||||
|
||||
/*
|
||||
* PPS signal lost when either time or frequency
|
||||
* synchronization requested
|
||||
*/
|
||||
(time_status & (STA_PPSFREQ | STA_PPSTIME) &&
|
||||
!(time_status & STA_PPSSIGNAL)) ||
|
||||
|
||||
/*
|
||||
* PPS jitter exceeded when time synchronization
|
||||
* requested
|
||||
*/
|
||||
(time_status & STA_PPSTIME &&
|
||||
time_status & STA_PPSJITTER) ||
|
||||
|
||||
/*
|
||||
* PPS wander exceeded or calibration error when
|
||||
* frequency synchronization requested
|
||||
*/
|
||||
(time_status & STA_PPSFREQ &&
|
||||
time_status & (STA_PPSWANDER | STA_PPSERROR)))
|
||||
*retval = TIME_ERROR;
|
||||
else
|
||||
*retval = time_state;
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_ntp_adjtime(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_ntp_adjtime_args /* {
|
||||
syscallarg(netbsd32_timexp_t) tp;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_timex ntv32;
|
||||
struct timex ntv;
|
||||
int error = 0;
|
||||
int modes;
|
||||
int s;
|
||||
extern long time_freq; /* frequency offset (scaled ppm) */
|
||||
extern long time_maxerror;
|
||||
extern long time_esterror;
|
||||
extern int time_state; /* clock state */
|
||||
extern int time_status; /* clock status bits */
|
||||
extern long time_constant; /* pll time constant */
|
||||
extern long time_offset; /* time offset (us) */
|
||||
extern long time_tolerance; /* frequency tolerance (scaled ppm) */
|
||||
extern long time_precision; /* clock precision (us) */
|
||||
|
||||
if ((error = copyin((caddr_t)(u_long)SCARG(uap, tp), (caddr_t)&ntv32,
|
||||
sizeof(ntv32))))
|
||||
return (error);
|
||||
netbsd32_to_timex(&ntv32, &ntv);
|
||||
|
||||
/*
|
||||
* Update selected clock variables - only the superuser can
|
||||
* change anything. Note that there is no error checking here on
|
||||
* the assumption the superuser should know what it is doing.
|
||||
*/
|
||||
modes = ntv.modes;
|
||||
if (modes != 0 && (error = suser(p->p_ucred, &p->p_acflag)))
|
||||
return (error);
|
||||
|
||||
s = splclock();
|
||||
if (modes & MOD_FREQUENCY)
|
||||
#ifdef PPS_SYNC
|
||||
time_freq = ntv.freq - pps_freq;
|
||||
#else /* PPS_SYNC */
|
||||
time_freq = ntv.freq;
|
||||
#endif /* PPS_SYNC */
|
||||
if (modes & MOD_MAXERROR)
|
||||
time_maxerror = ntv.maxerror;
|
||||
if (modes & MOD_ESTERROR)
|
||||
time_esterror = ntv.esterror;
|
||||
if (modes & MOD_STATUS) {
|
||||
time_status &= STA_RONLY;
|
||||
time_status |= ntv.status & ~STA_RONLY;
|
||||
}
|
||||
if (modes & MOD_TIMECONST)
|
||||
time_constant = ntv.constant;
|
||||
if (modes & MOD_OFFSET)
|
||||
hardupdate(ntv.offset);
|
||||
|
||||
/*
|
||||
* Retrieve all clock variables
|
||||
*/
|
||||
if (time_offset < 0)
|
||||
ntv.offset = -(-time_offset >> SHIFT_UPDATE);
|
||||
else
|
||||
ntv.offset = time_offset >> SHIFT_UPDATE;
|
||||
#ifdef PPS_SYNC
|
||||
ntv.freq = time_freq + pps_freq;
|
||||
#else /* PPS_SYNC */
|
||||
ntv.freq = time_freq;
|
||||
#endif /* PPS_SYNC */
|
||||
ntv.maxerror = time_maxerror;
|
||||
ntv.esterror = time_esterror;
|
||||
ntv.status = time_status;
|
||||
ntv.constant = time_constant;
|
||||
ntv.precision = time_precision;
|
||||
ntv.tolerance = time_tolerance;
|
||||
#ifdef PPS_SYNC
|
||||
ntv.shift = pps_shift;
|
||||
ntv.ppsfreq = pps_freq;
|
||||
ntv.jitter = pps_jitter >> PPS_AVG;
|
||||
ntv.stabil = pps_stabil;
|
||||
ntv.calcnt = pps_calcnt;
|
||||
ntv.errcnt = pps_errcnt;
|
||||
ntv.jitcnt = pps_jitcnt;
|
||||
ntv.stbcnt = pps_stbcnt;
|
||||
#endif /* PPS_SYNC */
|
||||
(void)splx(s);
|
||||
|
||||
netbsd32_from_timex(&ntv, &ntv32);
|
||||
error = copyout((caddr_t)&ntv32, (caddr_t)(u_long)SCARG(uap, tp),
|
||||
sizeof(ntv32));
|
||||
if (!error) {
|
||||
|
||||
/*
|
||||
* Status word error decode. See comments in
|
||||
* ntp_gettime() routine.
|
||||
*/
|
||||
if ((time_status & (STA_UNSYNC | STA_CLOCKERR)) ||
|
||||
(time_status & (STA_PPSFREQ | STA_PPSTIME) &&
|
||||
!(time_status & STA_PPSSIGNAL)) ||
|
||||
(time_status & STA_PPSTIME &&
|
||||
time_status & STA_PPSJITTER) ||
|
||||
(time_status & STA_PPSFREQ &&
|
||||
time_status & (STA_PPSWANDER | STA_PPSERROR)))
|
||||
*retval = TIME_ERROR;
|
||||
else
|
||||
*retval = time_state;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
#else
|
||||
int
|
||||
netbsd32_ntp_gettime(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
|
||||
return (ENOSYS);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_ntp_adjtime(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
|
||||
return (ENOSYS);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
netbsd32_setitimer(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_setitimer_args /* {
|
||||
syscallarg(int) which;
|
||||
syscallarg(const netbsd32_itimervalp_t) itv;
|
||||
syscallarg(netbsd32_itimervalp_t) oitv;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_itimerval s32it, *itvp;
|
||||
int which = SCARG(uap, which);
|
||||
struct netbsd32_getitimer_args getargs;
|
||||
struct itimerval aitv;
|
||||
int s, error;
|
||||
|
||||
if ((u_int)which > ITIMER_PROF)
|
||||
return (EINVAL);
|
||||
itvp = (struct netbsd32_itimerval *)(u_long)SCARG(uap, itv);
|
||||
if (itvp && (error = copyin(itvp, &s32it, sizeof(s32it))))
|
||||
return (error);
|
||||
netbsd32_to_itimerval(&s32it, &aitv);
|
||||
if (SCARG(uap, oitv) != NULL) {
|
||||
SCARG(&getargs, which) = which;
|
||||
SCARG(&getargs, itv) = SCARG(uap, oitv);
|
||||
if ((error = netbsd32_getitimer(p, &getargs, retval)) != 0)
|
||||
return (error);
|
||||
}
|
||||
if (itvp == 0)
|
||||
return (0);
|
||||
if (itimerfix(&aitv.it_value) || itimerfix(&aitv.it_interval))
|
||||
return (EINVAL);
|
||||
s = splclock();
|
||||
if (which == ITIMER_REAL) {
|
||||
callout_stop(&p->p_realit_ch);
|
||||
if (timerisset(&aitv.it_value)) {
|
||||
/*
|
||||
* Don't need to check hzto() return value, here.
|
||||
* callout_reset() does it for us.
|
||||
*/
|
||||
timeradd(&aitv.it_value, &time, &aitv.it_value);
|
||||
callout_reset(&p->p_realit_ch, hzto(&aitv.it_value),
|
||||
realitexpire, p);
|
||||
}
|
||||
p->p_realtimer = aitv;
|
||||
} else
|
||||
p->p_stats->p_timer[which] = aitv;
|
||||
splx(s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_getitimer(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_getitimer_args /* {
|
||||
syscallarg(int) which;
|
||||
syscallarg(netbsd32_itimervalp_t) itv;
|
||||
} */ *uap = v;
|
||||
int which = SCARG(uap, which);
|
||||
struct netbsd32_itimerval s32it;
|
||||
struct itimerval aitv;
|
||||
int s;
|
||||
|
||||
if ((u_int)which > ITIMER_PROF)
|
||||
return (EINVAL);
|
||||
s = splclock();
|
||||
if (which == ITIMER_REAL) {
|
||||
/*
|
||||
* Convert from absolute to relative time in .it_value
|
||||
* part of real time timer. If time for real time timer
|
||||
* has passed return 0, else return difference between
|
||||
* current time and time for the timer to go off.
|
||||
*/
|
||||
aitv = p->p_realtimer;
|
||||
if (timerisset(&aitv.it_value)) {
|
||||
if (timercmp(&aitv.it_value, &time, <))
|
||||
timerclear(&aitv.it_value);
|
||||
else
|
||||
timersub(&aitv.it_value, &time, &aitv.it_value);
|
||||
}
|
||||
} else
|
||||
aitv = p->p_stats->p_timer[which];
|
||||
splx(s);
|
||||
netbsd32_from_itimerval(&aitv, &s32it);
|
||||
return (copyout(&s32it, (caddr_t)(u_long)SCARG(uap, itv), sizeof(s32it)));
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_gettimeofday(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_gettimeofday_args /* {
|
||||
syscallarg(netbsd32_timevalp_t) tp;
|
||||
syscallarg(netbsd32_timezonep_t) tzp;
|
||||
} */ *uap = v;
|
||||
struct timeval atv;
|
||||
struct netbsd32_timeval tv32;
|
||||
int error = 0;
|
||||
struct netbsd32_timezone tzfake;
|
||||
|
||||
if (SCARG(uap, tp)) {
|
||||
microtime(&atv);
|
||||
netbsd32_from_timeval(&atv, &tv32);
|
||||
error = copyout(&tv32, (caddr_t)(u_long)SCARG(uap, tp), sizeof(tv32));
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
if (SCARG(uap, tzp)) {
|
||||
/*
|
||||
* NetBSD has no kernel notion of time zone, so we just
|
||||
* fake up a timezone struct and return it if demanded.
|
||||
*/
|
||||
tzfake.tz_minuteswest = 0;
|
||||
tzfake.tz_dsttime = 0;
|
||||
error = copyout(&tzfake, (caddr_t)(u_long)SCARG(uap, tzp), sizeof(tzfake));
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_settimeofday(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_settimeofday_args /* {
|
||||
syscallarg(const netbsd32_timevalp_t) tv;
|
||||
syscallarg(const netbsd32_timezonep_t) tzp;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_timeval atv32;
|
||||
struct timeval atv;
|
||||
int error;
|
||||
|
||||
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
||||
return (error);
|
||||
/* Verify all parameters before changing time. */
|
||||
if (SCARG(uap, tv) && (error = copyin((caddr_t)(u_long)SCARG(uap, tv),
|
||||
&atv32, sizeof(atv32))))
|
||||
return (error);
|
||||
netbsd32_to_timeval(&atv32, &atv);
|
||||
if (SCARG(uap, tv))
|
||||
if ((error = settime(&atv)))
|
||||
return (error);
|
||||
/* don't bother copying the tz in, we don't use it. */
|
||||
/*
|
||||
* NetBSD has no kernel notion of time zone, and only an
|
||||
* obsolete program would try to set it, so we log a warning.
|
||||
*/
|
||||
if (SCARG(uap, tzp))
|
||||
printf("pid %d attempted to set the "
|
||||
"(obsolete) kernel time zone\n", p->p_pid);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_adjtime(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_adjtime_args /* {
|
||||
syscallarg(const netbsd32_timevalp_t) delta;
|
||||
syscallarg(netbsd32_timevalp_t) olddelta;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_timeval atv;
|
||||
int32_t ndelta, ntickdelta, odelta;
|
||||
int s, error;
|
||||
extern long bigadj, timedelta;
|
||||
extern int tickdelta;
|
||||
|
||||
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
||||
return (error);
|
||||
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, delta), &atv, sizeof(struct timeval));
|
||||
if (error)
|
||||
return (error);
|
||||
/*
|
||||
* Compute the total correction and the rate at which to apply it.
|
||||
* Round the adjustment down to a whole multiple of the per-tick
|
||||
* delta, so that after some number of incremental changes in
|
||||
* hardclock(), tickdelta will become zero, lest the correction
|
||||
* overshoot and start taking us away from the desired final time.
|
||||
*/
|
||||
ndelta = atv.tv_sec * 1000000 + atv.tv_usec;
|
||||
if (ndelta > bigadj)
|
||||
ntickdelta = 10 * tickadj;
|
||||
else
|
||||
ntickdelta = tickadj;
|
||||
if (ndelta % ntickdelta)
|
||||
ndelta = ndelta / ntickdelta * ntickdelta;
|
||||
|
||||
/*
|
||||
* To make hardclock()'s job easier, make the per-tick delta negative
|
||||
* if we want time to run slower; then hardclock can simply compute
|
||||
* tick + tickdelta, and subtract tickdelta from timedelta.
|
||||
*/
|
||||
if (ndelta < 0)
|
||||
ntickdelta = -ntickdelta;
|
||||
s = splclock();
|
||||
odelta = timedelta;
|
||||
timedelta = ndelta;
|
||||
tickdelta = ntickdelta;
|
||||
splx(s);
|
||||
|
||||
if (SCARG(uap, olddelta)) {
|
||||
atv.tv_sec = odelta / 1000000;
|
||||
atv.tv_usec = odelta % 1000000;
|
||||
(void) copyout(&atv, (caddr_t)(u_long)SCARG(uap, olddelta),
|
||||
sizeof(atv));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_clock_gettime(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_clock_gettime_args /* {
|
||||
syscallarg(netbsd32_clockid_t) clock_id;
|
||||
syscallarg(netbsd32_timespecp_t) tp;
|
||||
} */ *uap = v;
|
||||
clockid_t clock_id;
|
||||
struct timeval atv;
|
||||
struct timespec ats;
|
||||
struct netbsd32_timespec ts32;
|
||||
|
||||
clock_id = SCARG(uap, clock_id);
|
||||
if (clock_id != CLOCK_REALTIME)
|
||||
return (EINVAL);
|
||||
|
||||
microtime(&atv);
|
||||
TIMEVAL_TO_TIMESPEC(&atv,&ats);
|
||||
netbsd32_from_timespec(&ats, &ts32);
|
||||
|
||||
return copyout(&ts32, (caddr_t)(u_long)SCARG(uap, tp), sizeof(ts32));
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_clock_settime(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_clock_settime_args /* {
|
||||
syscallarg(netbsd32_clockid_t) clock_id;
|
||||
syscallarg(const netbsd32_timespecp_t) tp;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_timespec ts32;
|
||||
clockid_t clock_id;
|
||||
struct timeval atv;
|
||||
struct timespec ats;
|
||||
int error;
|
||||
|
||||
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
||||
return (error);
|
||||
|
||||
clock_id = SCARG(uap, clock_id);
|
||||
if (clock_id != CLOCK_REALTIME)
|
||||
return (EINVAL);
|
||||
|
||||
if ((error = copyin((caddr_t)(u_long)SCARG(uap, tp), &ts32, sizeof(ts32))) != 0)
|
||||
return (error);
|
||||
|
||||
netbsd32_to_timespec(&ts32, &ats);
|
||||
TIMESPEC_TO_TIMEVAL(&atv,&ats);
|
||||
if ((error = settime(&atv)))
|
||||
return (error);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_clock_getres(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_clock_getres_args /* {
|
||||
syscallarg(netbsd32_clockid_t) clock_id;
|
||||
syscallarg(netbsd32_timespecp_t) tp;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_timespec ts32;
|
||||
clockid_t clock_id;
|
||||
struct timespec ts;
|
||||
int error = 0;
|
||||
|
||||
clock_id = SCARG(uap, clock_id);
|
||||
if (clock_id != CLOCK_REALTIME)
|
||||
return (EINVAL);
|
||||
|
||||
if (SCARG(uap, tp)) {
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 1000000000 / hz;
|
||||
|
||||
netbsd32_from_timespec(&ts, &ts32);
|
||||
error = copyout(&ts, (caddr_t)(u_long)SCARG(uap, tp), sizeof(ts));
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_nanosleep(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_nanosleep_args /* {
|
||||
syscallarg(const netbsd32_timespecp_t) rqtp;
|
||||
syscallarg(netbsd32_timespecp_t) rmtp;
|
||||
} */ *uap = v;
|
||||
static int nanowait;
|
||||
struct netbsd32_timespec ts32;
|
||||
struct timespec rqt;
|
||||
struct timespec rmt;
|
||||
struct timeval atv, utv;
|
||||
int error, s, timo;
|
||||
|
||||
error = copyin((caddr_t)(u_long)SCARG(uap, rqtp), (caddr_t)&ts32,
|
||||
sizeof(ts32));
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
netbsd32_to_timespec(&ts32, &rqt);
|
||||
TIMESPEC_TO_TIMEVAL(&atv,&rqt)
|
||||
if (itimerfix(&atv))
|
||||
return (EINVAL);
|
||||
|
||||
s = splclock();
|
||||
timeradd(&atv,&time,&atv);
|
||||
timo = hzto(&atv);
|
||||
/*
|
||||
* Avoid inadvertantly sleeping forever
|
||||
*/
|
||||
if (timo == 0)
|
||||
timo = 1;
|
||||
splx(s);
|
||||
|
||||
error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo);
|
||||
if (error == ERESTART)
|
||||
error = EINTR;
|
||||
if (error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
|
||||
if (SCARG(uap, rmtp)) {
|
||||
int error;
|
||||
|
||||
s = splclock();
|
||||
utv = time;
|
||||
splx(s);
|
||||
|
||||
timersub(&atv, &utv, &utv);
|
||||
if (utv.tv_sec < 0)
|
||||
timerclear(&utv);
|
||||
|
||||
TIMEVAL_TO_TIMESPEC(&utv,&rmt);
|
||||
netbsd32_from_timespec(&rmt, &ts32);
|
||||
error = copyout((caddr_t)&ts32, (caddr_t)(u_long)SCARG(uap,rmtp),
|
||||
sizeof(ts32));
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
|
@ -0,0 +1,204 @@
|
|||
/* $NetBSD: netbsd32_wait.c,v 1.1 2001/02/08 13:19:34 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
* 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/resourcevar.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/pool.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <compat/netbsd32/netbsd32.h>
|
||||
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
||||
#include <compat/netbsd32/netbsd32_conv.h>
|
||||
|
||||
int
|
||||
netbsd32_wait4(q, v, retval)
|
||||
struct proc *q;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_wait4_args /* {
|
||||
syscallarg(int) pid;
|
||||
syscallarg(netbsd32_intp) status;
|
||||
syscallarg(int) options;
|
||||
syscallarg(netbsd32_rusagep_t) rusage;
|
||||
} */ *uap = v;
|
||||
struct netbsd32_rusage ru32;
|
||||
int nfound;
|
||||
struct proc *p, *t;
|
||||
int status, error;
|
||||
|
||||
if (SCARG(uap, pid) == 0)
|
||||
SCARG(uap, pid) = -q->p_pgid;
|
||||
if (SCARG(uap, options) &~ (WUNTRACED|WNOHANG))
|
||||
return (EINVAL);
|
||||
|
||||
loop:
|
||||
nfound = 0;
|
||||
for (p = q->p_children.lh_first; p != 0; p = p->p_sibling.le_next) {
|
||||
if (SCARG(uap, pid) != WAIT_ANY &&
|
||||
p->p_pid != SCARG(uap, pid) &&
|
||||
p->p_pgid != -SCARG(uap, pid))
|
||||
continue;
|
||||
nfound++;
|
||||
if (p->p_stat == SZOMB) {
|
||||
retval[0] = p->p_pid;
|
||||
|
||||
if (SCARG(uap, status)) {
|
||||
status = p->p_xstat; /* convert to int */
|
||||
error = copyout((caddr_t)&status,
|
||||
(caddr_t)(u_long)SCARG(uap, status),
|
||||
sizeof(status));
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
if (SCARG(uap, rusage)) {
|
||||
netbsd32_from_rusage(p->p_ru, &ru32);
|
||||
if ((error = copyout((caddr_t)&ru32,
|
||||
(caddr_t)(u_long)SCARG(uap, rusage),
|
||||
sizeof(struct netbsd32_rusage))))
|
||||
return (error);
|
||||
}
|
||||
/*
|
||||
* If we got the child via ptrace(2) or procfs, and
|
||||
* the parent is different (meaning the process was
|
||||
* attached, rather than run as a child), then we need
|
||||
* to give it back to the old parent, and send the
|
||||
* parent a SIGCHLD. The rest of the cleanup will be
|
||||
* done when the old parent waits on the child.
|
||||
*/
|
||||
if ((p->p_flag & P_TRACED) &&
|
||||
p->p_oppid != p->p_pptr->p_pid) {
|
||||
t = pfind(p->p_oppid);
|
||||
proc_reparent(p, t ? t : initproc);
|
||||
p->p_oppid = 0;
|
||||
p->p_flag &= ~(P_TRACED|P_WAITED|P_FSTRACE);
|
||||
psignal(p->p_pptr, SIGCHLD);
|
||||
wakeup((caddr_t)p->p_pptr);
|
||||
return (0);
|
||||
}
|
||||
p->p_xstat = 0;
|
||||
ruadd(&q->p_stats->p_cru, p->p_ru);
|
||||
pool_put(&rusage_pool, p->p_ru);
|
||||
|
||||
/*
|
||||
* Finally finished with old proc entry.
|
||||
* Unlink it from its process group and free it.
|
||||
*/
|
||||
leavepgrp(p);
|
||||
|
||||
LIST_REMOVE(p, p_list); /* off zombproc */
|
||||
|
||||
LIST_REMOVE(p, p_sibling);
|
||||
|
||||
/*
|
||||
* Decrement the count of procs running with this uid.
|
||||
*/
|
||||
(void)chgproccnt(p->p_cred->p_ruid, -1);
|
||||
|
||||
/*
|
||||
* Free up credentials.
|
||||
*/
|
||||
if (--p->p_cred->p_refcnt == 0) {
|
||||
crfree(p->p_cred->pc_ucred);
|
||||
pool_put(&pcred_pool, p->p_cred);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release reference to text vnode
|
||||
*/
|
||||
if (p->p_textvp)
|
||||
vrele(p->p_textvp);
|
||||
|
||||
pool_put(&proc_pool, p);
|
||||
nprocs--;
|
||||
return (0);
|
||||
}
|
||||
if (p->p_stat == SSTOP && (p->p_flag & P_WAITED) == 0 &&
|
||||
(p->p_flag & P_TRACED || SCARG(uap, options) & WUNTRACED)) {
|
||||
p->p_flag |= P_WAITED;
|
||||
retval[0] = p->p_pid;
|
||||
|
||||
if (SCARG(uap, status)) {
|
||||
status = W_STOPCODE(p->p_xstat);
|
||||
error = copyout((caddr_t)&status,
|
||||
(caddr_t)(u_long)SCARG(uap, status),
|
||||
sizeof(status));
|
||||
} else
|
||||
error = 0;
|
||||
return (error);
|
||||
}
|
||||
}
|
||||
if (nfound == 0)
|
||||
return (ECHILD);
|
||||
if (SCARG(uap, options) & WNOHANG) {
|
||||
retval[0] = 0;
|
||||
return (0);
|
||||
}
|
||||
if ((error = tsleep((caddr_t)q, PWAIT | PCATCH, "wait", 0)) != 0)
|
||||
return (error);
|
||||
goto loop;
|
||||
}
|
||||
|
||||
int
|
||||
netbsd32_getrusage(p, v, retval)
|
||||
struct proc *p;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct netbsd32_getrusage_args /* {
|
||||
syscallarg(int) who;
|
||||
syscallarg(netbsd32_rusagep_t) rusage;
|
||||
} */ *uap = v;
|
||||
struct rusage *rup;
|
||||
struct netbsd32_rusage ru;
|
||||
|
||||
switch (SCARG(uap, who)) {
|
||||
|
||||
case RUSAGE_SELF:
|
||||
rup = &p->p_stats->p_ru;
|
||||
calcru(p, &rup->ru_utime, &rup->ru_stime, NULL);
|
||||
break;
|
||||
|
||||
case RUSAGE_CHILDREN:
|
||||
rup = &p->p_stats->p_cru;
|
||||
break;
|
||||
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
netbsd32_from_rusage(rup, &ru);
|
||||
return (copyout(&ru, (caddr_t)(u_long)SCARG(uap, rusage), sizeof(ru)));
|
||||
}
|
Loading…
Reference in New Issue