xref: /illumos-gate/usr/src/cmd/sgs/elfdump/common/gen_struct_layout.c (revision f985abb4a2473d3c04b086f7c9fab177e368ffef)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <stdlib.h>
28 #include <stddef.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <fcntl.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <unistd.h>
35 #include <sys/sysmacros.h>
36 #include <sys/corectl.h>
37 #include <procfs.h>
38 #include <sys/auxv.h>
39 #include <sys/old_procfs.h>
40 #include <sys/utsname.h>
41 
42 
43 
44 /*
45  * This standalone program is used to generate the contents
46  * of the struct_layout_XXX.c files that contain per-archtecture
47  * structure layout information.
48  *
49  * Although not part of elfdump, it is built by the makefile
50  * along with it.
51  * To use it:
52  *
53  *	1) Run it, capturing the output in a file.
54  *	2) If this is a replacement for an existing file,
55  *		diff the new and old copies to ensure only
56  *		the changes you expected are present.
57  *	3) Put the new file in the common directory under the name
58  *		struct_layout_XXX.c, where XXX is the name of
59  *		the architecture (i386, amd64, sparc, sparcv9, etc).
60  *	2) Add any necessary header and copyright comments.
61  *	3) If this is a new architecture:
62  *		- Add an extern statement for struct_layout_XXX()
63  *			to struct_layout.h
64  *		- Add a case for it to the function sl_struct_layout()
65  *			in struct_layout.c.
66  */
67 
68 
69 /*
70  * Which machine is this build for?
71  */
72 #if defined(__i386)
73 
74 #define	MACH	"i386"
75 
76 #elif defined(__amd64)
77 
78 #define	MACH	"amd64"
79 
80 #elif defined(__sparcv9)
81 
82 #define	MACH	"sparcv9"
83 
84 #elif defined(__sparc)
85 
86 #define	MACH	"sparc"
87 
88 #else
89 
90 #error "unrecognized build host type"
91 
92 #endif
93 
94 
95 /*
96  * START and END bracket a struct layout definition. They issue
97  * the typedef boilerplate, and the standard first element (sizeof)
98  * which captures the overall size of the structure.
99  *
100  * SCALAR_FIELD is for scalar struct fields
101  *
102  * ARRAY_FIELD is for  array struct fields
103  *
104  * ARRAY is for plain (non-struct) array types
105  */
106 #define	START(_name, _type) \
107 	(void) printf("\n\nstatic const sl_" #_name \
108 	    "_layout_t " #_name "_layout = {\n"); \
109 	(void) printf("\t{ 0,\t%d,\t0,\t0 },\t\t/* sizeof (%s) */\n", \
110 	    sizeof (_type), #_type)
111 #define	SCALAR_FIELD(_type, _field, _sign) \
112 	(void) printf("\t{ %d,\t%d,\t0,\t%d },\t\t/* " #_field " */\n", \
113 	    offsetof(_type, _field), sizeof (((_type *)0)->_field), _sign)
114 #define	ARRAY_FIELD(_type, _field, _sign) \
115 	(void) printf("\t{ %d,\t%d,\t%d,\t%d },\t\t/* " #_field "[] */\n", \
116 	    offsetof(_type, _field), sizeof (((_type *)0)->_field[0]), \
117 	    sizeof (((_type *)0)->_field) / sizeof (((_type *)0)->_field[0]), \
118 	    _sign)
119 #define	ARRAY(_type, _sign) \
120 	(void) printf("\t{ 0,\t%d,\t%d,\t%d },\t\t/* elt0 */\n", \
121 	    sizeof (*((_type *)0)[0]), \
122 	    sizeof (_type) / sizeof (*((_type *)0)[0]), _sign)
123 #define	END (void) printf("};\n")
124 
125 
126 /* auxv_t, <sys/auxv.h> */
127 static void
128 gen_auxv(void)
129 {
130 	START(auxv, auxv_t);
131 
132 	SCALAR_FIELD(auxv_t,	a_type,	1);
133 	SCALAR_FIELD(auxv_t,	a_un.a_val,	1);
134 	SCALAR_FIELD(auxv_t,	a_un.a_ptr,	0);
135 	SCALAR_FIELD(auxv_t,	a_un.a_fcn,	0);
136 
137 	END;
138 }
139 
140 
141 /* prgregset_t, <sys/prgregset.h> */
142 static void
143 gen_prgregset(void)
144 {
145 	START(prgregset, prgregset_t);
146 
147 	ARRAY(prgregset_t,	0);
148 
149 	END;
150 }
151 
152 
153 /* lwpstatus_t, <sys/procfs.h> */
154 static void
155 gen_lwpstatus(void)
156 {
157 	START(lwpstatus, lwpstatus_t);
158 
159 	SCALAR_FIELD(lwpstatus_t,	pr_flags,	0);
160 	SCALAR_FIELD(lwpstatus_t,	pr_lwpid,	0);
161 	SCALAR_FIELD(lwpstatus_t,	pr_why,		0);
162 	SCALAR_FIELD(lwpstatus_t,	pr_what,	0);
163 	SCALAR_FIELD(lwpstatus_t,	pr_cursig,	0);
164 	SCALAR_FIELD(lwpstatus_t,	pr_info,	0);
165 	SCALAR_FIELD(lwpstatus_t,	pr_lwppend,	0);
166 	SCALAR_FIELD(lwpstatus_t,	pr_lwphold,	0);
167 	SCALAR_FIELD(lwpstatus_t,	pr_action,	0);
168 	SCALAR_FIELD(lwpstatus_t,	pr_altstack,	0);
169 	SCALAR_FIELD(lwpstatus_t,	pr_oldcontext,	0);
170 	SCALAR_FIELD(lwpstatus_t,	pr_syscall,	0);
171 	SCALAR_FIELD(lwpstatus_t,	pr_nsysarg,	0);
172 	SCALAR_FIELD(lwpstatus_t,	pr_errno,	0);
173 	ARRAY_FIELD(lwpstatus_t,	pr_sysarg,	0);
174 	SCALAR_FIELD(lwpstatus_t,	pr_rval1,	0);
175 	SCALAR_FIELD(lwpstatus_t,	pr_rval2,	0);
176 	ARRAY_FIELD(lwpstatus_t,	pr_clname,	0);
177 	SCALAR_FIELD(lwpstatus_t,	pr_tstamp,	0);
178 	SCALAR_FIELD(lwpstatus_t,	pr_utime,	0);
179 	SCALAR_FIELD(lwpstatus_t,	pr_stime,	0);
180 	SCALAR_FIELD(lwpstatus_t,	pr_errpriv,	0);
181 	SCALAR_FIELD(lwpstatus_t,	pr_ustack,	0);
182 	SCALAR_FIELD(lwpstatus_t,	pr_instr,	0);
183 	SCALAR_FIELD(lwpstatus_t,	pr_reg,		0);
184 	SCALAR_FIELD(lwpstatus_t,	pr_fpreg,	0);
185 
186 	END;
187 }
188 
189 
190 /* pstatus_t, <sys/procfs.h> */
191 static void
192 gen_pstatus(void)
193 {
194 	START(pstatus, pstatus_t);
195 
196 	SCALAR_FIELD(pstatus_t,		pr_flags,	1);
197 	SCALAR_FIELD(pstatus_t,		pr_nlwp,	1);
198 	SCALAR_FIELD(pstatus_t,		pr_pid,		0);
199 	SCALAR_FIELD(pstatus_t,		pr_ppid,	0);
200 	SCALAR_FIELD(pstatus_t,		pr_pgid,	0);
201 	SCALAR_FIELD(pstatus_t,		pr_sid,		0);
202 	SCALAR_FIELD(pstatus_t,		pr_aslwpid,	1);
203 	SCALAR_FIELD(pstatus_t,		pr_agentid,	1);
204 	SCALAR_FIELD(pstatus_t,		pr_sigpend,	0);
205 	SCALAR_FIELD(pstatus_t,		pr_brkbase,	0);
206 	SCALAR_FIELD(pstatus_t,		pr_brksize,	0);
207 	SCALAR_FIELD(pstatus_t,		pr_stkbase,	0);
208 	SCALAR_FIELD(pstatus_t,		pr_stksize,	0);
209 	SCALAR_FIELD(pstatus_t,		pr_utime,	0);
210 	SCALAR_FIELD(pstatus_t,		pr_stime,	0);
211 	SCALAR_FIELD(pstatus_t,		pr_cutime,	0);
212 	SCALAR_FIELD(pstatus_t,		pr_cstime,	0);
213 	SCALAR_FIELD(pstatus_t,		pr_sigtrace,	0);
214 	SCALAR_FIELD(pstatus_t,		pr_flttrace,	0);
215 	SCALAR_FIELD(pstatus_t,		pr_sysentry,	0);
216 	SCALAR_FIELD(pstatus_t,		pr_sysexit,	0);
217 	SCALAR_FIELD(pstatus_t,		pr_dmodel,	0);
218 	SCALAR_FIELD(pstatus_t,		pr_taskid,	1);
219 	SCALAR_FIELD(pstatus_t,		pr_projid,	1);
220 	SCALAR_FIELD(pstatus_t,		pr_nzomb,	1);
221 	SCALAR_FIELD(pstatus_t,		pr_zoneid,	1);
222 	SCALAR_FIELD(pstatus_t,		pr_lwp,		0);
223 
224 	END;
225 }
226 
227 
228 /* prstatus_t, <sys/old_procfs.h> */
229 static void
230 gen_prstatus(void)
231 {
232 	START(prstatus, prstatus_t);
233 
234 	SCALAR_FIELD(prstatus_t,	pr_flags,	1);
235 	SCALAR_FIELD(prstatus_t,	pr_why,		1);
236 	SCALAR_FIELD(prstatus_t,	pr_what,	1);
237 	SCALAR_FIELD(prstatus_t,	pr_info,	0);
238 	SCALAR_FIELD(prstatus_t,	pr_cursig,	1);
239 	SCALAR_FIELD(prstatus_t,	pr_nlwp,	0);
240 	SCALAR_FIELD(prstatus_t,	pr_sigpend,	0);
241 	SCALAR_FIELD(prstatus_t,	pr_sighold,	0);
242 	SCALAR_FIELD(prstatus_t,	pr_altstack,	0);
243 	SCALAR_FIELD(prstatus_t,	pr_action,	0);
244 	SCALAR_FIELD(prstatus_t,	pr_pid,		0);
245 	SCALAR_FIELD(prstatus_t,	pr_ppid,	0);
246 	SCALAR_FIELD(prstatus_t,	pr_pgrp,	0);
247 	SCALAR_FIELD(prstatus_t,	pr_sid,		0);
248 	SCALAR_FIELD(prstatus_t,	pr_utime,	0);
249 	SCALAR_FIELD(prstatus_t,	pr_stime,	0);
250 	SCALAR_FIELD(prstatus_t,	pr_cutime,	0);
251 	SCALAR_FIELD(prstatus_t,	pr_cstime,	0);
252 	ARRAY_FIELD(prstatus_t,		pr_clname,	0);
253 	SCALAR_FIELD(prstatus_t,	pr_syscall,	1);
254 	SCALAR_FIELD(prstatus_t,	pr_nsysarg,	1);
255 	ARRAY_FIELD(prstatus_t,		pr_sysarg,	1);
256 	SCALAR_FIELD(prstatus_t,	pr_who,		0);
257 	SCALAR_FIELD(prstatus_t,	pr_lwppend,	0);
258 	SCALAR_FIELD(prstatus_t,	pr_oldcontext,	0);
259 	SCALAR_FIELD(prstatus_t,	pr_brkbase,	0);
260 	SCALAR_FIELD(prstatus_t,	pr_brksize,	0);
261 	SCALAR_FIELD(prstatus_t,	pr_stkbase,	0);
262 	SCALAR_FIELD(prstatus_t,	pr_stksize,	0);
263 	SCALAR_FIELD(prstatus_t,	pr_processor,	1);
264 	SCALAR_FIELD(prstatus_t,	pr_bind,	1);
265 	SCALAR_FIELD(prstatus_t,	pr_instr,	1);
266 	SCALAR_FIELD(prstatus_t,	pr_reg,		0);
267 
268 	END;
269 }
270 
271 
272 /* psinfo_t, <sys/procfs.h> */
273 static void
274 gen_psinfo(void)
275 {
276 	START(psinfo, psinfo_t);
277 
278 	SCALAR_FIELD(psinfo_t,		pr_flag,	1);
279 	SCALAR_FIELD(psinfo_t,		pr_nlwp,	1);
280 	SCALAR_FIELD(psinfo_t,		pr_pid,		0);
281 	SCALAR_FIELD(psinfo_t,		pr_ppid,	0);
282 	SCALAR_FIELD(psinfo_t,		pr_pgid,	0);
283 	SCALAR_FIELD(psinfo_t,		pr_sid,		0);
284 	SCALAR_FIELD(psinfo_t,		pr_uid,		0);
285 	SCALAR_FIELD(psinfo_t,		pr_euid,	0);
286 	SCALAR_FIELD(psinfo_t,		pr_gid,		0);
287 	SCALAR_FIELD(psinfo_t,		pr_egid,	0);
288 	SCALAR_FIELD(psinfo_t,		pr_addr,	0);
289 	SCALAR_FIELD(psinfo_t,		pr_size,	0);
290 	SCALAR_FIELD(psinfo_t,		pr_rssize,	0);
291 	SCALAR_FIELD(psinfo_t,		pr_ttydev,	0);
292 	SCALAR_FIELD(psinfo_t,		pr_pctcpu,	0);
293 	SCALAR_FIELD(psinfo_t,		pr_pctmem,	0);
294 	SCALAR_FIELD(psinfo_t,		pr_start,	0);
295 	SCALAR_FIELD(psinfo_t,		pr_time,	0);
296 	SCALAR_FIELD(psinfo_t,		pr_ctime,	0);
297 	ARRAY_FIELD(psinfo_t,		pr_fname,	0);
298 	ARRAY_FIELD(psinfo_t,		pr_psargs,	0);
299 	SCALAR_FIELD(psinfo_t,		pr_wstat,	1);
300 	SCALAR_FIELD(psinfo_t,		pr_argc,	1);
301 	SCALAR_FIELD(psinfo_t,		pr_argv,	0);
302 	SCALAR_FIELD(psinfo_t,		pr_envp,	0);
303 	SCALAR_FIELD(psinfo_t,		pr_dmodel,	0);
304 	SCALAR_FIELD(psinfo_t,		pr_taskid,	0);
305 	SCALAR_FIELD(psinfo_t,		pr_projid,	0);
306 	SCALAR_FIELD(psinfo_t,		pr_nzomb,	1);
307 	SCALAR_FIELD(psinfo_t,		pr_poolid,	0);
308 	SCALAR_FIELD(psinfo_t,		pr_zoneid,	0);
309 	SCALAR_FIELD(psinfo_t,		pr_contract,	0);
310 	SCALAR_FIELD(psinfo_t,		pr_lwp,		0);
311 
312 	END;
313 }
314 
315 /* prpsinfo_t, <sys/old_procfs.h> */
316 static void
317 gen_prpsinfo(void)
318 {
319 	START(prpsinfo, prpsinfo_t);
320 
321 	SCALAR_FIELD(prpsinfo_t,	pr_state,	0);
322 	SCALAR_FIELD(prpsinfo_t,	pr_sname,	0);
323 	SCALAR_FIELD(prpsinfo_t,	pr_zomb,	0);
324 	SCALAR_FIELD(prpsinfo_t,	pr_nice,	0);
325 	SCALAR_FIELD(prpsinfo_t,	pr_flag,	0);
326 	SCALAR_FIELD(prpsinfo_t,	pr_uid,		0);
327 	SCALAR_FIELD(prpsinfo_t,	pr_gid,		0);
328 	SCALAR_FIELD(prpsinfo_t,	pr_pid,		0);
329 	SCALAR_FIELD(prpsinfo_t,	pr_ppid,	0);
330 	SCALAR_FIELD(prpsinfo_t,	pr_pgrp,	0);
331 	SCALAR_FIELD(prpsinfo_t,	pr_sid,		0);
332 	SCALAR_FIELD(prpsinfo_t,	pr_addr,	0);
333 	SCALAR_FIELD(prpsinfo_t,	pr_size,	0);
334 	SCALAR_FIELD(prpsinfo_t,	pr_rssize,	0);
335 	SCALAR_FIELD(prpsinfo_t,	pr_wchan,	0);
336 	SCALAR_FIELD(prpsinfo_t,	pr_start,	0);
337 	SCALAR_FIELD(prpsinfo_t,	pr_time,	0);
338 	SCALAR_FIELD(prpsinfo_t,	pr_pri,		1);
339 	SCALAR_FIELD(prpsinfo_t,	pr_oldpri,	0);
340 	SCALAR_FIELD(prpsinfo_t,	pr_cpu,		0);
341 	SCALAR_FIELD(prpsinfo_t,	pr_ottydev,	0);
342 	SCALAR_FIELD(prpsinfo_t,	pr_lttydev,	0);
343 	ARRAY_FIELD(prpsinfo_t,		pr_clname,	0);
344 	ARRAY_FIELD(prpsinfo_t,		pr_fname,	0);
345 	ARRAY_FIELD(prpsinfo_t,		pr_psargs,	0);
346 	SCALAR_FIELD(prpsinfo_t,	pr_syscall,	1);
347 	SCALAR_FIELD(prpsinfo_t,	pr_ctime,	0);
348 	SCALAR_FIELD(prpsinfo_t,	pr_bysize,	0);
349 	SCALAR_FIELD(prpsinfo_t,	pr_byrssize,	0);
350 	SCALAR_FIELD(prpsinfo_t,	pr_argc,	1);
351 	SCALAR_FIELD(prpsinfo_t,	pr_argv,	0);
352 	SCALAR_FIELD(prpsinfo_t,	pr_envp,	0);
353 	SCALAR_FIELD(prpsinfo_t,	pr_wstat,	1);
354 	SCALAR_FIELD(prpsinfo_t,	pr_pctcpu,	0);
355 	SCALAR_FIELD(prpsinfo_t,	pr_pctmem,	0);
356 	SCALAR_FIELD(prpsinfo_t,	pr_euid,	0);
357 	SCALAR_FIELD(prpsinfo_t,	pr_egid,	0);
358 	SCALAR_FIELD(prpsinfo_t,	pr_aslwpid,	0);
359 	SCALAR_FIELD(prpsinfo_t,	pr_dmodel,	0);
360 
361 	END;
362 }
363 
364 /* lwpsinfo_t, <sys/procfs.h> */
365 static void
366 gen_lwpsinfo(void)
367 {
368 	START(lwpsinfo, lwpsinfo_t);
369 
370 	SCALAR_FIELD(lwpsinfo_t,	pr_flag,	1);
371 	SCALAR_FIELD(lwpsinfo_t,	pr_lwpid,	0);
372 	SCALAR_FIELD(lwpsinfo_t,	pr_addr,	0);
373 	SCALAR_FIELD(lwpsinfo_t,	pr_wchan,	0);
374 	SCALAR_FIELD(lwpsinfo_t,	pr_stype,	0);
375 	SCALAR_FIELD(lwpsinfo_t,	pr_state,	0);
376 	SCALAR_FIELD(lwpsinfo_t,	pr_sname,	0);
377 	SCALAR_FIELD(lwpsinfo_t,	pr_nice,	0);
378 	SCALAR_FIELD(lwpsinfo_t,	pr_syscall,	0);
379 	SCALAR_FIELD(lwpsinfo_t,	pr_oldpri,	0);
380 	SCALAR_FIELD(lwpsinfo_t,	pr_cpu,		0);
381 	SCALAR_FIELD(lwpsinfo_t,	pr_pri,		1);
382 	SCALAR_FIELD(lwpsinfo_t,	pr_pctcpu,	0);
383 	SCALAR_FIELD(lwpsinfo_t,	pr_start,	0);
384 	SCALAR_FIELD(lwpsinfo_t,	pr_time,	0);
385 	ARRAY_FIELD(lwpsinfo_t,		pr_clname,	0);
386 	ARRAY_FIELD(lwpsinfo_t,		pr_name,	0);
387 	SCALAR_FIELD(lwpsinfo_t,	pr_onpro,	1);
388 	SCALAR_FIELD(lwpsinfo_t,	pr_bindpro,	1);
389 	SCALAR_FIELD(lwpsinfo_t,	pr_bindpset,	1);
390 	SCALAR_FIELD(lwpsinfo_t,	pr_lgrp,	1);
391 
392 	END;
393 }
394 
395 /* prcred_t, <sys/procfs.h> */
396 static void
397 gen_prcred(void)
398 {
399 	START(prcred, prcred_t);
400 
401 	SCALAR_FIELD(prcred_t,		pr_euid,	0);
402 	SCALAR_FIELD(prcred_t,		pr_ruid,	0);
403 	SCALAR_FIELD(prcred_t,		pr_suid,	0);
404 	SCALAR_FIELD(prcred_t,		pr_egid,	0);
405 	SCALAR_FIELD(prcred_t,		pr_rgid,	0);
406 	SCALAR_FIELD(prcred_t,		pr_sgid,	0);
407 	SCALAR_FIELD(prcred_t,		pr_ngroups,	1);
408 	ARRAY_FIELD(prcred_t,		pr_groups,	0);
409 
410 	END;
411 }
412 
413 /* prpriv_t, <sys/procfs.h> */
414 static void
415 gen_prpriv(void)
416 {
417 	START(prpriv, prpriv_t);
418 
419 	SCALAR_FIELD(prpriv_t,		pr_nsets,	0);
420 	SCALAR_FIELD(prpriv_t,		pr_setsize,	0);
421 	SCALAR_FIELD(prpriv_t,		pr_infosize,	0);
422 	ARRAY_FIELD(prpriv_t,		pr_sets,	0);
423 
424 	END;
425 }
426 
427 
428 /* priv_impl_info_t, <sys/priv.h> */
429 static void
430 gen_priv_impl_info(void)
431 {
432 	START(priv_impl_info, priv_impl_info_t);
433 
434 	SCALAR_FIELD(priv_impl_info_t,	priv_headersize,	0);
435 	SCALAR_FIELD(priv_impl_info_t,	priv_flags,		0);
436 	SCALAR_FIELD(priv_impl_info_t,	priv_nsets,		0);
437 	SCALAR_FIELD(priv_impl_info_t,	priv_setsize,		0);
438 	SCALAR_FIELD(priv_impl_info_t,	priv_max,		0);
439 	SCALAR_FIELD(priv_impl_info_t,	priv_infosize,		0);
440 	SCALAR_FIELD(priv_impl_info_t,	priv_globalinfosize,	0);
441 
442 	END;
443 }
444 
445 
446 /* fltset_t, <sys/fault.h> */
447 static void
448 gen_fltset(void)
449 {
450 	START(fltset, fltset_t);
451 
452 	ARRAY_FIELD(fltset_t,	word,	0);
453 
454 	END;
455 }
456 
457 /* Layout description of siginfo_t, <sys/siginfo.h> */
458 static void
459 gen_siginfo(void)
460 {
461 	START(siginfo, siginfo_t);
462 
463 	SCALAR_FIELD(siginfo_t,		si_signo,		0);
464 	SCALAR_FIELD(siginfo_t,		si_errno,		0);
465 	SCALAR_FIELD(siginfo_t,		si_code,		1);
466 	SCALAR_FIELD(siginfo_t,		si_value.sival_int,	0);
467 	SCALAR_FIELD(siginfo_t,		si_value.sival_ptr,	0);
468 	SCALAR_FIELD(siginfo_t,		si_pid,			0);
469 	SCALAR_FIELD(siginfo_t,		si_uid,			0);
470 	SCALAR_FIELD(siginfo_t,		si_ctid,		0);
471 	SCALAR_FIELD(siginfo_t,		si_zoneid,		0);
472 	SCALAR_FIELD(siginfo_t,		si_entity,		0);
473 	SCALAR_FIELD(siginfo_t,		si_addr,		0);
474 	SCALAR_FIELD(siginfo_t,		si_status,		0);
475 	SCALAR_FIELD(siginfo_t,		si_band,		0);
476 
477 	END;
478 }
479 
480 /* sigset_t, <sys/signal.h> */
481 static void
482 gen_sigset(void)
483 {
484 	START(sigset, sigset_t);
485 
486 	ARRAY_FIELD(sigset_t,	__sigbits,	0);
487 
488 	END;
489 }
490 
491 
492 /* struct sigaction, <sys/signal.h> */
493 static void
494 gen_sigaction(void)
495 {
496 	START(sigaction, struct sigaction);
497 
498 	SCALAR_FIELD(struct sigaction,	sa_flags,	0);
499 	SCALAR_FIELD(struct sigaction,	sa_handler,	0);
500 	SCALAR_FIELD(struct sigaction,	sa_sigaction,	0);
501 	SCALAR_FIELD(struct sigaction,	sa_mask,	0);
502 
503 	END;
504 }
505 
506 /* stack_t, <sys/signal.h> */
507 static void
508 gen_stack(void)
509 {
510 	START(stack, stack_t);
511 
512 	SCALAR_FIELD(stack_t,	ss_sp,		0);
513 	SCALAR_FIELD(stack_t,	ss_size,	0);
514 	SCALAR_FIELD(stack_t,	ss_flags,	0);
515 
516 	END;
517 }
518 
519 /* sysset_t, <sys/syscall.h> */
520 static void
521 gen_sysset(void)
522 {
523 	START(sysset, sysset_t);
524 
525 	ARRAY_FIELD(sysset_t,	word,	0);
526 
527 	END;
528 }
529 
530 /* timestruc_t, <sys/time_impl.h> */
531 static void
532 gen_timestruc(void)
533 {
534 	START(timestruc, timestruc_t);
535 
536 	SCALAR_FIELD(timestruc_t,	tv_sec,		0);
537 	SCALAR_FIELD(timestruc_t,	tv_nsec,	0);
538 
539 	END;
540 }
541 
542 /* struct utsname, <sys/utsname.h> */
543 static void
544 gen_utsname(void)
545 {
546 	START(utsname, struct utsname);
547 
548 	ARRAY_FIELD(struct utsname,	sysname,	0);
549 	ARRAY_FIELD(struct utsname,	nodename,	0);
550 	ARRAY_FIELD(struct utsname,	release,	0);
551 	ARRAY_FIELD(struct utsname,	version,	0);
552 	ARRAY_FIELD(struct utsname,	machine,	0);
553 
554 	END;
555 }
556 
557 static void
558 gen_prfdinfo(void)
559 {
560 	START(prfdinfo, prfdinfo_t);
561 
562 	SCALAR_FIELD(prfdinfo_t,	pr_fd,		0);
563 	SCALAR_FIELD(prfdinfo_t,	pr_mode,	0);
564 	SCALAR_FIELD(prfdinfo_t,	pr_uid,		0);
565 	SCALAR_FIELD(prfdinfo_t,	pr_gid,		0);
566 	SCALAR_FIELD(prfdinfo_t,	pr_major,	0);
567 	SCALAR_FIELD(prfdinfo_t,	pr_minor,	0);
568 	SCALAR_FIELD(prfdinfo_t,	pr_rmajor,	0);
569 	SCALAR_FIELD(prfdinfo_t,	pr_rminor,	0);
570 	SCALAR_FIELD(prfdinfo_t,	pr_ino,		0);
571 	SCALAR_FIELD(prfdinfo_t,	pr_offset,	0);
572 	SCALAR_FIELD(prfdinfo_t,	pr_size,	0);
573 	SCALAR_FIELD(prfdinfo_t,	pr_fileflags,	0);
574 	SCALAR_FIELD(prfdinfo_t,	pr_fdflags,	0);
575 	ARRAY_FIELD(prfdinfo_t,		pr_path,	0);
576 
577 	END;
578 }
579 
580 
581 /*ARGSUSED*/
582 int
583 main(int argc, char *argv[])
584 {
585 	const char *fmt = "\t&%s_layout,\n";
586 
587 	printf("#include <struct_layout.h>\n");
588 
589 	gen_auxv();
590 	gen_prgregset();
591 	gen_lwpstatus();
592 	gen_pstatus();
593 	gen_prstatus();
594 	gen_psinfo();
595 	gen_prpsinfo();
596 	gen_lwpsinfo();
597 	gen_prcred();
598 	gen_prpriv();
599 	gen_priv_impl_info();
600 	gen_fltset();
601 	gen_siginfo();
602 	gen_sigset();
603 	gen_sigaction();
604 	gen_stack();
605 	gen_sysset();
606 	gen_timestruc();
607 	gen_utsname();
608 	gen_prfdinfo();
609 
610 
611 	/*
612 	 * Generate the full arch_layout description
613 	 */
614 	(void) printf(
615 	    "\n\n\n\nstatic const sl_arch_layout_t layout_%s = {\n",
616 	    MACH);
617 	(void) printf(fmt, "auxv");
618 	(void) printf(fmt, "fltset");
619 	(void) printf(fmt, "lwpsinfo");
620 	(void) printf(fmt, "lwpstatus");
621 	(void) printf(fmt, "prcred");
622 	(void) printf(fmt, "priv_impl_info");
623 	(void) printf(fmt, "prpriv");
624 	(void) printf(fmt, "psinfo");
625 	(void) printf(fmt, "pstatus");
626 	(void) printf(fmt, "prgregset");
627 	(void) printf(fmt, "prpsinfo");
628 	(void) printf(fmt, "prstatus");
629 	(void) printf(fmt, "sigaction");
630 	(void) printf(fmt, "siginfo");
631 	(void) printf(fmt, "sigset");
632 	(void) printf(fmt, "stack");
633 	(void) printf(fmt, "sysset");
634 	(void) printf(fmt, "timestruc");
635 	(void) printf(fmt, "utsname");
636 	(void) printf(fmt, "prfdinfo");
637 	(void) printf("};\n");
638 
639 	/*
640 	 * A public function, to make the information available
641 	 */
642 	(void) printf("\n\nconst sl_arch_layout_t *\n");
643 	(void) printf("struct_layout_%s(void)\n", MACH);
644 	(void) printf("{\n\treturn (&layout_%s);\n}\n", MACH);
645 
646 	return (0);
647 }
648