ptrace.h 5.3 KB

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