Print this page
27908 ::gcore breaks sparc build
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libproc/sparc/Pisadep.c
+++ new/usr/src/lib/libproc/sparc/Pisadep.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
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/stack.h>
27 27 #include <sys/regset.h>
28 28 #include <sys/frame.h>
29 29 #include <sys/sysmacros.h>
30 30 #include <sys/machelf.h>
31 31
32 32 #include <stdlib.h>
33 33 #include <unistd.h>
34 34 #include <sys/types.h>
35 35 #include <errno.h>
36 36 #include <string.h>
37 37
38 38 #include "Pcontrol.h"
39 39 #include "Pstack.h"
40 40 #include "Pisadep.h"
41 41
42 42 #define SYSCALL32 0x91d02008 /* 32-bit syscall (ta 8) instruction */
43 43
44 44 #ifndef WINDOWSIZE32
45 45 #define WINDOWSIZE32 (16 * sizeof (int32_t))
46 46 #endif
47 47
48 48 const char *
49 49 Ppltdest(struct ps_prochandle *P, uintptr_t pltaddr)
50 50 {
51 51 map_info_t *mp = Paddr2mptr(P, pltaddr);
52 52
53 53 uintptr_t r_addr;
54 54 file_info_t *fp;
55 55 Elf32_Rela r;
56 56 size_t i;
57 57
58 58 if (mp == NULL || (fp = mp->map_file) == NULL ||
59 59 fp->file_plt_base == 0 || pltaddr < fp->file_plt_base ||
60 60 pltaddr >= fp->file_plt_base + fp->file_plt_size) {
61 61 errno = EINVAL;
62 62 return (NULL);
63 63 }
64 64
65 65 i = (pltaddr - fp->file_plt_base -
66 66 M_PLT_XNumber * M32_PLT_ENTSIZE) / M32_PLT_ENTSIZE;
67 67
68 68 r_addr = fp->file_jmp_rel + i * sizeof (Elf32_Rela);
69 69
70 70 if (Pread(P, &r, sizeof (r), r_addr) == sizeof (r) &&
71 71 (i = ELF32_R_SYM(r.r_info)) < fp->file_dynsym.sym_symn) {
72 72
73 73 Elf_Data *data = fp->file_dynsym.sym_data_pri;
74 74 Elf32_Sym *symp = &(((Elf32_Sym *)data->d_buf)[i]);
75 75
76 76 return (fp->file_dynsym.sym_strs + symp->st_name);
77 77 }
78 78
79 79 return (NULL);
80 80 }
81 81
82 82 int
83 83 Pissyscall(struct ps_prochandle *P, uintptr_t addr)
84 84 {
85 85 instr_t sysinstr;
86 86 instr_t instr;
87 87
88 88 sysinstr = SYSCALL32;
89 89
90 90 if (Pread(P, &instr, sizeof (instr), addr) != sizeof (instr) ||
91 91 instr != sysinstr)
92 92 return (0);
93 93 else
94 94 return (1);
95 95 }
96 96
97 97 int
98 98 Pissyscall_prev(struct ps_prochandle *P, uintptr_t addr, uintptr_t *dst)
99 99 {
100 100 uintptr_t prevaddr = addr - sizeof (instr_t);
101 101
102 102 if (Pissyscall(P, prevaddr)) {
103 103 if (dst)
104 104 *dst = prevaddr;
105 105 return (1);
106 106 }
107 107
108 108 return (0);
109 109 }
110 110
111 111 /* ARGSUSED */
112 112 int
113 113 Pissyscall_text(struct ps_prochandle *P, const void *buf, size_t buflen)
114 114 {
115 115 instr_t sysinstr;
116 116
117 117 sysinstr = SYSCALL32;
118 118
119 119 if (buflen >= sizeof (instr_t) &&
120 120 memcmp(buf, &sysinstr, sizeof (instr_t)) == 0)
121 121 return (1);
122 122 else
123 123 return (0);
124 124 }
125 125
126 126 /*
127 127 * For gwindows_t support, we define a structure to pass arguments to
128 128 * a Plwp_iter() callback routine.
129 129 */
130 130 typedef struct {
131 131 struct ps_prochandle *gq_proc; /* libproc handle */
132 132 struct rwindow *gq_rwin; /* rwindow destination buffer */
133 133 uintptr_t gq_addr; /* stack address to match */
134 134 } gwin_query_t;
135 135
136 136 static int
137 137 find_gwin(gwin_query_t *gqp, const lwpstatus_t *psp)
138 138 {
139 139 gwindows_t gwin;
140 140 struct stat64 st;
141 141 char path[64];
142 142 ssize_t n;
143 143 int fd, i;
144 144 int rv = 0; /* Return value for skip to next lwp */
145 145
146 146 (void) snprintf(path, sizeof (path), "/proc/%d/lwp/%d/gwindows",
147 147 (int)gqp->gq_proc->pid, (int)psp->pr_lwpid);
148 148
149 149 if (stat64(path, &st) == -1 || st.st_size == 0)
150 150 return (0); /* Nothing doing; skip to next lwp */
151 151
152 152 if ((fd = open64(path, O_RDONLY)) >= 0) {
153 153 /*
154 154 * Zero out the gwindows_t because the gwindows file only has
155 155 * as much data as needed to represent the saved windows.
156 156 */
157 157 (void) memset(&gwin, 0, sizeof (gwin));
158 158 n = read(fd, &gwin, sizeof (gwin));
159 159
160 160 if (n > 0) {
161 161 /*
162 162 * If we actually found a non-zero gwindows file and
163 163 * were able to read it, iterate through the buffers
164 164 * looking for a stack pointer match; if one is found,
165 165 * copy out the corresponding register window.
166 166 */
167 167 for (i = 0; i < gwin.wbcnt; i++) {
168 168 if (gwin.spbuf[i] == (greg_t *)gqp->gq_addr) {
169 169 (void) memcpy(gqp->gq_rwin,
170 170 &gwin.wbuf[i],
171 171 sizeof (struct rwindow));
172 172
173 173 rv = 1; /* We're done */
174 174 break;
175 175 }
176 176 }
177 177 }
178 178 (void) close(fd);
179 179 }
↓ open down ↓ |
179 lines elided |
↑ open up ↑ |
180 180
181 181 return (rv);
182 182 }
183 183
184 184 static int
185 185 read_gwin(struct ps_prochandle *P, struct rwindow *rwp, uintptr_t sp)
186 186 {
187 187 gwin_query_t gq;
188 188
189 189 if (P->state == PS_DEAD) {
190 - lwp_info_t *lwp = list_next(&P->core->core_lwp_head);
190 + core_info_t *core = P->data;
191 + lwp_info_t *lwp = list_next(&core->core_lwp_head);
191 192 uint_t n;
192 193 int i;
193 194
194 - for (n = 0; n < P->core->core_nlwp; n++, lwp = list_next(lwp)) {
195 + for (n = 0; n < core->core_nlwp; n++, lwp = list_next(lwp)) {
195 196 gwindows_t *gwin = lwp->lwp_gwins;
196 197
197 198 if (gwin == NULL)
198 199 continue; /* No gwindows for this lwp */
199 200
200 201 /*
201 202 * If this lwp has gwindows associated with it, iterate
202 203 * through the buffers looking for a stack pointer
203 204 * match; if one is found, copy out the register window.
204 205 */
205 206 for (i = 0; i < gwin->wbcnt; i++) {
206 207 if (gwin->spbuf[i] == (greg_t *)sp) {
207 208 (void) memcpy(rwp, &gwin->wbuf[i],
208 209 sizeof (struct rwindow));
209 210 return (0); /* We're done */
210 211 }
211 212 }
212 213 }
213 214
214 215 return (-1); /* No gwindows match found */
215 216
216 217 }
217 218
218 219 gq.gq_proc = P;
219 220 gq.gq_rwin = rwp;
220 221 gq.gq_addr = sp;
221 222
222 223 return (Plwp_iter(P, (proc_lwp_f *)find_gwin, &gq) ? 0 : -1);
223 224 }
224 225
225 226 static void
226 227 ucontext_n_to_prgregs(const ucontext_t *src, prgregset_t dst)
227 228 {
228 229 const greg_t *gregs = &src->uc_mcontext.gregs[0];
229 230
230 231 dst[R_PSR] = gregs[REG_PSR];
231 232 dst[R_PC] = gregs[REG_PC];
232 233 dst[R_nPC] = gregs[REG_nPC];
233 234 dst[R_Y] = gregs[REG_Y];
234 235
235 236 dst[R_G1] = gregs[REG_G1];
236 237 dst[R_G2] = gregs[REG_G2];
237 238 dst[R_G3] = gregs[REG_G3];
238 239 dst[R_G4] = gregs[REG_G4];
239 240 dst[R_G5] = gregs[REG_G5];
240 241 dst[R_G6] = gregs[REG_G6];
241 242 dst[R_G7] = gregs[REG_G7];
242 243
243 244 dst[R_O0] = gregs[REG_O0];
244 245 dst[R_O1] = gregs[REG_O1];
245 246 dst[R_O2] = gregs[REG_O2];
246 247 dst[R_O3] = gregs[REG_O3];
247 248 dst[R_O4] = gregs[REG_O4];
248 249 dst[R_O5] = gregs[REG_O5];
249 250 dst[R_O6] = gregs[REG_O6];
250 251 dst[R_O7] = gregs[REG_O7];
251 252 }
252 253
253 254 int
254 255 Pstack_iter(struct ps_prochandle *P, const prgregset_t regs,
255 256 proc_stack_f *func, void *arg)
256 257 {
257 258 prgreg_t *prevfp = NULL;
258 259 uint_t pfpsize = 0;
259 260 int nfp = 0;
260 261 prgregset_t gregs;
261 262 long args[6];
262 263 prgreg_t fp;
263 264 int i;
264 265 int rv;
265 266 uintptr_t sp;
266 267 ssize_t n;
267 268 uclist_t ucl;
268 269 ucontext_t uc;
269 270
270 271 init_uclist(&ucl, P);
271 272 (void) memcpy(gregs, regs, sizeof (gregs));
272 273
273 274 for (;;) {
274 275 fp = gregs[R_FP];
275 276 if (stack_loop(fp, &prevfp, &nfp, &pfpsize))
276 277 break;
277 278
278 279 for (i = 0; i < 6; i++)
279 280 args[i] = gregs[R_I0 + i];
280 281 if ((rv = func(arg, gregs, 6, args)) != 0)
281 282 break;
282 283
283 284 gregs[R_PC] = gregs[R_I7];
284 285 gregs[R_nPC] = gregs[R_PC] + 4;
285 286 (void) memcpy(&gregs[R_O0], &gregs[R_I0], 8*sizeof (prgreg_t));
286 287 if ((sp = gregs[R_FP]) == 0)
287 288 break;
288 289
289 290 sp += STACK_BIAS;
290 291
291 292 if (find_uclink(&ucl, sp + SA(sizeof (struct frame))) &&
292 293 Pread(P, &uc, sizeof (uc), sp +
293 294 SA(sizeof (struct frame))) == sizeof (uc)) {
294 295 ucontext_n_to_prgregs(&uc, gregs);
295 296 sp = gregs[R_SP] + STACK_BIAS;
296 297 }
297 298
298 299 n = Pread(P, &gregs[R_L0], sizeof (struct rwindow), sp);
299 300
300 301 if (n == sizeof (struct rwindow))
301 302 continue;
302 303
303 304 /*
304 305 * If we get here, then our Pread of the register window
305 306 * failed. If this is because the address was not mapped,
306 307 * then we attempt to read this window via any gwindows
307 308 * information we have. If that too fails, abort our loop.
308 309 */
309 310 if (n > 0)
310 311 break; /* Failed for reason other than not mapped */
311 312
312 313 if (read_gwin(P, (struct rwindow *)&gregs[R_L0], sp) == -1)
313 314 break; /* No gwindows match either */
314 315 }
315 316
316 317 if (prevfp)
317 318 free(prevfp);
318 319
319 320 free_uclist(&ucl);
320 321 return (rv);
321 322 }
322 323
323 324 uintptr_t
324 325 Psyscall_setup(struct ps_prochandle *P, int nargs, int sysindex, uintptr_t sp)
325 326 {
326 327 sp -= (nargs > 6)?
327 328 WINDOWSIZE32 + sizeof (int32_t) * (1 + nargs) :
328 329 WINDOWSIZE32 + sizeof (int32_t) * (1 + 6);
329 330 sp = PSTACK_ALIGN32(sp);
330 331
331 332 P->status.pr_lwp.pr_reg[R_G1] = sysindex;
332 333 P->status.pr_lwp.pr_reg[R_SP] = sp;
333 334 P->status.pr_lwp.pr_reg[R_PC] = P->sysaddr;
334 335 P->status.pr_lwp.pr_reg[R_nPC] = P->sysaddr + sizeof (instr_t);
335 336
336 337 return (sp + WINDOWSIZE32 + sizeof (int32_t));
337 338 }
338 339
339 340 int
340 341 Psyscall_copyinargs(struct ps_prochandle *P, int nargs, argdes_t *argp,
341 342 uintptr_t ap)
342 343 {
343 344 uint32_t arglist[MAXARGS+2];
344 345 int i;
345 346 argdes_t *adp;
346 347
347 348 for (i = 0, adp = argp; i < nargs; i++, adp++) {
348 349 arglist[i] = adp->arg_value;
349 350
350 351 if (i < 6)
351 352 (void) Pputareg(P, R_O0+i, adp->arg_value);
352 353 }
353 354
354 355 if (nargs > 6 &&
355 356 Pwrite(P, &arglist[0], sizeof (int32_t) * nargs,
356 357 (uintptr_t)ap) != sizeof (int32_t) * nargs)
357 358 return (-1);
358 359
359 360 return (0);
360 361 }
361 362
362 363 /* ARGSUSED */
363 364 int
364 365 Psyscall_copyoutargs(struct ps_prochandle *P, int nargs, argdes_t *argp,
365 366 uintptr_t ap)
366 367 {
367 368 /* Do nothing */
368 369 return (0);
369 370 }
↓ open down ↓ |
165 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX