Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/exec/elf/elf_notes.c
+++ new/usr/src/uts/common/exec/elf/elf_notes.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, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
29 29 * Copyright 2018 Joyent, Inc.
30 30 * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
31 31 * Copyright 2023 Oxide Computer Company
32 32 */
33 33
34 34 #include <sys/types.h>
35 35 #include <sys/param.h>
36 36 #include <sys/thread.h>
37 37 #include <sys/sysmacros.h>
38 38 #include <sys/signal.h>
39 39 #include <sys/cred.h>
40 40 #include <sys/priv.h>
41 41 #include <sys/user.h>
42 42 #include <sys/file.h>
43 43 #include <sys/errno.h>
44 44 #include <sys/vnode.h>
45 45 #include <sys/mode.h>
46 46 #include <sys/vfs.h>
47 47 #include <sys/mman.h>
48 48 #include <sys/kmem.h>
49 49 #include <sys/proc.h>
50 50 #include <sys/pathname.h>
51 51 #include <sys/cmn_err.h>
52 52 #include <sys/systm.h>
53 53 #include <sys/elf.h>
54 54 #include <sys/vmsystm.h>
55 55 #include <sys/debug.h>
56 56 #include <sys/procfs.h>
57 57 #include <sys/regset.h>
58 58 #include <sys/auxv.h>
59 59 #include <sys/exec.h>
60 60 #include <sys/prsystm.h>
61 61 #include <sys/utsname.h>
62 62 #include <sys/zone.h>
63 63 #include <vm/as.h>
64 64 #include <vm/rm.h>
65 65 #include <sys/modctl.h>
66 66 #include <sys/systeminfo.h>
67 67 #include <sys/machelf.h>
68 68 #include <sys/sunddi.h>
69 69 #include "elf_impl.h"
70 70 #if defined(__i386_COMPAT)
71 71 #include <sys/sysi86.h>
72 72 #endif
73 73
74 74 void
75 75 setup_note_header(Phdr *v, proc_t *p)
76 76 {
77 77 int nlwp = p->p_lwpcnt;
78 78 int nzomb = p->p_zombcnt;
79 79 int nfd;
80 80 size_t size;
81 81 prcred_t *pcrp;
82 82 uf_info_t *fip;
83 83 uf_entry_t *ufp;
84 84 int fd;
85 85
86 86 fip = P_FINFO(p);
87 87 nfd = 0;
88 88 mutex_enter(&fip->fi_lock);
89 89 for (fd = 0; fd < fip->fi_nfiles; fd++) {
90 90 UF_ENTER(ufp, fip, fd);
91 91 if ((ufp->uf_file != NULL) && (ufp->uf_file->f_count > 0))
92 92 nfd++;
93 93 UF_EXIT(ufp);
94 94 }
95 95 mutex_exit(&fip->fi_lock);
96 96
97 97 v[0].p_type = PT_NOTE;
98 98 v[0].p_flags = PF_R;
99 99 v[0].p_filesz = (sizeof (Note) * (10 + 3 * nlwp + nzomb + nfd))
100 100 + roundup(sizeof (psinfo_t), sizeof (Word))
101 101 + roundup(sizeof (pstatus_t), sizeof (Word))
102 102 + roundup(prgetprivsize(), sizeof (Word))
103 103 + roundup(priv_get_implinfo_size(), sizeof (Word))
104 104 + roundup(strlen(platform) + 1, sizeof (Word))
105 105 + roundup(strlen(p->p_zone->zone_name) + 1, sizeof (Word))
106 106 + roundup(__KERN_NAUXV_IMPL * sizeof (aux_entry_t), sizeof (Word))
107 107 + roundup(sizeof (utsname), sizeof (Word))
108 108 + roundup(sizeof (core_content_t), sizeof (Word))
109 109 + roundup(sizeof (prsecflags_t), sizeof (Word))
110 110 + (nlwp + nzomb) * roundup(sizeof (lwpsinfo_t), sizeof (Word))
111 111 + nlwp * roundup(sizeof (lwpstatus_t), sizeof (Word))
112 112 + nlwp * roundup(sizeof (prlwpname_t), sizeof (Word))
113 113 + nfd * roundup(sizeof (prfdinfo_core_t), sizeof (Word));
114 114
115 115 if (curproc->p_agenttp != NULL) {
116 116 v[0].p_filesz += sizeof (Note) +
117 117 roundup(sizeof (psinfo_t), sizeof (Word));
118 118 }
119 119
120 120 size = sizeof (prcred_t) + sizeof (gid_t) * (ngroups_max - 1);
121 121 pcrp = kmem_alloc(size, KM_SLEEP);
122 122 prgetcred(p, pcrp);
123 123 if (pcrp->pr_ngroups != 0) {
124 124 v[0].p_filesz += sizeof (Note) + roundup(sizeof (prcred_t) +
125 125 sizeof (gid_t) * (pcrp->pr_ngroups - 1), sizeof (Word));
126 126 } else {
127 127 v[0].p_filesz += sizeof (Note) +
128 128 roundup(sizeof (prcred_t), sizeof (Word));
129 129 }
130 130 kmem_free(pcrp, size);
131 131
132 132
133 133 #if defined(__i386_COMPAT)
134 134 mutex_enter(&p->p_ldtlock);
135 135 size = prnldt(p) * sizeof (struct ssd);
136 136 mutex_exit(&p->p_ldtlock);
137 137 if (size != 0)
138 138 v[0].p_filesz += sizeof (Note) + roundup(size, sizeof (Word));
139 139 #endif /* __i386_COMPAT */
140 140
141 141 if ((size = prhasx(p) ? prgetprxregsize(p) : 0) != 0)
142 142 v[0].p_filesz += nlwp * sizeof (Note)
143 143 + nlwp * roundup(size, sizeof (Word));
144 144
145 145 #if defined(__sparc)
146 146 /*
147 147 * Figure out the number and sizes of register windows.
148 148 */
149 149 {
150 150 kthread_t *t = p->p_tlist;
151 151 do {
152 152 if ((size = prnwindows(ttolwp(t))) != 0) {
153 153 size = sizeof (gwindows_t) -
154 154 (SPARC_MAXREGWINDOW - size) *
155 155 sizeof (struct rwindow);
156 156 v[0].p_filesz += sizeof (Note) +
157 157 roundup(size, sizeof (Word));
158 158 }
159 159 } while ((t = t->t_forw) != p->p_tlist);
160 160 }
161 161 /*
162 162 * Space for the Ancillary State Registers.
163 163 */
164 164 if (p->p_model == DATAMODEL_LP64)
165 165 v[0].p_filesz += nlwp * sizeof (Note)
166 166 + nlwp * roundup(sizeof (asrset_t), sizeof (Word));
167 167 #endif /* __sparc */
168 168
169 169 mutex_enter(&p->p_lock);
170 170 if ((p->p_upanicflag & P_UPF_PANICKED) != 0) {
171 171 v[0].p_filesz += sizeof (Note) +
172 172 roundup(sizeof (prupanic_t), sizeof (Word));
173 173 }
174 174 mutex_exit(&p->p_lock);
175 175 }
176 176
177 177 int
178 178 write_elfnotes(proc_t *p, int sig, vnode_t *vp, offset_t offset,
179 179 rlim64_t rlimit, cred_t *credp, core_content_t content)
180 180 {
181 181 union {
182 182 psinfo_t psinfo;
183 183 pstatus_t pstatus;
184 184 lwpsinfo_t lwpsinfo;
185 185 lwpstatus_t lwpstatus;
186 186 #if defined(__sparc)
187 187 gwindows_t gwindows;
188 188 asrset_t asrset;
189 189 #endif /* __sparc */
190 190 char xregs[1];
191 191 aux_entry_t auxv[__KERN_NAUXV_IMPL];
192 192 prcred_t pcred;
193 193 prpriv_t ppriv;
194 194 priv_impl_info_t prinfo;
195 195 struct utsname uts;
196 196 prsecflags_t psecflags;
197 197 prupanic_t upanic;
198 198 } *bigwad;
199 199
200 200 size_t xregsize = prhasx(p) ? prgetprxregsize(p) : 0;
201 201 size_t crsize = sizeof (prcred_t) + sizeof (gid_t) * (ngroups_max - 1);
202 202 size_t psize = prgetprivsize();
203 203 size_t bigsize = MAX(psize, MAX(sizeof (*bigwad),
204 204 MAX(xregsize, crsize)));
205 205
206 206 priv_impl_info_t *prii;
207 207
208 208 lwpdir_t *ldp;
209 209 lwpent_t *lep;
210 210 kthread_t *t;
211 211 klwp_t *lwp;
212 212 user_t *up;
213 213 int i;
214 214 int nlwp;
215 215 int nzomb;
216 216 int error;
217 217 uchar_t oldsig;
218 218 uf_info_t *fip;
219 219 int fd;
220 220 vnode_t *vroot;
221 221
222 222 #if defined(__i386_COMPAT)
223 223 struct ssd *ssd;
224 224 size_t ssdsize;
225 225 #endif /* __i386_COMPAT */
226 226
227 227 bigsize = MAX(bigsize, priv_get_implinfo_size());
228 228
229 229 bigwad = kmem_alloc(bigsize, KM_SLEEP);
230 230
231 231 /*
232 232 * The order of the elfnote entries should be same here
233 233 * and in the gcore(1) command. Synchronization is
234 234 * needed between the kernel and gcore(1).
235 235 */
236 236
237 237 /*
238 238 * Get the psinfo, and set the wait status to indicate that a core was
239 239 * dumped. We have to forge this since p->p_wcode is not set yet.
240 240 */
241 241 mutex_enter(&p->p_lock);
242 242 prgetpsinfo(p, &bigwad->psinfo);
243 243 mutex_exit(&p->p_lock);
244 244 bigwad->psinfo.pr_wstat = wstat(CLD_DUMPED, sig);
245 245
246 246 error = elfnote(vp, &offset, NT_PSINFO, sizeof (bigwad->psinfo),
247 247 (caddr_t)&bigwad->psinfo, rlimit, credp);
248 248 if (error)
249 249 goto done;
250 250
251 251 /*
252 252 * Modify t_whystop and lwp_cursig so it appears that the current LWP
253 253 * is stopped after faulting on the signal that caused the core dump.
254 254 * As a result, prgetstatus() will record that signal, the saved
255 255 * lwp_siginfo, and its signal handler in the core file status. We
256 256 * restore lwp_cursig in case a subsequent signal was received while
257 257 * dumping core.
258 258 */
259 259 mutex_enter(&p->p_lock);
260 260 lwp = ttolwp(curthread);
261 261
262 262 oldsig = lwp->lwp_cursig;
263 263 lwp->lwp_cursig = (uchar_t)sig;
264 264 curthread->t_whystop = PR_FAULTED;
265 265
266 266 prgetstatus(p, &bigwad->pstatus, p->p_zone);
267 267 bigwad->pstatus.pr_lwp.pr_why = 0;
268 268
269 269 curthread->t_whystop = 0;
270 270 lwp->lwp_cursig = oldsig;
271 271 mutex_exit(&p->p_lock);
272 272
273 273 error = elfnote(vp, &offset, NT_PSTATUS, sizeof (bigwad->pstatus),
274 274 (caddr_t)&bigwad->pstatus, rlimit, credp);
275 275 if (error)
276 276 goto done;
277 277
278 278 error = elfnote(vp, &offset, NT_PLATFORM, strlen(platform) + 1,
279 279 platform, rlimit, credp);
280 280 if (error)
281 281 goto done;
282 282
283 283 up = PTOU(p);
284 284 for (i = 0; i < __KERN_NAUXV_IMPL; i++) {
285 285 bigwad->auxv[i].a_type = up->u_auxv[i].a_type;
286 286 bigwad->auxv[i].a_un.a_val = up->u_auxv[i].a_un.a_val;
287 287 }
288 288 error = elfnote(vp, &offset, NT_AUXV, sizeof (bigwad->auxv),
289 289 (caddr_t)bigwad->auxv, rlimit, credp);
290 290 if (error)
291 291 goto done;
292 292
293 293 bcopy(&utsname, &bigwad->uts, sizeof (struct utsname));
294 294 if (!INGLOBALZONE(p)) {
295 295 bcopy(p->p_zone->zone_nodename, &bigwad->uts.nodename,
296 296 _SYS_NMLN);
297 297 }
298 298 error = elfnote(vp, &offset, NT_UTSNAME, sizeof (struct utsname),
299 299 (caddr_t)&bigwad->uts, rlimit, credp);
300 300 if (error)
301 301 goto done;
302 302
303 303 prgetsecflags(p, &bigwad->psecflags);
304 304 error = elfnote(vp, &offset, NT_SECFLAGS, sizeof (prsecflags_t),
305 305 (caddr_t)&bigwad->psecflags, rlimit, credp);
306 306 if (error)
307 307 goto done;
308 308
309 309 prgetcred(p, &bigwad->pcred);
310 310
311 311 if (bigwad->pcred.pr_ngroups != 0) {
312 312 crsize = sizeof (prcred_t) +
313 313 sizeof (gid_t) * (bigwad->pcred.pr_ngroups - 1);
314 314 } else
315 315 crsize = sizeof (prcred_t);
316 316
317 317 error = elfnote(vp, &offset, NT_PRCRED, crsize,
318 318 (caddr_t)&bigwad->pcred, rlimit, credp);
319 319 if (error)
320 320 goto done;
321 321
322 322 error = elfnote(vp, &offset, NT_CONTENT, sizeof (core_content_t),
323 323 (caddr_t)&content, rlimit, credp);
324 324 if (error)
325 325 goto done;
326 326
327 327 prgetpriv(p, &bigwad->ppriv);
328 328
329 329 error = elfnote(vp, &offset, NT_PRPRIV, psize,
330 330 (caddr_t)&bigwad->ppriv, rlimit, credp);
331 331 if (error)
332 332 goto done;
333 333
334 334 prii = priv_hold_implinfo();
335 335 error = elfnote(vp, &offset, NT_PRPRIVINFO, priv_get_implinfo_size(),
336 336 (caddr_t)prii, rlimit, credp);
337 337 priv_release_implinfo();
338 338 if (error)
339 339 goto done;
|
↓ open down ↓ |
339 lines elided |
↑ open up ↑ |
340 340
341 341 /* zone can't go away as long as process exists */
342 342 error = elfnote(vp, &offset, NT_ZONENAME,
343 343 strlen(p->p_zone->zone_name) + 1, p->p_zone->zone_name,
344 344 rlimit, credp);
345 345 if (error)
346 346 goto done;
347 347
348 348
349 349 /* open file table */
350 + mutex_enter(&p->p_lock);
350 351 vroot = PTOU(p)->u_rdir;
351 352 if (vroot == NULL)
352 353 vroot = rootdir;
353 354
354 355 VN_HOLD(vroot);
356 + mutex_exit(&p->p_lock);
355 357
356 358 fip = P_FINFO(p);
357 359
358 360 for (fd = 0; fd < fip->fi_nfiles; fd++) {
359 361 uf_entry_t *ufp;
360 362 vnode_t *fvp;
361 363 struct file *fp;
362 364 vattr_t vattr;
363 365 prfdinfo_core_t fdinfo;
364 366
365 367 bzero(&fdinfo, sizeof (fdinfo));
366 368
367 369 mutex_enter(&fip->fi_lock);
368 370 UF_ENTER(ufp, fip, fd);
369 371 if (((fp = ufp->uf_file) == NULL) || (fp->f_count < 1)) {
370 372 UF_EXIT(ufp);
371 373 mutex_exit(&fip->fi_lock);
372 374 continue;
373 375 }
374 376
375 377 fdinfo.pr_fd = fd;
376 378 fdinfo.pr_fdflags = ufp->uf_flag;
377 379 fdinfo.pr_fileflags = fp->f_flag2;
378 380 fdinfo.pr_fileflags <<= 16;
379 381 fdinfo.pr_fileflags |= fp->f_flag;
380 382 if ((fdinfo.pr_fileflags & (FSEARCH | FEXEC)) == 0)
381 383 fdinfo.pr_fileflags += FOPEN;
382 384 fdinfo.pr_offset = fp->f_offset;
383 385
384 386
385 387 fvp = fp->f_vnode;
386 388 VN_HOLD(fvp);
387 389 UF_EXIT(ufp);
388 390 mutex_exit(&fip->fi_lock);
389 391
390 392 /*
391 393 * There are some vnodes that have no corresponding
392 394 * path. Its reasonable for this to fail, in which
393 395 * case the path will remain an empty string.
394 396 */
395 397 (void) vnodetopath(vroot, fvp, fdinfo.pr_path,
396 398 sizeof (fdinfo.pr_path), credp);
397 399
398 400 if (VOP_GETATTR(fvp, &vattr, 0, credp, NULL) != 0) {
399 401 /*
400 402 * Try to write at least a subset of information
401 403 */
402 404 fdinfo.pr_major = 0;
403 405 fdinfo.pr_minor = 0;
404 406 fdinfo.pr_ino = 0;
405 407 fdinfo.pr_mode = 0;
406 408 fdinfo.pr_uid = (uid_t)-1;
407 409 fdinfo.pr_gid = (gid_t)-1;
408 410 fdinfo.pr_rmajor = 0;
409 411 fdinfo.pr_rminor = 0;
410 412 fdinfo.pr_size = -1;
411 413
412 414 error = elfnote(vp, &offset, NT_FDINFO,
413 415 sizeof (fdinfo), &fdinfo, rlimit, credp);
414 416 VN_RELE(fvp);
415 417 if (error) {
416 418 VN_RELE(vroot);
417 419 goto done;
418 420 }
419 421 continue;
420 422 }
421 423
422 424 if (fvp->v_type == VSOCK)
423 425 fdinfo.pr_fileflags |= sock_getfasync(fvp);
424 426
425 427 VN_RELE(fvp);
426 428
427 429 /*
428 430 * This logic mirrors fstat(), which we cannot use
429 431 * directly, as it calls copyout().
430 432 */
431 433 fdinfo.pr_major = getmajor(vattr.va_fsid);
432 434 fdinfo.pr_minor = getminor(vattr.va_fsid);
433 435 fdinfo.pr_ino = (ino64_t)vattr.va_nodeid;
434 436 fdinfo.pr_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
435 437 fdinfo.pr_uid = vattr.va_uid;
436 438 fdinfo.pr_gid = vattr.va_gid;
437 439 fdinfo.pr_rmajor = getmajor(vattr.va_rdev);
438 440 fdinfo.pr_rminor = getminor(vattr.va_rdev);
439 441 fdinfo.pr_size = (off64_t)vattr.va_size;
440 442
441 443 error = elfnote(vp, &offset, NT_FDINFO,
442 444 sizeof (fdinfo), &fdinfo, rlimit, credp);
443 445 if (error) {
444 446 VN_RELE(vroot);
445 447 goto done;
446 448 }
447 449 }
448 450
449 451 VN_RELE(vroot);
450 452
451 453 #if defined(__i386_COMPAT)
452 454 mutex_enter(&p->p_ldtlock);
453 455 ssdsize = prnldt(p) * sizeof (struct ssd);
454 456 if (ssdsize != 0) {
455 457 ssd = kmem_alloc(ssdsize, KM_SLEEP);
456 458 prgetldt(p, ssd);
457 459 error = elfnote(vp, &offset, NT_LDT, ssdsize,
458 460 (caddr_t)ssd, rlimit, credp);
459 461 kmem_free(ssd, ssdsize);
460 462 }
461 463 mutex_exit(&p->p_ldtlock);
462 464 if (error)
463 465 goto done;
464 466 #endif /* defined(__i386_COMPAT) */
465 467
466 468 nlwp = p->p_lwpcnt;
467 469 nzomb = p->p_zombcnt;
468 470 /* for each entry in the lwp directory ... */
469 471 for (ldp = p->p_lwpdir; nlwp + nzomb != 0; ldp++) {
470 472 prlwpname_t name = { 0, };
471 473
472 474 if ((lep = ldp->ld_entry) == NULL) /* empty slot */
473 475 continue;
474 476
475 477 if ((t = lep->le_thread) != NULL) { /* active lwp */
476 478 ASSERT(nlwp != 0);
477 479 nlwp--;
478 480 lwp = ttolwp(t);
479 481 mutex_enter(&p->p_lock);
480 482 prgetlwpsinfo(t, &bigwad->lwpsinfo);
481 483 if (t->t_name != NULL) {
482 484 (void) strlcpy(name.pr_lwpname, t->t_name,
483 485 sizeof (name.pr_lwpname));
484 486 }
485 487 mutex_exit(&p->p_lock);
486 488 } else { /* zombie lwp */
487 489 ASSERT(nzomb != 0);
488 490 nzomb--;
489 491 bzero(&bigwad->lwpsinfo, sizeof (bigwad->lwpsinfo));
490 492 bigwad->lwpsinfo.pr_lwpid = lep->le_lwpid;
491 493 bigwad->lwpsinfo.pr_state = SZOMB;
492 494 bigwad->lwpsinfo.pr_sname = 'Z';
493 495 bigwad->lwpsinfo.pr_start.tv_sec = lep->le_start;
494 496 }
495 497
496 498 name.pr_lwpid = bigwad->lwpsinfo.pr_lwpid;
497 499
498 500 error = elfnote(vp, &offset, NT_LWPSINFO,
499 501 sizeof (bigwad->lwpsinfo), (caddr_t)&bigwad->lwpsinfo,
500 502 rlimit, credp);
501 503 if (error)
502 504 goto done;
503 505
504 506 if (t == NULL) /* nothing more to do for a zombie */
505 507 continue;
506 508
507 509 mutex_enter(&p->p_lock);
508 510 if (t == curthread) {
509 511 /*
510 512 * Modify t_whystop and lwp_cursig so it appears that
511 513 * the current LWP is stopped after faulting on the
512 514 * signal that caused the core dump. As a result,
513 515 * prgetlwpstatus() will record that signal, the saved
514 516 * lwp_siginfo, and its signal handler in the core file
515 517 * status. We restore lwp_cursig in case a subsequent
516 518 * signal was received while dumping core.
517 519 */
518 520 oldsig = lwp->lwp_cursig;
519 521 lwp->lwp_cursig = (uchar_t)sig;
520 522 t->t_whystop = PR_FAULTED;
521 523
522 524 prgetlwpstatus(t, &bigwad->lwpstatus, p->p_zone);
523 525 bigwad->lwpstatus.pr_why = 0;
524 526
525 527 t->t_whystop = 0;
526 528 lwp->lwp_cursig = oldsig;
527 529 } else {
528 530 prgetlwpstatus(t, &bigwad->lwpstatus, p->p_zone);
529 531 }
530 532 mutex_exit(&p->p_lock);
531 533 error = elfnote(vp, &offset, NT_LWPSTATUS,
532 534 sizeof (bigwad->lwpstatus), (caddr_t)&bigwad->lwpstatus,
533 535 rlimit, credp);
534 536 if (error)
535 537 goto done;
536 538
537 539 if ((error = elfnote(vp, &offset, NT_LWPNAME, sizeof (name),
538 540 (caddr_t)&name, rlimit, credp)) != 0)
539 541 goto done;
540 542
541 543
542 544 #if defined(__sparc)
543 545 /*
544 546 * Unspilled SPARC register windows.
545 547 */
546 548 {
547 549 size_t size = prnwindows(lwp);
548 550
549 551 if (size != 0) {
550 552 size = sizeof (gwindows_t) -
551 553 (SPARC_MAXREGWINDOW - size) *
552 554 sizeof (struct rwindow);
553 555 prgetwindows(lwp, &bigwad->gwindows);
554 556 error = elfnote(vp, &offset, NT_GWINDOWS,
555 557 size, (caddr_t)&bigwad->gwindows,
556 558 rlimit, credp);
557 559 if (error)
558 560 goto done;
559 561 }
560 562 }
561 563 /*
562 564 * Ancillary State Registers.
563 565 */
564 566 if (p->p_model == DATAMODEL_LP64) {
565 567 prgetasregs(lwp, bigwad->asrset);
566 568 error = elfnote(vp, &offset, NT_ASRS,
567 569 sizeof (asrset_t), (caddr_t)bigwad->asrset,
568 570 rlimit, credp);
569 571 if (error)
570 572 goto done;
571 573 }
572 574 #endif /* __sparc */
573 575
574 576 if (xregsize) {
575 577 prgetprxregs(lwp, (prxregset_t *)bigwad->xregs);
576 578 error = elfnote(vp, &offset, NT_PRXREG,
577 579 xregsize, bigwad->xregs, rlimit, credp);
578 580 if (error)
579 581 goto done;
580 582 }
581 583
582 584 if (t->t_lwp->lwp_spymaster != NULL) {
583 585 void *psaddr = t->t_lwp->lwp_spymaster;
584 586 #ifdef _ELF32_COMPAT
585 587 /*
586 588 * On a 64-bit kernel with 32-bit ELF compatibility,
587 589 * this file is compiled into two different objects:
588 590 * one is compiled normally, and the other is compiled
589 591 * with _ELF32_COMPAT set -- and therefore with a
590 592 * psinfo_t defined to be a psinfo32_t. However, the
591 593 * psinfo_t denoting our spymaster is always of the
592 594 * native type; if we are in the _ELF32_COMPAT case,
593 595 * we need to explicitly convert it.
594 596 */
595 597 if (p->p_model == DATAMODEL_ILP32) {
596 598 psinfo_kto32(psaddr, &bigwad->psinfo);
597 599 psaddr = &bigwad->psinfo;
598 600 }
599 601 #endif
600 602
601 603 error = elfnote(vp, &offset, NT_SPYMASTER,
602 604 sizeof (psinfo_t), psaddr, rlimit, credp);
603 605 if (error)
604 606 goto done;
605 607 }
606 608 }
607 609 ASSERT(nlwp == 0);
608 610
609 611 /*
610 612 * If a upanic occurred, add a note for it.
611 613 */
612 614 mutex_enter(&p->p_lock);
613 615 if ((p->p_upanicflag & P_UPF_PANICKED) != 0) {
614 616 bzero(&bigwad->upanic, sizeof (prupanic_t));
615 617 bigwad->upanic.pru_version = PRUPANIC_VERSION_1;
616 618 if ((p->p_upanicflag & P_UPF_INVALMSG) != 0) {
617 619 bigwad->upanic.pru_flags |= PRUPANIC_FLAG_MSG_ERROR;
618 620 }
619 621
620 622 if ((p->p_upanicflag & P_UPF_TRUNCMSG) != 0) {
621 623 bigwad->upanic.pru_flags |= PRUPANIC_FLAG_MSG_TRUNC;
622 624 }
623 625
624 626 if ((p->p_upanicflag & P_UPF_HAVEMSG) != 0) {
625 627 bigwad->upanic.pru_flags |= PRUPANIC_FLAG_MSG_VALID;
626 628 bcopy(p->p_upanic, bigwad->upanic.pru_data,
627 629 PRUPANIC_BUFLEN);
628 630 }
629 631
630 632 mutex_exit(&p->p_lock);
631 633 error = elfnote(vp, &offset, NT_UPANIC, sizeof (prupanic_t),
632 634 &bigwad->upanic, rlimit, credp);
633 635 if (error != 0) {
634 636 goto done;
635 637 }
636 638 } else {
637 639 mutex_exit(&p->p_lock);
638 640 }
639 641
640 642 done:
641 643 kmem_free(bigwad, bigsize);
642 644 return (error);
643 645 }
|
↓ open down ↓ |
279 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX