]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/ptrace.h
libarchive: import changes from upstream
[FreeBSD/FreeBSD.git] / sys / sys / ptrace.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1984, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *      @(#)ptrace.h    8.2 (Berkeley) 1/4/94
32  * $FreeBSD$
33  */
34
35 #ifndef _SYS_PTRACE_H_
36 #define _SYS_PTRACE_H_
37
38 #include <sys/signal.h>
39 #include <sys/param.h>
40 #include <machine/reg.h>
41
42 #define PT_TRACE_ME     0       /* child declares it's being traced */
43 #define PT_READ_I       1       /* read word in child's I space */
44 #define PT_READ_D       2       /* read word in child's D space */
45 /* was  PT_READ_U       3        * read word in child's user structure */
46 #define PT_WRITE_I      4       /* write word in child's I space */
47 #define PT_WRITE_D      5       /* write word in child's D space */
48 /* was  PT_WRITE_U      6        * write word in child's user structure */
49 #define PT_CONTINUE     7       /* continue the child */
50 #define PT_KILL         8       /* kill the child process */
51 #define PT_STEP         9       /* single step the child */
52
53 #define PT_ATTACH       10      /* trace some running process */
54 #define PT_DETACH       11      /* stop tracing a process */
55 #define PT_IO           12      /* do I/O to/from stopped process. */
56 #define PT_LWPINFO      13      /* Info about the LWP that stopped. */
57 #define PT_GETNUMLWPS   14      /* get total number of threads */
58 #define PT_GETLWPLIST   15      /* get thread list */
59 #define PT_CLEARSTEP    16      /* turn off single step */
60 #define PT_SETSTEP      17      /* turn on single step */
61 #define PT_SUSPEND      18      /* suspend a thread */
62 #define PT_RESUME       19      /* resume a thread */
63
64 #define PT_TO_SCE       20
65 #define PT_TO_SCX       21
66 #define PT_SYSCALL      22
67
68 #define PT_FOLLOW_FORK  23
69 #define PT_LWP_EVENTS   24      /* report LWP birth and exit */
70
71 #define PT_GET_EVENT_MASK 25    /* get mask of optional events */
72 #define PT_SET_EVENT_MASK 26    /* set mask of optional events */
73
74 #define PT_GET_SC_ARGS  27      /* fetch syscall args */
75 #define PT_GET_SC_RET   28      /* fetch syscall results */
76
77 #define PT_COREDUMP     29      /* create a coredump */
78
79 #define PT_GETREGS      33      /* get general-purpose registers */
80 #define PT_SETREGS      34      /* set general-purpose registers */
81 #define PT_GETFPREGS    35      /* get floating-point registers */
82 #define PT_SETFPREGS    36      /* set floating-point registers */
83 #define PT_GETDBREGS    37      /* get debugging registers */
84 #define PT_SETDBREGS    38      /* set debugging registers */
85
86 #define PT_VM_TIMESTAMP 40      /* Get VM version (timestamp) */
87 #define PT_VM_ENTRY     41      /* Get VM map (entry) */
88 #define PT_GETREGSET    42      /* Get a target register set */
89 #define PT_SETREGSET    43      /* Set a target register set */
90
91 #define PT_FIRSTMACH    64      /* for machine-specific requests */
92 #include <machine/ptrace.h>     /* machine-specific requests, if any */
93
94 /* Events used with PT_GET_EVENT_MASK and PT_SET_EVENT_MASK */
95 #define PTRACE_EXEC     0x0001
96 #define PTRACE_SCE      0x0002
97 #define PTRACE_SCX      0x0004
98 #define PTRACE_SYSCALL  (PTRACE_SCE | PTRACE_SCX)
99 #define PTRACE_FORK     0x0008
100 #define PTRACE_LWP      0x0010
101 #define PTRACE_VFORK    0x0020
102
103 #define PTRACE_DEFAULT  (PTRACE_EXEC)
104
105 struct ptrace_io_desc {
106         int     piod_op;        /* I/O operation */
107         void    *piod_offs;     /* child offset */
108         void    *piod_addr;     /* parent offset */
109         size_t  piod_len;       /* request length */
110 };
111
112 /*
113  * Operations in piod_op.
114  */
115 #define PIOD_READ_D     1       /* Read from D space */
116 #define PIOD_WRITE_D    2       /* Write to D space */
117 #define PIOD_READ_I     3       /* Read from I space */
118 #define PIOD_WRITE_I    4       /* Write to I space */
119
120 /* Argument structure for PT_LWPINFO. */
121 struct ptrace_lwpinfo {
122         lwpid_t pl_lwpid;       /* LWP described. */
123         int     pl_event;       /* Event that stopped the LWP. */
124 #define PL_EVENT_NONE   0
125 #define PL_EVENT_SIGNAL 1
126         int     pl_flags;       /* LWP flags. */
127 #define PL_FLAG_SA      0x01    /* M:N thread */
128 #define PL_FLAG_BOUND   0x02    /* M:N bound thread */
129 #define PL_FLAG_SCE     0x04    /* syscall enter point */
130 #define PL_FLAG_SCX     0x08    /* syscall leave point */
131 #define PL_FLAG_EXEC    0x10    /* exec(2) succeeded */
132 #define PL_FLAG_SI      0x20    /* siginfo is valid */
133 #define PL_FLAG_FORKED  0x40    /* new child */
134 #define PL_FLAG_CHILD   0x80    /* I am from child */
135 #define PL_FLAG_BORN    0x100   /* new LWP */
136 #define PL_FLAG_EXITED  0x200   /* exiting LWP */
137 #define PL_FLAG_VFORKED 0x400   /* new child via vfork */
138 #define PL_FLAG_VFORK_DONE 0x800 /* vfork parent has resumed */
139         sigset_t        pl_sigmask;     /* LWP signal mask */
140         sigset_t        pl_siglist;     /* LWP pending signal */
141         struct __siginfo pl_siginfo;    /* siginfo for signal */
142         char            pl_tdname[MAXCOMLEN + 1]; /* LWP name */
143         pid_t           pl_child_pid;   /* New child pid */
144         u_int           pl_syscall_code;
145         u_int           pl_syscall_narg;
146 };
147
148 #if defined(_WANT_LWPINFO32) || (defined(_KERNEL) && defined(__LP64__))
149 struct ptrace_lwpinfo32 {
150         lwpid_t pl_lwpid;       /* LWP described. */
151         int     pl_event;       /* Event that stopped the LWP. */
152         int     pl_flags;       /* LWP flags. */
153         sigset_t        pl_sigmask;     /* LWP signal mask */
154         sigset_t        pl_siglist;     /* LWP pending signal */
155         struct siginfo32 pl_siginfo;    /* siginfo for signal */
156         char            pl_tdname[MAXCOMLEN + 1]; /* LWP name. */
157         pid_t           pl_child_pid;   /* New child pid */
158         u_int           pl_syscall_code;
159         u_int           pl_syscall_narg;
160 };
161 #endif
162
163 /* Argument structure for PT_GET_SC_RET. */
164 struct ptrace_sc_ret {
165         register_t      sr_retval[2];   /* Only valid if sr_error == 0. */
166         int             sr_error;
167 };
168
169 /* Argument structure for PT_VM_ENTRY. */
170 struct ptrace_vm_entry {
171         int             pve_entry;      /* Entry number used for iteration. */
172         int             pve_timestamp;  /* Generation number of VM map. */
173         u_long          pve_start;      /* Start VA of range. */
174         u_long          pve_end;        /* End VA of range (incl). */
175         u_long          pve_offset;     /* Offset in backing object. */
176         u_int           pve_prot;       /* Protection of memory range. */
177         u_int           pve_pathlen;    /* Size of path. */
178         long            pve_fileid;     /* File ID. */
179         uint32_t        pve_fsid;       /* File system ID. */
180         char            *pve_path;      /* Path name of object. */
181 };
182
183 /* Argument structure for PT_COREDUMP */
184 struct ptrace_coredump {
185         int             pc_fd;          /* File descriptor to write dump to. */
186         uint32_t        pc_flags;       /* Flags PC_* */
187         off_t           pc_limit;       /* Maximum size of the coredump,
188                                            0 for no limit. */
189 };
190
191 /* Flags for PT_COREDUMP pc_flags */
192 #define PC_COMPRESS     0x00000001      /* Allow compression */
193 #define PC_ALL          0x00000002      /* Include non-dumpable entries */
194
195 #ifdef _KERNEL
196
197 struct thr_coredump_req {
198         struct vnode    *tc_vp;         /* vnode to write coredump to. */
199         off_t           tc_limit;       /* max coredump file size. */
200         int             tc_flags;       /* user flags */
201         int             tc_error;       /* request result */
202 };
203
204 int     ptrace_set_pc(struct thread *_td, unsigned long _addr);
205 int     ptrace_single_step(struct thread *_td);
206 int     ptrace_clear_single_step(struct thread *_td);
207
208 #ifdef __HAVE_PTRACE_MACHDEP
209 int     cpu_ptrace(struct thread *_td, int _req, void *_addr, int _data);
210 #endif
211
212 /*
213  * These are prototypes for functions that implement some of the
214  * debugging functionality exported by procfs / linprocfs and by the
215  * ptrace(2) syscall.  They used to be part of procfs, but they don't
216  * really belong there.
217  */
218 struct reg;
219 struct fpreg;
220 struct dbreg;
221 struct uio;
222 int     proc_read_regs(struct thread *_td, struct reg *_reg);
223 int     proc_write_regs(struct thread *_td, struct reg *_reg);
224 int     proc_read_fpregs(struct thread *_td, struct fpreg *_fpreg);
225 int     proc_write_fpregs(struct thread *_td, struct fpreg *_fpreg);
226 int     proc_read_dbregs(struct thread *_td, struct dbreg *_dbreg);
227 int     proc_write_dbregs(struct thread *_td, struct dbreg *_dbreg);
228 int     proc_sstep(struct thread *_td);
229 int     proc_rwmem(struct proc *_p, struct uio *_uio);
230 ssize_t proc_readmem(struct thread *_td, struct proc *_p, vm_offset_t _va,
231             void *_buf, size_t _len);
232 ssize_t proc_writemem(struct thread *_td, struct proc *_p, vm_offset_t _va,
233             void *_buf, size_t _len);
234 #ifdef COMPAT_FREEBSD32
235 struct reg32;
236 struct fpreg32;
237 struct dbreg32;
238 int     proc_read_regs32(struct thread *_td, struct reg32 *_reg32);
239 int     proc_write_regs32(struct thread *_td, struct reg32 *_reg32);
240 int     proc_read_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32);
241 int     proc_write_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32);
242 int     proc_read_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32);
243 int     proc_write_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32);
244 #endif
245
246 void    ptrace_unsuspend(struct proc *p);
247
248 extern bool allow_ptrace;
249
250 #else /* !_KERNEL */
251
252 #include <sys/cdefs.h>
253
254 __BEGIN_DECLS
255 int     ptrace(int _request, pid_t _pid, caddr_t _addr, int _data);
256 __END_DECLS
257
258 #endif /* !_KERNEL */
259
260 #endif  /* !_SYS_PTRACE_H_ */