ptrace.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Port on Texas Instruments TMS320C6x architecture
  3. *
  4. * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
  5. * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
  6. *
  7. * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/ptrace.h>
  14. #include <linux/tracehook.h>
  15. #include <linux/regset.h>
  16. #include <linux/elf.h>
  17. #include <asm/cacheflush.h>
  18. #define PT_REG_SIZE (sizeof(struct pt_regs))
  19. /*
  20. * Called by kernel/ptrace.c when detaching.
  21. */
  22. void ptrace_disable(struct task_struct *child)
  23. {
  24. /* nothing to do */
  25. }
  26. /*
  27. * Get a register number from live pt_regs for the specified task.
  28. */
  29. static inline long get_reg(struct task_struct *task, int regno)
  30. {
  31. long *addr = (long *)task_pt_regs(task);
  32. if (regno == PT_TSR || regno == PT_CSR)
  33. return 0;
  34. return addr[regno];
  35. }
  36. /*
  37. * Write contents of register REGNO in task TASK.
  38. */
  39. static inline int put_reg(struct task_struct *task,
  40. int regno,
  41. unsigned long data)
  42. {
  43. unsigned long *addr = (unsigned long *)task_pt_regs(task);
  44. if (regno != PT_TSR && regno != PT_CSR)
  45. addr[regno] = data;
  46. return 0;
  47. }
  48. /* regset get/set implementations */
  49. static int gpr_get(struct task_struct *target,
  50. const struct user_regset *regset,
  51. unsigned int pos, unsigned int count,
  52. void *kbuf, void __user *ubuf)
  53. {
  54. struct pt_regs *regs = task_pt_regs(target);
  55. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  56. regs,
  57. 0, sizeof(*regs));
  58. }
  59. static int gpr_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. int ret;
  65. struct pt_regs *regs = task_pt_regs(target);
  66. /* Don't copyin TSR or CSR */
  67. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  68. &regs,
  69. 0, PT_TSR * sizeof(long));
  70. if (ret)
  71. return ret;
  72. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  73. PT_TSR * sizeof(long),
  74. (PT_TSR + 1) * sizeof(long));
  75. if (ret)
  76. return ret;
  77. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  78. &regs,
  79. (PT_TSR + 1) * sizeof(long),
  80. PT_CSR * sizeof(long));
  81. if (ret)
  82. return ret;
  83. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  84. PT_CSR * sizeof(long),
  85. (PT_CSR + 1) * sizeof(long));
  86. if (ret)
  87. return ret;
  88. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  89. &regs,
  90. (PT_CSR + 1) * sizeof(long), -1);
  91. return ret;
  92. }
  93. enum c6x_regset {
  94. REGSET_GPR,
  95. };
  96. static const struct user_regset c6x_regsets[] = {
  97. [REGSET_GPR] = {
  98. .core_note_type = NT_PRSTATUS,
  99. .n = ELF_NGREG,
  100. .size = sizeof(u32),
  101. .align = sizeof(u32),
  102. .get = gpr_get,
  103. .set = gpr_set
  104. },
  105. };
  106. static const struct user_regset_view user_c6x_native_view = {
  107. .name = "tic6x",
  108. .e_machine = EM_TI_C6000,
  109. .regsets = c6x_regsets,
  110. .n = ARRAY_SIZE(c6x_regsets),
  111. };
  112. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  113. {
  114. return &user_c6x_native_view;
  115. }
  116. /*
  117. * Perform ptrace request
  118. */
  119. long arch_ptrace(struct task_struct *child, long request,
  120. unsigned long addr, unsigned long data)
  121. {
  122. int ret = 0;
  123. switch (request) {
  124. /*
  125. * write the word at location addr.
  126. */
  127. case PTRACE_POKETEXT:
  128. ret = generic_ptrace_pokedata(child, addr, data);
  129. if (ret == 0 && request == PTRACE_POKETEXT)
  130. flush_icache_range(addr, addr + 4);
  131. break;
  132. default:
  133. ret = ptrace_request(child, request, addr, data);
  134. break;
  135. }
  136. return ret;
  137. }
  138. /*
  139. * handle tracing of system call entry
  140. * - return the revised system call number or ULONG_MAX to cause ENOSYS
  141. */
  142. asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
  143. {
  144. if (tracehook_report_syscall_entry(regs))
  145. /* tracing decided this syscall should not happen, so
  146. * We'll return a bogus call number to get an ENOSYS
  147. * error, but leave the original number in
  148. * regs->orig_a4
  149. */
  150. return ULONG_MAX;
  151. return regs->b0;
  152. }
  153. /*
  154. * handle tracing of system call exit
  155. */
  156. asmlinkage void syscall_trace_exit(struct pt_regs *regs)
  157. {
  158. tracehook_report_syscall_exit(regs, 0);
  159. }