ptrace.h revision 1.23.4.1 1 /* $NetBSD: ptrace.h,v 1.23.4.1 2020/01/17 21:47:25 ad Exp $ */
2
3 /*
4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * Copyright (c) 1993 Christopher G. Demetriou
40 * All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by Christopher G. Demetriou.
53 * 4. The name of the author may not be used to endorse or promote products
54 * derived from this software without specific prior written permission
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
57 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
58 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
60 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
65 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 */
67
68 #ifndef _I386_PTRACE_H_
69 #define _I386_PTRACE_H_
70
71 /*
72 * i386-dependent ptrace definitions
73 */
74 #define PT_STEP (PT_FIRSTMACH + 0)
75 #define PT_GETREGS (PT_FIRSTMACH + 1)
76 #define PT_SETREGS (PT_FIRSTMACH + 2)
77 #define PT_GETFPREGS (PT_FIRSTMACH + 3)
78 #define PT_SETFPREGS (PT_FIRSTMACH + 4)
79
80 /* We have machine-dependent process tracing needs. */
81 #define __HAVE_PTRACE_MACHDEP
82
83 /* We have machine-dependent procfs nodes. */
84 #define __HAVE_PROCFS_MACHDEP
85
86 /* The machine-dependent ptrace(2) requests. */
87 #define PT_GETXMMREGS (PT_FIRSTMACH + 5)
88 #define PT_SETXMMREGS (PT_FIRSTMACH + 6)
89 #define PT_GETDBREGS (PT_FIRSTMACH + 7)
90 #define PT_SETDBREGS (PT_FIRSTMACH + 8)
91 #define PT_SETSTEP (PT_FIRSTMACH + 9)
92 #define PT_CLEARSTEP (PT_FIRSTMACH + 10)
93 #define PT_GETXSTATE (PT_FIRSTMACH + 11)
94 #define PT_SETXSTATE (PT_FIRSTMACH + 12)
95
96 #define PT_MACHDEP_STRINGS \
97 "PT_STEP", \
98 "PT_GETREGS", \
99 "PT_SETREGS", \
100 "PT_GETFPREGS", \
101 "PT_SETFPREGS", \
102 "PT_GETXMMREGS", \
103 "PT_SETXMMREGS", \
104 "PT_GETDBREGS", \
105 "PT_SETDBREGS", \
106 "PT_SETSTEP", \
107 "PT_CLEARSTEP", \
108 "PT_GETXSTATE", \
109 "PT_SETXSTATE"
110
111 #include <machine/reg.h>
112 #define PTRACE_REG_PC(r) (r)->r_eip
113 #define PTRACE_REG_FP(r) (r)->r_ebp
114 #define PTRACE_REG_SET_PC(r, v) (r)->r_eip = (v)
115 #define PTRACE_REG_SP(r) (r)->r_esp
116 #define PTRACE_REG_INTRV(r) (r)->r_eax
117
118 #define PTRACE_ILLEGAL_ASM __asm __volatile ("ud2" : : : "memory")
119
120 #define PTRACE_BREAKPOINT ((const uint8_t[]) { 0xcc })
121 #define PTRACE_BREAKPOINT_ASM __asm __volatile ("int3" : : : "memory")
122 #define PTRACE_BREAKPOINT_SIZE 1
123 #define PTRACE_BREAKPOINT_ADJ sizeof(PTRACE_BREAKPOINT)
124
125 #ifdef _KERNEL
126
127 /*
128 * These are used in sys_ptrace() to find good ptrace(2) requests.
129 */
130 #define PTRACE_MACHDEP_REQUEST_CASES \
131 case PT_GETXMMREGS: \
132 case PT_SETXMMREGS: \
133 case PT_GETXSTATE: \
134 case PT_SETXSTATE:
135
136 /*
137 * These are used to define machine-dependent procfs node types.
138 */
139 #define PROCFS_MACHDEP_NODE_TYPES \
140 Pmachdep_xmmregs, /* extended FP register set */
141
142 /*
143 * These are used in switch statements to catch machine-dependent
144 * procfs node types.
145 */
146 #define PROCFS_MACHDEP_NODETYPE_CASES \
147 case Pmachdep_xmmregs:
148
149 /*
150 * These are used to protect a privileged process's state.
151 */
152 #define PROCFS_MACHDEP_PROTECT_CASES \
153 case Pmachdep_xmmregs:
154
155 /*
156 * These are used to define the machine-dependent procfs nodes.
157 */
158 #define PROCFS_MACHDEP_NODETYPE_DEFNS \
159 { DT_REG, N("xmmregs"), Pmachdep_xmmregs, \
160 procfs_machdep_validxmmregs },
161
162 #define PT32_GETXSTATE PT_GETXSTATE
163 #define COREDUMP_MACHDEP_LWP_NOTES(l, ns, name) \
164 { \
165 struct xstate xstate; \
166 memset(&xstate, 0, sizeof(xstate)); \
167 if (!process_read_xstate(l, &xstate)) \
168 { \
169 ELFNAMEEND(coredump_savenote)(ns, \
170 CONCAT(CONCAT(PT, ELFSIZE), _GETXSTATE), name, \
171 &xstate, sizeof(xstate)); \
172 } \
173 }
174
175 struct xmmregs;
176
177 /* Functions used by both ptrace(2) and procfs. */
178 int process_machdep_doxmmregs(struct lwp *, struct lwp *, struct uio *);
179 int process_machdep_validxmmregs(struct proc *);
180 int process_machdep_doxstate(struct lwp *, struct lwp *, struct uio *);
181 int process_machdep_validxstate(struct proc *);
182
183 /* Functions used by procfs. */
184 struct mount;
185 struct pfsnode;
186 int procfs_machdep_doxmmregs(struct lwp *, struct lwp *,
187 struct pfsnode *, struct uio *);
188 int procfs_machdep_validxmmregs(struct lwp *, struct mount *);
189
190 #endif /* _KERNEL */
191
192 #endif /* _I386_PTRACE_H_ */
193