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