netbsd32_kern_proc.c revision 1.1.2.7 1 1.1.2.7 pgoyette /* $NetBSD: netbsd32_kern_proc.c,v 1.1.2.7 2019/01/22 07:42:40 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.7 pgoyette __KERNEL_RCSID(0, "$NetBSD: netbsd32_kern_proc.c,v 1.1.2.7 2019/01/22 07:42:40 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 #include <sys/param.h>
75 1.1.2.1 pgoyette #include <sys/systm.h>
76 1.1.2.1 pgoyette #include <sys/kernel.h>
77 1.1.2.1 pgoyette #include <sys/proc.h>
78 1.1.2.1 pgoyette #include <sys/resourcevar.h>
79 1.1.2.1 pgoyette #include <sys/buf.h>
80 1.1.2.1 pgoyette #include <sys/acct.h>
81 1.1.2.1 pgoyette #include <sys/wait.h>
82 1.1.2.1 pgoyette #include <sys/file.h>
83 1.1.2.1 pgoyette #include <ufs/ufs/quota.h>
84 1.1.2.1 pgoyette #include <sys/uio.h>
85 1.1.2.1 pgoyette #include <sys/pool.h>
86 1.1.2.1 pgoyette #include <sys/pset.h>
87 1.1.2.1 pgoyette #include <sys/mbuf.h>
88 1.1.2.1 pgoyette #include <sys/ioctl.h>
89 1.1.2.1 pgoyette #include <sys/tty.h>
90 1.1.2.1 pgoyette #include <sys/signalvar.h>
91 1.1.2.1 pgoyette #include <sys/ras.h>
92 1.1.2.1 pgoyette #include <sys/filedesc.h>
93 1.1.2.1 pgoyette #include <sys/syscall_stats.h>
94 1.1.2.1 pgoyette #include <sys/kauth.h>
95 1.1.2.1 pgoyette #include <sys/sleepq.h>
96 1.1.2.1 pgoyette #include <sys/atomic.h>
97 1.1.2.1 pgoyette #include <sys/kmem.h>
98 1.1.2.1 pgoyette #include <sys/namei.h>
99 1.1.2.1 pgoyette #include <sys/dtrace_bsd.h>
100 1.1.2.1 pgoyette #include <sys/sysctl.h>
101 1.1.2.1 pgoyette #include <sys/exec.h>
102 1.1.2.1 pgoyette #include <sys/cpu.h>
103 1.1.2.4 pgoyette #include <sys/compat_stub.h>
104 1.1.2.1 pgoyette
105 1.1.2.1 pgoyette #include <uvm/uvm_extern.h>
106 1.1.2.1 pgoyette #include <uvm/uvm.h>
107 1.1.2.1 pgoyette
108 1.1.2.1 pgoyette #include <compat/netbsd32/netbsd32.h>
109 1.1.2.4 pgoyette #include <compat/netbsd32/netbsd32_kern_proc.h>
110 1.1.2.1 pgoyette
111 1.1.2.1 pgoyette static int
112 1.1.2.1 pgoyette copyin_psstrings_32(struct proc *p, struct ps_strings *arginfo)
113 1.1.2.1 pgoyette {
114 1.1.2.1 pgoyette struct ps_strings32 arginfo32;
115 1.1.2.1 pgoyette
116 1.1.2.1 pgoyette int error = copyin_proc(p, (void *)p->p_psstrp, &arginfo32,
117 1.1.2.1 pgoyette sizeof(arginfo32));
118 1.1.2.1 pgoyette if (error)
119 1.1.2.1 pgoyette return error;
120 1.1.2.1 pgoyette arginfo->ps_argvstr = (void *)(uintptr_t)arginfo32.ps_argvstr;
121 1.1.2.1 pgoyette arginfo->ps_nargvstr = arginfo32.ps_nargvstr;
122 1.1.2.1 pgoyette arginfo->ps_envstr = (void *)(uintptr_t)arginfo32.ps_envstr;
123 1.1.2.1 pgoyette arginfo->ps_nenvstr = arginfo32.ps_nenvstr;
124 1.1.2.1 pgoyette return 0;
125 1.1.2.1 pgoyette }
126 1.1.2.1 pgoyette
127 1.1.2.7 pgoyette static vaddr_t
128 1.1.2.7 pgoyette get_base32(char **argv, size_t i)
129 1.1.2.1 pgoyette {
130 1.1.2.1 pgoyette
131 1.1.2.1 pgoyette netbsd32_charp *argv32;
132 1.1.2.1 pgoyette
133 1.1.2.1 pgoyette argv32 = (netbsd32_charp *)argv;
134 1.1.2.7 pgoyette return (vaddr_t)NETBSD32PTR64(argv32[i]);
135 1.1.2.1 pgoyette }
136 1.1.2.1 pgoyette
137 1.1.2.2 pgoyette #if !defined(_RUMPSERVER)
138 1.1.2.5 pgoyette MODULE_SET_HOOK(kern_proc_32_copyin_hook, "kern_proc_32", copyin_psstrings_32);
139 1.1.2.5 pgoyette MODULE_SET_HOOK(kern_proc_32_base_hook, "kern_proc_32", get_base32);
140 1.1.2.5 pgoyette MODULE_UNSET_HOOK(kern_proc_32_copyin_hook);
141 1.1.2.5 pgoyette MODULE_UNSET_HOOK(kern_proc_32_base_hook);
142 1.1.2.2 pgoyette #endif
143 1.1.2.1 pgoyette
144 1.1.2.1 pgoyette void
145 1.1.2.4 pgoyette netbsd32_kern_proc_32_init(void)
146 1.1.2.1 pgoyette {
147 1.1.2.1 pgoyette
148 1.1.2.2 pgoyette #if !defined(_RUMPSERVER)
149 1.1.2.5 pgoyette kern_proc_32_copyin_hook_set();
150 1.1.2.5 pgoyette kern_proc_32_base_hook_set();
151 1.1.2.2 pgoyette #endif
152 1.1.2.1 pgoyette }
153 1.1.2.1 pgoyette
154 1.1.2.1 pgoyette void
155 1.1.2.4 pgoyette netbsd32_kern_proc_32_fini(void)
156 1.1.2.1 pgoyette {
157 1.1.2.1 pgoyette
158 1.1.2.2 pgoyette #if !defined(_RUMPSERVER)
159 1.1.2.5 pgoyette kern_proc_32_copyin_hook_unset();
160 1.1.2.5 pgoyette kern_proc_32_base_hook_unset();
161 1.1.2.2 pgoyette #endif
162 1.1.2.1 pgoyette }
163