From ad748bfc05bd2578b5ab85dd2e3ce4ab9e6aea1e Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Wed, 27 Aug 2008 13:29:35 +0000 Subject: [PATCH] Fixed CALL range check. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@364 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/x64Emitter.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Source/Core/Common/Src/x64Emitter.cpp b/Source/Core/Common/Src/x64Emitter.cpp index 3c8cecc346..224cc2b806 100644 --- a/Source/Core/Common/Src/x64Emitter.cpp +++ b/Source/Core/Common/Src/x64Emitter.cpp @@ -307,21 +307,15 @@ namespace Gen arg.WriteRest(); } - inline s64 myabs(s64 a) { - if (a < 0) return -a; - return a; - } - void CALL(void *fnptr) { - s64 fn = (s64)fnptr; - s64 c = (s64)code; - if (myabs(fn - c) >= 0x80000000ULL) { - PanicAlert("CALL out of range (%p calls %p)", c, fn); + u64 distance = u64(fnptr) - (u64(code) + 5); + if (distance >= 0x0000000080000000ULL + && distance < 0xFFFFFFFF80000000ULL) { + PanicAlert("CALL out of range (%p calls %p)", code, fnptr); } - s32 distance = (s32)(fn - ((u64)code + 5)); - Write8(0xE8); - Write32(distance); + Write8(0xE8); + Write32(u32(distance)); } void x86SetJ8(u8 *j8)