1/* $NetBSD: ptrace.h,v 1.43 2011/08/31 22:58:39 jmcneill 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 */ 80typedef struct ptrace_event { 81 int pe_set_event; 82} ptrace_event_t; 83 84/* PT_GET_PROCESS_STATE */ 85typedef 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 */ 95struct 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 108/* 109 * Argument structure for PT_LWPINFO. 110 */ 111struct ptrace_lwpinfo { 112 lwpid_t pl_lwpid; /* LWP described */ 113 int pl_event; /* Event that stopped the LWP */ 114 /* Add fields at the end */ 115}; 116 117#define PL_EVENT_NONE 0 118#define PL_EVENT_SIGNAL 1 119 120#ifdef _KERNEL 121 122#if defined(PT_GETREGS) || defined(PT_SETREGS) 123struct reg; 124#ifndef process_reg32 125#define process_reg32 struct reg 126#endif 127#ifndef process_reg64 128#define process_reg64 struct reg 129#endif 130#endif 131#if defined(PT_GETFPREGS) || defined(PT_SETFPREGS) 132struct fpreg; 133#ifndef process_fpreg32 134#define process_fpreg32 struct fpreg 135#endif 136#ifndef process_fpreg64 137#define process_fpreg64 struct fpreg 138#endif 139#endif 140 141void ptrace_init(void); 142 143int process_doregs(struct lwp *, struct lwp *, struct uio *); 144int process_validregs(struct lwp *); 145 146int process_dofpregs(struct lwp *, struct lwp *, struct uio *); 147int process_validfpregs(struct lwp *); 148 149int process_domem(struct lwp *, struct lwp *, struct uio *); 150 151void process_stoptrace(void); 152 153void proc_reparent(struct proc *, struct proc *); 154#ifdef PT_GETFPREGS 155#ifdef __HAVE_PROCESS_XFPREGS 156int process_read_xfpregs(struct lwp *, struct fpreg *, size_t *); 157#ifndef process_read_xfpregs32 158#define process_read_xfpregs32 process_read_xfpregs 159#endif 160#ifndef process_read_xfpregs64 161#define process_read_xfpregs64 process_read_xfpregs 162#endif 163#else 164int process_read_fpregs(struct lwp *, struct fpreg *); 165#ifndef process_read_fpregs32 166#define process_read_fpregs32 process_read_fpregs 167#endif 168#ifndef process_read_fpregs64 169#define process_read_fpregs64 process_read_fpregs 170#endif 171#endif 172#endif 173#ifdef PT_GETREGS 174int process_read_regs(struct lwp *, struct reg *); 175#ifndef process_read_regs32 176#define process_read_regs32 process_read_regs 177#endif 178#ifndef process_read_regs64 179#define process_read_regs64 process_read_regs 180#endif 181#endif 182int process_set_pc(struct lwp *, void *); 183int process_sstep(struct lwp *, int); 184#ifdef PT_SETFPREGS 185#ifdef __HAVE_PROCESS_XFPREGS 186int process_write_xfpregs(struct lwp *, const struct fpreg *, size_t); 187#else 188int process_write_fpregs(struct lwp *, const struct fpreg *); 189#endif 190#endif 191#ifdef PT_SETREGS 192int process_write_regs(struct lwp *, const struct reg *); 193#endif 194 195#ifdef __HAVE_PROCFS_MACHDEP 196int ptrace_machdep_dorequest(struct lwp *, struct lwp *, int, 197 void *, int); 198#endif 199 200#ifndef FIX_SSTEP 201#define FIX_SSTEP(p) 202#endif 203 204#else /* !_KERNEL */ 205 206#include <sys/cdefs.h> 207 208__BEGIN_DECLS 209int ptrace(int _request, pid_t _pid, void *_addr, int _data); 210__END_DECLS 211 212#endif /* !_KERNEL */ 213 214#endif /* !_SYS_PTRACE_H_ */ 215