ptrace.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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[29];
  51. }
  52. static inline void instruction_pointer_set(struct pt_regs *regs,
  53. unsigned long val)
  54. {
  55. regs->cp0_epc = val;
  56. }
  57. /* Query offset/name of register from its name/offset */
  58. extern int regs_query_register_offset(const char *name);
  59. #define MAX_REG_OFFSET (offsetof(struct pt_regs, __last))
  60. /**
  61. * regs_get_register() - get register value from its offset
  62. * @regs: pt_regs from which register value is gotten.
  63. * @offset: offset number of the register.
  64. *
  65. * regs_get_register returns the value of a register. The @offset is the
  66. * offset of the register in struct pt_regs address which specified by @regs.
  67. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  68. */
  69. static inline unsigned long regs_get_register(struct pt_regs *regs,
  70. unsigned int offset)
  71. {
  72. if (unlikely(offset > MAX_REG_OFFSET))
  73. return 0;
  74. return *(unsigned long *)((unsigned long)regs + offset);
  75. }
  76. /**
  77. * regs_within_kernel_stack() - check the address in the stack
  78. * @regs: pt_regs which contains kernel stack pointer.
  79. * @addr: address which is checked.
  80. *
  81. * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
  82. * If @addr is within the kernel stack, it returns true. If not, returns false.
  83. */
  84. static inline int regs_within_kernel_stack(struct pt_regs *regs,
  85. unsigned long addr)
  86. {
  87. return ((addr & ~(THREAD_SIZE - 1)) ==
  88. (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
  89. }
  90. /**
  91. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  92. * @regs: pt_regs which contains kernel stack pointer.
  93. * @n: stack entry number.
  94. *
  95. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  96. * is specified by @regs. If the @n th entry is NOT in the kernel stack,
  97. * this returns 0.
  98. */
  99. static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  100. unsigned int n)
  101. {
  102. unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
  103. addr += n;
  104. if (regs_within_kernel_stack(regs, (unsigned long)addr))
  105. return *addr;
  106. else
  107. return 0;
  108. }
  109. struct task_struct;
  110. extern int ptrace_getregs(struct task_struct *child,
  111. struct user_pt_regs __user *data);
  112. extern int ptrace_setregs(struct task_struct *child,
  113. struct user_pt_regs __user *data);
  114. extern int ptrace_getfpregs(struct task_struct *child, __u32 __user *data);
  115. extern int ptrace_setfpregs(struct task_struct *child, __u32 __user *data);
  116. extern int ptrace_get_watch_regs(struct task_struct *child,
  117. struct pt_watch_regs __user *addr);
  118. extern int ptrace_set_watch_regs(struct task_struct *child,
  119. struct pt_watch_regs __user *addr);
  120. /*
  121. * Does the process account for user or for system time?
  122. */
  123. #define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER)
  124. static inline int is_syscall_success(struct pt_regs *regs)
  125. {
  126. return !regs->regs[7];
  127. }
  128. static inline long regs_return_value(struct pt_regs *regs)
  129. {
  130. if (is_syscall_success(regs) || !user_mode(regs))
  131. return regs->regs[2];
  132. else
  133. return -regs->regs[2];
  134. }
  135. #define instruction_pointer(regs) ((regs)->cp0_epc)
  136. #define profile_pc(regs) instruction_pointer(regs)
  137. extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall);
  138. extern asmlinkage void syscall_trace_leave(struct pt_regs *regs);
  139. extern void die(const char *, struct pt_regs *) __noreturn;
  140. static inline void die_if_kernel(const char *str, struct pt_regs *regs)
  141. {
  142. if (unlikely(!user_mode(regs)))
  143. die(str, regs);
  144. }
  145. #define current_pt_regs() \
  146. ({ \
  147. unsigned long sp = (unsigned long)__builtin_frame_address(0); \
  148. (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \
  149. })
  150. /* Helpers for working with the user stack pointer */
  151. static inline unsigned long user_stack_pointer(struct pt_regs *regs)
  152. {
  153. return regs->regs[29];
  154. }
  155. static inline void user_stack_pointer_set(struct pt_regs *regs,
  156. unsigned long val)
  157. {
  158. regs->regs[29] = val;
  159. }
  160. #endif /* _ASM_PTRACE_H */