]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Tighten x64 JIT address checks
authorDimitris Panokostas <midwan@gmail.com>
Tue, 19 May 2026 21:48:00 +0000 (23:48 +0200)
committerDimitris Panokostas <midwan@gmail.com>
Tue, 19 May 2026 21:48:00 +0000 (23:48 +0200)
jit/codegen_x86.h

index f2413c58a98b4a9f0fe2334daf7f83bfaf8e034a..49f76f6c3f88023b2518e12673e7c3245dd5798e 100644 (file)
@@ -423,15 +423,15 @@ static inline int x86_RIP_addressing_possible(uintptr addr, uintptr offset)
 #if X86_TARGET_64BIT
        /*
         * address of the next instruction.
-        * The opcode has already been emmitted,
-        * so this is the size of an 32bit displacement +
+        * The opcode has already been emitted,
+        * so this is the size of a 32-bit displacement +
         * the size of any immediate value that is part of the instruction (offset),
         */
-       uintptr dst = (uintptr)get_target() + 4 + offset;
-       intptr disp = dst - addr;
-       int ok = disp >= -0x80000000LL && disp <= 0x7fffffffLL;
-       /* fprintf(stderr, "x86_RIP_addressing_possible: %llx - %llx %16llx = %d\n", (unsigned long long)dst, (unsigned long long)addr, (long long)disp, ok); */
-       return ok;
+       uintptr next = (uintptr)get_target() + 4 + offset;
+       if (addr >= next) {
+               return addr - next <= 0x7fffffffULL;
+       }
+       return next - addr <= 0x80000000ULL;
 #else
        UNUSED(addr);
        UNUSED(offset);
@@ -443,7 +443,7 @@ static inline int x86_RIP_addressing_possible(uintptr addr, uintptr offset)
 static inline int x86_DISP32_addressing_possible(uintptr addr)
 {
 #if X86_TARGET_64BIT
-       return addr <= 0xFFFFFFFFULL;
+       return addr <= 0x7FFFFFFFULL;
 #else
        UNUSED(addr);
        return 1;