ptrace.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle
  7. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8. */
  9. #ifndef _ASM_PTRACE_H
  10. #define _ASM_PTRACE_H
  11. #include <linux/compiler.h>
  12. #include <linux/linkage.h>
  13. #include <linux/types.h>
  14. #include <asm/isadep.h>
  15. #include <asm/page.h>
  16. #include <asm/thread_info.h>
  17. #include <uapi/asm/ptrace.h>
  18. /*
  19. * This struct defines the way the registers are stored on the stack during a
  20. * system call/exception. As usual the registers k0/k1 aren't being saved.
  21. *
  22. * If you add a register here, also add it to regoffset_table[] in
  23. * arch/mips/kernel/ptrace.c.
  24. */
  25. struct pt_regs {
  26. #ifdef CONFIG_32BIT
  27. /* Pad bytes for argument save space on the stack. */
  28. unsigned long pad0[8];
  29. #endif
  30. /* Saved main processor registers. */
  31. unsigned long regs[32];
  32. /* Saved special registers. */
  33. unsigned long cp0_status;
  34. unsigned long hi;
  35. unsigned long lo;
  36. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  37. unsigned long acx;
  38. #endif
  39. unsigned long cp0_badvaddr;
  40. unsigned long cp0_cause;
  41. unsigned long cp0_epc;
  42. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  43. unsigned long long mpl[6]; /* MTM{0-5} */
  44. unsigned long long mtp[6]; /* MTP{0-5} */
  45. #endif
  46. unsigned long __last[0];
  47. } __aligned(8);
  48. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  49. {
  50. return regs->regs[31];
  51. }
  52. /*
  53. * Don't use asm-generic/ptrace.h it defines FP accessors that don't make
  54. * sense on MIPS. We rather want an error if they get invoked.
  55. */
  56. static inline void instruction_pointer_set(struct pt_regs *regs,
  57. unsigned long val)
  58. {
  59. regs->cp0_epc = val;
  60. }
  61. /* Query offset/name of register from its name/offset */
  62. extern int regs_query_register_offset(const char *name);
  63. #define MAX_REG_OFFSET (offsetof(struct pt_regs, __last))
  64. /**
  65. * regs_get_register() - get register value from its offset
  66. * @regs: pt_regs from which register value is gotten.
  67. * @offset: offset number of the register.
  68. *
  69. * regs_get_register returns the value of a register. The @offset is the
  70. * offset of the register in struct pt_regs address which specified by @regs.
  71. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  72. */
  73. static inline unsigned long regs_get_register(struct pt_regs *regs,
  74. unsigned int offset)
  75. {
  76. if (unlikely(offset > MAX_REG_OFFSET))
  77. return 0;
  78. return *(unsigned long *)((unsigned long)regs + offset);
  79. }
  80. /**
  81. * regs_within_kernel_stack() - check the address in the stack
  82. * @regs: pt_regs which contains kernel stack pointer.
  83. * @addr: address which is checked.
  84. *
  85. * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
  86. * If @addr is within the kernel stack, it returns true. If not, returns false.
  87. */
  88. static inline int regs_within_kernel_stack(struct pt_regs *regs,
  89. unsigned long addr)
  90. {
  91. return ((addr & ~(THREAD_SIZE - 1)) ==
  92. (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
  93. }
  94. /**
  95. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  96. * @regs: pt_regs which contains kernel stack pointer.
  97. * @n: stack entry number.
  98. *
  99. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  100. * is specified by @regs. If the @n th entry is NOT in the kernel stack,
  101. * this returns 0.
  102. */
  103. static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  104. unsigned int n)
  105. {
  106. unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
  107. addr += n;
  108. if (regs_within_kernel_stack(regs, (unsigned long)addr))
  109. return *addr;
  110. else
  111. return 0;
  112. }
  113. struct task_struct;
  114. extern int ptrace_getregs(struct task_struct *child,
  115. struct user_pt_regs __user *data);
  116. extern int ptrace_setregs(struct task_struct *child,
  117. struct user_pt_regs __user *data);
  118. extern int ptrace_getfpregs(struct task_struct *child, __u32 __user *data);
  119. extern int ptrace_setfpregs(struct task_struct *child, __u32 __user *data);
  120. extern int ptrace_get_watch_regs(struct task_struct *child,
  121. struct pt_watch_regs __user *addr);
  122. extern int ptrace_set_watch_regs(struct task_struct *child,
  123. struct pt_watch_regs __user *addr);
  124. /*
  125. * Does the process account for user or for system time?
  126. */
  127. #define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER)
  128. static inline int is_syscall_success(struct pt_regs *regs)
  129. {
  130. return !regs->regs[7];
  131. }
  132. static inline long regs_return_value(struct pt_regs *regs)
  133. {
  134. if (is_syscall_success(regs) || !user_mode(regs))
  135. return regs->regs[2];
  136. else
  137. return -regs->regs[2];
  138. }
  139. #define instruction_pointer(regs) ((regs)->cp0_epc)
  140. #define profile_pc(regs) instruction_pointer(regs)
  141. extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall);
  142. extern asmlinkage void syscall_trace_leave(struct pt_regs *regs);
  143. extern void die(const char *, struct pt_regs *) __noreturn;
  144. static inline void die_if_kernel(const char *str, struct pt_regs *regs)
  145. {
  146. if (unlikely(!user_mode(regs)))
  147. die(str, regs);
  148. }
  149. #define current_pt_regs() \
  150. ({ \
  151. unsigned long sp = (unsigned long)__builtin_frame_address(0); \
  152. (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \
  153. })
  154. /* Helpers for working with the user stack pointer */
  155. static inline unsigned long user_stack_pointer(struct pt_regs *regs)
  156. {
  157. return regs->regs[29];
  158. }
  159. static inline void user_stack_pointer_set(struct pt_regs *regs,
  160. unsigned long val)
  161. {
  162. regs->regs[29] = val;
  163. }
  164. #endif /* _ASM_PTRACE_H */