Home | History | Annotate | Line # | Download | only in i386
linux_exec_machdep.c revision 1.17.32.1
      1  1.17.32.1     skrll /*	$NetBSD: linux_exec_machdep.c,v 1.17.32.1 2017/08/28 17:51:58 skrll Exp $	*/
      2        1.1  christos 
      3        1.1  christos /*-
      4        1.1  christos  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5        1.1  christos  * All rights reserved.
      6        1.1  christos  *
      7        1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1  christos  * by Christos Zoulas.
      9        1.1  christos  *
     10        1.1  christos  * Redistribution and use in source and binary forms, with or without
     11        1.1  christos  * modification, are permitted provided that the following conditions
     12        1.1  christos  * are met:
     13        1.1  christos  * 1. Redistributions of source code must retain the above copyright
     14        1.1  christos  *    notice, this list of conditions and the following disclaimer.
     15        1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     17        1.1  christos  *    documentation and/or other materials provided with the distribution.
     18        1.1  christos  *
     19        1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1  christos  */
     31        1.1  christos 
     32        1.1  christos #include <sys/cdefs.h>
     33  1.17.32.1     skrll __KERNEL_RCSID(0, "$NetBSD: linux_exec_machdep.c,v 1.17.32.1 2017/08/28 17:51:58 skrll Exp $");
     34        1.1  christos 
     35        1.1  christos #if defined(_KERNEL_OPT)
     36        1.1  christos #include "opt_user_ldt.h"
     37        1.1  christos #endif
     38        1.1  christos 
     39        1.1  christos #include <sys/param.h>
     40        1.1  christos #include <sys/systm.h>
     41        1.1  christos #include <sys/resource.h>
     42        1.1  christos #include <sys/proc.h>
     43        1.1  christos #include <sys/conf.h>
     44        1.1  christos #include <sys/exec.h>
     45        1.1  christos #include <sys/exec_elf.h>
     46        1.1  christos #include <sys/vnode.h>
     47        1.1  christos #include <sys/lwp.h>
     48        1.1  christos 
     49        1.4        ad #include <sys/cpu.h>
     50        1.1  christos #include <machine/vmparam.h>
     51        1.1  christos 
     52        1.1  christos #include <uvm/uvm.h>
     53        1.1  christos 
     54        1.6  christos #include <sys/syscallargs.h>
     55        1.6  christos 
     56        1.6  christos #ifndef DEBUG_LINUX
     57        1.6  christos #define DPRINTF(a)
     58        1.6  christos #else
     59        1.6  christos #define DPRINTF(a)	uprintf a
     60        1.6  christos #endif
     61        1.6  christos 
     62        1.1  christos #include <compat/linux/common/linux_types.h>
     63        1.1  christos #include <compat/linux/common/linux_signal.h>
     64        1.6  christos #include <compat/linux/common/linux_machdep.h>
     65        1.1  christos #include <compat/linux/common/linux_util.h>
     66        1.1  christos #include <compat/linux/common/linux_ioctl.h>
     67        1.1  christos #include <compat/linux/common/linux_hdio.h>
     68        1.1  christos #include <compat/linux/common/linux_exec.h>
     69        1.1  christos #include <compat/linux/common/linux_errno.h>
     70       1.17    plunky #include <compat/linux/linux_syscallargs.h>
     71        1.1  christos 
     72        1.1  christos int
     73        1.3  christos linux_exec_setup_stack(struct lwp *l, struct exec_package *epp)
     74        1.1  christos {
     75        1.1  christos 	u_long max_stack_size;
     76        1.1  christos 	u_long access_linear_min, access_size;
     77        1.1  christos 	u_long noaccess_linear_min, noaccess_size;
     78        1.1  christos 
     79        1.1  christos #ifndef	USRSTACK32
     80        1.1  christos #define USRSTACK32	(0x00000000ffffffffL&~PGOFSET)
     81        1.1  christos #endif
     82        1.1  christos 
     83        1.1  christos 	if (epp->ep_flags & EXEC_32) {
     84        1.1  christos 		epp->ep_minsaddr = USRSTACK32;
     85        1.1  christos 		max_stack_size = MAXSSIZ;
     86        1.1  christos 	} else {
     87        1.1  christos 		epp->ep_minsaddr = USRSTACK;
     88        1.1  christos 		max_stack_size = MAXSSIZ;
     89        1.1  christos 	}
     90        1.1  christos 
     91        1.1  christos 	if (epp->ep_minsaddr > LINUX_USRSTACK)
     92        1.1  christos 		epp->ep_minsaddr = LINUX_USRSTACK;
     93        1.1  christos #ifdef DEBUG_LINUX
     94        1.1  christos 	else {
     95        1.1  christos 		/*
     96        1.1  christos 		 * Someone needs to make KERNBASE and TEXTADDR
     97        1.1  christos 		 * java versions < 1.4.2 need the stack to be
     98        1.1  christos 		 * at 0xC0000000
     99        1.1  christos 		 */
    100        1.1  christos 		uprintf("Cannot setup stack to 0xC0000000, "
    101        1.1  christos 		    "java will not work properly\n");
    102        1.1  christos 	}
    103        1.1  christos #endif
    104        1.2     perry 	epp->ep_maxsaddr = (u_long)STACK_GROW(epp->ep_minsaddr,
    105        1.1  christos 		max_stack_size);
    106        1.3  christos 	epp->ep_ssize = l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur;
    107        1.1  christos 
    108        1.1  christos 	/*
    109        1.1  christos 	 * set up commands for stack.  note that this takes *two*, one to
    110        1.1  christos 	 * map the part of the stack which we can access, and one to map
    111        1.1  christos 	 * the part which we can't.
    112        1.1  christos 	 *
    113        1.1  christos 	 * arguably, it could be made into one, but that would require the
    114        1.1  christos 	 * addition of another mapping proc, which is unnecessary
    115        1.1  christos 	 */
    116        1.1  christos 	access_size = epp->ep_ssize;
    117        1.1  christos 	access_linear_min = (u_long)STACK_ALLOC(epp->ep_minsaddr, access_size);
    118        1.1  christos 	noaccess_size = max_stack_size - access_size;
    119        1.2     perry 	noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
    120        1.1  christos 	    access_size), noaccess_size);
    121        1.1  christos 	if (noaccess_size > 0) {
    122       1.12       mrg 		NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
    123       1.12       mrg 		    noaccess_linear_min, NULLVP, 0, VM_PROT_NONE, VMCMD_STACK);
    124        1.1  christos 	}
    125        1.1  christos 	KASSERT(access_size > 0);
    126       1.12       mrg 	NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
    127       1.12       mrg 	    access_linear_min, NULLVP, 0, VM_PROT_READ | VM_PROT_WRITE,
    128       1.12       mrg 	    VMCMD_STACK);
    129        1.1  christos 
    130        1.1  christos 	return 0;
    131        1.1  christos }
    132        1.6  christos 
    133        1.6  christos int
    134        1.6  christos linux_sys_set_thread_area(struct lwp *l,
    135        1.6  christos     const struct linux_sys_set_thread_area_args *uap, register_t *retval)
    136        1.6  christos {
    137       1.16       chs 	/* {
    138       1.16       chs 		syscallarg(struct linux_user_desc *) desc;
    139       1.16       chs 	} */
    140        1.6  christos 
    141       1.16       chs 	return linux_lwp_setprivate(l, SCARG(uap, desc));
    142        1.6  christos }
    143        1.6  christos 
    144        1.6  christos int
    145        1.6  christos linux_sys_get_thread_area(struct lwp *l,
    146        1.6  christos     const struct linux_sys_get_thread_area_args *uap, register_t *retval)
    147        1.6  christos {
    148       1.16       chs 	/* {
    149       1.16       chs 		syscallarg(struct linux_user_desc *) desc;
    150       1.16       chs 	} */
    151        1.6  christos 
    152       1.16       chs 	/* glibc doesn't actually call this. */
    153       1.16       chs 	return ENOSYS;
    154        1.6  christos }
    155