Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/sys/exec.h
+++ new/usr/src/uts/common/sys/exec.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 27 /* All Rights Reserved */
28 28
29 29 /*
30 30 * Copyright 2016, Joyent, Inc.
31 31 */
32 32
33 33 #ifndef _SYS_EXEC_H
34 34 #define _SYS_EXEC_H
35 35
36 36 #include <sys/systm.h>
37 37 #include <vm/seg.h>
38 38 #include <vm/seg_vn.h>
39 39 #include <sys/model.h>
40 40 #include <sys/uio.h>
41 41 #include <sys/corectl.h>
42 42 #include <sys/machelf.h>
43 43
44 44 #ifdef __cplusplus
45 45 extern "C" {
46 46 #endif
47 47
48 48 /*
49 49 * Number of bytes to read for magic string
50 50 */
51 51 #define MAGIC_BYTES 8
52 52
53 53 #define getexmag(x) (((x)[0] << 8) + (x)[1])
54 54
55 55 typedef struct execa {
56 56 const char *fname;
57 57 const char **argp;
58 58 const char **envp;
59 59 } execa_t;
60 60
61 61 typedef struct execenv {
62 62 caddr_t ex_bssbase;
63 63 caddr_t ex_brkbase;
64 64 size_t ex_brksize;
65 65 vnode_t *ex_vp;
66 66 short ex_magic;
67 67 } execenv_t;
68 68
69 69 #ifdef _KERNEL
70 70
71 71 #define LOADABLE_EXEC(e) ((e)->exec_lock)
72 72 #define LOADED_EXEC(e) ((e)->exec_func)
73 73
74 74
75 75 /*
76 76 * User argument structure for passing exec information around between the
77 77 * common and machine-dependent portions of exec and the exec modules.
78 78 */
79 79 typedef struct uarg {
80 80 ssize_t na;
81 81 ssize_t ne;
82 82 ssize_t nc;
83 83 ssize_t arglen;
84 84 char *fname;
85 85 char *pathname;
86 86 ssize_t auxsize;
87 87 caddr_t stackend;
88 88 size_t stk_align;
89 89 size_t stk_size;
90 90 char *stk_base;
91 91 char *stk_strp;
92 92 int *stk_offp;
93 93 size_t usrstack_size;
94 94 uint_t stk_prot;
95 95 uint_t dat_prot;
96 96 int traceinval;
97 97 int addr32;
98 98 model_t to_model;
99 99 model_t from_model;
100 100 size_t to_ptrsize;
101 101 size_t from_ptrsize;
102 102 size_t ncargs;
103 103 struct execsw *execswp;
104 104 uintptr_t entry;
105 105 uintptr_t thrptr;
106 106 vnode_t *ex_vp;
107 107 char *emulator;
108 108 char *brandname;
109 109 const char *brand_nroot;
110 110 char *auxp_auxflags; /* addr of auxflags auxv on the user stack */
111 111 char *auxp_brand; /* address of first brand auxv on user stack */
112 112 cred_t *pfcred;
113 113 boolean_t scrubenv;
114 114 uintptr_t maxstack;
115 115 boolean_t stk_prot_override;
116 116 uintptr_t commpage;
117 117 } uarg_t;
118 118
119 119 /*
120 120 * Possible brand actions for exec.
121 121 */
122 122 #define EBA_NONE 0
123 123 #define EBA_NATIVE 1
124 124 #define EBA_BRAND 2
125 125
126 126 /*
127 127 * The following macro is a machine dependent encapsulation of
128 128 * postfix processing to hide the stack direction from elf.c
129 129 * thereby making the elf.c code machine independent.
130 130 */
131 131 #define execpoststack(ARGS, ARRAYADDR, BYTESIZE) \
132 132 (copyout((caddr_t)(ARRAYADDR), (ARGS)->stackend, (BYTESIZE)) ? EFAULT \
133 133 : (((ARGS)->stackend += (BYTESIZE)), 0))
134 134
135 135 /*
136 136 * This provides the current user stack address for an object of size BYTESIZE.
137 137 * Used to determine the stack address just before applying execpoststack().
138 138 */
139 139 #define stackaddress(ARGS, BYTESIZE) ((ARGS)->stackend)
140 140
141 141 /*
142 142 * Macro to add attribute/values the aux vector under construction.
143 143 */
144 144 /* BEGIN CSTYLED */
145 145 #if ((_LONG_ALIGNMENT == (2 * _INT_ALIGNMENT)) || \
146 146 (_POINTER_ALIGNMENT == (2 * _INT_ALIGNMENT)))
147 147 /* END CSTYLED */
148 148 /*
149 149 * This convoluted stuff is necessitated by the fact that there is
150 150 * potential padding in the aux vector, but not necessarily and
151 151 * without clearing the padding there is a small, but potential
152 152 * security hole.
153 153 */
154 154 #define ADDAUX(p, a, v) { \
155 155 (&(p)->a_type)[1] = 0; \
156 156 (p)->a_type = (a); \
157 157 (p)->a_un.a_val = (v); \
158 158 ++(p); \
159 159 }
160 160 #else
161 161 #define ADDAUX(p, a, v) { \
162 162 (p)->a_type = (a); \
163 163 ((p)++)->a_un.a_val = (v); \
164 164 }
165 165 #endif
166 166
167 167 #define INTPSZ MAXPATHLEN
168 168 #define INTP_MAXDEPTH 5 /* Nested interpreter depth matches Linux */
169 169 typedef struct intpdata {
170 170 char *intp;
171 171 char *intp_name[INTP_MAXDEPTH];
172 172 char *intp_arg[INTP_MAXDEPTH];
173 173 } intpdata_t;
174 174
175 175 #define EXECSETID_SETID 0x1 /* setid exec */
176 176 #define EXECSETID_UGIDS 0x2 /* [ug]ids mismatch */
177 177 #define EXECSETID_PRIVS 0x4 /* more privs than before */
178 178
179 179 struct execsw {
180 180 char *exec_magic;
181 181 int exec_magoff;
182 182 int exec_maglen;
183 183 int (*exec_func)(struct vnode *vp, struct execa *uap,
184 184 struct uarg *args, struct intpdata *idata, int level,
185 185 long *execsz, int setid, caddr_t exec_file,
186 186 struct cred *cred, int *brand_action);
187 187 int (*exec_core)(struct vnode *vp, struct proc *p,
188 188 struct cred *cred, rlim64_t rlimit, int sig,
189 189 core_content_t content);
190 190 krwlock_t *exec_lock;
191 191 };
192 192
193 193 extern int nexectype; /* number of elements in execsw */
194 194 extern struct execsw execsw[];
195 195 extern kmutex_t execsw_lock;
196 196
197 197 extern short elfmagic;
198 198 extern short intpmagic;
199 199 extern short javamagic;
200 200 #if defined(__sparc)
201 201 extern short aout_zmagic;
202 202 extern short aout_nmagic;
203 203 extern short aout_omagic;
204 204 #endif
205 205 extern short nomagic;
206 206
207 207 extern char elf32magicstr[];
208 208 extern char elf64magicstr[];
209 209 extern char intpmagicstr[];
210 210 extern char javamagicstr[];
211 211 #if defined(__sparc)
212 212 extern char aout_nmagicstr[];
213 213 extern char aout_zmagicstr[];
214 214 extern char aout_omagicstr[];
215 215 #endif
216 216 extern char nomagicstr[];
217 217
218 218 extern int exec_args(execa_t *, uarg_t *, intpdata_t *, void **);
219 219 extern int exece(const char *fname, const char **argp, const char **envp);
220 220 extern int exec_common(const char *fname, const char **argp,
221 221 const char **envp, int brand_action);
222 222 extern int gexec(vnode_t **vp, struct execa *uap, struct uarg *args,
223 223 struct intpdata *idata, int level, long *execsz, caddr_t exec_file,
224 224 struct cred *cred, int *brand_action);
225 225 extern struct execsw *allocate_execsw(char *name, char *magic,
226 226 size_t magic_size);
227 227 extern struct execsw *findexecsw(char *magic);
228 228 extern struct execsw *findexec_by_hdr(char *header);
229 229 extern struct execsw *findexec_by_magic(char *magic);
230 230 extern int execpermissions(struct vnode *vp, struct vattr *vattrp,
231 231 struct uarg *args);
232 232 extern int execmap(vnode_t *vp, caddr_t addr, size_t len, size_t zfodlen,
233 233 off_t offset, int prot, int page, uint_t);
234 234 extern void setexecenv(struct execenv *ep);
235 235 extern int execopen(struct vnode **vpp, int *fdp);
236 236 extern int execclose(int fd);
237 237 extern void setregs(uarg_t *);
238 238 extern void exec_set_sp(size_t);
239 239
240 240 /*
241 241 * Utility functions for branded process executing
242 242 */
243 243 #if !defined(_ELF32_COMPAT)
244 244 /*
245 245 * When compiling 64-bit kernels we don't want these definitions included
246 246 * when compiling the 32-bit compatability elf code in the elfexec module.
247 247 */
248 248 extern int elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
249 249 long *, int, caddr_t, cred_t *, int *);
250 250 extern int mapexec_brand(vnode_t *, uarg_t *, Ehdr *, Addr *,
251 251 intptr_t *, caddr_t, char **, caddr_t *, caddr_t *, size_t *,
252 252 uintptr_t *, uintptr_t *);
253 253 extern int elfreadhdr(vnode_t *, cred_t *, Ehdr *, int *, caddr_t *,
254 254 ssize_t *);
255 255 #endif /* !_ELF32_COMPAT */
256 256
257 257 #if defined(_LP64)
258 258 extern int elf32exec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
259 259 long *, int, caddr_t, cred_t *, int *);
260 260 extern int mapexec32_brand(vnode_t *, uarg_t *, Elf32_Ehdr *, Elf32_Addr *,
261 261 intptr_t *, caddr_t, char **, caddr_t *, caddr_t *, size_t *,
262 262 uintptr_t *, uintptr_t *);
263 263 extern int elf32readhdr(vnode_t *, cred_t *, Elf32_Ehdr *, int *, caddr_t *,
264 264 ssize_t *);
265 265 #endif /* _LP64 */
266 266
267 267 /*
268 268 * Utility functions for exec module core routines:
269 269 */
270 270 extern int core_seg(proc_t *, vnode_t *, offset_t, caddr_t,
271 271 size_t, rlim64_t, cred_t *);
272 272
273 273 extern int core_write(vnode_t *, enum uio_seg, offset_t,
274 274 const void *, size_t, rlim64_t, cred_t *);
275 275
276 276 /* a.out stuff */
277 277
278 278 struct exec;
279 279
280 280 extern caddr_t gettmem(struct exec *exp);
281 281 extern caddr_t getdmem(struct exec *exp);
282 282 extern ulong_t getdfile(struct exec *exp);
283 283 extern uint_t gettfile(struct exec *exp);
284 284 extern int chkaout(struct exdata *exp);
285 285 extern void getexinfo(struct exdata *edp_in, struct exdata *edp_out,
286 286 int *pagetext, int *pagedata);
287 287
288 288 #endif /* _KERNEL */
289 289
290 290 #ifdef __cplusplus
291 291 }
292 292 #endif
293 293
294 294 #endif /* _SYS_EXEC_H */
|
↓ open down ↓ |
294 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX