ptrace.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #define REG_O_ZERO(LOC) \
  38. if (!ret) \
  39. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, \
  40. offsetof(struct user_regs_struct, LOC), \
  41. offsetof(struct user_regs_struct, LOC) + 4);
  42. REG_O_ZERO(pad);
  43. REG_O_CHUNK(scratch, callee, ptregs);
  44. REG_O_ZERO(pad2);
  45. REG_O_CHUNK(callee, efa, cregs);
  46. REG_O_CHUNK(efa, stop_pc, &target->thread.fault_address);
  47. if (!ret) {
  48. if (in_brkpt_trap(ptregs)) {
  49. stop_pc_val = target->thread.fault_address;
  50. pr_debug("\t\tstop_pc (brk-pt)\n");
  51. } else {
  52. stop_pc_val = ptregs->ret;
  53. pr_debug("\t\tstop_pc (others)\n");
  54. }
  55. REG_O_ONE(stop_pc, &stop_pc_val);
  56. }
  57. return ret;
  58. }
  59. static int genregs_set(struct task_struct *target,
  60. const struct user_regset *regset,
  61. unsigned int pos, unsigned int count,
  62. const void *kbuf, const void __user *ubuf)
  63. {
  64. const struct pt_regs *ptregs = task_pt_regs(target);
  65. const struct callee_regs *cregs = task_callee_regs(target);
  66. int ret = 0;
  67. #define REG_IN_CHUNK(FIRST, NEXT, PTR) \
  68. if (!ret) \
  69. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
  70. (void *)(PTR), \
  71. offsetof(struct user_regs_struct, FIRST), \
  72. offsetof(struct user_regs_struct, NEXT));
  73. #define REG_IN_ONE(LOC, PTR) \
  74. if (!ret) \
  75. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
  76. (void *)(PTR), \
  77. offsetof(struct user_regs_struct, LOC), \
  78. offsetof(struct user_regs_struct, LOC) + 4);
  79. #define REG_IGNORE_ONE(LOC) \
  80. if (!ret) \
  81. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, \
  82. offsetof(struct user_regs_struct, LOC), \
  83. offsetof(struct user_regs_struct, LOC) + 4);
  84. REG_IGNORE_ONE(pad);
  85. /* TBD: disallow updates to STATUS32 etc*/
  86. REG_IN_CHUNK(scratch, pad2, ptregs); /* pt_regs[bta..sp] */
  87. REG_IGNORE_ONE(pad2);
  88. REG_IN_CHUNK(callee, efa, cregs); /* callee_regs[r25..r13] */
  89. REG_IGNORE_ONE(efa); /* efa update invalid */
  90. REG_IN_ONE(stop_pc, &ptregs->ret); /* stop_pc: PC update */
  91. return ret;
  92. }
  93. enum arc_getset {
  94. REGSET_GENERAL,
  95. };
  96. static const struct user_regset arc_regsets[] = {
  97. [REGSET_GENERAL] = {
  98. .core_note_type = NT_PRSTATUS,
  99. .n = ELF_NGREG,
  100. .size = sizeof(unsigned long),
  101. .align = sizeof(unsigned long),
  102. .get = genregs_get,
  103. .set = genregs_set,
  104. }
  105. };
  106. static const struct user_regset_view user_arc_view = {
  107. .name = UTS_MACHINE,
  108. .e_machine = EM_ARCOMPACT,
  109. .regsets = arc_regsets,
  110. .n = ARRAY_SIZE(arc_regsets)
  111. };
  112. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  113. {
  114. return &user_arc_view;
  115. }
  116. void ptrace_disable(struct task_struct *child)
  117. {
  118. }
  119. long arch_ptrace(struct task_struct *child, long request,
  120. unsigned long addr, unsigned long data)
  121. {
  122. int ret = -EIO;
  123. pr_debug("REQ=%ld: ADDR =0x%lx, DATA=0x%lx)\n", request, addr, data);
  124. switch (request) {
  125. default:
  126. ret = ptrace_request(child, request, addr, data);
  127. break;
  128. }
  129. return ret;
  130. }
  131. asmlinkage int syscall_trace_entry(struct pt_regs *regs)
  132. {
  133. if (tracehook_report_syscall_entry(regs))
  134. return ULONG_MAX;
  135. return regs->r8;
  136. }
  137. asmlinkage void syscall_trace_exit(struct pt_regs *regs)
  138. {
  139. tracehook_report_syscall_exit(regs, 0);
  140. }