ptrace.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Port on Texas Instruments TMS320C6x architecture
  4. *
  5. * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
  6. * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
  7. *
  8. * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
  9. */
  10. #include <linux/ptrace.h>
  11. #include <linux/tracehook.h>
  12. #include <linux/regset.h>
  13. #include <linux/elf.h>
  14. #include <linux/sched/task_stack.h>
  15. #include <asm/cacheflush.h>
  16. #define PT_REG_SIZE (sizeof(struct pt_regs))
  17. /*
  18. * Called by kernel/ptrace.c when detaching.
  19. */
  20. void ptrace_disable(struct task_struct *child)
  21. {
  22. /* nothing to do */
  23. }
  24. /*
  25. * Get a register number from live pt_regs for the specified task.
  26. */
  27. static inline long get_reg(struct task_struct *task, int regno)
  28. {
  29. long *addr = (long *)task_pt_regs(task);
  30. if (regno == PT_TSR || regno == PT_CSR)
  31. return 0;
  32. return addr[regno];
  33. }
  34. /*
  35. * Write contents of register REGNO in task TASK.
  36. */
  37. static inline int put_reg(struct task_struct *task,
  38. int regno,
  39. unsigned long data)
  40. {
  41. unsigned long *addr = (unsigned long *)task_pt_regs(task);
  42. if (regno != PT_TSR && regno != PT_CSR)
  43. addr[regno] = data;
  44. return 0;
  45. }
  46. /* regset get/set implementations */
  47. static int gpr_get(struct task_struct *target,
  48. const struct user_regset *regset,
  49. struct membuf to)
  50. {
  51. return membuf_write(&to, task_pt_regs(target), sizeof(struct pt_regs));
  52. }
  53. enum c6x_regset {
  54. REGSET_GPR,
  55. };
  56. static const struct user_regset c6x_regsets[] = {
  57. [REGSET_GPR] = {
  58. .core_note_type = NT_PRSTATUS,
  59. .n = ELF_NGREG,
  60. .size = sizeof(u32),
  61. .align = sizeof(u32),
  62. .regset_get = gpr_get,
  63. },
  64. };
  65. static const struct user_regset_view user_c6x_native_view = {
  66. .name = "tic6x",
  67. .e_machine = EM_TI_C6000,
  68. .regsets = c6x_regsets,
  69. .n = ARRAY_SIZE(c6x_regsets),
  70. };
  71. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  72. {
  73. return &user_c6x_native_view;
  74. }
  75. /*
  76. * Perform ptrace request
  77. */
  78. long arch_ptrace(struct task_struct *child, long request,
  79. unsigned long addr, unsigned long data)
  80. {
  81. int ret = 0;
  82. switch (request) {
  83. /*
  84. * write the word at location addr.
  85. */
  86. case PTRACE_POKETEXT:
  87. ret = generic_ptrace_pokedata(child, addr, data);
  88. if (ret == 0 && request == PTRACE_POKETEXT)
  89. flush_icache_range(addr, addr + 4);
  90. break;
  91. default:
  92. ret = ptrace_request(child, request, addr, data);
  93. break;
  94. }
  95. return ret;
  96. }
  97. /*
  98. * handle tracing of system call entry
  99. * - return the revised system call number or ULONG_MAX to cause ENOSYS
  100. */
  101. asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
  102. {
  103. if (tracehook_report_syscall_entry(regs))
  104. /* tracing decided this syscall should not happen, so
  105. * We'll return a bogus call number to get an ENOSYS
  106. * error, but leave the original number in
  107. * regs->orig_a4
  108. */
  109. return ULONG_MAX;
  110. return regs->b0;
  111. }
  112. /*
  113. * handle tracing of system call exit
  114. */
  115. asmlinkage void syscall_trace_exit(struct pt_regs *regs)
  116. {
  117. tracehook_report_syscall_exit(regs, 0);
  118. }