ptrace.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * linux/arch/h8300/kernel/ptrace.c
  3. *
  4. * Yoshinori Sato <ysato@users.sourceforge.jp>
  5. *
  6. * Based on:
  7. * linux/arch/m68k/kernel/ptrace.c
  8. *
  9. * Copyright (C) 1994 by Hamish Macdonald
  10. * Taken from linux/kernel/ptrace.c and modified for M680x0.
  11. * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
  12. *
  13. * This file is subject to the terms and conditions of the GNU General
  14. * Public License. See the file COPYING in the main directory of
  15. * this archive for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/mm.h>
  20. #include <linux/smp.h>
  21. #include <linux/errno.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/user.h>
  24. #include <linux/signal.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/page.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/system.h>
  29. #include <asm/processor.h>
  30. #include <asm/signal.h>
  31. /* cpu depend functions */
  32. extern long h8300_get_reg(struct task_struct *task, int regno);
  33. extern int h8300_put_reg(struct task_struct *task, int regno, unsigned long data);
  34. void user_disable_single_step(struct task_struct *child)
  35. {
  36. }
  37. /*
  38. * does not yet catch signals sent when the child dies.
  39. * in exit.c or in signal.c.
  40. */
  41. void ptrace_disable(struct task_struct *child)
  42. {
  43. user_disable_single_step(child);
  44. }
  45. long arch_ptrace(struct task_struct *child, long request,
  46. unsigned long addr, unsigned long data)
  47. {
  48. int ret;
  49. int regno = addr >> 2;
  50. unsigned long __user *datap = (unsigned long __user *) data;
  51. switch (request) {
  52. /* read the word at location addr in the USER area. */
  53. case PTRACE_PEEKUSR: {
  54. unsigned long tmp = 0;
  55. if ((addr & 3) || addr >= sizeof(struct user)) {
  56. ret = -EIO;
  57. break ;
  58. }
  59. ret = 0; /* Default return condition */
  60. if (regno < H8300_REGS_NO)
  61. tmp = h8300_get_reg(child, regno);
  62. else {
  63. switch (regno) {
  64. case 49:
  65. tmp = child->mm->start_code;
  66. break ;
  67. case 50:
  68. tmp = child->mm->start_data;
  69. break ;
  70. case 51:
  71. tmp = child->mm->end_code;
  72. break ;
  73. case 52:
  74. tmp = child->mm->end_data;
  75. break ;
  76. default:
  77. ret = -EIO;
  78. }
  79. }
  80. if (!ret)
  81. ret = put_user(tmp, datap);
  82. break ;
  83. }
  84. /* when I and D space are separate, this will have to be fixed. */
  85. case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
  86. if ((addr & 3) || addr >= sizeof(struct user)) {
  87. ret = -EIO;
  88. break ;
  89. }
  90. if (regno == PT_ORIG_ER0) {
  91. ret = -EIO;
  92. break ;
  93. }
  94. if (regno < H8300_REGS_NO) {
  95. ret = h8300_put_reg(child, regno, data);
  96. break ;
  97. }
  98. ret = -EIO;
  99. break ;
  100. case PTRACE_GETREGS: { /* Get all gp regs from the child. */
  101. int i;
  102. unsigned long tmp;
  103. for (i = 0; i < H8300_REGS_NO; i++) {
  104. tmp = h8300_get_reg(child, i);
  105. if (put_user(tmp, datap)) {
  106. ret = -EFAULT;
  107. break;
  108. }
  109. datap++;
  110. }
  111. ret = 0;
  112. break;
  113. }
  114. case PTRACE_SETREGS: { /* Set all gp regs in the child. */
  115. int i;
  116. unsigned long tmp;
  117. for (i = 0; i < H8300_REGS_NO; i++) {
  118. if (get_user(tmp, datap)) {
  119. ret = -EFAULT;
  120. break;
  121. }
  122. h8300_put_reg(child, i, tmp);
  123. datap++;
  124. }
  125. ret = 0;
  126. break;
  127. }
  128. default:
  129. ret = ptrace_request(child, request, addr, data);
  130. break;
  131. }
  132. return ret;
  133. }
  134. asmlinkage void do_syscall_trace(void)
  135. {
  136. if (!test_thread_flag(TIF_SYSCALL_TRACE))
  137. return;
  138. if (!(current->ptrace & PT_PTRACED))
  139. return;
  140. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  141. ? 0x80 : 0));
  142. /*
  143. * this isn't the same as continuing with a signal, but it will do
  144. * for normal use. strace only continues with a signal if the
  145. * stopping signal is not SIGTRAP. -brl
  146. */
  147. if (current->exit_code) {
  148. send_sig(current->exit_code, current, 1);
  149. current->exit_code = 0;
  150. }
  151. }