Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/exec/elf/old_notes.c
+++ new/usr/src/uts/common/exec/elf/old_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 #include <sys/types.h>
28 28 #include <sys/param.h>
29 29 #include <sys/thread.h>
30 30 #include <sys/sysmacros.h>
31 31 #include <sys/signal.h>
32 32 #include <sys/cred.h>
33 33 #include <sys/user.h>
34 34 #include <sys/errno.h>
35 35 #include <sys/vnode.h>
36 36 #include <sys/mman.h>
37 37 #include <sys/kmem.h>
38 38 #include <sys/proc.h>
39 39 #include <sys/pathname.h>
40 40 #include <sys/cmn_err.h>
41 41 #include <sys/systm.h>
42 42 #include <sys/elf.h>
43 43 #include <sys/vmsystm.h>
44 44 #include <sys/debug.h>
45 45 #include <sys/old_procfs.h>
46 46 #include <sys/auxv.h>
47 47 #include <sys/exec.h>
48 48 #include <sys/prsystm.h>
49 49 #include <vm/as.h>
50 50 #include <vm/rm.h>
51 51 #include <sys/modctl.h>
52 52 #include <sys/systeminfo.h>
53 53 #include <sys/machelf.h>
54 54 #include <sys/zone.h>
55 55 #include "elf_impl.h"
56 56
57 57 extern void oprgetstatus(kthread_t *, prstatus_t *, zone_t *);
58 58 extern void oprgetpsinfo(proc_t *, prpsinfo_t *, kthread_t *);
59 59
60 60 /*
61 61 * Historically the system dumped the xreg note when on SPARC. Because we no
62 62 * longer support SPARC we do not dump the old note form of the xregs for any
63 63 * additional platforms. Please do not add this back unless it's for SPARC's
64 64 * future resurrection.
65 65 */
66 66 void
67 67 setup_old_note_header(Phdr *v, proc_t *p)
68 68 {
69 69 int nlwp = p->p_lwpcnt;
70 70
71 71 v[0].p_type = PT_NOTE;
72 72 v[0].p_flags = PF_R;
73 73 v[0].p_filesz = (sizeof (Note) * (3 + nlwp))
74 74 + roundup(sizeof (prpsinfo_t), sizeof (Word))
75 75 + roundup(strlen(platform) + 1, sizeof (Word))
76 76 + roundup(__KERN_NAUXV_IMPL * sizeof (aux_entry_t),
77 77 sizeof (Word))
78 78 + nlwp * roundup(sizeof (prstatus_t), sizeof (Word));
79 79 if (prhasfp()) {
80 80 v[0].p_filesz += nlwp * sizeof (Note) +
81 81 nlwp * roundup(sizeof (prfpregset_t), sizeof (Word));
82 82 }
83 83 }
84 84
85 85 int
86 86 write_old_elfnotes(proc_t *p, int sig, vnode_t *vp, offset_t offset,
87 87 rlim64_t rlimit, cred_t *credp)
88 88 {
89 89 union {
90 90 prpsinfo_t psinfo;
91 91 prstatus_t prstat;
92 92 prfpregset_t fpregs;
93 93 aux_entry_t auxv[__KERN_NAUXV_IMPL];
94 94 } *bigwad;
95 95 size_t bigsize = sizeof (*bigwad);
96 96 kthread_t *t;
97 97 klwp_t *lwp;
98 98 user_t *up;
99 99 int i;
100 100 int nlwp;
101 101 int error;
102 102
103 103 bigwad = kmem_alloc(bigsize, KM_SLEEP);
104 104
105 105 /*
106 106 * The order of the elfnote entries should be same here and in
107 107 * the gcore(1) command. Synchronization is needed between the
108 108 * kernel and libproc's Pfgcore() function where the meat of
109 109 * the gcore(1) command lives.
110 110 */
111 111
112 112 mutex_enter(&p->p_lock);
113 113 oprgetpsinfo(p, &bigwad->psinfo, NULL);
114 114 mutex_exit(&p->p_lock);
115 115 error = elfnote(vp, &offset, NT_PRPSINFO, sizeof (bigwad->psinfo),
116 116 (caddr_t)&bigwad->psinfo, rlimit, credp);
117 117 if (error)
118 118 goto done;
119 119
120 120 error = elfnote(vp, &offset, NT_PLATFORM, strlen(platform) + 1,
121 121 platform, rlimit, credp);
122 122 if (error)
123 123 goto done;
124 124
125 125 up = PTOU(p);
126 126 for (i = 0; i < __KERN_NAUXV_IMPL; i++) {
127 127 bigwad->auxv[i].a_type = up->u_auxv[i].a_type;
128 128 bigwad->auxv[i].a_un.a_val = up->u_auxv[i].a_un.a_val;
129 129 }
130 130 error = elfnote(vp, &offset, NT_AUXV, sizeof (bigwad->auxv),
131 131 (caddr_t)bigwad->auxv, rlimit, credp);
132 132 if (error)
133 133 goto done;
134 134
135 135 t = curthread;
136 136 nlwp = p->p_lwpcnt;
137 137 do {
138 138 ASSERT(nlwp != 0);
139 139 nlwp--;
140 140 lwp = ttolwp(t);
141 141
142 142 mutex_enter(&p->p_lock);
143 143 if (t == curthread) {
144 144 uchar_t oldsig;
145 145
146 146 /*
147 147 * Modify t_whystop and lwp_cursig so it appears that
148 148 * the current LWP is stopped after faulting on the
149 149 * signal that caused the core dump. As a result,
150 150 * oprgetstatus() will record that signal, the saved
151 151 * lwp_siginfo, and its signal handler in the core file
152 152 * status. We restore lwp_cursig in case a subsequent
153 153 * signal was received while dumping core.
154 154 */
155 155 oldsig = lwp->lwp_cursig;
156 156 lwp->lwp_cursig = (uchar_t)sig;
157 157 t->t_whystop = PR_FAULTED;
158 158
159 159 oprgetstatus(t, &bigwad->prstat, p->p_zone);
160 160 bigwad->prstat.pr_why = 0;
161 161
162 162 t->t_whystop = 0;
163 163 lwp->lwp_cursig = oldsig;
164 164
165 165 } else {
166 166 oprgetstatus(t, &bigwad->prstat, p->p_zone);
167 167 }
168 168 mutex_exit(&p->p_lock);
169 169 error = elfnote(vp, &offset, NT_PRSTATUS,
170 170 sizeof (bigwad->prstat), (caddr_t)&bigwad->prstat,
171 171 rlimit, credp);
172 172 if (error)
173 173 goto done;
174 174
175 175 if (prhasfp()) {
176 176 prgetprfpregs(lwp, &bigwad->fpregs);
177 177 error = elfnote(vp, &offset, NT_PRFPREG,
178 178 sizeof (bigwad->fpregs), (caddr_t)&bigwad->fpregs,
179 179 rlimit, credp);
180 180 if (error)
181 181 goto done;
182 182 }
183 183 } while ((t = t->t_forw) != curthread);
184 184 ASSERT(nlwp == 0);
185 185
186 186 done:
187 187 kmem_free(bigwad, bigsize);
188 188 return (error);
189 189 }
|
↓ open down ↓ |
189 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX