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
|
/*--------------------------------------------------------------------*/
/*--- begin genoffsets.c ---*/
/*--------------------------------------------------------------------*/
/*
This file is part of Valgrind, a dynamic binary instrumentation
framework.
Copyright (C) 2004-2017 OpenWorks LLP
info@open-works.net
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any 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 GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
The GNU General Public License is contained in the file COPYING.
Neither the names of the U.S. Department of Energy nor the
University of California nor the names of its contributors may be
used to endorse or promote products derived from this software
without prior written permission.
*/
#include <stdio.h>
/* A program which, when compiled to assembly, exposes various guest
state offsets. The program isn't executed, since that breaks
cross-compilation.
It does rely on the assumption that 'my_offsetof(Ty,Field)' is
folded to a constant at a compile time, which seems a bit dodgy
to me. On gcc4 it is possible to use __builtin_offsetof, which
sounds safer, but that doesn't exist on older gccs. Oh Well.
*/
#include "../pub/libvex_basictypes.h"
#include "../pub/libvex_guest_x86.h"
#include "../pub/libvex_guest_amd64.h"
#include "../pub/libvex_guest_ppc32.h"
#include "../pub/libvex_guest_ppc64.h"
#include "../pub/libvex_guest_arm.h"
#include "../pub/libvex_guest_arm64.h"
#include "../pub/libvex_guest_s390x.h"
#include "../pub/libvex_guest_mips32.h"
#include "../pub/libvex_guest_mips64.h"
#define VG_STRINGIFZ(__str) #__str
#define VG_STRINGIFY(__str) VG_STRINGIFZ(__str)
#define my_offsetof(__type,__field) \
((unsigned long int)(&((__type*)0)->__field))
/* This forces gcc to evaluate the my_offsetof call at compile time,
and then emits it in the assembly, along with the nonsense string
"xyzzy", for easy greppability. Once this file is compiled to
assembly, the lines containing "xyzzy" are grepped out and sed-ed
to produce the final result. See the Makefile rule for
pub/libvex_guest_offsets.h. */
#define GENOFFSET(_structUppercase,_structLowercase,_fieldname) \
__asm__ __volatile__ ( \
"\n#define OFFSET_" \
VG_STRINGIFY(_structLowercase) "_" \
VG_STRINGIFY(_fieldname) \
" xyzzy%0\n" : /*out*/ \
: /*in*/ "n" \
(my_offsetof(VexGuest##_structUppercase##State, \
guest_##_fieldname)) \
)
void foo ( void );
__attribute__((noinline))
void foo ( void )
{
// x86
GENOFFSET(X86,x86,EAX);
GENOFFSET(X86,x86,EBX);
GENOFFSET(X86,x86,ECX);
GENOFFSET(X86,x86,EDX);
GENOFFSET(X86,x86,ESI);
GENOFFSET(X86,x86,EDI);
GENOFFSET(X86,x86,EBP);
GENOFFSET(X86,x86,ESP);
GENOFFSET(X86,x86,EIP);
GENOFFSET(X86,x86,CS);
GENOFFSET(X86,x86,DS);
GENOFFSET(X86,x86,ES);
GENOFFSET(X86,x86,FS);
GENOFFSET(X86,x86,GS);
GENOFFSET(X86,x86,SS);
// amd64
GENOFFSET(AMD64,amd64,RAX);
GENOFFSET(AMD64,amd64,RBX);
GENOFFSET(AMD64,amd64,RCX);
GENOFFSET(AMD64,amd64,RDX);
GENOFFSET(AMD64,amd64,RSI);
GENOFFSET(AMD64,amd64,RDI);
GENOFFSET(AMD64,amd64,RSP);
GENOFFSET(AMD64,amd64,RBP);
GENOFFSET(AMD64,amd64,R8);
GENOFFSET(AMD64,amd64,R9);
GENOFFSET(AMD64,amd64,R10);
GENOFFSET(AMD64,amd64,R11);
GENOFFSET(AMD64,amd64,R12);
GENOFFSET(AMD64,amd64,R13);
GENOFFSET(AMD64,amd64,R14);
GENOFFSET(AMD64,amd64,R15);
GENOFFSET(AMD64,amd64,RIP);
// ppc32
GENOFFSET(PPC32,ppc32,GPR0);
GENOFFSET(PPC32,ppc32,GPR1);
GENOFFSET(PPC32,ppc32,GPR2);
GENOFFSET(PPC32,ppc32,GPR3);
GENOFFSET(PPC32,ppc32,GPR4);
GENOFFSET(PPC32,ppc32,GPR5);
GENOFFSET(PPC32,ppc32,GPR6);
GENOFFSET(PPC32,ppc32,GPR7);
GENOFFSET(PPC32,ppc32,GPR8);
GENOFFSET(PPC32,ppc32,GPR9);
GENOFFSET(PPC32,ppc32,GPR10);
GENOFFSET(PPC32,ppc32,CIA);
GENOFFSET(PPC32,ppc32,CR0_0);
// ppc64
GENOFFSET(PPC64,ppc64,GPR0);
GENOFFSET(PPC64,ppc64,GPR1);
GENOFFSET(PPC64,ppc64,GPR2);
GENOFFSET(PPC64,ppc64,GPR3);
GENOFFSET(PPC64,ppc64,GPR4);
GENOFFSET(PPC64,ppc64,GPR5);
GENOFFSET(PPC64,ppc64,GPR6);
GENOFFSET(PPC64,ppc64,GPR7);
GENOFFSET(PPC64,ppc64,GPR8);
GENOFFSET(PPC64,ppc64,GPR9);
GENOFFSET(PPC64,ppc64,GPR10);
GENOFFSET(PPC64,ppc64,CIA);
GENOFFSET(PPC64,ppc64,CR0_0);
// arm
GENOFFSET(ARM,arm,R0);
GENOFFSET(ARM,arm,R1);
GENOFFSET(ARM,arm,R2);
GENOFFSET(ARM,arm,R3);
GENOFFSET(ARM,arm,R4);
GENOFFSET(ARM,arm,R5);
GENOFFSET(ARM,arm,R7);
GENOFFSET(ARM,arm,R13);
GENOFFSET(ARM,arm,R14);
GENOFFSET(ARM,arm,R15T);
// arm64
GENOFFSET(ARM64,arm64,X0);
GENOFFSET(ARM64,arm64,X1);
GENOFFSET(ARM64,arm64,X2);
GENOFFSET(ARM64,arm64,X3);
GENOFFSET(ARM64,arm64,X4);
GENOFFSET(ARM64,arm64,X5);
GENOFFSET(ARM64,arm64,X6);
GENOFFSET(ARM64,arm64,X7);
GENOFFSET(ARM64,arm64,X8);
GENOFFSET(ARM64,arm64,XSP);
GENOFFSET(ARM64,arm64,PC);
// s390x
GENOFFSET(S390X,s390x,r2);
GENOFFSET(S390X,s390x,r3);
GENOFFSET(S390X,s390x,r4);
GENOFFSET(S390X,s390x,r5);
GENOFFSET(S390X,s390x,r6);
GENOFFSET(S390X,s390x,r7);
GENOFFSET(S390X,s390x,r15);
GENOFFSET(S390X,s390x,IA);
GENOFFSET(S390X,s390x,SYSNO);
GENOFFSET(S390X,s390x,IP_AT_SYSCALL);
GENOFFSET(S390X,s390x,fpc);
GENOFFSET(S390X,s390x,CC_OP);
GENOFFSET(S390X,s390x,CC_DEP1);
GENOFFSET(S390X,s390x,CC_DEP2);
GENOFFSET(S390X,s390x,CC_NDEP);
// MIPS32
GENOFFSET(MIPS32,mips32,r0);
GENOFFSET(MIPS32,mips32,r1);
GENOFFSET(MIPS32,mips32,r2);
GENOFFSET(MIPS32,mips32,r3);
GENOFFSET(MIPS32,mips32,r4);
GENOFFSET(MIPS32,mips32,r5);
GENOFFSET(MIPS32,mips32,r6);
GENOFFSET(MIPS32,mips32,r7);
GENOFFSET(MIPS32,mips32,r8);
GENOFFSET(MIPS32,mips32,r9);
GENOFFSET(MIPS32,mips32,r10);
GENOFFSET(MIPS32,mips32,r11);
GENOFFSET(MIPS32,mips32,r12);
GENOFFSET(MIPS32,mips32,r13);
GENOFFSET(MIPS32,mips32,r14);
GENOFFSET(MIPS32,mips32,r15);
GENOFFSET(MIPS32,mips32,r15);
GENOFFSET(MIPS32,mips32,r17);
GENOFFSET(MIPS32,mips32,r18);
GENOFFSET(MIPS32,mips32,r19);
GENOFFSET(MIPS32,mips32,r20);
GENOFFSET(MIPS32,mips32,r21);
GENOFFSET(MIPS32,mips32,r22);
GENOFFSET(MIPS32,mips32,r23);
GENOFFSET(MIPS32,mips32,r24);
GENOFFSET(MIPS32,mips32,r25);
GENOFFSET(MIPS32,mips32,r26);
GENOFFSET(MIPS32,mips32,r27);
GENOFFSET(MIPS32,mips32,r28);
GENOFFSET(MIPS32,mips32,r29);
GENOFFSET(MIPS32,mips32,r30);
GENOFFSET(MIPS32,mips32,r31);
GENOFFSET(MIPS32,mips32,PC);
GENOFFSET(MIPS32,mips32,HI);
GENOFFSET(MIPS32,mips32,LO);
// MIPS64
GENOFFSET(MIPS64,mips64,r0);
GENOFFSET(MIPS64,mips64,r1);
GENOFFSET(MIPS64,mips64,r2);
GENOFFSET(MIPS64,mips64,r3);
GENOFFSET(MIPS64,mips64,r4);
GENOFFSET(MIPS64,mips64,r5);
GENOFFSET(MIPS64,mips64,r6);
GENOFFSET(MIPS64,mips64,r7);
GENOFFSET(MIPS64,mips64,r8);
GENOFFSET(MIPS64,mips64,r9);
GENOFFSET(MIPS64,mips64,r10);
GENOFFSET(MIPS64,mips64,r11);
GENOFFSET(MIPS64,mips64,r12);
GENOFFSET(MIPS64,mips64,r13);
GENOFFSET(MIPS64,mips64,r14);
GENOFFSET(MIPS64,mips64,r15);
GENOFFSET(MIPS64,mips64,r15);
GENOFFSET(MIPS64,mips64,r17);
GENOFFSET(MIPS64,mips64,r18);
GENOFFSET(MIPS64,mips64,r19);
GENOFFSET(MIPS64,mips64,r20);
GENOFFSET(MIPS64,mips64,r21);
GENOFFSET(MIPS64,mips64,r22);
GENOFFSET(MIPS64,mips64,r23);
GENOFFSET(MIPS64,mips64,r24);
GENOFFSET(MIPS64,mips64,r25);
GENOFFSET(MIPS64,mips64,r26);
GENOFFSET(MIPS64,mips64,r27);
GENOFFSET(MIPS64,mips64,r28);
GENOFFSET(MIPS64,mips64,r29);
GENOFFSET(MIPS64,mips64,r30);
GENOFFSET(MIPS64,mips64,r31);
GENOFFSET(MIPS64,mips64,PC);
GENOFFSET(MIPS64,mips64,HI);
GENOFFSET(MIPS64,mips64,LO);
}
/*--------------------------------------------------------------------*/
/*--- end genoffsets.c ---*/
/*--------------------------------------------------------------------*/
|