ia64/linux-2.6.18-xen.hg

annotate arch/sparc64/kernel/ptrace.c @ 0:831230e53067

Import 2.6.18 from kernel.org tarball.
author Ian Campbell <ian.campbell@xensource.com>
date Wed Apr 11 14:15:44 2007 +0100 (2007-04-11)
parents
children
rev   line source
ian@0 1 /* ptrace.c: Sparc process tracing support.
ian@0 2 *
ian@0 3 * Copyright (C) 1996 David S. Miller (davem@caipfs.rutgers.edu)
ian@0 4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
ian@0 5 *
ian@0 6 * Based upon code written by Ross Biro, Linus Torvalds, Bob Manson,
ian@0 7 * and David Mosberger.
ian@0 8 *
ian@0 9 * Added Linux support -miguel (weird, eh?, the original code was meant
ian@0 10 * to emulate SunOS).
ian@0 11 */
ian@0 12
ian@0 13 #include <linux/kernel.h>
ian@0 14 #include <linux/sched.h>
ian@0 15 #include <linux/mm.h>
ian@0 16 #include <linux/errno.h>
ian@0 17 #include <linux/ptrace.h>
ian@0 18 #include <linux/user.h>
ian@0 19 #include <linux/smp.h>
ian@0 20 #include <linux/smp_lock.h>
ian@0 21 #include <linux/security.h>
ian@0 22 #include <linux/seccomp.h>
ian@0 23 #include <linux/audit.h>
ian@0 24 #include <linux/signal.h>
ian@0 25
ian@0 26 #include <asm/asi.h>
ian@0 27 #include <asm/pgtable.h>
ian@0 28 #include <asm/system.h>
ian@0 29 #include <asm/uaccess.h>
ian@0 30 #include <asm/psrcompat.h>
ian@0 31 #include <asm/visasm.h>
ian@0 32 #include <asm/spitfire.h>
ian@0 33 #include <asm/page.h>
ian@0 34 #include <asm/cpudata.h>
ian@0 35
ian@0 36 /* Returning from ptrace is a bit tricky because the syscall return
ian@0 37 * low level code assumes any value returned which is negative and
ian@0 38 * is a valid errno will mean setting the condition codes to indicate
ian@0 39 * an error return. This doesn't work, so we have this hook.
ian@0 40 */
ian@0 41 static inline void pt_error_return(struct pt_regs *regs, unsigned long error)
ian@0 42 {
ian@0 43 regs->u_regs[UREG_I0] = error;
ian@0 44 regs->tstate |= (TSTATE_ICARRY | TSTATE_XCARRY);
ian@0 45 regs->tpc = regs->tnpc;
ian@0 46 regs->tnpc += 4;
ian@0 47 }
ian@0 48
ian@0 49 static inline void pt_succ_return(struct pt_regs *regs, unsigned long value)
ian@0 50 {
ian@0 51 regs->u_regs[UREG_I0] = value;
ian@0 52 regs->tstate &= ~(TSTATE_ICARRY | TSTATE_XCARRY);
ian@0 53 regs->tpc = regs->tnpc;
ian@0 54 regs->tnpc += 4;
ian@0 55 }
ian@0 56
ian@0 57 static inline void
ian@0 58 pt_succ_return_linux(struct pt_regs *regs, unsigned long value, void __user *addr)
ian@0 59 {
ian@0 60 if (test_thread_flag(TIF_32BIT)) {
ian@0 61 if (put_user(value, (unsigned int __user *) addr)) {
ian@0 62 pt_error_return(regs, EFAULT);
ian@0 63 return;
ian@0 64 }
ian@0 65 } else {
ian@0 66 if (put_user(value, (long __user *) addr)) {
ian@0 67 pt_error_return(regs, EFAULT);
ian@0 68 return;
ian@0 69 }
ian@0 70 }
ian@0 71 regs->u_regs[UREG_I0] = 0;
ian@0 72 regs->tstate &= ~(TSTATE_ICARRY | TSTATE_XCARRY);
ian@0 73 regs->tpc = regs->tnpc;
ian@0 74 regs->tnpc += 4;
ian@0 75 }
ian@0 76
ian@0 77 static void
ian@0 78 pt_os_succ_return (struct pt_regs *regs, unsigned long val, void __user *addr)
ian@0 79 {
ian@0 80 if (current->personality == PER_SUNOS)
ian@0 81 pt_succ_return (regs, val);
ian@0 82 else
ian@0 83 pt_succ_return_linux (regs, val, addr);
ian@0 84 }
ian@0 85
ian@0 86 /* #define ALLOW_INIT_TRACING */
ian@0 87 /* #define DEBUG_PTRACE */
ian@0 88
ian@0 89 #ifdef DEBUG_PTRACE
ian@0 90 char *pt_rq [] = {
ian@0 91 /* 0 */ "TRACEME", "PEEKTEXT", "PEEKDATA", "PEEKUSR",
ian@0 92 /* 4 */ "POKETEXT", "POKEDATA", "POKEUSR", "CONT",
ian@0 93 /* 8 */ "KILL", "SINGLESTEP", "SUNATTACH", "SUNDETACH",
ian@0 94 /* 12 */ "GETREGS", "SETREGS", "GETFPREGS", "SETFPREGS",
ian@0 95 /* 16 */ "READDATA", "WRITEDATA", "READTEXT", "WRITETEXT",
ian@0 96 /* 20 */ "GETFPAREGS", "SETFPAREGS", "unknown", "unknown",
ian@0 97 /* 24 */ "SYSCALL", ""
ian@0 98 };
ian@0 99 #endif
ian@0 100
ian@0 101 /*
ian@0 102 * Called by kernel/ptrace.c when detaching..
ian@0 103 *
ian@0 104 * Make sure single step bits etc are not set.
ian@0 105 */
ian@0 106 void ptrace_disable(struct task_struct *child)
ian@0 107 {
ian@0 108 /* nothing to do */
ian@0 109 }
ian@0 110
ian@0 111 /* To get the necessary page struct, access_process_vm() first calls
ian@0 112 * get_user_pages(). This has done a flush_dcache_page() on the
ian@0 113 * accessed page. Then our caller (copy_{to,from}_user_page()) did
ian@0 114 * to memcpy to read/write the data from that page.
ian@0 115 *
ian@0 116 * Now, the only thing we have to do is:
ian@0 117 * 1) flush the D-cache if it's possible than an illegal alias
ian@0 118 * has been created
ian@0 119 * 2) flush the I-cache if this is pre-cheetah and we did a write
ian@0 120 */
ian@0 121 void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
ian@0 122 unsigned long uaddr, void *kaddr,
ian@0 123 unsigned long len, int write)
ian@0 124 {
ian@0 125 BUG_ON(len > PAGE_SIZE);
ian@0 126
ian@0 127 if (tlb_type == hypervisor)
ian@0 128 return;
ian@0 129
ian@0 130 #ifdef DCACHE_ALIASING_POSSIBLE
ian@0 131 /* If bit 13 of the kernel address we used to access the
ian@0 132 * user page is the same as the virtual address that page
ian@0 133 * is mapped to in the user's address space, we can skip the
ian@0 134 * D-cache flush.
ian@0 135 */
ian@0 136 if ((uaddr ^ (unsigned long) kaddr) & (1UL << 13)) {
ian@0 137 unsigned long start = __pa(kaddr);
ian@0 138 unsigned long end = start + len;
ian@0 139 unsigned long dcache_line_size;
ian@0 140
ian@0 141 dcache_line_size = local_cpu_data().dcache_line_size;
ian@0 142
ian@0 143 if (tlb_type == spitfire) {
ian@0 144 for (; start < end; start += dcache_line_size)
ian@0 145 spitfire_put_dcache_tag(start & 0x3fe0, 0x0);
ian@0 146 } else {
ian@0 147 start &= ~(dcache_line_size - 1);
ian@0 148 for (; start < end; start += dcache_line_size)
ian@0 149 __asm__ __volatile__(
ian@0 150 "stxa %%g0, [%0] %1\n\t"
ian@0 151 "membar #Sync"
ian@0 152 : /* no outputs */
ian@0 153 : "r" (start),
ian@0 154 "i" (ASI_DCACHE_INVALIDATE));
ian@0 155 }
ian@0 156 }
ian@0 157 #endif
ian@0 158 if (write && tlb_type == spitfire) {
ian@0 159 unsigned long start = (unsigned long) kaddr;
ian@0 160 unsigned long end = start + len;
ian@0 161 unsigned long icache_line_size;
ian@0 162
ian@0 163 icache_line_size = local_cpu_data().icache_line_size;
ian@0 164
ian@0 165 for (; start < end; start += icache_line_size)
ian@0 166 flushi(start);
ian@0 167 }
ian@0 168 }
ian@0 169
ian@0 170 asmlinkage void do_ptrace(struct pt_regs *regs)
ian@0 171 {
ian@0 172 int request = regs->u_regs[UREG_I0];
ian@0 173 pid_t pid = regs->u_regs[UREG_I1];
ian@0 174 unsigned long addr = regs->u_regs[UREG_I2];
ian@0 175 unsigned long data = regs->u_regs[UREG_I3];
ian@0 176 unsigned long addr2 = regs->u_regs[UREG_I4];
ian@0 177 struct task_struct *child;
ian@0 178 int ret;
ian@0 179
ian@0 180 if (test_thread_flag(TIF_32BIT)) {
ian@0 181 addr &= 0xffffffffUL;
ian@0 182 data &= 0xffffffffUL;
ian@0 183 addr2 &= 0xffffffffUL;
ian@0 184 }
ian@0 185 lock_kernel();
ian@0 186 #ifdef DEBUG_PTRACE
ian@0 187 {
ian@0 188 char *s;
ian@0 189
ian@0 190 if ((request >= 0) && (request <= 24))
ian@0 191 s = pt_rq [request];
ian@0 192 else
ian@0 193 s = "unknown";
ian@0 194
ian@0 195 if (request == PTRACE_POKEDATA && data == 0x91d02001){
ian@0 196 printk ("do_ptrace: breakpoint pid=%d, addr=%016lx addr2=%016lx\n",
ian@0 197 pid, addr, addr2);
ian@0 198 } else
ian@0 199 printk("do_ptrace: rq=%s(%d) pid=%d addr=%016lx data=%016lx addr2=%016lx\n",
ian@0 200 s, request, pid, addr, data, addr2);
ian@0 201 }
ian@0 202 #endif
ian@0 203 if (request == PTRACE_TRACEME) {
ian@0 204 ret = ptrace_traceme();
ian@0 205 pt_succ_return(regs, 0);
ian@0 206 goto out;
ian@0 207 }
ian@0 208
ian@0 209 child = ptrace_get_task_struct(pid);
ian@0 210 if (IS_ERR(child)) {
ian@0 211 ret = PTR_ERR(child);
ian@0 212 pt_error_return(regs, -ret);
ian@0 213 goto out;
ian@0 214 }
ian@0 215
ian@0 216 if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
ian@0 217 || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
ian@0 218 if (ptrace_attach(child)) {
ian@0 219 pt_error_return(regs, EPERM);
ian@0 220 goto out_tsk;
ian@0 221 }
ian@0 222 pt_succ_return(regs, 0);
ian@0 223 goto out_tsk;
ian@0 224 }
ian@0 225
ian@0 226 ret = ptrace_check_attach(child, request == PTRACE_KILL);
ian@0 227 if (ret < 0) {
ian@0 228 pt_error_return(regs, -ret);
ian@0 229 goto out_tsk;
ian@0 230 }
ian@0 231
ian@0 232 if (!(test_thread_flag(TIF_32BIT)) &&
ian@0 233 ((request == PTRACE_READDATA64) ||
ian@0 234 (request == PTRACE_WRITEDATA64) ||
ian@0 235 (request == PTRACE_READTEXT64) ||
ian@0 236 (request == PTRACE_WRITETEXT64) ||
ian@0 237 (request == PTRACE_PEEKTEXT64) ||
ian@0 238 (request == PTRACE_POKETEXT64) ||
ian@0 239 (request == PTRACE_PEEKDATA64) ||
ian@0 240 (request == PTRACE_POKEDATA64))) {
ian@0 241 addr = regs->u_regs[UREG_G2];
ian@0 242 addr2 = regs->u_regs[UREG_G3];
ian@0 243 request -= 30; /* wheee... */
ian@0 244 }
ian@0 245
ian@0 246 switch(request) {
ian@0 247 case PTRACE_PEEKUSR:
ian@0 248 if (addr != 0)
ian@0 249 pt_error_return(regs, EIO);
ian@0 250 else
ian@0 251 pt_succ_return(regs, 0);
ian@0 252 goto out_tsk;
ian@0 253
ian@0 254 case PTRACE_PEEKTEXT: /* read word at location addr. */
ian@0 255 case PTRACE_PEEKDATA: {
ian@0 256 unsigned long tmp64;
ian@0 257 unsigned int tmp32;
ian@0 258 int res, copied;
ian@0 259
ian@0 260 res = -EIO;
ian@0 261 if (test_thread_flag(TIF_32BIT)) {
ian@0 262 copied = access_process_vm(child, addr,
ian@0 263 &tmp32, sizeof(tmp32), 0);
ian@0 264 tmp64 = (unsigned long) tmp32;
ian@0 265 if (copied == sizeof(tmp32))
ian@0 266 res = 0;
ian@0 267 } else {
ian@0 268 copied = access_process_vm(child, addr,
ian@0 269 &tmp64, sizeof(tmp64), 0);
ian@0 270 if (copied == sizeof(tmp64))
ian@0 271 res = 0;
ian@0 272 }
ian@0 273 if (res < 0)
ian@0 274 pt_error_return(regs, -res);
ian@0 275 else
ian@0 276 pt_os_succ_return(regs, tmp64, (void __user *) data);
ian@0 277 goto out_tsk;
ian@0 278 }
ian@0 279
ian@0 280 case PTRACE_POKETEXT: /* write the word at location addr. */
ian@0 281 case PTRACE_POKEDATA: {
ian@0 282 unsigned long tmp64;
ian@0 283 unsigned int tmp32;
ian@0 284 int copied, res = -EIO;
ian@0 285
ian@0 286 if (test_thread_flag(TIF_32BIT)) {
ian@0 287 tmp32 = data;
ian@0 288 copied = access_process_vm(child, addr,
ian@0 289 &tmp32, sizeof(tmp32), 1);
ian@0 290 if (copied == sizeof(tmp32))
ian@0 291 res = 0;
ian@0 292 } else {
ian@0 293 tmp64 = data;
ian@0 294 copied = access_process_vm(child, addr,
ian@0 295 &tmp64, sizeof(tmp64), 1);
ian@0 296 if (copied == sizeof(tmp64))
ian@0 297 res = 0;
ian@0 298 }
ian@0 299 if (res < 0)
ian@0 300 pt_error_return(regs, -res);
ian@0 301 else
ian@0 302 pt_succ_return(regs, res);
ian@0 303 goto out_tsk;
ian@0 304 }
ian@0 305
ian@0 306 case PTRACE_GETREGS: {
ian@0 307 struct pt_regs32 __user *pregs =
ian@0 308 (struct pt_regs32 __user *) addr;
ian@0 309 struct pt_regs *cregs = task_pt_regs(child);
ian@0 310 int rval;
ian@0 311
ian@0 312 if (__put_user(tstate_to_psr(cregs->tstate), (&pregs->psr)) ||
ian@0 313 __put_user(cregs->tpc, (&pregs->pc)) ||
ian@0 314 __put_user(cregs->tnpc, (&pregs->npc)) ||
ian@0 315 __put_user(cregs->y, (&pregs->y))) {
ian@0 316 pt_error_return(regs, EFAULT);
ian@0 317 goto out_tsk;
ian@0 318 }
ian@0 319 for (rval = 1; rval < 16; rval++)
ian@0 320 if (__put_user(cregs->u_regs[rval], (&pregs->u_regs[rval - 1]))) {
ian@0 321 pt_error_return(regs, EFAULT);
ian@0 322 goto out_tsk;
ian@0 323 }
ian@0 324 pt_succ_return(regs, 0);
ian@0 325 #ifdef DEBUG_PTRACE
ian@0 326 printk ("PC=%lx nPC=%lx o7=%lx\n", cregs->tpc, cregs->tnpc, cregs->u_regs [15]);
ian@0 327 #endif
ian@0 328 goto out_tsk;
ian@0 329 }
ian@0 330
ian@0 331 case PTRACE_GETREGS64: {
ian@0 332 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
ian@0 333 struct pt_regs *cregs = task_pt_regs(child);
ian@0 334 unsigned long tpc = cregs->tpc;
ian@0 335 int rval;
ian@0 336
ian@0 337 if ((task_thread_info(child)->flags & _TIF_32BIT) != 0)
ian@0 338 tpc &= 0xffffffff;
ian@0 339 if (__put_user(cregs->tstate, (&pregs->tstate)) ||
ian@0 340 __put_user(tpc, (&pregs->tpc)) ||
ian@0 341 __put_user(cregs->tnpc, (&pregs->tnpc)) ||
ian@0 342 __put_user(cregs->y, (&pregs->y))) {
ian@0 343 pt_error_return(regs, EFAULT);
ian@0 344 goto out_tsk;
ian@0 345 }
ian@0 346 for (rval = 1; rval < 16; rval++)
ian@0 347 if (__put_user(cregs->u_regs[rval], (&pregs->u_regs[rval - 1]))) {
ian@0 348 pt_error_return(regs, EFAULT);
ian@0 349 goto out_tsk;
ian@0 350 }
ian@0 351 pt_succ_return(regs, 0);
ian@0 352 #ifdef DEBUG_PTRACE
ian@0 353 printk ("PC=%lx nPC=%lx o7=%lx\n", cregs->tpc, cregs->tnpc, cregs->u_regs [15]);
ian@0 354 #endif
ian@0 355 goto out_tsk;
ian@0 356 }
ian@0 357
ian@0 358 case PTRACE_SETREGS: {
ian@0 359 struct pt_regs32 __user *pregs =
ian@0 360 (struct pt_regs32 __user *) addr;
ian@0 361 struct pt_regs *cregs = task_pt_regs(child);
ian@0 362 unsigned int psr, pc, npc, y;
ian@0 363 int i;
ian@0 364
ian@0 365 /* Must be careful, tracing process can only set certain
ian@0 366 * bits in the psr.
ian@0 367 */
ian@0 368 if (__get_user(psr, (&pregs->psr)) ||
ian@0 369 __get_user(pc, (&pregs->pc)) ||
ian@0 370 __get_user(npc, (&pregs->npc)) ||
ian@0 371 __get_user(y, (&pregs->y))) {
ian@0 372 pt_error_return(regs, EFAULT);
ian@0 373 goto out_tsk;
ian@0 374 }
ian@0 375 cregs->tstate &= ~(TSTATE_ICC);
ian@0 376 cregs->tstate |= psr_to_tstate_icc(psr);
ian@0 377 if (!((pc | npc) & 3)) {
ian@0 378 cregs->tpc = pc;
ian@0 379 cregs->tnpc = npc;
ian@0 380 }
ian@0 381 cregs->y = y;
ian@0 382 for (i = 1; i < 16; i++) {
ian@0 383 if (__get_user(cregs->u_regs[i], (&pregs->u_regs[i-1]))) {
ian@0 384 pt_error_return(regs, EFAULT);
ian@0 385 goto out_tsk;
ian@0 386 }
ian@0 387 }
ian@0 388 pt_succ_return(regs, 0);
ian@0 389 goto out_tsk;
ian@0 390 }
ian@0 391
ian@0 392 case PTRACE_SETREGS64: {
ian@0 393 struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
ian@0 394 struct pt_regs *cregs = task_pt_regs(child);
ian@0 395 unsigned long tstate, tpc, tnpc, y;
ian@0 396 int i;
ian@0 397
ian@0 398 /* Must be careful, tracing process can only set certain
ian@0 399 * bits in the psr.
ian@0 400 */
ian@0 401 if (__get_user(tstate, (&pregs->tstate)) ||
ian@0 402 __get_user(tpc, (&pregs->tpc)) ||
ian@0 403 __get_user(tnpc, (&pregs->tnpc)) ||
ian@0 404 __get_user(y, (&pregs->y))) {
ian@0 405 pt_error_return(regs, EFAULT);
ian@0 406 goto out_tsk;
ian@0 407 }
ian@0 408 if ((task_thread_info(child)->flags & _TIF_32BIT) != 0) {
ian@0 409 tpc &= 0xffffffff;
ian@0 410 tnpc &= 0xffffffff;
ian@0 411 }
ian@0 412 tstate &= (TSTATE_ICC | TSTATE_XCC);
ian@0 413 cregs->tstate &= ~(TSTATE_ICC | TSTATE_XCC);
ian@0 414 cregs->tstate |= tstate;
ian@0 415 if (!((tpc | tnpc) & 3)) {
ian@0 416 cregs->tpc = tpc;
ian@0 417 cregs->tnpc = tnpc;
ian@0 418 }
ian@0 419 cregs->y = y;
ian@0 420 for (i = 1; i < 16; i++) {
ian@0 421 if (__get_user(cregs->u_regs[i], (&pregs->u_regs[i-1]))) {
ian@0 422 pt_error_return(regs, EFAULT);
ian@0 423 goto out_tsk;
ian@0 424 }
ian@0 425 }
ian@0 426 pt_succ_return(regs, 0);
ian@0 427 goto out_tsk;
ian@0 428 }
ian@0 429
ian@0 430 case PTRACE_GETFPREGS: {
ian@0 431 struct fps {
ian@0 432 unsigned int regs[32];
ian@0 433 unsigned int fsr;
ian@0 434 unsigned int flags;
ian@0 435 unsigned int extra;
ian@0 436 unsigned int fpqd;
ian@0 437 struct fq {
ian@0 438 unsigned int insnaddr;
ian@0 439 unsigned int insn;
ian@0 440 } fpq[16];
ian@0 441 };
ian@0 442 struct fps __user *fps = (struct fps __user *) addr;
ian@0 443 unsigned long *fpregs = task_thread_info(child)->fpregs;
ian@0 444
ian@0 445 if (copy_to_user(&fps->regs[0], fpregs,
ian@0 446 (32 * sizeof(unsigned int))) ||
ian@0 447 __put_user(task_thread_info(child)->xfsr[0], (&fps->fsr)) ||
ian@0 448 __put_user(0, (&fps->fpqd)) ||
ian@0 449 __put_user(0, (&fps->flags)) ||
ian@0 450 __put_user(0, (&fps->extra)) ||
ian@0 451 clear_user(&fps->fpq[0], 32 * sizeof(unsigned int))) {
ian@0 452 pt_error_return(regs, EFAULT);
ian@0 453 goto out_tsk;
ian@0 454 }
ian@0 455 pt_succ_return(regs, 0);
ian@0 456 goto out_tsk;
ian@0 457 }
ian@0 458
ian@0 459 case PTRACE_GETFPREGS64: {
ian@0 460 struct fps {
ian@0 461 unsigned int regs[64];
ian@0 462 unsigned long fsr;
ian@0 463 };
ian@0 464 struct fps __user *fps = (struct fps __user *) addr;
ian@0 465 unsigned long *fpregs = task_thread_info(child)->fpregs;
ian@0 466
ian@0 467 if (copy_to_user(&fps->regs[0], fpregs,
ian@0 468 (64 * sizeof(unsigned int))) ||
ian@0 469 __put_user(task_thread_info(child)->xfsr[0], (&fps->fsr))) {
ian@0 470 pt_error_return(regs, EFAULT);
ian@0 471 goto out_tsk;
ian@0 472 }
ian@0 473 pt_succ_return(regs, 0);
ian@0 474 goto out_tsk;
ian@0 475 }
ian@0 476
ian@0 477 case PTRACE_SETFPREGS: {
ian@0 478 struct fps {
ian@0 479 unsigned int regs[32];
ian@0 480 unsigned int fsr;
ian@0 481 unsigned int flags;
ian@0 482 unsigned int extra;
ian@0 483 unsigned int fpqd;
ian@0 484 struct fq {
ian@0 485 unsigned int insnaddr;
ian@0 486 unsigned int insn;
ian@0 487 } fpq[16];
ian@0 488 };
ian@0 489 struct fps __user *fps = (struct fps __user *) addr;
ian@0 490 unsigned long *fpregs = task_thread_info(child)->fpregs;
ian@0 491 unsigned fsr;
ian@0 492
ian@0 493 if (copy_from_user(fpregs, &fps->regs[0],
ian@0 494 (32 * sizeof(unsigned int))) ||
ian@0 495 __get_user(fsr, (&fps->fsr))) {
ian@0 496 pt_error_return(regs, EFAULT);
ian@0 497 goto out_tsk;
ian@0 498 }
ian@0 499 task_thread_info(child)->xfsr[0] &= 0xffffffff00000000UL;
ian@0 500 task_thread_info(child)->xfsr[0] |= fsr;
ian@0 501 if (!(task_thread_info(child)->fpsaved[0] & FPRS_FEF))
ian@0 502 task_thread_info(child)->gsr[0] = 0;
ian@0 503 task_thread_info(child)->fpsaved[0] |= (FPRS_FEF | FPRS_DL);
ian@0 504 pt_succ_return(regs, 0);
ian@0 505 goto out_tsk;
ian@0 506 }
ian@0 507
ian@0 508 case PTRACE_SETFPREGS64: {
ian@0 509 struct fps {
ian@0 510 unsigned int regs[64];
ian@0 511 unsigned long fsr;
ian@0 512 };
ian@0 513 struct fps __user *fps = (struct fps __user *) addr;
ian@0 514 unsigned long *fpregs = task_thread_info(child)->fpregs;
ian@0 515
ian@0 516 if (copy_from_user(fpregs, &fps->regs[0],
ian@0 517 (64 * sizeof(unsigned int))) ||
ian@0 518 __get_user(task_thread_info(child)->xfsr[0], (&fps->fsr))) {
ian@0 519 pt_error_return(regs, EFAULT);
ian@0 520 goto out_tsk;
ian@0 521 }
ian@0 522 if (!(task_thread_info(child)->fpsaved[0] & FPRS_FEF))
ian@0 523 task_thread_info(child)->gsr[0] = 0;
ian@0 524 task_thread_info(child)->fpsaved[0] |= (FPRS_FEF | FPRS_DL | FPRS_DU);
ian@0 525 pt_succ_return(regs, 0);
ian@0 526 goto out_tsk;
ian@0 527 }
ian@0 528
ian@0 529 case PTRACE_READTEXT:
ian@0 530 case PTRACE_READDATA: {
ian@0 531 int res = ptrace_readdata(child, addr,
ian@0 532 (char __user *)addr2, data);
ian@0 533 if (res == data) {
ian@0 534 pt_succ_return(regs, 0);
ian@0 535 goto out_tsk;
ian@0 536 }
ian@0 537 if (res >= 0)
ian@0 538 res = -EIO;
ian@0 539 pt_error_return(regs, -res);
ian@0 540 goto out_tsk;
ian@0 541 }
ian@0 542
ian@0 543 case PTRACE_WRITETEXT:
ian@0 544 case PTRACE_WRITEDATA: {
ian@0 545 int res = ptrace_writedata(child, (char __user *) addr2,
ian@0 546 addr, data);
ian@0 547 if (res == data) {
ian@0 548 pt_succ_return(regs, 0);
ian@0 549 goto out_tsk;
ian@0 550 }
ian@0 551 if (res >= 0)
ian@0 552 res = -EIO;
ian@0 553 pt_error_return(regs, -res);
ian@0 554 goto out_tsk;
ian@0 555 }
ian@0 556 case PTRACE_SYSCALL: /* continue and stop at (return from) syscall */
ian@0 557 addr = 1;
ian@0 558
ian@0 559 case PTRACE_CONT: { /* restart after signal. */
ian@0 560 if (!valid_signal(data)) {
ian@0 561 pt_error_return(regs, EIO);
ian@0 562 goto out_tsk;
ian@0 563 }
ian@0 564
ian@0 565 if (request == PTRACE_SYSCALL) {
ian@0 566 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
ian@0 567 } else {
ian@0 568 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
ian@0 569 }
ian@0 570
ian@0 571 child->exit_code = data;
ian@0 572 #ifdef DEBUG_PTRACE
ian@0 573 printk("CONT: %s [%d]: set exit_code = %x %lx %lx\n", child->comm,
ian@0 574 child->pid, child->exit_code,
ian@0 575 task_pt_regs(child)->tpc,
ian@0 576 task_pt_regs(child)->tnpc);
ian@0 577
ian@0 578 #endif
ian@0 579 wake_up_process(child);
ian@0 580 pt_succ_return(regs, 0);
ian@0 581 goto out_tsk;
ian@0 582 }
ian@0 583
ian@0 584 /*
ian@0 585 * make the child exit. Best I can do is send it a sigkill.
ian@0 586 * perhaps it should be put in the status that it wants to
ian@0 587 * exit.
ian@0 588 */
ian@0 589 case PTRACE_KILL: {
ian@0 590 if (child->exit_state == EXIT_ZOMBIE) { /* already dead */
ian@0 591 pt_succ_return(regs, 0);
ian@0 592 goto out_tsk;
ian@0 593 }
ian@0 594 child->exit_code = SIGKILL;
ian@0 595 wake_up_process(child);
ian@0 596 pt_succ_return(regs, 0);
ian@0 597 goto out_tsk;
ian@0 598 }
ian@0 599
ian@0 600 case PTRACE_SUNDETACH: { /* detach a process that was attached. */
ian@0 601 int error = ptrace_detach(child, data);
ian@0 602 if (error) {
ian@0 603 pt_error_return(regs, EIO);
ian@0 604 goto out_tsk;
ian@0 605 }
ian@0 606 pt_succ_return(regs, 0);
ian@0 607 goto out_tsk;
ian@0 608 }
ian@0 609
ian@0 610 /* PTRACE_DUMPCORE unsupported... */
ian@0 611
ian@0 612 case PTRACE_GETEVENTMSG: {
ian@0 613 int err;
ian@0 614
ian@0 615 if (test_thread_flag(TIF_32BIT))
ian@0 616 err = put_user(child->ptrace_message,
ian@0 617 (unsigned int __user *) data);
ian@0 618 else
ian@0 619 err = put_user(child->ptrace_message,
ian@0 620 (unsigned long __user *) data);
ian@0 621 if (err)
ian@0 622 pt_error_return(regs, -err);
ian@0 623 else
ian@0 624 pt_succ_return(regs, 0);
ian@0 625 break;
ian@0 626 }
ian@0 627
ian@0 628 default: {
ian@0 629 int err = ptrace_request(child, request, addr, data);
ian@0 630 if (err)
ian@0 631 pt_error_return(regs, -err);
ian@0 632 else
ian@0 633 pt_succ_return(regs, 0);
ian@0 634 goto out_tsk;
ian@0 635 }
ian@0 636 }
ian@0 637 out_tsk:
ian@0 638 if (child)
ian@0 639 put_task_struct(child);
ian@0 640 out:
ian@0 641 unlock_kernel();
ian@0 642 }
ian@0 643
ian@0 644 asmlinkage void syscall_trace(struct pt_regs *regs, int syscall_exit_p)
ian@0 645 {
ian@0 646 /* do the secure computing check first */
ian@0 647 secure_computing(regs->u_regs[UREG_G1]);
ian@0 648
ian@0 649 if (unlikely(current->audit_context) && syscall_exit_p) {
ian@0 650 unsigned long tstate = regs->tstate;
ian@0 651 int result = AUDITSC_SUCCESS;
ian@0 652
ian@0 653 if (unlikely(tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
ian@0 654 result = AUDITSC_FAILURE;
ian@0 655
ian@0 656 audit_syscall_exit(result, regs->u_regs[UREG_I0]);
ian@0 657 }
ian@0 658
ian@0 659 if (!(current->ptrace & PT_PTRACED))
ian@0 660 goto out;
ian@0 661
ian@0 662 if (!test_thread_flag(TIF_SYSCALL_TRACE))
ian@0 663 goto out;
ian@0 664
ian@0 665 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
ian@0 666 ? 0x80 : 0));
ian@0 667
ian@0 668 /*
ian@0 669 * this isn't the same as continuing with a signal, but it will do
ian@0 670 * for normal use. strace only continues with a signal if the
ian@0 671 * stopping signal is not SIGTRAP. -brl
ian@0 672 */
ian@0 673 if (current->exit_code) {
ian@0 674 send_sig(current->exit_code, current, 1);
ian@0 675 current->exit_code = 0;
ian@0 676 }
ian@0 677
ian@0 678 out:
ian@0 679 if (unlikely(current->audit_context) && !syscall_exit_p)
ian@0 680 audit_syscall_entry((test_thread_flag(TIF_32BIT) ?
ian@0 681 AUDIT_ARCH_SPARC :
ian@0 682 AUDIT_ARCH_SPARC64),
ian@0 683 regs->u_regs[UREG_G1],
ian@0 684 regs->u_regs[UREG_I0],
ian@0 685 regs->u_regs[UREG_I1],
ian@0 686 regs->u_regs[UREG_I2],
ian@0 687 regs->u_regs[UREG_I3]);
ian@0 688 }