linux_exec_elf32.c revision 1.4 1 1.4 christos /* $NetBSD: linux_exec_elf32.c,v 1.4 1995/04/22 19:48:34 christos Exp $ */
2 1.1 fvdl
3 1.1 fvdl /*
4 1.1 fvdl * Copyright (c) 1995 Frank van der Linden
5 1.1 fvdl * All rights reserved.
6 1.1 fvdl *
7 1.1 fvdl * Redistribution and use in source and binary forms, with or without
8 1.1 fvdl * modification, are permitted provided that the following conditions
9 1.1 fvdl * are met:
10 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
11 1.1 fvdl * notice, this list of conditions and the following disclaimer.
12 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
14 1.1 fvdl * documentation and/or other materials provided with the distribution.
15 1.1 fvdl * 3. All advertising materials mentioning features or use of this software
16 1.1 fvdl * must display the following acknowledgement:
17 1.1 fvdl * This product includes software developed for the NetBSD Project
18 1.1 fvdl * by Frank van der Linden
19 1.1 fvdl * 4. The name of the author may not be used to endorse or promote products
20 1.1 fvdl * derived from this software without specific prior written permission
21 1.1 fvdl *
22 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 fvdl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 fvdl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 fvdl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 fvdl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 fvdl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 fvdl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 fvdl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 fvdl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 fvdl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 fvdl *
33 1.1 fvdl * based on kern/exec_aout.c and compat/sunos/sunos_exec.c
34 1.1 fvdl */
35 1.1 fvdl
36 1.1 fvdl #include <sys/param.h>
37 1.1 fvdl #include <sys/systm.h>
38 1.1 fvdl #include <sys/filedesc.h>
39 1.1 fvdl #include <sys/kernel.h>
40 1.1 fvdl #include <sys/proc.h>
41 1.1 fvdl #include <sys/mount.h>
42 1.1 fvdl #include <sys/malloc.h>
43 1.1 fvdl #include <sys/namei.h>
44 1.1 fvdl #include <sys/vnode.h>
45 1.1 fvdl #include <sys/file.h>
46 1.1 fvdl #include <sys/resourcevar.h>
47 1.1 fvdl #include <sys/wait.h>
48 1.1 fvdl
49 1.1 fvdl #include <sys/mman.h>
50 1.1 fvdl #include <vm/vm.h>
51 1.1 fvdl #include <vm/vm_param.h>
52 1.1 fvdl #include <vm/vm_map.h>
53 1.1 fvdl #include <vm/vm_kern.h>
54 1.1 fvdl #include <vm/vm_pager.h>
55 1.1 fvdl
56 1.1 fvdl #include <machine/cpu.h>
57 1.1 fvdl #include <machine/reg.h>
58 1.1 fvdl #include <machine/exec.h>
59 1.4 christos #include <machine/linux_machdep.h>
60 1.1 fvdl
61 1.1 fvdl #include <compat/linux/linux_types.h>
62 1.4 christos #include <compat/linux/linux_syscall.h>
63 1.1 fvdl #include <compat/linux/linux_syscallargs.h>
64 1.1 fvdl #include <compat/linux/linux_util.h>
65 1.1 fvdl #include <compat/linux/linux_exec.h>
66 1.1 fvdl
67 1.4 christos static void *linux_copyargs __P((struct exec_package *, struct ps_strings *,
68 1.4 christos void *, void *));
69 1.4 christos
70 1.4 christos #define LINUX_AUX_ARGSIZ 2
71 1.4 christos
72 1.4 christos extern int linux_error[];
73 1.4 christos extern struct sysent linux_sysent[];
74 1.4 christos extern char *linux_syscallnames[];
75 1.4 christos
76 1.4 christos struct emul emul_linux = {
77 1.4 christos "linux",
78 1.4 christos linux_error,
79 1.4 christos linux_sendsig,
80 1.4 christos LINUX_SYS_syscall,
81 1.4 christos LINUX_SYS_MAXSYSCALL,
82 1.4 christos linux_sysent,
83 1.4 christos linux_syscallnames,
84 1.4 christos LINUX_AUX_ARGSIZ,
85 1.4 christos linux_copyargs,
86 1.4 christos setregs,
87 1.4 christos linux_sigcode,
88 1.4 christos linux_esigcode,
89 1.4 christos };
90 1.4 christos
91 1.4 christos
92 1.4 christos static void *
93 1.4 christos linux_copyargs(pack, arginfo, stack, argp)
94 1.4 christos struct exec_package *pack;
95 1.4 christos struct ps_strings *arginfo;
96 1.4 christos void *stack;
97 1.4 christos void *argp;
98 1.4 christos {
99 1.4 christos char **cpp = stack;
100 1.4 christos char **stk = stack;
101 1.4 christos char *dp, *sp;
102 1.4 christos size_t len;
103 1.4 christos void *nullp = NULL;
104 1.4 christos int argc = arginfo->ps_nargvstr;
105 1.4 christos int envc = arginfo->ps_nenvstr;
106 1.4 christos
107 1.4 christos if (copyout(&argc, cpp++, sizeof(argc)))
108 1.4 christos return NULL;
109 1.4 christos
110 1.4 christos /* leave room for envp and argv */
111 1.4 christos cpp += 2;
112 1.4 christos if (copyout(&cpp, &stk[1], sizeof (cpp)))
113 1.4 christos return NULL;
114 1.4 christos
115 1.4 christos dp = (char *) (cpp + argc + envc + 2);
116 1.4 christos sp = argp;
117 1.4 christos
118 1.4 christos /* XXX don't copy them out, remap them! */
119 1.4 christos arginfo->ps_argvstr = dp; /* remember location of argv for later */
120 1.4 christos
121 1.4 christos for (; --argc >= 0; sp += len, dp += len)
122 1.4 christos if (copyout(&dp, cpp++, sizeof(dp)) ||
123 1.4 christos copyoutstr(sp, dp, ARG_MAX, &len))
124 1.4 christos return NULL;
125 1.4 christos
126 1.4 christos if (copyout(&nullp, cpp++, sizeof(nullp)))
127 1.4 christos return NULL;
128 1.4 christos
129 1.4 christos if (copyout(&cpp, &stk[2], sizeof (cpp)))
130 1.4 christos return NULL;
131 1.4 christos
132 1.4 christos arginfo->ps_envstr = dp; /* remember location of envp for later */
133 1.4 christos
134 1.4 christos for (; --envc >= 0; sp += len, dp += len)
135 1.4 christos if (copyout(&dp, cpp++, sizeof(dp)) ||
136 1.4 christos copyoutstr(sp, dp, ARG_MAX, &len))
137 1.4 christos return NULL;
138 1.4 christos
139 1.4 christos if (copyout(&nullp, cpp++, sizeof(nullp)))
140 1.4 christos return NULL;
141 1.4 christos
142 1.4 christos return cpp;
143 1.4 christos }
144 1.4 christos
145 1.4 christos
146 1.1 fvdl int
147 1.1 fvdl exec_linux_aout_makecmds(p, epp)
148 1.1 fvdl struct proc *p;
149 1.1 fvdl struct exec_package *epp;
150 1.1 fvdl {
151 1.1 fvdl struct exec *linux_ep = epp->ep_hdr;
152 1.1 fvdl int machtype, magic;
153 1.1 fvdl int error = ENOEXEC;
154 1.1 fvdl
155 1.1 fvdl magic = LINUX_N_MAGIC(linux_ep);
156 1.1 fvdl machtype = LINUX_N_MACHTYPE(linux_ep);
157 1.1 fvdl
158 1.1 fvdl
159 1.1 fvdl if (machtype != LINUX_MID_MACHINE)
160 1.1 fvdl return (ENOEXEC);
161 1.1 fvdl
162 1.1 fvdl switch (magic) {
163 1.1 fvdl case QMAGIC:
164 1.1 fvdl error = exec_linux_aout_prep_qmagic(p, epp);
165 1.1 fvdl break;
166 1.1 fvdl case ZMAGIC:
167 1.1 fvdl error = exec_linux_aout_prep_zmagic(p, epp);
168 1.1 fvdl break;
169 1.1 fvdl case NMAGIC:
170 1.1 fvdl error = exec_linux_aout_prep_nmagic(p, epp);
171 1.1 fvdl break;
172 1.1 fvdl case OMAGIC:
173 1.1 fvdl error = exec_linux_aout_prep_omagic(p, epp);
174 1.1 fvdl break;
175 1.1 fvdl }
176 1.4 christos if (error == 0)
177 1.4 christos epp->ep_emul = &emul_linux;
178 1.1 fvdl return error;
179 1.1 fvdl }
180 1.1 fvdl
181 1.1 fvdl /*
182 1.1 fvdl * Since text starts at 0x400 in Linux ZMAGIC executables, and 0x400
183 1.1 fvdl * is very likely not page aligned on most architectures, it is treated
184 1.1 fvdl * as an NMAGIC here. XXX
185 1.1 fvdl */
186 1.1 fvdl
187 1.1 fvdl int
188 1.1 fvdl exec_linux_aout_prep_zmagic(p, epp)
189 1.1 fvdl struct proc *p;
190 1.1 fvdl struct exec_package *epp;
191 1.1 fvdl {
192 1.1 fvdl struct exec *execp = epp->ep_hdr;
193 1.1 fvdl
194 1.1 fvdl epp->ep_taddr = LINUX_N_TXTADDR(*execp, ZMAGIC);
195 1.1 fvdl epp->ep_tsize = execp->a_text;
196 1.1 fvdl epp->ep_daddr = LINUX_N_DATADDR(*execp, ZMAGIC);
197 1.1 fvdl epp->ep_dsize = execp->a_data + execp->a_bss;
198 1.1 fvdl epp->ep_entry = execp->a_entry;
199 1.1 fvdl
200 1.1 fvdl /* set up command for text segment */
201 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, execp->a_text,
202 1.1 fvdl epp->ep_taddr, epp->ep_vp, LINUX_N_TXTOFF(*execp, ZMAGIC),
203 1.1 fvdl VM_PROT_READ|VM_PROT_EXECUTE);
204 1.1 fvdl
205 1.1 fvdl /* set up command for data segment */
206 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, execp->a_data,
207 1.1 fvdl epp->ep_daddr, epp->ep_vp, LINUX_N_DATOFF(*execp, ZMAGIC),
208 1.1 fvdl VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
209 1.1 fvdl
210 1.1 fvdl /* set up command for bss segment */
211 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, execp->a_bss,
212 1.1 fvdl epp->ep_daddr + execp->a_data, NULLVP, 0,
213 1.1 fvdl VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
214 1.1 fvdl
215 1.1 fvdl return exec_aout_setup_stack(p, epp);
216 1.1 fvdl }
217 1.1 fvdl
218 1.1 fvdl /*
219 1.1 fvdl * exec_aout_prep_nmagic(): Prepare Linux NMAGIC package.
220 1.1 fvdl * Not different from the normal stuff.
221 1.1 fvdl */
222 1.1 fvdl
223 1.1 fvdl int
224 1.1 fvdl exec_linux_aout_prep_nmagic(p, epp)
225 1.1 fvdl struct proc *p;
226 1.1 fvdl struct exec_package *epp;
227 1.1 fvdl {
228 1.1 fvdl struct exec *execp = epp->ep_hdr;
229 1.1 fvdl long bsize, baddr;
230 1.1 fvdl
231 1.1 fvdl epp->ep_taddr = LINUX_N_TXTADDR(*execp, NMAGIC);
232 1.1 fvdl epp->ep_tsize = execp->a_text;
233 1.1 fvdl epp->ep_daddr = LINUX_N_DATADDR(*execp, NMAGIC);
234 1.1 fvdl epp->ep_dsize = execp->a_data + execp->a_bss;
235 1.1 fvdl epp->ep_entry = execp->a_entry;
236 1.1 fvdl
237 1.1 fvdl /* set up command for text segment */
238 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, execp->a_text,
239 1.1 fvdl epp->ep_taddr, epp->ep_vp, LINUX_N_TXTOFF(*execp, NMAGIC),
240 1.1 fvdl VM_PROT_READ|VM_PROT_EXECUTE);
241 1.1 fvdl
242 1.1 fvdl /* set up command for data segment */
243 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, execp->a_data,
244 1.1 fvdl epp->ep_daddr, epp->ep_vp, LINUX_N_DATOFF(*execp, NMAGIC),
245 1.1 fvdl VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
246 1.1 fvdl
247 1.1 fvdl /* set up command for bss segment */
248 1.1 fvdl baddr = roundup(epp->ep_daddr + execp->a_data, NBPG);
249 1.1 fvdl bsize = epp->ep_daddr + epp->ep_dsize - baddr;
250 1.1 fvdl if (bsize > 0)
251 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, bsize, baddr,
252 1.1 fvdl NULLVP, 0, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
253 1.1 fvdl
254 1.1 fvdl return exec_aout_setup_stack(p, epp);
255 1.1 fvdl }
256 1.1 fvdl
257 1.1 fvdl /*
258 1.1 fvdl * exec_aout_prep_omagic(): Prepare Linux OMAGIC package.
259 1.1 fvdl * Business as usual.
260 1.1 fvdl */
261 1.1 fvdl
262 1.1 fvdl int
263 1.1 fvdl exec_linux_aout_prep_omagic(p, epp)
264 1.1 fvdl struct proc *p;
265 1.1 fvdl struct exec_package *epp;
266 1.1 fvdl {
267 1.1 fvdl struct exec *execp = epp->ep_hdr;
268 1.1 fvdl long dsize, bsize, baddr;
269 1.1 fvdl
270 1.1 fvdl epp->ep_taddr = LINUX_N_TXTADDR(*execp, OMAGIC);
271 1.1 fvdl epp->ep_tsize = execp->a_text;
272 1.1 fvdl epp->ep_daddr = LINUX_N_DATADDR(*execp, OMAGIC);
273 1.1 fvdl epp->ep_dsize = execp->a_data + execp->a_bss;
274 1.1 fvdl epp->ep_entry = execp->a_entry;
275 1.1 fvdl
276 1.1 fvdl /* set up command for text and data segments */
277 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn,
278 1.1 fvdl execp->a_text + execp->a_data, epp->ep_taddr, epp->ep_vp,
279 1.1 fvdl LINUX_N_TXTOFF(*execp, OMAGIC), VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
280 1.1 fvdl
281 1.1 fvdl /* set up command for bss segment */
282 1.1 fvdl baddr = roundup(epp->ep_daddr + execp->a_data, NBPG);
283 1.1 fvdl bsize = epp->ep_daddr + epp->ep_dsize - baddr;
284 1.1 fvdl if (bsize > 0)
285 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, bsize, baddr,
286 1.1 fvdl NULLVP, 0, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
287 1.1 fvdl
288 1.1 fvdl /*
289 1.1 fvdl * Make sure (# of pages) mapped above equals (vm_tsize + vm_dsize);
290 1.1 fvdl * obreak(2) relies on this fact. Both `vm_tsize' and `vm_dsize' are
291 1.1 fvdl * computed (in execve(2)) by rounding *up* `ep_tsize' and `ep_dsize'
292 1.1 fvdl * respectively to page boundaries.
293 1.1 fvdl * Compensate `ep_dsize' for the amount of data covered by the last
294 1.1 fvdl * text page.
295 1.1 fvdl */
296 1.1 fvdl dsize = epp->ep_dsize + execp->a_text - roundup(execp->a_text, NBPG);
297 1.1 fvdl epp->ep_dsize = (dsize > 0) ? dsize : 0;
298 1.1 fvdl return exec_aout_setup_stack(p, epp);
299 1.1 fvdl }
300 1.1 fvdl
301 1.1 fvdl int
302 1.1 fvdl exec_linux_aout_prep_qmagic(p, epp)
303 1.1 fvdl struct proc *p;
304 1.1 fvdl struct exec_package *epp;
305 1.1 fvdl {
306 1.1 fvdl struct exec *execp = epp->ep_hdr;
307 1.1 fvdl
308 1.1 fvdl epp->ep_taddr = LINUX_N_TXTADDR(*execp, QMAGIC);
309 1.1 fvdl epp->ep_tsize = execp->a_text;
310 1.1 fvdl epp->ep_daddr = LINUX_N_DATADDR(*execp, QMAGIC);
311 1.1 fvdl epp->ep_dsize = execp->a_data + execp->a_bss;
312 1.1 fvdl epp->ep_entry = execp->a_entry;
313 1.1 fvdl
314 1.1 fvdl /*
315 1.1 fvdl * check if vnode is in open for writing, because we want to
316 1.1 fvdl * demand-page out of it. if it is, don't do it, for various
317 1.1 fvdl * reasons
318 1.1 fvdl */
319 1.1 fvdl if ((execp->a_text != 0 || execp->a_data != 0) &&
320 1.1 fvdl epp->ep_vp->v_writecount != 0) {
321 1.1 fvdl #ifdef DIAGNOSTIC
322 1.1 fvdl if (epp->ep_vp->v_flag & VTEXT)
323 1.1 fvdl panic("exec: a VTEXT vnode has writecount != 0\n");
324 1.1 fvdl #endif
325 1.1 fvdl return ETXTBSY;
326 1.1 fvdl }
327 1.1 fvdl epp->ep_vp->v_flag |= VTEXT;
328 1.1 fvdl
329 1.1 fvdl /* set up command for text segment */
330 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_pagedvn, execp->a_text,
331 1.1 fvdl epp->ep_taddr, epp->ep_vp, LINUX_N_TXTOFF(*execp, QMAGIC),
332 1.1 fvdl VM_PROT_READ|VM_PROT_EXECUTE);
333 1.1 fvdl
334 1.1 fvdl /* set up command for data segment */
335 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_pagedvn, execp->a_data,
336 1.1 fvdl epp->ep_daddr, epp->ep_vp, LINUX_N_DATOFF(*execp, QMAGIC),
337 1.1 fvdl VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
338 1.1 fvdl
339 1.1 fvdl /* set up command for bss segment */
340 1.1 fvdl NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, execp->a_bss,
341 1.1 fvdl epp->ep_daddr + execp->a_data, NULLVP, 0,
342 1.1 fvdl VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
343 1.1 fvdl
344 1.1 fvdl return exec_aout_setup_stack(p, epp);
345 1.1 fvdl }
346 1.1 fvdl
347 1.1 fvdl /*
348 1.1 fvdl * The Linux system call to load shared libraries. The current shared
349 1.1 fvdl * libraries are just (QMAGIC) a.out files that are mapped onto a fixed
350 1.1 fvdl * address * in the process' address space. The address is given in
351 1.1 fvdl * a_entry. Read in the header, set up some VM commands and run them.
352 1.1 fvdl *
353 1.1 fvdl * Yes, both text and data are mapped at once, so we're left with
354 1.1 fvdl * writeable text for the shared libs. The Linux crt0 seemed to break
355 1.1 fvdl * sometimes when data was mapped seperately. It munmapped a uselib()
356 1.1 fvdl * of ld.so by hand, which failed with shared text and data for ld.so
357 1.1 fvdl * Yuck.
358 1.1 fvdl *
359 1.1 fvdl * Because of the problem with ZMAGIC executables (text starts
360 1.1 fvdl * at 0x400 in the file, but needs t be mapped at 0), ZMAGIC
361 1.1 fvdl * shared libs are not handled very efficiently :-(
362 1.1 fvdl */
363 1.1 fvdl
364 1.1 fvdl int
365 1.1 fvdl linux_uselib(p, uap, retval)
366 1.1 fvdl struct proc *p;
367 1.1 fvdl struct linux_uselib_args /* {
368 1.1 fvdl syscallarg(char *) path;
369 1.1 fvdl } */ *uap;
370 1.1 fvdl register_t *retval;
371 1.1 fvdl {
372 1.1 fvdl caddr_t sg;
373 1.1 fvdl long bsize, dsize, tsize, taddr, baddr, daddr;
374 1.1 fvdl struct nameidata ni;
375 1.1 fvdl struct vnode *vp;
376 1.1 fvdl struct exec hdr;
377 1.1 fvdl struct exec_vmcmd_set vcset;
378 1.1 fvdl int rem, i, magic, error;
379 1.1 fvdl
380 1.1 fvdl sg = stackgap_init();
381 1.2 fvdl CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
382 1.1 fvdl
383 1.1 fvdl NDINIT(&ni, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
384 1.1 fvdl
385 1.1 fvdl if ((error = namei(&ni)))
386 1.1 fvdl return error;
387 1.1 fvdl
388 1.1 fvdl vp = ni.ni_vp;
389 1.1 fvdl
390 1.1 fvdl if ((error = vn_rdwr(UIO_READ, vp, (caddr_t) &hdr, LINUX_AOUT_HDR_SIZE,
391 1.1 fvdl 0, UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred,
392 1.1 fvdl &rem, p))) {
393 1.1 fvdl vrele(vp);
394 1.1 fvdl return error;
395 1.1 fvdl }
396 1.1 fvdl
397 1.1 fvdl if (rem != 0) {
398 1.1 fvdl vrele(vp);
399 1.1 fvdl return ENOEXEC;
400 1.1 fvdl }
401 1.1 fvdl
402 1.1 fvdl magic = LINUX_N_MAGIC(&hdr);
403 1.1 fvdl taddr = hdr.a_entry & (~(NBPG - 1));
404 1.1 fvdl tsize = hdr.a_text;
405 1.1 fvdl daddr = taddr + tsize;
406 1.1 fvdl dsize = hdr.a_data + hdr.a_bss;
407 1.1 fvdl
408 1.1 fvdl if ((hdr.a_text != 0 || hdr.a_data != 0) && vp->v_writecount != 0) {
409 1.1 fvdl vrele(vp);
410 1.1 fvdl return ETXTBSY;
411 1.1 fvdl }
412 1.1 fvdl vp->v_flag |= VTEXT;
413 1.1 fvdl
414 1.1 fvdl vcset.evs_cnt = 0;
415 1.1 fvdl vcset.evs_used = 0;
416 1.1 fvdl
417 1.1 fvdl NEW_VMCMD(&vcset,
418 1.1 fvdl magic == ZMAGIC ? vmcmd_map_readvn : vmcmd_map_pagedvn,
419 1.1 fvdl hdr.a_text + hdr.a_data, taddr,
420 1.1 fvdl vp, LINUX_N_TXTOFF(hdr, magic),
421 1.1 fvdl VM_PROT_READ|VM_PROT_EXECUTE|VM_PROT_WRITE);
422 1.1 fvdl
423 1.1 fvdl baddr = roundup(daddr + hdr.a_data, NBPG);
424 1.1 fvdl bsize = daddr + dsize - baddr;
425 1.1 fvdl if (bsize > 0) {
426 1.1 fvdl NEW_VMCMD(&vcset, vmcmd_map_zero, bsize, baddr,
427 1.1 fvdl NULLVP, 0, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
428 1.1 fvdl }
429 1.1 fvdl
430 1.1 fvdl for (i = 0; i < vcset.evs_used && !error; i++) {
431 1.1 fvdl struct exec_vmcmd *vcp;
432 1.1 fvdl
433 1.1 fvdl vcp = &vcset.evs_cmds[i];
434 1.1 fvdl error = (*vcp->ev_proc)(p, vcp);
435 1.1 fvdl }
436 1.1 fvdl
437 1.1 fvdl kill_vmcmds(&vcset);
438 1.1 fvdl
439 1.1 fvdl vrele(vp);
440 1.1 fvdl
441 1.1 fvdl return error;
442 1.1 fvdl }
443 1.1 fvdl
444 1.1 fvdl /*
445 1.1 fvdl * Execve(2). Just check the alternate emulation path, and pass it on
446 1.1 fvdl * to the NetBSD execve().
447 1.1 fvdl */
448 1.1 fvdl int
449 1.1 fvdl linux_execve(p, uap, retval)
450 1.1 fvdl struct proc *p;
451 1.1 fvdl struct linux_execve_args /* {
452 1.1 fvdl syscallarg(char *) path;
453 1.1 fvdl syscallarg(char **) argv;
454 1.1 fvdl syscallarg(char **) envp;
455 1.1 fvdl } */ *uap;
456 1.1 fvdl register_t *retval;
457 1.1 fvdl {
458 1.1 fvdl caddr_t sg;
459 1.1 fvdl
460 1.1 fvdl sg = stackgap_init();
461 1.2 fvdl CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
462 1.1 fvdl
463 1.1 fvdl return execve(p, uap, retval);
464 1.1 fvdl }
465