27 #include <sys/cdefs.h>
30 #include <sys/param.h>
32 #include <sys/imgact.h>
33 #include <sys/imgact_aout.h>
34 #include <sys/kernel.h>
35 #include <sys/limits.h>
37 #include <sys/malloc.h>
38 #include <sys/mutex.h>
40 #include <sys/racct.h>
41 #include <sys/resourcevar.h>
42 #include <sys/signalvar.h>
43 #include <sys/syscall.h>
44 #include <sys/sysent.h>
45 #include <sys/systm.h>
46 #include <sys/vnode.h>
48 #include <machine/frame.h>
49 #include <machine/md_var.h>
53 #include <vm/vm_map.h>
54 #include <vm/vm_object.h>
55 #include <vm/vm_param.h>
58 #include <compat/compat32bit/compat32bit_signal.h>
59 #include <compat/compat32bit/compat32bit_util.h>
60 #include <compat/compat32bit/compat32bit_proto.h>
61 #include <compat/compat32bit/compat32bit_syscall.h>
62 #include <compat/ia32/ia32_signal.h>
66 static int aout_fixup(register_t **stack_base,
struct image_params *imgp);
69 struct sysentvec aout_sysvec = {
70 .sv_size = SYS_MAXSYSCALL,
79 .sv_sendsig = sendsig,
80 .sv_sigcode = sigcode,
81 .sv_szsigcode = &szsigcode,
82 .sv_prepsyscall = NULL,
83 .sv_name =
"BSDSUniX a.out",
85 .sv_imgact_try = NULL,
86 .sv_minsigstksz = MINSIGSTKSZ,
87 .sv_pagesize = PAGE_SIZE,
88 .sv_minuser = VM_MIN_ADDRESS,
89 .sv_maxuser = VM_MAXUSER_ADDRESS,
90 .sv_usrstack = USRSTACK,
91 .sv_psstrings = PS_STRINGS,
92 .sv_stackprot = VM_PROT_ALL,
94 .sv_setregs = exec_setregs,
97 .sv_flags = SV_ABI_BSDSUNIX | SV_AOUT | SV_IA32 | SV_ILP32,
98 .sv_set_syscall_retval = cpu_set_syscall_retval,
99 .sv_fetch_syscall_args = cpu_fetch_syscall_args,
101 .sv_schedtail = NULL,
104 #elif defined(__amd64__)
106 #define AOUT32_USRSTACK 0xbfc00000
107 #define AOUT32_PS_STRINGS \
108 (AOUT32_USRSTACK - sizeof(struct compat32bit_ps_strings))
109 #define AOUT32_MINUSER COMPAT_32BIT_MINUSER
111 extern const char *compat32bit_syscallnames[];
112 extern u_long ia32_maxssiz;
114 struct sysentvec aout_sysvec = {
115 .sv_size = COMPAT_32BIT_SYS_MAXSYSCALL,
116 .sv_table = compat32bit_sysent,
122 .sv_transtrap = NULL,
124 .sv_sendsig = ia32_sendsig,
125 .sv_sigcode = ia32_sigcode,
126 .sv_szsigcode = &sz_ia32_sigcode,
127 .sv_prepsyscall = NULL,
128 .sv_name =
"BSDSUniX a.out",
130 .sv_imgact_try = NULL,
131 .sv_minsigstksz = MINSIGSTKSZ,
132 .sv_pagesize = IA32_PAGE_SIZE,
133 .sv_minuser = AOUT32_MINUSER,
134 .sv_maxuser = AOUT32_USRSTACK,
135 .sv_usrstack = AOUT32_USRSTACK,
136 .sv_psstrings = AOUT32_PS_STRINGS,
137 .sv_stackprot = VM_PROT_ALL,
138 .sv_copyout_strings = compat32bit_copyout_strings,
139 .sv_setregs = ia32_setregs,
140 .sv_fixlimit = ia32_fixlimit,
141 .sv_maxssiz = &ia32_maxssiz,
142 .sv_flags = SV_ABI_BSDSUNIX | SV_AOUT | SV_IA32 | SV_ILP32,
143 .sv_set_syscall_retval = ia32_set_syscall_retval,
144 .sv_fetch_syscall_args = ia32_fetch_syscall_args,
145 .sv_syscallnames = compat32bit_syscallnames,
152 aout_fixup(register_t **stack_base,
struct image_params *imgp)
155 *(
char **)stack_base -=
sizeof(uint32_t);
156 return (suword32(*stack_base, imgp->args->argc));
162 const struct exec *a_out = (
const struct exec *) imgp->image_header;
163 struct vmspace *vmspace;
166 vm_offset_t text_end, data_end;
167 unsigned long virtual_offset;
168 unsigned long file_offset;
169 unsigned long bss_size;
178 if (((a_out->a_magic >> 16) & 0xff) != 0x86 &&
179 ((a_out->a_magic >> 16) & 0xff) != 0 &&
180 ((((int)ntohl(a_out->a_magic)) >> 16) & 0xff) != 0x86)
188 switch ((
int)(a_out->a_magic & 0xffff)) {
192 file_offset = PAGE_SIZE;
199 virtual_offset = PAGE_SIZE;
202 if (N_GETMID(*a_out) == MID_ZERO)
203 imgp->ps_strings = aout_sysvec.sv_psstrings;
207 switch ((
int)(ntohl(a_out->a_magic) & 0xffff)) {
210 virtual_offset = PAGE_SIZE;
218 bss_size = roundup(a_out->a_bss, PAGE_SIZE);
224 a_out->a_entry < virtual_offset ||
225 a_out->a_entry >= virtual_offset + a_out->a_text ||
228 a_out->a_text & PAGE_MASK || a_out->a_data & PAGE_MASK
233 virtual_offset + a_out->a_text + a_out->a_data + bss_size > UINT_MAX
239 if (a_out->a_data + a_out->a_text > imgp->attr->va_size)
245 PROC_LOCK(imgp->proc);
250 a_out->a_data + bss_size >
lim_cur(imgp->proc, RLIMIT_DATA) ||
251 racct_set(imgp->proc, RACCT_DATA, a_out->a_data + bss_size) != 0) {
252 PROC_UNLOCK(imgp->proc);
255 PROC_UNLOCK(imgp->proc);
265 VOP_UNLOCK(imgp->vp, 0);
272 vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY);
279 vmspace = imgp->proc->p_vmspace;
281 object = imgp->object;
282 map = &vmspace->vm_map;
284 vm_object_reference(
object);
286 text_end = virtual_offset + a_out->a_text;
287 error = vm_map_insert(map,
object,
289 virtual_offset, text_end,
290 VM_PROT_READ | VM_PROT_EXECUTE, VM_PROT_ALL,
291 MAP_COPY_ON_WRITE | MAP_PREFAULT);
294 vm_object_deallocate(
object);
297 data_end = text_end + a_out->a_data;
299 vm_object_reference(
object);
300 error = vm_map_insert(map,
object,
301 file_offset + a_out->a_text,
303 VM_PROT_ALL, VM_PROT_ALL,
304 MAP_COPY_ON_WRITE | MAP_PREFAULT);
307 vm_object_deallocate(
object);
313 error = vm_map_insert(map, NULL, 0,
314 data_end, data_end + bss_size,
315 VM_PROT_ALL, VM_PROT_ALL, 0);
324 vmspace->vm_tsize = a_out->a_text >> PAGE_SHIFT;
325 vmspace->vm_dsize = (a_out->a_data + bss_size) >> PAGE_SHIFT;
326 vmspace->vm_taddr = (caddr_t) (uintptr_t) virtual_offset;
327 vmspace->vm_daddr = (caddr_t) (uintptr_t)
328 (virtual_offset + a_out->a_text);
331 imgp->interpreted = 0;
332 imgp->entry_addr = a_out->a_entry;
334 imgp->proc->p_sysent = &aout_sysvec;
static int exec_aout_imgact(struct image_params *imgp)
static struct execsw aout_execsw
EXEC_SET(aout, aout_execsw)
rlim_t lim_cur(struct proc *p, int which)
int racct_set(struct proc *p, int resource, uint64_t amount)
register_t * exec_copyout_strings(struct image_params *imgp)
static int aout_fixup(register_t **stack_base, struct image_params *imgp)
int exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv)
static const struct execsw ** execsw
const char * syscallnames[]