ptrace.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. /*
  2. * linux/arch/arm/kernel/ptrace.c
  3. *
  4. * By Ross Biro 1/23/92
  5. * edited by Linus Torvalds
  6. * ARM modifications Copyright (C) 2000 Russell King
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/mm.h>
  15. #include <linux/smp.h>
  16. #include <linux/ptrace.h>
  17. #include <linux/user.h>
  18. #include <linux/security.h>
  19. #include <linux/init.h>
  20. #include <linux/signal.h>
  21. #include <linux/uaccess.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/system.h>
  24. #include <asm/traps.h>
  25. #include "ptrace.h"
  26. #define REG_PC 15
  27. #define REG_PSR 16
  28. /*
  29. * does not yet catch signals sent when the child dies.
  30. * in exit.c or in signal.c.
  31. */
  32. #if 0
  33. /*
  34. * Breakpoint SWI instruction: SWI &9F0001
  35. */
  36. #define BREAKINST_ARM 0xef9f0001
  37. #define BREAKINST_THUMB 0xdf00 /* fill this in later */
  38. #else
  39. /*
  40. * New breakpoints - use an undefined instruction. The ARM architecture
  41. * reference manual guarantees that the following instruction space
  42. * will produce an undefined instruction exception on all CPUs:
  43. *
  44. * ARM: xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx
  45. * Thumb: 1101 1110 xxxx xxxx
  46. */
  47. #define BREAKINST_ARM 0xe7f001f0
  48. #define BREAKINST_THUMB 0xde01
  49. #endif
  50. /*
  51. * this routine will get a word off of the processes privileged stack.
  52. * the offset is how far from the base addr as stored in the THREAD.
  53. * this routine assumes that all the privileged stacks are in our
  54. * data space.
  55. */
  56. static inline long get_user_reg(struct task_struct *task, int offset)
  57. {
  58. return task_pt_regs(task)->uregs[offset];
  59. }
  60. /*
  61. * this routine will put a word on the processes privileged stack.
  62. * the offset is how far from the base addr as stored in the THREAD.
  63. * this routine assumes that all the privileged stacks are in our
  64. * data space.
  65. */
  66. static inline int
  67. put_user_reg(struct task_struct *task, int offset, long data)
  68. {
  69. struct pt_regs newregs, *regs = task_pt_regs(task);
  70. int ret = -EINVAL;
  71. newregs = *regs;
  72. newregs.uregs[offset] = data;
  73. if (valid_user_regs(&newregs)) {
  74. regs->uregs[offset] = data;
  75. ret = 0;
  76. }
  77. return ret;
  78. }
  79. static inline int
  80. read_u32(struct task_struct *task, unsigned long addr, u32 *res)
  81. {
  82. int ret;
  83. ret = access_process_vm(task, addr, res, sizeof(*res), 0);
  84. return ret == sizeof(*res) ? 0 : -EIO;
  85. }
  86. static inline int
  87. read_instr(struct task_struct *task, unsigned long addr, u32 *res)
  88. {
  89. int ret;
  90. if (addr & 1) {
  91. u16 val;
  92. ret = access_process_vm(task, addr & ~1, &val, sizeof(val), 0);
  93. ret = ret == sizeof(val) ? 0 : -EIO;
  94. *res = val;
  95. } else {
  96. u32 val;
  97. ret = access_process_vm(task, addr & ~3, &val, sizeof(val), 0);
  98. ret = ret == sizeof(val) ? 0 : -EIO;
  99. *res = val;
  100. }
  101. return ret;
  102. }
  103. /*
  104. * Get value of register `rn' (in the instruction)
  105. */
  106. static unsigned long
  107. ptrace_getrn(struct task_struct *child, unsigned long insn)
  108. {
  109. unsigned int reg = (insn >> 16) & 15;
  110. unsigned long val;
  111. val = get_user_reg(child, reg);
  112. if (reg == 15)
  113. val += 8;
  114. return val;
  115. }
  116. /*
  117. * Get value of operand 2 (in an ALU instruction)
  118. */
  119. static unsigned long
  120. ptrace_getaluop2(struct task_struct *child, unsigned long insn)
  121. {
  122. unsigned long val;
  123. int shift;
  124. int type;
  125. if (insn & 1 << 25) {
  126. val = insn & 255;
  127. shift = (insn >> 8) & 15;
  128. type = 3;
  129. } else {
  130. val = get_user_reg (child, insn & 15);
  131. if (insn & (1 << 4))
  132. shift = (int)get_user_reg (child, (insn >> 8) & 15);
  133. else
  134. shift = (insn >> 7) & 31;
  135. type = (insn >> 5) & 3;
  136. }
  137. switch (type) {
  138. case 0: val <<= shift; break;
  139. case 1: val >>= shift; break;
  140. case 2:
  141. val = (((signed long)val) >> shift);
  142. break;
  143. case 3:
  144. val = (val >> shift) | (val << (32 - shift));
  145. break;
  146. }
  147. return val;
  148. }
  149. /*
  150. * Get value of operand 2 (in a LDR instruction)
  151. */
  152. static unsigned long
  153. ptrace_getldrop2(struct task_struct *child, unsigned long insn)
  154. {
  155. unsigned long val;
  156. int shift;
  157. int type;
  158. val = get_user_reg(child, insn & 15);
  159. shift = (insn >> 7) & 31;
  160. type = (insn >> 5) & 3;
  161. switch (type) {
  162. case 0: val <<= shift; break;
  163. case 1: val >>= shift; break;
  164. case 2:
  165. val = (((signed long)val) >> shift);
  166. break;
  167. case 3:
  168. val = (val >> shift) | (val << (32 - shift));
  169. break;
  170. }
  171. return val;
  172. }
  173. #define OP_MASK 0x01e00000
  174. #define OP_AND 0x00000000
  175. #define OP_EOR 0x00200000
  176. #define OP_SUB 0x00400000
  177. #define OP_RSB 0x00600000
  178. #define OP_ADD 0x00800000
  179. #define OP_ADC 0x00a00000
  180. #define OP_SBC 0x00c00000
  181. #define OP_RSC 0x00e00000
  182. #define OP_ORR 0x01800000
  183. #define OP_MOV 0x01a00000
  184. #define OP_BIC 0x01c00000
  185. #define OP_MVN 0x01e00000
  186. static unsigned long
  187. get_branch_address(struct task_struct *child, unsigned long pc, unsigned long insn)
  188. {
  189. u32 alt = 0;
  190. switch (insn & 0x0e000000) {
  191. case 0x00000000:
  192. case 0x02000000: {
  193. /*
  194. * data processing
  195. */
  196. long aluop1, aluop2, ccbit;
  197. if ((insn & 0x0fffffd0) == 0x012fff10) {
  198. /*
  199. * bx or blx
  200. */
  201. alt = get_user_reg(child, insn & 15);
  202. break;
  203. }
  204. if ((insn & 0xf000) != 0xf000)
  205. break;
  206. aluop1 = ptrace_getrn(child, insn);
  207. aluop2 = ptrace_getaluop2(child, insn);
  208. ccbit = get_user_reg(child, REG_PSR) & PSR_C_BIT ? 1 : 0;
  209. switch (insn & OP_MASK) {
  210. case OP_AND: alt = aluop1 & aluop2; break;
  211. case OP_EOR: alt = aluop1 ^ aluop2; break;
  212. case OP_SUB: alt = aluop1 - aluop2; break;
  213. case OP_RSB: alt = aluop2 - aluop1; break;
  214. case OP_ADD: alt = aluop1 + aluop2; break;
  215. case OP_ADC: alt = aluop1 + aluop2 + ccbit; break;
  216. case OP_SBC: alt = aluop1 - aluop2 + ccbit; break;
  217. case OP_RSC: alt = aluop2 - aluop1 + ccbit; break;
  218. case OP_ORR: alt = aluop1 | aluop2; break;
  219. case OP_MOV: alt = aluop2; break;
  220. case OP_BIC: alt = aluop1 & ~aluop2; break;
  221. case OP_MVN: alt = ~aluop2; break;
  222. }
  223. break;
  224. }
  225. case 0x04000000:
  226. case 0x06000000:
  227. /*
  228. * ldr
  229. */
  230. if ((insn & 0x0010f000) == 0x0010f000) {
  231. unsigned long base;
  232. base = ptrace_getrn(child, insn);
  233. if (insn & 1 << 24) {
  234. long aluop2;
  235. if (insn & 0x02000000)
  236. aluop2 = ptrace_getldrop2(child, insn);
  237. else
  238. aluop2 = insn & 0xfff;
  239. if (insn & 1 << 23)
  240. base += aluop2;
  241. else
  242. base -= aluop2;
  243. }
  244. read_u32(child, base, &alt);
  245. }
  246. break;
  247. case 0x08000000:
  248. /*
  249. * ldm
  250. */
  251. if ((insn & 0x00108000) == 0x00108000) {
  252. unsigned long base;
  253. unsigned int nr_regs;
  254. if (insn & (1 << 23)) {
  255. nr_regs = hweight16(insn & 65535) << 2;
  256. if (!(insn & (1 << 24)))
  257. nr_regs -= 4;
  258. } else {
  259. if (insn & (1 << 24))
  260. nr_regs = -4;
  261. else
  262. nr_regs = 0;
  263. }
  264. base = ptrace_getrn(child, insn);
  265. read_u32(child, base + nr_regs, &alt);
  266. break;
  267. }
  268. break;
  269. case 0x0a000000: {
  270. /*
  271. * bl or b
  272. */
  273. signed long displ;
  274. /* It's a branch/branch link: instead of trying to
  275. * figure out whether the branch will be taken or not,
  276. * we'll put a breakpoint at both locations. This is
  277. * simpler, more reliable, and probably not a whole lot
  278. * slower than the alternative approach of emulating the
  279. * branch.
  280. */
  281. displ = (insn & 0x00ffffff) << 8;
  282. displ = (displ >> 6) + 8;
  283. if (displ != 0 && displ != 4)
  284. alt = pc + displ;
  285. }
  286. break;
  287. }
  288. return alt;
  289. }
  290. static int
  291. swap_insn(struct task_struct *task, unsigned long addr,
  292. void *old_insn, void *new_insn, int size)
  293. {
  294. int ret;
  295. ret = access_process_vm(task, addr, old_insn, size, 0);
  296. if (ret == size)
  297. ret = access_process_vm(task, addr, new_insn, size, 1);
  298. return ret;
  299. }
  300. static void
  301. add_breakpoint(struct task_struct *task, struct debug_info *dbg, unsigned long addr)
  302. {
  303. int nr = dbg->nsaved;
  304. if (nr < 2) {
  305. u32 new_insn = BREAKINST_ARM;
  306. int res;
  307. res = swap_insn(task, addr, &dbg->bp[nr].insn, &new_insn, 4);
  308. if (res == 4) {
  309. dbg->bp[nr].address = addr;
  310. dbg->nsaved += 1;
  311. }
  312. } else
  313. printk(KERN_ERR "ptrace: too many breakpoints\n");
  314. }
  315. /*
  316. * Clear one breakpoint in the user program. We copy what the hardware
  317. * does and use bit 0 of the address to indicate whether this is a Thumb
  318. * breakpoint or an ARM breakpoint.
  319. */
  320. static void clear_breakpoint(struct task_struct *task, struct debug_entry *bp)
  321. {
  322. unsigned long addr = bp->address;
  323. union debug_insn old_insn;
  324. int ret;
  325. if (addr & 1) {
  326. ret = swap_insn(task, addr & ~1, &old_insn.thumb,
  327. &bp->insn.thumb, 2);
  328. if (ret != 2 || old_insn.thumb != BREAKINST_THUMB)
  329. printk(KERN_ERR "%s:%d: corrupted Thumb breakpoint at "
  330. "0x%08lx (0x%04x)\n", task->comm,
  331. task_pid_nr(task), addr, old_insn.thumb);
  332. } else {
  333. ret = swap_insn(task, addr & ~3, &old_insn.arm,
  334. &bp->insn.arm, 4);
  335. if (ret != 4 || old_insn.arm != BREAKINST_ARM)
  336. printk(KERN_ERR "%s:%d: corrupted ARM breakpoint at "
  337. "0x%08lx (0x%08x)\n", task->comm,
  338. task_pid_nr(task), addr, old_insn.arm);
  339. }
  340. }
  341. void ptrace_set_bpt(struct task_struct *child)
  342. {
  343. struct pt_regs *regs;
  344. unsigned long pc;
  345. u32 insn;
  346. int res;
  347. regs = task_pt_regs(child);
  348. pc = instruction_pointer(regs);
  349. if (thumb_mode(regs)) {
  350. printk(KERN_WARNING "ptrace: can't handle thumb mode\n");
  351. return;
  352. }
  353. res = read_instr(child, pc, &insn);
  354. if (!res) {
  355. struct debug_info *dbg = &child->thread.debug;
  356. unsigned long alt;
  357. dbg->nsaved = 0;
  358. alt = get_branch_address(child, pc, insn);
  359. if (alt)
  360. add_breakpoint(child, dbg, alt);
  361. /*
  362. * Note that we ignore the result of setting the above
  363. * breakpoint since it may fail. When it does, this is
  364. * not so much an error, but a forewarning that we may
  365. * be receiving a prefetch abort shortly.
  366. *
  367. * If we don't set this breakpoint here, then we can
  368. * lose control of the thread during single stepping.
  369. */
  370. if (!alt || predicate(insn) != PREDICATE_ALWAYS)
  371. add_breakpoint(child, dbg, pc + 4);
  372. }
  373. }
  374. /*
  375. * Ensure no single-step breakpoint is pending. Returns non-zero
  376. * value if child was being single-stepped.
  377. */
  378. void ptrace_cancel_bpt(struct task_struct *child)
  379. {
  380. int i, nsaved = child->thread.debug.nsaved;
  381. child->thread.debug.nsaved = 0;
  382. if (nsaved > 2) {
  383. printk("ptrace_cancel_bpt: bogus nsaved: %d!\n", nsaved);
  384. nsaved = 2;
  385. }
  386. for (i = 0; i < nsaved; i++)
  387. clear_breakpoint(child, &child->thread.debug.bp[i]);
  388. }
  389. /*
  390. * Called by kernel/ptrace.c when detaching..
  391. */
  392. void ptrace_disable(struct task_struct *child)
  393. {
  394. single_step_disable(child);
  395. }
  396. /*
  397. * Handle hitting a breakpoint.
  398. */
  399. void ptrace_break(struct task_struct *tsk, struct pt_regs *regs)
  400. {
  401. siginfo_t info;
  402. ptrace_cancel_bpt(tsk);
  403. info.si_signo = SIGTRAP;
  404. info.si_errno = 0;
  405. info.si_code = TRAP_BRKPT;
  406. info.si_addr = (void __user *)instruction_pointer(regs);
  407. force_sig_info(SIGTRAP, &info, tsk);
  408. }
  409. static int break_trap(struct pt_regs *regs, unsigned int instr)
  410. {
  411. ptrace_break(current, regs);
  412. return 0;
  413. }
  414. static struct undef_hook arm_break_hook = {
  415. .instr_mask = 0x0fffffff,
  416. .instr_val = 0x07f001f0,
  417. .cpsr_mask = PSR_T_BIT,
  418. .cpsr_val = 0,
  419. .fn = break_trap,
  420. };
  421. static struct undef_hook thumb_break_hook = {
  422. .instr_mask = 0xffff,
  423. .instr_val = 0xde01,
  424. .cpsr_mask = PSR_T_BIT,
  425. .cpsr_val = PSR_T_BIT,
  426. .fn = break_trap,
  427. };
  428. static int __init ptrace_break_init(void)
  429. {
  430. register_undef_hook(&arm_break_hook);
  431. register_undef_hook(&thumb_break_hook);
  432. return 0;
  433. }
  434. core_initcall(ptrace_break_init);
  435. /*
  436. * Read the word at offset "off" into the "struct user". We
  437. * actually access the pt_regs stored on the kernel stack.
  438. */
  439. static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
  440. unsigned long __user *ret)
  441. {
  442. unsigned long tmp;
  443. if (off & 3 || off >= sizeof(struct user))
  444. return -EIO;
  445. tmp = 0;
  446. if (off < sizeof(struct pt_regs))
  447. tmp = get_user_reg(tsk, off >> 2);
  448. return put_user(tmp, ret);
  449. }
  450. /*
  451. * Write the word at offset "off" into "struct user". We
  452. * actually access the pt_regs stored on the kernel stack.
  453. */
  454. static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
  455. unsigned long val)
  456. {
  457. if (off & 3 || off >= sizeof(struct user))
  458. return -EIO;
  459. if (off >= sizeof(struct pt_regs))
  460. return 0;
  461. return put_user_reg(tsk, off >> 2, val);
  462. }
  463. /*
  464. * Get all user integer registers.
  465. */
  466. static int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
  467. {
  468. struct pt_regs *regs = task_pt_regs(tsk);
  469. return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
  470. }
  471. /*
  472. * Set all user integer registers.
  473. */
  474. static int ptrace_setregs(struct task_struct *tsk, void __user *uregs)
  475. {
  476. struct pt_regs newregs;
  477. int ret;
  478. ret = -EFAULT;
  479. if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
  480. struct pt_regs *regs = task_pt_regs(tsk);
  481. ret = -EINVAL;
  482. if (valid_user_regs(&newregs)) {
  483. *regs = newregs;
  484. ret = 0;
  485. }
  486. }
  487. return ret;
  488. }
  489. /*
  490. * Get the child FPU state.
  491. */
  492. static int ptrace_getfpregs(struct task_struct *tsk, void __user *ufp)
  493. {
  494. return copy_to_user(ufp, &task_thread_info(tsk)->fpstate,
  495. sizeof(struct user_fp)) ? -EFAULT : 0;
  496. }
  497. /*
  498. * Set the child FPU state.
  499. */
  500. static int ptrace_setfpregs(struct task_struct *tsk, void __user *ufp)
  501. {
  502. struct thread_info *thread = task_thread_info(tsk);
  503. thread->used_cp[1] = thread->used_cp[2] = 1;
  504. return copy_from_user(&thread->fpstate, ufp,
  505. sizeof(struct user_fp)) ? -EFAULT : 0;
  506. }
  507. #ifdef CONFIG_IWMMXT
  508. /*
  509. * Get the child iWMMXt state.
  510. */
  511. static int ptrace_getwmmxregs(struct task_struct *tsk, void __user *ufp)
  512. {
  513. struct thread_info *thread = task_thread_info(tsk);
  514. if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
  515. return -ENODATA;
  516. iwmmxt_task_disable(thread); /* force it to ram */
  517. return copy_to_user(ufp, &thread->fpstate.iwmmxt, IWMMXT_SIZE)
  518. ? -EFAULT : 0;
  519. }
  520. /*
  521. * Set the child iWMMXt state.
  522. */
  523. static int ptrace_setwmmxregs(struct task_struct *tsk, void __user *ufp)
  524. {
  525. struct thread_info *thread = task_thread_info(tsk);
  526. if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
  527. return -EACCES;
  528. iwmmxt_task_release(thread); /* force a reload */
  529. return copy_from_user(&thread->fpstate.iwmmxt, ufp, IWMMXT_SIZE)
  530. ? -EFAULT : 0;
  531. }
  532. #endif
  533. #ifdef CONFIG_CRUNCH
  534. /*
  535. * Get the child Crunch state.
  536. */
  537. static int ptrace_getcrunchregs(struct task_struct *tsk, void __user *ufp)
  538. {
  539. struct thread_info *thread = task_thread_info(tsk);
  540. crunch_task_disable(thread); /* force it to ram */
  541. return copy_to_user(ufp, &thread->crunchstate, CRUNCH_SIZE)
  542. ? -EFAULT : 0;
  543. }
  544. /*
  545. * Set the child Crunch state.
  546. */
  547. static int ptrace_setcrunchregs(struct task_struct *tsk, void __user *ufp)
  548. {
  549. struct thread_info *thread = task_thread_info(tsk);
  550. crunch_task_release(thread); /* force a reload */
  551. return copy_from_user(&thread->crunchstate, ufp, CRUNCH_SIZE)
  552. ? -EFAULT : 0;
  553. }
  554. #endif
  555. #ifdef CONFIG_VFP
  556. /*
  557. * Get the child VFP state.
  558. */
  559. static int ptrace_getvfpregs(struct task_struct *tsk, void __user *data)
  560. {
  561. struct thread_info *thread = task_thread_info(tsk);
  562. union vfp_state *vfp = &thread->vfpstate;
  563. struct user_vfp __user *ufp = data;
  564. vfp_sync_state(thread);
  565. /* copy the floating point registers */
  566. if (copy_to_user(&ufp->fpregs, &vfp->hard.fpregs,
  567. sizeof(vfp->hard.fpregs)))
  568. return -EFAULT;
  569. /* copy the status and control register */
  570. if (put_user(vfp->hard.fpscr, &ufp->fpscr))
  571. return -EFAULT;
  572. return 0;
  573. }
  574. /*
  575. * Set the child VFP state.
  576. */
  577. static int ptrace_setvfpregs(struct task_struct *tsk, void __user *data)
  578. {
  579. struct thread_info *thread = task_thread_info(tsk);
  580. union vfp_state *vfp = &thread->vfpstate;
  581. struct user_vfp __user *ufp = data;
  582. vfp_sync_state(thread);
  583. /* copy the floating point registers */
  584. if (copy_from_user(&vfp->hard.fpregs, &ufp->fpregs,
  585. sizeof(vfp->hard.fpregs)))
  586. return -EFAULT;
  587. /* copy the status and control register */
  588. if (get_user(vfp->hard.fpscr, &ufp->fpscr))
  589. return -EFAULT;
  590. return 0;
  591. }
  592. #endif
  593. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  594. {
  595. int ret;
  596. switch (request) {
  597. /*
  598. * read word at location "addr" in the child process.
  599. */
  600. case PTRACE_PEEKTEXT:
  601. case PTRACE_PEEKDATA:
  602. ret = generic_ptrace_peekdata(child, addr, data);
  603. break;
  604. case PTRACE_PEEKUSR:
  605. ret = ptrace_read_user(child, addr, (unsigned long __user *)data);
  606. break;
  607. /*
  608. * write the word at location addr.
  609. */
  610. case PTRACE_POKETEXT:
  611. case PTRACE_POKEDATA:
  612. ret = generic_ptrace_pokedata(child, addr, data);
  613. break;
  614. case PTRACE_POKEUSR:
  615. ret = ptrace_write_user(child, addr, data);
  616. break;
  617. /*
  618. * continue/restart and stop at next (return from) syscall
  619. */
  620. case PTRACE_SYSCALL:
  621. case PTRACE_CONT:
  622. ret = -EIO;
  623. if (!valid_signal(data))
  624. break;
  625. if (request == PTRACE_SYSCALL)
  626. set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  627. else
  628. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  629. child->exit_code = data;
  630. single_step_disable(child);
  631. wake_up_process(child);
  632. ret = 0;
  633. break;
  634. /*
  635. * make the child exit. Best I can do is send it a sigkill.
  636. * perhaps it should be put in the status that it wants to
  637. * exit.
  638. */
  639. case PTRACE_KILL:
  640. single_step_disable(child);
  641. if (child->exit_state != EXIT_ZOMBIE) {
  642. child->exit_code = SIGKILL;
  643. wake_up_process(child);
  644. }
  645. ret = 0;
  646. break;
  647. /*
  648. * execute single instruction.
  649. */
  650. case PTRACE_SINGLESTEP:
  651. ret = -EIO;
  652. if (!valid_signal(data))
  653. break;
  654. single_step_enable(child);
  655. clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  656. child->exit_code = data;
  657. /* give it a chance to run. */
  658. wake_up_process(child);
  659. ret = 0;
  660. break;
  661. case PTRACE_GETREGS:
  662. ret = ptrace_getregs(child, (void __user *)data);
  663. break;
  664. case PTRACE_SETREGS:
  665. ret = ptrace_setregs(child, (void __user *)data);
  666. break;
  667. case PTRACE_GETFPREGS:
  668. ret = ptrace_getfpregs(child, (void __user *)data);
  669. break;
  670. case PTRACE_SETFPREGS:
  671. ret = ptrace_setfpregs(child, (void __user *)data);
  672. break;
  673. #ifdef CONFIG_IWMMXT
  674. case PTRACE_GETWMMXREGS:
  675. ret = ptrace_getwmmxregs(child, (void __user *)data);
  676. break;
  677. case PTRACE_SETWMMXREGS:
  678. ret = ptrace_setwmmxregs(child, (void __user *)data);
  679. break;
  680. #endif
  681. case PTRACE_GET_THREAD_AREA:
  682. ret = put_user(task_thread_info(child)->tp_value,
  683. (unsigned long __user *) data);
  684. break;
  685. case PTRACE_SET_SYSCALL:
  686. task_thread_info(child)->syscall = data;
  687. ret = 0;
  688. break;
  689. #ifdef CONFIG_CRUNCH
  690. case PTRACE_GETCRUNCHREGS:
  691. ret = ptrace_getcrunchregs(child, (void __user *)data);
  692. break;
  693. case PTRACE_SETCRUNCHREGS:
  694. ret = ptrace_setcrunchregs(child, (void __user *)data);
  695. break;
  696. #endif
  697. #ifdef CONFIG_VFP
  698. case PTRACE_GETVFPREGS:
  699. ret = ptrace_getvfpregs(child, (void __user *)data);
  700. break;
  701. case PTRACE_SETVFPREGS:
  702. ret = ptrace_setvfpregs(child, (void __user *)data);
  703. break;
  704. #endif
  705. default:
  706. ret = ptrace_request(child, request, addr, data);
  707. break;
  708. }
  709. return ret;
  710. }
  711. asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
  712. {
  713. unsigned long ip;
  714. if (!test_thread_flag(TIF_SYSCALL_TRACE))
  715. return scno;
  716. if (!(current->ptrace & PT_PTRACED))
  717. return scno;
  718. /*
  719. * Save IP. IP is used to denote syscall entry/exit:
  720. * IP = 0 -> entry, = 1 -> exit
  721. */
  722. ip = regs->ARM_ip;
  723. regs->ARM_ip = why;
  724. current_thread_info()->syscall = scno;
  725. /* the 0x80 provides a way for the tracing parent to distinguish
  726. between a syscall stop and SIGTRAP delivery */
  727. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  728. ? 0x80 : 0));
  729. /*
  730. * this isn't the same as continuing with a signal, but it will do
  731. * for normal use. strace only continues with a signal if the
  732. * stopping signal is not SIGTRAP. -brl
  733. */
  734. if (current->exit_code) {
  735. send_sig(current->exit_code, current, 1);
  736. current->exit_code = 0;
  737. }
  738. regs->ARM_ip = ip;
  739. return current_thread_info()->syscall;
  740. }