xref: /linux/arch/x86/um/asm/ptrace.h (revision 831c1926ee728c3e747255f7c0f434762e8e863d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __UM_X86_PTRACE_H
3 #define __UM_X86_PTRACE_H
4 
5 /* This is here because signal.c needs the REGSET_FP_LEGACY definition */
6 enum {
7 	REGSET_GENERAL,
8 #ifdef CONFIG_X86_32
9 	REGSET_FP_LEGACY,
10 #endif
11 	REGSET_FP,
12 	REGSET_XSTATE,
13 };
14 
15 #include <linux/compiler.h>
16 #ifndef CONFIG_X86_32
17 #define __FRAME_OFFSETS /* Needed to get the R* macros */
18 #endif
19 #include <asm/ptrace-generic.h>
20 
21 #define user_mode(r) UPT_IS_USER(&(r)->regs)
22 
23 #define PT_REGS_AX(r) UPT_AX(&(r)->regs)
24 #define PT_REGS_BX(r) UPT_BX(&(r)->regs)
25 #define PT_REGS_CX(r) UPT_CX(&(r)->regs)
26 #define PT_REGS_DX(r) UPT_DX(&(r)->regs)
27 
28 #define PT_REGS_SI(r) UPT_SI(&(r)->regs)
29 #define PT_REGS_DI(r) UPT_DI(&(r)->regs)
30 #define PT_REGS_BP(r) UPT_BP(&(r)->regs)
31 #define PT_REGS_EFLAGS(r) UPT_EFLAGS(&(r)->regs)
32 
33 #define PT_REGS_CS(r) UPT_CS(&(r)->regs)
34 #define PT_REGS_SS(r) UPT_SS(&(r)->regs)
35 #define PT_REGS_DS(r) UPT_DS(&(r)->regs)
36 #define PT_REGS_ES(r) UPT_ES(&(r)->regs)
37 
38 #define PT_REGS_ORIG_SYSCALL(r) PT_REGS_AX(r)
39 #define PT_REGS_SYSCALL_RET(r) PT_REGS_AX(r)
40 
41 #define PT_FIX_EXEC_STACK(sp) do ; while(0)
42 
43 #define profile_pc(regs) PT_REGS_IP(regs)
44 
45 #define UPT_RESTART_SYSCALL(r) (UPT_IP(r) -= 2)
46 #define PT_REGS_SET_SYSCALL_RETURN(r, res) (PT_REGS_AX(r) = (res))
47 
regs_return_value(struct pt_regs * regs)48 static inline long regs_return_value(struct pt_regs *regs)
49 {
50 	return PT_REGS_AX(regs);
51 }
52 
53 /*
54  * Forward declaration to avoid including sysdep/tls.h, which causes a
55  * circular include, and compilation failures.
56  */
57 struct user_desc;
58 
59 #ifdef CONFIG_X86_32
60 
61 extern int ptrace_get_thread_area(struct task_struct *child, int idx,
62                                   struct user_desc __user *user_desc);
63 
64 extern int ptrace_set_thread_area(struct task_struct *child, int idx,
65                                   struct user_desc __user *user_desc);
66 
67 extern int arch_switch_tls(struct task_struct *to);
68 
69 #else
70 
71 #define PT_REGS_R8(r) UPT_R8(&(r)->regs)
72 #define PT_REGS_R9(r) UPT_R9(&(r)->regs)
73 #define PT_REGS_R10(r) UPT_R10(&(r)->regs)
74 #define PT_REGS_R11(r) UPT_R11(&(r)->regs)
75 #define PT_REGS_R12(r) UPT_R12(&(r)->regs)
76 #define PT_REGS_R13(r) UPT_R13(&(r)->regs)
77 #define PT_REGS_R14(r) UPT_R14(&(r)->regs)
78 #define PT_REGS_R15(r) UPT_R15(&(r)->regs)
79 
80 #include <asm/errno.h>
81 
ptrace_get_thread_area(struct task_struct * child,int idx,struct user_desc __user * user_desc)82 static inline int ptrace_get_thread_area(struct task_struct *child, int idx,
83                                          struct user_desc __user *user_desc)
84 {
85         return -ENOSYS;
86 }
87 
ptrace_set_thread_area(struct task_struct * child,int idx,struct user_desc __user * user_desc)88 static inline int ptrace_set_thread_area(struct task_struct *child, int idx,
89                                          struct user_desc __user *user_desc)
90 {
91         return -ENOSYS;
92 }
93 
94 extern long arch_prctl(struct task_struct *task, int option,
95 		       unsigned long __user *addr);
96 
97 #endif
98 
99 #define user_stack_pointer(regs) PT_REGS_SP(regs)
100 
101 extern void arch_switch_to(struct task_struct *to);
102 
103 #endif /* __UM_X86_PTRACE_H */
104