From 9bc6cd4ed13ee90c2fa4dfe055c9a25deefd20e0 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 3 Mar 2021 21:19:38 +0100 Subject: A bit more work to prepare x86_64 emulation --- src/emu/x64emu_private.h | 2 +- src/emu/x64run.c | 26 +++++++++++++++++--------- src/wrapped/wrappedlibc.c | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/emu/x64emu_private.h b/src/emu/x64emu_private.h index ed2413f8..aaf25db4 100755 --- a/src/emu/x64emu_private.h +++ b/src/emu/x64emu_private.h @@ -51,7 +51,7 @@ typedef struct x64emu_s { uint64_t res; uint32_t *x86emu_parity_tab; // helper #ifdef HAVE_TRACE - uintptr_t prev2_ip, prev_ip; + uintptr_t prev2_ip; #endif // segments uint32_t segs[6]; // only 32bits value? diff --git a/src/emu/x64run.c b/src/emu/x64run.c index eba4c2d1..96d81976 100755 --- a/src/emu/x64run.c +++ b/src/emu/x64run.c @@ -31,7 +31,7 @@ int Run(x64emu_t *emu, int step) { uint8_t opcode; uint8_t nextop; - reg64_t *oped; + reg64_t *oped, *opgd; uint8_t tmp8u, tmp8u2; int8_t tmp8s; uint16_t tmp16u, tmp16u2; @@ -46,6 +46,7 @@ int Run(x64emu_t *emu, int step) sse_regs_t *opex, eax1; mmx_regs_t *opem, eam1; rex_t rex; + int unimp = 0; if(emu->quit) return 0; @@ -61,24 +62,29 @@ int Run(x64emu_t *emu, int step) #define F64S *(int64_t*)(R_RIP+=8, R_RIP-8) #define PK(a) *(uint8_t*)(R_RIP+a) #ifdef DYNAREC -#define STEP if(step) goto stepout; +#define STEP if(step) return 0; #else #define STEP #endif +#define GETED oped=GetEd(emu, rex, nextop) +#define GETGD opgd=GeG(emu, rex, nextop) +#define ED oped +#define GD opgd + x64emurun: //#include "modrm.h" while(1) { #ifdef HAVE_TRACE __builtin_prefetch((void*)R_RIP, 0, 0); - emu->prev2_ip = emu->prev_ip; - emu->prev_ip = R_RIP; + emu->prev2_ip = emu->old_ip; if(my_context->dec && ( (trace_end == 0) || ((R_RIP >= trace_start) && (R_RIP < trace_end))) ) PrintTrace(emu, R_RIP, 0); #endif + emu->old_ip = R_RIP; opcode = F8; if(opcode>=0x40 && opcode<=0x4f) { @@ -109,16 +115,18 @@ x64emurun: break; default: - UnimpOpcode(emu); + unimp = 1; goto fini; } } -#ifdef DYNAREC -stepout: - return 0; -#endif + fini: + if(unimp) { + R_RIP = emu->old_ip; + emu->quit = 1; + UnimpOpcode(emu); + } // fork handling // if(emu->fork) { // if(step) diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index dbd79dcc..e22e84ce 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -383,7 +383,7 @@ void EXPORT my___stack_chk_fail(x64emu_t* emu) { char buff[200]; #ifdef HAVE_TRACE - sprintf(buff, "%p: Stack is corrupted, aborting (prev IP=%p->%p)\n", (void*)emu->old_ip, (void*)emu->prev2_ip, (void*)emu->prev_ip); + sprintf(buff, "%p: Stack is corrupted, aborting (prev IP=%p)\n", (void*)emu->old_ip, (void*)emu->prev2_ip); #else sprintf(buff, "%p: Stack is corrupted, aborting\n", (void*)emu->old_ip); #endif -- cgit 1.4.1