ptrace.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/ptrace.h>
  9. #include <linux/tracehook.h>
  10. #include <linux/regset.h>
  11. #include <linux/unistd.h>
  12. #include <linux/elf.h>
  13. static struct callee_regs *task_callee_regs(struct task_struct *tsk)
  14. {
  15. struct callee_regs *tmp = (struct callee_regs *)tsk->thread.callee_reg;
  16. return tmp;
  17. }
  18. static int genregs_get(struct task_struct *target,
  19. const struct user_regset *regset,
  20. unsigned int pos, unsigned int count,
  21. void *kbuf, void __user *ubuf)
  22. {
  23. const struct pt_regs *ptregs = task_pt_regs(target);
  24. const struct callee_regs *cregs = task_callee_regs(target);
  25. int ret = 0;
  26. unsigned int stop_pc_val;
  27. #define REG_O_CHUNK(START, END, PTR) \
  28. if (!ret) \
  29. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \
  30. offsetof(struct user_regs_struct, START), \
  31. offsetof(struct user_regs_struct, END));
  32. #define REG_O_ONE(LOC, PTR) \
  33. if (!ret) \
  34. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \
  35. offsetof(struct user_regs_struct, LOC), \
  36. offsetof(struct user_regs_struct, LOC) + 4);
  37. REG_O_CHUNK(scratch, callee, ptregs);
  38. REG_O_CHUNK(callee, efa, cregs);
  39. REG_O_CHUNK(efa, stop_pc, &target->thread.fault_address);
  40. if (!ret) {
  41. if (in_brkpt_trap(ptregs)) {
  42. stop_pc_val = target->thread.fault_address;
  43. pr_debug("\t\tstop_pc (brk-pt)\n");
  44. } else {
  45. stop_pc_val = ptregs->ret;
  46. pr_debug("\t\tstop_pc (others)\n");
  47. }
  48. REG_O_ONE(stop_pc, &stop_pc_val);
  49. }
  50. return ret;
  51. }
  52. static int genregs_set(struct task_struct *target,
  53. const struct user_regset *regset,
  54. unsigned int pos, unsigned int count,
  55. const void *kbuf, const void __user *ubuf)
  56. {
  57. const struct pt_regs *ptregs = task_pt_regs(target);
  58. const struct callee_regs *cregs = task_callee_regs(target);
  59. int ret = 0;
  60. #define REG_IN_CHUNK(FIRST, NEXT, PTR) \
  61. if (!ret) \
  62. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
  63. (void *)(PTR), \
  64. offsetof(struct user_regs_struct, FIRST), \
  65. offsetof(struct user_regs_struct, NEXT));
  66. #define REG_IN_ONE(LOC, PTR) \
  67. if (!ret) \
  68. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
  69. (void *)(PTR), \
  70. offsetof(struct user_regs_struct, LOC), \
  71. offsetof(struct user_regs_struct, LOC) + 4);
  72. #define REG_IGNORE_ONE(LOC) \
  73. if (!ret) \
  74. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, \
  75. offsetof(struct user_regs_struct, LOC), \
  76. offsetof(struct user_regs_struct, LOC) + 4);
  77. /* TBD: disallow updates to STATUS32, orig_r8 etc*/
  78. REG_IN_CHUNK(scratch, callee, ptregs); /* pt_regs[bta..orig_r8] */
  79. REG_IN_CHUNK(callee, efa, cregs); /* callee_regs[r25..r13] */
  80. REG_IGNORE_ONE(efa); /* efa update invalid */
  81. REG_IN_ONE(stop_pc, &ptregs->ret); /* stop_pc: PC update */
  82. return ret;
  83. }
  84. enum arc_getset {
  85. REGSET_GENERAL,
  86. };
  87. static const struct user_regset arc_regsets[] = {
  88. [REGSET_GENERAL] = {
  89. .core_note_type = NT_PRSTATUS,
  90. .n = ELF_NGREG,
  91. .size = sizeof(unsigned long),
  92. .align = sizeof(unsigned long),
  93. .get = genregs_get,
  94. .set = genregs_set,
  95. }
  96. };
  97. static const struct user_regset_view user_arc_view = {
  98. .name = UTS_MACHINE,
  99. .e_machine = EM_ARCOMPACT,
  100. .regsets = arc_regsets,
  101. .n = ARRAY_SIZE(arc_regsets)
  102. };
  103. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  104. {
  105. return &user_arc_view;
  106. }
  107. void ptrace_disable(struct task_struct *child)
  108. {
  109. }
  110. long arch_ptrace(struct task_struct *child, long request,
  111. unsigned long addr, unsigned long data)
  112. {
  113. int ret = -EIO;
  114. pr_debug("REQ=%ld: ADDR =0x%lx, DATA=0x%lx)\n", request, addr, data);
  115. switch (request) {
  116. default:
  117. ret = ptrace_request(child, request, addr, data);
  118. break;
  119. }
  120. return ret;
  121. }
  122. asmlinkage int syscall_trace_entry(struct pt_regs *regs)
  123. {
  124. if (tracehook_report_syscall_entry(regs))
  125. return ULONG_MAX;
  126. return regs->r8;
  127. }
  128. asmlinkage void syscall_trace_exit(struct pt_regs *regs)
  129. {
  130. tracehook_report_syscall_exit(regs, 0);
  131. }