40 #include <sys/cmn_err.h>
41 #include <sys/systm.h>
42 #include <sys/elf.h>
43 #include <sys/vmsystm.h>
44 #include <sys/debug.h>
45 #include <sys/old_procfs.h>
46 #include <sys/auxv.h>
47 #include <sys/exec.h>
48 #include <sys/prsystm.h>
49 #include <vm/as.h>
50 #include <vm/rm.h>
51 #include <sys/modctl.h>
52 #include <sys/systeminfo.h>
53 #include <sys/machelf.h>
54 #include <sys/zone.h>
55 #include "elf_impl.h"
56
57 extern void oprgetstatus(kthread_t *, prstatus_t *, zone_t *);
58 extern void oprgetpsinfo(proc_t *, prpsinfo_t *, kthread_t *);
59
60 void
61 setup_old_note_header(Phdr *v, proc_t *p)
62 {
63 int nlwp = p->p_lwpcnt;
64 size_t size;
65
66 v[0].p_type = PT_NOTE;
67 v[0].p_flags = PF_R;
68 v[0].p_filesz = (sizeof (Note) * (3 + nlwp))
69 + roundup(sizeof (prpsinfo_t), sizeof (Word))
70 + roundup(strlen(platform) + 1, sizeof (Word))
71 + roundup(__KERN_NAUXV_IMPL * sizeof (aux_entry_t),
72 sizeof (Word))
73 + nlwp * roundup(sizeof (prstatus_t), sizeof (Word));
74 if (prhasfp())
75 v[0].p_filesz += nlwp * sizeof (Note)
76 + nlwp*roundup(sizeof (prfpregset_t), sizeof (Word));
77 if ((size = prhasx(p)? prgetprxregsize(p) : 0) != 0)
78 v[0].p_filesz += nlwp * sizeof (Note)
79 + nlwp * roundup(size, sizeof (Word));
80
81 #if defined(__sparc)
82 /*
83 * Figure out the number and sizes of register windows.
84 */
85 {
86 kthread_t *t = p->p_tlist;
87 do {
88 if ((size = prnwindows(ttolwp(t))) != 0) {
89 size = sizeof (gwindows_t) -
90 (SPARC_MAXREGWINDOW - size) *
91 sizeof (struct rwindow);
92 v[0].p_filesz += sizeof (Note) +
93 roundup(size, sizeof (Word));
94 }
95 } while ((t = t->t_forw) != p->p_tlist);
96 }
97 #endif /* __sparc */
98 }
99
100 int
101 write_old_elfnotes(proc_t *p, int sig, vnode_t *vp, offset_t offset,
102 rlim64_t rlimit, cred_t *credp)
103 {
104 union {
105 prpsinfo_t psinfo;
106 prstatus_t prstat;
107 prfpregset_t fpregs;
108 #if defined(__sparc)
109 gwindows_t gwindows;
110 #endif /* __sparc */
111 char xregs[1];
112 aux_entry_t auxv[__KERN_NAUXV_IMPL];
113 } *bigwad;
114 int xregsize = prhasx(p)? prgetprxregsize(p) : 0;
115 size_t bigsize = MAX(sizeof (*bigwad), (size_t)xregsize);
116 kthread_t *t;
117 klwp_t *lwp;
118 user_t *up;
119 int i;
120 int nlwp;
121 int error;
122
123 bigwad = kmem_alloc(bigsize, KM_SLEEP);
124
125 /*
126 * The order of the elfnote entries should be same here and in
127 * the gcore(1) command. Synchronization is needed between the
128 * kernel and libproc's Pfgcore() function where the meat of
129 * the gcore(1) command lives.
130 */
131
132 mutex_enter(&p->p_lock);
133 oprgetpsinfo(p, &bigwad->psinfo, NULL);
134 mutex_exit(&p->p_lock);
135 error = elfnote(vp, &offset, NT_PRPSINFO, sizeof (bigwad->psinfo),
182 t->t_whystop = 0;
183 lwp->lwp_cursig = oldsig;
184
185 } else {
186 oprgetstatus(t, &bigwad->prstat, p->p_zone);
187 }
188 mutex_exit(&p->p_lock);
189 error = elfnote(vp, &offset, NT_PRSTATUS,
190 sizeof (bigwad->prstat), (caddr_t)&bigwad->prstat,
191 rlimit, credp);
192 if (error)
193 goto done;
194
195 if (prhasfp()) {
196 prgetprfpregs(lwp, &bigwad->fpregs);
197 error = elfnote(vp, &offset, NT_PRFPREG,
198 sizeof (bigwad->fpregs), (caddr_t)&bigwad->fpregs,
199 rlimit, credp);
200 if (error)
201 goto done;
202 }
203
204 #if defined(__sparc)
205 /*
206 * Unspilled SPARC register windows.
207 */
208 {
209 size_t size = prnwindows(lwp);
210
211 if (size != 0) {
212 size = sizeof (gwindows_t) -
213 (SPARC_MAXREGWINDOW - size) *
214 sizeof (struct rwindow);
215 prgetwindows(lwp, &bigwad->gwindows);
216 error = elfnote(vp, &offset, NT_GWINDOWS,
217 size, (caddr_t)&bigwad->gwindows,
218 rlimit, credp);
219 if (error)
220 goto done;
221 }
222 }
223 #endif /* __sparc */
224
225 if (xregsize) {
226 prgetprxregs(lwp, bigwad->xregs);
227 error = elfnote(vp, &offset, NT_PRXREG,
228 xregsize, bigwad->xregs, rlimit, credp);
229 if (error)
230 goto done;
231 }
232 } while ((t = t->t_forw) != curthread);
233 ASSERT(nlwp == 0);
234
235 done:
236 kmem_free(bigwad, bigsize);
237 return (error);
238 }
|
40 #include <sys/cmn_err.h>
41 #include <sys/systm.h>
42 #include <sys/elf.h>
43 #include <sys/vmsystm.h>
44 #include <sys/debug.h>
45 #include <sys/old_procfs.h>
46 #include <sys/auxv.h>
47 #include <sys/exec.h>
48 #include <sys/prsystm.h>
49 #include <vm/as.h>
50 #include <vm/rm.h>
51 #include <sys/modctl.h>
52 #include <sys/systeminfo.h>
53 #include <sys/machelf.h>
54 #include <sys/zone.h>
55 #include "elf_impl.h"
56
57 extern void oprgetstatus(kthread_t *, prstatus_t *, zone_t *);
58 extern void oprgetpsinfo(proc_t *, prpsinfo_t *, kthread_t *);
59
60 /*
61 * Historically the system dumped the xreg note when on SPARC. Because we no
62 * longer support SPARC we do not dump the old note form of the xregs for any
63 * additional platforms. Please do not add this back unless it's for SPARC's
64 * future resurrection.
65 */
66 void
67 setup_old_note_header(Phdr *v, proc_t *p)
68 {
69 int nlwp = p->p_lwpcnt;
70
71 v[0].p_type = PT_NOTE;
72 v[0].p_flags = PF_R;
73 v[0].p_filesz = (sizeof (Note) * (3 + nlwp))
74 + roundup(sizeof (prpsinfo_t), sizeof (Word))
75 + roundup(strlen(platform) + 1, sizeof (Word))
76 + roundup(__KERN_NAUXV_IMPL * sizeof (aux_entry_t),
77 sizeof (Word))
78 + nlwp * roundup(sizeof (prstatus_t), sizeof (Word));
79 if (prhasfp()) {
80 v[0].p_filesz += nlwp * sizeof (Note) +
81 nlwp * roundup(sizeof (prfpregset_t), sizeof (Word));
82 }
83 }
84
85 int
86 write_old_elfnotes(proc_t *p, int sig, vnode_t *vp, offset_t offset,
87 rlim64_t rlimit, cred_t *credp)
88 {
89 union {
90 prpsinfo_t psinfo;
91 prstatus_t prstat;
92 prfpregset_t fpregs;
93 aux_entry_t auxv[__KERN_NAUXV_IMPL];
94 } *bigwad;
95 size_t bigsize = sizeof (*bigwad);
96 kthread_t *t;
97 klwp_t *lwp;
98 user_t *up;
99 int i;
100 int nlwp;
101 int error;
102
103 bigwad = kmem_alloc(bigsize, KM_SLEEP);
104
105 /*
106 * The order of the elfnote entries should be same here and in
107 * the gcore(1) command. Synchronization is needed between the
108 * kernel and libproc's Pfgcore() function where the meat of
109 * the gcore(1) command lives.
110 */
111
112 mutex_enter(&p->p_lock);
113 oprgetpsinfo(p, &bigwad->psinfo, NULL);
114 mutex_exit(&p->p_lock);
115 error = elfnote(vp, &offset, NT_PRPSINFO, sizeof (bigwad->psinfo),
162 t->t_whystop = 0;
163 lwp->lwp_cursig = oldsig;
164
165 } else {
166 oprgetstatus(t, &bigwad->prstat, p->p_zone);
167 }
168 mutex_exit(&p->p_lock);
169 error = elfnote(vp, &offset, NT_PRSTATUS,
170 sizeof (bigwad->prstat), (caddr_t)&bigwad->prstat,
171 rlimit, credp);
172 if (error)
173 goto done;
174
175 if (prhasfp()) {
176 prgetprfpregs(lwp, &bigwad->fpregs);
177 error = elfnote(vp, &offset, NT_PRFPREG,
178 sizeof (bigwad->fpregs), (caddr_t)&bigwad->fpregs,
179 rlimit, credp);
180 if (error)
181 goto done;
182 }
183 } while ((t = t->t_forw) != curthread);
184 ASSERT(nlwp == 0);
185
186 done:
187 kmem_free(bigwad, bigsize);
188 return (error);
189 }
|