ptrace.c 17 KB

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