Print this page
27908 ::gcore breaks sparc build
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libproc/sparcv9/Pisadep.c
+++ new/usr/src/lib/libproc/sparcv9/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 #define __sparcv9cpu
27 27
28 28 #include <sys/stack.h>
29 29 #include <sys/regset.h>
30 30 #include <sys/frame.h>
31 31 #include <sys/sysmacros.h>
32 32 #include <sys/machelf.h>
33 33
34 34 #include <stdlib.h>
35 35 #include <unistd.h>
36 36 #include <sys/types.h>
37 37 #include <errno.h>
38 38 #include <string.h>
39 39
40 40 #include "Pcontrol.h"
41 41 #include "Pstack.h"
42 42 #include "Pisadep.h"
43 43 #include "P32ton.h"
44 44
45 45 #define SYSCALL32 0x91d02008 /* 32-bit syscall (ta 8) instruction */
46 46 #define SYSCALL64 0x91d02040 /* 64-bit syscall (ta 64) instruction */
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 size_t i;
56 56
57 57 if (mp == NULL || (fp = mp->map_file) == NULL ||
58 58 fp->file_plt_base == 0 || pltaddr < fp->file_plt_base ||
59 59 pltaddr >= fp->file_plt_base + fp->file_plt_size) {
60 60 errno = EINVAL;
61 61 return (NULL);
62 62 }
63 63
64 64 if (P->status.pr_dmodel == PR_MODEL_LP64) {
65 65 Elf64_Rela r;
66 66 uintptr_t pltoff;
67 67
68 68 pltoff = pltaddr - fp->file_plt_base;
69 69 if (pltoff < (M64_PLT_NEARPLTS * M64_PLT_ENTSIZE)) {
70 70 i = (pltaddr - fp->file_plt_base -
71 71 M_PLT_XNumber * M64_PLT_ENTSIZE) / M64_PLT_ENTSIZE;
72 72 } else {
73 73 uintptr_t pltblockoff;
74 74 pltblockoff = pltoff - (M64_PLT_NEARPLTS *
75 75 M64_PLT_ENTSIZE);
76 76 i = M64_PLT_NEARPLTS +
77 77 ((pltblockoff / M64_PLT_FBLOCKSZ) *
78 78 M64_PLT_FBLKCNTS) + ((pltblockoff %
79 79 M64_PLT_FBLOCKSZ) / M64_PLT_FENTSIZE) -
80 80 M_PLT_XNumber;
81 81 }
82 82
83 83 r_addr = fp->file_jmp_rel + i * sizeof (Elf64_Rela);
84 84
85 85 if (Pread(P, &r, sizeof (r), r_addr) == sizeof (r) &&
86 86 (i = ELF64_R_SYM(r.r_info)) < fp->file_dynsym.sym_symn) {
87 87
88 88 Elf_Data *data = fp->file_dynsym.sym_data_pri;
89 89 Elf64_Sym *symp = &(((Elf64_Sym *)data->d_buf)[i]);
90 90
91 91 return (fp->file_dynsym.sym_strs + symp->st_name);
92 92 }
93 93
94 94 } else /* PR_MODEL_ILP32 */ {
95 95 Elf32_Rela r;
96 96
97 97 i = (pltaddr - fp->file_plt_base -
98 98 M_PLT_XNumber * M32_PLT_ENTSIZE) / M32_PLT_ENTSIZE;
99 99
100 100 r_addr = fp->file_jmp_rel + i * sizeof (Elf32_Rela);
101 101
102 102 if (Pread(P, &r, sizeof (r), r_addr) == sizeof (r) &&
103 103 (i = ELF32_R_SYM(r.r_info)) < fp->file_dynsym.sym_symn) {
104 104
105 105 Elf_Data *data = fp->file_dynsym.sym_data_pri;
106 106 Elf32_Sym *symp = &(((Elf32_Sym *)data->d_buf)[i]);
107 107
108 108 return (fp->file_dynsym.sym_strs + symp->st_name);
109 109 }
110 110 }
111 111
112 112 return (NULL);
113 113 }
114 114
115 115 int
116 116 Pissyscall(struct ps_prochandle *P, uintptr_t addr)
117 117 {
118 118 instr_t sysinstr;
119 119 instr_t instr;
120 120
121 121 if (P->status.pr_dmodel == PR_MODEL_LP64)
122 122 sysinstr = SYSCALL64;
123 123 else
124 124 sysinstr = SYSCALL32;
125 125
126 126 if (Pread(P, &instr, sizeof (instr), addr) != sizeof (instr) ||
127 127 instr != sysinstr)
128 128 return (0);
129 129 else
130 130 return (1);
131 131 }
132 132
133 133 int
134 134 Pissyscall_prev(struct ps_prochandle *P, uintptr_t addr, uintptr_t *dst)
135 135 {
136 136 uintptr_t prevaddr = addr - sizeof (instr_t);
137 137
138 138 if (Pissyscall(P, prevaddr)) {
139 139 if (dst)
140 140 *dst = prevaddr;
141 141 return (1);
142 142 }
143 143
144 144 return (0);
145 145 }
146 146
147 147 /* ARGSUSED */
148 148 int
149 149 Pissyscall_text(struct ps_prochandle *P, const void *buf, size_t buflen)
150 150 {
151 151 instr_t sysinstr;
152 152
153 153 if (P->status.pr_dmodel == PR_MODEL_LP64)
154 154 sysinstr = SYSCALL64;
155 155 else
156 156 sysinstr = SYSCALL32;
157 157
158 158 if (buflen >= sizeof (instr_t) &&
159 159 memcmp(buf, &sysinstr, sizeof (instr_t)) == 0)
160 160 return (1);
161 161 else
162 162 return (0);
163 163 }
164 164
165 165 /*
166 166 * For gwindows_t support, we define a structure to pass arguments to
167 167 * a Plwp_iter() callback routine.
168 168 */
169 169 typedef struct {
170 170 struct ps_prochandle *gq_proc; /* libproc handle */
171 171 struct rwindow *gq_rwin; /* rwindow destination buffer */
172 172 uintptr_t gq_addr; /* stack address to match */
173 173 } gwin_query_t;
174 174
175 175 static int
176 176 find_gwin(gwin_query_t *gqp, const lwpstatus_t *psp)
177 177 {
178 178 gwindows_t gwin;
179 179 struct stat64 st;
180 180 char path[64];
181 181 ssize_t n;
182 182 int fd, i;
183 183 int rv = 0; /* Return value for skip to next lwp */
184 184
185 185 (void) snprintf(path, sizeof (path), "/proc/%d/lwp/%d/gwindows",
186 186 (int)gqp->gq_proc->pid, (int)psp->pr_lwpid);
187 187
188 188 if (stat64(path, &st) == -1 || st.st_size == 0)
189 189 return (0); /* Nothing doing; skip to next lwp */
190 190
191 191 if ((fd = open64(path, O_RDONLY)) >= 0) {
192 192 /*
193 193 * Zero out the gwindows_t because the gwindows file only has
194 194 * as much data as needed to represent the saved windows.
195 195 */
196 196 if (gqp->gq_proc->status.pr_dmodel == PR_MODEL_ILP32) {
197 197 gwindows32_t g32;
198 198
199 199 (void) memset(&g32, 0, sizeof (g32));
200 200 if ((n = read(fd, &g32, sizeof (g32))) > 0)
201 201 gwindows_32_to_n(&g32, &gwin);
202 202
203 203 } else {
204 204 (void) memset(&gwin, 0, sizeof (gwin));
205 205 n = read(fd, &gwin, sizeof (gwin));
206 206 }
207 207
208 208 if (n > 0) {
209 209 /*
210 210 * If we actually found a non-zero gwindows file and
211 211 * were able to read it, iterate through the buffers
212 212 * looking for a stack pointer match; if one is found,
213 213 * copy out the corresponding register window.
214 214 */
215 215 for (i = 0; i < gwin.wbcnt; i++) {
216 216 if (gwin.spbuf[i] == (greg_t *)gqp->gq_addr) {
217 217 (void) memcpy(gqp->gq_rwin,
218 218 &gwin.wbuf[i],
219 219 sizeof (struct rwindow));
220 220
221 221 rv = 1; /* We're done */
222 222 break;
223 223 }
224 224 }
225 225 }
226 226 (void) close(fd);
227 227 }
↓ open down ↓ |
227 lines elided |
↑ open up ↑ |
228 228
229 229 return (rv);
230 230 }
231 231
232 232 static int
233 233 read_gwin(struct ps_prochandle *P, struct rwindow *rwp, uintptr_t sp)
234 234 {
235 235 gwin_query_t gq;
236 236
237 237 if (P->state == PS_DEAD) {
238 - lwp_info_t *lwp = list_next(&P->core->core_lwp_head);
238 + core_info_t *core = P->data;
239 + lwp_info_t *lwp = list_next(&core->core_lwp_head);
239 240 uint_t n;
240 241 int i;
241 242
242 - for (n = 0; n < P->core->core_nlwp; n++, lwp = list_next(lwp)) {
243 + for (n = 0; n < core->core_nlwp; n++, lwp = list_next(lwp)) {
243 244 gwindows_t *gwin = lwp->lwp_gwins;
244 245
245 246 if (gwin == NULL)
246 247 continue; /* No gwindows for this lwp */
247 248
248 249 /*
249 250 * If this lwp has gwindows associated with it, iterate
250 251 * through the buffers looking for a stack pointer
251 252 * match; if one is found, copy out the register window.
252 253 */
253 254 for (i = 0; i < gwin->wbcnt; i++) {
254 255 if (gwin->spbuf[i] == (greg_t *)sp) {
255 256 (void) memcpy(rwp, &gwin->wbuf[i],
256 257 sizeof (struct rwindow));
257 258 return (0); /* We're done */
258 259 }
259 260 }
260 261 }
261 262
262 263 return (-1); /* No gwindows match found */
263 264
264 265 }
265 266
266 267 gq.gq_proc = P;
267 268 gq.gq_rwin = rwp;
268 269 gq.gq_addr = sp;
269 270
270 271 return (Plwp_iter(P, (proc_lwp_f *)find_gwin, &gq) ? 0 : -1);
271 272 }
272 273
273 274 static void
274 275 ucontext_n_to_prgregs(const ucontext_t *src, prgregset_t dst)
275 276 {
276 277 const greg_t *gregs = &src->uc_mcontext.gregs[0];
277 278
278 279 dst[R_CCR] = gregs[REG_CCR];
279 280 dst[R_ASI] = gregs[REG_ASI];
280 281 dst[R_FPRS] = gregs[REG_FPRS];
281 282 dst[R_PC] = gregs[REG_PC];
282 283 dst[R_nPC] = gregs[REG_nPC];
283 284 dst[R_Y] = gregs[REG_Y];
284 285
285 286 dst[R_G1] = gregs[REG_G1];
286 287 dst[R_G2] = gregs[REG_G2];
287 288 dst[R_G3] = gregs[REG_G3];
288 289 dst[R_G4] = gregs[REG_G4];
289 290 dst[R_G5] = gregs[REG_G5];
290 291 dst[R_G6] = gregs[REG_G6];
291 292 dst[R_G7] = gregs[REG_G7];
292 293
293 294 dst[R_O0] = gregs[REG_O0];
294 295 dst[R_O1] = gregs[REG_O1];
295 296 dst[R_O2] = gregs[REG_O2];
296 297 dst[R_O3] = gregs[REG_O3];
297 298 dst[R_O4] = gregs[REG_O4];
298 299 dst[R_O5] = gregs[REG_O5];
299 300 dst[R_O6] = gregs[REG_O6];
300 301 dst[R_O7] = gregs[REG_O7];
301 302 }
302 303
303 304 static void
304 305 ucontext_32_to_prgregs(const ucontext32_t *src, prgregset_t dst)
305 306 {
306 307 /*
307 308 * We need to be very careful here to cast the greg32_t's (signed) to
308 309 * unsigned and then explicitly promote them as unsigned values.
309 310 */
310 311 const greg32_t *gregs = &src->uc_mcontext.gregs[0];
311 312
312 313 dst[R_PSR] = (uint64_t)(uint32_t)gregs[REG_PSR];
313 314 dst[R_PC] = (uint64_t)(uint32_t)gregs[REG_PC];
314 315 dst[R_nPC] = (uint64_t)(uint32_t)gregs[REG_nPC];
315 316 dst[R_Y] = (uint64_t)(uint32_t)gregs[REG_Y];
316 317
317 318 dst[R_G1] = (uint64_t)(uint32_t)gregs[REG_G1];
318 319 dst[R_G2] = (uint64_t)(uint32_t)gregs[REG_G2];
319 320 dst[R_G3] = (uint64_t)(uint32_t)gregs[REG_G3];
320 321 dst[R_G4] = (uint64_t)(uint32_t)gregs[REG_G4];
321 322 dst[R_G5] = (uint64_t)(uint32_t)gregs[REG_G5];
322 323 dst[R_G6] = (uint64_t)(uint32_t)gregs[REG_G6];
323 324 dst[R_G7] = (uint64_t)(uint32_t)gregs[REG_G7];
324 325
325 326 dst[R_O0] = (uint64_t)(uint32_t)gregs[REG_O0];
326 327 dst[R_O1] = (uint64_t)(uint32_t)gregs[REG_O1];
327 328 dst[R_O2] = (uint64_t)(uint32_t)gregs[REG_O2];
328 329 dst[R_O3] = (uint64_t)(uint32_t)gregs[REG_O3];
329 330 dst[R_O4] = (uint64_t)(uint32_t)gregs[REG_O4];
330 331 dst[R_O5] = (uint64_t)(uint32_t)gregs[REG_O5];
331 332 dst[R_O6] = (uint64_t)(uint32_t)gregs[REG_O6];
332 333 dst[R_O7] = (uint64_t)(uint32_t)gregs[REG_O7];
333 334 }
334 335
335 336 int
336 337 Pstack_iter(struct ps_prochandle *P, const prgregset_t regs,
337 338 proc_stack_f *func, void *arg)
338 339 {
339 340 prgreg_t *prevfp = NULL;
340 341 uint_t pfpsize = 0;
341 342 int nfp = 0;
342 343 prgregset_t gregs;
343 344 long args[6];
344 345 prgreg_t fp;
345 346 int i;
346 347 int rv;
347 348 uintptr_t sp;
348 349 ssize_t n;
349 350 uclist_t ucl;
350 351 ucontext_t uc;
351 352
352 353 init_uclist(&ucl, P);
353 354 (void) memcpy(gregs, regs, sizeof (gregs));
354 355
355 356 for (;;) {
356 357 fp = gregs[R_FP];
357 358 if (stack_loop(fp, &prevfp, &nfp, &pfpsize))
358 359 break;
359 360
360 361 for (i = 0; i < 6; i++)
361 362 args[i] = gregs[R_I0 + i];
362 363 if ((rv = func(arg, gregs, 6, args)) != 0)
363 364 break;
364 365
365 366 gregs[R_PC] = gregs[R_I7];
366 367 gregs[R_nPC] = gregs[R_PC] + 4;
367 368 (void) memcpy(&gregs[R_O0], &gregs[R_I0], 8*sizeof (prgreg_t));
368 369 if ((sp = gregs[R_FP]) == 0)
369 370 break;
370 371
371 372 if (P->status.pr_dmodel == PR_MODEL_ILP32) {
372 373 struct rwindow32 rw32;
373 374 ucontext32_t uc32;
374 375
375 376 if (find_uclink(&ucl, sp +
376 377 SA32(sizeof (struct frame32))) &&
377 378 Pread(P, &uc32, sizeof (uc32), sp +
378 379 SA32(sizeof (struct frame32))) == sizeof (uc32)) {
379 380 ucontext_32_to_prgregs(&uc32, gregs);
380 381 sp = gregs[R_SP];
381 382 }
382 383
383 384 n = Pread(P, &rw32, sizeof (struct rwindow32), sp);
384 385
385 386 if (n == sizeof (struct rwindow32)) {
386 387 rwindow_32_to_n(&rw32,
387 388 (struct rwindow *)&gregs[R_L0]);
388 389 continue;
389 390 }
390 391
391 392 } else {
392 393 sp += STACK_BIAS;
393 394
394 395 if (find_uclink(&ucl, sp + SA(sizeof (struct frame))) &&
395 396 Pread(P, &uc, sizeof (uc), sp +
396 397 SA(sizeof (struct frame))) == sizeof (uc)) {
397 398 ucontext_n_to_prgregs(&uc, gregs);
398 399 sp = gregs[R_SP] + STACK_BIAS;
399 400 }
400 401
401 402 n = Pread(P, &gregs[R_L0], sizeof (struct rwindow), sp);
402 403
403 404 if (n == sizeof (struct rwindow))
404 405 continue;
405 406 }
406 407
407 408 /*
408 409 * If we get here, then our Pread of the register window
409 410 * failed. If this is because the address was not mapped,
410 411 * then we attempt to read this window via any gwindows
411 412 * information we have. If that too fails, abort our loop.
412 413 */
413 414 if (n > 0)
414 415 break; /* Failed for reason other than not mapped */
415 416
416 417 if (read_gwin(P, (struct rwindow *)&gregs[R_L0], sp) == -1)
417 418 break; /* No gwindows match either */
418 419 }
419 420
420 421 if (prevfp)
421 422 free(prevfp);
422 423
423 424 free_uclist(&ucl);
424 425 return (rv);
425 426 }
426 427
427 428 uintptr_t
428 429 Psyscall_setup(struct ps_prochandle *P, int nargs, int sysindex, uintptr_t sp)
429 430 {
430 431 uintptr_t ret;
431 432 int model = P->status.pr_dmodel;
432 433
433 434 if (model == PR_MODEL_LP64) {
434 435 sp -= (nargs > 6)?
435 436 WINDOWSIZE64 + sizeof (int64_t) * nargs :
436 437 WINDOWSIZE64 + sizeof (int64_t) * 6;
437 438 sp = PSTACK_ALIGN64(sp);
438 439 ret = sp + WINDOWSIZE32 + sizeof (int32_t);
439 440 } else {
440 441 sp -= (nargs > 6)?
441 442 WINDOWSIZE32 + sizeof (int32_t) * (1 + nargs) :
442 443 WINDOWSIZE32 + sizeof (int32_t) * (1 + 6);
443 444 sp = PSTACK_ALIGN32(sp);
444 445 ret = sp + WINDOWSIZE64 + sizeof (int32_t);
445 446 }
446 447
447 448 P->status.pr_lwp.pr_reg[R_G1] = sysindex;
448 449 if (model == PR_MODEL_LP64)
449 450 P->status.pr_lwp.pr_reg[R_SP] = sp - STACK_BIAS;
450 451 else
451 452 P->status.pr_lwp.pr_reg[R_SP] = sp;
452 453 P->status.pr_lwp.pr_reg[R_PC] = P->sysaddr;
453 454 P->status.pr_lwp.pr_reg[R_nPC] = P->sysaddr + sizeof (instr_t);
454 455
455 456 return (ret);
456 457 }
457 458
458 459 int
459 460 Psyscall_copyinargs(struct ps_prochandle *P, int nargs, argdes_t *argp,
460 461 uintptr_t ap)
461 462 {
462 463 uint32_t arglist32[MAXARGS+2];
463 464 uint64_t arglist64[MAXARGS+2];
464 465 int i;
465 466 argdes_t *adp;
466 467 int model = P->status.pr_dmodel;
467 468
468 469 for (i = 0, adp = argp; i < nargs; i++, adp++) {
469 470 arglist32[i] = (uint32_t)adp->arg_value;
470 471 arglist64[i] = (uint64_t)adp->arg_value;
471 472
472 473 if (i < 6)
473 474 (void) Pputareg(P, R_O0+i, adp->arg_value);
474 475 }
475 476
476 477 if (model == PR_MODEL_LP64) {
477 478 if (nargs > 6 &&
478 479 Pwrite(P, &arglist64[0], sizeof (int64_t) * nargs,
479 480 (uintptr_t)ap) != sizeof (int64_t) * nargs)
480 481 return (-1);
481 482 } else {
482 483 if (nargs > 6 &&
483 484 Pwrite(P, &arglist32[0], sizeof (int32_t) * nargs,
484 485 (uintptr_t)ap) != sizeof (int32_t) * nargs)
485 486 return (-1);
486 487 }
487 488
488 489 return (0);
489 490 }
490 491
491 492 /* ARGSUSED */
492 493 int
493 494 Psyscall_copyoutargs(struct ps_prochandle *P, int nargs, argdes_t *argp,
494 495 uintptr_t ap)
495 496 {
496 497 /* Do nothing */
497 498 return (0);
498 499 }
↓ open down ↓ |
246 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX