ptrace.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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, long addr, long data)
  46. {
  47. int ret;
  48. switch (request) {
  49. /* read the word at location addr in the USER area. */
  50. case PTRACE_PEEKUSR: {
  51. unsigned long tmp = 0;
  52. if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
  53. ret = -EIO;
  54. break ;
  55. }
  56. ret = 0; /* Default return condition */
  57. addr = addr >> 2; /* temporary hack. */
  58. if (addr < H8300_REGS_NO)
  59. tmp = h8300_get_reg(child, addr);
  60. else {
  61. switch(addr) {
  62. case 49:
  63. tmp = child->mm->start_code;
  64. break ;
  65. case 50:
  66. tmp = child->mm->start_data;
  67. break ;
  68. case 51:
  69. tmp = child->mm->end_code;
  70. break ;
  71. case 52:
  72. tmp = child->mm->end_data;
  73. break ;
  74. default:
  75. ret = -EIO;
  76. }
  77. }
  78. if (!ret)
  79. ret = put_user(tmp,(unsigned long *) data);
  80. break ;
  81. }
  82. /* when I and D space are separate, this will have to be fixed. */
  83. case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
  84. if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
  85. ret = -EIO;
  86. break ;
  87. }
  88. addr = addr >> 2; /* temporary hack. */
  89. if (addr == PT_ORIG_ER0) {
  90. ret = -EIO;
  91. break ;
  92. }
  93. if (addr < H8300_REGS_NO) {
  94. ret = h8300_put_reg(child, addr, 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, (unsigned long *) data)) {
  105. ret = -EFAULT;
  106. break;
  107. }
  108. data += sizeof(long);
  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, (unsigned long *) data)) {
  118. ret = -EFAULT;
  119. break;
  120. }
  121. h8300_put_reg(child, i, tmp);
  122. data += sizeof(long);
  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. }