FreeBSD/Linux Kernel Cross Reference
sys/sys/exec.h
1 /* $NetBSD: exec.h,v 1.104 2004/02/13 11:36:23 wiz Exp $ */
2
3 /*-
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)exec.h 8.4 (Berkeley) 2/19/95
37 */
38
39 /*-
40 * Copyright (c) 1993 Theo de Raadt. All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 */
62
63 /*-
64 * Copyright (c) 1994 Christopher G. Demetriou
65 *
66 * Redistribution and use in source and binary forms, with or without
67 * modification, are permitted provided that the following conditions
68 * are met:
69 * 1. Redistributions of source code must retain the above copyright
70 * notice, this list of conditions and the following disclaimer.
71 * 2. Redistributions in binary form must reproduce the above copyright
72 * notice, this list of conditions and the following disclaimer in the
73 * documentation and/or other materials provided with the distribution.
74 * 3. All advertising materials mentioning features or use of this software
75 * must display the following acknowledgement:
76 * This product includes software developed by the University of
77 * California, Berkeley and its contributors.
78 * 4. Neither the name of the University nor the names of its contributors
79 * may be used to endorse or promote products derived from this software
80 * without specific prior written permission.
81 *
82 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
83 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
86 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92 * SUCH DAMAGE.
93 *
94 * @(#)exec.h 8.4 (Berkeley) 2/19/95
95 */
96
97 #ifndef _SYS_EXEC_H_
98 #define _SYS_EXEC_H_
99
100 /*
101 * The following structure is found at the top of the user stack of each
102 * user process. The ps program uses it to locate argv and environment
103 * strings. Programs that wish ps to display other information may modify
104 * it; normally ps_argvstr points to argv[0], and ps_nargvstr is the same
105 * as the program's argc. The fields ps_envstr and ps_nenvstr are the
106 * equivalent for the environment.
107 */
108 struct ps_strings {
109 char **ps_argvstr; /* first of 0 or more argument strings */
110 int ps_nargvstr; /* the number of argument strings */
111 char **ps_envstr; /* first of 0 or more environment strings */
112 int ps_nenvstr; /* the number of environment strings */
113 };
114
115 /*
116 * Below the ps_strings and sigtramp, we may require a gap on the stack
117 * (used to copyin/copyout various emulation data structures).
118 */
119 #define STACKGAPLEN 512 /* plenty enough for now */
120
121 /*
122 * the following structures allow execve() to put together processes
123 * in a more extensible and cleaner way.
124 *
125 * the exec_package struct defines an executable being execve()'d.
126 * it contains the header, the vmspace-building commands, the vnode
127 * information, and the arguments associated with the newly-execve'd
128 * process.
129 *
130 * the exec_vmcmd struct defines a command description to be used
131 * in creating the new process's vmspace.
132 */
133
134 struct lwp;
135 struct proc;
136 struct exec_package;
137 struct vnode;
138 struct ucred;
139
140 typedef int (*exec_makecmds_fcn) __P((struct proc *, struct exec_package *));
141
142 struct execsw {
143 u_int es_hdrsz; /* size of header for this format */
144 exec_makecmds_fcn es_makecmds; /* function to setup vmcmds */
145 union { /* probe function */
146 int (*elf_probe_func) __P((struct proc *,
147 struct exec_package *, void *, char *, vaddr_t *));
148 int (*ecoff_probe_func) __P((struct proc *,
149 struct exec_package *));
150 int (*mach_probe_func) __P((char **));
151 } u;
152 const struct emul *es_emul; /* os emulation */
153 int es_prio; /* entry priority */
154 int es_arglen; /* Extra argument size in words */
155 /* Copy arguments on the new stack */
156 int (*es_copyargs) __P((struct proc *, struct exec_package *,
157 struct ps_strings *, char **, void *));
158 /* Set registers before execution */
159 void (*es_setregs) __P((struct lwp *, struct exec_package *,
160 u_long));
161 /* Dump core */
162 int (*es_coredump) __P((struct lwp *, struct vnode *,
163 struct ucred *));
164 int (*es_setup_stack) __P((struct proc *, struct exec_package *));
165 };
166
167 #define EXECSW_PRIO_ANY 0x000 /* default, no preference */
168 #define EXECSW_PRIO_FIRST 0x001 /* this should be among first */
169 #define EXECSW_PRIO_LAST 0x002 /* this should be among last */
170
171 /* exec vmspace-creation command set; see below */
172 struct exec_vmcmd_set {
173 u_int evs_cnt;
174 u_int evs_used;
175 struct exec_vmcmd *evs_cmds;
176 };
177
178 #define EXEC_DEFAULT_VMCMD_SETSIZE 9 /* # of cmds in set to start */
179
180 struct exec_package {
181 const char *ep_name; /* file's name */
182 void *ep_hdr; /* file's exec header */
183 u_int ep_hdrlen; /* length of ep_hdr */
184 u_int ep_hdrvalid; /* bytes of ep_hdr that are valid */
185 struct nameidata *ep_ndp; /* namei data pointer for lookups */
186 struct exec_vmcmd_set ep_vmcmds; /* vmcmds used to build vmspace */
187 struct vnode *ep_vp; /* executable's vnode */
188 struct vattr *ep_vap; /* executable's attributes */
189 u_long ep_taddr; /* process's text address */
190 u_long ep_tsize; /* size of process's text */
191 u_long ep_daddr; /* process's data(+bss) address */
192 u_long ep_dsize; /* size of process's data(+bss) */
193 u_long ep_maxsaddr; /* proc's max stack addr ("top") */
194 u_long ep_minsaddr; /* proc's min stack addr ("bottom") */
195 u_long ep_ssize; /* size of process's stack */
196 u_long ep_entry; /* process's entry point */
197 vaddr_t ep_vm_minaddr; /* bottom of process address space */
198 vaddr_t ep_vm_maxaddr; /* top of process address space */
199 u_int ep_flags; /* flags; see below. */
200 char **ep_fa; /* a fake args vector for scripts */
201 int ep_fd; /* a file descriptor we're holding */
202 void *ep_emul_arg; /* emulation argument */
203 const struct execsw *ep_es; /* appropriate execsw entry */
204 const struct execsw *ep_esch;/* checked execsw entry */
205 };
206 #define EXEC_INDIR 0x0001 /* script handling already done */
207 #define EXEC_HASFD 0x0002 /* holding a shell script */
208 #define EXEC_HASARGL 0x0004 /* has fake args vector */
209 #define EXEC_SKIPARG 0x0008 /* don't copy user-supplied argv[0] */
210 #define EXEC_DESTR 0x0010 /* destructive ops performed */
211 #define EXEC_32 0x0020 /* 32-bit binary emulation */
212 #define EXEC_HASES 0x0040 /* don't update exec switch pointer */
213
214 struct exec_vmcmd {
215 int (*ev_proc) __P((struct proc *, struct exec_vmcmd *));
216 /* procedure to run for region of vmspace */
217 u_long ev_len; /* length of the segment to map */
218 u_long ev_addr; /* address in the vmspace to place it at */
219 struct vnode *ev_vp; /* vnode pointer for the file w/the data */
220 u_long ev_offset; /* offset in the file for the data */
221 u_int ev_prot; /* protections for segment */
222 int ev_flags;
223 #define VMCMD_RELATIVE 0x0001 /* ev_addr is relative to base entry */
224 #define VMCMD_BASE 0x0002 /* marks a base entry */
225 #define VMCMD_FIXED 0x0004 /* entry must be mapped at ev_addr */
226 };
227
228 #ifdef _KERNEL
229 #include <sys/mallocvar.h>
230
231 MALLOC_DECLARE(M_EXEC);
232
233 /*
234 * funtions used either by execve() or the various CPU-dependent execve()
235 * hooks.
236 */
237 void kill_vmcmd __P((struct exec_vmcmd **));
238 int exec_makecmds __P((struct proc *, struct exec_package *));
239 int exec_runcmds __P((struct proc *, struct exec_package *));
240 void vmcmdset_extend __P((struct exec_vmcmd_set *));
241 void kill_vmcmds __P((struct exec_vmcmd_set *));
242 int vmcmd_map_pagedvn __P((struct proc *, struct exec_vmcmd *));
243 int vmcmd_map_readvn __P((struct proc *, struct exec_vmcmd *));
244 int vmcmd_readvn __P((struct proc *, struct exec_vmcmd *));
245 int vmcmd_map_zero __P((struct proc *, struct exec_vmcmd *));
246 int copyargs __P((struct proc *, struct exec_package *,
247 struct ps_strings *, char **, void *));
248 void setregs __P((struct lwp *, struct exec_package *,
249 u_long));
250 #ifdef VERIFIED_EXEC
251 int check_veriexec __P((struct proc *, struct vnode *,
252 struct exec_package *, int));
253 int check_exec __P((struct proc *, struct exec_package *,
254 int));
255 #else
256 int check_exec __P((struct proc *, struct exec_package *));
257 #endif
258 int exec_init __P((int));
259 int exec_read_from __P((struct proc *, struct vnode *, u_long off,
260 void *, size_t));
261 int exec_setup_stack __P((struct proc *, struct exec_package *));
262
263
264 #ifdef LKM
265 int emul_register __P((const struct emul *, int));
266 int emul_unregister __P((const char *));
267 const struct emul *emul_search __P((const char *));
268
269 int exec_add __P((struct execsw *, const char *));
270 int exec_remove __P((const struct execsw *));
271 #endif /* LKM */
272
273 void new_vmcmd __P((struct exec_vmcmd_set *,
274 int (*) __P((struct proc *, struct exec_vmcmd *)),
275 u_long, u_long, struct vnode *, u_long, u_int, int));
276 #define NEW_VMCMD(evsp,proc,len,addr,vp,offset,prot) \
277 new_vmcmd(evsp,proc,len,addr,vp,offset,prot,0)
278 #define NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,flags) \
279 new_vmcmd(evsp,proc,len,addr,vp,offset,prot,flags)
280
281 #endif /* _KERNEL */
282
283 #include <sys/exec_aout.h>
284
285 #endif /* !_SYS_EXEC_H_ */
Cache object: 9f8b469d0440261526f34fed6a9b6556
|