ptrace.h revision 1.12.12.2 1 /* $NetBSD: ptrace.h,v 1.12.12.2 2020/04/13 08:03:30 martin Exp $ */
2
3 /*
4 * Copyright (c) 1993 Christopher G. Demetriou
5 * 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Christopher G. Demetriou.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 #ifndef _AMD64_PTRACE_H_
33 #define _AMD64_PTRACE_H_
34
35 #ifdef __x86_64__
36 /*
37 * amd64-dependent ptrace definitions
38 */
39 #define PT_STEP (PT_FIRSTMACH + 0)
40 #define PT_GETREGS (PT_FIRSTMACH + 1)
41 #define PT_SETREGS (PT_FIRSTMACH + 2)
42 #define PT_GETFPREGS (PT_FIRSTMACH + 3)
43 #define PT_SETFPREGS (PT_FIRSTMACH + 4)
44 #define PT_GETDBREGS (PT_FIRSTMACH + 5)
45 #define PT_SETDBREGS (PT_FIRSTMACH + 6)
46 #define PT_SETSTEP (PT_FIRSTMACH + 7)
47 #define PT_CLEARSTEP (PT_FIRSTMACH + 8)
48 #define PT_GETXSTATE (PT_FIRSTMACH + 9)
49 #define PT_SETXSTATE (PT_FIRSTMACH + 10)
50 #ifdef _KERNEL
51 /*
52 * Only used internally for COMPAT_NETBSD32
53 */
54 #define PT_GETXMMREGS (PT_FIRSTMACH + 11)
55 #define PT_SETXMMREGS (PT_FIRSTMACH + 12)
56 #endif
57
58 /* We have machine-dependent process tracing needs. */
59 #define __HAVE_PTRACE_MACHDEP
60
61 #define PT_MACHDEP_STRINGS \
62 "PT_STEP", \
63 "PT_GETREGS", \
64 "PT_SETREGS", \
65 "PT_GETFPREGS", \
66 "PT_SETFPREGS", \
67 "PT_GETDBREGS", \
68 "PT_SETDBREGS", \
69 "PT_SETSTEP", \
70 "PT_CLEARSTEP", \
71 "PT_GETXSTATE", \
72 "PT_SETXSTATE", \
73 "PT_GETXMMREGS", \
74 "PT_SETXMMREGS"
75
76 #include <machine/reg.h>
77 #define PTRACE_REG_PC(r) (r)->regs[_REG_RIP]
78 #define PTRACE_REG_FP(r) (r)->regs[_REG_RBP]
79 #define PTRACE_REG_SET_PC(r, v) (r)->regs[_REG_RIP] = (v)
80 #define PTRACE_REG_SP(r) (r)->regs[_REG_RSP]
81 #define PTRACE_REG_INTRV(r) (r)->regs[_REG_RAX]
82
83 #define PTRACE_ILLEGAL_ASM __asm __volatile ("ud2" : : : "memory")
84
85 #define PTRACE_BREAKPOINT ((const uint8_t[]) { 0xcc })
86 #define PTRACE_BREAKPOINT_ASM __asm __volatile ("int3" : : : "memory")
87 #define PTRACE_BREAKPOINT_SIZE 1
88 #define PTRACE_BREAKPOINT_ADJ 1
89
90 #ifdef _KERNEL
91
92 /*
93 * These are used in sys_ptrace() to find good ptrace(2) requests.
94 */
95 #define PTRACE_MACHDEP_REQUEST_CASES \
96 case PT_GETXSTATE: \
97 case PT_SETXSTATE: \
98 case PT_GETXMMREGS: \
99 case PT_SETXMMREGS:
100
101 int process_machdep_doxstate(struct lwp *, struct lwp *, struct uio *);
102 int process_machdep_validfpu(struct proc *);
103
104 #include <sys/module_hook.h>
105 MODULE_HOOK(netbsd32_process_doxmmregs_hook, int,
106 (struct lwp *, struct lwp *, void *, bool));
107
108 #ifdef EXEC_ELF32
109 #include <machine/netbsd32_machdep.h>
110 #endif
111 #define PT64_GETXSTATE PT_GETXSTATE
112 #define COREDUMP_MACHDEP_LWP_NOTES(l, ns, name) \
113 { \
114 struct xstate xstate; \
115 memset(&xstate, 0, sizeof(xstate)); \
116 if (!process_read_xstate(l, &xstate)) \
117 { \
118 ELFNAMEEND(coredump_savenote)(ns, \
119 CONCAT(CONCAT(PT, ELFSIZE), _GETXSTATE), name, \
120 &xstate, sizeof(xstate)); \
121 } \
122 }
123
124 #endif /* _KERNEL */
125
126 #ifdef _KERNEL_OPT
127 #include "opt_compat_netbsd32.h"
128
129 #ifdef COMPAT_NETBSD32
130 #include <machine/netbsd32_machdep.h>
131
132 #define process_read_regs32 netbsd32_process_read_regs
133 #define process_read_fpregs32 netbsd32_process_read_fpregs
134 #define process_read_dbregs32 netbsd32_process_read_dbregs
135
136 #define process_write_regs32 netbsd32_process_write_regs
137 #define process_write_fpregs32 netbsd32_process_write_fpregs
138 #define process_write_dbregs32 netbsd32_process_write_dbregs
139
140 #define process_reg32 struct reg32
141 #define process_fpreg32 struct fpreg32
142 #define process_dbreg32 struct dbreg32
143
144 #define PTRACE_TRANSLATE_REQUEST32(x) netbsd32_ptrace_translate_request(x)
145 #endif /* COMPAT_NETBSD32 */
146 #endif /* _KERNEL_OPT */
147
148 #else /* !__x86_64__ */
149
150 #include <i386/ptrace.h>
151
152 #endif /* __x86_64__ */
153
154 #endif /* _AMD64_PTRACE_H_ */
155