From fb8f8c12d3188a85f57a7f9e3a67ec167868cfe4 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 28 Jun 2015 13:30:17 -0700 Subject: 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 --- backend_x86.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'backend_x86.c') diff --git a/backend_x86.c b/backend_x86.c index f9128ef..63fcdc2 100644 --- a/backend_x86.c +++ b/backend_x86.c @@ -165,11 +165,15 @@ code_ptr gen_mem_fun(cpu_options * opts, memmap_chunk const * memmap, uint32_t n } } 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); -- cgit v1.2.3