linux_exec.c revision 1.32 1 1.32 christos /* $NetBSD: linux_exec.c,v 1.32 1998/10/03 20:17:40 christos Exp $ */
2 1.29 christos
3 1.29 christos /*-
4 1.29 christos * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 1.29 christos * All rights reserved.
6 1.29 christos *
7 1.29 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.31 erh * by Eric Haszlakiewicz and Thor Lancelot Simon.
9 1.31 erh *
10 1.31 erh * This code is derived from software contributed to The NetBSD Foundation
11 1.29 christos * by Christos Zoulas.
12 1.29 christos *
13 1.29 christos * Redistribution and use in source and binary forms, with or without
14 1.29 christos * modification, are permitted provided that the following conditions
15 1.29 christos * are met:
16 1.29 christos * 1. Redistributions of source code must retain the above copyright
17 1.29 christos * notice, this list of conditions and the following disclaimer.
18 1.29 christos * 2. Redistributions in binary form must reproduce the above copyright
19 1.29 christos * notice, this list of conditions and the following disclaimer in the
20 1.29 christos * documentation and/or other materials provided with the distribution.
21 1.29 christos * 3. All advertising materials mentioning features or use of this software
22 1.29 christos * must display the following acknowledgement:
23 1.29 christos * This product includes software developed by the NetBSD
24 1.29 christos * Foundation, Inc. and its contributors.
25 1.29 christos * 4. Neither the name of The NetBSD Foundation nor the names of its
26 1.29 christos * contributors may be used to endorse or promote products derived
27 1.29 christos * from this software without specific prior written permission.
28 1.29 christos *
29 1.29 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30 1.29 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 1.29 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 1.29 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33 1.29 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 1.29 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 1.29 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 1.29 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 1.29 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 1.29 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 1.29 christos * POSSIBILITY OF SUCH DAMAGE.
40 1.29 christos */
41 1.1 fvdl
42 1.1 fvdl /*
43 1.1 fvdl * Copyright (c) 1995 Frank van der Linden
44 1.1 fvdl * All rights reserved.
45 1.1 fvdl *
46 1.1 fvdl * Redistribution and use in source and binary forms, with or without
47 1.1 fvdl * modification, are permitted provided that the following conditions
48 1.1 fvdl * are met:
49 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
50 1.1 fvdl * notice, this list of conditions and the following disclaimer.
51 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
52 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
53 1.1 fvdl * documentation and/or other materials provided with the distribution.
54 1.7 fvdl * 3. The name of the author may not be used to endorse or promote products
55 1.1 fvdl * derived from this software without specific prior written permission
56 1.1 fvdl *
57 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 1.1 fvdl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 1.1 fvdl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 1.1 fvdl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 1.1 fvdl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62 1.1 fvdl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 1.1 fvdl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 1.1 fvdl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 1.1 fvdl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66 1.1 fvdl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 1.1 fvdl *
68 1.7 fvdl * based on exec_aout.c, sunos_exec.c and svr4_exec.c
69 1.1 fvdl */
70 1.1 fvdl
71 1.1 fvdl #include <sys/param.h>
72 1.1 fvdl #include <sys/systm.h>
73 1.1 fvdl #include <sys/kernel.h>
74 1.1 fvdl #include <sys/proc.h>
75 1.1 fvdl #include <sys/malloc.h>
76 1.1 fvdl #include <sys/namei.h>
77 1.1 fvdl #include <sys/vnode.h>
78 1.13 christos #include <sys/mount.h>
79 1.25 christos #include <sys/exec.h>
80 1.8 fvdl #include <sys/exec_elf.h>
81 1.1 fvdl
82 1.1 fvdl #include <sys/mman.h>
83 1.13 christos #include <sys/syscallargs.h>
84 1.13 christos
85 1.1 fvdl #include <vm/vm.h>
86 1.1 fvdl #include <vm/vm_param.h>
87 1.1 fvdl #include <vm/vm_map.h>
88 1.1 fvdl
89 1.1 fvdl #include <machine/cpu.h>
90 1.1 fvdl #include <machine/reg.h>
91 1.1 fvdl
92 1.32 christos #include <compat/linux/common/linux_types.h>
93 1.32 christos #include <compat/linux/common/linux_signal.h>
94 1.32 christos #include <compat/linux/common/linux_siginfo.h>
95 1.32 christos #include <compat/linux/common/linux_util.h>
96 1.32 christos #include <compat/linux/common/linux_exec.h>
97 1.32 christos #include <compat/linux/common/linux_machdep.h>
98 1.32 christos
99 1.32 christos #include <compat/linux/linux_syscallargs.h>
100 1.4 christos #include <compat/linux/linux_syscall.h>
101 1.8 fvdl
102 1.4 christos
103 1.9 christos const char linux_emul_path[] = "/emul/linux";
104 1.1 fvdl
105 1.1 fvdl /*
106 1.1 fvdl * Execve(2). Just check the alternate emulation path, and pass it on
107 1.1 fvdl * to the NetBSD execve().
108 1.1 fvdl */
109 1.1 fvdl int
110 1.12 mycroft linux_sys_execve(p, v, retval)
111 1.1 fvdl struct proc *p;
112 1.11 thorpej void *v;
113 1.11 thorpej register_t *retval;
114 1.11 thorpej {
115 1.12 mycroft struct linux_sys_execve_args /* {
116 1.1 fvdl syscallarg(char *) path;
117 1.1 fvdl syscallarg(char **) argv;
118 1.1 fvdl syscallarg(char **) envp;
119 1.11 thorpej } */ *uap = v;
120 1.16 mycroft struct sys_execve_args ap;
121 1.1 fvdl caddr_t sg;
122 1.1 fvdl
123 1.9 christos sg = stackgap_init(p->p_emul);
124 1.9 christos LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
125 1.1 fvdl
126 1.16 mycroft SCARG(&ap, path) = SCARG(uap, path);
127 1.16 mycroft SCARG(&ap, argp) = SCARG(uap, argp);
128 1.16 mycroft SCARG(&ap, envp) = SCARG(uap, envp);
129 1.16 mycroft
130 1.16 mycroft return sys_execve(p, &ap, retval);
131 1.1 fvdl }
132