Print this page
7029 want per-process exploit mitigation features (secflags)
7030 want basic address space layout randomization (aslr)
7031 noexec_user_stack should be a secflag
7032 want a means to forbid mappings around NULL.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/elfdump/common/gen_struct_layout.c
+++ new/usr/src/cmd/sgs/elfdump/common/gen_struct_layout.c
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 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 *
26 26 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 27 */
28 28
29 29 /*
30 30 * This program is used to generate the contents of the
31 31 * struct_layout_XXX.c files that contain per-archtecture
32 32 * structure layout information.
33 33 *
34 34 * Although not part of elfdump, it is built by the makefile
35 35 * along with it.
36 36 * To use it:
37 37 *
38 38 * 1) Run it, capturing the output in a file.
39 39 * 2) If this is a replacement for an existing file,
40 40 * diff the new and old copies to ensure only
41 41 * the changes you expected are present.
42 42 * 3) Put the new file in the common directory under the name
43 43 * struct_layout_XXX.c, where XXX is the name of
44 44 * the architecture (i386, amd64, sparc, sparcv9, etc).
45 45 * 2) Add any necessary header and copyright comments.
46 46 * 3) If this is a new architecture:
47 47 * - Add an extern statement for struct_layout_XXX()
48 48 * to struct_layout.h
49 49 * - Add a case for it to the function sl_struct_layout()
50 50 * in struct_layout.c.
51 51 */
52 52
53 53 #include <string.h>
54 54 #include <stdio.h>
55 55 #include <stdlib.h>
56 56 #include <ctype.h>
57 57 #include <err.h>
58 58 #include <sys/types.h>
59 59 #include <libctf.h>
60 60
61 61 /*
62 62 * This extracts CTF information from a temporary object file.
63 63 *
64 64 * START and END bracket a struct layout definition. They issue
65 65 * the typedef boilerplate, and the standard first element (sizeof)
66 66 * which captures the overall size of the structure.
67 67 *
68 68 * SCALAR_FIELD is for scalar struct fields
69 69 *
70 70 * ARRAY_FIELD is for array struct fields
71 71 *
72 72 * ARRAY_TYPE is for plain (non-struct) array types
73 73 */
74 74 #define START(_name, _type) \
75 75 do_start(#_name, #_type)
76 76 #define END (void) \
77 77 do_end()
78 78 #define SCALAR_FIELD(_type, _field, _sign) \
79 79 do_scalar_field(#_type, #_field, _sign, NULL)
80 80 #define SCALAR_FIELD4(_type, _field, _sign, _rtype) \
81 81 do_scalar_field(#_type, #_field, _sign, _rtype)
82 82 #define ARRAY_FIELD(_type, _field, _sign) \
83 83 do_array_field(#_type, #_field, _sign, NULL)
84 84 #define ARRAY_TYPE(_type, _sign) \
85 85 do_array_type(#_type, "elt0", _sign)
86 86
87 87 static void do_start(char *_name, char *_type);
88 88 static void do_end(void);
89 89 static void do_start_name(char *name);
90 90 static void do_start_sizeof(char *_type, char *realtype);
91 91 static void do_scalar_field(char *_type, char *_field,
92 92 int _sign, char *dotfield);
93 93 static void do_array_field(char *_type, char *_field,
94 94 int _sign, char *dotfield);
95 95 static void do_array_type(char *_type, char *_field, int _sign);
96 96
97 97 static void get_ctf_file(char *fname);
98 98 static int get_field_info(char *tname, char *fname, char *dotname,
99 99 int *offp, int *sizep);
100 100
101 101 static ctf_file_t *ctf;
102 102 static char *objfile;
103 103 static char *machname;
104 104
105 105 /* auxv_t, <sys/auxv.h> */
106 106 static void
107 107 gen_auxv(void)
108 108 {
109 109 START(auxv, auxv_t);
110 110
111 111 SCALAR_FIELD(auxv_t, a_type, 1);
112 112 SCALAR_FIELD(auxv_t, a_un.a_val, 1);
113 113 SCALAR_FIELD(auxv_t, a_un.a_ptr, 0);
114 114 SCALAR_FIELD(auxv_t, a_un.a_fcn, 0);
115 115
116 116 END;
117 117 }
118 118
119 119
120 120 /* prgregset_t, <sys/prgregset.h> */
121 121 static void
122 122 gen_prgregset(void)
123 123 {
124 124 START(prgregset, prgregset_t);
125 125
126 126 ARRAY_TYPE(prgregset_t, 0);
127 127
128 128 END;
129 129 }
130 130
131 131
132 132 /* lwpstatus_t, <sys/procfs.h> */
133 133 static void
134 134 gen_lwpstatus(void)
135 135 {
136 136 START(lwpstatus, lwpstatus_t);
137 137
138 138 SCALAR_FIELD(lwpstatus_t, pr_flags, 0);
139 139 SCALAR_FIELD(lwpstatus_t, pr_lwpid, 0);
140 140 SCALAR_FIELD(lwpstatus_t, pr_why, 0);
141 141 SCALAR_FIELD(lwpstatus_t, pr_what, 0);
142 142 SCALAR_FIELD(lwpstatus_t, pr_cursig, 0);
143 143 SCALAR_FIELD(lwpstatus_t, pr_info, 0);
144 144 SCALAR_FIELD(lwpstatus_t, pr_lwppend, 0);
145 145 SCALAR_FIELD(lwpstatus_t, pr_lwphold, 0);
146 146 SCALAR_FIELD(lwpstatus_t, pr_action, 0);
147 147 SCALAR_FIELD(lwpstatus_t, pr_altstack, 0);
148 148 SCALAR_FIELD(lwpstatus_t, pr_oldcontext, 0);
149 149 SCALAR_FIELD(lwpstatus_t, pr_syscall, 0);
150 150 SCALAR_FIELD(lwpstatus_t, pr_nsysarg, 0);
151 151 SCALAR_FIELD(lwpstatus_t, pr_errno, 0);
152 152 ARRAY_FIELD(lwpstatus_t, pr_sysarg, 0);
153 153 SCALAR_FIELD(lwpstatus_t, pr_rval1, 0);
154 154 SCALAR_FIELD(lwpstatus_t, pr_rval2, 0);
155 155 ARRAY_FIELD(lwpstatus_t, pr_clname, 0);
156 156 SCALAR_FIELD(lwpstatus_t, pr_tstamp, 0);
157 157 SCALAR_FIELD(lwpstatus_t, pr_utime, 0);
158 158 SCALAR_FIELD(lwpstatus_t, pr_stime, 0);
159 159 SCALAR_FIELD(lwpstatus_t, pr_errpriv, 0);
160 160 SCALAR_FIELD(lwpstatus_t, pr_ustack, 0);
161 161 SCALAR_FIELD(lwpstatus_t, pr_instr, 0);
162 162 SCALAR_FIELD(lwpstatus_t, pr_reg, 0);
163 163 SCALAR_FIELD(lwpstatus_t, pr_fpreg, 0);
164 164
165 165 END;
166 166 }
167 167
168 168
169 169 /* pstatus_t, <sys/procfs.h> */
170 170 static void
171 171 gen_pstatus(void)
172 172 {
173 173 START(pstatus, pstatus_t);
174 174
175 175 SCALAR_FIELD(pstatus_t, pr_flags, 1);
176 176 SCALAR_FIELD(pstatus_t, pr_nlwp, 1);
177 177 SCALAR_FIELD(pstatus_t, pr_pid, 0);
178 178 SCALAR_FIELD(pstatus_t, pr_ppid, 0);
179 179 SCALAR_FIELD(pstatus_t, pr_pgid, 0);
180 180 SCALAR_FIELD(pstatus_t, pr_sid, 0);
181 181 SCALAR_FIELD(pstatus_t, pr_aslwpid, 1);
182 182 SCALAR_FIELD(pstatus_t, pr_agentid, 1);
183 183 SCALAR_FIELD(pstatus_t, pr_sigpend, 0);
184 184 SCALAR_FIELD(pstatus_t, pr_brkbase, 0);
185 185 SCALAR_FIELD(pstatus_t, pr_brksize, 0);
186 186 SCALAR_FIELD(pstatus_t, pr_stkbase, 0);
187 187 SCALAR_FIELD(pstatus_t, pr_stksize, 0);
188 188 SCALAR_FIELD(pstatus_t, pr_utime, 0);
189 189 SCALAR_FIELD(pstatus_t, pr_stime, 0);
190 190 SCALAR_FIELD(pstatus_t, pr_cutime, 0);
191 191 SCALAR_FIELD(pstatus_t, pr_cstime, 0);
192 192 SCALAR_FIELD(pstatus_t, pr_sigtrace, 0);
193 193 SCALAR_FIELD(pstatus_t, pr_flttrace, 0);
194 194 SCALAR_FIELD(pstatus_t, pr_sysentry, 0);
195 195 SCALAR_FIELD(pstatus_t, pr_sysexit, 0);
196 196 SCALAR_FIELD(pstatus_t, pr_dmodel, 0);
197 197 SCALAR_FIELD(pstatus_t, pr_taskid, 1);
198 198 SCALAR_FIELD(pstatus_t, pr_projid, 1);
199 199 SCALAR_FIELD(pstatus_t, pr_nzomb, 1);
200 200 SCALAR_FIELD(pstatus_t, pr_zoneid, 1);
201 201 SCALAR_FIELD(pstatus_t, pr_lwp, 0);
202 202
203 203 END;
204 204 }
205 205
206 206
207 207 /* prstatus_t, <sys/old_procfs.h> */
208 208 static void
209 209 gen_prstatus(void)
210 210 {
211 211 START(prstatus, prstatus_t);
212 212
213 213 SCALAR_FIELD(prstatus_t, pr_flags, 1);
214 214 SCALAR_FIELD(prstatus_t, pr_why, 1);
215 215 SCALAR_FIELD(prstatus_t, pr_what, 1);
216 216 SCALAR_FIELD(prstatus_t, pr_info, 0);
217 217 SCALAR_FIELD(prstatus_t, pr_cursig, 1);
218 218 SCALAR_FIELD(prstatus_t, pr_nlwp, 0);
219 219 SCALAR_FIELD(prstatus_t, pr_sigpend, 0);
220 220 SCALAR_FIELD(prstatus_t, pr_sighold, 0);
221 221 SCALAR_FIELD(prstatus_t, pr_altstack, 0);
222 222 SCALAR_FIELD(prstatus_t, pr_action, 0);
223 223 SCALAR_FIELD(prstatus_t, pr_pid, 0);
224 224 SCALAR_FIELD(prstatus_t, pr_ppid, 0);
225 225 SCALAR_FIELD(prstatus_t, pr_pgrp, 0);
226 226 SCALAR_FIELD(prstatus_t, pr_sid, 0);
227 227 SCALAR_FIELD(prstatus_t, pr_utime, 0);
228 228 SCALAR_FIELD(prstatus_t, pr_stime, 0);
229 229 SCALAR_FIELD(prstatus_t, pr_cutime, 0);
230 230 SCALAR_FIELD(prstatus_t, pr_cstime, 0);
231 231 ARRAY_FIELD(prstatus_t, pr_clname, 0);
232 232 SCALAR_FIELD(prstatus_t, pr_syscall, 1);
233 233 SCALAR_FIELD(prstatus_t, pr_nsysarg, 1);
234 234 ARRAY_FIELD(prstatus_t, pr_sysarg, 1);
235 235 SCALAR_FIELD(prstatus_t, pr_who, 0);
236 236 SCALAR_FIELD(prstatus_t, pr_lwppend, 0);
237 237 SCALAR_FIELD(prstatus_t, pr_oldcontext, 0);
238 238 SCALAR_FIELD(prstatus_t, pr_brkbase, 0);
239 239 SCALAR_FIELD(prstatus_t, pr_brksize, 0);
240 240 SCALAR_FIELD(prstatus_t, pr_stkbase, 0);
241 241 SCALAR_FIELD(prstatus_t, pr_stksize, 0);
242 242 SCALAR_FIELD(prstatus_t, pr_processor, 1);
243 243 SCALAR_FIELD(prstatus_t, pr_bind, 1);
244 244 SCALAR_FIELD(prstatus_t, pr_instr, 1);
245 245 SCALAR_FIELD(prstatus_t, pr_reg, 0);
246 246
247 247 END;
248 248 }
249 249
250 250
251 251 /* psinfo_t, <sys/procfs.h> */
252 252 static void
253 253 gen_psinfo(void)
254 254 {
255 255 START(psinfo, psinfo_t);
256 256
257 257 SCALAR_FIELD(psinfo_t, pr_flag, 1);
258 258 SCALAR_FIELD(psinfo_t, pr_nlwp, 1);
259 259 SCALAR_FIELD(psinfo_t, pr_pid, 0);
260 260 SCALAR_FIELD(psinfo_t, pr_ppid, 0);
261 261 SCALAR_FIELD(psinfo_t, pr_pgid, 0);
262 262 SCALAR_FIELD(psinfo_t, pr_sid, 0);
263 263 SCALAR_FIELD(psinfo_t, pr_uid, 0);
264 264 SCALAR_FIELD(psinfo_t, pr_euid, 0);
265 265 SCALAR_FIELD(psinfo_t, pr_gid, 0);
266 266 SCALAR_FIELD(psinfo_t, pr_egid, 0);
267 267 SCALAR_FIELD(psinfo_t, pr_addr, 0);
268 268 SCALAR_FIELD(psinfo_t, pr_size, 0);
269 269 SCALAR_FIELD(psinfo_t, pr_rssize, 0);
270 270 SCALAR_FIELD(psinfo_t, pr_ttydev, 0);
271 271 SCALAR_FIELD(psinfo_t, pr_pctcpu, 0);
272 272 SCALAR_FIELD(psinfo_t, pr_pctmem, 0);
273 273 SCALAR_FIELD(psinfo_t, pr_start, 0);
274 274 SCALAR_FIELD(psinfo_t, pr_time, 0);
275 275 SCALAR_FIELD(psinfo_t, pr_ctime, 0);
276 276 ARRAY_FIELD(psinfo_t, pr_fname, 0);
277 277 ARRAY_FIELD(psinfo_t, pr_psargs, 0);
278 278 SCALAR_FIELD(psinfo_t, pr_wstat, 1);
279 279 SCALAR_FIELD(psinfo_t, pr_argc, 1);
280 280 SCALAR_FIELD(psinfo_t, pr_argv, 0);
281 281 SCALAR_FIELD(psinfo_t, pr_envp, 0);
282 282 SCALAR_FIELD(psinfo_t, pr_dmodel, 0);
283 283 SCALAR_FIELD(psinfo_t, pr_taskid, 0);
284 284 SCALAR_FIELD(psinfo_t, pr_projid, 0);
285 285 SCALAR_FIELD(psinfo_t, pr_nzomb, 1);
286 286 SCALAR_FIELD(psinfo_t, pr_poolid, 0);
287 287 SCALAR_FIELD(psinfo_t, pr_zoneid, 0);
288 288 SCALAR_FIELD(psinfo_t, pr_contract, 0);
289 289 SCALAR_FIELD(psinfo_t, pr_lwp, 0);
290 290
291 291 END;
292 292 }
293 293
294 294 /* prpsinfo_t, <sys/old_procfs.h> */
295 295 static void
296 296 gen_prpsinfo(void)
297 297 {
298 298 START(prpsinfo, prpsinfo_t);
299 299
300 300 SCALAR_FIELD(prpsinfo_t, pr_state, 0);
301 301 SCALAR_FIELD(prpsinfo_t, pr_sname, 0);
302 302 SCALAR_FIELD(prpsinfo_t, pr_zomb, 0);
303 303 SCALAR_FIELD(prpsinfo_t, pr_nice, 0);
304 304 SCALAR_FIELD(prpsinfo_t, pr_flag, 0);
305 305 SCALAR_FIELD(prpsinfo_t, pr_uid, 0);
306 306 SCALAR_FIELD(prpsinfo_t, pr_gid, 0);
307 307 SCALAR_FIELD(prpsinfo_t, pr_pid, 0);
308 308 SCALAR_FIELD(prpsinfo_t, pr_ppid, 0);
309 309 SCALAR_FIELD(prpsinfo_t, pr_pgrp, 0);
310 310 SCALAR_FIELD(prpsinfo_t, pr_sid, 0);
311 311 SCALAR_FIELD(prpsinfo_t, pr_addr, 0);
312 312 SCALAR_FIELD(prpsinfo_t, pr_size, 0);
313 313 SCALAR_FIELD(prpsinfo_t, pr_rssize, 0);
314 314 SCALAR_FIELD(prpsinfo_t, pr_wchan, 0);
315 315 SCALAR_FIELD(prpsinfo_t, pr_start, 0);
316 316 SCALAR_FIELD(prpsinfo_t, pr_time, 0);
317 317 SCALAR_FIELD(prpsinfo_t, pr_pri, 1);
318 318 SCALAR_FIELD(prpsinfo_t, pr_oldpri, 0);
319 319 SCALAR_FIELD(prpsinfo_t, pr_cpu, 0);
320 320 SCALAR_FIELD(prpsinfo_t, pr_ottydev, 0);
321 321 SCALAR_FIELD(prpsinfo_t, pr_lttydev, 0);
322 322 ARRAY_FIELD(prpsinfo_t, pr_clname, 0);
323 323 ARRAY_FIELD(prpsinfo_t, pr_fname, 0);
324 324 ARRAY_FIELD(prpsinfo_t, pr_psargs, 0);
325 325 SCALAR_FIELD(prpsinfo_t, pr_syscall, 1);
326 326 SCALAR_FIELD(prpsinfo_t, pr_ctime, 0);
327 327 SCALAR_FIELD(prpsinfo_t, pr_bysize, 0);
328 328 SCALAR_FIELD(prpsinfo_t, pr_byrssize, 0);
329 329 SCALAR_FIELD(prpsinfo_t, pr_argc, 1);
330 330 SCALAR_FIELD(prpsinfo_t, pr_argv, 0);
331 331 SCALAR_FIELD(prpsinfo_t, pr_envp, 0);
332 332 SCALAR_FIELD(prpsinfo_t, pr_wstat, 1);
333 333 SCALAR_FIELD(prpsinfo_t, pr_pctcpu, 0);
334 334 SCALAR_FIELD(prpsinfo_t, pr_pctmem, 0);
335 335 SCALAR_FIELD(prpsinfo_t, pr_euid, 0);
336 336 SCALAR_FIELD(prpsinfo_t, pr_egid, 0);
337 337 SCALAR_FIELD(prpsinfo_t, pr_aslwpid, 0);
338 338 SCALAR_FIELD(prpsinfo_t, pr_dmodel, 0);
339 339
340 340 END;
341 341 }
342 342
343 343 /* lwpsinfo_t, <sys/procfs.h> */
344 344 static void
345 345 gen_lwpsinfo(void)
346 346 {
347 347 START(lwpsinfo, lwpsinfo_t);
348 348
349 349 SCALAR_FIELD(lwpsinfo_t, pr_flag, 1);
350 350 SCALAR_FIELD(lwpsinfo_t, pr_lwpid, 0);
351 351 SCALAR_FIELD(lwpsinfo_t, pr_addr, 0);
352 352 SCALAR_FIELD(lwpsinfo_t, pr_wchan, 0);
353 353 SCALAR_FIELD(lwpsinfo_t, pr_stype, 0);
354 354 SCALAR_FIELD(lwpsinfo_t, pr_state, 0);
355 355 SCALAR_FIELD(lwpsinfo_t, pr_sname, 0);
356 356 SCALAR_FIELD(lwpsinfo_t, pr_nice, 0);
357 357 SCALAR_FIELD(lwpsinfo_t, pr_syscall, 0);
358 358 SCALAR_FIELD(lwpsinfo_t, pr_oldpri, 0);
359 359 SCALAR_FIELD(lwpsinfo_t, pr_cpu, 0);
360 360 SCALAR_FIELD(lwpsinfo_t, pr_pri, 1);
361 361 SCALAR_FIELD(lwpsinfo_t, pr_pctcpu, 0);
362 362 SCALAR_FIELD(lwpsinfo_t, pr_start, 0);
363 363 SCALAR_FIELD(lwpsinfo_t, pr_time, 0);
364 364 ARRAY_FIELD(lwpsinfo_t, pr_clname, 0);
365 365 ARRAY_FIELD(lwpsinfo_t, pr_name, 0);
366 366 SCALAR_FIELD(lwpsinfo_t, pr_onpro, 1);
367 367 SCALAR_FIELD(lwpsinfo_t, pr_bindpro, 1);
368 368 SCALAR_FIELD(lwpsinfo_t, pr_bindpset, 1);
369 369 SCALAR_FIELD(lwpsinfo_t, pr_lgrp, 1);
370 370
371 371 END;
372 372 }
373 373
374 374 /* prcred_t, <sys/procfs.h> */
375 375 static void
376 376 gen_prcred(void)
377 377 {
378 378 START(prcred, prcred_t);
379 379
380 380 SCALAR_FIELD(prcred_t, pr_euid, 0);
381 381 SCALAR_FIELD(prcred_t, pr_ruid, 0);
382 382 SCALAR_FIELD(prcred_t, pr_suid, 0);
383 383 SCALAR_FIELD(prcred_t, pr_egid, 0);
384 384 SCALAR_FIELD(prcred_t, pr_rgid, 0);
385 385 SCALAR_FIELD(prcred_t, pr_sgid, 0);
386 386 SCALAR_FIELD(prcred_t, pr_ngroups, 1);
387 387 ARRAY_FIELD(prcred_t, pr_groups, 0);
388 388
389 389 END;
390 390 }
391 391
392 392 /* prpriv_t, <sys/procfs.h> */
393 393 static void
394 394 gen_prpriv(void)
395 395 {
396 396 START(prpriv, prpriv_t);
397 397
398 398 SCALAR_FIELD(prpriv_t, pr_nsets, 0);
399 399 SCALAR_FIELD(prpriv_t, pr_setsize, 0);
400 400 SCALAR_FIELD(prpriv_t, pr_infosize, 0);
401 401 ARRAY_FIELD(prpriv_t, pr_sets, 0);
402 402
403 403 END;
404 404 }
405 405
406 406
407 407 /* priv_impl_info_t, <sys/priv.h> */
408 408 static void
409 409 gen_priv_impl_info(void)
410 410 {
411 411 START(priv_impl_info, priv_impl_info_t);
412 412
413 413 SCALAR_FIELD(priv_impl_info_t, priv_headersize, 0);
414 414 SCALAR_FIELD(priv_impl_info_t, priv_flags, 0);
415 415 SCALAR_FIELD(priv_impl_info_t, priv_nsets, 0);
416 416 SCALAR_FIELD(priv_impl_info_t, priv_setsize, 0);
417 417 SCALAR_FIELD(priv_impl_info_t, priv_max, 0);
418 418 SCALAR_FIELD(priv_impl_info_t, priv_infosize, 0);
419 419 SCALAR_FIELD(priv_impl_info_t, priv_globalinfosize, 0);
420 420
421 421 END;
422 422 }
423 423
424 424
425 425 /* fltset_t, <sys/fault.h> */
426 426 static void
427 427 gen_fltset(void)
428 428 {
429 429 START(fltset, fltset_t);
430 430
431 431 ARRAY_FIELD(fltset_t, word, 0);
432 432
433 433 END;
434 434 }
435 435
436 436 /*
437 437 * Layout description of siginfo_t, <sys/siginfo.h>
438 438 *
439 439 * Note: many siginfo_t members are #defines mapping to
440 440 * long dotted members of sub-structs or unions, and
441 441 * we need the full member spec (with dots) for those.
442 442 */
443 443 static void
444 444 gen_siginfo(void)
445 445 {
446 446 START(siginfo, siginfo_t);
447 447
448 448 SCALAR_FIELD(siginfo_t, si_signo, 0);
449 449 SCALAR_FIELD(siginfo_t, si_errno, 0);
450 450 SCALAR_FIELD(siginfo_t, si_code, 1);
451 451
452 452 SCALAR_FIELD4(siginfo_t, si_value.sival_int, 0,
453 453 "__data.__proc.__pdata.__kill.__value.sival_int");
454 454
455 455 SCALAR_FIELD4(siginfo_t, si_value.sival_ptr, 0,
456 456 "__data.__proc.__pdata.__kill.__value.sival_ptr");
457 457
458 458 SCALAR_FIELD4(siginfo_t, si_pid, 0,
459 459 "__data.__proc.__pid");
460 460
461 461 SCALAR_FIELD4(siginfo_t, si_uid, 0,
462 462 "__data.__proc.__pdata.__kill.__uid");
463 463
464 464 SCALAR_FIELD4(siginfo_t, si_ctid, 0,
465 465 "__data.__proc.__ctid");
466 466
467 467 SCALAR_FIELD4(siginfo_t, si_zoneid, 0,
468 468 "__data.__proc.__zoneid");
469 469
470 470 SCALAR_FIELD4(siginfo_t, si_entity, 0,
471 471 "__data.__rctl.__entity");
472 472
473 473 SCALAR_FIELD4(siginfo_t, si_addr, 0,
474 474 "__data.__fault.__addr");
475 475
476 476 SCALAR_FIELD4(siginfo_t, si_status, 0,
477 477 "__data.__proc.__pdata.__cld.__status");
478 478
479 479 SCALAR_FIELD4(siginfo_t, si_band, 0,
480 480 "__data.__file.__band");
481 481
482 482 END;
483 483 }
484 484
485 485 /* sigset_t, <sys/signal.h> */
486 486 static void
487 487 gen_sigset(void)
488 488 {
489 489 START(sigset, sigset_t);
490 490
491 491 ARRAY_FIELD(sigset_t, __sigbits, 0);
492 492
493 493 END;
494 494 }
495 495
496 496
497 497 /* struct sigaction, <sys/signal.h> */
498 498 static void
499 499 gen_sigaction(void)
500 500 {
501 501 START(sigaction, struct sigaction);
502 502
503 503 SCALAR_FIELD(struct sigaction, sa_flags, 0);
504 504
505 505 SCALAR_FIELD4(struct sigaction, sa_handler, 0,
506 506 "_funcptr._handler");
507 507
508 508 SCALAR_FIELD4(struct sigaction, sa_sigaction, 0,
509 509 "_funcptr._sigaction");
510 510
511 511 SCALAR_FIELD(struct sigaction, sa_mask, 0);
512 512
513 513 END;
514 514 }
515 515
516 516 /* stack_t, <sys/signal.h> */
517 517 static void
518 518 gen_stack(void)
519 519 {
520 520 START(stack, stack_t);
521 521
522 522 SCALAR_FIELD(stack_t, ss_sp, 0);
523 523 SCALAR_FIELD(stack_t, ss_size, 0);
524 524 SCALAR_FIELD(stack_t, ss_flags, 0);
525 525
526 526 END;
527 527 }
528 528
529 529 /* sysset_t, <sys/syscall.h> */
530 530 static void
531 531 gen_sysset(void)
532 532 {
533 533 START(sysset, sysset_t);
534 534
535 535 ARRAY_FIELD(sysset_t, word, 0);
536 536
537 537 END;
538 538 }
539 539
540 540 /* timestruc_t, <sys/time_impl.h> */
541 541 static void
542 542 gen_timestruc(void)
543 543 {
544 544 START(timestruc, timestruc_t);
545 545
546 546 SCALAR_FIELD(timestruc_t, tv_sec, 0);
547 547 SCALAR_FIELD(timestruc_t, tv_nsec, 0);
548 548
549 549 END;
550 550 }
551 551
552 552 /* struct utsname, <sys/utsname.h> */
553 553 static void
554 554 gen_utsname(void)
555 555 {
556 556 START(utsname, struct utsname);
557 557
558 558 ARRAY_FIELD(struct utsname, sysname, 0);
559 559 ARRAY_FIELD(struct utsname, nodename, 0);
560 560 ARRAY_FIELD(struct utsname, release, 0);
561 561 ARRAY_FIELD(struct utsname, version, 0);
562 562 ARRAY_FIELD(struct utsname, machine, 0);
563 563
564 564 END;
565 565 }
566 566
567 567 static void
568 568 gen_prfdinfo(void)
569 569 {
570 570 START(prfdinfo, prfdinfo_t);
571 571
572 572 SCALAR_FIELD(prfdinfo_t, pr_fd, 0);
573 573 SCALAR_FIELD(prfdinfo_t, pr_mode, 0);
574 574 SCALAR_FIELD(prfdinfo_t, pr_uid, 0);
575 575 SCALAR_FIELD(prfdinfo_t, pr_gid, 0);
576 576 SCALAR_FIELD(prfdinfo_t, pr_major, 0);
577 577 SCALAR_FIELD(prfdinfo_t, pr_minor, 0);
578 578 SCALAR_FIELD(prfdinfo_t, pr_rmajor, 0);
579 579 SCALAR_FIELD(prfdinfo_t, pr_rminor, 0);
↓ open down ↓ |
579 lines elided |
↑ open up ↑ |
580 580 SCALAR_FIELD(prfdinfo_t, pr_ino, 0);
581 581 SCALAR_FIELD(prfdinfo_t, pr_offset, 0);
582 582 SCALAR_FIELD(prfdinfo_t, pr_size, 0);
583 583 SCALAR_FIELD(prfdinfo_t, pr_fileflags, 0);
584 584 SCALAR_FIELD(prfdinfo_t, pr_fdflags, 0);
585 585 ARRAY_FIELD(prfdinfo_t, pr_path, 0);
586 586
587 587 END;
588 588 }
589 589
590 +static void
591 +gen_prsecflags(void)
592 +{
593 + START(prsecflags, prsecflags_t);
594 + SCALAR_FIELD(prsecflags_t, pr_version, 0);
595 + SCALAR_FIELD(prsecflags_t, pr_effective, 0);
596 + SCALAR_FIELD(prsecflags_t, pr_inherit, 0);
597 + SCALAR_FIELD(prsecflags_t, pr_lower, 0);
598 + SCALAR_FIELD(prsecflags_t, pr_upper, 0);
599 + END;
600 +}
590 601
591 602 /*ARGSUSED*/
592 603 int
593 604 main(int argc, char *argv[])
594 605 {
595 606 const char *fmt = "\t&%s_layout,\n";
596 607
597 608 /* get obj file for input */
598 609 if (argc < 3) {
599 610 (void) fprintf(stderr,
600 611 "usage: %s {object_file} {MACH}\n", argv[0]);
601 612 exit(1);
602 613 }
603 614
604 615 objfile = argv[1];
605 616 machname = argv[2];
606 617
607 618 get_ctf_file(objfile);
608 619
609 620 (void) printf("#include <struct_layout.h>\n");
610 621
611 622 gen_auxv();
612 623 gen_prgregset();
613 624 gen_lwpstatus();
614 625 gen_pstatus();
615 626 gen_prstatus();
616 627 gen_psinfo();
617 628 gen_prpsinfo();
618 629 gen_lwpsinfo();
619 630 gen_prcred();
620 631 gen_prpriv();
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
621 632 gen_priv_impl_info();
622 633 gen_fltset();
623 634 gen_siginfo();
624 635 gen_sigset();
625 636 gen_sigaction();
626 637 gen_stack();
627 638 gen_sysset();
628 639 gen_timestruc();
629 640 gen_utsname();
630 641 gen_prfdinfo();
631 -
642 + gen_prsecflags();
632 643
633 644 /*
634 645 * Generate the full arch_layout description
635 646 */
636 647 (void) printf(
637 648 "\n\n\n\nstatic const sl_arch_layout_t layout_%s = {\n",
638 649 machname);
639 650 (void) printf(fmt, "auxv");
640 651 (void) printf(fmt, "fltset");
641 652 (void) printf(fmt, "lwpsinfo");
642 653 (void) printf(fmt, "lwpstatus");
643 654 (void) printf(fmt, "prcred");
644 655 (void) printf(fmt, "priv_impl_info");
645 656 (void) printf(fmt, "prpriv");
646 657 (void) printf(fmt, "psinfo");
647 658 (void) printf(fmt, "pstatus");
648 659 (void) printf(fmt, "prgregset");
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
649 660 (void) printf(fmt, "prpsinfo");
650 661 (void) printf(fmt, "prstatus");
651 662 (void) printf(fmt, "sigaction");
652 663 (void) printf(fmt, "siginfo");
653 664 (void) printf(fmt, "sigset");
654 665 (void) printf(fmt, "stack");
655 666 (void) printf(fmt, "sysset");
656 667 (void) printf(fmt, "timestruc");
657 668 (void) printf(fmt, "utsname");
658 669 (void) printf(fmt, "prfdinfo");
670 + (void) printf(fmt, "prsecflags");
659 671 (void) printf("};\n");
660 672
661 673 /*
662 674 * A public function, to make the information available
663 675 */
664 676 (void) printf("\n\nconst sl_arch_layout_t *\n");
665 677 (void) printf("struct_layout_%s(void)\n", machname);
666 678 (void) printf("{\n\treturn (&layout_%s);\n}\n", machname);
667 679
668 680 return (0);
669 681 }
670 682
671 683 /*
672 684 * Helper functions using the CTF library to get type info.
673 685 */
674 686
675 687 static void
676 688 get_ctf_file(char *fname)
677 689 {
678 690 int ctferr;
679 691
680 692 objfile = fname;
681 693 if ((ctf = ctf_open(objfile, &ctferr)) == NULL) {
682 694 errx(1, "Couldn't open object file %s: %s\n", objfile,
683 695 ctf_errmsg(ctferr));
684 696 }
685 697 }
686 698
687 699 static void
688 700 print_row(int boff, int eltlen, int nelts, int issigned, char *comment)
689 701 {
690 702 (void) printf("\t{ %d,\t%d,\t%d,\t%d },\t\t/* %s */\n",
691 703 boff, eltlen, nelts, issigned, comment);
692 704 }
693 705
694 706 static void
695 707 do_start(char *sname, char *tname)
696 708 {
697 709 do_start_name(sname);
698 710 do_start_sizeof(tname, NULL);
699 711 }
700 712
701 713 static void
702 714 do_start_name(char *sname)
703 715 {
704 716 (void) printf("\n\nstatic const sl_%s_layout_t %s_layout = {\n",
705 717 sname, sname);
706 718 }
707 719
708 720 static void
709 721 do_end(void)
710 722 {
711 723 (void) printf("};\n");
712 724 }
713 725
714 726 static void
715 727 do_start_sizeof(char *tname, char *rtname)
716 728 {
717 729 char comment[100];
718 730 ctf_id_t stype;
719 731 int sz;
720 732
721 733 if (rtname == NULL)
722 734 rtname = tname;
723 735
724 736 if ((stype = ctf_lookup_by_name(ctf, rtname)) == CTF_ERR)
725 737 errx(1, "Couldn't find type %s", rtname);
726 738 if ((stype = ctf_type_resolve(ctf, stype)) == CTF_ERR)
727 739 errx(1, "Couldn't resolve type %s", tname);
728 740
729 741 if ((sz = (int)ctf_type_size(ctf, stype)) < 0) {
730 742 errx(1, "Couldn't get size for type %s", tname);
731 743 } else if (sz == 0) {
732 744 errx(1, "Invalid type size 0 for %s", tname);
733 745 }
734 746
735 747 (void) snprintf(comment, sizeof (comment), "sizeof (%s)", tname);
736 748 print_row(0, sz, 0, 0, comment);
737 749 }
738 750
739 751 static void
740 752 do_scalar_field(char *tname, char *fname, int _sign, char *dotfield)
741 753 {
742 754 int rc, off, sz, ftype;
743 755
744 756 rc = get_field_info(tname, fname, dotfield, &off, &ftype);
745 757 if (rc < 0)
746 758 errx(1, "Can't get field info for %s->%s", tname, fname);
747 759
748 760 if ((ftype = ctf_type_resolve(ctf, ftype)) == CTF_ERR)
749 761 errx(1, "Couldn't resolve type of %s->%s", tname, fname);
750 762
751 763 if ((sz = (int)ctf_type_size(ctf, ftype)) < 0) {
↓ open down ↓ |
83 lines elided |
↑ open up ↑ |
752 764 errx(1, "Couldn't get size for type ID %d", ftype);
753 765 } else if (sz == 0) {
754 766 errx(1, "Invalid type size 0 for type ID %d", ftype);
755 767 }
756 768
757 769 print_row(off, sz, 0, _sign, fname);
758 770 }
759 771
760 772 static void
761 773 do_array_field(char *tname, char *fname,
762 - int _sign, char *dotfield)
774 + int _sign, char *dotfield)
763 775 {
764 776 char comment[100];
765 777 ctf_arinfo_t ai;
766 778 int typekind;
767 779 int esz, rc, off, ftype;
768 780
769 781 rc = get_field_info(tname, fname, dotfield, &off, &ftype);
770 782 if (rc < 0)
771 783 errx(1, "Can't get field info for %s->%s", tname, fname);
772 784
773 785 if ((ftype = ctf_type_resolve(ctf, ftype)) == CTF_ERR)
774 786 errx(1, "Couldn't resolve type of %s->%s", tname, fname);
775 787
776 788 typekind = ctf_type_kind(ctf, ftype);
777 789 if (typekind != CTF_K_ARRAY)
778 790 errx(1, "Wrong type for %s->%s", tname, fname);
779 791
780 792 rc = ctf_array_info(ctf, ftype, &ai);
781 793 if (rc != 0)
782 794 errx(1, "Can't get array info for %s->%s\n", tname, fname);
783 795 esz = ctf_type_size(ctf, ai.ctr_contents);
784 796 if (esz < 0)
785 797 errx(1, "Can't get element size for %s->%s\n", tname, fname);
786 798
787 799 (void) snprintf(comment, sizeof (comment), "%s[]", fname);
788 800 print_row(off, esz, ai.ctr_nelems, _sign, comment);
789 801 }
790 802
791 803 static void
792 804 do_array_type(char *tname, char *fname, int _sign)
793 805 {
794 806 ctf_arinfo_t ai;
795 807 int stype, typekind;
796 808 int esz, rc;
797 809
798 810 if ((stype = ctf_lookup_by_name(ctf, tname)) == CTF_ERR)
799 811 errx(1, "Couldn't find type %s", tname);
800 812 if ((stype = ctf_type_resolve(ctf, stype)) == CTF_ERR)
801 813 errx(1, "Couldn't resolve type %s", tname);
802 814
803 815 typekind = ctf_type_kind(ctf, stype);
804 816 if (typekind != CTF_K_ARRAY)
805 817 errx(1, "Wrong type for %s->%s", tname, fname);
806 818
807 819 rc = ctf_array_info(ctf, stype, &ai);
808 820 if (rc != 0)
809 821 errx(1, "Can't get array info for %s->%s\n", tname, fname);
810 822 esz = ctf_type_size(ctf, ai.ctr_contents);
811 823 if (esz < 0)
812 824 errx(1, "Can't get element size for %s->%s\n", tname, fname);
813 825
814 826 print_row(0, esz, ai.ctr_nelems, _sign, fname);
815 827 }
816 828
817 829
818 830 struct gfinfo {
819 831 char *tname; /* top type name, i.e. the struct */
820 832 char *fname; /* field name */
821 833 char *dotname; /* full field name with dots (optional) */
822 834 char *prefix; /* current field search prefix */
823 835 int base_off;
824 836 int fld_off;
825 837 int fld_type;
826 838 };
827 839
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
828 840 static int gfi_iter(const char *fname, ctf_id_t mbrtid,
829 841 ulong_t off, void *varg);
830 842
831 843 /*
832 844 * Lookup field "fname" in type "tname". If "dotname" is non-NULL,
833 845 * that's the full field name with dots, i.e. a_un.un_foo, which
834 846 * we must search for by walking the struct CTF recursively.
835 847 */
836 848 static int
837 849 get_field_info(char *tname, char *fname, char *dotname,
838 - int *offp, int *tidp)
850 + int *offp, int *tidp)
839 851 {
840 852 struct gfinfo gfi;
841 853 ctf_id_t stype;
842 854 int typekind;
843 855 int rc;
844 856
845 857 if ((stype = ctf_lookup_by_name(ctf, tname)) == CTF_ERR)
846 858 errx(1, "Couldn't find type %s", tname);
847 859 if ((stype = ctf_type_resolve(ctf, stype)) == CTF_ERR)
848 860 errx(1, "Couldn't resolve type %s", tname);
849 861
850 862 /* If fname has a dot, use it as dotname too. */
851 863 if (dotname == NULL && strchr(fname, '.') != NULL)
852 864 dotname = fname;
853 865
854 866 gfi.tname = tname;
855 867 gfi.fname = fname;
856 868 gfi.dotname = dotname;
857 869 gfi.prefix = "";
858 870 gfi.base_off = 0;
859 871 gfi.fld_off = 0;
860 872 gfi.fld_type = 0;
861 873
862 874 typekind = ctf_type_kind(ctf, stype);
863 875 switch (typekind) {
864 876
865 877 case CTF_K_STRUCT:
866 878 case CTF_K_UNION:
867 879 rc = ctf_member_iter(ctf, stype, gfi_iter, &gfi);
868 880 break;
869 881
870 882 default:
871 883 errx(1, "Unexpected top-level type for %s", tname);
872 884 break;
873 885 }
874 886
875 887 if (rc < 0)
876 888 errx(1, "Error getting info for %s.%s", stype, fname);
877 889 if (rc == 0)
878 890 errx(1, "Did not find %s.%s", tname, fname);
879 891
880 892 *offp = gfi.fld_off;
881 893 *tidp = gfi.fld_type;
882 894
883 895 return (0);
884 896 }
885 897
886 898 /*
887 899 * Iteration callback for ctf_member_iter
888 900 * Return <0 on error, 0 to keep looking, >0 for found.
889 901 *
890 902 * If no dotname, simple search for fieldname.
891 903 * If we're asked to search with dotname, we need to do a full
892 904 * recursive walk of the types under the dotname.
893 905 */
894 906 int
895 907 gfi_iter(const char *fieldname, ctf_id_t mbrtid, ulong_t off, void *varg)
896 908 {
897 909 char namebuf[100];
898 910 struct gfinfo *gfi = varg;
899 911 char *saveprefix;
900 912 int saveoff;
901 913 int typekind;
902 914 int byteoff;
903 915 int len, rc;
904 916
905 917 byteoff = gfi->base_off + (int)(off >> 3);
906 918
907 919 /* Easy cases first: no dotname */
908 920 if (gfi->dotname == NULL) {
909 921 if (strcmp(gfi->fname, fieldname) == 0) {
910 922 gfi->fld_off = byteoff;
911 923 gfi->fld_type = mbrtid;
912 924 return (1);
913 925 }
914 926 return (0);
915 927 }
916 928
917 929 /* Exact match on the dotname? */
918 930 (void) snprintf(namebuf, sizeof (namebuf), "%s%s",
919 931 gfi->prefix, fieldname);
920 932 if (strcmp(gfi->dotname, namebuf) == 0) {
921 933 gfi->fld_off = byteoff;
922 934 gfi->fld_type = mbrtid;
923 935 return (1);
924 936 }
925 937
926 938 /*
927 939 * May need to recurse under this field, but
928 940 * only if there's a match through '.'
929 941 */
930 942 (void) strlcat(namebuf, ".", sizeof (namebuf));
931 943 len = strlen(namebuf);
932 944 if (strncmp(gfi->dotname, namebuf, len) != 0)
933 945 return (0);
934 946
935 947 typekind = ctf_type_kind(ctf, mbrtid);
936 948 switch (typekind) {
937 949 case CTF_K_STRUCT:
938 950 case CTF_K_UNION:
939 951 break;
940 952 default:
941 953 return (0);
942 954 }
943 955
944 956 /* Recursively walk members */
945 957 saveprefix = gfi->prefix;
946 958 saveoff = gfi->base_off;
947 959 gfi->prefix = namebuf;
948 960 gfi->base_off = byteoff;
949 961 rc = ctf_member_iter(ctf, mbrtid, gfi_iter, gfi);
950 962 gfi->prefix = saveprefix;
951 963 gfi->base_off = saveoff;
952 964
953 965 return (rc);
954 966 }
↓ open down ↓ |
106 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX