1121982Sjhb/* $NetBSD: netbsd32_kern_proc.c,v 1.6 2020/09/05 16:30:10 riastradh Exp $ */ 2121982Sjhb 3121982Sjhb/*- 4121982Sjhb * Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc. 5121982Sjhb * All rights reserved. 6121982Sjhb * 7121982Sjhb * This code is derived from software contributed to The NetBSD Foundation 8121982Sjhb * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9121982Sjhb * NASA Ames Research Center, and by Andrew Doran. 10121982Sjhb * 11121982Sjhb * Redistribution and use in source and binary forms, with or without 12121982Sjhb * modification, are permitted provided that the following conditions 13121982Sjhb * are met: 14121982Sjhb * 1. Redistributions of source code must retain the above copyright 15121982Sjhb * notice, this list of conditions and the following disclaimer. 16121982Sjhb * 2. Redistributions in binary form must reproduce the above copyright 17121982Sjhb * notice, this list of conditions and the following disclaimer in the 18121982Sjhb * documentation and/or other materials provided with the distribution. 19121982Sjhb * 20121982Sjhb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21121982Sjhb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22121982Sjhb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23121982Sjhb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24121982Sjhb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25121982Sjhb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26121982Sjhb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27121982Sjhb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28121982Sjhb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29121982Sjhb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30121982Sjhb * POSSIBILITY OF SUCH DAMAGE. 31121982Sjhb */ 32121982Sjhb 33121982Sjhb/* 34151979Sjhb * Copyright (c) 1982, 1986, 1989, 1991, 1993 35151979Sjhb * The Regents of the University of California. All rights reserved. 36151979Sjhb * 37151979Sjhb * Redistribution and use in source and binary forms, with or without 38151979Sjhb * modification, are permitted provided that the following conditions 39151979Sjhb * are met: 40151979Sjhb * 1. Redistributions of source code must retain the above copyright 41151979Sjhb * notice, this list of conditions and the following disclaimer. 42151979Sjhb * 2. Redistributions in binary form must reproduce the above copyright 43151979Sjhb * notice, this list of conditions and the following disclaimer in the 44151979Sjhb * documentation and/or other materials provided with the distribution. 45151979Sjhb * 3. Neither the name of the University nor the names of its contributors 46164265Sjhb * may be used to endorse or promote products derived from this software 47164265Sjhb * without specific prior written permission. 48164265Sjhb * 49151979Sjhb * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50187880Sjeff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51164265Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52164265Sjhb * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53121982Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54151979Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55164265Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56164265Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57164265Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58164265Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59164265Sjhb * SUCH DAMAGE. 60151979Sjhb * 61151979Sjhb * @(#)kern_proc.c 8.7 (Berkeley) 2/14/95 62151979Sjhb */ 63151979Sjhb 64151979Sjhb#include <sys/cdefs.h> 65151979Sjhb__KERNEL_RCSID(0, "$NetBSD: netbsd32_kern_proc.c,v 1.6 2020/09/05 16:30:10 riastradh Exp $"); 66163212Sjhb 67163212Sjhb#ifdef _KERNEL_OPT 68151979Sjhb#include "opt_kstack.h" 69151979Sjhb#include "opt_maxuprc.h" 70151979Sjhb#include "opt_dtrace.h" 71121982Sjhb#include "opt_compat_netbsd32.h" 72121982Sjhb#endif 73121982Sjhb 74121982Sjhb#include <sys/param.h> 75121982Sjhb#include <sys/systm.h> 76121982Sjhb#include <sys/kernel.h> 77121982Sjhb#include <sys/proc.h> 78121982Sjhb#include <sys/resourcevar.h> 79121982Sjhb#include <sys/buf.h> 80121982Sjhb#include <sys/acct.h> 81121982Sjhb#include <sys/wait.h> 82121982Sjhb#include <sys/file.h> 83121982Sjhb#include <ufs/ufs/quota.h> 84121982Sjhb#include <sys/uio.h> 85121982Sjhb#include <sys/pool.h> 86133907Speter#include <sys/pset.h> 87121982Sjhb#include <sys/mbuf.h> 88121982Sjhb#include <sys/ioctl.h> 89169391Sjhb#include <sys/tty.h> 90121982Sjhb#include <sys/signalvar.h> 91121982Sjhb#include <sys/ras.h> 92163219Sjhb#include <sys/filedesc.h> 93163219Sjhb#include <sys/syscall_stats.h> 94129284Speter#include <sys/kauth.h> 95129284Speter#include <sys/sleepq.h> 96156124Sjhb#include <sys/atomic.h> 97163219Sjhb#include <sys/kmem.h> 98121982Sjhb#include <sys/namei.h> 99121982Sjhb#include <sys/dtrace_bsd.h> 100133907Speter#include <sys/sysctl.h> 101133907Speter#include <sys/exec.h> 102133907Speter#include <sys/cpu.h> 103133907Speter#include <sys/compat_stub.h> 104133907Speter 105133907Speter#include <compat/netbsd32/netbsd32.h> 106121982Sjhb#include <compat/netbsd32/netbsd32_kern_proc.h> 107121982Sjhb 108121982Sjhbstatic int 109121982Sjhbcopyin_psstrings_32(struct proc *p, struct ps_strings *arginfo) 110121982Sjhb{ 111121982Sjhb struct ps_strings32 arginfo32; 112121982Sjhb 113121982Sjhb int error = copyin_proc(p, (void *)p->p_psstrp, &arginfo32, 114151658Sjhb sizeof(arginfo32)); 115121982Sjhb if (error) 116121982Sjhb return error; 117121982Sjhb arginfo->ps_argvstr = (void *)(uintptr_t)arginfo32.ps_argvstr; 118169391Sjhb arginfo->ps_nargvstr = arginfo32.ps_nargvstr; 119121982Sjhb arginfo->ps_envstr = (void *)(uintptr_t)arginfo32.ps_envstr; 120121982Sjhb arginfo->ps_nenvstr = arginfo32.ps_nenvstr; 121153241Sjhb return 0; 122121982Sjhb} 123121982Sjhb 124140555Speterstatic vaddr_t 125121982Sjhbget_base32(char **argv, size_t i) 126163219Sjhb{ 127163219Sjhb 128163219Sjhb netbsd32_charp *argv32; 129129284Speter 130129284Speter argv32 = (netbsd32_charp *)argv; 131129284Speter return (vaddr_t)NETBSD32PTR64(argv32[i]); 132129284Speter} 133129284Speter 134156124Sjhbvoid 135167273Sjhbnetbsd32_kern_proc_32_init(void) 136156124Sjhb{ 137166901Spiso 138166901Spiso#if !defined(_RUMPSERVER) 139166901Spiso MODULE_HOOK_SET(kern_proc32_copyin_hook, copyin_psstrings_32); 140177181Sjhb MODULE_HOOK_SET(kern_proc32_base_hook, get_base32); 141177181Sjhb#endif 142177181Sjhb} 143129284Speter 144129284Spetervoid 145153241Sjhbnetbsd32_kern_proc_32_fini(void) 146121982Sjhb{ 147163219Sjhb 148121982Sjhb#if !defined(_RUMPSERVER) 149121982Sjhb MODULE_HOOK_UNSET(kern_proc32_copyin_hook); 150121982Sjhb MODULE_HOOK_UNSET(kern_proc32_base_hook); 151121982Sjhb#endif 152140555Speter} 153169391Sjhb