Home | History | Annotate | Line # | Download | only in freebsd
freebsd_exec.c revision 1.1
      1  1.1  mycroft /*	$NetBSD: freebsd_exec.c,v 1.1 1995/10/10 01:19:27 mycroft Exp $	*/
      2  1.1  mycroft 
      3  1.1  mycroft /*
      4  1.1  mycroft  * Copyright (c) 1993, 1994 Christopher G. Demetriou
      5  1.1  mycroft  * All rights reserved.
      6  1.1  mycroft  *
      7  1.1  mycroft  * Redistribution and use in source and binary forms, with or without
      8  1.1  mycroft  * modification, are permitted provided that the following conditions
      9  1.1  mycroft  * are met:
     10  1.1  mycroft  * 1. Redistributions of source code must retain the above copyright
     11  1.1  mycroft  *    notice, this list of conditions and the following disclaimer.
     12  1.1  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  mycroft  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  mycroft  *    documentation and/or other materials provided with the distribution.
     15  1.1  mycroft  * 3. All advertising materials mentioning features or use of this software
     16  1.1  mycroft  *    must display the following acknowledgement:
     17  1.1  mycroft  *      This product includes software developed by Christopher G. Demetriou.
     18  1.1  mycroft  * 4. The name of the author may not be used to endorse or promote products
     19  1.1  mycroft  *    derived from this software without specific prior written permission
     20  1.1  mycroft  *
     21  1.1  mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1  mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1  mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1  mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1  mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1  mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1  mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1  mycroft  */
     32  1.1  mycroft 
     33  1.1  mycroft #include <sys/param.h>
     34  1.1  mycroft #include <sys/systm.h>
     35  1.1  mycroft #include <sys/proc.h>
     36  1.1  mycroft #include <sys/malloc.h>
     37  1.1  mycroft #include <sys/vnode.h>
     38  1.1  mycroft #include <sys/exec.h>
     39  1.1  mycroft #include <sys/resourcevar.h>
     40  1.1  mycroft #include <vm/vm.h>
     41  1.1  mycroft 
     42  1.1  mycroft #include <machine/freebsd_machdep.h>
     43  1.1  mycroft 
     44  1.1  mycroft #include <compat/freebsd/freebsd_syscall.h>
     45  1.1  mycroft #include <compat/freebsd/freebsd_exec.h>
     46  1.1  mycroft 
     47  1.1  mycroft extern struct sysent freebsd_sysent[];
     48  1.1  mycroft extern char *freebsd_syscallnames[];
     49  1.1  mycroft 
     50  1.1  mycroft struct emul emul_freebsd = {
     51  1.1  mycroft 	"freebsd",
     52  1.1  mycroft 	NULL,
     53  1.1  mycroft 	freebsd_sendsig,
     54  1.1  mycroft 	FREEBSD_SYS_syscall,
     55  1.1  mycroft 	FREEBSD_SYS_MAXSYSCALL,
     56  1.1  mycroft 	freebsd_sysent,
     57  1.1  mycroft 	freebsd_syscallnames,
     58  1.1  mycroft 	0,
     59  1.1  mycroft 	copyargs,
     60  1.1  mycroft 	setregs,
     61  1.1  mycroft 	freebsd_sigcode,
     62  1.1  mycroft 	freebsd_esigcode,
     63  1.1  mycroft };
     64  1.1  mycroft 
     65  1.1  mycroft /*
     66  1.1  mycroft  * exec_aout_makecmds(): Check if it's an a.out-format executable.
     67  1.1  mycroft  *
     68  1.1  mycroft  * Given a proc pointer and an exec package pointer, see if the referent
     69  1.1  mycroft  * of the epp is in a.out format.  First check 'standard' magic numbers for
     70  1.1  mycroft  * this architecture.  If that fails, try a cpu-dependent hook.
     71  1.1  mycroft  *
     72  1.1  mycroft  * This function, in the former case, or the hook, in the latter, is
     73  1.1  mycroft  * responsible for creating a set of vmcmds which can be used to build
     74  1.1  mycroft  * the process's vm space and inserting them into the exec package.
     75  1.1  mycroft  */
     76  1.1  mycroft 
     77  1.1  mycroft int
     78  1.1  mycroft exec_freebsd_aout_makecmds(p, epp)
     79  1.1  mycroft 	struct proc *p;
     80  1.1  mycroft 	struct exec_package *epp;
     81  1.1  mycroft {
     82  1.1  mycroft 	u_long midmag;
     83  1.1  mycroft 	int error = ENOEXEC;
     84  1.1  mycroft 	struct exec *execp = epp->ep_hdr;
     85  1.1  mycroft 
     86  1.1  mycroft 	if (epp->ep_hdrvalid < sizeof(struct exec))
     87  1.1  mycroft 		return ENOEXEC;
     88  1.1  mycroft 
     89  1.1  mycroft 	midmag = FREEBSD_N_GETMID(*execp) << 16 | FREEBSD_N_GETMAGIC(*execp);
     90  1.1  mycroft 
     91  1.1  mycroft 	/* assume FreeBSD's MID_MACHINE and [ZQNO]MAGIC is same as NetBSD's */
     92  1.1  mycroft 	switch (midmag) {
     93  1.1  mycroft 	case (MID_MACHINE << 16) | ZMAGIC:
     94  1.1  mycroft 		error = cpu_exec_aout_prep_oldzmagic(p, epp);
     95  1.1  mycroft 		break;
     96  1.1  mycroft 	case (MID_MACHINE << 16) | QMAGIC:
     97  1.1  mycroft 		error = exec_aout_prep_zmagic(p, epp);
     98  1.1  mycroft 		break;
     99  1.1  mycroft 	case (MID_MACHINE << 16) | NMAGIC:
    100  1.1  mycroft 		error = exec_aout_prep_nmagic(p, epp);
    101  1.1  mycroft 		break;
    102  1.1  mycroft 	case (MID_MACHINE << 16) | OMAGIC:
    103  1.1  mycroft 		error = exec_aout_prep_omagic(p, epp);
    104  1.1  mycroft 		break;
    105  1.1  mycroft 	}
    106  1.1  mycroft 	if (error == 0)
    107  1.1  mycroft 		epp->ep_emul = &emul_freebsd;
    108  1.1  mycroft 	else
    109  1.1  mycroft 		kill_vmcmds(&epp->ep_vmcmds);
    110  1.1  mycroft 
    111  1.1  mycroft 	return error;
    112  1.1  mycroft }
    113