Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / ibcs2 / ibcs2_exec.c
blobd8903091ffaaf3542cfc3ca52f2c94bcf81340ea
1 /* $NetBSD: ibcs2_exec.c,v 1.72 2008/11/19 18:36:03 ad Exp $ */
3 /*
4 * Copyright (c) 1994, 1995, 1998 Scott Bartram
5 * Copyright (c) 1994 Adam Glass
6 * Copyright (c) 1993, 1994 Christopher G. Demetriou
7 * All rights reserved.
9 * originally from kern/exec_ecoff.c
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Scott Bartram.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: ibcs2_exec.c,v 1.72 2008/11/19 18:36:03 ad Exp $");
40 #if defined(_KERNEL_OPT)
41 #include "opt_syscall_debug.h"
42 #endif
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/proc.h>
48 #include <sys/malloc.h>
49 #include <sys/namei.h>
50 #include <sys/vnode.h>
51 #include <sys/mount.h>
52 #include <sys/exec.h>
54 #include <uvm/uvm_extern.h>
56 #include <machine/ibcs2_machdep.h>
58 #include <compat/ibcs2/ibcs2_types.h>
59 #include <compat/ibcs2/ibcs2_exec.h>
60 #include <compat/ibcs2/ibcs2_signal.h>
61 #include <compat/ibcs2/ibcs2_errno.h>
62 #include <compat/ibcs2/ibcs2_syscall.h>
64 static void ibcs2_e_proc_exec(struct proc *, struct exec_package *);
66 extern struct sysent ibcs2_sysent[];
67 extern const char * const ibcs2_syscallnames[];
68 extern char ibcs2_sigcode[], ibcs2_esigcode[];
69 #ifndef __HAVE_SYSCALL_INTERN
70 void syscall(void);
71 #endif
73 #ifdef IBCS2_DEBUG
74 int ibcs2_debug = 1;
75 #endif
77 struct uvm_object *emul_ibcs2_object;
79 struct emul emul_ibcs2 = {
80 "ibcs2",
81 "/emul/ibcs2",
82 #ifndef __HAVE_MINIMAL_EMUL
84 native_to_ibcs2_errno,
85 IBCS2_SYS_syscall,
86 IBCS2_SYS_NSYSENT,
87 #endif
88 ibcs2_sysent,
89 #ifdef SYSCALL_DEBUG
90 ibcs2_syscallnames,
91 #else
92 NULL,
93 #endif
94 ibcs2_sendsig,
95 trapsignal,
96 NULL, /* e_tracesig */
97 ibcs2_sigcode,
98 ibcs2_esigcode,
99 &emul_ibcs2_object,
100 ibcs2_setregs,
101 ibcs2_e_proc_exec,
102 NULL, /* e_proc_fork */
103 NULL, /* e_proc_exit */
104 NULL, /* e_lwp_fork */
105 NULL, /* e_lwp_exec */
106 #ifdef __HAVE_SYSCALL_INTERN
107 ibcs2_syscall_intern,
108 #else
109 syscall,
110 #endif
111 NULL, /* e_sysctlovly */
112 NULL, /* e_fault */
114 uvm_default_mapaddr,
115 NULL, /* e_usertrap */
116 NULL, /* e_sa */
117 0, /* e_ucsize */
118 NULL, /* e_startlwp */
122 * This is exec process hook. Find out if this is x.out executable, if
123 * yes, set flag appropriately, so that emul code which needs to adjust
124 * behaviour accordingly can do so.
126 static void
127 ibcs2_e_proc_exec(struct proc *p, struct exec_package *epp)
129 if (epp->ep_esch->es_makecmds == exec_ibcs2_xout_makecmds)
130 p->p_emuldata = IBCS2_EXEC_XENIX;
131 else
132 p->p_emuldata = IBCS2_EXEC_OTHER;
136 * ibcs2_exec_setup_stack(): Set up the stack segment for an
137 * executable.
139 * Note that the ep_ssize parameter must be set to be the current stack
140 * limit; this is adjusted in the body of execve() to yield the
141 * appropriate stack segment usage once the argument length is
142 * calculated.
144 * This function returns an int for uniformity with other (future) formats'
145 * stack setup functions. They might have errors to return.
149 ibcs2_exec_setup_stack(struct lwp *l, struct exec_package *epp)
151 u_long max_stack_size;
152 u_long access_linear_min, access_size;
153 u_long noaccess_linear_min, noaccess_size;
155 #ifndef USRSTACK32
156 #define USRSTACK32 (0x00000000ffffffffL&~PGOFSET)
157 #endif
159 if (epp->ep_flags & EXEC_32) {
160 epp->ep_minsaddr = USRSTACK32;
161 max_stack_size = MAXSSIZ;
162 } else {
163 epp->ep_minsaddr = USRSTACK;
164 max_stack_size = MAXSSIZ;
166 epp->ep_maxsaddr = (u_long)STACK_GROW(epp->ep_minsaddr,
167 max_stack_size);
168 epp->ep_ssize = l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur;
171 * set up commands for stack. note that this takes *two*, one to
172 * map the part of the stack which we can access, and one to map
173 * the part which we can't.
175 * arguably, it could be made into one, but that would require the
176 * addition of another mapping proc, which is unnecessary
178 access_size = epp->ep_ssize;
179 access_linear_min = (u_long)STACK_ALLOC(epp->ep_minsaddr, access_size);
180 noaccess_size = max_stack_size - access_size;
181 noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
182 access_size), noaccess_size);
183 if (noaccess_size > 0) {
184 NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
185 noaccess_linear_min, NULL, 0, VM_PROT_NONE, VMCMD_STACK);
187 KASSERT(access_size > 0);
188 /* XXX: some ibcs2 binaries need an executable stack. */
189 NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
190 access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE |
191 VM_PROT_EXECUTE, VMCMD_STACK);
193 return 0;