Print this page
7029 want per-process exploit mitigation features (secflags)
7030 want basic address space layout randomization (aslr)
7031 noexec_user_stack should be a secflag
7032 want a means to forbid mappings around NULL.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/elfdump/common/struct_layout.c
+++ new/usr/src/cmd/sgs/elfdump/common/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
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
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 -#pragma ident "%Z%%M% %I% %E% SMI"
27 26
28 27 #include <stdlib.h>
29 28 #include <stdio.h>
30 29 #include <string.h>
31 30 #include <msg.h>
32 31 #include <_elfdump.h>
33 32 #include <struct_layout.h>
34 33 #include <conv.h>
35 34
36 35
37 36 /*
38 37 * Functions for extracting and formatting numeric values from
39 38 * structure data.
40 39 */
41 40
42 41
43 42
44 43
45 44 /*
46 45 * Extract the integral field into the value union given and
47 46 * perform any necessary byte swapping to make the result readable
48 47 * on the elfdump host.
49 48 */
50 49 void
51 50 sl_extract_num_field(const char *data, int do_swap, const sl_field_t *fdesc,
52 51 sl_data_t *field_data)
53 52 {
54 53 /* Copy the value bytes into our union */
55 54 (void) memcpy(field_data, data + fdesc->slf_offset,
56 55 fdesc->slf_eltlen);
57 56
58 57 /* Do byte swapping as necessary */
59 58 if (do_swap) {
60 59 switch (fdesc->slf_eltlen) {
61 60 case 2:
62 61 field_data->sld_ui16 = BSWAP_HALF(field_data->sld_ui16);
63 62 break;
64 63
65 64 case 4:
66 65 field_data->sld_ui32 = BSWAP_WORD(field_data->sld_ui32);
67 66 break;
68 67
69 68 case 8:
70 69 field_data->sld_ui64 =
71 70 BSWAP_LWORD(field_data->sld_ui64);
72 71 break;
73 72 }
74 73 }
75 74 }
76 75
77 76 /*
78 77 * Extract the given integer field, and return its value, cast
79 78 * to Word. Note that this operation must not be used on values
80 79 * that can be negative, or larger than 32-bits, as information
81 80 * can be lost.
82 81 */
83 82 Word
84 83 sl_extract_as_word(const char *data, int do_swap, const sl_field_t *fdesc)
85 84 {
86 85 sl_data_t v;
87 86
88 87 /* Extract the value from the raw data */
89 88 sl_extract_num_field(data, do_swap, fdesc, &v);
90 89
91 90 if (fdesc->slf_sign) {
92 91 switch (fdesc->slf_eltlen) {
93 92 case 1:
94 93 return ((Word) v.sld_i8);
95 94 case 2:
96 95 return ((Word) v.sld_i16);
97 96 case 4:
98 97 return ((Word) v.sld_i32);
99 98 case 8:
100 99 return ((Word) v.sld_i64);
101 100 }
102 101 } else {
103 102 switch (fdesc->slf_eltlen) {
104 103 case 1:
105 104 return ((Word) v.sld_ui8);
106 105 case 2:
107 106 return ((Word) v.sld_ui16);
108 107 case 4:
109 108 return ((Word) v.sld_ui32);
110 109 case 8:
111 110 return ((Word) v.sld_ui64);
112 111 }
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
113 112 }
114 113
115 114 /* This should not be reached */
116 115 assert(0);
117 116 return (0);
118 117 }
119 118
120 119
121 120 /*
122 121 * Extract the given integer field, and return its value, cast
123 - * to Word. Note that this operation must not be used on values
122 + * to Lword. Note that this operation must not be used on values
124 123 * that can be negative, as information can be lost.
125 124 */
126 125 Lword
127 126 sl_extract_as_lword(const char *data, int do_swap, const sl_field_t *fdesc)
128 127 {
129 128 sl_data_t v;
130 129
131 130 /* Extract the value from the raw data */
132 131 sl_extract_num_field(data, do_swap, fdesc, &v);
133 132
134 133 if (fdesc->slf_sign) {
135 134 switch (fdesc->slf_eltlen) {
136 135 case 1:
137 136 return ((Lword) v.sld_i8);
138 137 case 2:
139 138 return ((Lword) v.sld_i16);
140 139 case 4:
141 140 return ((Lword) v.sld_i32);
142 141 case 8:
143 142 return ((Lword) v.sld_i64);
144 143 }
145 144 } else {
146 145 switch (fdesc->slf_eltlen) {
147 146 case 1:
148 147 return ((Lword) v.sld_ui8);
149 148 case 2:
150 149 return ((Lword) v.sld_ui16);
151 150 case 4:
152 151 return ((Lword) v.sld_ui32);
153 152 case 8:
154 153 return ((Lword) v.sld_ui64);
155 154 }
156 155 }
157 156
158 157 /* This should not be reached */
159 158 assert(0);
160 159 return (0);
161 160 }
162 161
163 162
164 163 /*
165 164 * Extract the given integer field, and return its value, cast
166 165 * to int32_t. Note that this operation must not be used on unsigned
167 166 * values larger than 31-bits, or on signed values larger than 32-bits,
168 167 * as information can be lost.
169 168 */
170 169 Sword
171 170 sl_extract_as_sword(const char *data, int do_swap, const sl_field_t *fdesc)
172 171 {
173 172 sl_data_t v;
174 173
175 174 /* Extract the value from the raw data */
176 175 sl_extract_num_field(data, do_swap, fdesc, &v);
177 176
178 177 if (fdesc->slf_sign) {
179 178 switch (fdesc->slf_eltlen) {
180 179 case 1:
181 180 return ((Sword)v.sld_i8);
182 181 case 2:
183 182 return ((Sword)v.sld_i16);
184 183 case 4:
185 184 return ((Sword)v.sld_i32);
186 185 case 8:
187 186 return ((Sword)v.sld_i64);
188 187 }
189 188 } else {
190 189 switch (fdesc->slf_eltlen) {
191 190 case 1:
192 191 return ((Sword)v.sld_ui8);
193 192 case 2:
194 193 return ((Sword)v.sld_ui16);
195 194 case 4:
196 195 return ((Sword)v.sld_ui32);
197 196 case 8:
198 197 return ((Sword)v.sld_ui64);
199 198 }
200 199 }
201 200
202 201 /* This should not be reached */
203 202 assert(0);
204 203 return (0);
205 204 }
206 205
207 206
208 207 /*
209 208 * Extract the integral field and format it into the supplied buffer.
210 209 */
211 210 const char *
212 211 sl_fmt_num(const char *data, int do_swap, const sl_field_t *fdesc,
213 212 sl_fmt_num_t fmt_type, sl_fmtbuf_t buf)
214 213 {
215 214 /*
216 215 * These static arrays are indexed by [fdesc->slf_sign][fmt_type]
217 216 * to get a format string to use for the specified combination.
218 217 */
219 218 static const char *fmt_i8[2][3] = {
220 219 {
221 220 MSG_ORIG(MSG_CNOTE_FMT_U),
222 221 MSG_ORIG(MSG_CNOTE_FMT_X),
223 222 MSG_ORIG(MSG_CNOTE_FMT_Z2X)
224 223 },
225 224 {
226 225 MSG_ORIG(MSG_CNOTE_FMT_D),
227 226 MSG_ORIG(MSG_CNOTE_FMT_X),
228 227 MSG_ORIG(MSG_CNOTE_FMT_Z2X)
229 228 }
230 229 };
231 230 static const char *fmt_i16[2][3] = {
232 231 {
233 232 MSG_ORIG(MSG_CNOTE_FMT_U),
234 233 MSG_ORIG(MSG_CNOTE_FMT_X),
235 234 MSG_ORIG(MSG_CNOTE_FMT_Z4X)
236 235 },
237 236 {
238 237 MSG_ORIG(MSG_CNOTE_FMT_D),
239 238 MSG_ORIG(MSG_CNOTE_FMT_X),
240 239 MSG_ORIG(MSG_CNOTE_FMT_Z4X)
241 240 }
242 241 };
243 242 static const char *fmt_i32[2][3] = {
244 243 {
245 244 MSG_ORIG(MSG_CNOTE_FMT_U),
246 245 MSG_ORIG(MSG_CNOTE_FMT_X),
247 246 MSG_ORIG(MSG_CNOTE_FMT_Z8X)
248 247 },
249 248 {
250 249 MSG_ORIG(MSG_CNOTE_FMT_D),
251 250 MSG_ORIG(MSG_CNOTE_FMT_X),
252 251 MSG_ORIG(MSG_CNOTE_FMT_Z8X)
253 252 }
254 253 };
255 254 static const char *fmt_i64[2][3] = {
256 255 {
257 256 MSG_ORIG(MSG_CNOTE_FMT_LLU),
258 257 MSG_ORIG(MSG_CNOTE_FMT_LLX),
259 258 MSG_ORIG(MSG_CNOTE_FMT_Z16LLX)
260 259 },
261 260 {
262 261 MSG_ORIG(MSG_CNOTE_FMT_LLD),
263 262 MSG_ORIG(MSG_CNOTE_FMT_LLX),
264 263 MSG_ORIG(MSG_CNOTE_FMT_Z16LLX)
265 264 }
266 265 };
267 266
268 267 sl_data_t v;
269 268
270 269 /* Extract the value from the raw data */
271 270 sl_extract_num_field(data, do_swap, fdesc, &v);
272 271
273 272 /*
274 273 * Format into the buffer. Note that we depend on the signed
275 274 * and unsigned versions of each width being equivalent as long
276 275 * as the format specifies the proper formatting.
277 276 */
278 277 switch (fdesc->slf_eltlen) {
279 278 case 1:
280 279 (void) snprintf(buf, sizeof (sl_fmtbuf_t),
281 280 fmt_i8[fdesc->slf_sign][fmt_type], (uint32_t)v.sld_ui8);
282 281 break;
283 282
284 283 case 2:
285 284 (void) snprintf(buf, sizeof (sl_fmtbuf_t),
286 285 fmt_i16[fdesc->slf_sign][fmt_type], (uint32_t)v.sld_ui16);
287 286 break;
288 287
289 288 case 4:
290 289 (void) snprintf(buf, sizeof (sl_fmtbuf_t),
291 290 fmt_i32[fdesc->slf_sign][fmt_type], v.sld_ui32);
292 291 break;
293 292
294 293 case 8:
295 294 (void) snprintf(buf, sizeof (sl_fmtbuf_t),
296 295 fmt_i64[fdesc->slf_sign][fmt_type], v.sld_ui64);
297 296 break;
298 297 }
299 298
300 299 return (buf);
301 300 }
302 301
303 302 /*
304 303 * Return structure layout definition for the given machine type,
305 304 * or NULL if the specified machine is not supported.
306 305 */
307 306 const sl_arch_layout_t *
308 307 sl_mach(Half mach)
309 308 {
310 309 switch (mach) {
311 310 case EM_386:
312 311 return (struct_layout_i386());
313 312
314 313 case EM_AMD64:
315 314 return (struct_layout_amd64());
316 315
317 316 case EM_SPARC:
318 317 case EM_SPARC32PLUS:
319 318 return (struct_layout_sparc());
320 319
321 320 case EM_SPARCV9:
322 321 return (struct_layout_sparcv9());
323 322 }
324 323
325 324 /* Unsupported architecture */
326 325 return (NULL);
327 326 }
↓ open down ↓ |
194 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX