diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2023-12-05 21:21:34 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2023-12-05 21:21:34 +0100 |
| commit | bdf2922f5d5e4f98731833dc727048a32b514902 (patch) | |
| tree | 8469ef332ab98cb4f26b056143ed686dd2761022 /src | |
| parent | f52d13f86adee09506b74efa679dc1cd2e4548e2 (diff) | |
| download | box64-bdf2922f5d5e4f98731833dc727048a32b514902.tar.gz box64-bdf2922f5d5e4f98731833dc727048a32b514902.zip | |
[INTERPRETER] Added addling to divide by 0 exception
Diffstat (limited to 'src')
| -rw-r--r-- | src/emu/x64run.c | 12 | ||||
| -rw-r--r-- | src/include/signals.h | 1 | ||||
| -rw-r--r-- | src/libtools/signals.c | 23 |
3 files changed, 36 insertions, 0 deletions
diff --git a/src/emu/x64run.c b/src/emu/x64run.c index 7209aa28..b9b6ddf7 100644 --- a/src/emu/x64run.c +++ b/src/emu/x64run.c @@ -1744,9 +1744,13 @@ x64emurun: imul8(emu, EB->byte[0]); break; case 6: /* DIV Eb */ + if(!EB->byte[0]) + emit_div0(emu, (void*)R_RIP, 0); div8(emu, EB->byte[0]); break; case 7: /* IDIV Eb */ + if(!EB->byte[0]) + emit_div0(emu, (void*)R_RIP, 0); idiv8(emu, EB->byte[0]); break; } @@ -1775,9 +1779,13 @@ x64emurun: imul64_rax(emu, ED->q[0]); break; case 6: /* DIV Ed */ + if(!ED->q[0]) + emit_div0(emu, (void*)R_RIP, 0); div64(emu, ED->q[0]); break; case 7: /* IDIV Ed */ + if(!ED->q[0]) + emit_div0(emu, (void*)R_RIP, 0); idiv64(emu, ED->q[0]); break; } @@ -1811,11 +1819,15 @@ x64emurun: emu->regs[_DX].dword[1] = 0; break; case 6: /* DIV Ed */ + if(!ED->dword[0]) + emit_div0(emu, (void*)R_RIP, 0); div32(emu, ED->dword[0]); //emu->regs[_AX].dword[1] = 0; // already put high regs to 0 //emu->regs[_DX].dword[1] = 0; break; case 7: /* IDIV Ed */ + if(!ED->dword[0]) + emit_div0(emu, (void*)R_RIP, 0); idiv32(emu, ED->dword[0]); //emu->regs[_AX].dword[1] = 0; //emu->regs[_DX].dword[1] = 0; diff --git a/src/include/signals.h b/src/include/signals.h index 3fe8a2f7..deda21f7 100644 --- a/src/include/signals.h +++ b/src/include/signals.h @@ -38,5 +38,6 @@ void fini_signal_helper(void); void emit_signal(x64emu_t* emu, int sig, void* addr, int code); void emit_interruption(x64emu_t* emu, int num, void* addr); +void emit_div0(x64emu_t* emu, void* addr, int code); #endif //__SIGNALS_H__ diff --git a/src/libtools/signals.c b/src/libtools/signals.c index 6ed84dc9..2cf6ce6e 100644 --- a/src/libtools/signals.c +++ b/src/libtools/signals.c @@ -1009,6 +1009,10 @@ void my_sigactionhandler_oldcode(int32_t sig, int simple, siginfo_t* info, void } else { sigcontext->uc_mcontext.gregs[X64_ERR] = 0x0a|(int_n<<3); } + } else if(info->si_errno==0xcafe) { + info2->si_errno = 0; + sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 0; + info2->si_signo = SIGFPE; } } else if(sig==SIGFPE) { if (info->si_code == FPE_INTOVF) @@ -1707,6 +1711,25 @@ void emit_interruption(x64emu_t* emu, int num, void* addr) my_sigactionhandler_oldcode(SIGSEGV, 0, &info, NULL, NULL, NULL); } +void emit_div0(x64emu_t* emu, void* addr, int code) +{ + siginfo_t info = {0}; + info.si_signo = SIGSEGV; + info.si_errno = 0xcafe; + info.si_code = code; + info.si_addr = addr; + const char* x64name = NULL; + const char* elfname = NULL; + if(box64_log>LOG_INFO || box64_dynarec_dump || box64_showsegv) { + x64name = getAddrFunctionName(R_RIP); + elfheader_t* elf = FindElfAddress(my_context, R_RIP); + if(elf) + elfname = ElfName(elf); + printf_log(LOG_NONE, "Emit Divide by 0 at IP=%p(%s / %s) / addr=%p\n", (void*)R_RIP, x64name?x64name:"???", elfname?elfname:"?", addr); + } + my_sigactionhandler_oldcode(SIGSEGV, 0, &info, NULL, NULL, NULL); +} + EXPORT sighandler_t my_signal(x64emu_t* emu, int signum, sighandler_t handler) { if(signum<0 || signum>MAX_SIGNAL) |