xref: /openbsd/sys/sys/ptrace.h (revision 8fb2af3a)
1 /*	$OpenBSD: ptrace.h,v 1.16 2020/03/16 11:58:46 mpi Exp $	*/
2 /*	$NetBSD: ptrace.h,v 1.21 1996/02/09 18:25:26 christos Exp $	*/
3 
4 /*-
5  * Copyright (c) 1984, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)ptrace.h	8.2 (Berkeley) 1/4/94
33  */
34 
35 #ifndef	_SYS_PTRACE_H_
36 #define	_SYS_PTRACE_H_
37 
38 #define	PT_TRACE_ME	0	/* child declares it's being traced */
39 #define	PT_READ_I	1	/* read word in child's I space */
40 #define	PT_READ_D	2	/* read word in child's D space */
41 #define	PT_WRITE_I	4	/* write word in child's I space */
42 #define	PT_WRITE_D	5	/* write word in child's D space */
43 #define	PT_CONTINUE	7	/* continue the child */
44 #define	PT_KILL		8	/* kill the child process */
45 #define	PT_ATTACH	9	/* attach to running process */
46 #define	PT_DETACH	10	/* detach from running process */
47 #define PT_IO		11	/* do I/O to/from the stopped process. */
48 
49 struct ptrace_io_desc {
50 	int	piod_op;	/* I/O operation */
51 	void	*piod_offs;	/* child offset */
52 	void	*piod_addr;	/* parent offset */
53 	size_t	piod_len;	/* request length */
54 };
55 
56 /*
57  * Operations in piod_op.
58  */
59 #define PIOD_READ_D	1	/* Read from D space */
60 #define PIOD_WRITE_D	2	/* Write to D space */
61 #define PIOD_READ_I	3	/* Read from I space */
62 #define PIOD_WRITE_I	4	/* Write to I space */
63 #define PIOD_READ_AUXV	5	/* Read from aux array */
64 
65 #define PT_SET_EVENT_MASK	12
66 #define PT_GET_EVENT_MASK	13
67 
68 typedef struct ptrace_event {
69 	int	pe_set_event;
70 } ptrace_event_t;
71 
72 #define PTRACE_FORK	0x0002	/* Report forks */
73 
74 #define PT_GET_PROCESS_STATE	14
75 
76 typedef struct ptrace_state {
77 	int	pe_report_event;
78 	pid_t	pe_other_pid;
79 	pid_t	pe_tid;
80 } ptrace_state_t;
81 
82 #define PT_GET_THREAD_FIRST	15
83 #define PT_GET_THREAD_NEXT	16
84 
85 struct ptrace_thread_state {
86 	pid_t	pts_tid;
87 };
88 
89 #define	PT_FIRSTMACH	32	/* for machine-specific requests */
90 #include <machine/ptrace.h>	/* machine-specific requests, if any */
91 
92 #ifdef _KERNEL
93 
94 /*
95  * There is a bunch of PT_ requests that are machine dependent, but not
96  * optional. Check if they were defined by MD code here.
97  */
98 #if !defined(PT_GETREGS) || !defined(PT_SETREGS)
99 #error Machine dependent ptrace not complete.
100 #endif
101 
102 struct reg;
103 #if defined(PT_GETFPREGS) || defined(PT_SETFPREGS)
104 struct fpreg;
105 #endif
106 
107 void	process_reparent(struct process *_child, struct process *_newparent);
108 void	process_untrace(struct process *_tr);
109 #ifdef PT_GETFPREGS
110 int	process_read_fpregs(struct proc *_t, struct fpreg *);
111 #endif
112 int	process_read_regs(struct proc *_t, struct reg *);
113 int	process_set_pc(struct proc *_t, caddr_t _addr);
114 int	process_sstep(struct proc *_t, int _sstep);
115 #ifdef PT_SETFPREGS
116 int	process_write_fpregs(struct proc *_t, struct fpreg *);
117 #endif
118 int	process_write_regs(struct proc *_t, struct reg *);
119 int	process_checkioperm(struct proc *_curp, struct process *_tr);
120 int	process_domem(struct proc *_curp, struct process *_tr, struct uio *,
121 	    int _req);
122 
123 #ifndef FIX_SSTEP
124 #define FIX_SSTEP(p)
125 #endif
126 
127 #else /* !_KERNEL */
128 
129 #include <sys/cdefs.h>
130 
131 __BEGIN_DECLS
132 int	ptrace(int _request, pid_t _pid, caddr_t _addr, int _data);
133 __END_DECLS
134 
135 #endif /* !_KERNEL */
136 
137 #endif	/* !_SYS_PTRACE_H_ */
138