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/processor.h>
  29. #include <asm/signal.h>
  30. /* cpu depend functions */
  31. extern long h8300_get_reg(struct task_struct *task, int regno);
  32. extern int h8300_put_reg(struct task_struct *task, int regno, unsigned long data);
  33. void user_disable_single_step(struct task_struct *child)
  34. {
  35. }
  36. /*
  37. * does not yet catch signals sent when the child dies.
  38. * in exit.c or in signal.c.
  39. */
  40. void ptrace_disable(struct task_struct *child)
  41. {
  42. user_disable_single_step(child);
  43. }
  44. long arch_ptrace(struct task_struct *child, long request,
  45. unsigned long addr, unsigned long data)
  46. {
  47. int ret;
  48. int regno = addr >> 2;
  49. unsigned long __user *datap = (unsigned long __user *) data;
  50. switch (request) {
  51. /* read the word at location addr in the USER area. */
  52. case PTRACE_PEEKUSR: {
  53. unsigned long tmp = 0;
  54. if ((addr & 3) || addr >= sizeof(struct user)) {
  55. ret = -EIO;
  56. break ;
  57. }
  58. ret = 0; /* Default return condition */
  59. if (regno < H8300_REGS_NO)
  60. tmp = h8300_get_reg(child, regno);
  61. else {
  62. switch (regno) {
  63. case 49:
  64. tmp = child->mm->start_code;
  65. break ;
  66. case 50:
  67. tmp = child->mm->start_data;
  68. break ;
  69. case 51:
  70. tmp = child->mm->end_code;
  71. break ;
  72. case 52:
  73. tmp = child->mm->end_data;
  74. break ;
  75. default:
  76. ret = -EIO;
  77. }
  78. }
  79. if (!ret)
  80. ret = put_user(tmp, datap);
  81. break ;
  82. }
  83. /* when I and D space are separate, this will have to be fixed. */
  84. case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
  85. if ((addr & 3) || addr >= sizeof(struct user)) {
  86. ret = -EIO;
  87. break ;
  88. }
  89. if (regno == PT_ORIG_ER0) {
  90. ret = -EIO;
  91. break ;
  92. }
  93. if (regno < H8300_REGS_NO) {
  94. ret = h8300_put_reg(child, regno, data);
  95. break ;
  96. }
  97. ret = -EIO;
  98. break ;
  99. case PTRACE_GETREGS: { /* Get all gp regs from the child. */
  100. int i;
  101. unsigned long tmp;
  102. for (i = 0; i < H8300_REGS_NO; i++) {
  103. tmp = h8300_get_reg(child, i);
  104. if (put_user(tmp, datap)) {
  105. ret = -EFAULT;
  106. break;
  107. }
  108. datap++;
  109. }
  110. ret = 0;
  111. break;
  112. }
  113. case PTRACE_SETREGS: { /* Set all gp regs in the child. */
  114. int i;
  115. unsigned long tmp;
  116. for (i = 0; i < H8300_REGS_NO; i++) {
  117. if (get_user(tmp, datap)) {
  118. ret = -EFAULT;
  119. break;
  120. }
  121. h8300_put_reg(child, i, tmp);
  122. datap++;
  123. }
  124. ret = 0;
  125. break;
  126. }
  127. default:
  128. ret = ptrace_request(child, request, addr, data);
  129. break;
  130. }
  131. return ret;
  132. }
  133. asmlinkage void do_syscall_trace(void)
  134. {
  135. if (!test_thread_flag(TIF_SYSCALL_TRACE))
  136. return;
  137. if (!(current->ptrace & PT_PTRACED))
  138. return;
  139. ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
  140. ? 0x80 : 0));
  141. /*
  142. * this isn't the same as continuing with a signal, but it will do
  143. * for normal use. strace only continues with a signal if the
  144. * stopping signal is not SIGTRAP. -brl
  145. */
  146. if (current->exit_code) {
  147. send_sig(current->exit_code, current, 1);
  148. current->exit_code = 0;
  149. }
  150. }