| 1 | /*	$OpenBSD: ptrace.h,v 1.17 2025/12/11 14:13:18 kurt 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 | #define PT_PTS_NAMELEN	32 |
| 86 | |
| 87 | struct ptrace_thread_state { |
| 88 | 	pid_t	pts_tid; |
| 89 | 	char	pts_name[PT_PTS_NAMELEN]; |
| 90 | }; |
| 91 | |
| 92 | #define	PT_FIRSTMACH	32	/* for machine-specific requests */ |
| 93 | #include <machine/ptrace.h>	/* machine-specific requests, if any */ |
| 94 | |
| 95 | #ifdef _KERNEL |
| 96 | |
| 97 | /* |
| 98 | * There is a bunch of PT_ requests that are machine dependent, but not |
| 99 | * optional. Check if they were defined by MD code here. |
| 100 | */ |
| 101 | #if !defined(PT_GETREGS) || !defined(PT_SETREGS) |
| 102 | #error Machine dependent ptrace not complete. |
| 103 | #endif |
| 104 | |
| 105 | struct reg; |
| 106 | #if defined(PT_GETFPREGS) || defined(PT_SETFPREGS) |
| 107 | struct fpreg; |
| 108 | #endif |
| 109 | |
| 110 | void	process_reparent(struct process *_child, struct process *_newparent); |
| 111 | void	process_untrace(struct process *_tr); |
| 112 | #ifdef PT_GETFPREGS |
| 113 | int	process_read_fpregs(struct proc *_t, struct fpreg *); |
| 114 | #endif |
| 115 | int	process_read_regs(struct proc *_t, struct reg *); |
| 116 | int	process_set_pc(struct proc *_t, caddr_t _addr); |
| 117 | int	process_sstep(struct proc *_t, int _sstep); |
| 118 | #ifdef PT_SETFPREGS |
| 119 | int	process_write_fpregs(struct proc *_t, struct fpreg *); |
| 120 | #endif |
| 121 | int	process_write_regs(struct proc *_t, struct reg *); |
| 122 | int	process_checkioperm(struct proc *_curp, struct process *_tr); |
| 123 | int	process_domem(struct proc *_curp, struct process *_tr, struct uio *, |
| 124 | 	 int _req); |
| 125 | |
| 126 | #ifndef FIX_SSTEP |
| 127 | #define FIX_SSTEP(p) |
| 128 | #endif |
| 129 | |
| 130 | #else /* !_KERNEL */ |
| 131 | |
| 132 | #include <sys/cdefs.h> |
| 133 | |
| 134 | __BEGIN_DECLS |
| 135 | int	ptrace(int _request, pid_t _pid, caddr_t _addr, int _data); |
| 136 | __END_DECLS |
| 137 | |
| 138 | #endif /* !_KERNEL */ |
| 139 | |
| 140 | #endif	/* !_SYS_PTRACE_H_ */ |