Home | History | Annotate | Line # | Download | only in i386
      1 /*	$NetBSD: aout_machdep.c,v 1.1 2008/11/20 10:53:09 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum, by Jason R. Thorpe of the Numerical Aerospace
      9  * Simulation Facility, NASA Ames Research Center and by Julio M. Merino Vidal.
     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  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*-
     34  * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
     35  * All rights reserved.
     36  *
     37  * This code is derived from software contributed to Berkeley by
     38  * William Jolitz.
     39  *
     40  * Redistribution and use in source and binary forms, with or without
     41  * modification, are permitted provided that the following conditions
     42  * are met:
     43  * 1. Redistributions of source code must retain the above copyright
     44  *    notice, this list of conditions and the following disclaimer.
     45  * 2. Redistributions in binary form must reproduce the above copyright
     46  *    notice, this list of conditions and the following disclaimer in the
     47  *    documentation and/or other materials provided with the distribution.
     48  * 3. Neither the name of the University nor the names of its contributors
     49  *    may be used to endorse or promote products derived from this software
     50  *    without specific prior written permission.
     51  *
     52  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  * SUCH DAMAGE.
     63  *
     64  *	@(#)machdep.c	7.4 (Berkeley) 6/3/91
     65  */
     66 
     67 #include <sys/cdefs.h>
     68 __KERNEL_RCSID(0, "$NetBSD: aout_machdep.c,v 1.1 2008/11/20 10:53:09 ad Exp $");
     69 
     70 #ifdef _KERNEL_OPT
     71 #include "opt_compat_netbsd.h"
     72 #endif
     73 
     74 #include <sys/param.h>
     75 #include <sys/systm.h>
     76 #include <sys/exec.h>
     77 #include <sys/exec_aout.h>
     78 
     79 #ifdef COMPAT_NOMID
     80 static int
     81 exec_nomid(struct lwp *l, struct exec_package *epp)
     82 {
     83 	int error;
     84 	u_long midmag, magic;
     85 	u_short mid;
     86 	struct exec *execp = epp->ep_hdr;
     87 
     88 	/* check on validity of epp->ep_hdr performed by exec_out_makecmds */
     89 
     90 	midmag = ntohl(execp->a_midmag);
     91 	mid = (midmag >> 16) & 0xffff;
     92 	magic = midmag & 0xffff;
     93 
     94 	if (magic == 0) {
     95 		magic = (execp->a_midmag & 0xffff);
     96 		mid = MID_ZERO;
     97 	}
     98 
     99 	midmag = mid << 16 | magic;
    100 
    101 	switch (midmag) {
    102 	case (MID_ZERO << 16) | ZMAGIC:
    103 		/*
    104 		 * 386BSD's ZMAGIC format:
    105 		 */
    106 		error = exec_aout_prep_oldzmagic(l, epp);
    107 		break;
    108 
    109 	case (MID_ZERO << 16) | QMAGIC:
    110 		/*
    111 		 * BSDI's QMAGIC format:
    112 		 * same as new ZMAGIC format, but with different magic number
    113 		 */
    114 		error = exec_aout_prep_zmagic(l, epp);
    115 		break;
    116 
    117 	case (MID_ZERO << 16) | NMAGIC:
    118 		/*
    119 		 * BSDI's NMAGIC format:
    120 		 * same as NMAGIC format, but with different magic number
    121 		 * and with text starting at 0.
    122 		 */
    123 		error = exec_aout_prep_oldnmagic(l, epp);
    124 		break;
    125 
    126 	case (MID_ZERO << 16) | OMAGIC:
    127 		/*
    128 		 * BSDI's OMAGIC format:
    129 		 * same as OMAGIC format, but with different magic number
    130 		 * and with text starting at 0.
    131 		 */
    132 		error = exec_aout_prep_oldomagic(l, epp);
    133 		break;
    134 
    135 	default:
    136 		error = ENOEXEC;
    137 	}
    138 
    139 	return error;
    140 }
    141 #endif
    142 
    143 /*
    144  * cpu_exec_aout_makecmds():
    145  *	CPU-dependent a.out format hook for execve().
    146  *
    147  * Determine of the given exec package refers to something which we
    148  * understand and, if so, set up the vmcmds for it.
    149  *
    150  * On the i386, old (386bsd) ZMAGIC binaries and BSDI QMAGIC binaries
    151  * if COMPAT_NOMID is given as a kernel option.
    152  */
    153 int
    154 cpu_exec_aout_makecmds(struct lwp *l, struct exec_package *epp)
    155 {
    156 	int error = ENOEXEC;
    157 
    158 #ifdef COMPAT_NOMID
    159 	if ((error = exec_nomid(l, epp)) == 0)
    160 		return error;
    161 #else
    162 	(void) l;
    163 	(void) epp;
    164 #endif /* ! COMPAT_NOMID */
    165 
    166 	return error;
    167 }
    168