root / lab4 / .minix-src / include / sys / exec.h @ 14
History | View | Annotate | Download (13.5 KB)
1 | 13 | up20180614 | /* $NetBSD: exec.h,v 1.149 2015/10/10 10:51:15 maxv 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 | struct pathbuf; /* from namei.h */ |
||
101 | |||
102 | |||
103 | /*
|
||
104 | * The following structure is found at the top of the user stack of each
|
||
105 | * user process. The ps program uses it to locate argv and environment
|
||
106 | * strings. Programs that wish ps to display other information may modify
|
||
107 | * it; normally ps_argvstr points to argv[0], and ps_nargvstr is the same
|
||
108 | * as the program's argc. The fields ps_envstr and ps_nenvstr are the
|
||
109 | * equivalent for the environment.
|
||
110 | */
|
||
111 | struct ps_strings {
|
||
112 | char **ps_argvstr; /* first of 0 or more argument strings */ |
||
113 | int ps_nargvstr; /* the number of argument strings */ |
||
114 | char **ps_envstr; /* first of 0 or more environment strings */ |
||
115 | int ps_nenvstr; /* the number of environment strings */ |
||
116 | }; |
||
117 | |||
118 | #ifdef _KERNEL
|
||
119 | struct ps_strings32 {
|
||
120 | uint32_t ps_argvstr; /* first of 0 or more argument strings */
|
||
121 | int32_t ps_nargvstr; /* the number of argument strings */
|
||
122 | uint32_t ps_envstr; /* first of 0 or more environment strings */
|
||
123 | int32_t ps_nenvstr; /* the number of environment strings */
|
||
124 | }; |
||
125 | #endif
|
||
126 | |||
127 | /*
|
||
128 | * the following structures allow execve() to put together processes
|
||
129 | * in a more extensible and cleaner way.
|
||
130 | *
|
||
131 | * the exec_package struct defines an executable being execve()'d.
|
||
132 | * it contains the header, the vmspace-building commands, the vnode
|
||
133 | * information, and the arguments associated with the newly-execve'd
|
||
134 | * process.
|
||
135 | *
|
||
136 | * the exec_vmcmd struct defines a command description to be used
|
||
137 | * in creating the new process's vmspace.
|
||
138 | */
|
||
139 | |||
140 | #include <sys/uio.h> |
||
141 | |||
142 | struct lwp;
|
||
143 | struct proc;
|
||
144 | struct exec_package;
|
||
145 | struct vnode;
|
||
146 | struct coredump_iostate;
|
||
147 | |||
148 | typedef int (*exec_makecmds_fcn)(struct lwp *, struct exec_package *); |
||
149 | |||
150 | struct execsw {
|
||
151 | u_int es_hdrsz; /* size of header for this format */
|
||
152 | exec_makecmds_fcn es_makecmds; /* function to setup vmcmds */
|
||
153 | union { /* probe function */ |
||
154 | int (*elf_probe_func)(struct lwp *, |
||
155 | struct exec_package *, void *, char *, vaddr_t *); |
||
156 | int (*ecoff_probe_func)(struct lwp *, struct exec_package *); |
||
157 | } u; |
||
158 | struct emul *es_emul; /* os emulation */ |
||
159 | int es_prio; /* entry priority */ |
||
160 | int es_arglen; /* Extra argument size in words */ |
||
161 | /* Copy arguments on the new stack */
|
||
162 | int (*es_copyargs)(struct lwp *, struct exec_package *, |
||
163 | struct ps_strings *, char **, void *); |
||
164 | /* Set registers before execution */
|
||
165 | void (*es_setregs)(struct lwp *, struct exec_package *, vaddr_t); |
||
166 | /* Dump core */
|
||
167 | int (*es_coredump)(struct lwp *, struct coredump_iostate *); |
||
168 | int (*es_setup_stack)(struct lwp *, struct exec_package *); |
||
169 | }; |
||
170 | |||
171 | #define EXECSW_PRIO_ANY 0x000 /* default, no preference */ |
||
172 | #define EXECSW_PRIO_FIRST 0x001 /* this should be among first */ |
||
173 | #define EXECSW_PRIO_LAST 0x002 /* this should be among last */ |
||
174 | |||
175 | /* exec vmspace-creation command set; see below */
|
||
176 | struct exec_vmcmd_set {
|
||
177 | u_int evs_cnt; |
||
178 | u_int evs_used; |
||
179 | struct exec_vmcmd *evs_cmds;
|
||
180 | }; |
||
181 | |||
182 | #define EXEC_DEFAULT_VMCMD_SETSIZE 9 /* # of cmds in set to start */ |
||
183 | struct exec_fakearg {
|
||
184 | char *fa_arg;
|
||
185 | size_t fa_len; |
||
186 | }; |
||
187 | |||
188 | struct exec_package {
|
||
189 | const char *ep_kname; /* kernel-side copy of file's name */ |
||
190 | char *ep_resolvedname; /* fully resolved path from namei */ |
||
191 | void *ep_hdr; /* file's exec header */ |
||
192 | u_int ep_hdrlen; /* length of ep_hdr */
|
||
193 | u_int ep_hdrvalid; /* bytes of ep_hdr that are valid */
|
||
194 | struct exec_vmcmd_set ep_vmcmds; /* vmcmds used to build vmspace */ |
||
195 | struct vnode *ep_vp; /* executable's vnode */ |
||
196 | struct vattr *ep_vap; /* executable's attributes */ |
||
197 | vaddr_t ep_taddr; /* process's text address */
|
||
198 | vsize_t ep_tsize; /* size of process's text */
|
||
199 | vaddr_t ep_daddr; /* process's data(+bss) address */
|
||
200 | vsize_t ep_dsize; /* size of process's data(+bss) */
|
||
201 | vaddr_t ep_maxsaddr; /* proc's max stack addr ("top") */
|
||
202 | vaddr_t ep_minsaddr; /* proc's min stack addr ("bottom") */
|
||
203 | vsize_t ep_ssize; /* size of process's stack */
|
||
204 | vaddr_t ep_entry; /* process's entry point */
|
||
205 | vaddr_t ep_entryoffset; /* offset to entry point */
|
||
206 | vaddr_t ep_vm_minaddr; /* bottom of process address space */
|
||
207 | vaddr_t ep_vm_maxaddr; /* top of process address space */
|
||
208 | u_int ep_flags; /* flags; see below. */
|
||
209 | size_t ep_fa_len; /* byte size of ep_fa */
|
||
210 | struct exec_fakearg *ep_fa; /* a fake args vector for scripts */ |
||
211 | int ep_fd; /* a file descriptor we're holding */ |
||
212 | void *ep_emul_arg; /* emulation argument */ |
||
213 | const struct execsw *ep_esch;/* execsw entry */ |
||
214 | struct vnode *ep_emul_root; /* base of emulation filesystem */ |
||
215 | struct vnode *ep_interp; /* vnode of (elf) interpeter */ |
||
216 | uint32_t ep_pax_flags; /* pax flags */
|
||
217 | char *ep_path; /* absolute path of executable */ |
||
218 | void (*ep_emul_arg_free)(void *); |
||
219 | /* free ep_emul_arg */
|
||
220 | uint32_t ep_osversion; /* OS version */
|
||
221 | char ep_machine_arch[12]; /* from MARCH note */ |
||
222 | }; |
||
223 | #define EXEC_INDIR 0x0001 /* script handling already done */ |
||
224 | #define EXEC_HASFD 0x0002 /* holding a shell script */ |
||
225 | #define EXEC_HASARGL 0x0004 /* has fake args vector */ |
||
226 | #define EXEC_SKIPARG 0x0008 /* don't copy user-supplied argv[0] */ |
||
227 | #define EXEC_DESTR 0x0010 /* destructive ops performed */ |
||
228 | #define EXEC_32 0x0020 /* 32-bit binary emulation */ |
||
229 | #define EXEC_FORCEAUX 0x0040 /* always use ELF AUX vector */ |
||
230 | #define EXEC_TOPDOWN_VM 0x0080 /* may use top-down VM layout */ |
||
231 | #define EXEC_FROM32 0x0100 /* exec'ed from 32-bit binary */ |
||
232 | |||
233 | struct exec_vmcmd {
|
||
234 | int (*ev_proc)(struct lwp *, struct exec_vmcmd *); |
||
235 | /* procedure to run for region of vmspace */
|
||
236 | vsize_t ev_len; /* length of the segment to map */
|
||
237 | vaddr_t ev_addr; /* address in the vmspace to place it at */
|
||
238 | struct vnode *ev_vp; /* vnode pointer for the file w/the data */ |
||
239 | vsize_t ev_offset; /* offset in the file for the data */
|
||
240 | u_int ev_prot; /* protections for segment */
|
||
241 | int ev_flags;
|
||
242 | #define VMCMD_RELATIVE 0x0001 /* ev_addr is relative to base entry */ |
||
243 | #define VMCMD_BASE 0x0002 /* marks a base entry */ |
||
244 | #define VMCMD_FIXED 0x0004 /* entry must be mapped at ev_addr */ |
||
245 | #define VMCMD_STACK 0x0008 /* entry is for a stack */ |
||
246 | }; |
||
247 | |||
248 | #ifdef _KERNEL
|
||
249 | /*
|
||
250 | * funtions used either by execve() or the various CPU-dependent execve()
|
||
251 | * hooks.
|
||
252 | */
|
||
253 | void kill_vmcmd (struct exec_vmcmd **); |
||
254 | int exec_makecmds (struct lwp *, struct exec_package *); |
||
255 | int exec_runcmds (struct lwp *, struct exec_package *); |
||
256 | void vmcmdset_extend (struct exec_vmcmd_set *); |
||
257 | void kill_vmcmds (struct exec_vmcmd_set *); |
||
258 | int vmcmd_map_pagedvn (struct lwp *, struct exec_vmcmd *); |
||
259 | int vmcmd_map_readvn (struct lwp *, struct exec_vmcmd *); |
||
260 | int vmcmd_readvn (struct lwp *, struct exec_vmcmd *); |
||
261 | int vmcmd_map_zero (struct lwp *, struct exec_vmcmd *); |
||
262 | int copyargs (struct lwp *, struct exec_package *, |
||
263 | struct ps_strings *, char **, void *); |
||
264 | int copyin_psstrings (struct proc *, struct ps_strings *); |
||
265 | int copy_procargs (struct proc *, int, size_t *, |
||
266 | int (*)(void *, const void *, size_t, size_t), void *); |
||
267 | void setregs (struct lwp *, struct exec_package *, vaddr_t); |
||
268 | int check_veriexec (struct lwp *, struct vnode *, |
||
269 | struct exec_package *, int); |
||
270 | int check_exec (struct lwp *, struct exec_package *, |
||
271 | struct pathbuf *);
|
||
272 | int exec_init (int); |
||
273 | int exec_read_from (struct lwp *, struct vnode *, u_long off, |
||
274 | void *, size_t);
|
||
275 | int exec_setup_stack (struct lwp *, struct exec_package *); |
||
276 | |||
277 | int coredump_write (struct coredump_iostate *, enum uio_seg, |
||
278 | const void *, size_t); |
||
279 | off_t coredump_offset (struct coredump_iostate *);
|
||
280 | |||
281 | void exec_free_emul_arg (struct exec_package *); |
||
282 | |||
283 | |||
284 | /*
|
||
285 | * Machine dependent functions
|
||
286 | */
|
||
287 | struct core;
|
||
288 | struct core32;
|
||
289 | int cpu_coredump(struct lwp *, struct coredump_iostate *, struct core *); |
||
290 | int cpu_coredump32(struct lwp *, struct coredump_iostate *, struct core32 *); |
||
291 | |||
292 | int exec_add(struct execsw *, int); |
||
293 | int exec_remove(struct execsw *, int); |
||
294 | |||
295 | void new_vmcmd(struct exec_vmcmd_set *, |
||
296 | int (*)(struct lwp *, struct exec_vmcmd *), |
||
297 | vsize_t, vaddr_t, struct vnode *, u_long, u_int, int); |
||
298 | #define NEW_VMCMD(evsp,lwp,len,addr,vp,offset,prot) \
|
||
299 | new_vmcmd(evsp,lwp,len,addr,vp,offset,prot,0)
|
||
300 | #define NEW_VMCMD2(evsp,lwp,len,addr,vp,offset,prot,flags) \
|
||
301 | new_vmcmd(evsp,lwp,len,addr,vp,offset,prot,flags) |
||
302 | |||
303 | typedef int (*execve_fetch_element_t)(char * const *, size_t, char **); |
||
304 | int execve1(struct lwp *, const char *, char * const *, char * const *, |
||
305 | execve_fetch_element_t); |
||
306 | |||
307 | struct posix_spawn_file_actions;
|
||
308 | struct posix_spawnattr;
|
||
309 | int check_posix_spawn (struct lwp *); |
||
310 | void posix_spawn_fa_free(struct posix_spawn_file_actions *, size_t); |
||
311 | int do_posix_spawn(struct lwp *, pid_t *, bool*, const char *, |
||
312 | struct posix_spawn_file_actions *, struct posix_spawnattr *, |
||
313 | char *const *argv, char *const *, execve_fetch_element_t); |
||
314 | |||
315 | extern int maxexec; |
||
316 | |||
317 | #endif /* _KERNEL */ |
||
318 | |||
319 | #endif /* !_SYS_EXEC_H_ */ |