1c6c9aed4Sab /*
2c6c9aed4Sab  * CDDL HEADER START
3c6c9aed4Sab  *
4c6c9aed4Sab  * The contents of this file are subject to the terms of the
5c6c9aed4Sab  * Common Development and Distribution License (the "License").
6c6c9aed4Sab  * You may not use this file except in compliance with the License.
7c6c9aed4Sab  *
8c6c9aed4Sab  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c6c9aed4Sab  * or http://www.opensolaris.org/os/licensing.
10c6c9aed4Sab  * See the License for the specific language governing permissions
11c6c9aed4Sab  * and limitations under the License.
12c6c9aed4Sab  *
13c6c9aed4Sab  * When distributing Covered Code, include this CDDL HEADER in each
14c6c9aed4Sab  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c6c9aed4Sab  * If applicable, add the following below this CDDL HEADER, with the
16c6c9aed4Sab  * fields enclosed by brackets "[]" replaced with your own identifying
17c6c9aed4Sab  * information: Portions Copyright [yyyy] [name of copyright owner]
18c6c9aed4Sab  *
19c6c9aed4Sab  * CDDL HEADER END
20c6c9aed4Sab  */
21c6c9aed4Sab 
22c6c9aed4Sab /*
234f680cc6SAli Bahrami  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24c6c9aed4Sab  * Use is subject to license terms.
25c6c9aed4Sab  */
26c6c9aed4Sab 
2734bdffbfSGarrett D'Amore /*
2834bdffbfSGarrett D'Amore  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
29ab618543SJohn Levon  * Copyright 2018 Joyent, Inc.
30a02120c4SAndy Fiddaman  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
3134bdffbfSGarrett D'Amore  */
3234bdffbfSGarrett D'Amore 
33c6c9aed4Sab #ifndef	_STRUCT_LAYOUT_H
34c6c9aed4Sab #define	_STRUCT_LAYOUT_H
35c6c9aed4Sab 
36c6c9aed4Sab #include	<conv.h>
37c6c9aed4Sab #include	<_machelf.h>
38c6c9aed4Sab 
39c6c9aed4Sab /*
40c6c9aed4Sab  * Local include file for elfdump, used to define structure layout
41c6c9aed4Sab  * definitions for various system structs.
42c6c9aed4Sab  */
43c6c9aed4Sab 
44c6c9aed4Sab #ifdef	__cplusplus
45c6c9aed4Sab extern "C" {
46c6c9aed4Sab #endif
47c6c9aed4Sab 
48c6c9aed4Sab 
49c6c9aed4Sab /*
50c6c9aed4Sab  * Solaris defines system structs that elfdump needs to display
51c6c9aed4Sab  * data from. We have a variety of hurdles to overcome in doing this:
52c6c9aed4Sab  *
53c6c9aed4Sab  *	- The size of system types can differ between ELFCLASS32 and
54c6c9aed4Sab  *		ELFCLASS64.
55c6c9aed4Sab  *	- Stucture layout can differ between architectures, so a given
56c6c9aed4Sab  *		field can have a different struct offset than is native
57c6c9aed4Sab  *		for the system running elfdump. Depending on the struct
58c6c9aed4Sab  *		in question, the layout for one platform may be impossible
59c6c9aed4Sab  *		to achieve on another.
60c6c9aed4Sab  *	- The byte order of the core object can differ from that
61c6c9aed4Sab  *		of the system running elfdump.
62c6c9aed4Sab  *
63c6c9aed4Sab  * The result is that in the fully general case, each architecture
64c6c9aed4Sab  * can have a slightly different definition of these structures.
65c6c9aed4Sab  * The usual approach of assigning a pointer of the desired structure
66c6c9aed4Sab  * type and then accessing fields through that pointer cannot be used
67c6c9aed4Sab  * here. That approach can only be used to access structures with the
68c6c9aed4Sab  * native layout of the elfdump host. We want any instance of elfdump
69c6c9aed4Sab  * to be able to examine a Solaris object for any supported architecture,
70c6c9aed4Sab  * so we need a more flexible approach.
71c6c9aed4Sab  *
72c6c9aed4Sab  * The solution to this problem lies in the fact that the binary
73c6c9aed4Sab  * layout of these public types cannot be changed, except in backward
74c6c9aed4Sab  * compatible ways. They are written to core files or published in
75c6c9aed4Sab  * other ways such that we can't make changes that would make it
76c6c9aed4Sab  * impossible to analyze old files. This means that we can build
77c6c9aed4Sab  * table of offsets and sizes for each field of each struct, on
78c6c9aed4Sab  * a per-archecture basis. These tables can be used to access the
79c6c9aed4Sab  * struct fields directly from the note desc data, and elfdump
80c6c9aed4Sab  * on any host can read the data from any other host.
81c6c9aed4Sab  *
82c6c9aed4Sab  * When reading these tables, it can be very helpful to examine
83c6c9aed4Sab  * the struct definition at the same time.
84c6c9aed4Sab  */
85c6c9aed4Sab 
86c6c9aed4Sab /*
87c6c9aed4Sab  * sl_field_t is used to describe a struct field
88c6c9aed4Sab  */
89c6c9aed4Sab typedef struct {
90c6c9aed4Sab 	ushort_t	slf_offset;	/* Offset from start of struct */
91c6c9aed4Sab 	ushort_t	slf_eltlen;	/* Size of datum, in bytes */
92c6c9aed4Sab 	ushort_t	slf_nelts;	/* 0 for scalar, # of els for array */
93c6c9aed4Sab 	uchar_t		slf_sign;	/* True (1) if signed quantity */
94c6c9aed4Sab } sl_field_t;
95c6c9aed4Sab 
96c6c9aed4Sab /*
9734bdffbfSGarrett D'Amore  * This type is used to extract and manipulate data described by
98c6c9aed4Sab  * sl_field_t. We rely on the C guarantee that all the fields in
99c6c9aed4Sab  * a union have offset 0.
100c6c9aed4Sab  */
101c6c9aed4Sab typedef union {
102c6c9aed4Sab 	char		sld_i8;
103ab618543SJohn Levon 	uchar_t		sld_ui8;
104c6c9aed4Sab 	short		sld_i16;
105c6c9aed4Sab 	ushort_t	sld_ui16;
106c6c9aed4Sab 	int32_t		sld_i32;
107c6c9aed4Sab 	uint32_t	sld_ui32;
108c6c9aed4Sab 	int64_t		sld_i64;
109c6c9aed4Sab 	uint64_t	sld_ui64;
110c6c9aed4Sab } sl_data_t;
111c6c9aed4Sab 
112c6c9aed4Sab /*
113c6c9aed4Sab  * Buffer large enough to format any integral value in a field
114c6c9aed4Sab  */
1154f680cc6SAli Bahrami typedef char sl_fmtbuf_t[CONV_INV_BUFSIZE * 2];
116c6c9aed4Sab 
117c6c9aed4Sab /*
118c6c9aed4Sab  * Types of formatting done by fmt_num()
119c6c9aed4Sab  */
120c6c9aed4Sab typedef enum {
121c6c9aed4Sab 	SL_FMT_NUM_DEC = 0,	/* Decimal integer */
122c6c9aed4Sab 	SL_FMT_NUM_HEX = 1,	/* Hex integer, with natural width */
123c6c9aed4Sab 	SL_FMT_NUM_ZHEX = 2,	/* Hex integer, fixed width with zero fill  */
124c6c9aed4Sab } sl_fmt_num_t;
125c6c9aed4Sab 
126c6c9aed4Sab 
127c6c9aed4Sab 
128c6c9aed4Sab 
129c6c9aed4Sab /*
130c6c9aed4Sab  * Layout description of auxv_t, from <sys/auxv.h>.
131c6c9aed4Sab  */
132c6c9aed4Sab typedef struct {
133c6c9aed4Sab 	sl_field_t		sizeof_struct;
134c6c9aed4Sab 	sl_field_t		a_type;
135c6c9aed4Sab 	sl_field_t		a_val;
136c6c9aed4Sab 	sl_field_t		a_ptr;
137c6c9aed4Sab 	sl_field_t		a_fcn;
138c6c9aed4Sab } sl_auxv_layout_t;
139c6c9aed4Sab 
140c6c9aed4Sab /*
141c6c9aed4Sab  * Layout description of prgregset_t, an architecture specific
142c6c9aed4Sab  * array of general register c values
143c6c9aed4Sab  */
144c6c9aed4Sab typedef struct {
145c6c9aed4Sab 	sl_field_t		sizeof_struct;
146c6c9aed4Sab 	sl_field_t		elt0;
147c6c9aed4Sab } sl_prgregset_layout_t;
148c6c9aed4Sab 
149c6c9aed4Sab /*
150c6c9aed4Sab  * Layout description of lwpstatus_t, from <sys/procfs.h>.
151c6c9aed4Sab  */
152c6c9aed4Sab typedef struct {
153c6c9aed4Sab 	sl_field_t		sizeof_struct;
154c6c9aed4Sab 	sl_field_t		pr_flags;
155c6c9aed4Sab 	sl_field_t		pr_lwpid;
156c6c9aed4Sab 	sl_field_t		pr_why;
157c6c9aed4Sab 	sl_field_t		pr_what;
158c6c9aed4Sab 	sl_field_t		pr_cursig;
159c6c9aed4Sab 	sl_field_t		pr_info;
160c6c9aed4Sab 	sl_field_t		pr_lwppend;
161c6c9aed4Sab 	sl_field_t		pr_lwphold;
162c6c9aed4Sab 	sl_field_t		pr_action;
163c6c9aed4Sab 	sl_field_t		pr_altstack;
164c6c9aed4Sab 	sl_field_t		pr_oldcontext;
165c6c9aed4Sab 	sl_field_t		pr_syscall;
166c6c9aed4Sab 	sl_field_t		pr_nsysarg;
167c6c9aed4Sab 	sl_field_t		pr_errno;
168c6c9aed4Sab 	sl_field_t		pr_sysarg;
169c6c9aed4Sab 	sl_field_t		pr_rval1;
170c6c9aed4Sab 	sl_field_t		pr_rval2;
171c6c9aed4Sab 	sl_field_t		pr_clname;
172c6c9aed4Sab 	sl_field_t		pr_tstamp;
173c6c9aed4Sab 	sl_field_t		pr_utime;
174c6c9aed4Sab 	sl_field_t		pr_stime;
175c6c9aed4Sab 	sl_field_t		pr_errpriv;
176c6c9aed4Sab 	sl_field_t		pr_ustack;
177c6c9aed4Sab 	sl_field_t		pr_instr;
178c6c9aed4Sab 	sl_field_t		pr_reg;
179c6c9aed4Sab 	sl_field_t		pr_fpreg;
180c6c9aed4Sab } sl_lwpstatus_layout_t;
181c6c9aed4Sab 
182c6c9aed4Sab /*
183c6c9aed4Sab  * Layout description of pstatus_t, from <sys/procfs.h>.
184c6c9aed4Sab  */
185c6c9aed4Sab typedef struct {
186c6c9aed4Sab 	sl_field_t		sizeof_struct;
187c6c9aed4Sab 	sl_field_t		pr_flags;
188c6c9aed4Sab 	sl_field_t		pr_nlwp;
189c6c9aed4Sab 	sl_field_t		pr_pid;
190c6c9aed4Sab 	sl_field_t		pr_ppid;
191c6c9aed4Sab 	sl_field_t		pr_pgid;
192c6c9aed4Sab 	sl_field_t		pr_sid;
193c6c9aed4Sab 	sl_field_t		pr_aslwpid;
194c6c9aed4Sab 	sl_field_t		pr_agentid;
195c6c9aed4Sab 	sl_field_t		pr_sigpend;
196c6c9aed4Sab 	sl_field_t		pr_brkbase;
197c6c9aed4Sab 	sl_field_t		pr_brksize;
198c6c9aed4Sab 	sl_field_t		pr_stkbase;
199c6c9aed4Sab 	sl_field_t		pr_stksize;
200c6c9aed4Sab 	sl_field_t		pr_utime;
201c6c9aed4Sab 	sl_field_t		pr_stime;
202c6c9aed4Sab 	sl_field_t		pr_cutime;
203c6c9aed4Sab 	sl_field_t		pr_cstime;
204c6c9aed4Sab 	sl_field_t		pr_sigtrace;
205c6c9aed4Sab 	sl_field_t		pr_flttrace;
206c6c9aed4Sab 	sl_field_t		pr_sysentry;
207c6c9aed4Sab 	sl_field_t		pr_sysexit;
208c6c9aed4Sab 	sl_field_t		pr_dmodel;
209c6c9aed4Sab 	sl_field_t		pr_taskid;
210c6c9aed4Sab 	sl_field_t		pr_projid;
211c6c9aed4Sab 	sl_field_t		pr_nzomb;
212c6c9aed4Sab 	sl_field_t		pr_zoneid;
213c6c9aed4Sab 	sl_field_t		pr_lwp;
214c6c9aed4Sab } sl_pstatus_layout_t;
215c6c9aed4Sab 
216c6c9aed4Sab /*
217c6c9aed4Sab  * Layout description of prstatus_t, from <sys/old_procfs.h>.
218c6c9aed4Sab  */
219c6c9aed4Sab typedef struct {
220c6c9aed4Sab 	sl_field_t		sizeof_struct;
221c6c9aed4Sab 	sl_field_t		pr_flags;
222c6c9aed4Sab 	sl_field_t		pr_why;
223c6c9aed4Sab 	sl_field_t		pr_what;
224c6c9aed4Sab 	sl_field_t		pr_info;
225c6c9aed4Sab 	sl_field_t		pr_cursig;
226c6c9aed4Sab 	sl_field_t		pr_nlwp;
227c6c9aed4Sab 	sl_field_t		pr_sigpend;
228c6c9aed4Sab 	sl_field_t		pr_sighold;
229c6c9aed4Sab 	sl_field_t		pr_altstack;
230c6c9aed4Sab 	sl_field_t		pr_action;
231c6c9aed4Sab 	sl_field_t		pr_pid;
232c6c9aed4Sab 	sl_field_t		pr_ppid;
233c6c9aed4Sab 	sl_field_t		pr_pgrp;
234c6c9aed4Sab 	sl_field_t		pr_sid;
235c6c9aed4Sab 	sl_field_t		pr_utime;
236c6c9aed4Sab 	sl_field_t		pr_stime;
237c6c9aed4Sab 	sl_field_t		pr_cutime;
238c6c9aed4Sab 	sl_field_t		pr_cstime;
239c6c9aed4Sab 	sl_field_t		pr_clname;
240c6c9aed4Sab 	sl_field_t		pr_syscall;
241c6c9aed4Sab 	sl_field_t		pr_nsysarg;
242c6c9aed4Sab 	sl_field_t		pr_sysarg;
243c6c9aed4Sab 	sl_field_t		pr_who;
244c6c9aed4Sab 	sl_field_t		pr_lwppend;
245c6c9aed4Sab 	sl_field_t		pr_oldcontext;
246c6c9aed4Sab 	sl_field_t		pr_brkbase;
247c6c9aed4Sab 	sl_field_t		pr_brksize;
248c6c9aed4Sab 	sl_field_t		pr_stkbase;
249c6c9aed4Sab 	sl_field_t		pr_stksize;
250c6c9aed4Sab 	sl_field_t		pr_processor;
251c6c9aed4Sab 	sl_field_t		pr_bind;
252c6c9aed4Sab 	sl_field_t		pr_instr;
253c6c9aed4Sab 	sl_field_t		pr_reg;
254c6c9aed4Sab } sl_prstatus_layout_t;
255c6c9aed4Sab 
256c6c9aed4Sab /*
257c6c9aed4Sab  * Layout description of psinfo_t, from <sys/procfs.h>.
258c6c9aed4Sab  */
259c6c9aed4Sab typedef struct {
260c6c9aed4Sab 	sl_field_t		sizeof_struct;
261c6c9aed4Sab 	sl_field_t		pr_flag;
262c6c9aed4Sab 	sl_field_t		pr_nlwp;
263c6c9aed4Sab 	sl_field_t		pr_pid;
264c6c9aed4Sab 	sl_field_t		pr_ppid;
265c6c9aed4Sab 	sl_field_t		pr_pgid;
266c6c9aed4Sab 	sl_field_t		pr_sid;
267c6c9aed4Sab 	sl_field_t		pr_uid;
268c6c9aed4Sab 	sl_field_t		pr_euid;
269c6c9aed4Sab 	sl_field_t		pr_gid;
270c6c9aed4Sab 	sl_field_t		pr_egid;
271c6c9aed4Sab 	sl_field_t		pr_addr;
272c6c9aed4Sab 	sl_field_t		pr_size;
273c6c9aed4Sab 	sl_field_t		pr_rssize;
274c6c9aed4Sab 	sl_field_t		pr_ttydev;
275c6c9aed4Sab 	sl_field_t		pr_pctcpu;
276c6c9aed4Sab 	sl_field_t		pr_pctmem;
277c6c9aed4Sab 	sl_field_t		pr_start;
278c6c9aed4Sab 	sl_field_t		pr_time;
279c6c9aed4Sab 	sl_field_t		pr_ctime;
280c6c9aed4Sab 	sl_field_t		pr_fname;
281c6c9aed4Sab 	sl_field_t		pr_psargs;
282c6c9aed4Sab 	sl_field_t		pr_wstat;
283c6c9aed4Sab 	sl_field_t		pr_argc;
284c6c9aed4Sab 	sl_field_t		pr_argv;
285c6c9aed4Sab 	sl_field_t		pr_envp;
286c6c9aed4Sab 	sl_field_t		pr_dmodel;
287c6c9aed4Sab 	sl_field_t		pr_taskid;
288c6c9aed4Sab 	sl_field_t		pr_projid;
289c6c9aed4Sab 	sl_field_t		pr_nzomb;
290c6c9aed4Sab 	sl_field_t		pr_poolid;
291c6c9aed4Sab 	sl_field_t		pr_zoneid;
292c6c9aed4Sab 	sl_field_t		pr_contract;
293c6c9aed4Sab 	sl_field_t		pr_lwp;
294c6c9aed4Sab } sl_psinfo_layout_t;
295c6c9aed4Sab 
296c6c9aed4Sab /*
297c6c9aed4Sab  * Layout description of prpsinfo_t, from <sys/old_procfs.h>.
298c6c9aed4Sab  */
299c6c9aed4Sab typedef struct {
300c6c9aed4Sab 	sl_field_t		sizeof_struct;
301c6c9aed4Sab 	sl_field_t		pr_state;
302c6c9aed4Sab 	sl_field_t		pr_sname;
303c6c9aed4Sab 	sl_field_t		pr_zomb;
304c6c9aed4Sab 	sl_field_t		pr_nice;
305c6c9aed4Sab 	sl_field_t		pr_flag;
306c6c9aed4Sab 	sl_field_t		pr_uid;
307c6c9aed4Sab 	sl_field_t		pr_gid;
308c6c9aed4Sab 	sl_field_t		pr_pid;
309c6c9aed4Sab 	sl_field_t		pr_ppid;
310c6c9aed4Sab 	sl_field_t		pr_pgrp;
311c6c9aed4Sab 	sl_field_t		pr_sid;
312c6c9aed4Sab 	sl_field_t		pr_addr;
313c6c9aed4Sab 	sl_field_t		pr_size;
314c6c9aed4Sab 	sl_field_t		pr_rssize;
315c6c9aed4Sab 	sl_field_t		pr_wchan;
316c6c9aed4Sab 	sl_field_t		pr_start;
317c6c9aed4Sab 	sl_field_t		pr_time;
318c6c9aed4Sab 	sl_field_t		pr_pri;
319c6c9aed4Sab 	sl_field_t		pr_oldpri;
320c6c9aed4Sab 	sl_field_t		pr_cpu;
321c6c9aed4Sab 	sl_field_t		pr_ottydev;
322c6c9aed4Sab 	sl_field_t		pr_lttydev;
323c6c9aed4Sab 	sl_field_t		pr_clname;
324c6c9aed4Sab 	sl_field_t		pr_fname;
325c6c9aed4Sab 	sl_field_t		pr_psargs;
326c6c9aed4Sab 	sl_field_t		pr_syscall;
327c6c9aed4Sab 	sl_field_t		pr_ctime;
328c6c9aed4Sab 	sl_field_t		pr_bysize;
329c6c9aed4Sab 	sl_field_t		pr_byrssize;
330c6c9aed4Sab 	sl_field_t		pr_argc;
331c6c9aed4Sab 	sl_field_t		pr_argv;
332c6c9aed4Sab 	sl_field_t		pr_envp;
333c6c9aed4Sab 	sl_field_t		pr_wstat;
334c6c9aed4Sab 	sl_field_t		pr_pctcpu;
335c6c9aed4Sab 	sl_field_t		pr_pctmem;
336c6c9aed4Sab 	sl_field_t		pr_euid;
337c6c9aed4Sab 	sl_field_t		pr_egid;
338c6c9aed4Sab 	sl_field_t		pr_aslwpid;
339c6c9aed4Sab 	sl_field_t		pr_dmodel;
340c6c9aed4Sab } sl_prpsinfo_layout_t;
341c6c9aed4Sab 
342c6c9aed4Sab /*
343c6c9aed4Sab  * Layout description of lwpsinfo_t, from <sys/procfs.h>.
344c6c9aed4Sab  */
345c6c9aed4Sab typedef struct {
346c6c9aed4Sab 	sl_field_t		sizeof_struct;
347c6c9aed4Sab 	sl_field_t		pr_flag;
348c6c9aed4Sab 	sl_field_t		pr_lwpid;
349c6c9aed4Sab 	sl_field_t		pr_addr;
350c6c9aed4Sab 	sl_field_t		pr_wchan;
351c6c9aed4Sab 	sl_field_t		pr_stype;
352c6c9aed4Sab 	sl_field_t		pr_state;
353c6c9aed4Sab 	sl_field_t		pr_sname;
354c6c9aed4Sab 	sl_field_t		pr_nice;
355c6c9aed4Sab 	sl_field_t		pr_syscall;
356c6c9aed4Sab 	sl_field_t		pr_oldpri;
357c6c9aed4Sab 	sl_field_t		pr_cpu;
358c6c9aed4Sab 	sl_field_t		pr_pri;
359c6c9aed4Sab 	sl_field_t		pr_pctcpu;
360c6c9aed4Sab 	sl_field_t		pr_start;
361c6c9aed4Sab 	sl_field_t		pr_time;
362c6c9aed4Sab 	sl_field_t		pr_clname;
363c6c9aed4Sab 	sl_field_t		pr_name;
364c6c9aed4Sab 	sl_field_t		pr_onpro;
365c6c9aed4Sab 	sl_field_t		pr_bindpro;
366c6c9aed4Sab 	sl_field_t		pr_bindpset;
367c6c9aed4Sab 	sl_field_t		pr_lgrp;
368c6c9aed4Sab } sl_lwpsinfo_layout_t;
369c6c9aed4Sab 
370c6c9aed4Sab /*
371c6c9aed4Sab  * Layout description of prcred_t, from <sys/procfs.h>.
372c6c9aed4Sab  */
373c6c9aed4Sab typedef struct {
374c6c9aed4Sab 	sl_field_t		sizeof_struct;
375c6c9aed4Sab 	sl_field_t		pr_euid;
376c6c9aed4Sab 	sl_field_t		pr_ruid;
377c6c9aed4Sab 	sl_field_t		pr_suid;
378c6c9aed4Sab 	sl_field_t		pr_egid;
379c6c9aed4Sab 	sl_field_t		pr_rgid;
380c6c9aed4Sab 	sl_field_t		pr_sgid;
381c6c9aed4Sab 	sl_field_t		pr_ngroups;
382c6c9aed4Sab 	sl_field_t		pr_groups;
383c6c9aed4Sab } sl_prcred_layout_t;
384c6c9aed4Sab 
385c6c9aed4Sab /*
386c6c9aed4Sab  * Layout description of prpriv_t, from <sys/procfs.h>.
387c6c9aed4Sab  */
388c6c9aed4Sab typedef struct {
389c6c9aed4Sab 	sl_field_t		sizeof_struct;
390c6c9aed4Sab 	sl_field_t		pr_nsets;
391c6c9aed4Sab 	sl_field_t		pr_setsize;
392c6c9aed4Sab 	sl_field_t		pr_infosize;
393c6c9aed4Sab 	sl_field_t		pr_sets;
394c6c9aed4Sab } sl_prpriv_layout_t;
395c6c9aed4Sab 
396c6c9aed4Sab /*
397c6c9aed4Sab  * Layout description of priv_impl_info_t, from <sys/priv.h>.
398c6c9aed4Sab  */
399c6c9aed4Sab typedef struct {
400c6c9aed4Sab 	sl_field_t		sizeof_struct;
401c6c9aed4Sab 	sl_field_t		priv_headersize;
402c6c9aed4Sab 	sl_field_t		priv_flags;
403c6c9aed4Sab 	sl_field_t		priv_nsets;
404c6c9aed4Sab 	sl_field_t		priv_setsize;
405c6c9aed4Sab 	sl_field_t		priv_max;
406c6c9aed4Sab 	sl_field_t		priv_infosize;
407c6c9aed4Sab 	sl_field_t		priv_globalinfosize;
408c6c9aed4Sab } sl_priv_impl_info_layout_t;
409c6c9aed4Sab 
410c6c9aed4Sab /*
411c6c9aed4Sab  * Layout description of fltset_t, from <sys/fault.h>.
412c6c9aed4Sab  */
413c6c9aed4Sab typedef struct {
414c6c9aed4Sab 	sl_field_t		sizeof_struct;
415c6c9aed4Sab 	sl_field_t		word;
416c6c9aed4Sab } sl_fltset_layout_t;
417c6c9aed4Sab 
418c6c9aed4Sab /*
419c6c9aed4Sab  * Layout description of siginfo_t, from <sys/siginfo.h>.
420c6c9aed4Sab  *
421c6c9aed4Sab  * siginfo_t is unusual, in that it contains a large union
422c6c9aed4Sab  * full of private fields. There are macros defined to give
423c6c9aed4Sab  * access to these fields via the names documented in the
424c6c9aed4Sab  * siginfo manpage. We stick to the documented names
425c6c9aed4Sab  * rather than try to unravel the undocumented blob. Hence,
426c6c9aed4Sab  * the layout description below is a "logical" view of siginfo_t.
427c6c9aed4Sab  * The fields below are not necessarily in the same order as
428c6c9aed4Sab  * they appear in siginfo_t, nor are they everything that is in
429c6c9aed4Sab  * that struct. They may also overlap each other, if they are
430c6c9aed4Sab  * contained within of the union.
431c6c9aed4Sab  *
432c6c9aed4Sab  * The f_ prefixes are used to prevent our field names from
433c6c9aed4Sab  * clashing with the macros defined in siginfo.h.
434c6c9aed4Sab  */
435c6c9aed4Sab typedef struct {
436c6c9aed4Sab 	sl_field_t		sizeof_struct;
437c6c9aed4Sab 	sl_field_t		f_si_signo;
438c6c9aed4Sab 	sl_field_t		f_si_errno;
439c6c9aed4Sab 	sl_field_t		f_si_code;
440c6c9aed4Sab 	sl_field_t		f_si_value_int;
441c6c9aed4Sab 	sl_field_t		f_si_value_ptr;
442c6c9aed4Sab 	sl_field_t		f_si_pid;
443c6c9aed4Sab 	sl_field_t		f_si_uid;
444c6c9aed4Sab 	sl_field_t		f_si_ctid;
445c6c9aed4Sab 	sl_field_t		f_si_zoneid;
446c6c9aed4Sab 	sl_field_t		f_si_entity;
447c6c9aed4Sab 	sl_field_t		f_si_addr;
448c6c9aed4Sab 	sl_field_t		f_si_status;
449c6c9aed4Sab 	sl_field_t		f_si_band;
450c6c9aed4Sab } sl_siginfo_layout_t;
451c6c9aed4Sab 
452c6c9aed4Sab /*
453c6c9aed4Sab  * Layout description of sigset_t, from <sys/signal.h>.
454c6c9aed4Sab  */
455c6c9aed4Sab typedef struct {
456c6c9aed4Sab 	sl_field_t		sizeof_struct;
457c6c9aed4Sab 	sl_field_t		sigbits;
458c6c9aed4Sab } sl_sigset_layout_t;
459c6c9aed4Sab 
460c6c9aed4Sab /*
461c6c9aed4Sab  * Layout description of struct sigaction, from <sys/signal.h>.
462c6c9aed4Sab  */
463c6c9aed4Sab typedef struct {
464c6c9aed4Sab 	sl_field_t		sizeof_struct;
465c6c9aed4Sab 	sl_field_t		sa_flags;
466c6c9aed4Sab 	sl_field_t		sa_hand;
467c6c9aed4Sab 	sl_field_t		sa_sigact;
468c6c9aed4Sab 	sl_field_t		sa_mask;
469c6c9aed4Sab } sl_sigaction_layout_t;
470c6c9aed4Sab 
471c6c9aed4Sab /*
472c6c9aed4Sab  * Layout description of stack_t, from <sys/signal.h>.
473c6c9aed4Sab  */
474c6c9aed4Sab typedef struct {
475c6c9aed4Sab 	sl_field_t		sizeof_struct;
476c6c9aed4Sab 	sl_field_t		ss_sp;
477c6c9aed4Sab 	sl_field_t		ss_size;
478c6c9aed4Sab 	sl_field_t		ss_flags;
479c6c9aed4Sab } sl_stack_layout_t;
480c6c9aed4Sab 
481c6c9aed4Sab /*
482c6c9aed4Sab  * Layout description of sysset_t, from <sys/syscall.h>.
483c6c9aed4Sab  */
484c6c9aed4Sab typedef struct {
485c6c9aed4Sab 	sl_field_t		sizeof_struct;
486c6c9aed4Sab 	sl_field_t		word;
487c6c9aed4Sab } sl_sysset_layout_t;
488c6c9aed4Sab 
489c6c9aed4Sab /*
490c6c9aed4Sab  * Layout description of timestruc_t, from <sys/time_impl.h>.
491c6c9aed4Sab  */
492c6c9aed4Sab typedef struct {
493c6c9aed4Sab 	sl_field_t		sizeof_struct;
494c6c9aed4Sab 	sl_field_t		tv_sec;
495c6c9aed4Sab 	sl_field_t		tv_nsec;
496c6c9aed4Sab } sl_timestruc_layout_t;
497c6c9aed4Sab 
498c6c9aed4Sab /*
499c6c9aed4Sab  * Layout description of struct utsname, from <sys/utsname.h>.
500c6c9aed4Sab  */
501c6c9aed4Sab typedef struct {
502c6c9aed4Sab 	sl_field_t		sizeof_struct;
503c6c9aed4Sab 	sl_field_t		sysname;
504c6c9aed4Sab 	sl_field_t		nodename;
505c6c9aed4Sab 	sl_field_t		release;
506c6c9aed4Sab 	sl_field_t		version;
507c6c9aed4Sab 	sl_field_t		machine;
508c6c9aed4Sab } sl_utsname_layout_t;
509c6c9aed4Sab 
51034bdffbfSGarrett D'Amore /*
511a02120c4SAndy Fiddaman  * Layout description of prfdinfo_core_t, from <sys/procfs.h>.
51234bdffbfSGarrett D'Amore  */
51334bdffbfSGarrett D'Amore typedef struct {
51434bdffbfSGarrett D'Amore 	sl_field_t		sizeof_struct;
51534bdffbfSGarrett D'Amore 	sl_field_t		pr_fd;
51634bdffbfSGarrett D'Amore 	sl_field_t		pr_mode;
51734bdffbfSGarrett D'Amore 	sl_field_t		pr_uid;
51834bdffbfSGarrett D'Amore 	sl_field_t		pr_gid;
51934bdffbfSGarrett D'Amore 	sl_field_t		pr_major;
52034bdffbfSGarrett D'Amore 	sl_field_t		pr_minor;
52134bdffbfSGarrett D'Amore 	sl_field_t		pr_rmajor;
52234bdffbfSGarrett D'Amore 	sl_field_t		pr_rminor;
52334bdffbfSGarrett D'Amore 	sl_field_t		pr_ino;
52434bdffbfSGarrett D'Amore 	sl_field_t		pr_offset;
52534bdffbfSGarrett D'Amore 	sl_field_t		pr_size;
52634bdffbfSGarrett D'Amore 	sl_field_t		pr_fileflags;
52734bdffbfSGarrett D'Amore 	sl_field_t		pr_fdflags;
52834bdffbfSGarrett D'Amore 	sl_field_t		pr_path;
52934bdffbfSGarrett D'Amore } sl_prfdinfo_layout_t;
53034bdffbfSGarrett D'Amore 
531d2a70789SRichard Lowe typedef struct {
532d2a70789SRichard Lowe 	sl_field_t		sizeof_struct;
533d2a70789SRichard Lowe 	sl_field_t		pr_version;
534d2a70789SRichard Lowe 	sl_field_t		pr_effective;
535d2a70789SRichard Lowe 	sl_field_t		pr_inherit;
536d2a70789SRichard Lowe 	sl_field_t		pr_lower;
537d2a70789SRichard Lowe 	sl_field_t		pr_upper;
538d2a70789SRichard Lowe } sl_prsecflags_layout_t;
539d2a70789SRichard Lowe 
540ab618543SJohn Levon typedef struct {
541ab618543SJohn Levon 	sl_field_t		sizeof_struct;
542ab618543SJohn Levon 	sl_field_t		pr_lwpid;
543ab618543SJohn Levon 	sl_field_t		pr_lwpname;
544ab618543SJohn Levon } sl_prlwpname_layout_t;
545ab618543SJohn Levon 
546*350ffdd5SRobert Mustacchi typedef struct {
547*350ffdd5SRobert Mustacchi 	sl_field_t		sizeof_struct;
548*350ffdd5SRobert Mustacchi 	sl_field_t		pru_version;
549*350ffdd5SRobert Mustacchi 	sl_field_t		pru_flags;
550*350ffdd5SRobert Mustacchi 	sl_field_t		pru_data;
551*350ffdd5SRobert Mustacchi } sl_prupanic_layout_t;
552*350ffdd5SRobert Mustacchi 
553c6c9aed4Sab /*
554c6c9aed4Sab  * This type collects all of the layout definitions for
555c6c9aed4Sab  * a given architecture.
556c6c9aed4Sab  */
557c6c9aed4Sab typedef struct {
558c6c9aed4Sab 	const sl_auxv_layout_t		*auxv;		/* auxv_t */
559c6c9aed4Sab 	const sl_fltset_layout_t	*fltset;	/* fltset_t */
560c6c9aed4Sab 	const sl_lwpsinfo_layout_t	*lwpsinfo;	/* lwpsinfo_t */
561c6c9aed4Sab 	const sl_lwpstatus_layout_t	*lwpstatus;	/* lwpstatus_t */
562c6c9aed4Sab 	const sl_prcred_layout_t	*prcred;	/* prcred_t */
563c6c9aed4Sab 	const sl_priv_impl_info_layout_t *priv_impl_info; /* priv_impl_info_t */
564c6c9aed4Sab 	const sl_prpriv_layout_t	*prpriv;	/* prpriv_t */
565c6c9aed4Sab 	const sl_psinfo_layout_t	*psinfo;	/* psinfo_t */
566c6c9aed4Sab 	const sl_pstatus_layout_t	*pstatus;	/* pstatus_t */
567c6c9aed4Sab 	const sl_prgregset_layout_t	*prgregset;	/* prgregset_t */
568c6c9aed4Sab 	const sl_prpsinfo_layout_t	*prpsinfo;	/* prpsinfo_t */
569c6c9aed4Sab 	const sl_prstatus_layout_t	*prstatus;	/* prstatus_t */
570c6c9aed4Sab 	const sl_sigaction_layout_t	*sigaction;	/* struct sigaction */
571c6c9aed4Sab 	const sl_siginfo_layout_t	*siginfo;	/* siginfo_t */
572c6c9aed4Sab 	const sl_sigset_layout_t	*sigset;	/* sigset_t */
573c6c9aed4Sab 	const sl_stack_layout_t		*stack;		/* stack_t */
574c6c9aed4Sab 	const sl_sysset_layout_t	*sysset;	/* sysset_t */
575c6c9aed4Sab 	const sl_timestruc_layout_t	*timestruc;	/* timestruc_t */
576c6c9aed4Sab 	const sl_utsname_layout_t	*utsname;	/* struct utsname */
57734bdffbfSGarrett D'Amore 	const sl_prfdinfo_layout_t	*prfdinfo;	/* prdinfo_t */
578d2a70789SRichard Lowe 	const sl_prsecflags_layout_t	*prsecflags;	/* prsecflags_t */
579ab618543SJohn Levon 	const sl_prlwpname_layout_t	*prlwpname;	/* prlwpname_t */
580*350ffdd5SRobert Mustacchi 	const sl_prupanic_layout_t	*prupanic;	/* prupanic_t */
581c6c9aed4Sab } sl_arch_layout_t;
582c6c9aed4Sab 
583c6c9aed4Sab 
584c6c9aed4Sab 
585c6c9aed4Sab extern	void		sl_extract_num_field(const char *data, int do_swap,
586c6c9aed4Sab 			    const sl_field_t *fdesc, sl_data_t *field_data);
587c6c9aed4Sab extern	Word		sl_extract_as_word(const char *data, int do_swap,
588c6c9aed4Sab 			    const sl_field_t *fdesc);
589c6c9aed4Sab extern	Lword		sl_extract_as_lword(const char *data, int do_swap,
590c6c9aed4Sab 			    const sl_field_t *fdesc);
591c6c9aed4Sab extern	Sword		sl_extract_as_sword(const char *data, int do_swap,
592c6c9aed4Sab 			    const sl_field_t *fdesc);
593c6c9aed4Sab extern	const char	*sl_fmt_num(const char *data, int do_swap,
594c6c9aed4Sab 			    const sl_field_t *fdesc, sl_fmt_num_t fmt_type,
595c6c9aed4Sab 			    sl_fmtbuf_t buf);
596c6c9aed4Sab 
597c6c9aed4Sab 
598c6c9aed4Sab extern	const sl_arch_layout_t	*sl_mach(Half);
599c6c9aed4Sab extern	const sl_arch_layout_t	*struct_layout_i386(void);
600c6c9aed4Sab extern	const sl_arch_layout_t	*struct_layout_amd64(void);
601c6c9aed4Sab extern	const sl_arch_layout_t	*struct_layout_sparc(void);
602c6c9aed4Sab extern	const sl_arch_layout_t	*struct_layout_sparcv9(void);
603c6c9aed4Sab 
604c6c9aed4Sab 
605c6c9aed4Sab 
606c6c9aed4Sab #ifdef	__cplusplus
607c6c9aed4Sab }
608c6c9aed4Sab #endif
609c6c9aed4Sab 
610c6c9aed4Sab #endif	/* _STRUCT_LAYOUT_H */
611