about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-07-16 17:24:49 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-07-16 17:24:49 +0200
commit886ae378c567181cc44c87e87e6e6c6855fc8edf (patch)
tree396db5a2de7a99586351a281ee7b097da7567c68
parent60d886c052250ba4473ec010d968ea2cea0563fe (diff)
downloadbox64-886ae378c567181cc44c87e87e6e6c6855fc8edf.tar.gz
box64-886ae378c567181cc44c87e87e6e6c6855fc8edf.zip
Changed how TRAPNO 12 is triggered
-rw-r--r--src/libtools/signals.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libtools/signals.c b/src/libtools/signals.c
index b57c522b..7d052c29 100644
--- a/src/libtools/signals.c
+++ b/src/libtools/signals.c
@@ -1140,12 +1140,12 @@ void my_sigactionhandler_oldcode(int32_t sig, int simple, siginfo_t* info, void
             sigcontext->uc_mcontext.gregs[X64_TRAPNO] = ((info->si_code==SEGV_ACCERR) || (info->si_errno==0x1234) || (info->si_errno==0xdead) || ((uintptr_t)info->si_addr==0))?13:14;
         } else if(info->si_code==SEGV_ACCERR && !(prot&PROT_WRITE)) {
             sigcontext->uc_mcontext.gregs[X64_ERR] = 0x0002;    // write flag issue
-            if(labs((intptr_t)info->si_addr-(intptr_t)sigcontext->uc_mcontext.gregs[X64_RSP])<16)
+            sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 14;
+        } else {
+            if((info->si_code!=SEGV_ACCERR) && labs((intptr_t)info->si_addr-(intptr_t)sigcontext->uc_mcontext.gregs[X64_RSP])<16)
                 sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 12; // stack overflow probably
             else
-                sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 14;
-        } else {
-            sigcontext->uc_mcontext.gregs[X64_TRAPNO] = (info->si_code == SEGV_ACCERR)?13:14;
+                sigcontext->uc_mcontext.gregs[X64_TRAPNO] = (info->si_code == SEGV_ACCERR)?13:14;
             //X64_ERR seems to be INT:8 CODE:8. So for write access segfault it's 0x0002 For a read it's 0x0004 (and 8 for exec). For an int 2d it could be 0x2D01 for example
             sigcontext->uc_mcontext.gregs[X64_ERR] = 0x0004;    // read error? there is no execute control in box64 anyway
         }
@@ -1189,6 +1189,7 @@ void my_sigactionhandler_oldcode(int32_t sig, int simple, siginfo_t* info, void
     else if(sig==SIGTRAP)
         sigcontext->uc_mcontext.gregs[X64_TRAPNO] = info->si_code;
     //TODO: SIGABRT generate what?
+    printf_log(LOG_DEBUG, "Signal %d: TRAPNO=%d, ERR=%d, RIP=%p\n", sig, sigcontext->uc_mcontext.gregs[X64_TRAPNO], sigcontext->uc_mcontext.gregs[X64_ERR],sigcontext->uc_mcontext.gregs[X64_RIP]);
     // call the signal handler
     x64_ucontext_t sigcontext_copy = *sigcontext;
     // save old value from emu