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