changeset 2339:8990c2f431b1

Fix crash when function pointer path is taken in MMAP_FUNC_NULL region that also has MMAP_CODE
author Michael Pavone <pavone@retrodev.com>
date Sat, 02 Sep 2023 12:08:43 -0700
parents bc17ece8dd00
children b9cd3c64652d
files backend_x86.c
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/backend_x86.c	Sat Sep 02 10:52:16 2023 -0700
+++ b/backend_x86.c	Sat Sep 02 12:08:43 2023 -0700
@@ -227,6 +227,11 @@
 					cmp_irdisp(code, 0, opts->context_reg, opts->mem_ptr_off + sizeof(void*) * memmap[chunk].ptr_index, SZ_PTR);
 					code_ptr not_null = code->cur + 1;
 					jcc(code, CC_NZ, code->cur + 2);
+					uint32_t stack_off;
+					if (need_addr_pop) {
+						stack_off = code->stack_off;
+						pop_r(code, adr_reg);
+					}
 					call(code, opts->save_context);
 					if (is_write) {
 						call_args_abi(code, cfun, 3, opts->scratch2, opts->context_reg, opts->scratch1);
@@ -238,6 +243,9 @@
 						mov_rr(code, RAX, opts->scratch1, size);
 					}
 					jmp(code, opts->load_context);
+					if (need_addr_pop) {
+						code->stack_off = stack_off;
+					}
 
 					*not_null = code->cur - (not_null + 1);
 				}