1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* String conversion routines for program header attributes.
*/
#include <stdio.h>
#include <string.h>
#include <_conv.h>
#include <phdr_msg.h>
static const conv_ds_t **
conv_phdr_type_strings(Conv_fmt_flags_t fmt_flags)
{
#define ALL ELFOSABI_NONE, EM_NONE
#define SOL ELFOSABI_SOLARIS, EM_NONE
#define LIN ELFOSABI_LINUX, EM_NONE
static const Msg phdrs_def[] = {
MSG_PT_NULL, MSG_PT_LOAD,
MSG_PT_DYNAMIC, MSG_PT_INTERP,
MSG_PT_NOTE, MSG_PT_SHLIB,
MSG_PT_PHDR, MSG_PT_TLS
};
static const Msg phdrs_dmp[] = {
MSG_PT_NULL_CFNP, MSG_PT_LOAD_CFNP,
MSG_PT_DYNAMIC_DMP, MSG_PT_INTERP_CFNP,
MSG_PT_NOTE_CFNP, MSG_PT_SHLIB_CFNP,
MSG_PT_PHDR_CFNP, MSG_PT_TLS_CFNP
};
static const Msg phdrs_cf[] = {
MSG_PT_NULL_CF, MSG_PT_LOAD_CF,
MSG_PT_DYNAMIC_CF, MSG_PT_INTERP_CF,
MSG_PT_NOTE_CF, MSG_PT_SHLIB_CF,
MSG_PT_PHDR_CF, MSG_PT_TLS_CF
};
static const Msg phdrs_cfnp[] = {
MSG_PT_NULL_CFNP, MSG_PT_LOAD_CFNP,
MSG_PT_DYNAMIC_CFNP, MSG_PT_INTERP_CFNP,
MSG_PT_NOTE_CFNP, MSG_PT_SHLIB_CFNP,
MSG_PT_PHDR_CFNP, MSG_PT_TLS_CFNP
};
static const Msg phdrs_nf[] = {
MSG_PT_NULL_NF, MSG_PT_LOAD_NF,
MSG_PT_DYNAMIC_NF, MSG_PT_INTERP_NF,
MSG_PT_NOTE_NF, MSG_PT_SHLIB_NF,
MSG_PT_PHDR_NF, MSG_PT_TLS_NF
};
#if PT_NUM != (PT_TLS + 1)
error "PT_NUM has grown. Update phdrs[]"
#endif
static const conv_ds_msg_t ds_phdrs_def = {
CONV_DS_MSG_INIT(PT_NULL, phdrs_def) };
static const conv_ds_msg_t ds_phdrs_dmp = {
CONV_DS_MSG_INIT(PT_NULL, phdrs_dmp) };
static const conv_ds_msg_t ds_phdrs_cf = {
CONV_DS_MSG_INIT(PT_NULL, phdrs_cf) };
static const conv_ds_msg_t ds_phdrs_cfnp = {
CONV_DS_MSG_INIT(PT_NULL, phdrs_cfnp) };
static const conv_ds_msg_t ds_phdrs_nf = {
CONV_DS_MSG_INIT(PT_NULL, phdrs_nf) };
static const Val_desc2 phdrs_osabi_def[] = {
{ PT_SUNWBSS, SOL, MSG_PT_SUNWBSS },
{ PT_SUNWSTACK, SOL, MSG_PT_SUNWSTACK },
{ PT_SUNWDTRACE, SOL, MSG_PT_SUNWDTRACE },
{ PT_SUNWCAP, SOL, MSG_PT_SUNWCAP },
{ PT_SUNW_UNWIND, SOL, MSG_PT_SUNW_UNWIND },
{ PT_SUNW_EH_FRAME, SOL, MSG_PT_SUNW_EH_FRAME },
{ PT_GNU_EH_FRAME, LIN, MSG_PT_GNU_EH_FRAME },
{ PT_GNU_STACK, LIN, MSG_PT_GNU_STACK },
{ PT_GNU_RELRO, LIN, MSG_PT_GNU_RELRO },
{ 0 }
};
static const Val_desc2 phdrs_osabi_cf[] = {
{ PT_SUNWBSS, SOL, MSG_PT_SUNWBSS_CF },
{ PT_SUNWSTACK, SOL, MSG_PT_SUNWSTACK_CF },
{ PT_SUNWDTRACE, SOL, MSG_PT_SUNWDTRACE_CF },
{ PT_SUNWCAP, SOL, MSG_PT_SUNWCAP_CF },
{ PT_SUNW_UNWIND, SOL, MSG_PT_SUNW_UNWIND_CF },
{ PT_SUNW_EH_FRAME, SOL, MSG_PT_SUNW_EH_FRAME_CF },
{ PT_GNU_EH_FRAME, LIN, MSG_PT_GNU_EH_FRAME_CF },
{ PT_GNU_STACK, LIN, MSG_PT_GNU_STACK_CF },
{ PT_GNU_RELRO, LIN, MSG_PT_GNU_RELRO_CF },
{ 0 }
};
static const Val_desc2 phdrs_osabi_cfnp[] = {
{ PT_SUNWBSS, SOL, MSG_PT_SUNWBSS_CFNP },
{ PT_SUNWSTACK, SOL, MSG_PT_SUNWSTACK_CFNP },
{ PT_SUNWDTRACE, SOL, MSG_PT_SUNWDTRACE_CFNP },
{ PT_SUNWCAP, SOL, MSG_PT_SUNWCAP_CFNP },
{ PT_SUNW_UNWIND, SOL, MSG_PT_SUNW_UNWIND_CFNP },
{ PT_SUNW_EH_FRAME, SOL, MSG_PT_SUNW_EH_FRAME_CFNP },
{ PT_GNU_EH_FRAME, LIN, MSG_PT_GNU_EH_FRAME_CFNP },
{ PT_GNU_STACK, LIN, MSG_PT_GNU_STACK_CFNP },
{ PT_GNU_RELRO, LIN, MSG_PT_GNU_RELRO_CFNP },
{ 0 }
};
static const Val_desc2 phdrs_osabi_nf[] = {
{ PT_SUNWBSS, SOL, MSG_PT_SUNWBSS_NF },
{ PT_SUNWSTACK, SOL, MSG_PT_SUNWSTACK_NF },
{ PT_SUNWDTRACE, SOL, MSG_PT_SUNWDTRACE_NF },
{ PT_SUNWCAP, SOL, MSG_PT_SUNWCAP_NF },
{ PT_SUNW_UNWIND, SOL, MSG_PT_SUNW_UNWIND_NF },
{ PT_SUNW_EH_FRAME, SOL, MSG_PT_SUNW_EH_FRAME_NF },
{ PT_GNU_EH_FRAME, LIN, MSG_PT_GNU_EH_FRAME_NF },
{ PT_GNU_STACK, LIN, MSG_PT_GNU_STACK_NF },
{ PT_GNU_RELRO, LIN, MSG_PT_GNU_RELRO_NF },
{ 0 }
};
#if PT_LOSUNW != PT_SUNWBSS
#error "PT_LOSUNW has grown. Update phdrs_osabi[]"
#endif
static const conv_ds_vd2_t ds_phdrs_osabi_def = {
CONV_DS_VD2, PT_LOOS, PT_HIOS, phdrs_osabi_def };
static const conv_ds_vd2_t ds_phdrs_osabi_cf = {
CONV_DS_VD2, PT_LOOS, PT_HIOS, phdrs_osabi_cf };
static const conv_ds_vd2_t ds_phdrs_osabi_cfnp = {
CONV_DS_VD2, PT_LOOS, PT_HIOS, phdrs_osabi_cfnp };
static const conv_ds_vd2_t ds_phdrs_osabi_nf = {
CONV_DS_VD2, PT_LOOS, PT_HIOS, phdrs_osabi_nf };
/* Build NULL terminated return arrays for each string style */
static const conv_ds_t *ds_def[] = {
CONV_DS_ADDR(ds_phdrs_def), CONV_DS_ADDR(ds_phdrs_osabi_def),
NULL };
static const conv_ds_t *ds_dmp[] = {
CONV_DS_ADDR(ds_phdrs_dmp), CONV_DS_ADDR(ds_phdrs_osabi_cfnp),
NULL };
static const conv_ds_t *ds_cf[] = {
CONV_DS_ADDR(ds_phdrs_cf), CONV_DS_ADDR(ds_phdrs_osabi_cf),
NULL };
static const conv_ds_t *ds_cfnp[] = {
CONV_DS_ADDR(ds_phdrs_cfnp), CONV_DS_ADDR(ds_phdrs_osabi_cfnp),
NULL };
static const conv_ds_t *ds_nf[] = {
CONV_DS_ADDR(ds_phdrs_nf), CONV_DS_ADDR(ds_phdrs_osabi_nf),
NULL };
/* Select the strings to use */
switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
case CONV_FMT_ALT_DUMP:
return (ds_dmp);
case CONV_FMT_ALT_CF:
return (ds_cf);
case CONV_FMT_ALT_CFNP:
return (ds_cfnp);
case CONV_FMT_ALT_NF:
return (ds_nf);
}
return (ds_def);
#undef ALL
#undef SOL
#undef LIN
}
const char *
conv_phdr_type(uchar_t osabi, Half mach, Word type, Conv_fmt_flags_t fmt_flags,
Conv_inv_buf_t *inv_buf)
{
return (conv_map_ds(osabi, mach, type,
conv_phdr_type_strings(fmt_flags), fmt_flags, inv_buf));
}
conv_iter_ret_t
conv_iter_phdr_type(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags,
conv_iter_cb_t func, void *uvalue)
{
return (conv_iter_ds(osabi, EM_NONE,
conv_phdr_type_strings(fmt_flags), func, uvalue));
}
static const Val_desc2 *
conv_phdr_flags_strings(Conv_fmt_flags_t fmt_flags)
{
/* The CF style has the longest strings */
#define PHDRSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
MSG_PF_X_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
MSG_PF_W_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
MSG_PF_R_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
MSG_PF_SUNW_FAILURE_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
MSG_PF_SUNW_KILLED_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
MSG_PF_SUNW_SIGINFO_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
/*
* Ensure that Conv_phdr_flags_buf_t is large enough:
*
* PHDRSZ is the real minimum size of the buffer required by
* conv_phdr_flags(). However, Conv_phdr_flags_buf_t uses
* CONV_PHDR_FLAGS_BUFSIZE to set the buffer size. We do things this
* way because the definition of PHDRSZ uses information that is not
* available in the environment of other programs that include the
* conv.h header file.
*/
#if (CONV_PHDR_FLAGS_BUFSIZE != PHDRSZ) && !defined(__lint)
#define REPORT_BUFSIZE PHDRSZ
#include "report_bufsize.h"
#error "CONV_PHDR_FLAGS_BUFSIZE does not match PHDRSZ"
#endif
#define ALL ELFOSABI_NONE, EM_NONE
#define SOL ELFOSABI_SOLARIS, EM_NONE
static const Val_desc2 vda_cf[] = {
{ PF_X, ALL, MSG_PF_X_CF },
{ PF_W, ALL, MSG_PF_W_CF },
{ PF_R, ALL, MSG_PF_R_CF },
{ PF_SUNW_FAILURE, SOL, MSG_PF_SUNW_FAILURE_CF },
{ PF_SUNW_KILLED, SOL, MSG_PF_SUNW_KILLED_CF },
{ PF_SUNW_SIGINFO, SOL, MSG_PF_SUNW_SIGINFO_CF },
{ 0 }
};
static const Val_desc2 vda_nf[] = {
{ PF_X, ALL, MSG_PF_X_NF },
{ PF_W, ALL, MSG_PF_W_NF },
{ PF_R, ALL, MSG_PF_R_NF },
{ PF_SUNW_FAILURE, SOL, MSG_PF_SUNW_FAILURE_NF },
{ PF_SUNW_KILLED, SOL, MSG_PF_SUNW_KILLED_NF },
{ PF_SUNW_SIGINFO, SOL, MSG_PF_SUNW_SIGINFO_NF },
{ 0 }
};
return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ?
vda_nf : vda_cf);
#undef ALL
#undef SOL
}
const char *
conv_phdr_flags(uchar_t osabi, Word flags, Conv_fmt_flags_t fmt_flags,
Conv_phdr_flags_buf_t *phdr_flags_buf)
{
static CONV_EXPN_FIELD_ARG conv_arg = {
NULL, sizeof (phdr_flags_buf->buf) };
if (flags == 0)
return (MSG_ORIG(MSG_GBL_ZERO));
conv_arg.buf = phdr_flags_buf->buf;
conv_arg.oflags = conv_arg.rflags = flags;
(void) conv_expn_field2(&conv_arg, osabi, EM_NONE,
conv_phdr_flags_strings(fmt_flags), fmt_flags);
return ((const char *)phdr_flags_buf->buf);
}
conv_iter_ret_t
conv_iter_phdr_flags(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags,
conv_iter_cb_t func, void *uvalue)
{
if (conv_iter_vd2(osabi, EM_NONE,
conv_phdr_flags_strings(fmt_flags),
func, uvalue) == CONV_ITER_DONE)
return (CONV_ITER_DONE);
return (CONV_ITER_CONT);
}
|