Print this page
uts: Allow for address space randomisation.
Randomise the base addresses of shared objects, non-fixed mappings, the
stack and the heap. Introduce a service, svc:/system/process-security,
and a tool psecflags(1) to control and observe it
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libproc/common/P32ton.c
+++ new/usr/src/lib/libproc/common/P32ton.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
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
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 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 27 #include <sys/types.h>
30 28 #include <sys/mkdev.h>
31 29 #include <sys/regset.h>
32 30 #include <string.h>
33 31
34 32 #if defined(__amd64)
35 33 #include <sys/fp.h>
36 34 #include <ieeefp.h>
37 35 #endif
38 36
39 37 #include "P32ton.h"
40 38
41 39 dev_t
42 40 prexpldev(dev32_t d)
43 41 {
44 42 if (d != (dev32_t)-1L)
45 43 return (makedev((d >> NBITSMINOR32) & MAXMAJ32, d & MAXMIN32));
46 44
47 45 return ((dev_t)PRNODEV);
48 46 }
49 47
50 48
51 49 dev32_t
52 50 prcmpldev(dev_t d)
53 51 {
54 52 #ifdef _LP64
55 53 if (d == PRNODEV) {
56 54 return (PRNODEV32);
57 55 } else {
58 56 major_t maj = major(d);
59 57 minor_t min = minor(d);
60 58
61 59 if (maj == (major_t)PRNODEV || min == (minor_t)PRNODEV)
62 60 return (PRNODEV32);
63 61
64 62 return ((dev32_t)((maj << NBITSMINOR32) | min));
65 63 }
66 64 #else
67 65 return ((dev32_t)d);
68 66 #endif
69 67 }
70 68
71 69 #ifdef _LP64
72 70
73 71 void
74 72 timestruc_32_to_n(const timestruc32_t *src, timestruc_t *dst)
75 73 {
76 74 dst->tv_sec = (time_t)(uint32_t)src->tv_sec;
77 75 dst->tv_nsec = (long)(uint32_t)src->tv_nsec;
78 76 }
79 77
80 78 void
81 79 stack_32_to_n(const stack32_t *src, stack_t *dst)
82 80 {
83 81 dst->ss_sp = (caddr_t)(uintptr_t)src->ss_sp;
84 82 dst->ss_size = src->ss_size;
85 83 dst->ss_flags = src->ss_flags;
86 84 }
87 85
88 86 void
89 87 sigaction_32_to_n(const struct sigaction32 *src, struct sigaction *dst)
90 88 {
91 89 (void) memset(dst, 0, sizeof (struct sigaction));
92 90 dst->sa_flags = src->sa_flags;
93 91 dst->sa_handler = (void (*)())(uintptr_t)src->sa_handler;
94 92 (void) memcpy(&dst->sa_mask, &src->sa_mask, sizeof (dst->sa_mask));
95 93 }
96 94
97 95 void
98 96 siginfo_32_to_n(const siginfo32_t *src, siginfo_t *dst)
99 97 {
100 98 (void) memset(dst, 0, sizeof (siginfo_t));
101 99
102 100 /*
103 101 * The absolute minimum content is si_signo and si_code.
104 102 */
105 103 dst->si_signo = src->si_signo;
106 104 if ((dst->si_code = src->si_code) == SI_NOINFO)
107 105 return;
108 106
109 107 /*
110 108 * A siginfo generated by user level is structured
111 109 * differently from one generated by the kernel.
112 110 */
113 111 if (SI_FROMUSER(src)) {
114 112 dst->si_pid = src->si_pid;
115 113 dst->si_ctid = src->si_ctid;
116 114 dst->si_zoneid = src->si_zoneid;
117 115 dst->si_uid = src->si_uid;
118 116 if (SI_CANQUEUE(src->si_code)) {
119 117 dst->si_value.sival_int =
120 118 (long)(uint32_t)src->si_value.sival_int;
121 119 }
122 120 return;
123 121 }
124 122
125 123 dst->si_errno = src->si_errno;
126 124
127 125 switch (src->si_signo) {
128 126 default:
129 127 dst->si_pid = src->si_pid;
130 128 dst->si_ctid = src->si_ctid;
131 129 dst->si_zoneid = src->si_zoneid;
132 130 dst->si_uid = src->si_uid;
133 131 dst->si_value.sival_int =
134 132 (long)(uint32_t)src->si_value.sival_int;
135 133 break;
136 134 case SIGCLD:
137 135 dst->si_pid = src->si_pid;
138 136 dst->si_ctid = src->si_ctid;
139 137 dst->si_zoneid = src->si_zoneid;
140 138 dst->si_status = src->si_status;
141 139 dst->si_stime = src->si_stime;
142 140 dst->si_utime = src->si_utime;
143 141 break;
144 142 case SIGSEGV:
145 143 case SIGBUS:
146 144 case SIGILL:
147 145 case SIGTRAP:
148 146 case SIGFPE:
149 147 case SIGEMT:
150 148 dst->si_addr = (void *)(uintptr_t)src->si_addr;
151 149 dst->si_trapno = src->si_trapno;
152 150 dst->si_pc = (void *)(uintptr_t)src->si_pc;
153 151 break;
154 152 case SIGPOLL:
155 153 case SIGXFSZ:
156 154 dst->si_fd = src->si_fd;
157 155 dst->si_band = src->si_band;
158 156 break;
159 157 case SIGPROF:
160 158 dst->si_faddr = (void *)(uintptr_t)src->si_faddr;
161 159 dst->si_tstamp.tv_sec = src->si_tstamp.tv_sec;
162 160 dst->si_tstamp.tv_nsec = src->si_tstamp.tv_nsec;
163 161 dst->si_syscall = src->si_syscall;
164 162 dst->si_nsysarg = src->si_nsysarg;
165 163 dst->si_fault = src->si_fault;
166 164 break;
167 165 }
168 166 }
169 167
170 168 void
171 169 auxv_32_to_n(const auxv32_t *src, auxv_t *dst)
172 170 {
173 171 /*
174 172 * This is a little sketchy: we have three types of values stored
175 173 * in an auxv (long, void *, and void (*)()) so the only sign-extension
176 174 * issue is with the long. We could case on all possible AT_* types,
177 175 * but this seems silly since currently none of the types which use
178 176 * a_un.a_val actually use negative numbers as a value. For this
179 177 * reason, it seems simpler to just do an unsigned expansion for now.
180 178 */
181 179 dst->a_type = src->a_type;
182 180 dst->a_un.a_ptr = (void *)(uintptr_t)src->a_un.a_ptr;
183 181 }
184 182
185 183 #if defined(__sparc)
186 184 void
187 185 rwindow_32_to_n(const struct rwindow32 *src, struct rwindow *dst)
188 186 {
189 187 int i;
190 188
191 189 for (i = 0; i < 8; i++) {
192 190 dst->rw_local[i] = (uint64_t)(uint32_t)src->rw_local[i];
193 191 dst->rw_in[i] = (uint64_t)(uint32_t)src->rw_in[i];
194 192 }
195 193 }
196 194
197 195 void
198 196 gwindows_32_to_n(const gwindows32_t *src, gwindows_t *dst)
199 197 {
200 198 int i;
201 199
202 200 (void) memset(dst, 0, sizeof (gwindows_t));
203 201 dst->wbcnt = src->wbcnt;
204 202
205 203 for (i = 0; i < src->wbcnt; i++) {
206 204 if (src->spbuf[i] != 0) {
207 205 rwindow_32_to_n(&src->wbuf[i], &dst->wbuf[i]);
208 206 dst->spbuf[i] = (greg_t *)(uintptr_t)src->spbuf[i];
209 207 }
210 208 }
211 209 }
212 210 #endif /* __sparc */
213 211
214 212 void
215 213 prgregset_32_to_n(const prgreg32_t *src, prgreg_t *dst)
216 214 {
217 215 #ifdef __amd64
218 216 (void) memset(dst, 0, NPRGREG * sizeof (prgreg_t));
219 217 dst[REG_GS] = (uint32_t)src[GS];
220 218 dst[REG_FS] = (uint32_t)src[FS];
221 219 dst[REG_DS] = (uint32_t)src[DS];
222 220 dst[REG_ES] = (uint32_t)src[ES];
223 221 dst[REG_RDI] = (uint32_t)src[EDI];
224 222 dst[REG_RSI] = (uint32_t)src[ESI];
225 223 dst[REG_RBP] = (uint32_t)src[EBP];
226 224 dst[REG_RBX] = (uint32_t)src[EBX];
227 225 dst[REG_RDX] = (uint32_t)src[EDX];
228 226 dst[REG_RCX] = (uint32_t)src[ECX];
229 227 dst[REG_RAX] = (uint32_t)src[EAX];
230 228 dst[REG_TRAPNO] = (uint32_t)src[TRAPNO];
231 229 dst[REG_ERR] = (uint32_t)src[ERR];
232 230 dst[REG_RIP] = (uint32_t)src[EIP];
233 231 dst[REG_CS] = (uint32_t)src[CS];
234 232 dst[REG_RFL] = (uint32_t)src[EFL];
235 233 dst[REG_RSP] = (uint32_t)src[UESP];
236 234 dst[REG_SS] = (uint32_t)src[SS];
237 235 #else
238 236 int i;
239 237
240 238 for (i = 0; i < NPRGREG; i++)
241 239 dst[i] = (prgreg_t)(uint32_t)src[i];
242 240 #endif
243 241 }
244 242
245 243 void
246 244 prfpregset_32_to_n(const prfpregset32_t *src, prfpregset_t *dst)
247 245 {
248 246 #if defined(__sparc)
249 247 int i;
250 248
251 249 (void) memset(dst, 0, sizeof (prfpregset_t));
252 250
253 251 for (i = 0; i < 32; i++)
254 252 dst->pr_fr.pr_regs[i] = src->pr_fr.pr_regs[i];
255 253
256 254 /*
257 255 * We deliberately do not convert pr_qcnt or pr_q because it is a long-
258 256 * standing /proc bug that this information is not exported, and another
259 257 * bug further caused these values to be returned as uninitialized data
260 258 * when the 64-bit kernel exported them for a 32-bit process with en=0.
261 259 */
262 260 dst->pr_filler = src->pr_filler;
263 261 dst->pr_fsr = src->pr_fsr;
264 262 dst->pr_q_entrysize = src->pr_q_entrysize;
265 263 dst->pr_en = src->pr_en;
266 264
267 265 #elif defined(__amd64)
268 266
269 267 struct _fpstate32 *src32 = (struct _fpstate32 *)src;
270 268 struct fpchip_state *dst64 = (struct fpchip_state *)dst;
271 269 int i;
272 270
273 271 (void) memcpy(dst64->st, src32->_st, sizeof (src32->_st));
274 272 (void) memcpy(dst64->xmm, src32->xmm, sizeof (src32->xmm));
275 273 (void) memset((caddr_t)dst64->xmm + sizeof (src32->xmm), 0,
276 274 sizeof (dst64->xmm) - sizeof (src32->xmm));
277 275 dst64->cw = (uint16_t)src32->cw;
278 276 dst64->sw = (uint16_t)src32->sw;
279 277 dst64->fop = 0;
280 278 dst64->rip = src32->ipoff;
281 279 dst64->rdp = src32->dataoff;
282 280 dst64->mxcsr = src32->mxcsr;
283 281 dst64->mxcsr_mask = 0;
284 282 dst64->status = src32->status;
285 283 dst64->xstatus = src32->xstatus;
286 284
287 285 /*
288 286 * Converting from the tag field to the compressed fctw is easy.
289 287 * If the two tag bits are 3, then the register is empty and we
290 288 * clear the bit in fctw. Otherwise we set the bit.
291 289 */
292 290
293 291 dst64->fctw = 0;
294 292 for (i = 0; i < 8; i++)
295 293 if (((src32->tag >> (i * 2)) & 3) != 3)
296 294 dst64->fctw |= 1 << i;
297 295 #else
298 296 #error "unrecognized ISA"
299 297 #endif
300 298 }
301 299
302 300 void
303 301 lwpstatus_32_to_n(const lwpstatus32_t *src, lwpstatus_t *dst)
304 302 {
305 303 int i;
306 304
307 305 dst->pr_flags = src->pr_flags;
308 306 dst->pr_lwpid = src->pr_lwpid;
309 307 dst->pr_why = src->pr_why;
310 308 dst->pr_what = src->pr_what;
311 309 dst->pr_cursig = src->pr_cursig;
312 310
313 311 siginfo_32_to_n(&src->pr_info, &dst->pr_info);
314 312
315 313 dst->pr_lwppend = src->pr_lwppend;
316 314 dst->pr_lwphold = src->pr_lwphold;
317 315
318 316 sigaction_32_to_n(&src->pr_action, &dst->pr_action);
319 317 stack_32_to_n(&src->pr_altstack, &dst->pr_altstack);
320 318
321 319 dst->pr_oldcontext = src->pr_oldcontext;
322 320 dst->pr_syscall = src->pr_syscall;
323 321 dst->pr_nsysarg = src->pr_nsysarg;
324 322 dst->pr_errno = src->pr_errno;
325 323
326 324 for (i = 0; i < PRSYSARGS; i++)
327 325 dst->pr_sysarg[i] = (long)(uint32_t)src->pr_sysarg[i];
328 326
329 327 dst->pr_rval1 = (long)(uint32_t)src->pr_rval1;
330 328 dst->pr_rval2 = (long)(uint32_t)src->pr_rval2;
331 329
332 330 (void) memcpy(&dst->pr_clname[0], &src->pr_clname[0], PRCLSZ);
333 331 timestruc_32_to_n(&src->pr_tstamp, &dst->pr_tstamp);
334 332
335 333 dst->pr_ustack = src->pr_ustack;
336 334 dst->pr_instr = src->pr_instr;
337 335
338 336 prgregset_32_to_n(src->pr_reg, dst->pr_reg);
339 337 prfpregset_32_to_n(&src->pr_fpreg, &dst->pr_fpreg);
340 338 }
341 339
342 340 void
343 341 pstatus_32_to_n(const pstatus32_t *src, pstatus_t *dst)
344 342 {
345 343 dst->pr_flags = src->pr_flags;
346 344 dst->pr_nlwp = src->pr_nlwp;
347 345 dst->pr_nzomb = src->pr_nzomb;
348 346 dst->pr_pid = src->pr_pid;
349 347 dst->pr_ppid = src->pr_ppid;
350 348 dst->pr_pgid = src->pr_pgid;
351 349 dst->pr_sid = src->pr_sid;
352 350 dst->pr_taskid = src->pr_taskid;
353 351 dst->pr_projid = src->pr_projid;
354 352 dst->pr_zoneid = src->pr_zoneid;
355 353 dst->pr_aslwpid = src->pr_aslwpid;
356 354 dst->pr_agentid = src->pr_agentid;
357 355 dst->pr_sigpend = src->pr_sigpend;
358 356 dst->pr_brkbase = src->pr_brkbase;
359 357 dst->pr_brksize = src->pr_brksize;
360 358 dst->pr_stkbase = src->pr_stkbase;
361 359 dst->pr_stksize = src->pr_stksize;
362 360
363 361 timestruc_32_to_n(&src->pr_utime, &dst->pr_utime);
↓ open down ↓ |
325 lines elided |
↑ open up ↑ |
364 362 timestruc_32_to_n(&src->pr_stime, &dst->pr_stime);
365 363 timestruc_32_to_n(&src->pr_cutime, &dst->pr_cutime);
366 364 timestruc_32_to_n(&src->pr_cstime, &dst->pr_cstime);
367 365
368 366 dst->pr_sigtrace = src->pr_sigtrace;
369 367 dst->pr_flttrace = src->pr_flttrace;
370 368 dst->pr_sysentry = src->pr_sysentry;
371 369 dst->pr_sysexit = src->pr_sysexit;
372 370 dst->pr_dmodel = src->pr_dmodel;
373 371
372 + (void) memcpy(&dst->pr_secflags, &src->pr_secflags, sizeof (psecflags_t));
373 +
374 374 lwpstatus_32_to_n(&src->pr_lwp, &dst->pr_lwp);
375 375 }
376 376
377 377 void
378 378 lwpsinfo_32_to_n(const lwpsinfo32_t *src, lwpsinfo_t *dst)
379 379 {
380 380 dst->pr_flag = src->pr_flag;
381 381 dst->pr_lwpid = src->pr_lwpid;
382 382 dst->pr_addr = src->pr_addr;
383 383 dst->pr_wchan = src->pr_wchan;
384 384 dst->pr_stype = src->pr_stype;
385 385 dst->pr_state = src->pr_state;
386 386 dst->pr_sname = src->pr_sname;
387 387 dst->pr_nice = src->pr_nice;
388 388 dst->pr_syscall = src->pr_syscall;
389 389 dst->pr_oldpri = src->pr_oldpri;
390 390 dst->pr_cpu = src->pr_cpu;
391 391 dst->pr_pri = src->pr_pri;
392 392 dst->pr_pctcpu = src->pr_pctcpu;
393 393
394 394 timestruc_32_to_n(&src->pr_start, &dst->pr_start);
395 395 timestruc_32_to_n(&src->pr_time, &dst->pr_time);
396 396
397 397 (void) memcpy(&dst->pr_clname[0], &src->pr_clname[0], PRCLSZ);
398 398 (void) memcpy(&dst->pr_name[0], &src->pr_name[0], PRFNSZ);
399 399
400 400 dst->pr_onpro = src->pr_onpro;
401 401 dst->pr_bindpro = src->pr_bindpro;
402 402 dst->pr_bindpset = src->pr_bindpset;
403 403 dst->pr_lgrp = src->pr_lgrp;
404 404 }
405 405
406 406 void
407 407 psinfo_32_to_n(const psinfo32_t *src, psinfo_t *dst)
408 408 {
409 409 dst->pr_flag = src->pr_flag;
410 410 dst->pr_nlwp = src->pr_nlwp;
411 411 dst->pr_nzomb = src->pr_nzomb;
412 412 dst->pr_pid = src->pr_pid;
413 413 dst->pr_pgid = src->pr_pgid;
414 414 dst->pr_sid = src->pr_sid;
415 415 dst->pr_taskid = src->pr_taskid;
416 416 dst->pr_projid = src->pr_projid;
417 417 dst->pr_zoneid = src->pr_zoneid;
418 418 dst->pr_uid = src->pr_uid;
419 419 dst->pr_euid = src->pr_euid;
420 420 dst->pr_gid = src->pr_gid;
421 421 dst->pr_egid = src->pr_egid;
422 422 dst->pr_addr = src->pr_addr;
423 423 dst->pr_size = src->pr_size;
424 424 dst->pr_rssize = src->pr_rssize;
425 425
426 426 dst->pr_ttydev = prexpldev(src->pr_ttydev);
427 427
428 428 dst->pr_pctcpu = src->pr_pctcpu;
429 429 dst->pr_pctmem = src->pr_pctmem;
430 430
431 431 timestruc_32_to_n(&src->pr_start, &dst->pr_start);
432 432 timestruc_32_to_n(&src->pr_time, &dst->pr_time);
433 433 timestruc_32_to_n(&src->pr_ctime, &dst->pr_ctime);
434 434
435 435 (void) memcpy(&dst->pr_fname[0], &src->pr_fname[0], PRFNSZ);
436 436 (void) memcpy(&dst->pr_psargs[0], &src->pr_psargs[0], PRARGSZ);
437 437
438 438 dst->pr_wstat = src->pr_wstat;
439 439 dst->pr_argc = src->pr_argc;
440 440 dst->pr_argv = src->pr_argv;
441 441 dst->pr_envp = src->pr_envp;
442 442 dst->pr_dmodel = src->pr_dmodel;
443 443
444 444 lwpsinfo_32_to_n(&src->pr_lwp, &dst->pr_lwp);
445 445 }
446 446
447 447 void
448 448 timestruc_n_to_32(const timestruc_t *src, timestruc32_t *dst)
449 449 {
450 450 dst->tv_sec = (time32_t)src->tv_sec;
451 451 dst->tv_nsec = (int32_t)src->tv_nsec;
452 452 }
453 453
454 454 void
455 455 stack_n_to_32(const stack_t *src, stack32_t *dst)
456 456 {
457 457 dst->ss_sp = (caddr32_t)(uintptr_t)src->ss_sp;
458 458 dst->ss_size = src->ss_size;
459 459 dst->ss_flags = src->ss_flags;
460 460 }
461 461
462 462 void
463 463 sigaction_n_to_32(const struct sigaction *src, struct sigaction32 *dst)
464 464 {
465 465 (void) memset(dst, 0, sizeof (struct sigaction32));
466 466 dst->sa_flags = src->sa_flags;
467 467 dst->sa_handler = (caddr32_t)(uintptr_t)src->sa_handler;
468 468 (void) memcpy(&dst->sa_mask, &src->sa_mask, sizeof (dst->sa_mask));
469 469 }
470 470
471 471 void
472 472 siginfo_n_to_32(const siginfo_t *src, siginfo32_t *dst)
473 473 {
474 474 (void) memset(dst, 0, sizeof (siginfo32_t));
475 475
476 476 /*
477 477 * The absolute minimum content is si_signo and si_code.
478 478 */
479 479 dst->si_signo = src->si_signo;
480 480 if ((dst->si_code = src->si_code) == SI_NOINFO)
481 481 return;
482 482
483 483 /*
484 484 * A siginfo generated by user level is structured
485 485 * differently from one generated by the kernel.
486 486 */
487 487 if (SI_FROMUSER(src)) {
488 488 dst->si_pid = src->si_pid;
489 489 dst->si_ctid = src->si_ctid;
490 490 dst->si_zoneid = src->si_zoneid;
491 491 dst->si_uid = src->si_uid;
492 492 if (SI_CANQUEUE(src->si_code)) {
493 493 dst->si_value.sival_int =
494 494 (int32_t)src->si_value.sival_int;
495 495 }
496 496 return;
497 497 }
498 498
499 499 dst->si_errno = src->si_errno;
500 500
501 501 switch (src->si_signo) {
502 502 default:
503 503 dst->si_pid = src->si_pid;
504 504 dst->si_ctid = src->si_ctid;
505 505 dst->si_zoneid = src->si_zoneid;
506 506 dst->si_uid = src->si_uid;
507 507 dst->si_value.sival_int =
508 508 (int32_t)src->si_value.sival_int;
509 509 break;
510 510 case SIGCLD:
511 511 dst->si_pid = src->si_pid;
512 512 dst->si_ctid = src->si_ctid;
513 513 dst->si_zoneid = src->si_zoneid;
514 514 dst->si_status = src->si_status;
515 515 dst->si_stime = src->si_stime;
516 516 dst->si_utime = src->si_utime;
517 517 break;
518 518 case SIGSEGV:
519 519 case SIGBUS:
520 520 case SIGILL:
521 521 case SIGTRAP:
522 522 case SIGFPE:
523 523 case SIGEMT:
524 524 dst->si_addr = (caddr32_t)(uintptr_t)src->si_addr;
525 525 dst->si_trapno = src->si_trapno;
526 526 dst->si_pc = (caddr32_t)(uintptr_t)src->si_pc;
527 527 break;
528 528 case SIGPOLL:
529 529 case SIGXFSZ:
530 530 dst->si_fd = src->si_fd;
531 531 dst->si_band = src->si_band;
532 532 break;
533 533 case SIGPROF:
534 534 dst->si_faddr = (caddr32_t)(uintptr_t)src->si_faddr;
535 535 dst->si_tstamp.tv_sec = src->si_tstamp.tv_sec;
536 536 dst->si_tstamp.tv_nsec = src->si_tstamp.tv_nsec;
537 537 dst->si_syscall = src->si_syscall;
538 538 dst->si_nsysarg = src->si_nsysarg;
539 539 dst->si_fault = src->si_fault;
540 540 break;
541 541 }
542 542 }
543 543
544 544 void
545 545 auxv_n_to_32(const auxv_t *src, auxv32_t *dst)
546 546 {
547 547 dst->a_type = src->a_type;
548 548 dst->a_un.a_ptr = (caddr32_t)(uintptr_t)src->a_un.a_ptr;
549 549 }
550 550
551 551 void
552 552 prgregset_n_to_32(const prgreg_t *src, prgreg32_t *dst)
553 553 {
554 554 #ifdef __amd64
555 555 (void) memset(dst, 0, NPRGREG32 * sizeof (prgreg32_t));
556 556 dst[GS] = src[REG_GS];
557 557 dst[FS] = src[REG_FS];
558 558 dst[DS] = src[REG_DS];
559 559 dst[ES] = src[REG_ES];
560 560 dst[EDI] = src[REG_RDI];
561 561 dst[ESI] = src[REG_RSI];
562 562 dst[EBP] = src[REG_RBP];
563 563 dst[EBX] = src[REG_RBX];
564 564 dst[EDX] = src[REG_RDX];
565 565 dst[ECX] = src[REG_RCX];
566 566 dst[EAX] = src[REG_RAX];
567 567 dst[TRAPNO] = src[REG_TRAPNO];
568 568 dst[ERR] = src[REG_ERR];
569 569 dst[EIP] = src[REG_RIP];
570 570 dst[CS] = src[REG_CS];
571 571 dst[EFL] = src[REG_RFL];
572 572 dst[UESP] = src[REG_RSP];
573 573 dst[SS] = src[REG_SS];
574 574 #else
575 575 int i;
576 576
577 577 for (i = 0; i < NPRGREG; i++)
578 578 dst[i] = (prgreg32_t)src[i];
579 579 #endif
580 580 }
581 581
582 582 void
583 583 prfpregset_n_to_32(const prfpregset_t *src, prfpregset32_t *dst)
584 584 {
585 585 #if defined(__sparc)
586 586 int i;
587 587
588 588 (void) memset(dst, 0, sizeof (prfpregset32_t));
589 589
590 590 for (i = 0; i < 32; i++)
591 591 dst->pr_fr.pr_regs[i] = src->pr_fr.pr_regs[i];
592 592
593 593 dst->pr_filler = src->pr_filler;
594 594 dst->pr_fsr = src->pr_fsr;
595 595 dst->pr_q_entrysize = src->pr_q_entrysize;
596 596 dst->pr_en = src->pr_en;
597 597
598 598 #elif defined(__amd64)
599 599
600 600 struct _fpstate32 *dst32 = (struct _fpstate32 *)dst;
601 601 struct fpchip_state *src64 = (struct fpchip_state *)src;
602 602 uint32_t top;
603 603 int i;
604 604
605 605 (void) memcpy(dst32->_st, src64->st, sizeof (dst32->_st));
606 606 (void) memcpy(dst32->xmm, src64->xmm, sizeof (dst32->xmm));
607 607 dst32->cw = src64->cw;
608 608 dst32->sw = src64->sw;
609 609 dst32->ipoff = (unsigned int)src64->rip;
610 610 dst32->cssel = 0;
611 611 dst32->dataoff = (unsigned int)src64->rdp;
612 612 dst32->datasel = 0;
613 613 dst32->status = src64->status;
614 614 dst32->mxcsr = src64->mxcsr;
615 615 dst32->xstatus = src64->xstatus;
616 616
617 617 /*
618 618 * AMD64 stores the tag in a compressed form. It is
619 619 * necessary to extract the original 2-bit tag value.
620 620 * See AMD64 Architecture Programmer's Manual Volume 2:
621 621 * System Programming, Chapter 11.
622 622 */
623 623
624 624 top = (src64->sw & FPS_TOP) >> 11;
625 625 dst32->tag = 0;
626 626 for (i = 0; i < 8; i++) {
627 627 /*
628 628 * Recall that we need to use the current TOP-of-stack value to
629 629 * associate the _st[] index back to a physical register number,
630 630 * since tag word indices are physical register numbers. Then
631 631 * to get the tag value, we shift over two bits for each tag
632 632 * index, and then grab the bottom two bits.
633 633 */
634 634 uint_t tag_index = (i + top) & 7;
635 635 uint_t tag_fctw = (src64->fctw >> tag_index) & 1;
636 636 uint_t tag_value;
637 637 uint_t exp;
638 638
639 639 /*
640 640 * Union for overlaying _fpreg structure on to quad-precision
641 641 * floating-point value (long double).
642 642 */
643 643 union {
644 644 struct _fpreg reg;
645 645 long double ld;
646 646 } fpru;
647 647
648 648 fpru.ld = src64->st[i].__fpr_pad._q;
649 649 exp = fpru.reg.exponent & 0x7fff;
650 650
651 651 if (tag_fctw == 0) {
652 652 tag_value = 3; /* empty */
653 653 } else if (exp == 0) {
654 654 if (fpru.reg.significand[0] == 0 &&
655 655 fpru.reg.significand[1] == 0 &&
656 656 fpru.reg.significand[2] == 0 &&
657 657 fpru.reg.significand[3] == 0)
658 658 tag_value = 1; /* zero */
659 659 else
660 660 tag_value = 2; /* special: denormal */
661 661 } else if (exp == 0x7fff) {
662 662 tag_value = 2; /* special: infinity or NaN */
663 663 } else if (fpru.reg.significand[3] & 0x8000) {
664 664 tag_value = 0; /* valid */
665 665 } else {
666 666 tag_value = 2; /* special: unnormal */
667 667 }
668 668 dst32->tag |= tag_value << (tag_index * 2);
669 669 }
670 670 #else
671 671 #error "unrecognized ISA"
672 672 #endif
673 673 }
674 674
675 675 void
676 676 lwpstatus_n_to_32(const lwpstatus_t *src, lwpstatus32_t *dst)
677 677 {
678 678 int i;
679 679
680 680 dst->pr_flags = src->pr_flags;
681 681 dst->pr_lwpid = src->pr_lwpid;
682 682 dst->pr_why = src->pr_why;
683 683 dst->pr_what = src->pr_what;
684 684 dst->pr_cursig = src->pr_cursig;
685 685
686 686 siginfo_n_to_32(&src->pr_info, &dst->pr_info);
687 687
688 688 dst->pr_lwppend = src->pr_lwppend;
689 689 dst->pr_lwphold = src->pr_lwphold;
690 690
691 691 sigaction_n_to_32(&src->pr_action, &dst->pr_action);
692 692 stack_n_to_32(&src->pr_altstack, &dst->pr_altstack);
693 693
694 694 dst->pr_oldcontext = (caddr32_t)src->pr_oldcontext;
695 695 dst->pr_syscall = src->pr_syscall;
696 696 dst->pr_nsysarg = src->pr_nsysarg;
697 697 dst->pr_errno = src->pr_errno;
698 698
699 699 for (i = 0; i < PRSYSARGS; i++)
700 700 dst->pr_sysarg[i] = (int32_t)src->pr_sysarg[i];
701 701
702 702 dst->pr_rval1 = (int32_t)src->pr_rval1;
703 703 dst->pr_rval2 = (int32_t)src->pr_rval2;
704 704
705 705 (void) memcpy(&dst->pr_clname[0], &src->pr_clname[0], PRCLSZ);
706 706 timestruc_n_to_32(&src->pr_tstamp, &dst->pr_tstamp);
707 707
708 708 dst->pr_ustack = (caddr32_t)src->pr_ustack;
709 709 dst->pr_instr = src->pr_instr;
710 710
711 711 prgregset_n_to_32(src->pr_reg, dst->pr_reg);
712 712 prfpregset_n_to_32(&src->pr_fpreg, &dst->pr_fpreg);
713 713 }
714 714
715 715 void
716 716 pstatus_n_to_32(const pstatus_t *src, pstatus32_t *dst)
717 717 {
718 718 dst->pr_flags = src->pr_flags;
719 719 dst->pr_nlwp = src->pr_nlwp;
720 720 dst->pr_nzomb = src->pr_nzomb;
721 721 dst->pr_pid = (pid32_t)src->pr_pid;
722 722 dst->pr_ppid = (pid32_t)src->pr_ppid;
723 723 dst->pr_pgid = (pid32_t)src->pr_pgid;
724 724 dst->pr_sid = (pid32_t)src->pr_sid;
725 725 dst->pr_taskid = (id32_t)src->pr_taskid;
726 726 dst->pr_projid = (id32_t)src->pr_projid;
727 727 dst->pr_zoneid = (id32_t)src->pr_zoneid;
728 728 dst->pr_aslwpid = (id32_t)src->pr_aslwpid;
729 729 dst->pr_agentid = (id32_t)src->pr_agentid;
730 730 dst->pr_sigpend = src->pr_sigpend;
731 731 dst->pr_brkbase = (caddr32_t)src->pr_brkbase;
732 732 dst->pr_brksize = (size32_t)src->pr_brksize;
733 733 dst->pr_stkbase = (caddr32_t)src->pr_stkbase;
734 734 dst->pr_stksize = (size32_t)src->pr_stksize;
735 735
736 736 timestruc_n_to_32(&src->pr_utime, &dst->pr_utime);
↓ open down ↓ |
353 lines elided |
↑ open up ↑ |
737 737 timestruc_n_to_32(&src->pr_stime, &dst->pr_stime);
738 738 timestruc_n_to_32(&src->pr_cutime, &dst->pr_cutime);
739 739 timestruc_n_to_32(&src->pr_cstime, &dst->pr_cstime);
740 740
741 741 dst->pr_sigtrace = src->pr_sigtrace;
742 742 dst->pr_flttrace = src->pr_flttrace;
743 743 dst->pr_sysentry = src->pr_sysentry;
744 744 dst->pr_sysexit = src->pr_sysexit;
745 745 dst->pr_dmodel = src->pr_dmodel;
746 746
747 + (void) memcpy(&dst->pr_secflags, &src->pr_secflags, sizeof (psecflags_t));
748 +
747 749 lwpstatus_n_to_32(&src->pr_lwp, &dst->pr_lwp);
748 750 }
749 751
750 752 void
751 753 lwpsinfo_n_to_32(const lwpsinfo_t *src, lwpsinfo32_t *dst)
752 754 {
753 755 dst->pr_flag = src->pr_flag;
754 756 dst->pr_lwpid = (id32_t)src->pr_lwpid;
755 757 dst->pr_addr = (caddr32_t)src->pr_addr;
756 758 dst->pr_wchan = (caddr32_t)src->pr_wchan;
757 759 dst->pr_stype = src->pr_stype;
758 760 dst->pr_state = src->pr_state;
759 761 dst->pr_sname = src->pr_sname;
760 762 dst->pr_nice = src->pr_nice;
761 763 dst->pr_syscall = src->pr_syscall;
762 764 dst->pr_oldpri = src->pr_oldpri;
763 765 dst->pr_cpu = src->pr_cpu;
764 766 dst->pr_pri = src->pr_pri;
765 767 dst->pr_pctcpu = src->pr_pctcpu;
766 768
767 769 timestruc_n_to_32(&src->pr_start, &dst->pr_start);
768 770 timestruc_n_to_32(&src->pr_time, &dst->pr_time);
769 771
770 772 (void) memcpy(&dst->pr_clname[0], &src->pr_clname[0], PRCLSZ);
771 773 (void) memcpy(&dst->pr_name[0], &src->pr_name[0], PRFNSZ);
772 774
773 775 dst->pr_onpro = src->pr_onpro;
774 776 dst->pr_bindpro = src->pr_bindpro;
775 777 dst->pr_bindpset = src->pr_bindpset;
776 778 dst->pr_lgrp = src->pr_lgrp;
777 779 }
778 780
779 781 void
780 782 psinfo_n_to_32(const psinfo_t *src, psinfo32_t *dst)
781 783 {
782 784 dst->pr_flag = src->pr_flag;
783 785 dst->pr_nlwp = src->pr_nlwp;
784 786 dst->pr_nzomb = src->pr_nzomb;
785 787 dst->pr_pid = (pid32_t)src->pr_pid;
786 788 dst->pr_pgid = (pid32_t)src->pr_pgid;
787 789 dst->pr_sid = (pid32_t)src->pr_sid;
788 790 dst->pr_taskid = (id32_t)src->pr_taskid;
789 791 dst->pr_projid = (id32_t)src->pr_projid;
790 792 dst->pr_zoneid = (id32_t)src->pr_zoneid;
791 793 dst->pr_uid = (uid32_t)src->pr_uid;
792 794 dst->pr_euid = (uid32_t)src->pr_euid;
793 795 dst->pr_gid = (gid32_t)src->pr_gid;
794 796 dst->pr_egid = (gid32_t)src->pr_egid;
795 797 dst->pr_addr = (caddr32_t)src->pr_addr;
796 798 dst->pr_size = (size32_t)src->pr_size;
797 799 dst->pr_rssize = (size32_t)src->pr_rssize;
798 800
799 801 dst->pr_ttydev = prcmpldev(src->pr_ttydev);
800 802
801 803 dst->pr_pctcpu = src->pr_pctcpu;
802 804 dst->pr_pctmem = src->pr_pctmem;
803 805
804 806 timestruc_n_to_32(&src->pr_start, &dst->pr_start);
805 807 timestruc_n_to_32(&src->pr_time, &dst->pr_time);
806 808 timestruc_n_to_32(&src->pr_ctime, &dst->pr_ctime);
807 809
808 810 (void) memcpy(&dst->pr_fname[0], &src->pr_fname[0], PRFNSZ);
809 811 (void) memcpy(&dst->pr_psargs[0], &src->pr_psargs[0], PRARGSZ);
810 812
811 813 dst->pr_wstat = src->pr_wstat;
812 814 dst->pr_argc = src->pr_argc;
813 815 dst->pr_argv = (caddr32_t)src->pr_argv;
814 816 dst->pr_envp = (caddr32_t)src->pr_envp;
815 817 dst->pr_dmodel = src->pr_dmodel;
816 818
817 819 lwpsinfo_n_to_32(&src->pr_lwp, &dst->pr_lwp);
818 820 }
819 821
820 822
821 823 #endif /* _LP64 */
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX