Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_kern_proc.c revision 1.1.2.3
      1 /*	$NetBSD: netbsd32_kern_proc.c,v 1.1.2.3 2018/09/23 11:50:03 pgoyette Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center, and by Andrew Doran.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Copyright (c) 1982, 1986, 1989, 1991, 1993
     35  *	The Regents of the University of California.  All rights reserved.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  * 3. Neither the name of the University nor the names of its contributors
     46  *    may be used to endorse or promote products derived from this software
     47  *    without specific prior written permission.
     48  *
     49  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59  * SUCH DAMAGE.
     60  *
     61  *	@(#)kern_proc.c	8.7 (Berkeley) 2/14/95
     62  */
     63 
     64 #include <sys/cdefs.h>
     65 __KERNEL_RCSID(0, "$NetBSD: netbsd32_kern_proc.c,v 1.1.2.3 2018/09/23 11:50:03 pgoyette Exp $");
     66 
     67 #ifdef _KERNEL_OPT
     68 #include "opt_kstack.h"
     69 #include "opt_maxuprc.h"
     70 #include "opt_dtrace.h"
     71 #include "opt_compat_netbsd32.h"
     72 #endif
     73 
     74 #include <sys/param.h>
     75 #include <sys/systm.h>
     76 #include <sys/kernel.h>
     77 #include <sys/proc.h>
     78 #include <sys/resourcevar.h>
     79 #include <sys/buf.h>
     80 #include <sys/acct.h>
     81 #include <sys/wait.h>
     82 #include <sys/file.h>
     83 #include <ufs/ufs/quota.h>
     84 #include <sys/uio.h>
     85 #include <sys/pool.h>
     86 #include <sys/pset.h>
     87 #include <sys/mbuf.h>
     88 #include <sys/ioctl.h>
     89 #include <sys/tty.h>
     90 #include <sys/signalvar.h>
     91 #include <sys/ras.h>
     92 #include <sys/filedesc.h>
     93 #include <sys/syscall_stats.h>
     94 #include <sys/kauth.h>
     95 #include <sys/sleepq.h>
     96 #include <sys/atomic.h>
     97 #include <sys/kmem.h>
     98 #include <sys/namei.h>
     99 #include <sys/dtrace_bsd.h>
    100 #include <sys/sysctl.h>
    101 #include <sys/exec.h>
    102 #include <sys/cpu.h>
    103 
    104 #include <uvm/uvm_extern.h>
    105 #include <uvm/uvm.h>
    106 
    107 #include <compat/netbsd32/netbsd32.h>
    108 
    109 static int
    110 copyin_psstrings_32(struct proc *p, struct ps_strings *arginfo)
    111 {
    112 	struct ps_strings32 arginfo32;
    113 
    114 	int error = copyin_proc(p, (void *)p->p_psstrp, &arginfo32,
    115 	    sizeof(arginfo32));
    116 	if (error)
    117 		return error;
    118 	arginfo->ps_argvstr = (void *)(uintptr_t)arginfo32.ps_argvstr;
    119 	arginfo->ps_nargvstr = arginfo32.ps_nargvstr;
    120 	arginfo->ps_envstr = (void *)(uintptr_t)arginfo32.ps_envstr;
    121 	arginfo->ps_nenvstr = arginfo32.ps_nenvstr;
    122 	return 0;
    123 }
    124 
    125 static int
    126 get_base32(char **argv, size_t i, vaddr_t *base)
    127 {
    128 
    129 	netbsd32_charp *argv32;
    130 
    131 	argv32 = (netbsd32_charp *)argv;
    132 	*base = (vaddr_t)NETBSD32PTR64(argv32[i]);
    133 
    134 	return 0;
    135 }
    136 
    137 #if !defined(_RUMPSERVER)
    138 MODULE_SET_HOOK2(kern_proc_32_hook, "kern_proc_32",
    139     copyin_psstrings_32, get_base32);
    140 MODULE_UNSET_HOOK2(kern_proc_32_hook);
    141 #endif
    142 
    143 void
    144 kern_proc_32_init(void)
    145 {
    146 
    147 #if !defined(_RUMPSERVER)
    148 	kern_proc_32_hook_set();
    149 #endif
    150 }
    151 
    152 void
    153 kern_proc_32_fini(void)
    154 {
    155 
    156 #if !defined(_RUMPSERVER)
    157 	kern_proc_32_hook_unset();
    158 #endif
    159 }
    160