Annotation of src/sys/compat/linux/common/linux_exec.c, Revision 1.35.8.5
1.35.8.5! bouyer 1: /* $NetBSD: linux_exec.c,v 1.35.8.4 2000/12/13 15:49:49 bouyer Exp $ */
1.29 christos 2:
3: /*-
1.35.8.4 bouyer 4: * Copyright (c) 1994, 1995, 1998, 2000 The NetBSD Foundation, Inc.
1.29 christos 5: * All rights reserved.
6: *
7: * This code is derived from software contributed to The NetBSD Foundation
1.33 fvdl 8: * by Christos Zoulas, Frank van der Linden, Eric Haszlakiewicz and
9: * Thor Lancelot Simon.
1.29 christos 10: *
11: * Redistribution and use in source and binary forms, with or without
12: * modification, are permitted provided that the following conditions
13: * are met:
14: * 1. Redistributions of source code must retain the above copyright
15: * notice, this list of conditions and the following disclaimer.
16: * 2. Redistributions in binary form must reproduce the above copyright
17: * notice, this list of conditions and the following disclaimer in the
18: * documentation and/or other materials provided with the distribution.
19: * 3. All advertising materials mentioning features or use of this software
20: * must display the following acknowledgement:
21: * This product includes software developed by the NetBSD
22: * Foundation, Inc. and its contributors.
23: * 4. Neither the name of The NetBSD Foundation nor the names of its
24: * contributors may be used to endorse or promote products derived
25: * from this software without specific prior written permission.
26: *
27: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37: * POSSIBILITY OF SUCH DAMAGE.
1.1 fvdl 38: */
39:
40: #include <sys/param.h>
41: #include <sys/systm.h>
42: #include <sys/kernel.h>
43: #include <sys/proc.h>
44: #include <sys/malloc.h>
45: #include <sys/namei.h>
46: #include <sys/vnode.h>
1.13 christos 47: #include <sys/mount.h>
1.25 christos 48: #include <sys/exec.h>
1.8 fvdl 49: #include <sys/exec_elf.h>
1.1 fvdl 50:
51: #include <sys/mman.h>
1.13 christos 52: #include <sys/syscallargs.h>
1.1 fvdl 53:
54: #include <machine/cpu.h>
55: #include <machine/reg.h>
56:
1.32 christos 57: #include <compat/linux/common/linux_types.h>
58: #include <compat/linux/common/linux_signal.h>
59: #include <compat/linux/common/linux_util.h>
60: #include <compat/linux/common/linux_exec.h>
61: #include <compat/linux/common/linux_machdep.h>
62:
63: #include <compat/linux/linux_syscallargs.h>
1.4 christos 64: #include <compat/linux/linux_syscall.h>
1.35.8.2 bouyer 65: #include <compat/linux/common/linux_misc.h>
66: #include <compat/linux/common/linux_errno.h>
67: #include <compat/linux/common/linux_emuldata.h>
1.4 christos 68:
1.35.8.2 bouyer 69: extern struct sysent linux_sysent[];
70: extern const char * const linux_syscallnames[];
71: extern char linux_sigcode[], linux_esigcode[];
1.35.8.4 bouyer 72: #ifndef __HAVE_SYSCALL_INTERN
73: void syscall __P((void));
74: #endif
1.35.8.2 bouyer 75:
76: static void linux_e_proc_exec __P((struct proc *, struct exec_package *));
77: static void linux_e_proc_fork __P((struct proc *, struct proc *));
78: static void linux_e_proc_exit __P((struct proc *));
79:
1.1 fvdl 80: /*
81: * Execve(2). Just check the alternate emulation path, and pass it on
82: * to the NetBSD execve().
83: */
84: int
1.12 mycroft 85: linux_sys_execve(p, v, retval)
1.1 fvdl 86: struct proc *p;
1.11 thorpej 87: void *v;
88: register_t *retval;
89: {
1.12 mycroft 90: struct linux_sys_execve_args /* {
1.35 christos 91: syscallarg(const char *) path;
1.1 fvdl 92: syscallarg(char **) argv;
93: syscallarg(char **) envp;
1.11 thorpej 94: } */ *uap = v;
1.16 mycroft 95: struct sys_execve_args ap;
1.1 fvdl 96: caddr_t sg;
97:
1.9 christos 98: sg = stackgap_init(p->p_emul);
1.35.8.3 bouyer 99: CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
1.1 fvdl 100:
1.16 mycroft 101: SCARG(&ap, path) = SCARG(uap, path);
102: SCARG(&ap, argp) = SCARG(uap, argp);
103: SCARG(&ap, envp) = SCARG(uap, envp);
104:
105: return sys_execve(p, &ap, retval);
1.35.8.2 bouyer 106: }
107:
108: /*
109: * Emulation switch.
110: */
111: const struct emul emul_linux = {
112: "linux",
1.35.8.3 bouyer 113: "/emul/linux",
1.35.8.4 bouyer 114: #ifndef __HAVE_MINIMAL_EMUL
115: 0,
1.35.8.5! bouyer 116: (int*)native_to_linux_errno,
1.35.8.2 bouyer 117: LINUX_SYS_syscall,
118: LINUX_SYS_MAXSYSCALL,
1.35.8.4 bouyer 119: #endif
1.35.8.2 bouyer 120: linux_sysent,
121: linux_syscallnames,
1.35.8.4 bouyer 122: linux_sendsig,
1.35.8.2 bouyer 123: linux_sigcode,
124: linux_esigcode,
125: linux_e_proc_exec,
126: linux_e_proc_fork,
127: linux_e_proc_exit,
1.35.8.4 bouyer 128: #ifdef __HAVE_SYSCALL_INTERN
129: linux_syscall_intern,
1.35.8.3 bouyer 130: #else
1.35.8.4 bouyer 131: syscall,
1.35.8.3 bouyer 132: #endif
1.35.8.2 bouyer 133: };
134:
135: /*
136: * Allocate per-process structures. Called when executing Linux
137: * process. We can re-used the old emuldata - if it's not null,
138: * the executed process is of same emulation as original forked one.
139: */
140: static void
141: linux_e_proc_exec(p, epp)
142: struct proc *p;
143: struct exec_package *epp;
144: {
145: if (!p->p_emuldata) {
146: /* allocate new Linux emuldata */
147: MALLOC(p->p_emuldata, void *, sizeof(struct linux_emuldata),
148: M_EMULDATA, M_WAITOK);
149: }
150:
151: memset(p->p_emuldata, '\0', sizeof(struct linux_emuldata));
152: }
153:
154: /*
155: * Emulation per-process exit hook.
156: */
157: static void
158: linux_e_proc_exit(p)
159: struct proc *p;
160: {
161: /* free Linux emuldata and set the pointer to null */
162: FREE(p->p_emuldata, M_EMULDATA);
163: p->p_emuldata = NULL;
164: }
165:
166: /*
167: * Emulation fork hook.
168: */
169: static void
170: linux_e_proc_fork(p, parent)
171: struct proc *p, *parent;
172: {
173: /*
174: * It could be desirable to copy some stuff from parent's
175: * emuldata. We don't need anything like that for now.
176: * So just allocate new emuldata for the new process.
177: */
178: p->p_emuldata = NULL;
179: linux_e_proc_exec(p, NULL);
1.1 fvdl 180: }
CVSweb <webmaster@jp.NetBSD.org>