changeset 760:656b1fded67f

Fix self modifying code checks on platforms like OS X on which guest RAM ends up at an address unreachable with a 32-bit displacement
author Michael Pavone <pavone@retrodev.com>
date Sun, 28 Jun 2015 13:30:17 -0700
parents c47e1750c264
children ffb8cc5845fa
files backend_x86.c
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/backend_x86.c	Sun Jun 28 10:21:51 2015 -0700
+++ b/backend_x86.c	Sun Jun 28 13:30:17 2015 -0700
@@ -165,11 +165,15 @@
 					}
 				} else {
 					if (is_write) {
-						push_r(code, opts->scratch1);
-						mov_ir(code, (intptr_t)memmap[chunk].buffer, opts->scratch1, SZ_PTR);
-						add_rr(code, opts->scratch1, opts->scratch2, SZ_PTR);
-						pop_r(code, opts->scratch1);
+						push_r(code, opts->scratch2);
+						mov_ir(code, (intptr_t)memmap[chunk].buffer, opts->scratch2, SZ_PTR);
+						add_rdispr(code, RSP, 0, opts->scratch2, SZ_PTR);
 						mov_rrind(code, opts->scratch1, opts->scratch2, tmp_size);
+						if (is_write && (memmap[chunk].flags & MMAP_CODE)) {
+							pop_r(code, opts->scratch2);
+						} else {
+							add_ir(code, sizeof(void*), RSP, SZ_D);
+						}
 					} else {
 						push_r(code, opts->scratch2);
 						mov_ir(code, (intptr_t)memmap[chunk].buffer, opts->scratch2, SZ_PTR);