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