ptrace.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. long bx;
  32. long cx;
  33. long dx;
  34. long si;
  35. long di;
  36. long bp;
  37. long ax;
  38. int ds;
  39. int es;
  40. int fs;
  41. /* int gs; */
  42. long orig_ax;
  43. long ip;
  44. int cs;
  45. long flags;
  46. long sp;
  47. int 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 __KERNEL__
  112. /* the DS BTS struct is used for ptrace as well */
  113. #include <asm/ds.h>
  114. struct task_struct;
  115. extern void ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier);
  116. extern unsigned long profile_pc(struct pt_regs *regs);
  117. extern unsigned long
  118. convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
  119. #ifdef CONFIG_X86_32
  120. extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code);
  121. #else
  122. void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
  123. #endif
  124. #define regs_return_value(regs) ((regs)->ax)
  125. /*
  126. * user_mode_vm(regs) determines whether a register set came from user mode.
  127. * This is true if V8086 mode was enabled OR if the register set was from
  128. * protected mode with RPL-3 CS value. This tricky test checks that with
  129. * one comparison. Many places in the kernel can bypass this full check
  130. * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
  131. */
  132. static inline int user_mode(struct pt_regs *regs)
  133. {
  134. #ifdef CONFIG_X86_32
  135. return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
  136. #else
  137. return !!(regs->cs & 3);
  138. #endif
  139. }
  140. static inline int user_mode_vm(struct pt_regs *regs)
  141. {
  142. #ifdef CONFIG_X86_32
  143. return ((regs->cs & SEGMENT_RPL_MASK) |
  144. (regs->flags & VM_MASK)) >= USER_RPL;
  145. #else
  146. return user_mode(regs);
  147. #endif
  148. }
  149. static inline int v8086_mode(struct pt_regs *regs)
  150. {
  151. #ifdef CONFIG_X86_32
  152. return (regs->flags & VM_MASK);
  153. #else
  154. return 0; /* No V86 mode support in long mode */
  155. #endif
  156. }
  157. /*
  158. * X86_32 CPUs don't save ss and esp if the CPU is already in kernel mode
  159. * when it traps. So regs will be the current sp.
  160. *
  161. * This is valid only for kernel mode traps.
  162. */
  163. static inline unsigned long kernel_trap_sp(struct pt_regs *regs)
  164. {
  165. #ifdef CONFIG_X86_32
  166. return (unsigned long)regs;
  167. #else
  168. return regs->sp;
  169. #endif
  170. }
  171. static inline unsigned long instruction_pointer(struct pt_regs *regs)
  172. {
  173. return regs->ip;
  174. }
  175. static inline unsigned long frame_pointer(struct pt_regs *regs)
  176. {
  177. return regs->bp;
  178. }
  179. /*
  180. * These are defined as per linux/ptrace.h, which see.
  181. */
  182. #define arch_has_single_step() (1)
  183. extern void user_enable_single_step(struct task_struct *);
  184. extern void user_disable_single_step(struct task_struct *);
  185. extern void user_enable_block_step(struct task_struct *);
  186. #ifdef CONFIG_X86_DEBUGCTLMSR
  187. #define arch_has_block_step() (1)
  188. #else
  189. #define arch_has_block_step() (boot_cpu_data.x86 >= 6)
  190. #endif
  191. struct user_desc;
  192. extern int do_get_thread_area(struct task_struct *p, int idx,
  193. struct user_desc __user *info);
  194. extern int do_set_thread_area(struct task_struct *p, int idx,
  195. struct user_desc __user *info, int can_allocate);
  196. #endif /* __KERNEL__ */
  197. #endif /* !__ASSEMBLY__ */
  198. #endif