|
From: <sv...@va...> - 2006-01-10 08:01:14
|
Author: sewardj
Date: 2006-01-10 08:01:07 +0000 (Tue, 10 Jan 2006)
New Revision: 1534
Log:
Function wrapping support for amd64.
Modified:
branches/FNWRAP/priv/guest-amd64/toIR.c
branches/FNWRAP/priv/host-amd64/hdefs.c
Modified: branches/FNWRAP/priv/guest-amd64/toIR.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/FNWRAP/priv/guest-amd64/toIR.c 2006-01-07 22:58:54 UTC (rev =
1533)
+++ branches/FNWRAP/priv/guest-amd64/toIR.c 2006-01-10 08:01:07 UTC (rev =
1534)
@@ -122,6 +122,28 @@
sto{s,sb,sw,sd,sq}
xlat{,b} */
=20
+/* "Special" instructions.
+
+ This instruction decoder can decode three special instructions
+ which mean nothing natively (are no-ops as far as regs/mem are
+ concerned) but have meaning for supporting Valgrind. A special
+ instruction is flagged by the 16-byte preamble 48C1C703 48C1C70D
+ 48C1C73D 48C1C733 (in the standard interpretation, that means: rolq
+ $3, %rdi; rolq $13, %rdi; rolq $61, %rdi; rolq $51, %rdi).
+ Following that, one of the following 3 are allowed (standard
+ interpretation in parentheses):
+
+ 4887DB (xchgq %rbx,%rbx) %RDX =3D client_request ( %RAX )
+ 4887C9 (xchgq %rcx,%rcx) %RAX =3D guest_NRADDR
+ 4887D2 (xchgq %rdx,%rdx) call-noredir *%RAX
+
+ Any other bytes following the 16-byte preamble are illegal and
+ constitute a failure in instruction decoding. This all assumes
+ that the preamble will never occur except in specific code
+ fragments designed for Valgrind to catch.
+
+ No prefixes may precede a "Special" instruction. */
+
/* Translates AMD64 code to IR. */
=20
#include "libvex_basictypes.h"
@@ -396,7 +418,9 @@
=20
#define OFFB_EMWARN offsetof(VexGuestAMD64State,guest_EMWARN)
=20
+#define OFFB_NRADDR offsetof(VexGuestAMD64State,guest_NRADDR)
=20
+
/*------------------------------------------------------------*/
/*--- Helper bits and pieces for deconstructing the ---*/
/*--- amd64 insn stream. ---*/
@@ -7940,29 +7964,61 @@
if (put_IP)
stmt( IRStmt_Put( OFFB_RIP, mkU64(guest_RIP_curr_instr)) );
=20
- /* Spot the client-request magic sequence. */
+ /* Spot "Special" instructions (see comment at top of file). */
{
UChar* code =3D (UChar*)(guest_code + delta);
- /* Spot this:
- C1C01D roll $29, %eax
- C1C003 roll $3, %eax
- C1C81B rorl $27, %eax
- C1C805 rorl $5, %eax
- C1C00D roll $13, %eax
- C1C013 roll $19, %eax =20
+ /* Spot the 16-byte preamble:
+ 48C1C703 rolq $3, %rdi
+ 48C1C70D rolq $13, %rdi
+ 48C1C73D rolq $61, %rdi
+ 48C1C733 rolq $51, %rdi
*/
- if (code[ 0] =3D=3D 0xC1 && code[ 1] =3D=3D 0xC0 && code[ 2] =3D=3D=
0x1D &&
- code[ 3] =3D=3D 0xC1 && code[ 4] =3D=3D 0xC0 && code[ 5] =3D=3D=
0x03 &&
- code[ 6] =3D=3D 0xC1 && code[ 7] =3D=3D 0xC8 && code[ 8] =3D=3D=
0x1B &&
- code[ 9] =3D=3D 0xC1 && code[10] =3D=3D 0xC8 && code[11] =3D=3D=
0x05 &&
- code[12] =3D=3D 0xC1 && code[13] =3D=3D 0xC0 && code[14] =3D=3D=
0x0D &&
- code[15] =3D=3D 0xC1 && code[16] =3D=3D 0xC0 && code[17] =3D=3D=
0x13
- ) {
- DIP("%%edx =3D client_request ( %%eax )\n"); =20
- delta +=3D 18;
- jmp_lit(Ijk_ClientReq, guest_RIP_bbstart+delta);
- dres.whatNext =3D Dis_StopHere;
- goto decode_success;
+ if (code[ 0] =3D=3D 0x48 && code[ 1] =3D=3D 0xC1 && code[ 2] =3D=3D=
0xC7=20
+ && code[ 3] =3D=3D 0x03 &=
&
+ code[ 4] =3D=3D 0x48 && code[ 5] =3D=3D 0xC1 && code[ 6] =3D=3D=
0xC7=20
+ && code[ 7] =3D=3D 0x0D &=
&
+ code[ 8] =3D=3D 0x48 && code[ 9] =3D=3D 0xC1 && code[10] =3D=3D=
0xC7=20
+ && code[11] =3D=3D 0x3D &=
&
+ code[12] =3D=3D 0x48 && code[13] =3D=3D 0xC1 && code[14] =3D=3D=
0xC7=20
+ && code[15] =3D=3D 0x33) =
{
+ /* Got a "Special" instruction preamble. Which one is it? */
+ if (code[16] =3D=3D 0x48 && code[17] =3D=3D 0x87=20
+ && code[18] =3D=3D 0xDB /* xchgq %rbx,%rbx=
*/) {
+ /* %RDX =3D client_request ( %RAX ) */
+ DIP("%%rdx =3D client_request ( %%rax )\n");
+ delta +=3D 19;
+ jmp_lit(Ijk_ClientReq, guest_RIP_bbstart+delta);
+ dres.whatNext =3D Dis_StopHere;
+ goto decode_success;
+ }
+ else
+ if (code[16] =3D=3D 0x48 && code[17] =3D=3D 0x87=20
+ && code[18] =3D=3D 0xC9 /* xchgq %rcx,%rcx=
*/) {
+ /* %RAX =3D guest_NRADDR */
+ DIP("%%rax =3D guest_NRADDR\n");
+ delta +=3D 19;
+ putIRegRAX(8, IRExpr_Get( OFFB_NRADDR, Ity_I64 ));
+ goto decode_success;
+ }
+ else
+ if (code[16] =3D=3D 0x48 && code[17] =3D=3D 0x87=20
+ && code[18] =3D=3D 0xD2 /* xchgq %rdx,%rdx=
*/) {
+ /* call-noredir *%RAX */
+ DIP("call-noredir *%%rax\n");
+ delta +=3D 19;
+ t1 =3D newTemp(Ity_I64);
+ assign(t1, getIRegRAX(8));
+ t2 =3D newTemp(Ity_I64);
+ assign(t2, binop(Iop_Sub64, getIReg64(R_RSP), mkU64(8)));
+ putIReg64(R_RSP, mkexpr(t2));
+ storeLE( mkexpr(t2), mkU64(guest_RIP_bbstart+delta));
+ jmp_treg(Ijk_NoRedir,t1);
+ dres.whatNext =3D Dis_StopHere;
+ goto decode_success;
+ }
+ /* We don't know what it is. */
+ goto decode_failure;
+ /*NOTREACHED*/
}
}
=20
Modified: branches/FNWRAP/priv/host-amd64/hdefs.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/FNWRAP/priv/host-amd64/hdefs.c 2006-01-07 22:58:54 UTC (rev =
1533)
+++ branches/FNWRAP/priv/host-amd64/hdefs.c 2006-01-10 08:01:07 UTC (rev =
1534)
@@ -2606,6 +2606,9 @@
case Ijk_TInval:
*p++ =3D 0xBD;
p =3D emit32(p, VEX_TRC_JMP_TINVAL); break;
+ case Ijk_NoRedir:
+ *p++ =3D 0xBD;
+ p =3D emit32(p, VEX_TRC_JMP_NOREDIR); break;
case Ijk_Ret:
case Ijk_Call:
case Ijk_Boring:
|