xref: /openbsd-src/sys/kern/exec_conf.c (revision 8500990981f885cbe5e6a4958549cacc238b5ae6)
1 /*	$OpenBSD: exec_conf.c,v 1.16 2003/08/23 20:27:30 tedu Exp $	*/
2 /*	$NetBSD: exec_conf.c,v 1.16 1995/12/09 05:34:47 cgd Exp $	*/
3 
4 /*
5  * Copyright (c) 1993, 1994 Christopher G. Demetriou
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Christopher G. Demetriou.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <sys/param.h>
35 #include <sys/exec.h>
36 #include <sys/exec_script.h>
37 
38 #if defined(_KERN_DO_ECOFF)
39 #include <sys/exec_ecoff.h>
40 #endif
41 
42 #if defined(_KERN_DO_ELF) || defined(_KERN_DO_ELF64)
43 #include <sys/exec_elf.h>
44 #endif
45 
46 #ifdef COMPAT_SVR4
47 #include <compat/svr4/svr4_exec.h>
48 #endif
49 
50 #ifdef COMPAT_IBCS2
51 #include <compat/ibcs2/ibcs2_exec.h>
52 #endif
53 
54 #ifdef COMPAT_LINUX
55 #include <compat/linux/linux_exec.h>
56 #endif
57 
58 #ifdef COMPAT_BSDOS
59 #include <compat/bsdos/bsdos_exec.h>
60 #endif
61 
62 #ifdef COMPAT_FREEBSD
63 #include <compat/freebsd/freebsd_exec.h>
64 #endif
65 
66 #ifdef COMPAT_HPUX
67 #include <compat/hpux/hpux_exec.h>
68 #endif
69 
70 #ifdef COMPAT_M68K4K
71 #include <compat/m68k4k/m68k4k_exec.h>
72 #endif
73 
74 #ifdef COMPAT_VAX1K
75 #include <compat/vax1k/vax1k_exec.h>
76 #endif
77 
78 struct execsw execsw[] = {
79 #ifdef LKM
80 	{ 0, NULL, },					/* entries for LKMs */
81 	{ 0, NULL, },
82 	{ 0, NULL, },
83 	{ 0, NULL, },
84 	{ 0, NULL, },
85 #endif
86 	{ MAXINTERP, exec_script_makecmds, },		/* shell scripts */
87 #ifdef _KERN_DO_AOUT
88 	{ sizeof(struct exec), exec_aout_makecmds, },	/* a.out binaries */
89 #endif
90 #ifdef _KERN_DO_ECOFF
91 	{ ECOFF_HDR_SIZE, exec_ecoff_makecmds, },	/* ecoff binaries */
92 #endif
93 #ifdef _KERN_DO_ELF
94 	{ sizeof(Elf32_Ehdr), exec_elf32_makecmds, },	/* elf binaries */
95 #endif
96 #ifdef _KERN_DO_ELF64
97 	{ sizeof(Elf64_Ehdr), exec_elf64_makecmds, },	/* elf binaries */
98 #endif
99 #ifdef COMPAT_LINUX
100 	{ LINUX_AOUT_HDR_SIZE, exec_linux_aout_makecmds, }, /* linux a.out */
101 #endif
102 #ifdef COMPAT_IBCS2
103 	{ COFF_HDR_SIZE, exec_ibcs2_coff_makecmds, },	/* coff binaries */
104 	{ XOUT_HDR_SIZE, exec_ibcs2_xout_makecmds, },	/* x.out binaries */
105 #endif
106 #ifdef COMPAT_BSDOS
107 	{ BSDOS_AOUT_HDR_SIZE, exec_bsdos_aout_makecmds, },	/* bsdos */
108 #endif
109 #ifdef COMPAT_FREEBSD
110 	{ FREEBSD_AOUT_HDR_SIZE, exec_freebsd_aout_makecmds, },	/* freebsd */
111 #endif
112 #ifdef COMPAT_HPUX
113 	{ HPUX_EXEC_HDR_SIZE, exec_hpux_makecmds, },	/* HP-UX a.out */
114 #endif
115 #ifdef COMPAT_M68K4K
116 	{ sizeof(struct exec), exec_m68k4k_makecmds, },	/* m68k4k a.out */
117 #endif
118 #ifdef COMPAT_VAX1K
119 	{ sizeof(struct exec), exec_vax1k_makecmds, },	/* vax1k a.out */
120 #endif
121 };
122 int nexecs = (sizeof execsw / sizeof(*execsw));
123 int exec_maxhdrsz;
124 
125 extern struct emul emul_native, emul_elf32, emul_elf64, emul_aout,
126 	emul_bsdos, emul_aout_freebsd, emul_elf_freebsd, emul_hpux,
127 	emul_ibcs2, emul_linux_elf, emul_linux_aout, emul_elf64_netbsd,
128 	emul_osf1, emul_sunos, emul_svr4, emul_ultrix;
129 struct emul *emulsw[] = {
130 #if defined (_KERN_DO_AOUT) && defined (COMPAT_AOUT)
131 	&emul_aout,
132 #endif
133 #ifdef COMPAT_BSDOS
134 	&emul_bsdos,
135 #endif
136 #ifdef COMPAT_FREEBSD
137 	&emul_aout_freebsd,
138 	&emul_elf_freebsd,
139 #endif
140 #ifdef COMPAT_HPUX
141 	&emul_hpux,
142 #endif
143 #ifdef COMPAT_IBCS2
144 	&emul_ibcs2,
145 #endif
146 #ifdef COMPAT_LINUX
147 	&emul_linux_elf,
148 	&emul_linux_aout,
149 #endif
150 #if defined (COMPAT_NETBSD) && defined (_KERN_DO_ELF64)
151 	&emul_elf64_netbsd,
152 #endif
153 #ifdef COMPAT_OSF1
154 	&emul_osf1,
155 #endif
156 #ifdef COMPAT_SUNOS
157 	&emul_sunos,
158 #endif
159 #ifdef COMPAT_SVR4
160 	&emul_svr4,
161 #endif
162 #ifdef COMPAT_ULTRIX
163 	&emul_ultrix,
164 #endif
165 };
166 int	nemuls = sizeof(emulsw) / sizeof(*emulsw);
167 
168 void	init_exec(void);
169 
170 void
171 init_exec(void)
172 {
173 	int i;
174 
175 	/*
176 	 * figure out the maximum size of an exec header.
177 	 * XXX should be able to keep LKM code from modifying exec switch
178 	 * when we're still using it, but...
179 	 */
180 	for (i = 0; i < nexecs; i++)
181 		if (execsw[i].es_check != NULL &&
182 		    execsw[i].es_hdrsz > exec_maxhdrsz)
183 			exec_maxhdrsz = execsw[i].es_hdrsz;
184 }
185