1 /* $NetBSD: ibcs2_exec_elf32.c,v 1.16 2007/12/04 18:40:10 dsl Exp $ */
4 * Copyright (c) 1994, 1995, 1998 Scott Bartram
5 * Copyright (c) 1994 Adam Glass
6 * Copyright (c) 1993, 1994 Christopher G. Demetriou
9 * originally from kern/exec_ecoff.c
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Scott Bartram.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: ibcs2_exec_elf32.c,v 1.16 2007/12/04 18:40:10 dsl Exp $");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
46 #include <sys/malloc.h>
47 #include <sys/namei.h>
48 #include <sys/vnode.h>
49 #include <sys/mount.h>
51 #include <sys/exec_elf.h>
56 #include <machine/reg.h>
57 #include <machine/ibcs2_machdep.h>
59 #include <compat/ibcs2/ibcs2_types.h>
60 #include <compat/ibcs2/ibcs2_exec.h>
61 #include <compat/ibcs2/ibcs2_errno.h>
62 #include <compat/ibcs2/ibcs2_util.h>
64 static int ibcs2_elf32_signature(struct lwp
*l
, struct exec_package
*,
68 * The SCO compiler adds the string "SCO" to the .notes section of all
69 * binaries I've seen so far.
71 * XXX - probably should only compare the id in the actual ELF notes struct
74 #define SCO_SIGNATURE "\004\0\0\0\014\0\0\0\001\0\0\0SCO\0"
77 ibcs2_elf32_signature(struct lwp
*l
, struct exec_package
*epp
, Elf32_Ehdr
*eh
)
79 size_t shsize
= sizeof(Elf32_Shdr
) * eh
->e_shnum
;
81 static const char signature
[] = SCO_SIGNATURE
;
82 char tbuf
[sizeof(signature
) - 1];
86 if (shsize
> 64 * 1024)
89 sh
= (Elf32_Shdr
*)malloc(shsize
, M_TEMP
, M_WAITOK
);
91 if ((error
= exec_read_from(l
, epp
->ep_vp
, eh
->e_shoff
, sh
,
95 for (i
= 0; i
< eh
->e_shnum
; i
++) {
96 Elf32_Shdr
*s
= &sh
[i
];
97 if (s
->sh_type
!= SHT_NOTE
||
99 s
->sh_size
< sizeof(signature
) - 1)
102 if ((error
= exec_read_from(l
, epp
->ep_vp
, s
->sh_offset
, tbuf
,
103 sizeof(signature
) - 1)) != 0)
106 if (memcmp(tbuf
, signature
, sizeof(signature
) - 1) == 0)
109 break; /* only one .note section so quit */
119 * ibcs2_elf32_probe - search the executable for signs of SCO
123 ibcs2_elf32_probe(struct lwp
*l
, struct exec_package
*epp
, void *eh
, char *itp
,
128 if ((error
= ibcs2_elf32_signature(l
, epp
, eh
)) != 0)
132 if ((error
= emul_find_interp(l
, epp
, itp
)))