Mercurial > repos > blastem
comparison backend_x86.c @ 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 | 6677afe78a6f |
children | bf4f1a8d1d48 |
comparison
equal
deleted
inserted
replaced
2338:bc17ece8dd00 | 2339:8990c2f431b1 |
---|---|
225 if (memmap[chunk].flags & MMAP_PTR_IDX) { | 225 if (memmap[chunk].flags & MMAP_PTR_IDX) { |
226 if (memmap[chunk].flags & MMAP_FUNC_NULL) { | 226 if (memmap[chunk].flags & MMAP_FUNC_NULL) { |
227 cmp_irdisp(code, 0, opts->context_reg, opts->mem_ptr_off + sizeof(void*) * memmap[chunk].ptr_index, SZ_PTR); | 227 cmp_irdisp(code, 0, opts->context_reg, opts->mem_ptr_off + sizeof(void*) * memmap[chunk].ptr_index, SZ_PTR); |
228 code_ptr not_null = code->cur + 1; | 228 code_ptr not_null = code->cur + 1; |
229 jcc(code, CC_NZ, code->cur + 2); | 229 jcc(code, CC_NZ, code->cur + 2); |
230 uint32_t stack_off; | |
231 if (need_addr_pop) { | |
232 stack_off = code->stack_off; | |
233 pop_r(code, adr_reg); | |
234 } | |
230 call(code, opts->save_context); | 235 call(code, opts->save_context); |
231 if (is_write) { | 236 if (is_write) { |
232 call_args_abi(code, cfun, 3, opts->scratch2, opts->context_reg, opts->scratch1); | 237 call_args_abi(code, cfun, 3, opts->scratch2, opts->context_reg, opts->scratch1); |
233 mov_rr(code, RAX, opts->context_reg, SZ_PTR); | 238 mov_rr(code, RAX, opts->context_reg, SZ_PTR); |
234 } else { | 239 } else { |
236 call_args_abi(code, cfun, 2, opts->scratch1, opts->context_reg); | 241 call_args_abi(code, cfun, 2, opts->scratch1, opts->context_reg); |
237 pop_r(code, opts->context_reg); | 242 pop_r(code, opts->context_reg); |
238 mov_rr(code, RAX, opts->scratch1, size); | 243 mov_rr(code, RAX, opts->scratch1, size); |
239 } | 244 } |
240 jmp(code, opts->load_context); | 245 jmp(code, opts->load_context); |
246 if (need_addr_pop) { | |
247 code->stack_off = stack_off; | |
248 } | |
241 | 249 |
242 *not_null = code->cur - (not_null + 1); | 250 *not_null = code->cur - (not_null + 1); |
243 } | 251 } |
244 if (size == SZ_B) { | 252 if (size == SZ_B) { |
245 if ((memmap[chunk].flags & MMAP_ONLY_ODD) || (memmap[chunk].flags & MMAP_ONLY_EVEN)) { | 253 if ((memmap[chunk].flags & MMAP_ONLY_ODD) || (memmap[chunk].flags & MMAP_ONLY_EVEN)) { |