4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/thread.h>
32 #include <sys/sysmacros.h>
33 #include <sys/signal.h>
36 #include <sys/errno.h>
37 #include <sys/vnode.h>
41 #include <sys/pathname.h>
42 #include <sys/cmn_err.h>
43 #include <sys/systm.h>
45 #include <sys/vmsystm.h>
46 #include <sys/debug.h>
47 #include <sys/old_procfs.h>
50 #include <sys/prsystm.h>
53 #include <sys/modctl.h>
54 #include <sys/systeminfo.h>
55 #include <sys/machelf.h>
59 extern void oprgetstatus(kthread_t
*, prstatus_t
*, zone_t
*);
60 extern void oprgetpsinfo(proc_t
*, prpsinfo_t
*, kthread_t
*);
63 setup_old_note_header(Phdr
*v
, proc_t
*p
)
65 int nlwp
= p
->p_lwpcnt
;
68 v
[0].p_type
= PT_NOTE
;
70 v
[0].p_filesz
= (sizeof (Note
) * (3 + nlwp
))
71 + roundup(sizeof (prpsinfo_t
), sizeof (Word
))
72 + roundup(strlen(platform
) + 1, sizeof (Word
))
73 + roundup(__KERN_NAUXV_IMPL
* sizeof (aux_entry_t
),
75 + nlwp
* roundup(sizeof (prstatus_t
), sizeof (Word
));
77 v
[0].p_filesz
+= nlwp
* sizeof (Note
)
78 + nlwp
*roundup(sizeof (prfpregset_t
), sizeof (Word
));
79 if ((size
= prhasx(p
)? prgetprxregsize(p
) : 0) != 0)
80 v
[0].p_filesz
+= nlwp
* sizeof (Note
)
81 + nlwp
* roundup(size
, sizeof (Word
));
86 write_old_elfnotes(proc_t
*p
, int sig
, vnode_t
*vp
, offset_t offset
,
87 rlim64_t rlimit
, cred_t
*credp
)
94 aux_entry_t auxv
[__KERN_NAUXV_IMPL
];
96 int xregsize
= prhasx(p
)? prgetprxregsize(p
) : 0;
97 size_t bigsize
= MAX(sizeof (*bigwad
), (size_t)xregsize
);
105 bigwad
= kmem_alloc(bigsize
, KM_SLEEP
);
108 * The order of the elfnote entries should be same here and in
109 * the gcore(1) command. Synchronization is needed between the
110 * kernel and libproc's Pfgcore() function where the meat of
111 * the gcore(1) command lives.
114 mutex_enter(&p
->p_lock
);
115 oprgetpsinfo(p
, &bigwad
->psinfo
, NULL
);
116 mutex_exit(&p
->p_lock
);
117 error
= elfnote(vp
, &offset
, NT_PRPSINFO
, sizeof (bigwad
->psinfo
),
118 (caddr_t
)&bigwad
->psinfo
, rlimit
, credp
);
122 error
= elfnote(vp
, &offset
, NT_PLATFORM
, strlen(platform
) + 1,
123 platform
, rlimit
, credp
);
128 for (i
= 0; i
< __KERN_NAUXV_IMPL
; i
++) {
129 bigwad
->auxv
[i
].a_type
= up
->u_auxv
[i
].a_type
;
130 bigwad
->auxv
[i
].a_un
.a_val
= up
->u_auxv
[i
].a_un
.a_val
;
132 error
= elfnote(vp
, &offset
, NT_AUXV
, sizeof (bigwad
->auxv
),
133 (caddr_t
)bigwad
->auxv
, rlimit
, credp
);
144 mutex_enter(&p
->p_lock
);
145 if (t
== curthread
) {
149 * Modify t_whystop and lwp_cursig so it appears that
150 * the current LWP is stopped after faulting on the
151 * signal that caused the core dump. As a result,
152 * oprgetstatus() will record that signal, the saved
153 * lwp_siginfo, and its signal handler in the core file
154 * status. We restore lwp_cursig in case a subsequent
155 * signal was received while dumping core.
157 oldsig
= lwp
->lwp_cursig
;
158 lwp
->lwp_cursig
= (uchar_t
)sig
;
159 t
->t_whystop
= PR_FAULTED
;
161 oprgetstatus(t
, &bigwad
->prstat
, p
->p_zone
);
162 bigwad
->prstat
.pr_why
= 0;
165 lwp
->lwp_cursig
= oldsig
;
168 oprgetstatus(t
, &bigwad
->prstat
, p
->p_zone
);
170 mutex_exit(&p
->p_lock
);
171 error
= elfnote(vp
, &offset
, NT_PRSTATUS
,
172 sizeof (bigwad
->prstat
), (caddr_t
)&bigwad
->prstat
,
178 prgetprfpregs(lwp
, &bigwad
->fpregs
);
179 error
= elfnote(vp
, &offset
, NT_PRFPREG
,
180 sizeof (bigwad
->fpregs
), (caddr_t
)&bigwad
->fpregs
,
188 prgetprxregs(lwp
, bigwad
->xregs
);
189 error
= elfnote(vp
, &offset
, NT_PRXREG
,
190 xregsize
, bigwad
->xregs
, rlimit
, credp
);
194 } while ((t
= t
->t_forw
) != curthread
);
198 kmem_free(bigwad
, bigsize
);