ptrace.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 <linux/sched/task_stack.h>
  18. #include <asm/cacheflush.h>
  19. #define PT_REG_SIZE (sizeof(struct pt_regs))
  20. /*
  21. * Called by kernel/ptrace.c when detaching.
  22. */
  23. void ptrace_disable(struct task_struct *child)
  24. {
  25. /* nothing to do */
  26. }
  27. /*
  28. * Get a register number from live pt_regs for the specified task.
  29. */
  30. static inline long get_reg(struct task_struct *task, int regno)
  31. {
  32. long *addr = (long *)task_pt_regs(task);
  33. if (regno == PT_TSR || regno == PT_CSR)
  34. return 0;
  35. return addr[regno];
  36. }
  37. /*
  38. * Write contents of register REGNO in task TASK.
  39. */
  40. static inline int put_reg(struct task_struct *task,
  41. int regno,
  42. unsigned long data)
  43. {
  44. unsigned long *addr = (unsigned long *)task_pt_regs(task);
  45. if (regno != PT_TSR && regno != PT_CSR)
  46. addr[regno] = data;
  47. return 0;
  48. }
  49. /* regset get/set implementations */
  50. static int gpr_get(struct task_struct *target,
  51. const struct user_regset *regset,
  52. unsigned int pos, unsigned int count,
  53. void *kbuf, void __user *ubuf)
  54. {
  55. struct pt_regs *regs = task_pt_regs(target);
  56. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  57. regs,
  58. 0, sizeof(*regs));
  59. }
  60. enum c6x_regset {
  61. REGSET_GPR,
  62. };
  63. static const struct user_regset c6x_regsets[] = {
  64. [REGSET_GPR] = {
  65. .core_note_type = NT_PRSTATUS,
  66. .n = ELF_NGREG,
  67. .size = sizeof(u32),
  68. .align = sizeof(u32),
  69. .get = gpr_get,
  70. },
  71. };
  72. static const struct user_regset_view user_c6x_native_view = {
  73. .name = "tic6x",
  74. .e_machine = EM_TI_C6000,
  75. .regsets = c6x_regsets,
  76. .n = ARRAY_SIZE(c6x_regsets),
  77. };
  78. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  79. {
  80. return &user_c6x_native_view;
  81. }
  82. /*
  83. * Perform ptrace request
  84. */
  85. long arch_ptrace(struct task_struct *child, long request,
  86. unsigned long addr, unsigned long data)
  87. {
  88. int ret = 0;
  89. switch (request) {
  90. /*
  91. * write the word at location addr.
  92. */
  93. case PTRACE_POKETEXT:
  94. ret = generic_ptrace_pokedata(child, addr, data);
  95. if (ret == 0 && request == PTRACE_POKETEXT)
  96. flush_icache_range(addr, addr + 4);
  97. break;
  98. default:
  99. ret = ptrace_request(child, request, addr, data);
  100. break;
  101. }
  102. return ret;
  103. }
  104. /*
  105. * handle tracing of system call entry
  106. * - return the revised system call number or ULONG_MAX to cause ENOSYS
  107. */
  108. asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
  109. {
  110. if (tracehook_report_syscall_entry(regs))
  111. /* tracing decided this syscall should not happen, so
  112. * We'll return a bogus call number to get an ENOSYS
  113. * error, but leave the original number in
  114. * regs->orig_a4
  115. */
  116. return ULONG_MAX;
  117. return regs->b0;
  118. }
  119. /*
  120. * handle tracing of system call exit
  121. */
  122. asmlinkage void syscall_trace_exit(struct pt_regs *regs)
  123. {
  124. tracehook_report_syscall_exit(regs, 0);
  125. }