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_xout.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_xout.c,v 1.18 2007/12/08 18:36:01 dsl 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_xout.c,v 1.18 2007/12/08 18:36:01 dsl Exp $");
   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>
   47 #include <sys/mount.h>
   48 #include <sys/exec.h>
   49 #include <sys/resourcevar.h>
   50 
   51 #include <sys/mman.h>
   52 #include <sys/syscallargs.h>
   53 
   54 #include <sys/cpu.h>
   55 #include <machine/reg.h>
   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_errno.h>
   61 #include <compat/ibcs2/ibcs2_util.h>
   62 #include <compat/ibcs2/ibcs2_syscall.h>
   63 
   64 int exec_ibcs2_xout_prep_nmagic(struct lwp *, struct exec_package *,
   65                                      struct xexec *, struct xext *);
   66 int exec_ibcs2_xout_prep_zmagic(struct lwp *, struct exec_package *,
   67                                      struct xexec *, struct xext *);
   68 
   69 int
   70 exec_ibcs2_xout_makecmds(struct lwp *l, struct exec_package *epp)
   71 {
   72         int error;
   73         struct xexec *xp = epp->ep_hdr;
   74         struct xext *xep;
   75 
   76         if (epp->ep_hdrvalid < XOUT_HDR_SIZE)
   77                 return ENOEXEC;
   78 
   79         if ((xp->x_magic != XOUT_MAGIC) || (xp->x_cpu != XC_386))
   80                 return ENOEXEC;
   81         if ((xp->x_renv & (XE_ABS | XE_VMOD)) || !(xp->x_renv & XE_EXEC))
   82                 return ENOEXEC;
   83 
   84         xep = (void *)((char *)epp->ep_hdr + sizeof(struct xexec));
   85 #ifdef notyet
   86         if (xp->x_renv & XE_PURE)
   87                 error = exec_ibcs2_xout_prep_zmagic(l, epp, xp, xep);
   88         else
   89 #endif
   90                 error = exec_ibcs2_xout_prep_nmagic(l, epp, xp, xep);
   91 
   92         if (error)
   93                 kill_vmcmds(&epp->ep_vmcmds);
   94 
   95         return error;
   96 }
   97 
   98 /*
   99  * exec_ibcs2_xout_prep_nmagic(): Prepare a pure x.out binary's exec package
  100  *
  101  */
  102 
  103 int
  104 exec_ibcs2_xout_prep_nmagic(struct lwp *l, struct exec_package *epp, struct xexec *xp, struct xext *xep)
  105 {
  106         int error;
  107         size_t nseg, i;
  108         long baddr, bsize;
  109         struct xseg *xs;
  110         size_t resid;
  111         size_t segsize = (size_t)xep->xe_segsize;
  112 
  113         if (segsize > 16 * sizeof(*xs))
  114                 return ENOEXEC;
  115 
  116         /* read in segment table */
  117         xs = (struct xseg *)malloc(segsize, M_TEMP, M_WAITOK);
  118         error = vn_rdwr(UIO_READ, epp->ep_vp, (void *)xs,
  119                         segsize, xep->xe_segpos,
  120                         UIO_SYSSPACE, IO_NODELOCKED, l->l_cred,
  121                         &resid, NULL);
  122         if (error) {
  123                 DPRINTF(("segment table read error %d\n", error));
  124                 free(xs, M_TEMP);
  125                 return ENOEXEC;
  126         }
  127 
  128         for (nseg = segsize / sizeof(*xs), i = 0; i < nseg; i++) {
  129                 switch (xs[i].xs_type) {
  130                 case XS_TTEXT:  /* text segment */
  131 
  132                         DPRINTF(("text addr %lx psize %ld vsize %ld off %ld\n",
  133                                  xs[i].xs_rbase, xs[i].xs_psize,
  134                                  xs[i].xs_vsize, xs[i].xs_filpos));
  135 
  136                         epp->ep_taddr = xs[i].xs_rbase; /* XXX - align ??? */
  137                         epp->ep_tsize = xs[i].xs_vsize;
  138 
  139                         DPRINTF(("VMCMD: addr %lx size %ld offset %ld\n",
  140                                  epp->ep_taddr, epp->ep_tsize,
  141                                  xs[i].xs_filpos));
  142                         NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn,
  143                                   epp->ep_tsize, epp->ep_taddr,
  144                                   epp->ep_vp, xs[i].xs_filpos,
  145                                   VM_PROT_READ|VM_PROT_EXECUTE);
  146                         break;
  147 
  148                 case XS_TDATA:  /* data segment */
  149 
  150                         DPRINTF(("data addr %lx psize %ld vsize %ld off %ld\n",
  151                                  xs[i].xs_rbase, xs[i].xs_psize,
  152                                  xs[i].xs_vsize, xs[i].xs_filpos));
  153 
  154                         epp->ep_daddr = xs[i].xs_rbase; /* XXX - align ??? */
  155                         epp->ep_dsize = xs[i].xs_vsize;
  156 
  157                         DPRINTF(("VMCMD: addr %lx size %ld offset %ld\n",
  158                                  epp->ep_daddr, xs[i].xs_psize,
  159                                  xs[i].xs_filpos));
  160                         NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn,
  161                                   xs[i].xs_psize, epp->ep_daddr,
  162                                   epp->ep_vp, xs[i].xs_filpos,
  163                                   VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
  164 
  165                         /* set up command for bss segment */
  166                         baddr = round_page(epp->ep_daddr + xs[i].xs_psize);
  167                         bsize = epp->ep_daddr + epp->ep_dsize - baddr;
  168                         if (bsize > 0) {
  169                                 DPRINTF(("VMCMD: bss addr %lx size %ld off %d\n",
  170                                          baddr, bsize, 0));
  171                                 NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero,
  172                                           bsize, baddr, NULLVP, 0,
  173                                           VM_PROT_READ|VM_PROT_WRITE|
  174                                           VM_PROT_EXECUTE);
  175                         }
  176                         break;
  177 
  178                 default:
  179                         break;
  180                 }
  181         }
  182 
  183         /* set up entry point */
  184         epp->ep_entry = xp->x_entry;
  185 
  186         DPRINTF(("text addr: %lx size: %ld data addr: %lx size: %ld entry: %lx\n",
  187                  epp->ep_taddr, epp->ep_tsize,
  188                  epp->ep_daddr, epp->ep_dsize,
  189                  epp->ep_entry));
  190 
  191         free(xs, M_TEMP);
  192         return (*epp->ep_esch->es_setup_stack)(l, epp);
  193 }

Cache object: bd2daf06e67975020418d0ae35110ced


[ 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.