1 /* $OpenBSD: bsdos_exec.c,v 1.4 2001/11/06 19:53:17 miod Exp $ */ 2 3 /* 4 * Copyright (c) 1993, 1994 Christopher G. Demetriou 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Christopher G. Demetriou. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/param.h> 34 #include <sys/systm.h> 35 #include <sys/proc.h> 36 #include <sys/signalvar.h> 37 #include <sys/malloc.h> 38 #include <sys/vnode.h> 39 #include <sys/exec.h> 40 #include <sys/resourcevar.h> 41 #include <uvm/uvm_extern.h> 42 43 #if 0 44 #include <machine/bsdos_machdep.h> 45 #endif 46 47 #include <compat/bsdos/bsdos_exec.h> 48 #include <compat/bsdos/bsdos_syscall.h> 49 50 extern struct sysent bsdos_sysent[]; 51 #ifdef SYSCALL_DEBUG 52 extern char *bsdos_syscallnames[]; 53 #endif 54 55 extern char sigcode[], esigcode[]; 56 57 struct emul emul_bsdos = { 58 "bsdos", 59 NULL, 60 sendsig, 61 BSDOS_SYS_syscall, 62 BSDOS_SYS_MAXSYSCALL, 63 bsdos_sysent, 64 #ifdef SYSCALL_DEBUG 65 bsdos_syscallnames, 66 #else 67 NULL, 68 #endif 69 0, 70 copyargs, 71 setregs, 72 NULL, 73 sigcode, 74 esigcode, 75 }; 76 77 /* 78 * exec_aout_makecmds(): Check if it's an a.out-format executable. 79 * 80 * Given a proc pointer and an exec package pointer, see if the referent 81 * of the epp is in a.out format. First check 'standard' magic numbers for 82 * this architecture. If that fails, try a cpu-dependent hook. 83 * 84 * This function, in the former case, or the hook, in the latter, is 85 * responsible for creating a set of vmcmds which can be used to build 86 * the process's vm space and inserting them into the exec package. 87 */ 88 89 int 90 exec_bsdos_aout_makecmds(p, epp) 91 struct proc *p; 92 struct exec_package *epp; 93 { 94 u_long midmag, magic; 95 u_short mid; 96 int error = ENOEXEC; 97 struct exec *execp = epp->ep_hdr; 98 99 if (epp->ep_hdrvalid < sizeof(struct exec)) 100 return ENOEXEC; 101 102 midmag = ntohl(execp->a_midmag); 103 mid = (midmag >> 16) & 0xffff; 104 magic = midmag & 0xffff; 105 106 if (magic == 0) { 107 magic = (execp->a_midmag & 0xffff); 108 mid = MID_BSDOS; 109 } 110 111 midmag = mid << 16 | magic; 112 113 switch (midmag) { 114 case (MID_BSDOS << 16) | ZMAGIC: 115 /* 116 * 386BSD's ZMAGIC format: 117 */ 118 error = exec_aout_prep_oldzmagic(p, epp); 119 break; 120 case (MID_BSDOS << 16) | QMAGIC: 121 /* 122 * BSDI's QMAGIC format: 123 * same as new ZMAGIC format, but with different magic number. 124 */ 125 error = exec_aout_prep_zmagic(p, epp); 126 break; 127 case (MID_BSDOS << 16) | NMAGIC: 128 /* 129 * BSDI's NMAGIC format: 130 * same as NMAGIC format, but with different magic number 131 * and with text starting at 0. 132 */ 133 error = exec_aout_prep_oldnmagic(p, epp); 134 break; 135 case (MID_BSDOS << 16) | OMAGIC: 136 /* 137 * BSDI's OMAGIC format: 138 * same as OMAGIC format, but with different magic number 139 * and with text starting at 0. 140 */ 141 error = exec_aout_prep_oldomagic(p, epp); 142 break; 143 } 144 if (error == 0) 145 epp->ep_emul = &emul_bsdos; 146 else 147 kill_vmcmds(&epp->ep_vmcmds); 148 149 return error; 150 }