ptrace.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  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. void user_disable_single_step(struct task_struct *task)
  390. {
  391. task->ptrace &= ~PT_SINGLESTEP;
  392. ptrace_cancel_bpt(task);
  393. }
  394. void user_enable_single_step(struct task_struct *task)
  395. {
  396. task->ptrace |= PT_SINGLESTEP;
  397. }
  398. /*
  399. * Called by kernel/ptrace.c when detaching..
  400. */
  401. void ptrace_disable(struct task_struct *child)
  402. {
  403. user_disable_single_step(child);
  404. }
  405. /*
  406. * Handle hitting a breakpoint.
  407. */
  408. void ptrace_break(struct task_struct *tsk, struct pt_regs *regs)
  409. {
  410. siginfo_t info;
  411. ptrace_cancel_bpt(tsk);
  412. info.si_signo = SIGTRAP;
  413. info.si_errno = 0;
  414. info.si_code = TRAP_BRKPT;
  415. info.si_addr = (void __user *)instruction_pointer(regs);
  416. force_sig_info(SIGTRAP, &info, tsk);
  417. }
  418. static int break_trap(struct pt_regs *regs, unsigned int instr)
  419. {
  420. ptrace_break(current, regs);
  421. return 0;
  422. }
  423. static struct undef_hook arm_break_hook = {
  424. .instr_mask = 0x0fffffff,
  425. .instr_val = 0x07f001f0,
  426. .cpsr_mask = PSR_T_BIT,
  427. .cpsr_val = 0,
  428. .fn = break_trap,
  429. };
  430. static struct undef_hook thumb_break_hook = {
  431. .instr_mask = 0xffff,
  432. .instr_val = 0xde01,
  433. .cpsr_mask = PSR_T_BIT,
  434. .cpsr_val = PSR_T_BIT,
  435. .fn = break_trap,
  436. };
  437. static int thumb2_break_trap(struct pt_regs *regs, unsigned int instr)
  438. {
  439. unsigned int instr2;
  440. void __user *pc;
  441. /* Check the second half of the instruction. */
  442. pc = (void __user *)(instruction_pointer(regs) + 2);
  443. if (processor_mode(regs) == SVC_MODE) {
  444. instr2 = *(u16 *) pc;
  445. } else {
  446. get_user(instr2, (u16 __user *)pc);
  447. }
  448. if (instr2 == 0xa000) {
  449. ptrace_break(current, regs);
  450. return 0;
  451. } else {
  452. return 1;
  453. }
  454. }
  455. static struct undef_hook thumb2_break_hook = {
  456. .instr_mask = 0xffff,
  457. .instr_val = 0xf7f0,
  458. .cpsr_mask = PSR_T_BIT,
  459. .cpsr_val = PSR_T_BIT,
  460. .fn = thumb2_break_trap,
  461. };
  462. static int __init ptrace_break_init(void)
  463. {
  464. register_undef_hook(&arm_break_hook);
  465. register_undef_hook(&thumb_break_hook);
  466. register_undef_hook(&thumb2_break_hook);
  467. return 0;
  468. }
  469. core_initcall(ptrace_break_init);
  470. /*
  471. * Read the word at offset "off" into the "struct user". We
  472. * actually access the pt_regs stored on the kernel stack.
  473. */
  474. static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
  475. unsigned long __user *ret)
  476. {
  477. unsigned long tmp;
  478. if (off & 3 || off >= sizeof(struct user))
  479. return -EIO;
  480. tmp = 0;
  481. if (off == PT_TEXT_ADDR)
  482. tmp = tsk->mm->start_code;
  483. else if (off == PT_DATA_ADDR)
  484. tmp = tsk->mm->start_data;
  485. else if (off == PT_TEXT_END_ADDR)
  486. tmp = tsk->mm->end_code;
  487. else if (off < sizeof(struct pt_regs))
  488. tmp = get_user_reg(tsk, off >> 2);
  489. return put_user(tmp, ret);
  490. }
  491. /*
  492. * Write the word at offset "off" into "struct user". We
  493. * actually access the pt_regs stored on the kernel stack.
  494. */
  495. static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
  496. unsigned long val)
  497. {
  498. if (off & 3 || off >= sizeof(struct user))
  499. return -EIO;
  500. if (off >= sizeof(struct pt_regs))
  501. return 0;
  502. return put_user_reg(tsk, off >> 2, val);
  503. }
  504. /*
  505. * Get all user integer registers.
  506. */
  507. static int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
  508. {
  509. struct pt_regs *regs = task_pt_regs(tsk);
  510. return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
  511. }
  512. /*
  513. * Set all user integer registers.
  514. */
  515. static int ptrace_setregs(struct task_struct *tsk, void __user *uregs)
  516. {
  517. struct pt_regs newregs;
  518. int ret;
  519. ret = -EFAULT;
  520. if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
  521. struct pt_regs *regs = task_pt_regs(tsk);
  522. ret = -EINVAL;
  523. if (valid_user_regs(&newregs)) {
  524. *regs = newregs;
  525. ret = 0;
  526. }
  527. }
  528. return ret;
  529. }
  530. /*
  531. * Get the child FPU state.
  532. */
  533. static int ptrace_getfpregs(struct task_struct *tsk, void __user *ufp)
  534. {
  535. return copy_to_user(ufp, &task_thread_info(tsk)->fpstate,
  536. sizeof(struct user_fp)) ? -EFAULT : 0;
  537. }
  538. /*
  539. * Set the child FPU state.
  540. */
  541. static int ptrace_setfpregs(struct task_struct *tsk, void __user *ufp)
  542. {
  543. struct thread_info *thread = task_thread_info(tsk);
  544. thread->used_cp[1] = thread->used_cp[2] = 1;
  545. return copy_from_user(&thread->fpstate, ufp,
  546. sizeof(struct user_fp)) ? -EFAULT : 0;
  547. }
  548. #ifdef CONFIG_IWMMXT
  549. /*
  550. * Get the child iWMMXt state.
  551. */
  552. static int ptrace_getwmmxregs(struct task_struct *tsk, void __user *ufp)
  553. {
  554. struct thread_info *thread = task_thread_info(tsk);
  555. if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
  556. return -ENODATA;
  557. iwmmxt_task_disable(thread); /* force it to ram */
  558. return copy_to_user(ufp, &thread->fpstate.iwmmxt, IWMMXT_SIZE)
  559. ? -EFAULT : 0;
  560. }
  561. /*
  562. * Set the child iWMMXt state.
  563. */
  564. static int ptrace_setwmmxregs(struct task_struct *tsk, void __user *ufp)
  565. {
  566. struct thread_info *thread = task_thread_info(tsk);
  567. if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
  568. return -EACCES;
  569. iwmmxt_task_release(thread); /* force a reload */
  570. return copy_from_user(&thread->fpstate.iwmmxt, ufp, IWMMXT_SIZE)
  571. ? -EFAULT : 0;
  572. }
  573. #endif
  574. #ifdef CONFIG_CRUNCH
  575. /*
  576. * Get the child Crunch state.
  577. */
  578. static int ptrace_getcrunchregs(struct task_struct *tsk, void __user *ufp)
  579. {
  580. struct thread_info *thread = task_thread_info(tsk);
  581. crunch_task_disable(thread); /* force it to ram */
  582. return copy_to_user(ufp, &thread->crunchstate, CRUNCH_SIZE)
  583. ? -EFAULT : 0;
  584. }
  585. /*
  586. * Set the child Crunch state.
  587. */
  588. static int ptrace_setcrunchregs(struct task_struct *tsk, void __user *ufp)
  589. {
  590. struct thread_info *thread = task_thread_info(tsk);
  591. crunch_task_release(thread); /* force a reload */
  592. return copy_from_user(&thread->crunchstate, ufp, CRUNCH_SIZE)
  593. ? -EFAULT : 0;
  594. }
  595. #endif
  596. #ifdef CONFIG_VFP
  597. /*
  598. * Get the child VFP state.
  599. */
  600. static int ptrace_getvfpregs(struct task_struct *tsk, void __user *data)
  601. {
  602. struct thread_info *thread = task_thread_info(tsk);
  603. union vfp_state *vfp = &thread->vfpstate;
  604. struct user_vfp __user *ufp = data;
  605. vfp_sync_hwstate(thread);
  606. /* copy the floating point registers */
  607. if (copy_to_user(&ufp->fpregs, &vfp->hard.fpregs,
  608. sizeof(vfp->hard.fpregs)))
  609. return -EFAULT;
  610. /* copy the status and control register */
  611. if (put_user(vfp->hard.fpscr, &ufp->fpscr))
  612. return -EFAULT;
  613. return 0;
  614. }
  615. /*
  616. * Set the child VFP state.
  617. */
  618. static int ptrace_setvfpregs(struct task_struct *tsk, void __user *data)
  619. {
  620. struct thread_info *thread = task_thread_info(tsk);
  621. union vfp_state *vfp = &thread->vfpstate;
  622. struct user_vfp __user *ufp = data;
  623. vfp_sync_hwstate(thread);
  624. /* copy the floating point registers */
  625. if (copy_from_user(&vfp->hard.fpregs, &ufp->fpregs,
  626. sizeof(vfp->hard.fpregs)))
  627. return -EFAULT;
  628. /* copy the status and control register */
  629. if (get_user(vfp->hard.fpscr, &ufp->fpscr))
  630. return -EFAULT;
  631. vfp_flush_hwstate(thread);
  632. return 0;
  633. }
  634. #endif
  635. long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  636. {
  637. int ret;
  638. switch (request) {
  639. case PTRACE_PEEKUSR:
  640. ret = ptrace_read_user(child, addr, (unsigned long __user *)data);
  641. break;
  642. case PTRACE_POKEUSR:
  643. ret = ptrace_write_user(child, addr, data);
  644. break;
  645. case PTRACE_GETREGS:
  646. ret = ptrace_getregs(child, (void __user *)data);
  647. break;
  648. case PTRACE_SETREGS:
  649. ret = ptrace_setregs(child, (void __user *)data);
  650. break;
  651. case PTRACE_GETFPREGS:
  652. ret = ptrace_getfpregs(child, (void __user *)data);
  653. break;
  654. case PTRACE_SETFPREGS:
  655. ret = ptrace_setfpregs(child, (void __user *)data);
  656. break;
  657. #ifdef CONFIG_IWMMXT
  658. case PTRACE_GETWMMXREGS:
  659. ret = ptrace_getwmmxregs(child, (void __user *)data);
  660. break;
  661. case PTRACE_SETWMMXREGS:
  662. ret = ptrace_setwmmxregs(child, (void __user *)data);
  663. break;
  664. #endif
  665. case PTRACE_GET_THREAD_AREA:
  666. ret = put_user(task_thread_info(child)->tp_value,
  667. (unsigned long __user *) data);
  668. break;
  669. case PTRACE_SET_SYSCALL:
  670. task_thread_info(child)->syscall = data;
  671. ret = 0;
  672. break;
  673. #ifdef CONFIG_CRUNCH
  674. case PTRACE_GETCRUNCHREGS:
  675. ret = ptrace_getcrunchregs(child, (void __user *)data);
  676. break;
  677. case PTRACE_SETCRUNCHREGS:
  678. ret = ptrace_setcrunchregs(child, (void __user *)data);
  679. break;
  680. #endif
  681. #ifdef CONFIG_VFP
  682. case PTRACE_GETVFPREGS:
  683. ret = ptrace_getvfpregs(child, (void __user *)data);
  684. break;
  685. case PTRACE_SETVFPREGS:
  686. ret = ptrace_setvfpregs(child, (void __user *)data);
  687. break;
  688. #endif
  689. default:
  690. ret = ptrace_request(child, request, addr, data);
  691. break;
  692. }
  693. return ret;
  694. }
  695. asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
  696. {
  697. unsigned long ip;
  698. if (!test_thread_flag(TIF_SYSCALL_TRACE))
  699. return scno;
  700. if (!(current->ptrace & PT_PTRACED))
  701. return scno;
  702. /*
  703. * Save IP. IP is used to denote syscall entry/exit:
  704. * IP = 0 -> entry, = 1 -> exit
  705. */
  706. ip = regs->ARM_ip;
  707. regs->ARM_ip = why;
  708. current_thread_info()->syscall = scno;
  709. /* the 0x80 provides a way for the tracing parent to distinguish
  710. between a syscall stop and SIGTRAP delivery */
  711. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  712. ? 0x80 : 0));
  713. /*
  714. * this isn't the same as continuing with a signal, but it will do
  715. * for normal use. strace only continues with a signal if the
  716. * stopping signal is not SIGTRAP. -brl
  717. */
  718. if (current->exit_code) {
  719. send_sig(current->exit_code, current, 1);
  720. current->exit_code = 0;
  721. }
  722. regs->ARM_ip = ip;
  723. return current_thread_info()->syscall;
  724. }