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