1 /* $NetBSD: svr4_32_exec_elf32.c,v 1.20 2008/04/28 20:23:46 martin Exp $ */
2
3 /*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: svr4_32_exec_elf32.c,v 1.20 2008/04/28 20:23:46 martin Exp $");
34
35 #define ELFSIZE 32 /* XXX should die */
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/proc.h>
41 #include <sys/malloc.h>
42 #include <sys/namei.h>
43 #include <sys/vnode.h>
44 #include <sys/exec_elf.h>
45 #include <sys/exec.h>
46
47 #include <sys/mman.h>
48
49 #include <sys/cpu.h>
50 #include <machine/reg.h>
51
52 #include <compat/svr4_32/svr4_32_types.h>
53 #include <compat/svr4_32/svr4_32_util.h>
54 #include <compat/svr4_32/svr4_32_exec.h>
55 #include <compat/netbsd32/netbsd32_exec.h>
56 #include <compat/svr4/svr4_errno.h>
57
58 /*
59 * Since this only works on 64-bit machines trying to execute
60 * 32-bit binaries, it's pretty much limited to sparc64
61 * trying to run solaris binaries. So, to simplify this
62 * I'm making this svr4_32_copyargs() SPARC/Solaris specific
63 * so we can run Solaris 8 dynamic binaries that require
64 * lots of fancy specialized support.
65 */
66
67 int sun_flags = EF_SPARC_SUN_US1|EF_SPARC_32PLUS;
68 int sun_hwcap = (AV_SPARC_HWMUL_32x32|AV_SPARC_HWDIV_32x32|AV_SPARC_HWFSMULD);
69
70 #if 0
71 int
72 svr4_32_copyargs(struct lwp *l, struct exec_package *pack, struct ps_strings *arginfo, char **stackp, void *argp)
73 {
74 size_t len;
75 AuxInfo ai[SVR4_32_AUX_ARGSIZ], *a, *platform=NULL, *exec=NULL;
76 struct elf_args *ap;
77 extern char machine_model[];
78 int error;
79
80 if ((error = netbsd32_copyargs(l, pack, arginfo, stackp, argp)) != 0)
81 return error;
82
83 a = ai;
84
85 /*
86 * Push extra arguments on the stack needed by dynamically
87 * linked binaries
88 */
89 if ((ap = (struct elf_args *)pack->ep_emul_arg)) {
90 struct proc *p = curproc; /* XXXXX */
91
92 a->a_type = AT_SUN_PLATFORM;
93 platform = a; /* Patch this later. */
94 a++;
95
96 if (pack->ep_ndp->ni_cnd.cn_flags & HASBUF) {
97 a->a_type = AT_SUN_EXECNAME;
98 exec = a; /* Patch this later. */
99 a++;
100 }
101
102 a->a_type = AT_PHDR;
103 a->a_v = ap->arg_phaddr;
104 a++;
105
106 a->a_type = AT_PHENT;
107 a->a_v = ap->arg_phentsize;
108 a++;
109
110 a->a_type = AT_PHNUM;
111 a->a_v = ap->arg_phnum;
112 a++;
113
114 a->a_type = AT_ENTRY;
115 a->a_v = ap->arg_entry;
116 a++;
117
118 a->a_type = AT_BASE;
119 a->a_v = ap->arg_interp;
120 a++;
121
122 if (sun_flags) {
123 a->a_type = AT_FLAGS;
124 a->a_v = sun_flags;
125 a++;
126 }
127
128 a->a_type = AT_PAGESZ;
129 a->a_v = PAGE_SIZE;
130 a++;
131
132 a->a_type = AT_EUID;
133 a->a_v = kauth_cred_geteuid(l->l_cred);
134 a++;
135
136 a->a_type = AT_RUID;
137 a->a_v = kauth_cred_getuid(l->l_cred);
138 a++;
139
140 a->a_type = AT_EGID;
141 a->a_v = kauth_cred_getegid(l->l_cred);
142 a++;
143
144 a->a_type = AT_RGID;
145 a->a_v = kauth_cred_getgid(l->l_cred);
146 a++;
147
148 if (sun_hwcap) {
149 a->a_type = AT_SUN_HWCAP;
150 a->a_v = sun_hwcap;
151 a++;
152 }
153
154 free((char *)ap, M_TEMP);
155 pack->ep_emul_arg = NULL;
156 }
157
158 a->a_type = AT_NULL;
159 a->a_v = 0;
160 a++;
161
162 len = (a - ai) * sizeof(AuxInfo);
163
164 if (platform) {
165 char *ptr = (char *)a;
166 const char *path = NULL;
167
168 /* Copy out the platform name. */
169 platform->a_v = (u_long)(*stackp) + len;
170 /* XXXX extremely inefficient.... */
171 strcpy(ptr, machine_model);
172 ptr += strlen(machine_model) + 1;
173 len += strlen(machine_model) + 1;
174
175 if (exec) {
176 path = pack->ep_ndp->ni_cnd.cn_pnbuf;
177
178 /* Copy out the file we're executing. */
179 exec->a_v = (u_long)(*stackp) + len;
180 strcpy(ptr, path);
181 len += strlen(ptr)+1;
182 }
183
184 /* Round to 32-bits */
185 len = (len+7)&~0x7L;
186 }
187 if ((error = copyout(ai, *stackp, len)) != 0)
188 return error;
189 *stackp += len;
190
191 return error;
192 }
193 #else
194 int
195 svr4_32_copyargs(struct lwp *l, struct exec_package *pack, struct ps_strings *arginfo, char **stackp, void *argp)
196 {
197 size_t len;
198 AuxInfo ai[SVR4_32_AUX_ARGSIZ], *a;
199 struct elf_args *ap;
200 int error;
201
202 if ((error = netbsd32_copyargs(l, pack, arginfo, stackp, argp)) != 0)
203 return error;
204
205 a = ai;
206
207 /*
208 * Push extra arguments on the stack needed by dynamically
209 * linked binaries
210 */
211 if ((ap = (struct elf_args *)pack->ep_emul_arg)) {
212
213 a->a_type = AT_PHDR;
214 a->a_v = ap->arg_phaddr;
215 a++;
216
217 a->a_type = AT_PHENT;
218 a->a_v = ap->arg_phentsize;
219 a++;
220
221 a->a_type = AT_PHNUM;
222 a->a_v = ap->arg_phnum;
223 a++;
224
225 a->a_type = AT_PAGESZ;
226 a->a_v = PAGE_SIZE;
227 a++;
228
229 a->a_type = AT_BASE;
230 a->a_v = ap->arg_interp;
231 a++;
232
233 a->a_type = AT_ENTRY;
234 a->a_v = ap->arg_entry;
235 a++;
236
237 if (sun_flags) {
238 a->a_type = AT_FLAGS;
239 a->a_v = sun_flags;
240 a++;
241 }
242
243 free((char *)ap, M_TEMP);
244 pack->ep_emul_arg = NULL;
245 }
246
247 a->a_type = AT_NULL;
248 a->a_v = 0;
249 a++;
250
251 len = (a - ai) * sizeof(AuxInfo);
252 if (copyout(ai, *stackp, len))
253 return error;
254 *stackp += len;
255
256 return 0;
257 }
258 #endif
259
260 int
261 svr4_32_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh, char *itp, vaddr_t *pos)
262 {
263 int error;
264
265 if (itp) {
266 if ((error = emul_find_interp(l, epp, itp)))
267 return error;
268 }
269 epp->ep_flags |= EXEC_32;
270 #ifdef SVR4_32_INTERP_ADDR
271 *pos = SVR4_32_INTERP_ADDR;
272 #endif
273 return 0;
274 }
Cache object: 8164315c6b09a140300f09f08bc19770
|