1 /** $MirOS: src/sys/kern/exec_conf.c,v 1.3 2008/11/16 20:46:13 tg Exp $ */
2 /* $OpenBSD: exec_conf.c,v 1.17 2004/04/15 00:22:42 tedu Exp $ */
3 /* $NetBSD: exec_conf.c,v 1.16 1995/12/09 05:34:47 cgd Exp $ */
4
5 /*
6 * Copyright (c) 1993, 1994 Christopher G. Demetriou
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Christopher G. Demetriou.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/param.h>
36 #include <sys/exec.h>
37 #include <sys/exec_script.h>
38
39 #if defined(_KERN_DO_ECOFF)
40 #include <sys/exec_ecoff.h>
41 #endif
42
43 #if defined(_KERN_DO_ELF) || defined(_KERN_DO_ELF64)
44 #include <sys/exec_elf.h>
45 #endif
46
47 #ifdef COMPAT_LINUX
48 #include <compat/linux/linux_exec.h>
49 #endif
50
51 #ifdef COMPAT_OPENBSD
52 #include <compat/openbsd/compat_openbsd.h>
53 #endif
54
55 extern struct emul emul_native, emul_elf32, emul_elf64, emul_aout,
56 emul_linux_elf, emul_linux_aout, emul_openbsd_aout,
57 emul_openbsd;
58
59 struct execsw execsw[] = {
60 { MAXINTERP, exec_script_makecmds, &emul_native, }, /* shell scripts */
61 #ifdef _KERN_DO_ECOFF
62 { ECOFF_HDR_SIZE, exec_ecoff_makecmds, &emul_native }, /* ecoff binaries */
63 #endif
64 #ifdef _KERN_DO_AOUT
65 #ifdef COMPAT_OPENBSD
66 { sizeof(struct exec), exec_aout_makecmds, &emul_openbsd_aout },
67 #else
68 { sizeof(struct exec), exec_aout_makecmds, &emul_native }, /* a.out binaries */
69 #endif
70 #endif
71 #ifdef _KERN_DO_ELF
72 { sizeof(Elf32_Ehdr), exec_elf32_makecmds, &emul_native }, /* elf binaries */
73 #endif
74 #ifdef _KERN_DO_ELF64
75 { sizeof(Elf64_Ehdr), exec_elf64_makecmds, &emul_native }, /* elf binaries */
76 #endif /* ELF64 */
77 #ifdef COMPAT_LINUX
78 { LINUX_AOUT_HDR_SIZE, exec_linux_aout_makecmds, &emul_linux_aout }, /* linux a.out */
79 { sizeof(Elf32_Ehdr), exec_linux_elf32_makecmds, &emul_linux_elf },
80 #endif
81 #ifdef COMPAT_OPENBSD
82 { sizeof(Elf32_Ehdr), exec_openbsd_elf32_makecmds, &emul_openbsd }, /* OpenBSD ELF */
83 #endif
84 #ifdef LKM
85 { 0, NULL, NULL }, /* entries for LKMs */
86 { 0, NULL, NULL },
87 { 0, NULL, NULL },
88 { 0, NULL, NULL },
89 { 0, NULL, NULL },
90 #endif
91 };
92 int nexecs = (sizeof execsw / sizeof(*execsw));
93 int exec_maxhdrsz;
94
95 void init_exec(void);
96
97 void
init_exec(void)98 init_exec(void)
99 {
100 int i;
101
102 /*
103 * figure out the maximum size of an exec header.
104 * XXX should be able to keep LKM code from modifying exec switch
105 * when we're still using it, but...
106 */
107 for (i = 0; i < nexecs; i++)
108 if (execsw[i].es_check != NULL &&
109 execsw[i].es_hdrsz > exec_maxhdrsz)
110 exec_maxhdrsz = execsw[i].es_hdrsz;
111 }
112