root/compat/vax1k/vax1k_exec.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. exec_vax1k_makecmds
  2. exec_vax1k_prep_anymagic

    1 /*      $OpenBSD: vax1k_exec.c,v 1.2 2002/03/14 01:26:51 millert Exp $  */
    2 /*      $NetBSD: vax1k_exec.c,v 1.1 1998/08/21 13:25:47 ragge Exp $     */
    3 
    4 /*
    5  * Copyright (c) 1993, 1994 Christopher G. Demetriou
    6  * All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. All advertising materials mentioning features or use of this software
   17  *    must display the following acknowledgement:
   18  *      This product includes software developed by Christopher G. Demetriou.
   19  * 4. The name of the author may not be used to endorse or promote products
   20  *    derived from this software without specific prior written permission
   21  *
   22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   32  */
   33 
   34 /*
   35  * Exec glue to provide compatibility with older NetBSD vax1k exectuables.
   36  *
   37  * Because NetBSD/vax now uses 4k page size, older binaries (that started
   38  * on an 1k boundary) cannot be mmap'ed. Therefore they are read in 
   39  * (via vn_rdwr) as OMAGIC binaries and executed. This will use a little
   40  * bit more memory, but otherwise won't affect the execution speed.
   41  */
   42 
   43 #include <sys/param.h>
   44 #include <sys/systm.h>
   45 #include <sys/proc.h>
   46 #include <sys/malloc.h>
   47 #include <sys/vnode.h>
   48 #include <sys/exec.h>
   49 #include <sys/resourcevar.h>
   50 
   51 #include <compat/vax1k/vax1k_exec.h>
   52 
   53 int     exec_vax1k_prep_anymagic(struct proc *, struct exec_package *, int);
   54 
   55 /*
   56  * exec_vax1k_makecmds(): Check if it's an a.out-format executable
   57  * with an vax1k magic number.
   58  *
   59  * Given a proc pointer and an exec package pointer, see if the referent
   60  * of the epp is in a.out format.  Just check 'standard' magic numbers for
   61  * this architecture.
   62  *
   63  * This function, in the former case, or the hook, in the latter, is
   64  * responsible for creating a set of vmcmds which can be used to build
   65  * the process's vm space and inserting them into the exec package.
   66  */
   67 
   68 int
   69 exec_vax1k_makecmds(p, epp)
   70         struct proc *p;
   71         struct exec_package *epp;
   72 {
   73         u_long midmag, magic;
   74         u_short mid;
   75         int error;
   76         struct exec *execp = epp->ep_hdr;
   77 
   78         if (epp->ep_hdrvalid < sizeof(struct exec))
   79                 return ENOEXEC;
   80 
   81         midmag = ntohl(execp->a_midmag);
   82         mid = (midmag >> 16) & 0x3ff;
   83         magic = midmag & 0xffff;
   84 
   85         midmag = mid << 16 | magic;
   86 
   87         switch (midmag) {
   88         case (MID_VAX1K << 16) | ZMAGIC:
   89                 error = exec_vax1k_prep_anymagic(p, epp, 0);
   90                 break;
   91 
   92         case (MID_VAX1K << 16) | NMAGIC:
   93         case (MID_VAX1K << 16) | OMAGIC:
   94                 error = exec_vax1k_prep_anymagic(p, epp, sizeof(struct exec));
   95                 break;
   96 
   97         default:
   98                 error = ENOEXEC;
   99         }
  100 
  101         if (error)
  102                 kill_vmcmds(&epp->ep_vmcmds);
  103 
  104         return error;
  105 }
  106 
  107 /*
  108  * exec_vax1k_prep_anymagic(): Prepare an vax1k ?MAGIC binary's exec package
  109  *
  110  * First, set of the various offsets/lengths in the exec package.
  111  * Note that all code is mapped RW; no protection, but because it is
  112  * only used for compatibility it won't hurt.
  113  *
  114  */
  115 int
  116 exec_vax1k_prep_anymagic(p, epp, off)
  117         struct proc *p;
  118         struct exec_package *epp;
  119         int off;
  120 {
  121         long etmp, tmp;
  122         struct exec *execp = epp->ep_hdr;
  123 
  124         epp->ep_taddr = execp->a_entry & ~(VAX1K_USRTEXT - 1);
  125         epp->ep_tsize = execp->a_text + execp->a_data;
  126         epp->ep_daddr = epp->ep_tsize + epp->ep_taddr;
  127         epp->ep_dsize = execp->a_bss;
  128         epp->ep_entry = execp->a_entry;
  129 
  130         /* set up command for text segment */
  131         NEW_VMCMD(&epp->ep_vmcmds, vax1k_map_readvn,
  132             epp->ep_tsize,  epp->ep_taddr, epp->ep_vp, off,
  133             VM_PROT_WRITE|VM_PROT_READ|VM_PROT_EXECUTE);
  134 
  135         tmp = round_page(epp->ep_daddr);
  136         etmp = execp->a_bss - (tmp - epp->ep_daddr);
  137 
  138         /* set up command for bss segment */
  139         if (etmp > 0)
  140                 NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, etmp, tmp, NULLVP, 0,
  141                     VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
  142 
  143         return exec_setup_stack(p, epp);
  144 }

/* [<][>][^][v][top][bottom][index][help] */