ptrace.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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 <linux/perf_event.h>
  23. #include <linux/hw_breakpoint.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/system.h>
  26. #include <asm/traps.h>
  27. #define REG_PC 15
  28. #define REG_PSR 16
  29. /*
  30. * does not yet catch signals sent when the child dies.
  31. * in exit.c or in signal.c.
  32. */
  33. #if 0
  34. /*
  35. * Breakpoint SWI instruction: SWI &9F0001
  36. */
  37. #define BREAKINST_ARM 0xef9f0001
  38. #define BREAKINST_THUMB 0xdf00 /* fill this in later */
  39. #else
  40. /*
  41. * New breakpoints - use an undefined instruction. The ARM architecture
  42. * reference manual guarantees that the following instruction space
  43. * will produce an undefined instruction exception on all CPUs:
  44. *
  45. * ARM: xxxx 0111 1111 xxxx xxxx xxxx 1111 xxxx
  46. * Thumb: 1101 1110 xxxx xxxx
  47. */
  48. #define BREAKINST_ARM 0xe7f001f0
  49. #define BREAKINST_THUMB 0xde01
  50. #endif
  51. struct pt_regs_offset {
  52. const char *name;
  53. int offset;
  54. };
  55. #define REG_OFFSET_NAME(r) \
  56. {.name = #r, .offset = offsetof(struct pt_regs, ARM_##r)}
  57. #define REG_OFFSET_END {.name = NULL, .offset = 0}
  58. static const struct pt_regs_offset regoffset_table[] = {
  59. REG_OFFSET_NAME(r0),
  60. REG_OFFSET_NAME(r1),
  61. REG_OFFSET_NAME(r2),
  62. REG_OFFSET_NAME(r3),
  63. REG_OFFSET_NAME(r4),
  64. REG_OFFSET_NAME(r5),
  65. REG_OFFSET_NAME(r6),
  66. REG_OFFSET_NAME(r7),
  67. REG_OFFSET_NAME(r8),
  68. REG_OFFSET_NAME(r9),
  69. REG_OFFSET_NAME(r10),
  70. REG_OFFSET_NAME(fp),
  71. REG_OFFSET_NAME(ip),
  72. REG_OFFSET_NAME(sp),
  73. REG_OFFSET_NAME(lr),
  74. REG_OFFSET_NAME(pc),
  75. REG_OFFSET_NAME(cpsr),
  76. REG_OFFSET_NAME(ORIG_r0),
  77. REG_OFFSET_END,
  78. };
  79. /**
  80. * regs_query_register_offset() - query register offset from its name
  81. * @name: the name of a register
  82. *
  83. * regs_query_register_offset() returns the offset of a register in struct
  84. * pt_regs from its name. If the name is invalid, this returns -EINVAL;
  85. */
  86. int regs_query_register_offset(const char *name)
  87. {
  88. const struct pt_regs_offset *roff;
  89. for (roff = regoffset_table; roff->name != NULL; roff++)
  90. if (!strcmp(roff->name, name))
  91. return roff->offset;
  92. return -EINVAL;
  93. }
  94. /**
  95. * regs_query_register_name() - query register name from its offset
  96. * @offset: the offset of a register in struct pt_regs.
  97. *
  98. * regs_query_register_name() returns the name of a register from its
  99. * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
  100. */
  101. const char *regs_query_register_name(unsigned int offset)
  102. {
  103. const struct pt_regs_offset *roff;
  104. for (roff = regoffset_table; roff->name != NULL; roff++)
  105. if (roff->offset == offset)
  106. return roff->name;
  107. return NULL;
  108. }
  109. /**
  110. * regs_within_kernel_stack() - check the address in the stack
  111. * @regs: pt_regs which contains kernel stack pointer.
  112. * @addr: address which is checked.
  113. *
  114. * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
  115. * If @addr is within the kernel stack, it returns true. If not, returns false.
  116. */
  117. bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
  118. {
  119. return ((addr & ~(THREAD_SIZE - 1)) ==
  120. (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
  121. }
  122. /**
  123. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  124. * @regs: pt_regs which contains kernel stack pointer.
  125. * @n: stack entry number.
  126. *
  127. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  128. * is specified by @regs. If the @n th entry is NOT in the kernel stack,
  129. * this returns 0.
  130. */
  131. unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
  132. {
  133. unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
  134. addr += n;
  135. if (regs_within_kernel_stack(regs, (unsigned long)addr))
  136. return *addr;
  137. else
  138. return 0;
  139. }
  140. /*
  141. * this routine will get a word off of the processes privileged stack.
  142. * the offset is how far from the base addr as stored in the THREAD.
  143. * this routine assumes that all the privileged stacks are in our
  144. * data space.
  145. */
  146. static inline long get_user_reg(struct task_struct *task, int offset)
  147. {
  148. return task_pt_regs(task)->uregs[offset];
  149. }
  150. /*
  151. * this routine will put a word on the processes privileged stack.
  152. * the offset is how far from the base addr as stored in the THREAD.
  153. * this routine assumes that all the privileged stacks are in our
  154. * data space.
  155. */
  156. static inline int
  157. put_user_reg(struct task_struct *task, int offset, long data)
  158. {
  159. struct pt_regs newregs, *regs = task_pt_regs(task);
  160. int ret = -EINVAL;
  161. newregs = *regs;
  162. newregs.uregs[offset] = data;
  163. if (valid_user_regs(&newregs)) {
  164. regs->uregs[offset] = data;
  165. ret = 0;
  166. }
  167. return ret;
  168. }
  169. /*
  170. * Called by kernel/ptrace.c when detaching..
  171. */
  172. void ptrace_disable(struct task_struct *child)
  173. {
  174. /* Nothing to do. */
  175. }
  176. /*
  177. * Handle hitting a breakpoint.
  178. */
  179. void ptrace_break(struct task_struct *tsk, struct pt_regs *regs)
  180. {
  181. siginfo_t info;
  182. info.si_signo = SIGTRAP;
  183. info.si_errno = 0;
  184. info.si_code = TRAP_BRKPT;
  185. info.si_addr = (void __user *)instruction_pointer(regs);
  186. force_sig_info(SIGTRAP, &info, tsk);
  187. }
  188. static int break_trap(struct pt_regs *regs, unsigned int instr)
  189. {
  190. ptrace_break(current, regs);
  191. return 0;
  192. }
  193. static struct undef_hook arm_break_hook = {
  194. .instr_mask = 0x0fffffff,
  195. .instr_val = 0x07f001f0,
  196. .cpsr_mask = PSR_T_BIT,
  197. .cpsr_val = 0,
  198. .fn = break_trap,
  199. };
  200. static struct undef_hook thumb_break_hook = {
  201. .instr_mask = 0xffff,
  202. .instr_val = 0xde01,
  203. .cpsr_mask = PSR_T_BIT,
  204. .cpsr_val = PSR_T_BIT,
  205. .fn = break_trap,
  206. };
  207. static int thumb2_break_trap(struct pt_regs *regs, unsigned int instr)
  208. {
  209. unsigned int instr2;
  210. void __user *pc;
  211. /* Check the second half of the instruction. */
  212. pc = (void __user *)(instruction_pointer(regs) + 2);
  213. if (processor_mode(regs) == SVC_MODE) {
  214. instr2 = *(u16 *) pc;
  215. } else {
  216. get_user(instr2, (u16 __user *)pc);
  217. }
  218. if (instr2 == 0xa000) {
  219. ptrace_break(current, regs);
  220. return 0;
  221. } else {
  222. return 1;
  223. }
  224. }
  225. static struct undef_hook thumb2_break_hook = {
  226. .instr_mask = 0xffff,
  227. .instr_val = 0xf7f0,
  228. .cpsr_mask = PSR_T_BIT,
  229. .cpsr_val = PSR_T_BIT,
  230. .fn = thumb2_break_trap,
  231. };
  232. static int __init ptrace_break_init(void)
  233. {
  234. register_undef_hook(&arm_break_hook);
  235. register_undef_hook(&thumb_break_hook);
  236. register_undef_hook(&thumb2_break_hook);
  237. return 0;
  238. }
  239. core_initcall(ptrace_break_init);
  240. /*
  241. * Read the word at offset "off" into the "struct user". We
  242. * actually access the pt_regs stored on the kernel stack.
  243. */
  244. static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
  245. unsigned long __user *ret)
  246. {
  247. unsigned long tmp;
  248. if (off & 3 || off >= sizeof(struct user))
  249. return -EIO;
  250. tmp = 0;
  251. if (off == PT_TEXT_ADDR)
  252. tmp = tsk->mm->start_code;
  253. else if (off == PT_DATA_ADDR)
  254. tmp = tsk->mm->start_data;
  255. else if (off == PT_TEXT_END_ADDR)
  256. tmp = tsk->mm->end_code;
  257. else if (off < sizeof(struct pt_regs))
  258. tmp = get_user_reg(tsk, off >> 2);
  259. return put_user(tmp, ret);
  260. }
  261. /*
  262. * Write the word at offset "off" into "struct user". We
  263. * actually access the pt_regs stored on the kernel stack.
  264. */
  265. static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
  266. unsigned long val)
  267. {
  268. if (off & 3 || off >= sizeof(struct user))
  269. return -EIO;
  270. if (off >= sizeof(struct pt_regs))
  271. return 0;
  272. return put_user_reg(tsk, off >> 2, val);
  273. }
  274. /*
  275. * Get all user integer registers.
  276. */
  277. static int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
  278. {
  279. struct pt_regs *regs = task_pt_regs(tsk);
  280. return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
  281. }
  282. /*
  283. * Set all user integer registers.
  284. */
  285. static int ptrace_setregs(struct task_struct *tsk, void __user *uregs)
  286. {
  287. struct pt_regs newregs;
  288. int ret;
  289. ret = -EFAULT;
  290. if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
  291. struct pt_regs *regs = task_pt_regs(tsk);
  292. ret = -EINVAL;
  293. if (valid_user_regs(&newregs)) {
  294. *regs = newregs;
  295. ret = 0;
  296. }
  297. }
  298. return ret;
  299. }
  300. /*
  301. * Get the child FPU state.
  302. */
  303. static int ptrace_getfpregs(struct task_struct *tsk, void __user *ufp)
  304. {
  305. return copy_to_user(ufp, &task_thread_info(tsk)->fpstate,
  306. sizeof(struct user_fp)) ? -EFAULT : 0;
  307. }
  308. /*
  309. * Set the child FPU state.
  310. */
  311. static int ptrace_setfpregs(struct task_struct *tsk, void __user *ufp)
  312. {
  313. struct thread_info *thread = task_thread_info(tsk);
  314. thread->used_cp[1] = thread->used_cp[2] = 1;
  315. return copy_from_user(&thread->fpstate, ufp,
  316. sizeof(struct user_fp)) ? -EFAULT : 0;
  317. }
  318. #ifdef CONFIG_IWMMXT
  319. /*
  320. * Get the child iWMMXt state.
  321. */
  322. static int ptrace_getwmmxregs(struct task_struct *tsk, void __user *ufp)
  323. {
  324. struct thread_info *thread = task_thread_info(tsk);
  325. if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
  326. return -ENODATA;
  327. iwmmxt_task_disable(thread); /* force it to ram */
  328. return copy_to_user(ufp, &thread->fpstate.iwmmxt, IWMMXT_SIZE)
  329. ? -EFAULT : 0;
  330. }
  331. /*
  332. * Set the child iWMMXt state.
  333. */
  334. static int ptrace_setwmmxregs(struct task_struct *tsk, void __user *ufp)
  335. {
  336. struct thread_info *thread = task_thread_info(tsk);
  337. if (!test_ti_thread_flag(thread, TIF_USING_IWMMXT))
  338. return -EACCES;
  339. iwmmxt_task_release(thread); /* force a reload */
  340. return copy_from_user(&thread->fpstate.iwmmxt, ufp, IWMMXT_SIZE)
  341. ? -EFAULT : 0;
  342. }
  343. #endif
  344. #ifdef CONFIG_CRUNCH
  345. /*
  346. * Get the child Crunch state.
  347. */
  348. static int ptrace_getcrunchregs(struct task_struct *tsk, void __user *ufp)
  349. {
  350. struct thread_info *thread = task_thread_info(tsk);
  351. crunch_task_disable(thread); /* force it to ram */
  352. return copy_to_user(ufp, &thread->crunchstate, CRUNCH_SIZE)
  353. ? -EFAULT : 0;
  354. }
  355. /*
  356. * Set the child Crunch state.
  357. */
  358. static int ptrace_setcrunchregs(struct task_struct *tsk, void __user *ufp)
  359. {
  360. struct thread_info *thread = task_thread_info(tsk);
  361. crunch_task_release(thread); /* force a reload */
  362. return copy_from_user(&thread->crunchstate, ufp, CRUNCH_SIZE)
  363. ? -EFAULT : 0;
  364. }
  365. #endif
  366. #ifdef CONFIG_VFP
  367. /*
  368. * Get the child VFP state.
  369. */
  370. static int ptrace_getvfpregs(struct task_struct *tsk, void __user *data)
  371. {
  372. struct thread_info *thread = task_thread_info(tsk);
  373. union vfp_state *vfp = &thread->vfpstate;
  374. struct user_vfp __user *ufp = data;
  375. vfp_sync_hwstate(thread);
  376. /* copy the floating point registers */
  377. if (copy_to_user(&ufp->fpregs, &vfp->hard.fpregs,
  378. sizeof(vfp->hard.fpregs)))
  379. return -EFAULT;
  380. /* copy the status and control register */
  381. if (put_user(vfp->hard.fpscr, &ufp->fpscr))
  382. return -EFAULT;
  383. return 0;
  384. }
  385. /*
  386. * Set the child VFP state.
  387. */
  388. static int ptrace_setvfpregs(struct task_struct *tsk, void __user *data)
  389. {
  390. struct thread_info *thread = task_thread_info(tsk);
  391. union vfp_state *vfp = &thread->vfpstate;
  392. struct user_vfp __user *ufp = data;
  393. vfp_sync_hwstate(thread);
  394. /* copy the floating point registers */
  395. if (copy_from_user(&vfp->hard.fpregs, &ufp->fpregs,
  396. sizeof(vfp->hard.fpregs)))
  397. return -EFAULT;
  398. /* copy the status and control register */
  399. if (get_user(vfp->hard.fpscr, &ufp->fpscr))
  400. return -EFAULT;
  401. vfp_flush_hwstate(thread);
  402. return 0;
  403. }
  404. #endif
  405. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  406. /*
  407. * Convert a virtual register number into an index for a thread_info
  408. * breakpoint array. Breakpoints are identified using positive numbers
  409. * whilst watchpoints are negative. The registers are laid out as pairs
  410. * of (address, control), each pair mapping to a unique hw_breakpoint struct.
  411. * Register 0 is reserved for describing resource information.
  412. */
  413. static int ptrace_hbp_num_to_idx(long num)
  414. {
  415. if (num < 0)
  416. num = (ARM_MAX_BRP << 1) - num;
  417. return (num - 1) >> 1;
  418. }
  419. /*
  420. * Returns the virtual register number for the address of the
  421. * breakpoint at index idx.
  422. */
  423. static long ptrace_hbp_idx_to_num(int idx)
  424. {
  425. long mid = ARM_MAX_BRP << 1;
  426. long num = (idx << 1) + 1;
  427. return num > mid ? mid - num : num;
  428. }
  429. /*
  430. * Handle hitting a HW-breakpoint.
  431. */
  432. static void ptrace_hbptriggered(struct perf_event *bp, int unused,
  433. struct perf_sample_data *data,
  434. struct pt_regs *regs)
  435. {
  436. struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
  437. long num;
  438. int i;
  439. siginfo_t info;
  440. for (i = 0; i < ARM_MAX_HBP_SLOTS; ++i)
  441. if (current->thread.debug.hbp[i] == bp)
  442. break;
  443. num = (i == ARM_MAX_HBP_SLOTS) ? 0 : ptrace_hbp_idx_to_num(i);
  444. info.si_signo = SIGTRAP;
  445. info.si_errno = (int)num;
  446. info.si_code = TRAP_HWBKPT;
  447. info.si_addr = (void __user *)(bkpt->trigger);
  448. force_sig_info(SIGTRAP, &info, current);
  449. }
  450. /*
  451. * Set ptrace breakpoint pointers to zero for this task.
  452. * This is required in order to prevent child processes from unregistering
  453. * breakpoints held by their parent.
  454. */
  455. void clear_ptrace_hw_breakpoint(struct task_struct *tsk)
  456. {
  457. memset(tsk->thread.debug.hbp, 0, sizeof(tsk->thread.debug.hbp));
  458. }
  459. /*
  460. * Unregister breakpoints from this task and reset the pointers in
  461. * the thread_struct.
  462. */
  463. void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
  464. {
  465. int i;
  466. struct thread_struct *t = &tsk->thread;
  467. for (i = 0; i < ARM_MAX_HBP_SLOTS; i++) {
  468. if (t->debug.hbp[i]) {
  469. unregister_hw_breakpoint(t->debug.hbp[i]);
  470. t->debug.hbp[i] = NULL;
  471. }
  472. }
  473. }
  474. static u32 ptrace_get_hbp_resource_info(void)
  475. {
  476. u8 num_brps, num_wrps, debug_arch, wp_len;
  477. u32 reg = 0;
  478. num_brps = hw_breakpoint_slots(TYPE_INST);
  479. num_wrps = hw_breakpoint_slots(TYPE_DATA);
  480. debug_arch = arch_get_debug_arch();
  481. wp_len = arch_get_max_wp_len();
  482. reg |= debug_arch;
  483. reg <<= 8;
  484. reg |= wp_len;
  485. reg <<= 8;
  486. reg |= num_wrps;
  487. reg <<= 8;
  488. reg |= num_brps;
  489. return reg;
  490. }
  491. static struct perf_event *ptrace_hbp_create(struct task_struct *tsk, int type)
  492. {
  493. struct perf_event_attr attr;
  494. ptrace_breakpoint_init(&attr);
  495. /* Initialise fields to sane defaults. */
  496. attr.bp_addr = 0;
  497. attr.bp_len = HW_BREAKPOINT_LEN_4;
  498. attr.bp_type = type;
  499. attr.disabled = 1;
  500. return register_user_hw_breakpoint(&attr, ptrace_hbptriggered, tsk);
  501. }
  502. static int ptrace_gethbpregs(struct task_struct *tsk, long num,
  503. unsigned long __user *data)
  504. {
  505. u32 reg;
  506. int idx, ret = 0;
  507. struct perf_event *bp;
  508. struct arch_hw_breakpoint_ctrl arch_ctrl;
  509. if (num == 0) {
  510. reg = ptrace_get_hbp_resource_info();
  511. } else {
  512. idx = ptrace_hbp_num_to_idx(num);
  513. if (idx < 0 || idx >= ARM_MAX_HBP_SLOTS) {
  514. ret = -EINVAL;
  515. goto out;
  516. }
  517. bp = tsk->thread.debug.hbp[idx];
  518. if (!bp) {
  519. reg = 0;
  520. goto put;
  521. }
  522. arch_ctrl = counter_arch_bp(bp)->ctrl;
  523. /*
  524. * Fix up the len because we may have adjusted it
  525. * to compensate for an unaligned address.
  526. */
  527. while (!(arch_ctrl.len & 0x1))
  528. arch_ctrl.len >>= 1;
  529. if (num & 0x1)
  530. reg = bp->attr.bp_addr;
  531. else
  532. reg = encode_ctrl_reg(arch_ctrl);
  533. }
  534. put:
  535. if (put_user(reg, data))
  536. ret = -EFAULT;
  537. out:
  538. return ret;
  539. }
  540. static int ptrace_sethbpregs(struct task_struct *tsk, long num,
  541. unsigned long __user *data)
  542. {
  543. int idx, gen_len, gen_type, implied_type, ret = 0;
  544. u32 user_val;
  545. struct perf_event *bp;
  546. struct arch_hw_breakpoint_ctrl ctrl;
  547. struct perf_event_attr attr;
  548. if (num == 0)
  549. goto out;
  550. else if (num < 0)
  551. implied_type = HW_BREAKPOINT_RW;
  552. else
  553. implied_type = HW_BREAKPOINT_X;
  554. idx = ptrace_hbp_num_to_idx(num);
  555. if (idx < 0 || idx >= ARM_MAX_HBP_SLOTS) {
  556. ret = -EINVAL;
  557. goto out;
  558. }
  559. if (get_user(user_val, data)) {
  560. ret = -EFAULT;
  561. goto out;
  562. }
  563. bp = tsk->thread.debug.hbp[idx];
  564. if (!bp) {
  565. bp = ptrace_hbp_create(tsk, implied_type);
  566. if (IS_ERR(bp)) {
  567. ret = PTR_ERR(bp);
  568. goto out;
  569. }
  570. tsk->thread.debug.hbp[idx] = bp;
  571. }
  572. attr = bp->attr;
  573. if (num & 0x1) {
  574. /* Address */
  575. attr.bp_addr = user_val;
  576. } else {
  577. /* Control */
  578. decode_ctrl_reg(user_val, &ctrl);
  579. ret = arch_bp_generic_fields(ctrl, &gen_len, &gen_type);
  580. if (ret)
  581. goto out;
  582. if ((gen_type & implied_type) != gen_type) {
  583. ret = -EINVAL;
  584. goto out;
  585. }
  586. attr.bp_len = gen_len;
  587. attr.bp_type = gen_type;
  588. attr.disabled = !ctrl.enabled;
  589. }
  590. ret = modify_user_hw_breakpoint(bp, &attr);
  591. out:
  592. return ret;
  593. }
  594. #endif
  595. long arch_ptrace(struct task_struct *child, long request,
  596. unsigned long addr, unsigned long data)
  597. {
  598. int ret;
  599. unsigned long __user *datap = (unsigned long __user *) data;
  600. switch (request) {
  601. case PTRACE_PEEKUSR:
  602. ret = ptrace_read_user(child, addr, datap);
  603. break;
  604. case PTRACE_POKEUSR:
  605. ret = ptrace_write_user(child, addr, data);
  606. break;
  607. case PTRACE_GETREGS:
  608. ret = ptrace_getregs(child, datap);
  609. break;
  610. case PTRACE_SETREGS:
  611. ret = ptrace_setregs(child, datap);
  612. break;
  613. case PTRACE_GETFPREGS:
  614. ret = ptrace_getfpregs(child, datap);
  615. break;
  616. case PTRACE_SETFPREGS:
  617. ret = ptrace_setfpregs(child, datap);
  618. break;
  619. #ifdef CONFIG_IWMMXT
  620. case PTRACE_GETWMMXREGS:
  621. ret = ptrace_getwmmxregs(child, datap);
  622. break;
  623. case PTRACE_SETWMMXREGS:
  624. ret = ptrace_setwmmxregs(child, datap);
  625. break;
  626. #endif
  627. case PTRACE_GET_THREAD_AREA:
  628. ret = put_user(task_thread_info(child)->tp_value,
  629. datap);
  630. break;
  631. case PTRACE_SET_SYSCALL:
  632. task_thread_info(child)->syscall = data;
  633. ret = 0;
  634. break;
  635. #ifdef CONFIG_CRUNCH
  636. case PTRACE_GETCRUNCHREGS:
  637. ret = ptrace_getcrunchregs(child, datap);
  638. break;
  639. case PTRACE_SETCRUNCHREGS:
  640. ret = ptrace_setcrunchregs(child, datap);
  641. break;
  642. #endif
  643. #ifdef CONFIG_VFP
  644. case PTRACE_GETVFPREGS:
  645. ret = ptrace_getvfpregs(child, datap);
  646. break;
  647. case PTRACE_SETVFPREGS:
  648. ret = ptrace_setvfpregs(child, datap);
  649. break;
  650. #endif
  651. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  652. case PTRACE_GETHBPREGS:
  653. ret = ptrace_gethbpregs(child, addr,
  654. (unsigned long __user *)data);
  655. break;
  656. case PTRACE_SETHBPREGS:
  657. ret = ptrace_sethbpregs(child, addr,
  658. (unsigned long __user *)data);
  659. break;
  660. #endif
  661. default:
  662. ret = ptrace_request(child, request, addr, data);
  663. break;
  664. }
  665. return ret;
  666. }
  667. asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
  668. {
  669. unsigned long ip;
  670. if (!test_thread_flag(TIF_SYSCALL_TRACE))
  671. return scno;
  672. if (!(current->ptrace & PT_PTRACED))
  673. return scno;
  674. /*
  675. * Save IP. IP is used to denote syscall entry/exit:
  676. * IP = 0 -> entry, = 1 -> exit
  677. */
  678. ip = regs->ARM_ip;
  679. regs->ARM_ip = why;
  680. current_thread_info()->syscall = scno;
  681. /* the 0x80 provides a way for the tracing parent to distinguish
  682. between a syscall stop and SIGTRAP delivery */
  683. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  684. ? 0x80 : 0));
  685. /*
  686. * this isn't the same as continuing with a signal, but it will do
  687. * for normal use. strace only continues with a signal if the
  688. * stopping signal is not SIGTRAP. -brl
  689. */
  690. if (current->exit_code) {
  691. send_sig(current->exit_code, current, 1);
  692. current->exit_code = 0;
  693. }
  694. regs->ARM_ip = ip;
  695. return current_thread_info()->syscall;
  696. }