replace mips:elf_check_itp() and ELFNAME2(netbsd32,probe_noteless) that it's based upon with a common compat_elf_check_interp(). tested on MALTA64 and sparc64.diff -r1.58 -r1.59 src/sys/arch/mips/mips/cpu_exec.c
(mrg)
--- src/sys/arch/mips/mips/cpu_exec.c 2009/12/14 00:46:05 1.58
+++ src/sys/arch/mips/mips/cpu_exec.c 2009/12/14 04:09:38 1.59
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cpu_exec.c,v 1.58 2009/12/14 00:46:05 matt Exp $ */ | 1 | /* $NetBSD: cpu_exec.c,v 1.59 2009/12/14 04:09:38 mrg Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by Ralph | 7 | * This code is derived from software contributed to Berkeley by Ralph | |
8 | * Campbell. | 8 | * Campbell. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -25,43 +25,45 @@ | @@ -25,43 +25,45 @@ | |||
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | * | 33 | * | |
34 | * @(#)machdep.c 8.3 (Berkeley) 1/12/94 | 34 | * @(#)machdep.c 8.3 (Berkeley) 1/12/94 | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | __KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.58 2009/12/14 00:46:05 matt Exp $"); | 38 | __KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.59 2009/12/14 04:09:38 mrg Exp $"); | |
39 | 39 | |||
40 | #include "opt_compat_netbsd.h" | 40 | #include "opt_compat_netbsd.h" | |
41 | #include "opt_compat_ultrix.h" | 41 | #include "opt_compat_ultrix.h" | |
42 | #include "opt_execfmt.h" | 42 | #include "opt_execfmt.h" | |
43 | 43 | |||
44 | #include <sys/param.h> | 44 | #include <sys/param.h> | |
45 | #include <sys/systm.h> | 45 | #include <sys/systm.h> | |
46 | #include <sys/proc.h> | 46 | #include <sys/proc.h> | |
47 | #include <sys/malloc.h> | 47 | #include <sys/malloc.h> | |
48 | #include <sys/vnode.h> | 48 | #include <sys/vnode.h> | |
49 | #include <sys/exec.h> | 49 | #include <sys/exec.h> | |
50 | #include <sys/namei.h> | 50 | #include <sys/namei.h> | |
51 | #include <sys/resourcevar.h> | 51 | #include <sys/resourcevar.h> | |
52 | 52 | |||
53 | #include <uvm/uvm_extern.h> | 53 | #include <uvm/uvm_extern.h> | |
54 | 54 | |||
55 | #include <compat/common/compat_util.h> | |||
56 | ||||
55 | #ifdef EXEC_ECOFF | 57 | #ifdef EXEC_ECOFF | |
56 | #include <sys/exec_ecoff.h> | 58 | #include <sys/exec_ecoff.h> | |
57 | #endif | 59 | #endif | |
58 | #include <sys/exec_elf.h> /* mandatory */ | 60 | #include <sys/exec_elf.h> /* mandatory */ | |
59 | #include <machine/reg.h> | 61 | #include <machine/reg.h> | |
60 | #include <mips/regnum.h> /* symbolic register indices */ | 62 | #include <mips/regnum.h> /* symbolic register indices */ | |
61 | 63 | |||
62 | int mips_elf_makecmds(struct lwp *, struct exec_package *); | 64 | int mips_elf_makecmds(struct lwp *, struct exec_package *); | |
63 | 65 | |||
64 | #ifdef EXEC_ECOFF | 66 | #ifdef EXEC_ECOFF | |
65 | void | 67 | void | |
66 | cpu_exec_ecoff_setregs(struct lwp *l, struct exec_package *epp, vaddr_t stack) | 68 | cpu_exec_ecoff_setregs(struct lwp *l, struct exec_package *epp, vaddr_t stack) | |
67 | { | 69 | { | |
@@ -231,62 +233,26 @@ mips_elf_makecmds (struct lwp *l, struct | @@ -231,62 +233,26 @@ mips_elf_makecmds (struct lwp *l, struct | |||
231 | * note that in memory, things assumed to be: 0 ....... ep_maxsaddr | 233 | * note that in memory, things assumed to be: 0 ....... ep_maxsaddr | |
232 | * <stack> ep_minsaddr | 234 | * <stack> ep_minsaddr | |
233 | */ | 235 | */ | |
234 | NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, | 236 | NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, | |
235 | ((epp->ep_minsaddr - epp->ep_ssize) - epp->ep_maxsaddr), | 237 | ((epp->ep_minsaddr - epp->ep_ssize) - epp->ep_maxsaddr), | |
236 | epp->ep_maxsaddr, NULLVP, 0, VM_PROT_NONE, VMCMD_STACK); | 238 | epp->ep_maxsaddr, NULLVP, 0, VM_PROT_NONE, VMCMD_STACK); | |
237 | NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, epp->ep_ssize, | 239 | NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, epp->ep_ssize, | |
238 | (epp->ep_minsaddr - epp->ep_ssize), NULLVP, 0, | 240 | (epp->ep_minsaddr - epp->ep_ssize), NULLVP, 0, | |
239 | VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, VMCMD_STACK); | 241 | VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, VMCMD_STACK); | |
240 | 242 | |||
241 | return 0; | 243 | return 0; | |
242 | } | 244 | } | |
243 | 245 | |||
244 | static int | |||
245 | elf_check_itp(struct exec_package *epp, const char *itp, | |||
246 | const char *itp_suffix) | |||
247 | { | |||
248 | if (itp) { | |||
249 | /* | |||
250 | * If the path is exactly "/usr/libexec/ld.elf_so", first | |||
251 | * try to see if "/usr/libexec/ld.elf_so-<abi>" exists | |||
252 | * and if so, use that instead. | |||
253 | * XXX maybe move this into compat/common | |||
254 | */ | |||
255 | if (strcmp(itp, "/usr/libexec/ld.elf_so") == 0 || | |||
256 | strcmp(itp, "/libexec/ld.elf_so") == 0) { | |||
257 | struct nameidata nd; | |||
258 | char *path; | |||
259 | int error; | |||
260 | ||||
261 | path = PNBUF_GET(); | |||
262 | snprintf(path, MAXPATHLEN, "%s-%s", itp, itp_suffix); | |||
263 | NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path); | |||
264 | error = namei(&nd); | |||
265 | /* | |||
266 | * If that worked, replace interpreter in case we | |||
267 | * actually need to load it | |||
268 | */ | |||
269 | if (error == 0) { | |||
270 | if (epp->ep_interp != NULL) | |||
271 | vrele(epp->ep_interp); | |||
272 | epp->ep_interp = nd.ni_vp; | |||
273 | } | |||
274 | PNBUF_PUT(path); | |||
275 | } | |||
276 | } | |||
277 | return 0; | |||
278 | } | |||
279 | ||||
280 | #if EXEC_ELF32 | 246 | #if EXEC_ELF32 | |
281 | int | 247 | int | |
282 | mips_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0, | 248 | mips_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0, | |
283 | char *itp, vaddr_t *start_p) | 249 | char *itp, vaddr_t *start_p) | |
284 | { | 250 | { | |
285 | struct proc * const p = l->l_proc; | 251 | struct proc * const p = l->l_proc; | |
286 | const Elf32_Ehdr * const eh = eh0; | 252 | const Elf32_Ehdr * const eh = eh0; | |
287 | int old_abi = p->p_md.md_abi; | 253 | int old_abi = p->p_md.md_abi; | |
288 | const char *itp_suffix = NULL; | 254 | const char *itp_suffix = NULL; | |
289 | 255 | |||
290 | /* | 256 | /* | |
291 | * Verify we can support the architecture. | 257 | * Verify we can support the architecture. | |
292 | */ | 258 | */ | |
@@ -328,27 +294,28 @@ mips_netbsd_elf32_probe(struct lwp *l, s | @@ -328,27 +294,28 @@ mips_netbsd_elf32_probe(struct lwp *l, s | |||
328 | case EF_MIPS_ABI_O32: | 294 | case EF_MIPS_ABI_O32: | |
329 | itp_suffix = "o32"; | 295 | itp_suffix = "o32"; | |
330 | p->p_md.md_abi = _MIPS_BSD_API_O32; | 296 | p->p_md.md_abi = _MIPS_BSD_API_O32; | |
331 | #ifdef COMPAT_16 | 297 | #ifdef COMPAT_16 | |
332 | *start_p = ELF32_LINK_ADDR; | 298 | *start_p = ELF32_LINK_ADDR; | |
333 | #endif | 299 | #endif | |
334 | if (old_abi != p->p_md.md_abi) | 300 | if (old_abi != p->p_md.md_abi) | |
335 | printf("pid %d(%s): ABI set to O32 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags); | 301 | printf("pid %d(%s): ABI set to O32 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags); | |
336 | break; | 302 | break; | |
337 | default: | 303 | default: | |
338 | return ENOEXEC; | 304 | return ENOEXEC; | |
339 | } | 305 | } | |
340 | 306 | |||
341 | return elf_check_itp(epp, itp, itp_suffix); | 307 | (void)compat_elf_check_interp(epp, itp, itp_suffix); | |
308 | return 0; | |||
342 | } | 309 | } | |
343 | 310 | |||
344 | void | 311 | void | |
345 | coredump_elf32_setup(struct lwp *l, void *eh0) | 312 | coredump_elf32_setup(struct lwp *l, void *eh0) | |
346 | { | 313 | { | |
347 | struct proc * const p = l->l_proc; | 314 | struct proc * const p = l->l_proc; | |
348 | Elf32_Ehdr * const eh = eh0; | 315 | Elf32_Ehdr * const eh = eh0; | |
349 | 316 | |||
350 | /* | 317 | /* | |
351 | * Mark the type of CPU that the dump happened on. | 318 | * Mark the type of CPU that the dump happened on. | |
352 | */ | 319 | */ | |
353 | if (cpu_arch & CPU_ARCH_MIPS64) { | 320 | if (cpu_arch & CPU_ARCH_MIPS64) { | |
354 | eh->e_flags |= EF_MIPS_ARCH_64; | 321 | eh->e_flags |= EF_MIPS_ARCH_64; | |
@@ -421,27 +388,28 @@ mips_netbsd_elf64_probe(struct lwp *l, s | @@ -421,27 +388,28 @@ mips_netbsd_elf64_probe(struct lwp *l, s | |||
421 | if (old_abi != p->p_md.md_abi) | 388 | if (old_abi != p->p_md.md_abi) | |
422 | printf("pid %d(%s): ABI set to N64 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags); | 389 | printf("pid %d(%s): ABI set to N64 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags); | |
423 | break; | 390 | break; | |
424 | case EF_MIPS_ABI_O64: | 391 | case EF_MIPS_ABI_O64: | |
425 | itp_suffix = "o64"; | 392 | itp_suffix = "o64"; | |
426 | p->p_md.md_abi = _MIPS_BSD_API_O64; | 393 | p->p_md.md_abi = _MIPS_BSD_API_O64; | |
427 | if (old_abi != p->p_md.md_abi) | 394 | if (old_abi != p->p_md.md_abi) | |
428 | printf("pid %d(%s): ABI set to O64 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags); | 395 | printf("pid %d(%s): ABI set to O64 (e_flags=%#x)\n", p->p_pid, p->p_comm, eh->e_flags); | |
429 | break; | 396 | break; | |
430 | default: | 397 | default: | |
431 | return ENOEXEC; | 398 | return ENOEXEC; | |
432 | } | 399 | } | |
433 | 400 | |||
434 | return elf_check_itp(epp, itp, itp_suffix); | 401 | (void)compat_elf_check_interp(epp, itp, itp_suffix); | |
402 | return 0; | |||
435 | } | 403 | } | |
436 | 404 | |||
437 | void | 405 | void | |
438 | coredump_elf64_setup(struct lwp *l, void *eh0) | 406 | coredump_elf64_setup(struct lwp *l, void *eh0) | |
439 | { | 407 | { | |
440 | struct proc * const p = l->l_proc; | 408 | struct proc * const p = l->l_proc; | |
441 | Elf64_Ehdr * const eh = eh0; | 409 | Elf64_Ehdr * const eh = eh0; | |
442 | 410 | |||
443 | /* | 411 | /* | |
444 | * Mark the type of CPU that the dump happened on. | 412 | * Mark the type of CPU that the dump happened on. | |
445 | */ | 413 | */ | |
446 | if (cpu_arch & CPU_ARCH_MIPS64) { | 414 | if (cpu_arch & CPU_ARCH_MIPS64) { | |
447 | eh->e_flags |= EF_MIPS_ARCH_64; | 415 | eh->e_flags |= EF_MIPS_ARCH_64; |
--- src/sys/compat/common/compat_util.c 2009/06/29 05:08:15 1.42
+++ src/sys/compat/common/compat_util.c 2009/12/14 04:09:38 1.43
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: compat_util.c,v 1.42 2009/06/29 05:08:15 dholland Exp $ */ | 1 | /* $NetBSD: compat_util.c,v 1.43 2009/12/14 04:09:38 mrg Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1994 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1994 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Christos Zoulas and Frank van der Linden. | 8 | * by Christos Zoulas and Frank van der Linden. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -19,28 +19,56 @@ | @@ -19,28 +19,56 @@ | |||
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | 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 | 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 | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 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 | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 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 | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | /* | |||
33 | * Copyright (c) 2008, 2009 Matthew R. Green | |||
34 | * All rights reserved. | |||
35 | * | |||
36 | * Redistribution and use in source and binary forms, with or without | |||
37 | * modification, are permitted provided that the following conditions | |||
38 | * are met: | |||
39 | * 1. Redistributions of source code must retain the above copyright | |||
40 | * notice, this list of conditions and the following disclaimer. | |||
41 | * 2. Redistributions in binary form must reproduce the above copyright | |||
42 | * notice, this list of conditions and the following disclaimer in the | |||
43 | * documentation and/or other materials provided with the distribution. | |||
44 | * 3. The name of the author may not be used to endorse or promote products | |||
45 | * derived from this software without specific prior written permission. | |||
46 | * | |||
47 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |||
48 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
49 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |||
50 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |||
51 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |||
52 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||
53 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |||
54 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||
56 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
57 | * SUCH DAMAGE. | |||
58 | */ | |||
59 | ||||
32 | #include <sys/cdefs.h> | 60 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: compat_util.c,v 1.42 2009/06/29 05:08:15 dholland Exp $"); | 61 | __KERNEL_RCSID(0, "$NetBSD: compat_util.c,v 1.43 2009/12/14 04:09:38 mrg Exp $"); | |
34 | 62 | |||
35 | #include <sys/param.h> | 63 | #include <sys/param.h> | |
36 | #include <sys/systm.h> | 64 | #include <sys/systm.h> | |
37 | #include <sys/namei.h> | 65 | #include <sys/namei.h> | |
38 | #include <sys/proc.h> | 66 | #include <sys/proc.h> | |
39 | #include <sys/file.h> | 67 | #include <sys/file.h> | |
40 | #include <sys/stat.h> | 68 | #include <sys/stat.h> | |
41 | #include <sys/filedesc.h> | 69 | #include <sys/filedesc.h> | |
42 | #include <sys/exec.h> | 70 | #include <sys/exec.h> | |
43 | #include <sys/ioctl.h> | 71 | #include <sys/ioctl.h> | |
44 | #include <sys/kernel.h> | 72 | #include <sys/kernel.h> | |
45 | #include <sys/malloc.h> | 73 | #include <sys/malloc.h> | |
46 | #include <sys/vnode.h> | 74 | #include <sys/vnode.h> | |
@@ -137,13 +165,59 @@ emul_flags_translate(const struct emul_f | @@ -137,13 +165,59 @@ emul_flags_translate(const struct emul_f | |||
137 | } | 165 | } | |
138 | 166 | |||
139 | void | 167 | void | |
140 | compat_offseterr(struct vnode *vp, const char *msg) | 168 | compat_offseterr(struct vnode *vp, const char *msg) | |
141 | { | 169 | { | |
142 | struct mount *mp; | 170 | struct mount *mp; | |
143 | 171 | |||
144 | mp = vp->v_mount; | 172 | mp = vp->v_mount; | |
145 | 173 | |||
146 | log(LOG_ERR, "%s: dir offset too large on fs %s (mounted from %s)\n", | 174 | log(LOG_ERR, "%s: dir offset too large on fs %s (mounted from %s)\n", | |
147 | msg, mp->mnt_stat.f_mntonname, mp->mnt_stat.f_mntfromname); | 175 | msg, mp->mnt_stat.f_mntonname, mp->mnt_stat.f_mntfromname); | |
148 | uprintf("%s: dir offset too large for emulated program\n", msg); | 176 | uprintf("%s: dir offset too large for emulated program\n", msg); | |
149 | } | 177 | } | |
178 | ||||
179 | /* | |||
180 | * Look for native NetBSD compatibility libraries, usually interp-ABI. | |||
181 | * It returns 0 if it changed the interpreter, otherwise it returns | |||
182 | * the error from namei(). Callers should not try any more processing | |||
183 | * if this returns 0, and probably should just ignore the return value. | |||
184 | */ | |||
185 | int | |||
186 | compat_elf_check_interp(struct exec_package *epp, | |||
187 | char *interp, | |||
188 | const char *interp_suffix) | |||
189 | { | |||
190 | int error = 0; | |||
191 | ||||
192 | /* | |||
193 | * Don't look for something else, if someone has already found and | |||
194 | * setup the ep_interp already. | |||
195 | */ | |||
196 | if (interp && epp->ep_interp == NULL) { | |||
197 | /* | |||
198 | * If the path is exactly "/usr/libexec/ld.elf_so", first | |||
199 | * try to see if "/usr/libexec/ld.elf_so-<abi>" exists | |||
200 | * and if so, use that instead. | |||
201 | */ | |||
202 | if (strcmp(interp, "/usr/libexec/ld.elf_so") == 0 || | |||
203 | strcmp(interp, "/libexec/ld.elf_so") == 0) { | |||
204 | struct vnode *vp; | |||
205 | char *path; | |||
206 | ||||
207 | path = PNBUF_GET(); | |||
208 | snprintf(path, MAXPATHLEN, "%s-%s", interp, interp_suffix); | |||
209 | error = namei_simple_kernel(path, | |||
210 | NSM_FOLLOW_NOEMULROOT, &vp); | |||
211 | /* | |||
212 | * If that worked, replace interpreter in case we | |||
213 | * actually need to load it. | |||
214 | */ | |||
215 | if (error == 0) { | |||
216 | epp->ep_interp = vp; | |||
217 | snprintf(interp, MAXPATHLEN, "%s", path); | |||
218 | } | |||
219 | PNBUF_PUT(path); | |||
220 | } | |||
221 | } | |||
222 | return error; | |||
223 | } |
--- src/sys/compat/common/compat_util.h 2008/11/19 18:36:02 1.21
+++ src/sys/compat/common/compat_util.h 2009/12/14 04:09:38 1.22
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: compat_util.h,v 1.21 2008/11/19 18:36:02 ad Exp $ */ | 1 | /* $NetBSD: compat_util.h,v 1.22 2009/12/14 04:09:38 mrg Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1994 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1994 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Christos Zoulas. | 8 | * by Christos Zoulas. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -21,26 +21,27 @@ | @@ -21,26 +21,27 @@ | |||
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 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 | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 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 | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | /* | 32 | /* | |
33 | * Copyright (c) 1995 Frank van der Linden | 33 | * Copyright (c) 1995 Frank van der Linden | |
34 | * Copyright (c) 2009 Matthew R. Green | |||
34 | * All rights reserved. | 35 | * All rights reserved. | |
35 | * | 36 | * | |
36 | * Redistribution and use in source and binary forms, with or without | 37 | * Redistribution and use in source and binary forms, with or without | |
37 | * modification, are permitted provided that the following conditions | 38 | * modification, are permitted provided that the following conditions | |
38 | * are met: | 39 | * are met: | |
39 | * 1. Redistributions of source code must retain the above copyright | 40 | * 1. Redistributions of source code must retain the above copyright | |
40 | * notice, this list of conditions and the following disclaimer. | 41 | * notice, this list of conditions and the following disclaimer. | |
41 | * 2. Redistributions in binary form must reproduce the above copyright | 42 | * 2. Redistributions in binary form must reproduce the above copyright | |
42 | * notice, this list of conditions and the following disclaimer in the | 43 | * notice, this list of conditions and the following disclaimer in the | |
43 | * documentation and/or other materials provided with the distribution. | 44 | * documentation and/or other materials provided with the distribution. | |
44 | * 3. The name of the author may not be used to endorse or promote products | 45 | * 3. The name of the author may not be used to endorse or promote products | |
45 | * derived from this software without specific prior written permission | 46 | * derived from this software without specific prior written permission | |
46 | * | 47 | * | |
@@ -69,17 +70,19 @@ struct emul_flags_xtab { | @@ -69,17 +70,19 @@ struct emul_flags_xtab { | |||
69 | unsigned long oval; | 70 | unsigned long oval; | |
70 | unsigned long nval; | 71 | unsigned long nval; | |
71 | }; | 72 | }; | |
72 | 73 | |||
73 | void emul_find_root(struct lwp *, struct exec_package *); | 74 | void emul_find_root(struct lwp *, struct exec_package *); | |
74 | 75 | |||
75 | int emul_find_interp(struct lwp *, struct exec_package *, const char *); | 76 | int emul_find_interp(struct lwp *, struct exec_package *, const char *); | |
76 | 77 | |||
77 | unsigned long emul_flags_translate(const struct emul_flags_xtab *tab, | 78 | unsigned long emul_flags_translate(const struct emul_flags_xtab *tab, | |
78 | unsigned long in, unsigned long *leftover); | 79 | unsigned long in, unsigned long *leftover); | |
79 | 80 | |||
80 | void compat_offseterr(struct vnode *, const char *); | 81 | void compat_offseterr(struct vnode *, const char *); | |
81 | 82 | |||
83 | int compat_elf_check_interp(struct exec_package *, char *, const char *); | |||
84 | ||||
82 | void compat_sysctl_init(void); | 85 | void compat_sysctl_init(void); | |
83 | void compat_sysctl_fini(void); | 86 | void compat_sysctl_fini(void); | |
84 | 87 | |||
85 | #endif /* !_COMPAT_UTIL_H_ */ | 88 | #endif /* !_COMPAT_UTIL_H_ */ |
--- src/sys/compat/netbsd32/netbsd32_exec_elf32.c 2009/12/14 00:47:11 1.31
+++ src/sys/compat/netbsd32/netbsd32_exec_elf32.c 2009/12/14 04:09:38 1.32
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: netbsd32_exec_elf32.c,v 1.31 2009/12/14 00:47:11 matt Exp $ */ | 1 | /* $NetBSD: netbsd32_exec_elf32.c,v 1.32 2009/12/14 04:09:38 mrg Exp $ */ | |
2 | /* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */ | 2 | /* from: NetBSD: exec_aout.c,v 1.15 1996/09/26 23:34:46 cgd Exp */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 1998, 2001 Matthew R. Green. | 5 | * Copyright (c) 1998, 2001 Matthew R. Green. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -47,43 +47,45 @@ | @@ -47,43 +47,45 @@ | |||
47 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 47 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
48 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 48 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
49 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 49 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
50 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 50 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
51 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 51 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
52 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 52 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
53 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 53 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
54 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 54 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
55 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 55 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
56 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 56 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
57 | */ | 57 | */ | |
58 | 58 | |||
59 | #include <sys/cdefs.h> | 59 | #include <sys/cdefs.h> | |
60 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.31 2009/12/14 00:47:11 matt Exp $"); | 60 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_exec_elf32.c,v 1.32 2009/12/14 04:09:38 mrg Exp $"); | |
61 | 61 | |||
62 | #define ELFSIZE 32 | 62 | #define ELFSIZE 32 | |
63 | 63 | |||
64 | #include <sys/param.h> | 64 | #include <sys/param.h> | |
65 | #include <sys/systm.h> | 65 | #include <sys/systm.h> | |
66 | #include <sys/proc.h> | 66 | #include <sys/proc.h> | |
67 | #include <sys/malloc.h> | 67 | #include <sys/malloc.h> | |
68 | #include <sys/vnode.h> | 68 | #include <sys/vnode.h> | |
69 | #include <sys/exec.h> | 69 | #include <sys/exec.h> | |
70 | #include <sys/exec_elf.h> | 70 | #include <sys/exec_elf.h> | |
71 | #include <sys/resourcevar.h> | 71 | #include <sys/resourcevar.h> | |
72 | #include <sys/signal.h> | 72 | #include <sys/signal.h> | |
73 | #include <sys/signalvar.h> | 73 | #include <sys/signalvar.h> | |
74 | #include <sys/kauth.h> | 74 | #include <sys/kauth.h> | |
75 | #include <sys/namei.h> | 75 | #include <sys/namei.h> | |
76 | 76 | |||
77 | #include <compat/common/compat_util.h> | |||
78 | ||||
77 | #include <compat/netbsd32/netbsd32.h> | 79 | #include <compat/netbsd32/netbsd32.h> | |
78 | #include <compat/netbsd32/netbsd32_exec.h> | 80 | #include <compat/netbsd32/netbsd32_exec.h> | |
79 | 81 | |||
80 | #include <machine/netbsd32_machdep.h> | 82 | #include <machine/netbsd32_machdep.h> | |
81 | 83 | |||
82 | int netbsd32_copyinargs(struct exec_package *, struct ps_strings *, | 84 | int netbsd32_copyinargs(struct exec_package *, struct ps_strings *, | |
83 | void *, size_t, const void *, const void *); | 85 | void *, size_t, const void *, const void *); | |
84 | int ELFNAME2(netbsd32,probe_noteless)(struct lwp *, struct exec_package *epp, | 86 | int ELFNAME2(netbsd32,probe_noteless)(struct lwp *, struct exec_package *epp, | |
85 | void *eh, char *itp, vaddr_t *pos); | 87 | void *eh, char *itp, vaddr_t *pos); | |
86 | extern int ELFNAME2(netbsd,signature)(struct lwp *, struct exec_package *, | 88 | extern int ELFNAME2(netbsd,signature)(struct lwp *, struct exec_package *, | |
87 | Elf_Ehdr *); | 89 | Elf_Ehdr *); | |
88 | 90 | |||
89 | int | 91 | int | |
@@ -99,63 +101,29 @@ ELFNAME2(netbsd32,probe)(struct lwp *l, | @@ -99,63 +101,29 @@ ELFNAME2(netbsd32,probe)(struct lwp *l, | |||
99 | if ((error = ELF_MD_PROBE_FUNC(l, epp, eh, itp, pos)) != 0) | 101 | if ((error = ELF_MD_PROBE_FUNC(l, epp, eh, itp, pos)) != 0) | |
100 | return error; | 102 | return error; | |
101 | #elif defined(ELF_INTERP_NON_RELOCATABLE) | 103 | #elif defined(ELF_INTERP_NON_RELOCATABLE) | |
102 | *pos = ELF_LINK_ADDR; | 104 | *pos = ELF_LINK_ADDR; | |
103 | #endif | 105 | #endif | |
104 | 106 | |||
105 | return ELFNAME2(netbsd32,probe_noteless)(l, epp, eh, itp, pos); | 107 | return ELFNAME2(netbsd32,probe_noteless)(l, epp, eh, itp, pos); | |
106 | } | 108 | } | |
107 | 109 | |||
108 | int | 110 | int | |
109 | ELFNAME2(netbsd32,probe_noteless)(struct lwp *l, struct exec_package *epp, | 111 | ELFNAME2(netbsd32,probe_noteless)(struct lwp *l, struct exec_package *epp, | |
110 | void *eh, char *itp, vaddr_t *pos) | 112 | void *eh, char *itp, vaddr_t *pos) | |
111 | { | 113 | { | |
112 | int error; | 114 | if (itp && epp->ep_interp == NULL) { | |
113 | 115 | extern const char machine32[]; | ||
114 | if (itp) { | 116 | (void)compat_elf_check_interp(epp, itp, machine32); | |
115 | /* | |||
116 | * If the path is exactly "/usr/libexec/ld.elf_so", first | |||
117 | * try to see if "/usr/libexec/ld.elf_so-<arch>" exists | |||
118 | * and if so, use that instead. | |||
119 | * XXX maybe move this into compat/common | |||
120 | */ | |||
121 | error = 0; | |||
122 | if (strcmp(itp, "/usr/libexec/ld.elf_so") == 0 || | |||
123 | strcmp(itp, "/libexec/ld.elf_so") == 0) { | |||
124 | extern const char machine32[]; | |||
125 | struct vnode *vp; | |||
126 | char *path; | |||
127 | ||||
128 | if (epp->ep_interp != NULL) | |||
129 | vrele(epp->ep_interp); | |||
130 | ||||
131 | path = PNBUF_GET(); | |||
132 | snprintf(path, MAXPATHLEN, "%s-%s", itp, machine32); | |||
133 | error = namei_simple_kernel(path, | |||
134 | NSM_FOLLOW_NOEMULROOT, &vp); | |||
135 | /* | |||
136 | * If that worked, save interpreter in case we | |||
137 | * actually need to load it | |||
138 | */ | |||
139 | if (error != 0) | |||
140 | epp->ep_interp = NULL; | |||
141 | else | |||
142 | epp->ep_interp = vp; | |||
143 | PNBUF_PUT(path); | |||
144 | } | |||
145 | ||||
146 | /* Translate interpreter name if needed */ | |||
147 | if (error && (error = emul_find_interp(l, epp, itp)) != 0) | |||
148 | return error; | |||
149 | } | 117 | } | |
150 | epp->ep_flags |= EXEC_32; | 118 | epp->ep_flags |= EXEC_32; | |
151 | epp->ep_vm_minaddr = VM_MIN_ADDRESS; | 119 | epp->ep_vm_minaddr = VM_MIN_ADDRESS; | |
152 | epp->ep_vm_maxaddr = USRSTACK32; | 120 | epp->ep_vm_maxaddr = USRSTACK32; | |
153 | #ifdef ELF_INTERP_NON_RELOCATABLE | 121 | #ifdef ELF_INTERP_NON_RELOCATABLE | |
154 | *pos = ELF_LINK_ADDR; | 122 | *pos = ELF_LINK_ADDR; | |
155 | #endif | 123 | #endif | |
156 | return 0; | 124 | return 0; | |
157 | } | 125 | } | |
158 | 126 | |||
159 | /* round up and down to page boundaries. */ | 127 | /* round up and down to page boundaries. */ | |
160 | #define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) | 128 | #define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) | |
161 | #define ELF_TRUNC(a, b) ((a) & ~((b) - 1)) | 129 | #define ELF_TRUNC(a, b) ((a) & ~((b) - 1)) |