xref: /linux/include/uapi/linux/ptrace.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells #ifndef _UAPI_LINUX_PTRACE_H
3607ca46eSDavid Howells #define _UAPI_LINUX_PTRACE_H
4607ca46eSDavid Howells /* ptrace.h */
5607ca46eSDavid Howells /* structs and defines to help the user use the ptrace system call. */
6607ca46eSDavid Howells 
7607ca46eSDavid Howells /* has the defines to get at the registers. */
8607ca46eSDavid Howells 
984c751bdSAndrey Vagin #include <linux/types.h>
10607ca46eSDavid Howells 
11607ca46eSDavid Howells #define PTRACE_TRACEME		   0
12607ca46eSDavid Howells #define PTRACE_PEEKTEXT		   1
13607ca46eSDavid Howells #define PTRACE_PEEKDATA		   2
14607ca46eSDavid Howells #define PTRACE_PEEKUSR		   3
15607ca46eSDavid Howells #define PTRACE_POKETEXT		   4
16607ca46eSDavid Howells #define PTRACE_POKEDATA		   5
17607ca46eSDavid Howells #define PTRACE_POKEUSR		   6
18607ca46eSDavid Howells #define PTRACE_CONT		   7
19607ca46eSDavid Howells #define PTRACE_KILL		   8
20607ca46eSDavid Howells #define PTRACE_SINGLESTEP	   9
21607ca46eSDavid Howells 
22607ca46eSDavid Howells #define PTRACE_ATTACH		  16
23607ca46eSDavid Howells #define PTRACE_DETACH		  17
24607ca46eSDavid Howells 
25607ca46eSDavid Howells #define PTRACE_SYSCALL		  24
26607ca46eSDavid Howells 
27607ca46eSDavid Howells /* 0x4200-0x4300 are reserved for architecture-independent additions.  */
28607ca46eSDavid Howells #define PTRACE_SETOPTIONS	0x4200
29607ca46eSDavid Howells #define PTRACE_GETEVENTMSG	0x4201
30607ca46eSDavid Howells #define PTRACE_GETSIGINFO	0x4202
31607ca46eSDavid Howells #define PTRACE_SETSIGINFO	0x4203
32607ca46eSDavid Howells 
33607ca46eSDavid Howells /*
34607ca46eSDavid Howells  * Generic ptrace interface that exports the architecture specific regsets
35607ca46eSDavid Howells  * using the corresponding NT_* types (which are also used in the core dump).
36607ca46eSDavid Howells  * Please note that the NT_PRSTATUS note type in a core dump contains a full
37607ca46eSDavid Howells  * 'struct elf_prstatus'. But the user_regset for NT_PRSTATUS contains just the
38607ca46eSDavid Howells  * elf_gregset_t that is the pr_reg field of 'struct elf_prstatus'. For all the
39607ca46eSDavid Howells  * other user_regset flavors, the user_regset layout and the ELF core dump note
40607ca46eSDavid Howells  * payload are exactly the same layout.
41607ca46eSDavid Howells  *
42607ca46eSDavid Howells  * This interface usage is as follows:
43607ca46eSDavid Howells  *	struct iovec iov = { buf, len};
44607ca46eSDavid Howells  *
45607ca46eSDavid Howells  *	ret = ptrace(PTRACE_GETREGSET/PTRACE_SETREGSET, pid, NT_XXX_TYPE, &iov);
46607ca46eSDavid Howells  *
47607ca46eSDavid Howells  * On the successful completion, iov.len will be updated by the kernel,
48607ca46eSDavid Howells  * specifying how much the kernel has written/read to/from the user's iov.buf.
49607ca46eSDavid Howells  */
50607ca46eSDavid Howells #define PTRACE_GETREGSET	0x4204
51607ca46eSDavid Howells #define PTRACE_SETREGSET	0x4205
52607ca46eSDavid Howells 
53607ca46eSDavid Howells #define PTRACE_SEIZE		0x4206
54607ca46eSDavid Howells #define PTRACE_INTERRUPT	0x4207
55607ca46eSDavid Howells #define PTRACE_LISTEN		0x4208
56607ca46eSDavid Howells 
5784c751bdSAndrey Vagin #define PTRACE_PEEKSIGINFO	0x4209
5884c751bdSAndrey Vagin 
5984c751bdSAndrey Vagin struct ptrace_peeksiginfo_args {
6084c751bdSAndrey Vagin 	__u64 off;	/* from which siginfo to start */
6184c751bdSAndrey Vagin 	__u32 flags;
6284c751bdSAndrey Vagin 	__s32 nr;	/* how may siginfos to take */
6384c751bdSAndrey Vagin };
6484c751bdSAndrey Vagin 
6529000caeSAndrey Vagin #define PTRACE_GETSIGMASK	0x420a
6629000caeSAndrey Vagin #define PTRACE_SETSIGMASK	0x420b
6729000caeSAndrey Vagin 
68f8e529edSTycho Andersen #define PTRACE_SECCOMP_GET_FILTER	0x420c
6926500475STycho Andersen #define PTRACE_SECCOMP_GET_METADATA	0x420d
7026500475STycho Andersen 
7126500475STycho Andersen struct seccomp_metadata {
722a040f9fSTycho Andersen 	__u64 filter_off;	/* Input: which filter */
732a040f9fSTycho Andersen 	__u64 flags;		/* Output: filter's flags */
7426500475STycho Andersen };
75f8e529edSTycho Andersen 
76201766a2SElvira Khabirova #define PTRACE_GET_SYSCALL_INFO		0x420e
77201766a2SElvira Khabirova #define PTRACE_SYSCALL_INFO_NONE	0
78201766a2SElvira Khabirova #define PTRACE_SYSCALL_INFO_ENTRY	1
79201766a2SElvira Khabirova #define PTRACE_SYSCALL_INFO_EXIT	2
80201766a2SElvira Khabirova #define PTRACE_SYSCALL_INFO_SECCOMP	3
81201766a2SElvira Khabirova 
82201766a2SElvira Khabirova struct ptrace_syscall_info {
83201766a2SElvira Khabirova 	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
840032ce0fSPeilin Ye 	__u8 pad[3];
850032ce0fSPeilin Ye 	__u32 arch;
86201766a2SElvira Khabirova 	__u64 instruction_pointer;
87201766a2SElvira Khabirova 	__u64 stack_pointer;
88201766a2SElvira Khabirova 	union {
89201766a2SElvira Khabirova 		struct {
90201766a2SElvira Khabirova 			__u64 nr;
91201766a2SElvira Khabirova 			__u64 args[6];
92201766a2SElvira Khabirova 		} entry;
93201766a2SElvira Khabirova 		struct {
94201766a2SElvira Khabirova 			__s64 rval;
95201766a2SElvira Khabirova 			__u8 is_error;
96201766a2SElvira Khabirova 		} exit;
97201766a2SElvira Khabirova 		struct {
98201766a2SElvira Khabirova 			__u64 nr;
99201766a2SElvira Khabirova 			__u64 args[6];
100201766a2SElvira Khabirova 			__u32 ret_data;
101201766a2SElvira Khabirova 		} seccomp;
102201766a2SElvira Khabirova 	};
103201766a2SElvira Khabirova };
104201766a2SElvira Khabirova 
10590f093faSPiotr Figiel #define PTRACE_GET_RSEQ_CONFIGURATION	0x420f
10690f093faSPiotr Figiel 
10790f093faSPiotr Figiel struct ptrace_rseq_configuration {
10890f093faSPiotr Figiel 	__u64 rseq_abi_pointer;
10990f093faSPiotr Figiel 	__u32 rseq_abi_size;
11090f093faSPiotr Figiel 	__u32 signature;
11190f093faSPiotr Figiel 	__u32 flags;
11290f093faSPiotr Figiel 	__u32 pad;
11390f093faSPiotr Figiel };
11490f093faSPiotr Figiel 
115*3f67987cSGregory Price #define PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG 0x4210
116*3f67987cSGregory Price #define PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG 0x4211
117*3f67987cSGregory Price 
118*3f67987cSGregory Price /*
119*3f67987cSGregory Price  * struct ptrace_sud_config - Per-task configuration for Syscall User Dispatch
120*3f67987cSGregory Price  * @mode:	One of PR_SYS_DISPATCH_ON or PR_SYS_DISPATCH_OFF
121*3f67987cSGregory Price  * @selector:	Tracees user virtual address of SUD selector
122*3f67987cSGregory Price  * @offset:	SUD exclusion area (virtual address)
123*3f67987cSGregory Price  * @len:	Length of SUD exclusion area
124*3f67987cSGregory Price  *
125*3f67987cSGregory Price  * Used to get/set the syscall user dispatch configuration for a tracee.
126*3f67987cSGregory Price  * Selector is optional (may be NULL), and if invalid will produce
127*3f67987cSGregory Price  * a SIGSEGV in the tracee upon first access.
128*3f67987cSGregory Price  *
129*3f67987cSGregory Price  * If mode is PR_SYS_DISPATCH_ON, syscall dispatch will be enabled. If
130*3f67987cSGregory Price  * PR_SYS_DISPATCH_OFF, syscall dispatch will be disabled and all other
131*3f67987cSGregory Price  * parameters must be 0.  The value in *selector (if not null), also determines
132*3f67987cSGregory Price  * whether syscall dispatch will occur.
133*3f67987cSGregory Price  *
134*3f67987cSGregory Price  * The Syscall User Dispatch Exclusion area described by offset/len is the
135*3f67987cSGregory Price  * virtual address space from which syscalls will not produce a user
136*3f67987cSGregory Price  * dispatch.
137*3f67987cSGregory Price  */
138*3f67987cSGregory Price struct ptrace_sud_config {
139*3f67987cSGregory Price 	__u64 mode;
140*3f67987cSGregory Price 	__u64 selector;
141*3f67987cSGregory Price 	__u64 offset;
142*3f67987cSGregory Price 	__u64 len;
143*3f67987cSGregory Price };
144*3f67987cSGregory Price 
145201766a2SElvira Khabirova /*
146201766a2SElvira Khabirova  * These values are stored in task->ptrace_message
147336d4b81SEric W. Biederman  * by ptrace_stop to describe the current syscall-stop.
148201766a2SElvira Khabirova  */
149201766a2SElvira Khabirova #define PTRACE_EVENTMSG_SYSCALL_ENTRY	1
150201766a2SElvira Khabirova #define PTRACE_EVENTMSG_SYSCALL_EXIT	2
151201766a2SElvira Khabirova 
15284c751bdSAndrey Vagin /* Read signals from a shared (process wide) queue */
15384c751bdSAndrey Vagin #define PTRACE_PEEKSIGINFO_SHARED	(1 << 0)
15484c751bdSAndrey Vagin 
155607ca46eSDavid Howells /* Wait extended result codes for the above trace options.  */
156607ca46eSDavid Howells #define PTRACE_EVENT_FORK	1
157607ca46eSDavid Howells #define PTRACE_EVENT_VFORK	2
158607ca46eSDavid Howells #define PTRACE_EVENT_CLONE	3
159607ca46eSDavid Howells #define PTRACE_EVENT_EXEC	4
160607ca46eSDavid Howells #define PTRACE_EVENT_VFORK_DONE	5
161607ca46eSDavid Howells #define PTRACE_EVENT_EXIT	6
162607ca46eSDavid Howells #define PTRACE_EVENT_SECCOMP	7
163607ca46eSDavid Howells /* Extended result codes which enabled by means other than options.  */
164607ca46eSDavid Howells #define PTRACE_EVENT_STOP	128
165607ca46eSDavid Howells 
166607ca46eSDavid Howells /* Options set using PTRACE_SETOPTIONS or using PTRACE_SEIZE @data param */
167607ca46eSDavid Howells #define PTRACE_O_TRACESYSGOOD	1
168607ca46eSDavid Howells #define PTRACE_O_TRACEFORK	(1 << PTRACE_EVENT_FORK)
169607ca46eSDavid Howells #define PTRACE_O_TRACEVFORK	(1 << PTRACE_EVENT_VFORK)
170607ca46eSDavid Howells #define PTRACE_O_TRACECLONE	(1 << PTRACE_EVENT_CLONE)
171607ca46eSDavid Howells #define PTRACE_O_TRACEEXEC	(1 << PTRACE_EVENT_EXEC)
172607ca46eSDavid Howells #define PTRACE_O_TRACEVFORKDONE	(1 << PTRACE_EVENT_VFORK_DONE)
173607ca46eSDavid Howells #define PTRACE_O_TRACEEXIT	(1 << PTRACE_EVENT_EXIT)
174607ca46eSDavid Howells #define PTRACE_O_TRACESECCOMP	(1 << PTRACE_EVENT_SECCOMP)
175607ca46eSDavid Howells 
176992fb6e1SOleg Nesterov /* eventless options */
177992fb6e1SOleg Nesterov #define PTRACE_O_EXITKILL		(1 << 20)
17813c4a901STycho Andersen #define PTRACE_O_SUSPEND_SECCOMP	(1 << 21)
179992fb6e1SOleg Nesterov 
18013c4a901STycho Andersen #define PTRACE_O_MASK		(\
18113c4a901STycho Andersen 	0x000000ff | PTRACE_O_EXITKILL | PTRACE_O_SUSPEND_SECCOMP)
182607ca46eSDavid Howells 
183607ca46eSDavid Howells #include <asm/ptrace.h>
184607ca46eSDavid Howells 
185607ca46eSDavid Howells 
186607ca46eSDavid Howells #endif /* _UAPI_LINUX_PTRACE_H */
187