xref: /linux/include/uapi/linux/ptrace.h (revision 00c010e130e58301db2ea0cec1eadc931e1cb8cf)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _UAPI_LINUX_PTRACE_H
3 #define _UAPI_LINUX_PTRACE_H
4 /* ptrace.h */
5 /* structs and defines to help the user use the ptrace system call. */
6 
7 /* has the defines to get at the registers. */
8 
9 #include <linux/types.h>
10 
11 #define PTRACE_TRACEME		   0
12 #define PTRACE_PEEKTEXT		   1
13 #define PTRACE_PEEKDATA		   2
14 #define PTRACE_PEEKUSR		   3
15 #define PTRACE_POKETEXT		   4
16 #define PTRACE_POKEDATA		   5
17 #define PTRACE_POKEUSR		   6
18 #define PTRACE_CONT		   7
19 #define PTRACE_KILL		   8
20 #define PTRACE_SINGLESTEP	   9
21 
22 #define PTRACE_ATTACH		  16
23 #define PTRACE_DETACH		  17
24 
25 #define PTRACE_SYSCALL		  24
26 
27 /* 0x4200-0x4300 are reserved for architecture-independent additions.  */
28 #define PTRACE_SETOPTIONS	0x4200
29 #define PTRACE_GETEVENTMSG	0x4201
30 #define PTRACE_GETSIGINFO	0x4202
31 #define PTRACE_SETSIGINFO	0x4203
32 
33 /*
34  * Generic ptrace interface that exports the architecture specific regsets
35  * using the corresponding NT_* types (which are also used in the core dump).
36  * Please note that the NT_PRSTATUS note type in a core dump contains a full
37  * 'struct elf_prstatus'. But the user_regset for NT_PRSTATUS contains just the
38  * elf_gregset_t that is the pr_reg field of 'struct elf_prstatus'. For all the
39  * other user_regset flavors, the user_regset layout and the ELF core dump note
40  * payload are exactly the same layout.
41  *
42  * This interface usage is as follows:
43  *	struct iovec iov = { buf, len};
44  *
45  *	ret = ptrace(PTRACE_GETREGSET/PTRACE_SETREGSET, pid, NT_XXX_TYPE, &iov);
46  *
47  * On the successful completion, iov.len will be updated by the kernel,
48  * specifying how much the kernel has written/read to/from the user's iov.buf.
49  */
50 #define PTRACE_GETREGSET	0x4204
51 #define PTRACE_SETREGSET	0x4205
52 
53 #define PTRACE_SEIZE		0x4206
54 #define PTRACE_INTERRUPT	0x4207
55 #define PTRACE_LISTEN		0x4208
56 
57 #define PTRACE_PEEKSIGINFO	0x4209
58 
59 struct ptrace_peeksiginfo_args {
60 	__u64 off;	/* from which siginfo to start */
61 	__u32 flags;
62 	__s32 nr;	/* how may siginfos to take */
63 };
64 
65 #define PTRACE_GETSIGMASK	0x420a
66 #define PTRACE_SETSIGMASK	0x420b
67 
68 #define PTRACE_SECCOMP_GET_FILTER	0x420c
69 #define PTRACE_SECCOMP_GET_METADATA	0x420d
70 
71 struct seccomp_metadata {
72 	__u64 filter_off;	/* Input: which filter */
73 	__u64 flags;		/* Output: filter's flags */
74 };
75 
76 #define PTRACE_GET_SYSCALL_INFO		0x420e
77 #define PTRACE_SET_SYSCALL_INFO		0x4212
78 #define PTRACE_SYSCALL_INFO_NONE	0
79 #define PTRACE_SYSCALL_INFO_ENTRY	1
80 #define PTRACE_SYSCALL_INFO_EXIT	2
81 #define PTRACE_SYSCALL_INFO_SECCOMP	3
82 
83 struct ptrace_syscall_info {
84 	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
85 	__u8 reserved;
86 	__u16 flags;
87 	__u32 arch;
88 	__u64 instruction_pointer;
89 	__u64 stack_pointer;
90 	union {
91 		struct {
92 			__u64 nr;
93 			__u64 args[6];
94 		} entry;
95 		struct {
96 			__s64 rval;
97 			__u8 is_error;
98 		} exit;
99 		struct {
100 			__u64 nr;
101 			__u64 args[6];
102 			__u32 ret_data;
103 			__u32 reserved2;
104 		} seccomp;
105 	};
106 };
107 
108 #define PTRACE_GET_RSEQ_CONFIGURATION	0x420f
109 
110 struct ptrace_rseq_configuration {
111 	__u64 rseq_abi_pointer;
112 	__u32 rseq_abi_size;
113 	__u32 signature;
114 	__u32 flags;
115 	__u32 pad;
116 };
117 
118 #define PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG 0x4210
119 #define PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG 0x4211
120 
121 /*
122  * struct ptrace_sud_config - Per-task configuration for Syscall User Dispatch
123  * @mode:	One of PR_SYS_DISPATCH_ON or PR_SYS_DISPATCH_OFF
124  * @selector:	Tracees user virtual address of SUD selector
125  * @offset:	SUD exclusion area (virtual address)
126  * @len:	Length of SUD exclusion area
127  *
128  * Used to get/set the syscall user dispatch configuration for a tracee.
129  * Selector is optional (may be NULL), and if invalid will produce
130  * a SIGSEGV in the tracee upon first access.
131  *
132  * If mode is PR_SYS_DISPATCH_ON, syscall dispatch will be enabled. If
133  * PR_SYS_DISPATCH_OFF, syscall dispatch will be disabled and all other
134  * parameters must be 0.  The value in *selector (if not null), also determines
135  * whether syscall dispatch will occur.
136  *
137  * The Syscall User Dispatch Exclusion area described by offset/len is the
138  * virtual address space from which syscalls will not produce a user
139  * dispatch.
140  */
141 struct ptrace_sud_config {
142 	__u64 mode;
143 	__u64 selector;
144 	__u64 offset;
145 	__u64 len;
146 };
147 
148 /* 0x4212 is PTRACE_SET_SYSCALL_INFO */
149 
150 /*
151  * These values are stored in task->ptrace_message
152  * by ptrace_stop to describe the current syscall-stop.
153  */
154 #define PTRACE_EVENTMSG_SYSCALL_ENTRY	1
155 #define PTRACE_EVENTMSG_SYSCALL_EXIT	2
156 
157 /* Read signals from a shared (process wide) queue */
158 #define PTRACE_PEEKSIGINFO_SHARED	(1 << 0)
159 
160 /* Wait extended result codes for the above trace options.  */
161 #define PTRACE_EVENT_FORK	1
162 #define PTRACE_EVENT_VFORK	2
163 #define PTRACE_EVENT_CLONE	3
164 #define PTRACE_EVENT_EXEC	4
165 #define PTRACE_EVENT_VFORK_DONE	5
166 #define PTRACE_EVENT_EXIT	6
167 #define PTRACE_EVENT_SECCOMP	7
168 /* Extended result codes which enabled by means other than options.  */
169 #define PTRACE_EVENT_STOP	128
170 
171 /* Options set using PTRACE_SETOPTIONS or using PTRACE_SEIZE @data param */
172 #define PTRACE_O_TRACESYSGOOD	1
173 #define PTRACE_O_TRACEFORK	(1 << PTRACE_EVENT_FORK)
174 #define PTRACE_O_TRACEVFORK	(1 << PTRACE_EVENT_VFORK)
175 #define PTRACE_O_TRACECLONE	(1 << PTRACE_EVENT_CLONE)
176 #define PTRACE_O_TRACEEXEC	(1 << PTRACE_EVENT_EXEC)
177 #define PTRACE_O_TRACEVFORKDONE	(1 << PTRACE_EVENT_VFORK_DONE)
178 #define PTRACE_O_TRACEEXIT	(1 << PTRACE_EVENT_EXIT)
179 #define PTRACE_O_TRACESECCOMP	(1 << PTRACE_EVENT_SECCOMP)
180 
181 /* eventless options */
182 #define PTRACE_O_EXITKILL		(1 << 20)
183 #define PTRACE_O_SUSPEND_SECCOMP	(1 << 21)
184 
185 #define PTRACE_O_MASK		(\
186 	0x000000ff | PTRACE_O_EXITKILL | PTRACE_O_SUSPEND_SECCOMP)
187 
188 #include <asm/ptrace.h>
189 
190 
191 #endif /* _UAPI_LINUX_PTRACE_H */
192