1 /* $NetBSD: netbsd32_kern_proc.c,v 1.6 2020/09/05 16:30:10 riastradh 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.6 2020/09/05 16:30:10 riastradh 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 #include <sys/compat_stub.h>
104
105 #include <compat/netbsd32/netbsd32.h>
106 #include <compat/netbsd32/netbsd32_kern_proc.h>
107
108 static int
copyin_psstrings_32(struct proc * p,struct ps_strings * arginfo)109 copyin_psstrings_32(struct proc *p, struct ps_strings *arginfo)
110 {
111 struct ps_strings32 arginfo32;
112
113 int error = copyin_proc(p, (void *)p->p_psstrp, &arginfo32,
114 sizeof(arginfo32));
115 if (error)
116 return error;
117 arginfo->ps_argvstr = (void *)(uintptr_t)arginfo32.ps_argvstr;
118 arginfo->ps_nargvstr = arginfo32.ps_nargvstr;
119 arginfo->ps_envstr = (void *)(uintptr_t)arginfo32.ps_envstr;
120 arginfo->ps_nenvstr = arginfo32.ps_nenvstr;
121 return 0;
122 }
123
124 static vaddr_t
get_base32(char ** argv,size_t i)125 get_base32(char **argv, size_t i)
126 {
127
128 netbsd32_charp *argv32;
129
130 argv32 = (netbsd32_charp *)argv;
131 return (vaddr_t)NETBSD32PTR64(argv32[i]);
132 }
133
134 void
netbsd32_kern_proc_32_init(void)135 netbsd32_kern_proc_32_init(void)
136 {
137
138 #if !defined(_RUMPSERVER)
139 MODULE_HOOK_SET(kern_proc32_copyin_hook, copyin_psstrings_32);
140 MODULE_HOOK_SET(kern_proc32_base_hook, get_base32);
141 #endif
142 }
143
144 void
netbsd32_kern_proc_32_fini(void)145 netbsd32_kern_proc_32_fini(void)
146 {
147
148 #if !defined(_RUMPSERVER)
149 MODULE_HOOK_UNSET(kern_proc32_copyin_hook);
150 MODULE_HOOK_UNSET(kern_proc32_base_hook);
151 #endif
152 }
153