ptrace.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #ifndef _ASM_X86_PTRACE_H
  2. #define _ASM_X86_PTRACE_H
  3. #include <asm/segment.h>
  4. #include <asm/page_types.h>
  5. #include <uapi/asm/ptrace.h>
  6. #ifndef __ASSEMBLY__
  7. #ifdef __i386__
  8. struct pt_regs {
  9. unsigned long bx;
  10. unsigned long cx;
  11. unsigned long dx;
  12. unsigned long si;
  13. unsigned long di;
  14. unsigned long bp;
  15. unsigned long ax;
  16. unsigned long ds;
  17. unsigned long es;
  18. unsigned long fs;
  19. unsigned long gs;
  20. unsigned long orig_ax;
  21. unsigned long ip;
  22. unsigned long cs;
  23. unsigned long flags;
  24. unsigned long sp;
  25. unsigned long ss;
  26. };
  27. #else /* __i386__ */
  28. struct pt_regs {
  29. /*
  30. * C ABI says these regs are callee-preserved. They aren't saved on kernel entry
  31. * unless syscall needs a complete, fully filled "struct pt_regs".
  32. */
  33. unsigned long r15;
  34. unsigned long r14;
  35. unsigned long r13;
  36. unsigned long r12;
  37. unsigned long bp;
  38. unsigned long bx;
  39. /* These regs are callee-clobbered. Always saved on kernel entry. */
  40. unsigned long r11;
  41. unsigned long r10;
  42. unsigned long r9;
  43. unsigned long r8;
  44. unsigned long ax;
  45. unsigned long cx;
  46. unsigned long dx;
  47. unsigned long si;
  48. unsigned long di;
  49. /*
  50. * On syscall entry, this is syscall#. On CPU exception, this is error code.
  51. * On hw interrupt, it's IRQ number:
  52. */
  53. unsigned long orig_ax;
  54. /* Return frame for iretq */
  55. unsigned long ip;
  56. unsigned long cs;
  57. unsigned long flags;
  58. unsigned long sp;
  59. unsigned long ss;
  60. /* top of stack page */
  61. };
  62. #endif /* !__i386__ */
  63. #ifdef CONFIG_PARAVIRT
  64. #include <asm/paravirt_types.h>
  65. #endif
  66. struct cpuinfo_x86;
  67. struct task_struct;
  68. extern unsigned long profile_pc(struct pt_regs *regs);
  69. #define profile_pc profile_pc
  70. extern unsigned long
  71. convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
  72. extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
  73. int error_code, int si_code);
  74. static inline unsigned long regs_return_value(struct pt_regs *regs)
  75. {
  76. return regs->ax;
  77. }
  78. /*
  79. * user_mode(regs) determines whether a register set came from user
  80. * mode. On x86_32, this is true if V8086 mode was enabled OR if the
  81. * register set was from protected mode with RPL-3 CS value. This
  82. * tricky test checks that with one comparison.
  83. *
  84. * On x86_64, vm86 mode is mercifully nonexistent, and we don't need
  85. * the extra check.
  86. */
  87. static inline int user_mode(struct pt_regs *regs)
  88. {
  89. #ifdef CONFIG_X86_32
  90. return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >= USER_RPL;
  91. #else
  92. return !!(regs->cs & 3);
  93. #endif
  94. }
  95. static inline int v8086_mode(struct pt_regs *regs)
  96. {
  97. #ifdef CONFIG_X86_32
  98. return (regs->flags & X86_VM_MASK);
  99. #else
  100. return 0; /* No V86 mode support in long mode */
  101. #endif
  102. }
  103. #ifdef CONFIG_X86_64
  104. static inline bool user_64bit_mode(struct pt_regs *regs)
  105. {
  106. #ifndef CONFIG_PARAVIRT
  107. /*
  108. * On non-paravirt systems, this is the only long mode CPL 3
  109. * selector. We do not allow long mode selectors in the LDT.
  110. */
  111. return regs->cs == __USER_CS;
  112. #else
  113. /* Headers are too twisted for this to go in paravirt.h. */
  114. return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
  115. #endif
  116. }
  117. #define current_user_stack_pointer() current_pt_regs()->sp
  118. #define compat_user_stack_pointer() current_pt_regs()->sp
  119. #endif
  120. #ifdef CONFIG_X86_32
  121. extern unsigned long kernel_stack_pointer(struct pt_regs *regs);
  122. #else
  123. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  124. {
  125. return regs->sp;
  126. }
  127. #endif
  128. #define GET_IP(regs) ((regs)->ip)
  129. #define GET_FP(regs) ((regs)->bp)
  130. #define GET_USP(regs) ((regs)->sp)
  131. #include <asm-generic/ptrace.h>
  132. /* Query offset/name of register from its name/offset */
  133. extern int regs_query_register_offset(const char *name);
  134. extern const char *regs_query_register_name(unsigned int offset);
  135. #define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
  136. /**
  137. * regs_get_register() - get register value from its offset
  138. * @regs: pt_regs from which register value is gotten.
  139. * @offset: offset number of the register.
  140. *
  141. * regs_get_register returns the value of a register. The @offset is the
  142. * offset of the register in struct pt_regs address which specified by @regs.
  143. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  144. */
  145. static inline unsigned long regs_get_register(struct pt_regs *regs,
  146. unsigned int offset)
  147. {
  148. if (unlikely(offset > MAX_REG_OFFSET))
  149. return 0;
  150. #ifdef CONFIG_X86_32
  151. /*
  152. * Traps from the kernel do not save sp and ss.
  153. * Use the helper function to retrieve sp.
  154. */
  155. if (offset == offsetof(struct pt_regs, sp) &&
  156. regs->cs == __KERNEL_CS)
  157. return kernel_stack_pointer(regs);
  158. #endif
  159. return *(unsigned long *)((unsigned long)regs + offset);
  160. }
  161. /**
  162. * regs_within_kernel_stack() - check the address in the stack
  163. * @regs: pt_regs which contains kernel stack pointer.
  164. * @addr: address which is checked.
  165. *
  166. * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
  167. * If @addr is within the kernel stack, it returns true. If not, returns false.
  168. */
  169. static inline int regs_within_kernel_stack(struct pt_regs *regs,
  170. unsigned long addr)
  171. {
  172. return ((addr & ~(THREAD_SIZE - 1)) ==
  173. (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
  174. }
  175. /**
  176. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  177. * @regs: pt_regs which contains kernel stack pointer.
  178. * @n: stack entry number.
  179. *
  180. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  181. * is specified by @regs. If the @n th entry is NOT in the kernel stack,
  182. * this returns 0.
  183. */
  184. static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  185. unsigned int n)
  186. {
  187. unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
  188. addr += n;
  189. if (regs_within_kernel_stack(regs, (unsigned long)addr))
  190. return *addr;
  191. else
  192. return 0;
  193. }
  194. #define arch_has_single_step() (1)
  195. #ifdef CONFIG_X86_DEBUGCTLMSR
  196. #define arch_has_block_step() (1)
  197. #else
  198. #define arch_has_block_step() (boot_cpu_data.x86 >= 6)
  199. #endif
  200. #define ARCH_HAS_USER_SINGLE_STEP_INFO
  201. /*
  202. * When hitting ptrace_stop(), we cannot return using SYSRET because
  203. * that does not restore the full CPU state, only a minimal set. The
  204. * ptracer can change arbitrary register values, which is usually okay
  205. * because the usual ptrace stops run off the signal delivery path which
  206. * forces IRET; however, ptrace_event() stops happen in arbitrary places
  207. * in the kernel and don't force IRET path.
  208. *
  209. * So force IRET path after a ptrace stop.
  210. */
  211. #define arch_ptrace_stop_needed(code, info) \
  212. ({ \
  213. force_iret(); \
  214. false; \
  215. })
  216. struct user_desc;
  217. extern int do_get_thread_area(struct task_struct *p, int idx,
  218. struct user_desc __user *info);
  219. extern int do_set_thread_area(struct task_struct *p, int idx,
  220. struct user_desc __user *info, int can_allocate);
  221. #endif /* !__ASSEMBLY__ */
  222. #endif /* _ASM_X86_PTRACE_H */