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