ptrace.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #ifndef _ASM_X86_PTRACE_H
  2. #define _ASM_X86_PTRACE_H
  3. #include <linux/compiler.h> /* For __user */
  4. #include <asm/ptrace-abi.h>
  5. #ifndef __ASSEMBLY__
  6. #ifdef __i386__
  7. /* this struct defines the way the registers are stored on the
  8. stack during a system call. */
  9. #ifndef __KERNEL__
  10. struct pt_regs {
  11. long ebx;
  12. long ecx;
  13. long edx;
  14. long esi;
  15. long edi;
  16. long ebp;
  17. long eax;
  18. int xds;
  19. int xes;
  20. int xfs;
  21. /* int gs; */
  22. long orig_eax;
  23. long eip;
  24. int xcs;
  25. long eflags;
  26. long esp;
  27. int xss;
  28. };
  29. #else /* __KERNEL__ */
  30. struct pt_regs {
  31. unsigned long bx;
  32. unsigned long cx;
  33. unsigned long dx;
  34. unsigned long si;
  35. unsigned long di;
  36. unsigned long bp;
  37. unsigned long ax;
  38. unsigned long ds;
  39. unsigned long es;
  40. unsigned long fs;
  41. /* int gs; */
  42. unsigned long orig_ax;
  43. unsigned long ip;
  44. unsigned long cs;
  45. unsigned long flags;
  46. unsigned long sp;
  47. unsigned long ss;
  48. };
  49. #include <asm/vm86.h>
  50. #include <asm/segment.h>
  51. #endif /* __KERNEL__ */
  52. #else /* __i386__ */
  53. #ifndef __KERNEL__
  54. struct pt_regs {
  55. unsigned long r15;
  56. unsigned long r14;
  57. unsigned long r13;
  58. unsigned long r12;
  59. unsigned long rbp;
  60. unsigned long rbx;
  61. /* arguments: non interrupts/non tracing syscalls only save upto here*/
  62. unsigned long r11;
  63. unsigned long r10;
  64. unsigned long r9;
  65. unsigned long r8;
  66. unsigned long rax;
  67. unsigned long rcx;
  68. unsigned long rdx;
  69. unsigned long rsi;
  70. unsigned long rdi;
  71. unsigned long orig_rax;
  72. /* end of arguments */
  73. /* cpu exception frame or undefined */
  74. unsigned long rip;
  75. unsigned long cs;
  76. unsigned long eflags;
  77. unsigned long rsp;
  78. unsigned long ss;
  79. /* top of stack page */
  80. };
  81. #else /* __KERNEL__ */
  82. struct pt_regs {
  83. unsigned long r15;
  84. unsigned long r14;
  85. unsigned long r13;
  86. unsigned long r12;
  87. unsigned long bp;
  88. unsigned long bx;
  89. /* arguments: non interrupts/non tracing syscalls only save upto here*/
  90. unsigned long r11;
  91. unsigned long r10;
  92. unsigned long r9;
  93. unsigned long r8;
  94. unsigned long ax;
  95. unsigned long cx;
  96. unsigned long dx;
  97. unsigned long si;
  98. unsigned long di;
  99. unsigned long orig_ax;
  100. /* end of arguments */
  101. /* cpu exception frame or undefined */
  102. unsigned long ip;
  103. unsigned long cs;
  104. unsigned long flags;
  105. unsigned long sp;
  106. unsigned long ss;
  107. /* top of stack page */
  108. };
  109. #endif /* __KERNEL__ */
  110. #endif /* !__i386__ */
  111. #ifdef CONFIG_X86_PTRACE_BTS
  112. /* a branch trace record entry
  113. *
  114. * In order to unify the interface between various processor versions,
  115. * we use the below data structure for all processors.
  116. */
  117. enum bts_qualifier {
  118. BTS_INVALID = 0,
  119. BTS_BRANCH,
  120. BTS_TASK_ARRIVES,
  121. BTS_TASK_DEPARTS
  122. };
  123. struct bts_struct {
  124. __u64 qualifier;
  125. union {
  126. /* BTS_BRANCH */
  127. struct {
  128. __u64 from_ip;
  129. __u64 to_ip;
  130. } lbr;
  131. /* BTS_TASK_ARRIVES or
  132. BTS_TASK_DEPARTS */
  133. __u64 jiffies;
  134. } variant;
  135. };
  136. #endif /* CONFIG_X86_PTRACE_BTS */
  137. #ifdef __KERNEL__
  138. #include <linux/init.h>
  139. struct cpuinfo_x86;
  140. struct task_struct;
  141. #ifdef CONFIG_X86_PTRACE_BTS
  142. extern void __cpuinit ptrace_bts_init_intel(struct cpuinfo_x86 *);
  143. extern void ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier);
  144. #else
  145. #define ptrace_bts_init_intel(config) do {} while (0)
  146. #endif /* CONFIG_X86_PTRACE_BTS */
  147. extern unsigned long profile_pc(struct pt_regs *regs);
  148. extern unsigned long
  149. convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
  150. #ifdef CONFIG_X86_32
  151. extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
  152. int error_code);
  153. #else
  154. void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
  155. #endif
  156. static inline unsigned long regs_return_value(struct pt_regs *regs)
  157. {
  158. return regs->ax;
  159. }
  160. /*
  161. * user_mode_vm(regs) determines whether a register set came from user mode.
  162. * This is true if V8086 mode was enabled OR if the register set was from
  163. * protected mode with RPL-3 CS value. This tricky test checks that with
  164. * one comparison. Many places in the kernel can bypass this full check
  165. * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
  166. */
  167. static inline int user_mode(struct pt_regs *regs)
  168. {
  169. #ifdef CONFIG_X86_32
  170. return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
  171. #else
  172. return !!(regs->cs & 3);
  173. #endif
  174. }
  175. static inline int user_mode_vm(struct pt_regs *regs)
  176. {
  177. #ifdef CONFIG_X86_32
  178. return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
  179. USER_RPL;
  180. #else
  181. return user_mode(regs);
  182. #endif
  183. }
  184. static inline int v8086_mode(struct pt_regs *regs)
  185. {
  186. #ifdef CONFIG_X86_32
  187. return (regs->flags & X86_VM_MASK);
  188. #else
  189. return 0; /* No V86 mode support in long mode */
  190. #endif
  191. }
  192. /*
  193. * X86_32 CPUs don't save ss and esp if the CPU is already in kernel mode
  194. * when it traps. So regs will be the current sp.
  195. *
  196. * This is valid only for kernel mode traps.
  197. */
  198. static inline unsigned long kernel_trap_sp(struct pt_regs *regs)
  199. {
  200. #ifdef CONFIG_X86_32
  201. return (unsigned long)regs;
  202. #else
  203. return regs->sp;
  204. #endif
  205. }
  206. static inline unsigned long instruction_pointer(struct pt_regs *regs)
  207. {
  208. return regs->ip;
  209. }
  210. static inline unsigned long frame_pointer(struct pt_regs *regs)
  211. {
  212. return regs->bp;
  213. }
  214. /*
  215. * These are defined as per linux/ptrace.h, which see.
  216. */
  217. #define arch_has_single_step() (1)
  218. extern void user_enable_single_step(struct task_struct *);
  219. extern void user_disable_single_step(struct task_struct *);
  220. extern void user_enable_block_step(struct task_struct *);
  221. #ifdef CONFIG_X86_DEBUGCTLMSR
  222. #define arch_has_block_step() (1)
  223. #else
  224. #define arch_has_block_step() (boot_cpu_data.x86 >= 6)
  225. #endif
  226. struct user_desc;
  227. extern int do_get_thread_area(struct task_struct *p, int idx,
  228. struct user_desc __user *info);
  229. extern int do_set_thread_area(struct task_struct *p, int idx,
  230. struct user_desc __user *info, int can_allocate);
  231. #define __ARCH_WANT_COMPAT_SYS_PTRACE
  232. #endif /* __KERNEL__ */
  233. #endif /* !__ASSEMBLY__ */
  234. #endif