From 45d25f8b3860cbaa1cfe4dafd0e9ea2bccee6d19 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Tue, 19 May 2026 23:48:00 +0200 Subject: [PATCH] Tighten x64 JIT address checks --- jit/codegen_x86.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jit/codegen_x86.h b/jit/codegen_x86.h index f2413c58..49f76f6c 100644 --- a/jit/codegen_x86.h +++ b/jit/codegen_x86.h @@ -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; -- 2.47.3