1/* 2 * Copyright (c) 1993, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by David Greenman 16 * 4. The name of the developer may be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 *
| 1/* 2 * Copyright (c) 1993, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by David Greenman 16 * 4. The name of the developer may be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 *
|
31 * $Id: imgact_aout.c,v 1.6 1994/08/18 22:34:55 wollman Exp $
| 31 * $Id: imgact_aout.c,v 1.7 1994/08/24 11:50:36 sos Exp $
|
32 */ 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/resourcevar.h> 37#include <sys/exec.h> 38#include <sys/mman.h> 39#include <sys/imgact.h>
| 32 */ 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/resourcevar.h> 37#include <sys/exec.h> 38#include <sys/mman.h> 39#include <sys/imgact.h>
|
| 40#include <sys/imgact_aout.h>
|
40#include <sys/kernel.h> 41#include <sys/sysent.h> 42 43#include <vm/vm.h> 44 45int 46exec_aout_imgact(iparams) 47 struct image_params *iparams; 48{ 49 struct exec *a_out = (struct exec *) iparams->image_header; 50 struct vmspace *vmspace = iparams->proc->p_vmspace; 51 unsigned long vmaddr, virtual_offset, file_offset; 52 unsigned long bss_size; 53 int error, len; 54 extern struct sysentvec aout_sysvec; 55 56 /* 57 * Set file/virtual offset based on a.out variant. 58 * We do two cases: host byte order and network byte order 59 * (for NetBSD compatibility) 60 */ 61 switch ((int)(a_out->a_magic & 0xffff)) { 62 case ZMAGIC: 63 virtual_offset = 0; 64 if (a_out->a_text) { 65 file_offset = NBPG; 66 } else { 67 /* Bill's "screwball mode" */ 68 file_offset = 0; 69 } 70 break; 71 case QMAGIC: 72 virtual_offset = NBPG; 73 file_offset = 0; 74 break; 75 default: 76 /* NetBSD compatibility */ 77 switch ((int)(ntohl(a_out->a_magic) & 0xffff)) { 78 case ZMAGIC: 79 case QMAGIC: 80 virtual_offset = NBPG; 81 file_offset = 0; 82 break; 83 default: 84 return (-1); 85 } 86 } 87 88 bss_size = roundup(a_out->a_bss, NBPG); 89 90 /* 91 * Check various fields in header for validity/bounds. 92 */ 93 if (/* entry point must lay with text region */ 94 a_out->a_entry < virtual_offset || 95 a_out->a_entry >= virtual_offset + a_out->a_text || 96 97 /* text and data size must each be page rounded */ 98 a_out->a_text % NBPG || 99 a_out->a_data % NBPG) 100 return (-1); 101 102 /* text + data can't exceed file size */ 103 if (a_out->a_data + a_out->a_text > iparams->attr->va_size) 104 return (EFAULT); 105 106 /* 107 * text/data/bss must not exceed limits 108 */ 109 if (/* text can't exceed maximum text size */ 110 a_out->a_text > MAXTSIZ || 111 112 /* data + bss can't exceed maximum data size */ 113 a_out->a_data + bss_size > MAXDSIZ || 114 115 /* data + bss can't exceed rlimit */ 116 a_out->a_data + bss_size > 117 iparams->proc->p_rlimit[RLIMIT_DATA].rlim_cur) 118 return (ENOMEM); 119 120 /* copy in arguments and/or environment from old process */ 121 error = exec_extract_strings(iparams); 122 if (error) 123 return (error); 124 125 /* 126 * Destroy old process VM and create a new one (with a new stack) 127 */ 128 exec_new_vmspace(iparams); 129 130 /* 131 * Map text read/execute 132 */ 133 vmaddr = virtual_offset; 134 error = 135 vm_mmap(&vmspace->vm_map, /* map */ 136 &vmaddr, /* address */ 137 a_out->a_text, /* size */ 138 VM_PROT_READ | VM_PROT_EXECUTE, /* protection */ 139 VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_WRITE, /* max protection */ 140 MAP_PRIVATE | MAP_FIXED, /* flags */ 141 (caddr_t)iparams->vnodep, /* vnode */ 142 file_offset); /* offset */ 143 if (error) 144 return (error); 145 146 /* 147 * Map data read/write (if text is 0, assume text is in data area 148 * [Bill's screwball mode]) 149 */ 150 vmaddr = virtual_offset + a_out->a_text; 151 error = 152 vm_mmap(&vmspace->vm_map, 153 &vmaddr, 154 a_out->a_data, 155 VM_PROT_READ | VM_PROT_WRITE | (a_out->a_text ? 0 : VM_PROT_EXECUTE), 156 VM_PROT_ALL, MAP_PRIVATE | MAP_FIXED, 157 (caddr_t) iparams->vnodep, 158 file_offset + a_out->a_text); 159 if (error) 160 return (error); 161 162 /* 163 * Allocate demand-zeroed area for uninitialized data 164 * "bss" = 'block started by symbol' - named after the IBM 7090 165 * instruction of the same name. 166 */ 167 vmaddr = virtual_offset + a_out->a_text + a_out->a_data; 168 error = vm_allocate(&vmspace->vm_map, &vmaddr, bss_size, FALSE); 169 if (error) 170 return (error); 171 172 /* Fill in process VM information */ 173 vmspace->vm_tsize = a_out->a_text >> PAGE_SHIFT; 174 vmspace->vm_dsize = (a_out->a_data + bss_size) >> PAGE_SHIFT; 175 vmspace->vm_taddr = (caddr_t) virtual_offset; 176 vmspace->vm_daddr = (caddr_t) virtual_offset + a_out->a_text; 177 178 /* Fill in image_params */ 179 iparams->interpreted = 0; 180 iparams->entry_addr = a_out->a_entry; 181 182 iparams->proc->p_sysent = &aout_sysvec; 183 return (0); 184} 185 186/* 187 * Tell kern_execve.c about it, with a little help from the linker. 188 * Since `const' objects end up in the text segment, TEXT_SET is the 189 * correct directive to use. 190 */ 191static const struct execsw aout_execsw = { exec_aout_imgact, "a.out" }; 192TEXT_SET(execsw_set, aout_execsw); 193
| 41#include <sys/kernel.h> 42#include <sys/sysent.h> 43 44#include <vm/vm.h> 45 46int 47exec_aout_imgact(iparams) 48 struct image_params *iparams; 49{ 50 struct exec *a_out = (struct exec *) iparams->image_header; 51 struct vmspace *vmspace = iparams->proc->p_vmspace; 52 unsigned long vmaddr, virtual_offset, file_offset; 53 unsigned long bss_size; 54 int error, len; 55 extern struct sysentvec aout_sysvec; 56 57 /* 58 * Set file/virtual offset based on a.out variant. 59 * We do two cases: host byte order and network byte order 60 * (for NetBSD compatibility) 61 */ 62 switch ((int)(a_out->a_magic & 0xffff)) { 63 case ZMAGIC: 64 virtual_offset = 0; 65 if (a_out->a_text) { 66 file_offset = NBPG; 67 } else { 68 /* Bill's "screwball mode" */ 69 file_offset = 0; 70 } 71 break; 72 case QMAGIC: 73 virtual_offset = NBPG; 74 file_offset = 0; 75 break; 76 default: 77 /* NetBSD compatibility */ 78 switch ((int)(ntohl(a_out->a_magic) & 0xffff)) { 79 case ZMAGIC: 80 case QMAGIC: 81 virtual_offset = NBPG; 82 file_offset = 0; 83 break; 84 default: 85 return (-1); 86 } 87 } 88 89 bss_size = roundup(a_out->a_bss, NBPG); 90 91 /* 92 * Check various fields in header for validity/bounds. 93 */ 94 if (/* entry point must lay with text region */ 95 a_out->a_entry < virtual_offset || 96 a_out->a_entry >= virtual_offset + a_out->a_text || 97 98 /* text and data size must each be page rounded */ 99 a_out->a_text % NBPG || 100 a_out->a_data % NBPG) 101 return (-1); 102 103 /* text + data can't exceed file size */ 104 if (a_out->a_data + a_out->a_text > iparams->attr->va_size) 105 return (EFAULT); 106 107 /* 108 * text/data/bss must not exceed limits 109 */ 110 if (/* text can't exceed maximum text size */ 111 a_out->a_text > MAXTSIZ || 112 113 /* data + bss can't exceed maximum data size */ 114 a_out->a_data + bss_size > MAXDSIZ || 115 116 /* data + bss can't exceed rlimit */ 117 a_out->a_data + bss_size > 118 iparams->proc->p_rlimit[RLIMIT_DATA].rlim_cur) 119 return (ENOMEM); 120 121 /* copy in arguments and/or environment from old process */ 122 error = exec_extract_strings(iparams); 123 if (error) 124 return (error); 125 126 /* 127 * Destroy old process VM and create a new one (with a new stack) 128 */ 129 exec_new_vmspace(iparams); 130 131 /* 132 * Map text read/execute 133 */ 134 vmaddr = virtual_offset; 135 error = 136 vm_mmap(&vmspace->vm_map, /* map */ 137 &vmaddr, /* address */ 138 a_out->a_text, /* size */ 139 VM_PROT_READ | VM_PROT_EXECUTE, /* protection */ 140 VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_WRITE, /* max protection */ 141 MAP_PRIVATE | MAP_FIXED, /* flags */ 142 (caddr_t)iparams->vnodep, /* vnode */ 143 file_offset); /* offset */ 144 if (error) 145 return (error); 146 147 /* 148 * Map data read/write (if text is 0, assume text is in data area 149 * [Bill's screwball mode]) 150 */ 151 vmaddr = virtual_offset + a_out->a_text; 152 error = 153 vm_mmap(&vmspace->vm_map, 154 &vmaddr, 155 a_out->a_data, 156 VM_PROT_READ | VM_PROT_WRITE | (a_out->a_text ? 0 : VM_PROT_EXECUTE), 157 VM_PROT_ALL, MAP_PRIVATE | MAP_FIXED, 158 (caddr_t) iparams->vnodep, 159 file_offset + a_out->a_text); 160 if (error) 161 return (error); 162 163 /* 164 * Allocate demand-zeroed area for uninitialized data 165 * "bss" = 'block started by symbol' - named after the IBM 7090 166 * instruction of the same name. 167 */ 168 vmaddr = virtual_offset + a_out->a_text + a_out->a_data; 169 error = vm_allocate(&vmspace->vm_map, &vmaddr, bss_size, FALSE); 170 if (error) 171 return (error); 172 173 /* Fill in process VM information */ 174 vmspace->vm_tsize = a_out->a_text >> PAGE_SHIFT; 175 vmspace->vm_dsize = (a_out->a_data + bss_size) >> PAGE_SHIFT; 176 vmspace->vm_taddr = (caddr_t) virtual_offset; 177 vmspace->vm_daddr = (caddr_t) virtual_offset + a_out->a_text; 178 179 /* Fill in image_params */ 180 iparams->interpreted = 0; 181 iparams->entry_addr = a_out->a_entry; 182 183 iparams->proc->p_sysent = &aout_sysvec; 184 return (0); 185} 186 187/* 188 * Tell kern_execve.c about it, with a little help from the linker. 189 * Since `const' objects end up in the text segment, TEXT_SET is the 190 * correct directive to use. 191 */ 192static const struct execsw aout_execsw = { exec_aout_imgact, "a.out" }; 193TEXT_SET(execsw_set, aout_execsw); 194
|