Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / sys / ptrace.h @ 13

History | View | Annotate | Download (8.64 KB)

1 13 up20180614
/*        $NetBSD: ptrace.h,v 1.46 2015/07/02 03:47:54 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
void        ptrace_init(void);
143
144
int        process_doregs(struct lwp *, struct lwp *, struct uio *);
145
int        process_validregs(struct lwp *);
146
147
int        process_dofpregs(struct lwp *, struct lwp *, struct uio *);
148
int        process_validfpregs(struct lwp *);
149
150
int        process_domem(struct lwp *, struct lwp *, struct uio *);
151
152
void        process_stoptrace(void);
153
154
void        proc_reparent(struct proc *, struct proc *);
155
156
/*
157
 * 64bit architectures that support 32bit emulation (amd64 and sparc64)
158
 * will #define process_read_regs32 to netbsd32_process_read_regs (etc).
159
 * In all other cases these #defines drop the size suffix.
160
 */
161
#ifdef PT_GETFPREGS
162
int        process_read_fpregs(struct lwp *, struct fpreg *, size_t *);
163
#ifndef process_read_fpregs32
164
#define process_read_fpregs32        process_read_fpregs
165
#endif
166
#ifndef process_read_fpregs64
167
#define process_read_fpregs64        process_read_fpregs
168
#endif
169
#endif
170
#ifdef PT_GETREGS
171
int        process_read_regs(struct lwp *, struct reg *);
172
#ifndef process_read_regs32
173
#define process_read_regs32        process_read_regs
174
#endif
175
#ifndef process_read_regs64
176
#define process_read_regs64        process_read_regs
177
#endif
178
#endif
179
int        process_set_pc(struct lwp *, void *);
180
int        process_sstep(struct lwp *, int);
181
#ifdef PT_SETFPREGS
182
int        process_write_fpregs(struct lwp *, const struct fpreg *, size_t);
183
#endif
184
#ifdef PT_SETREGS
185
int        process_write_regs(struct lwp *, const struct reg *);
186
#endif
187
188
#ifdef __HAVE_PROCFS_MACHDEP
189
int        ptrace_machdep_dorequest(struct lwp *, struct lwp *, int,
190
            void *, int);
191
#endif
192
193
#ifndef FIX_SSTEP
194
#define FIX_SSTEP(p)
195
#endif
196
197
#else /* !_KERNEL */
198
199
#include <sys/cdefs.h>
200
201
__BEGIN_DECLS
202
int        ptrace(int _request, pid_t _pid, void *_addr, int _data);
203
__END_DECLS
204
205
#endif /* !_KERNEL */
206
207
#if defined(__minix)
208
/* Trace options. */
209
#define TO_TRACEFORK   0x1     /* automatically attach to forked children */
210
#define TO_ALTEXEC     0x2     /* send SIGSTOP on successful exec() */
211
#define TO_NOEXEC      0x4     /* do not send signal on successful exec() */
212
213
/* Trace spaces. */
214
#define TS_INS         0       /* text space */
215
#define TS_DATA        1       /* data space */
216
217
/* Trance range structure. */
218
struct ptrace_range {
219
  int pr_space;                        /* space in traced process */
220
  long pr_addr;                        /* address in traced process */
221
  void *pr_ptr;                        /* buffer in caller process */
222
  size_t pr_size;              /* size of range, in bytes */
223
};
224
225
/* Trace requests aliases for minix. */
226
#define T_OK           PT_TRACE_ME /* enable tracing by parent for this process */
227
#define T_GETINS       PT_READ_I   /* return value from instruction space */
228
#define T_GETDATA      PT_READ_D   /* return value from data space */
229
#define T_SETINS       PT_WRITE_I  /* set value from instruction space */
230
#define T_SETDATA      PT_WRITE_D  /* set value from data space */
231
#define T_RESUME       PT_CONTINUE /* resume execution */
232
#define T_EXIT         PT_KILL     /* exit */
233
#define T_SYSCALL      PT_SYSCALL /* trace system call */
234
#define T_ATTACH       PT_ATTACH  /* attach to a running process */
235
#define T_DETACH       PT_DETACH  /* detach from a traced process */
236
237
/* Trace requests unique to minix */
238
#define T_STOP        -1       /* stop the process */
239
#define T_READB_INS    100     /* Read a byte from the text segment of an
240
                                * untraced process (only for root)
241
                                */
242
#define T_WRITEB_INS   101     /* Write a byte in the text segment of an
243
                                * untraced process (only for root)
244
                                */
245
#define T_GETUSER      102       /* return value from user process table */
246
#define T_SETUSER      103       /* set value in user process table */
247
#define T_STEP         104       /* set trace bit */
248
#define T_SETOPT       105       /* set trace options */
249
#define T_GETRANGE     106       /* get range of values */
250
#define T_SETRANGE     107       /* set range of values */
251
252
#endif /* defined(__minix) */
253
254
#endif        /* !_SYS_PTRACE_H_ */