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