summaryrefslogtreecommitdiff
path: root/open-vm-tools/lib/include/sigPosixRegs.h
blob: fec53adbcd22709c7b5e796ef0f68cf5cb3abf27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*********************************************************
 * Copyright (C) 2009 VMware, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation version 2.1 and no later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *********************************************************/

/*
 * sigPosixRegs.h --
 *
 *      Platform-specific definitions for saved CPU registers inside
 *      ucontext_t. These aren't part of sigPosix.h since few source
 *      files need them, and this header is a bit invasive, and it must
 *      be defined before system headers.
 */

#ifndef _SIGPOSIXREGS_H_
#define _SIGPOSIXREGS_H_

#define INCLUDE_ALLOW_USERLEVEL
#define INCLUDE_ALLOW_VMCORE
#include "includeCheck.h"


#if __linux__         // We need the REG_foo offsets in the gregset_t;
#  define _GNU_SOURCE // _GNU_SOURCE maps to __USE_GNU

/* And, the REG_foo definitions conflict with our own in x86.h */
#  if defined(__x86_64__)
#    define REG_RAX GNU_REG_RAX
#    define REG_RBX GNU_REG_RBX
#    define REG_RCX GNU_REG_RCX
#    define REG_RDX GNU_REG_RDX
#    define REG_RSI GNU_REG_RSI
#    define REG_RDI GNU_REG_RDI
#    define REG_RSP GNU_REG_RSP
#    define REG_RBP GNU_REG_RBP
#    define REG_RIP GNU_REG_RIP
#    define REG_R8  GNU_REG_R8
#    define REG_R9  GNU_REG_R9
#    define REG_R10 GNU_REG_R10
#    define REG_R11 GNU_REG_R11
#    define REG_R12 GNU_REG_R12
#    define REG_R13 GNU_REG_R13
#    define REG_R14 GNU_REG_R14
#    define REG_R15 GNU_REG_R15
#  elif defined(__i386__)
#    define REG_EAX GNU_REG_EAX
#    define REG_EBX GNU_REG_EBX
#    define REG_ECX GNU_REG_ECX
#    define REG_EDX GNU_REG_EDX
#    define REG_ESI GNU_REG_ESI
#    define REG_EDI GNU_REG_EDI
#    define REG_ESP GNU_REG_ESP
#    define REG_EBP GNU_REG_EBP
#    define REG_EIP GNU_REG_EIP
#  endif
#endif

#include <signal.h>
#ifndef __ANDROID__
#include <sys/ucontext.h>
#endif

#if __linux__
#  if defined(__x86_64__)
#    undef REG_RAX
#    undef REG_RBX
#    undef REG_RCX
#    undef REG_RDX
#    undef REG_RSI
#    undef REG_RDI
#    undef REG_RSP
#    undef REG_RBP
#    undef REG_RIP
#    undef REG_R8
#    undef REG_R9
#    undef REG_R10
#    undef REG_R11
#    undef REG_R12
#    undef REG_R13
#    undef REG_R14
#    undef REG_R15
#  elif defined(__i386__)
#    undef REG_EAX
#    undef REG_EBX
#    undef REG_ECX
#    undef REG_EDX
#    undef REG_ESI
#    undef REG_EDI
#    undef REG_ESP
#    undef REG_EBP
#    undef REG_EIP
#  endif
#endif

