diff options
author | Michael Pavone <pavone@retrodev.com> | 2015-06-28 13:30:17 -0700 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2015-06-28 13:30:17 -0700 |
commit | fb8f8c12d3188a85f57a7f9e3a67ec167868cfe4 (patch) | |
tree | 172154e5fed10d3e23184350327f32b13450efdb | |
parent | f345f5d118a45778f46b478f438eb47fc31d6705 (diff) |
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
-rw-r--r-- | backend_x86.c | 12 |
1 files changed, 8 insertions, 4 deletions
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); |