The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/ibcs2/ibcs2_exec.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: ibcs2_exec.c,v 1.71.4.1 2009/04/01 00:25:21 snj Exp $  */
    2 
    3 /*
    4  * Copyright (c) 1994, 1995, 1998 Scott Bartram
    5  * Copyright (c) 1994 Adam Glass
    6  * Copyright (c) 1993, 1994 Christopher G. Demetriou
    7  * All rights reserved.
    8  *
    9  * originally from kern/exec_ecoff.c
   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 Scott Bartram.
   22  * 4. The name of the author may not be used to endorse or promote products
   23  *    derived from this software without specific prior written permission
   24  *
   25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   27  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   28  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   30  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   35  */
   36 
   37 #include <sys/cdefs.h>
   38 __KERNEL_RCSID(0, "$NetBSD: ibcs2_exec.c,v 1.71.4.1 2009/04/01 00:25:21 snj Exp $");
   39 
   40 #if defined(_KERNEL_OPT)
   41 #include "opt_syscall_debug.h"
   42 #endif
   43 
   44 #include <sys/param.h>
   45 #include <sys/systm.h>
   46 #include <sys/kernel.h>
   47 #include <sys/proc.h>
   48 #include <sys/malloc.h>
   49 #include <sys/namei.h>
   50 #include <sys/vnode.h>
   51 #include <sys/mount.h>
   52 #include <sys/exec.h>
   53 
   54 #include <uvm/uvm_extern.h>
   55 
   56 #include <machine/ibcs2_machdep.h>
   57 
   58 #include <compat/ibcs2/ibcs2_types.h>
   59 #include <compat/ibcs2/ibcs2_exec.h>
   60 #include <compat/ibcs2/ibcs2_signal.h>
   61 #include <compat/ibcs2/ibcs2_errno.h>
   62 #include <compat/ibcs2/ibcs2_syscall.h>
   63 
   64 static void ibcs2_e_proc_exec(struct proc *, struct exec_package *);
   65 
   66 extern struct sysent ibcs2_sysent[];
   67 extern const char * const ibcs2_syscallnames[];
   68 extern char ibcs2_sigcode[], ibcs2_esigcode[];
   69 #ifndef __HAVE_SYSCALL_INTERN
   70 void syscall(void);
   71 #endif
   72 
   73 #ifdef IBCS2_DEBUG
   74 int ibcs2_debug = 1;
   75 #endif
   76 
   77 struct uvm_object *emul_ibcs2_object;
   78 
   79 const struct emul emul_ibcs2 = {
   80         "ibcs2",
   81         "/emul/ibcs2",
   82 #ifndef __HAVE_MINIMAL_EMUL
   83         0,
   84         native_to_ibcs2_errno,
   85         IBCS2_SYS_syscall,
   86         IBCS2_SYS_NSYSENT,
   87 #endif
   88         ibcs2_sysent,
   89 #ifdef SYSCALL_DEBUG
   90         ibcs2_syscallnames,
   91 #else
   92         NULL,
   93 #endif
   94         ibcs2_sendsig,
   95         trapsignal,
   96         NULL,   /* e_tracesig */
   97         ibcs2_sigcode,
   98         ibcs2_esigcode,
   99         &emul_ibcs2_object,
  100         ibcs2_setregs,
  101         ibcs2_e_proc_exec,
  102         NULL,   /* e_proc_fork */
  103         NULL,   /* e_proc_exit */
  104         NULL,   /* e_lwp_fork */
  105         NULL,   /* e_lwp_exec */
  106 #ifdef __HAVE_SYSCALL_INTERN
  107         ibcs2_syscall_intern,
  108 #else
  109         syscall,
  110 #endif
  111         NULL,   /* e_sysctlovly */
  112         NULL,   /* e_fault */
  113 
  114         uvm_default_mapaddr,
  115         NULL,   /* e_usertrap */
  116         NULL,   /* e_sa */
  117         0,      /* e_ucsize */
  118         NULL,   /* e_startlwp */
  119 };
  120 
  121 /*
  122  * This is exec process hook. Find out if this is x.out executable, if
  123  * yes, set flag appropriately, so that emul code which needs to adjust
  124  * behaviour accordingly can do so.
  125  */
  126 static void
  127 ibcs2_e_proc_exec(struct proc *p, struct exec_package *epp)
  128 {
  129         if (epp->ep_esch->es_makecmds == exec_ibcs2_xout_makecmds)
  130                 p->p_emuldata = IBCS2_EXEC_XENIX;
  131         else
  132                 p->p_emuldata = IBCS2_EXEC_OTHER;
  133 }
  134 
  135 /*
  136  * ibcs2_exec_setup_stack(): Set up the stack segment for an
  137  * executable.
  138  *
  139  * Note that the ep_ssize parameter must be set to be the current stack
  140  * limit; this is adjusted in the body of execve() to yield the
  141  * appropriate stack segment usage once the argument length is
  142  * calculated.
  143  *
  144  * This function returns an int for uniformity with other (future) formats'
  145  * stack setup functions.  They might have errors to return.
  146  */
  147 
  148 int
  149 ibcs2_exec_setup_stack(struct lwp *l, struct exec_package *epp)
  150 {
  151         u_long max_stack_size;
  152         u_long access_linear_min, access_size;
  153         u_long noaccess_linear_min, noaccess_size;
  154 
  155 #ifndef USRSTACK32
  156 #define USRSTACK32      (0x00000000ffffffffL&~PGOFSET)
  157 #endif
  158 
  159         if (epp->ep_flags & EXEC_32) {
  160                 epp->ep_minsaddr = USRSTACK32;
  161                 max_stack_size = MAXSSIZ;
  162         } else {
  163                 epp->ep_minsaddr = USRSTACK;
  164                 max_stack_size = MAXSSIZ;
  165         }
  166         epp->ep_maxsaddr = (u_long)STACK_GROW(epp->ep_minsaddr,
  167                 max_stack_size);
  168         epp->ep_ssize = l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur;
  169 
  170         /*
  171          * set up commands for stack.  note that this takes *two*, one to
  172          * map the part of the stack which we can access, and one to map
  173          * the part which we can't.
  174          *
  175          * arguably, it could be made into one, but that would require the
  176          * addition of another mapping proc, which is unnecessary
  177          */
  178         access_size = epp->ep_ssize;
  179         access_linear_min = (u_long)STACK_ALLOC(epp->ep_minsaddr, access_size);
  180         noaccess_size = max_stack_size - access_size;
  181         noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
  182             access_size), noaccess_size);
  183         if (noaccess_size > 0) {
  184                 NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
  185                     noaccess_linear_min, NULL, 0, VM_PROT_NONE, VMCMD_STACK);
  186         }
  187         KASSERT(access_size > 0);
  188         /* XXX: some ibcs2 binaries need an executable stack. */
  189         NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
  190             access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE |
  191             VM_PROT_EXECUTE, VMCMD_STACK);
  192 
  193         return 0;
  194 }

Cache object: 3db73ff4b1f34e51f1311386736c78a7


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.