ptrace.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. #endif
  121. #ifdef CONFIG_X86_32
  122. extern unsigned long kernel_stack_pointer(struct pt_regs *regs);
  123. #else
  124. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  125. {
  126. return regs->sp;
  127. }
  128. #endif
  129. #define GET_IP(regs) ((regs)->ip)
  130. #define GET_FP(regs) ((regs)->bp)
  131. #define GET_USP(regs) ((regs)->sp)
  132. #include <asm-generic/ptrace.h>
  133. /* Query offset/name of register from its name/offset */
  134. extern int regs_query_register_offset(const char *name);
  135. extern const char *regs_query_register_name(unsigned int offset);
  136. #define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
  137. /**
  138. * regs_get_register() - get register value from its offset
  139. * @regs: pt_regs from which register value is gotten.
  140. * @offset: offset number of the register.
  141. *
  142. * regs_get_register returns the value of a register. The @offset is the
  143. * offset of the register in struct pt_regs address which specified by @regs.
  144. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  145. */
  146. static inline unsigned long regs_get_register(struct pt_regs *regs,
  147. unsigned int offset)
  148. {
  149. if (unlikely(offset > MAX_REG_OFFSET))
  150. return 0;
  151. #ifdef CONFIG_X86_32
  152. /*
  153. * Traps from the kernel do not save sp and ss.
  154. * Use the helper function to retrieve sp.
  155. */
  156. if (offset == offsetof(struct pt_regs, sp) &&
  157. regs->cs == __KERNEL_CS)
  158. return kernel_stack_pointer(regs);
  159. #endif
  160. return *(unsigned long *)((unsigned long)regs + offset);
  161. }
  162. /**
  163. * regs_within_kernel_stack() - check the address in the stack
  164. * @regs: pt_regs which contains kernel stack pointer.
  165. * @addr: address which is checked.
  166. *
  167. * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
  168. * If @addr is within the kernel stack, it returns true. If not, returns false.
  169. */
  170. static inline int regs_within_kernel_stack(struct pt_regs *regs,
  171. unsigned long addr)
  172. {
  173. return ((addr & ~(THREAD_SIZE - 1)) ==
  174. (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
  175. }
  176. /**
  177. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  178. * @regs: pt_regs which contains kernel stack pointer.
  179. * @n: stack entry number.
  180. *
  181. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  182. * is specified by @regs. If the @n th entry is NOT in the kernel stack,
  183. * this returns 0.
  184. */
  185. static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  186. unsigned int n)
  187. {
  188. unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
  189. addr += n;
  190. if (regs_within_kernel_stack(regs, (unsigned long)addr))
  191. return *addr;
  192. else
  193. return 0;
  194. }
  195. #define arch_has_single_step() (1)
  196. #ifdef CONFIG_X86_DEBUGCTLMSR
  197. #define arch_has_block_step() (1)
  198. #else
  199. #define arch_has_block_step() (boot_cpu_data.x86 >= 6)
  200. #endif
  201. #define ARCH_HAS_USER_SINGLE_STEP_INFO
  202. struct user_desc;
  203. extern int do_get_thread_area(struct task_struct *p, int idx,
  204. struct user_desc __user *info);
  205. extern int do_set_thread_area(struct task_struct *p, int idx,
  206. struct user_desc __user *info, int can_allocate);
  207. #endif /* !__ASSEMBLY__ */
  208. #endif /* _ASM_X86_PTRACE_H */