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 unchanged lines hidden (view full) ---
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: imgact_aout.c,v 1.36 1997/09/02 20:05:33 bde Exp $
27 */
28
29#include <sys/param.h>
30#include <sys/resourcevar.h>
31#include <sys/exec.h>
32#include <sys/mman.h>
33#include <sys/imgact.h>
34#include <sys/imgact_aout.h>
35#include <sys/kernel.h>
36#include <sys/proc.h>
37#include <sys/sysent.h>
38#include <sys/vnode.h>
39
40#include <vm/vm.h>
41#include <vm/vm_param.h>
42#include <vm/vm_prot.h>
43#include <sys/lock.h>
44#include <vm/pmap.h>
45#include <vm/vm_map.h>
46#include <vm/vm_extern.h>
47
48static int exec_aout_imgact __P((struct image_params *imgp));
49
50int
51exec_aout_imgact(imgp)
52 struct image_params *imgp;
53{
54 const struct exec *a_out = (const struct exec *) imgp->image_header;
55 struct vmspace *vmspace;
56 vm_offset_t vmaddr;
57 unsigned long virtual_offset;
58 unsigned long file_offset;
59 unsigned long bss_size;
60 int error;
61
62 /*
63 * Linux and *BSD binaries look very much alike,
64 * only the machine id is different:
--- 75 unchanged lines hidden (view full) ---
140 */
141 exec_new_vmspace(imgp);
142
143 /*
144 * The vm space can be changed by exec_new_vmspace
145 */
146 vmspace = imgp->proc->p_vmspace;
147
148 /*
149 * Map text/data read/execute
150 */
151 vmaddr = virtual_offset;
152 error =
153 vm_mmap(&vmspace->vm_map, /* map */
154 &vmaddr, /* address */
155 a_out->a_text + a_out->a_data, /* size */
156 VM_PROT_READ | VM_PROT_EXECUTE, /* protection */
157 VM_PROT_ALL, /* max protection */
158 MAP_PRIVATE | MAP_FIXED, /* flags */
159 (caddr_t)imgp->vp, /* vnode */
160 file_offset); /* offset */
161 if (error)
162 return (error);
163
164 /*
165 * allow writing of data
166 */
167 vm_map_protect(&vmspace->vm_map,
168 vmaddr + a_out->a_text,
169 vmaddr + a_out->a_text + a_out->a_data,
170 VM_PROT_ALL,
171 FALSE);
172
173 if (bss_size != 0) {
174 /*
175 * Allocate demand-zeroed area for uninitialized data
176 * "bss" = 'block started by symbol' - named after the IBM 7090
177 * instruction of the same name.
178 */
179 vmaddr = virtual_offset + a_out->a_text + a_out->a_data;
180 error = vm_map_find(&vmspace->vm_map, NULL, 0,
181 &vmaddr, bss_size, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0);
182 if (error)
183 return (error);
184 }
185
186 /* Fill in process VM information */
187 vmspace->vm_tsize = a_out->a_text >> PAGE_SHIFT;
188 vmspace->vm_dsize = (a_out->a_data + bss_size) >> PAGE_SHIFT;
189 vmspace->vm_taddr = (caddr_t) virtual_offset;
190 vmspace->vm_daddr = (caddr_t) virtual_offset + a_out->a_text;
191
192 /* Fill in image_params */
193 imgp->interpreted = 0;
--- 17 unchanged lines hidden ---
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 unchanged lines hidden (view full) ---
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: imgact_aout.c,v 1.36 1997/09/02 20:05:33 bde Exp $
27 */
28
29#include <sys/param.h>
30#include <sys/resourcevar.h>
31#include <sys/exec.h>
32#include <sys/mman.h>
33#include <sys/imgact.h>
34#include <sys/imgact_aout.h>
35#include <sys/kernel.h>
36#include <sys/proc.h>
37#include <sys/sysent.h>
38#include <sys/vnode.h>
39
40#include <vm/vm.h>
41#include <vm/vm_param.h>
42#include <vm/vm_prot.h>
43#include <sys/lock.h>
44#include <vm/pmap.h>
45#include <vm/vm_map.h>
46#include <vm/vm_extern.h>
47
48static int exec_aout_imgact __P((struct image_params *imgp));
49
50int
51exec_aout_imgact(imgp)
52 struct image_params *imgp;
53{
54 const struct exec *a_out = (const struct exec *) imgp->image_header;
55 struct vmspace *vmspace;
56 vm_offset_t vmaddr;
57 unsigned long virtual_offset;
58 unsigned long file_offset;
59 unsigned long bss_size;
60 int error;
61
62 /*
63 * Linux and *BSD binaries look very much alike,
64 * only the machine id is different:
--- 75 unchanged lines hidden (view full) ---
140 */
141 exec_new_vmspace(imgp);
142
143 /*
144 * The vm space can be changed by exec_new_vmspace
145 */
146 vmspace = imgp->proc->p_vmspace;
147
148 /*
149 * Map text/data read/execute
150 */
151 vmaddr = virtual_offset;
152 error =
153 vm_mmap(&vmspace->vm_map, /* map */
154 &vmaddr, /* address */
155 a_out->a_text + a_out->a_data, /* size */
156 VM_PROT_READ | VM_PROT_EXECUTE, /* protection */
157 VM_PROT_ALL, /* max protection */
158 MAP_PRIVATE | MAP_FIXED, /* flags */
159 (caddr_t)imgp->vp, /* vnode */
160 file_offset); /* offset */
161 if (error)
162 return (error);
163
164 /*
165 * allow writing of data
166 */
167 vm_map_protect(&vmspace->vm_map,
168 vmaddr + a_out->a_text,
169 vmaddr + a_out->a_text + a_out->a_data,
170 VM_PROT_ALL,
171 FALSE);
172
173 if (bss_size != 0) {
174 /*
175 * Allocate demand-zeroed area for uninitialized data
176 * "bss" = 'block started by symbol' - named after the IBM 7090
177 * instruction of the same name.
178 */
179 vmaddr = virtual_offset + a_out->a_text + a_out->a_data;
180 error = vm_map_find(&vmspace->vm_map, NULL, 0,
181 &vmaddr, bss_size, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0);
182 if (error)
183 return (error);
184 }
185
186 /* Fill in process VM information */
187 vmspace->vm_tsize = a_out->a_text >> PAGE_SHIFT;
188 vmspace->vm_dsize = (a_out->a_data + bss_size) >> PAGE_SHIFT;
189 vmspace->vm_taddr = (caddr_t) virtual_offset;
190 vmspace->vm_daddr = (caddr_t) virtual_offset + a_out->a_text;
191
192 /* Fill in image_params */
193 imgp->interpreted = 0;
--- 17 unchanged lines hidden ---