1 /* $NetBSD: ptrace.h,v 1.42 2009/12/14 00:48:35 matt 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 the 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_FIRSTMACH 32 /* for machine-specific requests */ 51 #include <machine/ptrace.h> /* machine-specific requests, if any */ 52 53 /* 54 * Argument structure for PT_IO. 55 */ 56 struct ptrace_io_desc { 57 int piod_op; /* I/O operation (see below) */ 58 void *piod_offs; /* child offset */ 59 void *piod_addr; /* parent offset */ 60 size_t piod_len; /* request length (in)/actual count (out) */ 61 }; 62 63 /* piod_op */ 64 #define PIOD_READ_D 1 /* read from D space */ 65 #define PIOD_WRITE_D 2 /* write to D spcae */ 66 #define PIOD_READ_I 3 /* read from I space */ 67 #define PIOD_WRITE_I 4 /* write to I space */ 68 69 /* 70 * Argument structure for PT_LWPINFO. 71 */ 72 struct ptrace_lwpinfo { 73 lwpid_t pl_lwpid; /* LWP described */ 74 int pl_event; /* Event that stopped the LWP */ 75 /* Add fields at the end */ 76 }; 77 78 #define PL_EVENT_NONE 0 79 #define PL_EVENT_SIGNAL 1 80 81 #ifdef _KERNEL 82 83 #if defined(PT_GETREGS) || defined(PT_SETREGS) 84 struct reg; 85 #ifndef process_reg32 86 #define process_reg32 struct reg 87 #endif 88 #ifndef process_reg64 89 #define process_reg64 struct reg 90 #endif 91 #endif 92 #if defined(PT_GETFPREGS) || defined(PT_SETFPREGS) 93 struct fpreg; 94 #ifndef process_fpreg32 95 #define process_fpreg32 struct fpreg 96 #endif 97 #ifndef process_fpreg64 98 #define process_fpreg64 struct fpreg 99 #endif 100 #endif 101 102 void ptrace_init(void); 103 104 int process_doregs(struct lwp *, struct lwp *, struct uio *); 105 int process_validregs(struct lwp *); 106 107 int process_dofpregs(struct lwp *, struct lwp *, struct uio *); 108 int process_validfpregs(struct lwp *); 109 110 int process_domem(struct lwp *, struct lwp *, struct uio *); 111 112 void process_stoptrace(void); 113 114 void proc_reparent(struct proc *, struct proc *); 115 #ifdef PT_GETFPREGS 116 #ifdef __HAVE_PROCESS_XFPREGS 117 int process_read_xfpregs(struct lwp *, struct fpreg *, size_t *); 118 #ifndef process_read_xfpregs32 119 #define process_read_xfpregs32 process_read_xfpregs 120 #endif 121 #ifndef process_read_xfpregs64 122 #define process_read_xfpregs64 process_read_xfpregs 123 #endif 124 #else 125 int process_read_fpregs(struct lwp *, struct fpreg *); 126 #ifndef process_read_fpregs32 127 #define process_read_fpregs32 process_read_fpregs 128 #endif 129 #ifndef process_read_fpregs64 130 #define process_read_fpregs64 process_read_fpregs 131 #endif 132 #endif 133 #endif 134 #ifdef PT_GETREGS 135 int process_read_regs(struct lwp *, struct reg *); 136 #ifndef process_read_regs32 137 #define process_read_regs32 process_read_regs 138 #endif 139 #ifndef process_read_regs64 140 #define process_read_regs64 process_read_regs 141 #endif 142 #endif 143 int process_set_pc(struct lwp *, void *); 144 int process_sstep(struct lwp *, int); 145 #ifdef PT_SETFPREGS 146 #ifdef __HAVE_PROCESS_XFPREGS 147 int process_write_xfpregs(struct lwp *, const struct fpreg *, size_t); 148 #else 149 int process_write_fpregs(struct lwp *, const struct fpreg *); 150 #endif 151 #endif 152 #ifdef PT_SETREGS 153 int process_write_regs(struct lwp *, const struct reg *); 154 #endif 155 156 #ifdef __HAVE_PROCFS_MACHDEP 157 int ptrace_machdep_dorequest(struct lwp *, struct lwp *, int, 158 void *, int); 159 #endif 160 161 #ifndef FIX_SSTEP 162 #define FIX_SSTEP(p) 163 #endif 164 165 #else /* !_KERNEL */ 166 167 #include <sys/cdefs.h> 168 169 __BEGIN_DECLS 170 int ptrace(int _request, pid_t _pid, void *_addr, int _data); 171 __END_DECLS 172 173 #endif /* !_KERNEL */ 174 175 #endif /* !_SYS_PTRACE_H_ */ 176