No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / svr4_32 / svr4_32_exec_elf32.c
blob49f43910b60cf384917538bb02736af9939f4a15
1 /* $NetBSD: svr4_32_exec_elf32.c,v 1.19 2007/12/08 18:36:27 dsl Exp $ */
3 /*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: svr4_32_exec_elf32.c,v 1.19 2007/12/08 18:36:27 dsl Exp $");
35 #define ELFSIZE 32 /* XXX should die */
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>
47 #include <sys/mman.h>
49 #include <sys/cpu.h>
50 #include <machine/reg.h>
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>
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.
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);
70 #if 0
71 int
72 svr4_32_copyargs(struct lwp *l, struct exec_package *pack, struct ps_strings *arginfo, char **stackp, void *argp)
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;
80 if ((error = netbsd32_copyargs(l, pack, arginfo, stackp, argp)) != 0)
81 return error;
83 a = ai;
86 * Push extra arguments on the stack needed by dynamically
87 * linked binaries
89 if ((ap = (struct elf_args *)pack->ep_emul_arg)) {
90 struct proc *p = curproc; /* XXXXX */
92 a->a_type = AT_SUN_PLATFORM;
93 platform = a; /* Patch this later. */
94 a++;
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++;
102 a->a_type = AT_PHDR;
103 a->a_v = ap->arg_phaddr;
104 a++;
106 a->a_type = AT_PHENT;
107 a->a_v = ap->arg_phentsize;
108 a++;
110 a->a_type = AT_PHNUM;
111 a->a_v = ap->arg_phnum;
112 a++;
114 a->a_type = AT_ENTRY;
115 a->a_v = ap->arg_entry;
116 a++;
118 a->a_type = AT_BASE;
119 a->a_v = ap->arg_interp;
120 a++;
122 if (sun_flags) {
123 a->a_type = AT_FLAGS;
124 a->a_v = sun_flags;
125 a++;
128 a->a_type = AT_PAGESZ;
129 a->a_v = PAGE_SIZE;
130 a++;
132 a->a_type = AT_EUID;
133 a->a_v = kauth_cred_geteuid(l->l_cred);
134 a++;
136 a->a_type = AT_RUID;
137 a->a_v = kauth_cred_getuid(l->l_cred);
138 a++;
140 a->a_type = AT_EGID;
141 a->a_v = kauth_cred_getegid(l->l_cred);
142 a++;
144 a->a_type = AT_RGID;
145 a->a_v = kauth_cred_getgid(l->l_cred);
146 a++;
148 if (sun_hwcap) {
149 a->a_type = AT_SUN_HWCAP;
150 a->a_v = sun_hwcap;
151 a++;
154 free((char *)ap, M_TEMP);
155 pack->ep_emul_arg = NULL;
158 a->a_type = AT_NULL;
159 a->a_v = 0;
160 a++;
162 len = (a - ai) * sizeof(AuxInfo);
164 if (platform) {
165 char *ptr = (char *)a;
166 const char *path = NULL;
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;
175 if (exec) {
176 path = pack->ep_ndp->ni_cnd.cn_pnbuf;
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;
184 /* Round to 32-bits */
185 len = (len+7)&~0x7L;
187 if ((error = copyout(ai, *stackp, len)) != 0)
188 return error;
189 *stackp += len;
191 return error;
193 #else
195 svr4_32_copyargs(struct lwp *l, struct exec_package *pack, struct ps_strings *arginfo, char **stackp, void *argp)
197 size_t len;
198 AuxInfo ai[SVR4_32_AUX_ARGSIZ], *a;
199 struct elf_args *ap;
200 int error;
202 if ((error = netbsd32_copyargs(l, pack, arginfo, stackp, argp)) != 0)
203 return error;
205 a = ai;
208 * Push extra arguments on the stack needed by dynamically
209 * linked binaries
211 if ((ap = (struct elf_args *)pack->ep_emul_arg)) {
213 a->a_type = AT_PHDR;
214 a->a_v = ap->arg_phaddr;
215 a++;
217 a->a_type = AT_PHENT;
218 a->a_v = ap->arg_phentsize;
219 a++;
221 a->a_type = AT_PHNUM;
222 a->a_v = ap->arg_phnum;
223 a++;
225 a->a_type = AT_PAGESZ;
226 a->a_v = PAGE_SIZE;
227 a++;
229 a->a_type = AT_BASE;
230 a->a_v = ap->arg_interp;
231 a++;
233 a->a_type = AT_ENTRY;
234 a->a_v = ap->arg_entry;
235 a++;
237 if (sun_flags) {
238 a->a_type = AT_FLAGS;
239 a->a_v = sun_flags;
240 a++;
243 free((char *)ap, M_TEMP);
244 pack->ep_emul_arg = NULL;
247 a->a_type = AT_NULL;
248 a->a_v = 0;
249 a++;
251 len = (a - ai) * sizeof(AuxInfo);
252 if (copyout(ai, *stackp, len))
253 return error;
254 *stackp += len;
256 return 0;
258 #endif
261 svr4_32_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh, char *itp, vaddr_t *pos)
263 int error;
265 if (itp) {
266 if ((error = emul_find_interp(l, epp, itp)))
267 return error;
269 epp->ep_flags |= EXEC_32;
270 #ifdef SVR4_32_INTERP_ADDR
271 *pos = SVR4_32_INTERP_ADDR;
272 #endif
273 return 0;