ptrace.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. unsigned long r15;
  30. unsigned long r14;
  31. unsigned long r13;
  32. unsigned long r12;
  33. unsigned long bp;
  34. unsigned long bx;
  35. /* arguments: non interrupts/non tracing syscalls only save up to here*/
  36. unsigned long r11;
  37. unsigned long r10;
  38. unsigned long r9;
  39. unsigned long r8;
  40. unsigned long ax;
  41. unsigned long cx;
  42. unsigned long dx;
  43. unsigned long si;
  44. unsigned long di;
  45. unsigned long orig_ax;
  46. /* end of arguments */
  47. /* cpu exception frame or undefined */
  48. unsigned long ip;
  49. unsigned long cs;
  50. unsigned long flags;
  51. unsigned long sp;
  52. unsigned long ss;
  53. /* top of stack page */
  54. };
  55. #endif /* !__i386__ */
  56. #include <linux/init.h>
  57. #ifdef CONFIG_PARAVIRT
  58. #include <asm/paravirt_types.h>
  59. #endif
  60. struct cpuinfo_x86;
  61. struct task_struct;
  62. extern unsigned long profile_pc(struct pt_regs *regs);
  63. #define profile_pc profile_pc
  64. extern unsigned long
  65. convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
  66. extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
  67. int error_code, int si_code);
  68. extern long syscall_trace_enter(struct pt_regs *);
  69. extern void syscall_trace_leave(struct pt_regs *);
  70. static inline unsigned long regs_return_value(struct pt_regs *regs)
  71. {
  72. return regs->ax;
  73. }
  74. /*
  75. * user_mode_vm(regs) determines whether a register set came from user mode.
  76. * This is true if V8086 mode was enabled OR if the register set was from
  77. * protected mode with RPL-3 CS value. This tricky test checks that with
  78. * one comparison. Many places in the kernel can bypass this full check
  79. * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
  80. */
  81. static inline int user_mode(struct pt_regs *regs)
  82. {
  83. #ifdef CONFIG_X86_32
  84. return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
  85. #else
  86. return !!(regs->cs & 3);
  87. #endif
  88. }
  89. static inline int user_mode_vm(struct pt_regs *regs)
  90. {
  91. #ifdef CONFIG_X86_32
  92. return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
  93. USER_RPL;
  94. #else
  95. return user_mode(regs);
  96. #endif
  97. }
  98. static inline int v8086_mode(struct pt_regs *regs)
  99. {
  100. #ifdef CONFIG_X86_32
  101. return (regs->flags & X86_VM_MASK);
  102. #else
  103. return 0; /* No V86 mode support in long mode */
  104. #endif
  105. }
  106. #ifdef CONFIG_X86_64
  107. static inline bool user_64bit_mode(struct pt_regs *regs)
  108. {
  109. #ifndef CONFIG_PARAVIRT
  110. /*
  111. * On non-paravirt systems, this is the only long mode CPL 3
  112. * selector. We do not allow long mode selectors in the LDT.
  113. */
  114. return regs->cs == __USER_CS;
  115. #else
  116. /* Headers are too twisted for this to go in paravirt.h. */
  117. return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
  118. #endif
  119. }
  120. #define current_user_stack_pointer() this_cpu_read(old_rsp)
  121. /* ia32 vs. x32 difference */
  122. #define compat_user_stack_pointer() \
  123. (test_thread_flag(TIF_IA32) \
  124. ? current_pt_regs()->sp \
  125. : this_cpu_read(old_rsp))
  126. #endif
  127. #ifdef CONFIG_X86_32
  128. extern unsigned long kernel_stack_pointer(struct pt_regs *regs);
  129. #else
  130. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  131. {
  132. return regs->sp;
  133. }
  134. #endif
  135. #define GET_IP(regs) ((regs)->ip)
  136. #define GET_FP(regs) ((regs)->bp)
  137. #define GET_USP(regs) ((regs)->sp)
  138. #include <asm-generic/ptrace.h>
  139. /* Query offset/name of register from its name/offset */
  140. extern int regs_query_register_offset(const char *name);
  141. extern const char *regs_query_register_name(unsigned int offset);
  142. #define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
  143. /**
  144. * regs_get_register() - get register value from its offset
  145. * @regs: pt_regs from which register value is gotten.
  146. * @offset: offset number of the register.
  147. *
  148. * regs_get_register returns the value of a register. The @offset is the
  149. * offset of the register in struct pt_regs address which specified by @regs.
  150. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  151. */
  152. static inline unsigned long regs_get_register(struct pt_regs *regs,
  153. unsigned int offset)
  154. {
  155. if (unlikely(offset > MAX_REG_OFFSET))
  156. return 0;
  157. #ifdef CONFIG_X86_32
  158. /*
  159. * Traps from the kernel do not save sp and ss.
  160. * Use the helper function to retrieve sp.
  161. */
  162. if (offset == offsetof(struct pt_regs, sp) &&
  163. regs->cs == __KERNEL_CS)
  164. return kernel_stack_pointer(regs);
  165. #endif
  166. return *(unsigned long *)((unsigned long)regs + offset);
  167. }
  168. /**
  169. * regs_within_kernel_stack() - check the address in the stack
  170. * @regs: pt_regs which contains kernel stack pointer.
  171. * @addr: address which is checked.
  172. *
  173. * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
  174. * If @addr is within the kernel stack, it returns true. If not, returns false.
  175. */
  176. static inline int regs_within_kernel_stack(struct pt_regs *regs,
  177. unsigned long addr)
  178. {
  179. return ((addr & ~(THREAD_SIZE - 1)) ==
  180. (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
  181. }
  182. /**
  183. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  184. * @regs: pt_regs which contains kernel stack pointer.
  185. * @n: stack entry number.
  186. *
  187. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  188. * is specified by @regs. If the @n th entry is NOT in the kernel stack,
  189. * this returns 0.
  190. */
  191. static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  192. unsigned int n)
  193. {
  194. unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
  195. addr += n;
  196. if (regs_within_kernel_stack(regs, (unsigned long)addr))
  197. return *addr;
  198. else
  199. return 0;
  200. }
  201. #define arch_has_single_step() (1)
  202. #ifdef CONFIG_X86_DEBUGCTLMSR
  203. #define arch_has_block_step() (1)
  204. #else
  205. #define arch_has_block_step() (boot_cpu_data.x86 >= 6)
  206. #endif
  207. #define ARCH_HAS_USER_SINGLE_STEP_INFO
  208. struct user_desc;
  209. extern int do_get_thread_area(struct task_struct *p, int idx,
  210. struct user_desc __user *info);
  211. extern int do_set_thread_area(struct task_struct *p, int idx,
  212. struct user_desc __user *info, int can_allocate);
  213. #endif /* !__ASSEMBLY__ */
  214. #endif /* _ASM_X86_PTRACE_H */