| 1 | /* $NetBSD: ptrace.h,v 1.49 2016/11/04 18:14:04 christos Exp $ */ |
| 2 | |
| 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 | */ |
| 33 | |
| 34 | #ifndef _SYS_PTRACE_H_ |
| 35 | #define _SYS_PTRACE_H_ |
| 36 | |
| 37 | #define PT_TRACE_ME 0 /* child declares it's being traced */ |
| 38 | #define PT_READ_I 1 /* read word in child's I space */ |
| 39 | #define PT_READ_D 2 /* read word in child's D space */ |
| 40 | #define PT_WRITE_I 4 /* write word in child's I space */ |
| 41 | #define PT_WRITE_D 5 /* write word in child's D space */ |
| 42 | #define PT_CONTINUE 7 /* continue the child */ |
| 43 | #define PT_KILL 8 /* kill the child process */ |
| 44 | #define PT_ATTACH 9 /* attach to running process */ |
| 45 | #define PT_DETACH 10 /* detach from running process */ |
| 46 | #define PT_IO 11 /* do I/O to/from the stopped process */ |
| 47 | #define PT_DUMPCORE 12 /* make child generate a core dump */ |
| 48 | #define PT_LWPINFO 13 /* get info about the LWP */ |
| 49 | #define PT_SYSCALL 14 /* stop on syscall entry/exit */ |
| 50 | #define PT_SYSCALLEMU 15 /* cancel syscall, tracer emulates it */ |
| 51 | #define PT_SET_EVENT_MASK 16 /* set the event mask, defined below */ |
| 52 | #define PT_GET_EVENT_MASK 17 /* get the event mask, defined below */ |
| 53 | #define PT_GET_PROCESS_STATE 18 /* get process state, defined below */ |
| 54 | |
| 55 | #define PT_FIRSTMACH 32 /* for machine-specific requests */ |
| 56 | #include <machine/ptrace.h> /* machine-specific requests, if any */ |
| 57 | |
| 58 | #define PT_STRINGS \ |
| 59 | /* 0 */ "PT_TRACE_ME", \ |
| 60 | /* 1 */ "PT_READ_I", \ |
| 61 | /* 2 */ "PT_READ_D", \ |
| 62 | /* 3 */ "*PT_INVALID_3*", \ |
| 63 | /* 4 */ "PT_WRITE_I", \ |
| 64 | /* 5 */ "PT_WRITE_D", \ |
| 65 | /* 6 */ "*PT_INVALID_6*", \ |
| 66 | /* 7 */ "PT_CONTINUE", \ |
| 67 | /* 8 */ "PT_KILL", \ |
| 68 | /* 9 */ "PT_ATTACH", \ |
| 69 | /* 10 */ "PT_DETACH", \ |
| 70 | /* 11 */ "PT_IO", \ |
| 71 | /* 12 */ "PT_DUMPCORE", \ |
| 72 | /* 13 */ "PT_LWPINFO", \ |
| 73 | /* 14 */ "PT_SYSCALL", \ |
| 74 | /* 15 */ "PT_SYSCALLEMU", \ |
| 75 | /* 16 */ "PT_SET_EVENT_MASK", \ |
| 76 | /* 17 */ "PT_GET_EVENT_MASK", \ |
| 77 | /* 18 */ "PT_GET_PROCESS_STATE", |
| 78 | |
| 79 | /* PT_{G,S}EVENT_MASK */ |
| 80 | typedef struct ptrace_event { |
| 81 | int pe_set_event; |
| 82 | } ptrace_event_t; |
| 83 | |
| 84 | /* PT_GET_PROCESS_STATE */ |
| 85 | typedef struct ptrace_state { |
| 86 | int pe_report_event; |
| 87 | pid_t pe_other_pid; |
| 88 | } ptrace_state_t; |
| 89 | |
| 90 | #define PTRACE_FORK 0x0001 /* Report forks */ |
| 91 | |
| 92 | /* |
| 93 | * Argument structure for PT_IO. |
| 94 | */ |
| 95 | struct ptrace_io_desc { |
| 96 | int piod_op; /* I/O operation (see below) */ |
| 97 | void *piod_offs; /* child offset */ |
| 98 | void *piod_addr; /* parent offset */ |
| 99 | size_t piod_len; /* request length (in)/actual count (out) */ |
| 100 | }; |
| 101 | |
| 102 | /* piod_op */ |
| 103 | #define PIOD_READ_D 1 /* read from D space */ |
| 104 | #define PIOD_WRITE_D 2 /* write to D spcae */ |
| 105 | #define PIOD_READ_I 3 /* read from I space */ |
| 106 | #define PIOD_WRITE_I 4 /* write to I space */ |
| 107 | #define PIOD_READ_AUXV 5 /* Read from aux array */ |
| 108 | |
| 109 | /* |
| 110 | * Argument structure for PT_LWPINFO. |
| 111 | */ |
| 112 | struct ptrace_lwpinfo { |
| 113 | lwpid_t pl_lwpid; /* LWP described */ |
| 114 | int pl_event; /* Event that stopped the LWP */ |
| 115 | /* Add fields at the end */ |
| 116 | }; |
| 117 | |
| 118 | #define PL_EVENT_NONE 0 |
| 119 | #define PL_EVENT_SIGNAL 1 |
| 120 | |
| 121 | #ifdef _KERNEL |
| 122 | |
| 123 | #if defined(PT_GETREGS) || defined(PT_SETREGS) |
| 124 | struct reg; |
| 125 | #ifndef process_reg32 |
| 126 | #define process_reg32 struct reg |
| 127 | #endif |
| 128 | #ifndef process_reg64 |
| 129 | #define process_reg64 struct reg |
| 130 | #endif |
| 131 | #endif |
| 132 | #if defined(PT_GETFPREGS) || defined(PT_SETFPREGS) |
| 133 | struct fpreg; |
| 134 | #ifndef process_fpreg32 |
| 135 | #define process_fpreg32 struct fpreg |
| 136 | #endif |
| 137 | #ifndef process_fpreg64 |
| 138 | #define process_fpreg64 struct fpreg |
| 139 | #endif |
| 140 | #endif |
| 141 | |
| 142 | struct ptrace_methods { |
| 143 | int (*ptm_copyinpiod)(struct ptrace_io_desc *, const void *); |
| 144 | void (*ptm_copyoutpiod)(const struct ptrace_io_desc *, void *); |
| 145 | int (*ptm_doregs)(struct lwp *, struct lwp *, struct uio *); |
| 146 | int (*ptm_dofpregs)(struct lwp *, struct lwp *, struct uio *); |
| 147 | }; |
| 148 | |
| 149 | int ptrace_init(void); |
| 150 | int ptrace_fini(void); |
| 151 | void ptrace_hooks(void); |
| 152 | |
| 153 | int process_doregs(struct lwp *, struct lwp *, struct uio *); |
| 154 | int process_validregs(struct lwp *); |
| 155 | |
| 156 | int process_dofpregs(struct lwp *, struct lwp *, struct uio *); |
| 157 | int process_validfpregs(struct lwp *); |
| 158 | |
| 159 | int process_domem(struct lwp *, struct lwp *, struct uio *); |
| 160 | |
| 161 | void process_stoptrace(void); |
| 162 | |
| 163 | void proc_reparent(struct proc *, struct proc *); |
| 164 | void proc_changeparent(struct proc *, struct proc *); |
| 165 | |
| 166 | |
| 167 | int do_ptrace(struct ptrace_methods *, struct lwp *, int, pid_t, void *, |
| 168 | int, register_t *); |
| 169 | |
| 170 | /* |
| 171 | * 64bit architectures that support 32bit emulation (amd64 and sparc64) |
| 172 | * will #define process_read_regs32 to netbsd32_process_read_regs (etc). |
| 173 | * In all other cases these #defines drop the size suffix. |
| 174 | */ |
| 175 | #ifdef PT_GETFPREGS |
| 176 | int process_read_fpregs(struct lwp *, struct fpreg *, size_t *); |
| 177 | #ifndef process_read_fpregs32 |
| 178 | #define process_read_fpregs32 process_read_fpregs |
| 179 | #endif |
| 180 | #ifndef process_read_fpregs64 |
| 181 | #define process_read_fpregs64 process_read_fpregs |
| 182 | #endif |
| 183 | #endif |
| 184 | #ifdef PT_GETREGS |
| 185 | int process_read_regs(struct lwp *, struct reg *); |
| 186 | #ifndef process_read_regs32 |
| 187 | #define process_read_regs32 process_read_regs |
| 188 | #endif |
| 189 | #ifndef process_read_regs64 |
| 190 | #define process_read_regs64 process_read_regs |
| 191 | #endif |
| 192 | #endif |
| 193 | int process_set_pc(struct lwp *, void *); |
| 194 | int process_sstep(struct lwp *, int); |
| 195 | #ifdef PT_SETFPREGS |
| 196 | int process_write_fpregs(struct lwp *, const struct fpreg *, size_t); |
| 197 | #ifndef process_write_fpregs32 |
| 198 | #define process_write_fpregs32 process_write_fpregs |
| 199 | #endif |
| 200 | #ifndef process_write_fpregs64 |
| 201 | #define process_write_fpregs64 process_write_fpregs |
| 202 | #endif |
| 203 | #endif |
| 204 | #ifdef PT_SETREGS |
| 205 | int process_write_regs(struct lwp *, const struct reg *); |
| 206 | #ifndef process_write_regs32 |
| 207 | #define process_write_regs32 process_write_regs |
| 208 | #endif |
| 209 | #ifndef process_write_regs64 |
| 210 | #define process_write_regs64 process_write_regs |
| 211 | #endif |
| 212 | #endif |
| 213 | |
| 214 | #ifdef __HAVE_PROCFS_MACHDEP |
| 215 | int ptrace_machdep_dorequest(struct lwp *, struct lwp *, int, |
| 216 | void *, int); |
| 217 | #endif |
| 218 | |
| 219 | #ifndef FIX_SSTEP |
| 220 | #define FIX_SSTEP(p) |
| 221 | #endif |
| 222 | |
| 223 | #else /* !_KERNEL */ |
| 224 | |
| 225 | #include <sys/cdefs.h> |
| 226 | |
| 227 | __BEGIN_DECLS |
| 228 | int ptrace(int _request, pid_t _pid, void *_addr, int _data); |
| 229 | __END_DECLS |
| 230 | |
| 231 | #endif /* !_KERNEL */ |
| 232 | |
| 233 | #endif /* !_SYS_PTRACE_H_ */ |
| 234 | |