ptrace.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. #include <asm/page_types.h>
  9. #endif
  10. #ifndef __ASSEMBLY__
  11. #ifdef __i386__
  12. /* this struct defines the way the registers are stored on the
  13. stack during a system call. */
  14. #ifndef __KERNEL__
  15. struct pt_regs {
  16. long ebx;
  17. long ecx;
  18. long edx;
  19. long esi;
  20. long edi;
  21. long ebp;
  22. long eax;
  23. int xds;
  24. int xes;
  25. int xfs;
  26. int xgs;
  27. long orig_eax;
  28. long eip;
  29. int xcs;
  30. long eflags;
  31. long esp;
  32. int xss;
  33. };
  34. #else /* __KERNEL__ */
  35. struct pt_regs {
  36. unsigned long bx;
  37. unsigned long cx;
  38. unsigned long dx;
  39. unsigned long si;
  40. unsigned long di;
  41. unsigned long bp;
  42. unsigned long ax;
  43. unsigned long ds;
  44. unsigned long es;
  45. unsigned long fs;
  46. unsigned long gs;
  47. unsigned long orig_ax;
  48. unsigned long ip;
  49. unsigned long cs;
  50. unsigned long flags;
  51. unsigned long sp;
  52. unsigned long ss;
  53. };
  54. #endif /* __KERNEL__ */
  55. #else /* __i386__ */
  56. #ifndef __KERNEL__
  57. struct pt_regs {
  58. unsigned long r15;
  59. unsigned long r14;
  60. unsigned long r13;
  61. unsigned long r12;
  62. unsigned long rbp;
  63. unsigned long rbx;
  64. /* arguments: non interrupts/non tracing syscalls only save up to here*/
  65. unsigned long r11;
  66. unsigned long r10;
  67. unsigned long r9;
  68. unsigned long r8;
  69. unsigned long rax;
  70. unsigned long rcx;
  71. unsigned long rdx;
  72. unsigned long rsi;
  73. unsigned long rdi;
  74. unsigned long orig_rax;
  75. /* end of arguments */
  76. /* cpu exception frame or undefined */
  77. unsigned long rip;
  78. unsigned long cs;
  79. unsigned long eflags;
  80. unsigned long rsp;
  81. unsigned long ss;
  82. /* top of stack page */
  83. };
  84. #else /* __KERNEL__ */
  85. struct pt_regs {
  86. unsigned long r15;
  87. unsigned long r14;
  88. unsigned long r13;
  89. unsigned long r12;
  90. unsigned long bp;
  91. unsigned long bx;
  92. /* arguments: non interrupts/non tracing syscalls only save up to here*/
  93. unsigned long r11;
  94. unsigned long r10;
  95. unsigned long r9;
  96. unsigned long r8;
  97. unsigned long ax;
  98. unsigned long cx;
  99. unsigned long dx;
  100. unsigned long si;
  101. unsigned long di;
  102. unsigned long orig_ax;
  103. /* end of arguments */
  104. /* cpu exception frame or undefined */
  105. unsigned long ip;
  106. unsigned long cs;
  107. unsigned long flags;
  108. unsigned long sp;
  109. unsigned long ss;
  110. /* top of stack page */
  111. };
  112. #endif /* __KERNEL__ */
  113. #endif /* !__i386__ */
  114. #ifdef __KERNEL__
  115. #include <linux/init.h>
  116. #ifdef CONFIG_PARAVIRT
  117. #include <asm/paravirt_types.h>
  118. #endif
  119. struct cpuinfo_x86;
  120. struct task_struct;
  121. extern unsigned long profile_pc(struct pt_regs *regs);
  122. #define profile_pc profile_pc
  123. extern unsigned long
  124. convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
  125. extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
  126. int error_code, int si_code);
  127. extern long syscall_trace_enter(struct pt_regs *);
  128. extern void syscall_trace_leave(struct pt_regs *);
  129. static inline unsigned long regs_return_value(struct pt_regs *regs)
  130. {
  131. return regs->ax;
  132. }
  133. /*
  134. * user_mode_vm(regs) determines whether a register set came from user mode.
  135. * This is true if V8086 mode was enabled OR if the register set was from
  136. * protected mode with RPL-3 CS value. This tricky test checks that with
  137. * one comparison. Many places in the kernel can bypass this full check
  138. * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
  139. */
  140. static inline int user_mode(struct pt_regs *regs)
  141. {
  142. #ifdef CONFIG_X86_32
  143. return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
  144. #else
  145. return !!(regs->cs & 3);
  146. #endif
  147. }
  148. static inline int user_mode_vm(struct pt_regs *regs)
  149. {
  150. #ifdef CONFIG_X86_32
  151. return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
  152. USER_RPL;
  153. #else
  154. return user_mode(regs);
  155. #endif
  156. }
  157. static inline int v8086_mode(struct pt_regs *regs)
  158. {
  159. #ifdef CONFIG_X86_32
  160. return (regs->flags & X86_VM_MASK);
  161. #else
  162. return 0; /* No V86 mode support in long mode */
  163. #endif
  164. }
  165. #ifdef CONFIG_X86_64
  166. static inline bool user_64bit_mode(struct pt_regs *regs)
  167. {
  168. #ifndef CONFIG_PARAVIRT
  169. /*
  170. * On non-paravirt systems, this is the only long mode CPL 3
  171. * selector. We do not allow long mode selectors in the LDT.
  172. */
  173. return regs->cs == __USER_CS;
  174. #else
  175. /* Headers are too twisted for this to go in paravirt.h. */
  176. return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
  177. #endif
  178. }
  179. #endif
  180. #ifdef CONFIG_X86_32
  181. extern unsigned long kernel_stack_pointer(struct pt_regs *regs);
  182. #else
  183. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  184. {
  185. return regs->sp;
  186. }
  187. #endif
  188. #define GET_IP(regs) ((regs)->ip)
  189. #define GET_FP(regs) ((regs)->bp)
  190. #define GET_USP(regs) ((regs)->sp)
  191. #include <asm-generic/ptrace.h>
  192. /* Query offset/name of register from its name/offset */
  193. extern int regs_query_register_offset(const char *name);
  194. extern const char *regs_query_register_name(unsigned int offset);
  195. #define MAX_REG_OFFSET (offsetof(struct pt_regs, ss))
  196. /**
  197. * regs_get_register() - get register value from its offset
  198. * @regs: pt_regs from which register value is gotten.
  199. * @offset: offset number of the register.
  200. *
  201. * regs_get_register returns the value of a register. The @offset is the
  202. * offset of the register in struct pt_regs address which specified by @regs.
  203. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  204. */
  205. static inline unsigned long regs_get_register(struct pt_regs *regs,
  206. unsigned int offset)
  207. {
  208. if (unlikely(offset > MAX_REG_OFFSET))
  209. return 0;
  210. return *(unsigned long *)((unsigned long)regs + offset);
  211. }
  212. /**
  213. * regs_within_kernel_stack() - check the address in the stack
  214. * @regs: pt_regs which contains kernel stack pointer.
  215. * @addr: address which is checked.
  216. *
  217. * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
  218. * If @addr is within the kernel stack, it returns true. If not, returns false.
  219. */
  220. static inline int regs_within_kernel_stack(struct pt_regs *regs,
  221. unsigned long addr)
  222. {
  223. return ((addr & ~(THREAD_SIZE - 1)) ==
  224. (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
  225. }
  226. /**
  227. * regs_get_kernel_stack_nth() - get Nth entry of the stack
  228. * @regs: pt_regs which contains kernel stack pointer.
  229. * @n: stack entry number.
  230. *
  231. * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
  232. * is specified by @regs. If the @n th entry is NOT in the kernel stack,
  233. * this returns 0.
  234. */
  235. static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  236. unsigned int n)
  237. {
  238. unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
  239. addr += n;
  240. if (regs_within_kernel_stack(regs, (unsigned long)addr))
  241. return *addr;
  242. else
  243. return 0;
  244. }
  245. #define arch_has_single_step() (1)
  246. #ifdef CONFIG_X86_DEBUGCTLMSR
  247. #define arch_has_block_step() (1)
  248. #else
  249. #define arch_has_block_step() (boot_cpu_data.x86 >= 6)
  250. #endif
  251. #define ARCH_HAS_USER_SINGLE_STEP_INFO
  252. /*
  253. * When hitting ptrace_stop(), we cannot return using SYSRET because
  254. * that does not restore the full CPU state, only a minimal set. The
  255. * ptracer can change arbitrary register values, which is usually okay
  256. * because the usual ptrace stops run off the signal delivery path which
  257. * forces IRET; however, ptrace_event() stops happen in arbitrary places
  258. * in the kernel and don't force IRET path.
  259. *
  260. * So force IRET path after a ptrace stop.
  261. */
  262. #define arch_ptrace_stop_needed(code, info) \
  263. ({ \
  264. set_thread_flag(TIF_NOTIFY_RESUME); \
  265. false; \
  266. })
  267. struct user_desc;
  268. extern int do_get_thread_area(struct task_struct *p, int idx,
  269. struct user_desc __user *info);
  270. extern int do_set_thread_area(struct task_struct *p, int idx,
  271. struct user_desc __user *info, int can_allocate);
  272. #endif /* __KERNEL__ */
  273. #endif /* !__ASSEMBLY__ */
  274. #endif /* _ASM_X86_PTRACE_H */