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