#if defined(__APPLE__)
#if __DARWIN_UNIX03
#ifdef __x86_64__
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__rax)
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__rbx)
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__rcx)
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__rdx)
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__rdi)
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__rsi)
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__rbp)
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__rsp)
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__rip)
#define SC_R8(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r8)
#define SC_R9(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r9)
#define SC_R10(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__r10)
#define SC_R11(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__r11)
#define SC_R12(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__r12)
#define SC_R13(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__r13)
#define SC_R14(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__r14)
#define SC_R15(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__r15)
#elif defined(__arm__)
#define SC_R0(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[0])
#define SC_R1(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[1])
#define SC_R2(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[2])
#define SC_R3(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[3])
#define SC_R4(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[4])
#define SC_R5(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[5])
#define SC_R6(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[6])
#define SC_R7(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[7])
#define SC_R8(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[8])
#define SC_R9(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[9])
#define SC_R10(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__r[10])
#define SC_FP(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[11])
#define SC_IP(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__r[12])
#define SC_SP(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__sp)
#define SC_LR(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__lr)
#define SC_PC(uc)  ((unsigned long) (uc)->uc_mcontext->__ss.__pc)
#else
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__eax)
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__ebx)
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__ecx)
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__edx)
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__edi)
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__esi)
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__ebp)
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__esp)
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext->__ss.__eip)
#endif
#else
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext->ss.eax)
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext->ss.ebx)
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext->ss.ecx)
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext->ss.edx)
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext->ss.edi)
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext->ss.esi)
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext->ss.ebp)
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext->ss.esp)
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext->ss.eip)
#endif
#elif defined(__FreeBSD__)
#ifdef __x86_64__
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.mc_rax)
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.mc_rbx)
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.mc_rcx)
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.mc_rdx)
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.mc_rdi)
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.mc_rsi)
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.mc_rbp)
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.mc_rsp)
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.mc_rip)
#define SC_R8(uc)  ((unsigned long) (uc)->uc_mcontext.mc_r8)
#define SC_R9(uc)  ((unsigned long) (uc)->uc_mcontext.mc_r9)
#define SC_R10(uc) ((unsigned long) (uc)->uc_mcontext.mc_r10)
#define SC_R11(uc) ((unsigned long) (uc)->uc_mcontext.mc_r11)
#define SC_R12(uc) ((unsigned long) (uc)->uc_mcontext.mc_r12)
#define SC_R13(uc) ((unsigned long) (uc)->uc_mcontext.mc_r13)
#define SC_R14(uc) ((unsigned long) (uc)->uc_mcontext.mc_r14)
#define SC_R15(uc) ((unsigned long) (uc)->uc_mcontext.mc_r15)
#else
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.mc_eax)
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.mc_ebx)
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.mc_ecx)
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.mc_edx)
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.mc_edi)
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.mc_esi)
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.mc_ebp)
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.mc_esp)
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.mc_eip)
#endif
#elif defined (sun)
#ifdef __x86_64__
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RAX])
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RBX])
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RCX])
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RDX])
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RDI])
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RSI])
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RBP])
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RSP])
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_RIP])
#define SC_R8(uc)  ((unsigned long) (uc)->uc_mcontext.gregs[REG_R8])
#define SC_R9(uc)  ((unsigned long) (uc)->uc_mcontext.gregs[REG_R9])
#define SC_R10(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_R10])
#define SC_R11(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_R11])
#define SC_R12(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_R12])
#define SC_R13(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_R13])
#define SC_R14(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_R14])
#define SC_R15(uc) ((unsigned long) (uc)->uc_mcontext.gregs[REG_R15])
#else
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[EAX])
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[EBX])
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[ECX])
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[EDX])
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.gregs[EDI])
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.gregs[ESI])
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[EBP])
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[ESP])
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[EIP])
#endif
#elif defined(ANDROID_X86)
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.eax)
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.ebx)
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.ecx)
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.edx)
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.edi)
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.esi)
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.ebp)
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.esp)
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.eip)
#else
#ifdef __x86_64__
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RAX])
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RBX])
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RCX])
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RDX])
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RDI])
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RSI])
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RBP])
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RSP])
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_RIP])
#define SC_R8(uc)  ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_R8])
#define SC_R9(uc)  ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_R9])
#define SC_R10(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_R10])
#define SC_R11(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_R11])
#define SC_R12(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_R12])
#define SC_R13(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_R13])
#define SC_R14(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_R14])
#define SC_R15(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_R15])
#elif defined(__arm__)
#define SC_R0(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r0)
#define SC_R1(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r1)
#define SC_R2(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r2)
#define SC_R3(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r3)
#define SC_R4(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r4)
#define SC_R5(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r5)
#define SC_R6(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r6)
#define SC_R7(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r7)
#define SC_R8(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r8)
#define SC_R9(uc)  ((unsigned long) (uc)->uc_mcontext.arm_r9)
#define SC_R10(uc) ((unsigned long) (uc)->uc_mcontext.arm_r10)
#define SC_FP(uc)  ((unsigned long) (uc)->uc_mcontext.arm_fp)
#define SC_IP(uc)  ((unsigned long) (uc)->uc_mcontext.arm_ip)
#define SC_SP(uc)  ((unsigned long) (uc)->uc_mcontext.arm_sp)
#define SC_LR(uc)  ((unsigned long) (uc)->uc_mcontext.arm_lr)
#define SC_PC(uc)  ((unsigned long) (uc)->uc_mcontext.arm_pc)
#else
#define SC_EAX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_EAX])
#define SC_EBX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_EBX])
#define SC_ECX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_ECX])
#define SC_EDX(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_EDX])
#define SC_EDI(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_EDI])
#define SC_ESI(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_ESI])
#define SC_EBP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_EBP])
#define SC_ESP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_ESP])
#define SC_EIP(uc) ((unsigned long) (uc)->uc_mcontext.gregs[GNU_REG_EIP])
#endif
#endif

#endif // ifndef _SIGPOSIXREGS_H_