diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dynarec/arm64/dynarec_arm64_00.c | 5 | ||||
| -rw-r--r-- | src/dynarec/arm64/dynarec_arm64_functions.c | 1 | ||||
| -rw-r--r-- | src/dynarec/dynarec_native_functions.c | 9 | ||||
| -rw-r--r-- | src/dynarec/la64/dynarec_la64_00.c | 4 | ||||
| -rw-r--r-- | src/dynarec/rv64/dynarec_rv64_00_3.c | 4 | ||||
| -rw-r--r-- | src/emu/x64int3.c | 6 | ||||
| -rw-r--r-- | src/emu/x64run.c | 35 | ||||
| -rw-r--r-- | src/emu/x64run0f.c | 28 | ||||
| -rw-r--r-- | src/emu/x64run660f.c | 8 | ||||
| -rw-r--r-- | src/emu/x64run670f.c | 4 | ||||
| -rw-r--r-- | src/emu/x64runavx0f.c | 6 | ||||
| -rw-r--r-- | src/emu/x64runavx0f38.c | 14 | ||||
| -rw-r--r-- | src/emu/x64runavx660f.c | 4 | ||||
| -rw-r--r-- | src/emu/x64runavx660f38.c | 10 | ||||
| -rw-r--r-- | src/emu/x64runavx660f3a.c | 8 | ||||
| -rw-r--r-- | src/emu/x64runf20f.c | 6 | ||||
| -rw-r--r-- | src/emu/x64syscall.c | 7 | ||||
| -rwxr-xr-x | src/emu/x86int3.c | 6 | ||||
| -rw-r--r-- | src/include/signals.h | 2 | ||||
| -rw-r--r-- | src/include/x64_signals.h | 177 | ||||
| -rw-r--r-- | src/libtools/signal32.c | 32 | ||||
| -rw-r--r-- | src/libtools/signals.c | 106 | ||||
| -rw-r--r-- | src/libtools/threads.c | 4 | ||||
| -rw-r--r-- | src/os/emit_signal_wine.c | 6 | ||||
| -rw-r--r-- | src/os/emit_signals_linux.c | 31 | ||||
| -rwxr-xr-x | src/wrapped32/wrappedlibc.c | 2 |
26 files changed, 366 insertions, 159 deletions
diff --git a/src/dynarec/arm64/dynarec_arm64_00.c b/src/dynarec/arm64/dynarec_arm64_00.c index eac955a7..a547f2a1 100644 --- a/src/dynarec/arm64/dynarec_arm64_00.c +++ b/src/dynarec/arm64/dynarec_arm64_00.c @@ -3,6 +3,7 @@ #include <stddef.h> #include <errno.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64context.h" @@ -2626,9 +2627,9 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin if(!BOX64ENV(ignoreint3)) { // check if TRAP signal is handled TABLE64C(x1, const_context); - MOV32w(x2, offsetof(box64context_t, signals[SIGTRAP])); + MOV32w(x2, offsetof(box64context_t, signals[X64_SIGTRAP])); LDRx_REG(x3, x1, x2); - //LDRx_U12(x3, x1, offsetof(box64context_t, signals[SIGTRAP])); + //LDRx_U12(x3, x1, offsetof(box64context_t, signals[X64_SIGTRAP])); CMPSx_U12(x3, 0); B_MARK(cEQ); GETIP(addr); // update RIP diff --git a/src/dynarec/arm64/dynarec_arm64_functions.c b/src/dynarec/arm64/dynarec_arm64_functions.c index 84832f65..15c0f3f0 100644 --- a/src/dynarec/arm64/dynarec_arm64_functions.c +++ b/src/dynarec/arm64/dynarec_arm64_functions.c @@ -4,7 +4,6 @@ #include <errno.h> #include <string.h> #include <math.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> diff --git a/src/dynarec/dynarec_native_functions.c b/src/dynarec/dynarec_native_functions.c index 4c87385a..bb696ac2 100644 --- a/src/dynarec/dynarec_native_functions.c +++ b/src/dynarec/dynarec_native_functions.c @@ -7,6 +7,7 @@ #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64context.h" @@ -186,20 +187,20 @@ void native_ud(x64emu_t* emu) { if(BOX64ENV(dynarec_test)) emu->test.test = 0; - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); } void native_br(x64emu_t* emu) { if(BOX64ENV(dynarec_test)) emu->test.test = 0; - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xb09d); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xb09d); } void native_priv(x64emu_t* emu) { emu->test.test = 0; - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); } void native_int(x64emu_t* emu, int num) @@ -216,7 +217,7 @@ void native_wineint(x64emu_t* emu, int num) #endif void native_int3(x64emu_t* emu) { - EmitSignal(emu, SIGTRAP, NULL, 3); + EmitSignal(emu, X64_SIGTRAP, NULL, 3); } void native_div0(x64emu_t* emu) diff --git a/src/dynarec/la64/dynarec_la64_00.c b/src/dynarec/la64/dynarec_la64_00.c index 23fd9004..556ccd34 100644 --- a/src/dynarec/la64/dynarec_la64_00.c +++ b/src/dynarec/la64/dynarec_la64_00.c @@ -2,8 +2,8 @@ #include <stdlib.h> #include <stddef.h> #include <errno.h> -#include <signal.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64context.h" @@ -1997,7 +1997,7 @@ uintptr_t dynarec64_00(dynarec_la64_t* dyn, uintptr_t addr, uintptr_t ip, int ni if (!BOX64ENV(ignoreint3)) { // check if TRAP signal is handled TABLE64C(x1, const_context); - MOV32w(x2, offsetof(box64context_t, signals[SIGTRAP])); + MOV32w(x2, offsetof(box64context_t, signals[X64_SIGTRAP])); LDX_D(x3, x1, x2); BEQZ_MARK(x3); GETIP(addr, x7); diff --git a/src/dynarec/rv64/dynarec_rv64_00_3.c b/src/dynarec/rv64/dynarec_rv64_00_3.c index 924f3e36..654805aa 100644 --- a/src/dynarec/rv64/dynarec_rv64_00_3.c +++ b/src/dynarec/rv64/dynarec_rv64_00_3.c @@ -2,9 +2,9 @@ #include <stdlib.h> #include <stddef.h> #include <errno.h> -#include <signal.h> #include <assert.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64context.h" @@ -482,7 +482,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int if (!BOX64ENV(ignoreint3)) { // check if TRAP signal is handled TABLE64C(x1, const_context); - MOV32w(x2, offsetof(box64context_t, signals[SIGTRAP])); + MOV32w(x2, offsetof(box64context_t, signals[X64_SIGTRAP])); ADD(x2, x2, x1); LD(x3, x2, 0); BEQZ_MARK(x3); diff --git a/src/emu/x64int3.c b/src/emu/x64int3.c index 1e9d2376..f79a451d 100644 --- a/src/emu/x64int3.c +++ b/src/emu/x64int3.c @@ -8,11 +8,11 @@ #include <unistd.h> #include <sys/types.h> #include <pthread.h> -#include <signal.h> #include <poll.h> #include <sys/wait.h> #include <elf.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -395,9 +395,9 @@ void x64Int3(x64emu_t* emu, uintptr_t* addr) printf_log(LOG_DEBUG, "%04d|Warning, x64int3 with no CC opcode at %p?\n", GetTID(), (void*)R_RIP); return; } - if(!BOX64ENV(ignoreint3) && my_context->signals[SIGTRAP]) { + if(!BOX64ENV(ignoreint3) && my_context->signals[X64_SIGTRAP]) { R_RIP = *addr; // update RIP - EmitSignal(emu, SIGTRAP, NULL, 3); + EmitSignal(emu, X64_SIGTRAP, NULL, 3); } else { printf_log(LOG_DEBUG, "%04d|Warning, ignoring unsupported Int 3 call @%p\n", GetTID(), (void*)R_RIP); R_RIP = *addr; diff --git a/src/emu/x64run.c b/src/emu/x64run.c index af2bc58f..a393e84c 100644 --- a/src/emu/x64run.c +++ b/src/emu/x64run.c @@ -7,6 +7,7 @@ #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -333,7 +334,7 @@ x64emurun: if(rex.is32bits) { R_AX = aas16(emu, R_AX); } else { - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); goto fini; } break; @@ -433,7 +434,7 @@ x64emurun: GETGD; int* bounds = (int*)GETEA(0); if(bounds[0]<GD->dword[0] || bounds[1]>GD->dword[0]) - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xb09d); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xb09d); } else { unimp = 1; goto fini; @@ -592,7 +593,7 @@ x64emurun: if(rex.is32bits && BOX64ENV(ignoreint3)) { } else { - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); } STEP; #endif @@ -1562,7 +1563,7 @@ x64emurun: } else if (tmp8u==0x03) { R_RIP = addr; #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGTRAP, NULL, 3); + EmitSignal(emu, X64_SIGTRAP, NULL, 3); STEP2; #endif } else { @@ -1598,7 +1599,7 @@ x64emurun: if((new_cs&3)!=3) { printf_log(LOG_NONE, "Warning, unexpected new_cs=0x%x\n", new_cs); R_RSP-=(rex.w?4:8)*2; - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0); // GP if trying to change priv level + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0); // GP if trying to change priv level } #endif RESET_FLAGS(emu); @@ -1878,7 +1879,7 @@ x64emurun: F8; if(rex.is32bits && BOX64ENV(ignoreint3)) {} else - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); STEP; #endif break; @@ -1918,7 +1919,7 @@ x64emurun: #ifndef TEST_INTERPRETER if(rex.is32bits && BOX64ENV(ignoreint3)) {} else - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); STEP; #endif break; @@ -1940,14 +1941,14 @@ x64emurun: case 0xF1: /* INT1 */ emu->old_ip = R_RIP; #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 128); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 128); #endif break; case 0xF4: /* HLT */ // this is a privilege opcode... #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); STEP; #endif break; @@ -2093,14 +2094,14 @@ x64emurun: // this is a privilege opcode if(rex.is32bits && BOX64ENV(ignoreint3)) {} else - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); STEP; break; case 0xFB: /* STI */ // this is a privilege opcode if(rex.is32bits && BOX64ENV(ignoreint3)) {} else - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); STEP; break; case 0xFC: /* CLD */ @@ -2167,7 +2168,7 @@ x64emurun: GETET(0); if(MODREG) { printf_log(LOG_NONE, "Illegal Opcode %p: (%02X %02X %02X %02X) %02X %02X %02X %02X\n", (void*)R_RIP, PK(-6), PK(-5), PK(-4), PK(-3), opcode, nextop, PK(0), PK(1)); - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); goto fini; } else { if(rex.is32bits || !rex.w) { @@ -2216,7 +2217,7 @@ x64emurun: GETET(0); if(MODREG) { printf_log(LOG_NONE, "Illegal Opcode %p: (%02X %02X %02X %02X) %02X %02X %02X %02X\n", (void*)R_RIP, PK(-6), PK(-5), PK(-4), PK(-3), opcode, nextop, PK(0), PK(1)); - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); goto fini; } else { if(rex.is32bits || !rex.w) { @@ -2260,7 +2261,7 @@ x64emurun: break; default: printf_log(LOG_NONE, "Illegal Opcode %p: (%02X %02X %02X %02X) %02X %02X %02X %02X %02X %02X\n", (void*)R_RIP, PK(-6), PK(-5), PK(-4), PK(-3), opcode, nextop, PK(0), PK(1), PK(2), PK(3)); - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); goto fini; } break; @@ -2276,7 +2277,7 @@ x64emurun: } else { tf_next = 0; R_RIP = addr; - EmitSignal(emu, SIGTRAP, (void*)addr, 1); + EmitSignal(emu, X64_SIGTRAP, (void*)addr, 1); if(emu->quit) goto fini; } } @@ -2290,7 +2291,7 @@ fini: // check the TRACE flag before going to out, in case it's a step by step scenario if(!emu->quit && !emu->fork && ACCESS_FLAG(F_TF)) { R_RIP = addr; - EmitSignal(emu, SIGTRAP, (void*)addr, 1); + EmitSignal(emu, X64_SIGTRAP, (void*)addr, 1); if(emu->quit) goto fini; } #endif @@ -2300,7 +2301,7 @@ if(emu->segs[_CS]!=0x33 && emu->segs[_CS]!=0x23) printf_log(LOG_NONE, "Warning, if(unimp) { //emu->quit = 1; UnimpOpcode(emu, is32bits); - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); } // fork handling if(emu->fork) { diff --git a/src/emu/x64run0f.c b/src/emu/x64run0f.c index 92de2706..046861da 100644 --- a/src/emu/x64run0f.c +++ b/src/emu/x64run0f.c @@ -5,10 +5,10 @@ #include <math.h> #include <fenv.h> #include <string.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -96,19 +96,19 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) case 0xC8: /* MONITOR */ // this is a privilege opcode... #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0); #endif break; case 0xC9: /* MWAIT */ // this is a privilege opcode... #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0); #endif break; case 0xD0: if(R_RCX) { #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); #endif } else { R_RAX = 0b111; // x87 & SSE & AVX for now @@ -185,7 +185,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) case 0x06: /* CLTS */ // this is a privilege opcode... #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0); #endif break; @@ -193,13 +193,13 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) case 0x09: /* WBINVD */ // this is a privilege opcode... #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0); #endif break; case 0x0B: /* UD2 */ #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); #endif break; @@ -222,7 +222,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) break; case 0x0E: /* FEMMS */ #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); #endif break; @@ -312,7 +312,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) case 0x23: /* MOV drX, REG */ // this is a privilege opcode... #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0); #endif break; @@ -413,7 +413,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) case 0x30: /* WRMSR */ // this is a privilege opcode... #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0); #endif break; case 0x31: /* RDTSC */ @@ -426,20 +426,20 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) case 0x32: /* RDMSR */ // priviledge instruction #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); STEP; #endif break; case 0x34: /* SYSENTER */ #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); STEP; #endif break; case 0x35: /* SYSEXIT */ #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0xbad0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0xbad0); STEP; #endif break; @@ -713,7 +713,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) case 0x3F: #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); #endif break; GOCOND(0x40 diff --git a/src/emu/x64run660f.c b/src/emu/x64run660f.c index 5129bc7b..c3405bc5 100644 --- a/src/emu/x64run660f.c +++ b/src/emu/x64run660f.c @@ -5,10 +5,10 @@ #include <math.h> #include <fenv.h> #include <string.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -720,7 +720,7 @@ uintptr_t Run660F(x64emu_t *emu, rex_t rex, uintptr_t addr) GETED(0); // this is a privilege opcode... #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGSEGV, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGSEGV, (void*)R_RIP, 0); #endif break; @@ -1700,7 +1700,7 @@ uintptr_t Run660F(x64emu_t *emu, rex_t rex, uintptr_t addr) nextop = F8; if(!BOX64ENV(cputype) || (nextop&0xC0)>>3) { #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); #endif } else { //TODO: test /0 @@ -1716,7 +1716,7 @@ uintptr_t Run660F(x64emu_t *emu, rex_t rex, uintptr_t addr) nextop = F8; if(!BOX64ENV(cputype) || !(MODREG)) { #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); #endif } else { //TODO: test/r diff --git a/src/emu/x64run670f.c b/src/emu/x64run670f.c index 870c8fac..54fe8808 100644 --- a/src/emu/x64run670f.c +++ b/src/emu/x64run670f.c @@ -4,10 +4,10 @@ #include <stdlib.h> #include <math.h> #include <string.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -189,7 +189,7 @@ uintptr_t Run670F(x64emu_t *emu, rex_t rex, int rep, uintptr_t addr) nextop = F8; FAKEED32(0); #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); #endif break; default: diff --git a/src/emu/x64runavx0f.c b/src/emu/x64runavx0f.c index 934bed34..9093de3c 100644 --- a/src/emu/x64runavx0f.c +++ b/src/emu/x64runavx0f.c @@ -5,10 +5,10 @@ #include <math.h> #include <fenv.h> #include <string.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -604,13 +604,13 @@ uintptr_t RunAVX_0F(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) case 0x77: if(!vex.l) { // VZEROUPPER if(vex.v!=0) { - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); } else { memset(emu->ymm, 0, sizeof(sse_regs_t)*((vex.rex.is32bits)?8:16)); } } else { // VZEROALL if(vex.v!=0) { - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); } else { memset(emu->xmm, 0, sizeof(sse_regs_t)*((vex.rex.is32bits)?8:16)); memset(emu->ymm, 0, sizeof(sse_regs_t)*((vex.rex.is32bits)?8:16)); diff --git a/src/emu/x64runavx0f38.c b/src/emu/x64runavx0f38.c index a96b8f6b..a17b2e75 100644 --- a/src/emu/x64runavx0f38.c +++ b/src/emu/x64runavx0f38.c @@ -5,10 +5,10 @@ #include <math.h> #include <fenv.h> #include <string.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -61,7 +61,7 @@ uintptr_t RunAVX_0F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) case 0xF2: /* ANDN Gd, Vd, Ed */ nextop = F8; - if(vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); ResetFlags(emu); GETGD; GETED(0); @@ -81,7 +81,7 @@ uintptr_t RunAVX_0F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) nextop = F8; switch((nextop>>3)&7) { case 1: /* BLSR Vd, Ed */ - if(vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); ResetFlags(emu); GETVD; GETED(0); @@ -101,7 +101,7 @@ uintptr_t RunAVX_0F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) } break; case 2: /* BLSMSK Vd, Ed */ - if(vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); ResetFlags(emu); GETVD; GETED(0); @@ -122,7 +122,7 @@ uintptr_t RunAVX_0F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) } break; case 3: /* BLSI Vd, Ed */ - if(vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); ResetFlags(emu); GETVD; GETED(0); @@ -151,7 +151,7 @@ uintptr_t RunAVX_0F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) case 0xF5: /* BZHI Gd, Ed, Vd */ nextop = F8; - if(vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); GETGD; GETED(0); GETVD; @@ -179,7 +179,7 @@ uintptr_t RunAVX_0F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) case 0xF7: /* BEXTR Gd, Ed, Vd */ nextop = F8; - if(vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); ResetFlags(emu); GETGD; GETED(0); diff --git a/src/emu/x64runavx660f.c b/src/emu/x64runavx660f.c index b08a5f6c..5570a979 100644 --- a/src/emu/x64runavx660f.c +++ b/src/emu/x64runavx660f.c @@ -5,10 +5,10 @@ #include <math.h> #include <fenv.h> #include <string.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -1956,7 +1956,7 @@ uintptr_t RunAVX_660F(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) case 0xF7: /* VMASKMOVDQU Gx, Ex */ nextop = F8; if(vex.l) { - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); } GETEX(0); GETGX; diff --git a/src/emu/x64runavx660f38.c b/src/emu/x64runavx660f38.c index 3d83d513..42e61f32 100644 --- a/src/emu/x64runavx660f38.c +++ b/src/emu/x64runavx660f38.c @@ -5,10 +5,10 @@ #include <math.h> #include <fenv.h> #include <string.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -539,7 +539,7 @@ uintptr_t RunAVX_660F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) GETEY; GETGY; GETVY; - if(!vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(!vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); if(GX==EX) { eax1 = *EX; EX = &eax1; @@ -992,7 +992,7 @@ uintptr_t RunAVX_660F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) GETEY; GETGY; GETVY; - if(!vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(!vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); if(GX==EX) { eax1 = *EX; EX = &eax1; @@ -1388,7 +1388,7 @@ uintptr_t RunAVX_660F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) case 0x92: /* VGATHERDPD/VGATHERDPS Gx, VSIB, Vx */ nextop = F8; if(((nextop&7)!=4) || MODREG) { - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); } GETGX; GETVX; @@ -1455,7 +1455,7 @@ uintptr_t RunAVX_660F38(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) case 0x93: /* VGATHERQPD/VGATHERQPS Gx, VSIB, Vx */ nextop = F8; if(((nextop&7)!=4) || MODREG) { - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); } GETGX; GETVX; diff --git a/src/emu/x64runavx660f3a.c b/src/emu/x64runavx660f3a.c index 5c4292e9..42dcaf79 100644 --- a/src/emu/x64runavx660f3a.c +++ b/src/emu/x64runavx660f3a.c @@ -5,10 +5,10 @@ #include <math.h> #include <fenv.h> #include <string.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -99,7 +99,7 @@ uintptr_t RunAVX_660F3A(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) GETGY; GETEY; u8 = F8; - if(!vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(!vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); if(GX==EX) { eax1 = *EX; EX = &eax1; @@ -184,7 +184,7 @@ uintptr_t RunAVX_660F3A(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) GETGY; GETVY; u8 = F8; - if(!vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(!vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); if(GX==EX) { eax1 = *EX; EX = &eax1; @@ -767,7 +767,7 @@ uintptr_t RunAVX_660F3A(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step) GETGY; GETVY; u8 = F8; - if(!vex.l) EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + if(!vex.l) EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); if(GX==EX) { eax1 = *EX; EX = &eax1; diff --git a/src/emu/x64runf20f.c b/src/emu/x64runf20f.c index 094499cf..1d1f080b 100644 --- a/src/emu/x64runf20f.c +++ b/src/emu/x64runf20f.c @@ -5,10 +5,10 @@ #include <math.h> #include <fenv.h> #include <string.h> -#include <signal.h> #include <sys/types.h> #include <unistd.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -301,7 +301,7 @@ uintptr_t RunF20F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) nextop = F8; if(!BOX64ENV(cputype) || !(MODREG)) { #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); #endif } else { //TODO: test /r @@ -319,7 +319,7 @@ uintptr_t RunF20F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step) nextop = F8; if(!BOX64ENV(cputype) || !(MODREG)) { #ifndef TEST_INTERPRETER - EmitSignal(emu, SIGILL, (void*)R_RIP, 0); + EmitSignal(emu, X64_SIGILL, (void*)R_RIP, 0); #endif } else { //TODO: test /r diff --git a/src/emu/x64syscall.c b/src/emu/x64syscall.c index 3392cdcc..7ca489c3 100644 --- a/src/emu/x64syscall.c +++ b/src/emu/x64syscall.c @@ -22,6 +22,7 @@ #include <poll.h> #include <sys/epoll.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -447,9 +448,9 @@ void EXPORT x64Syscall(x64emu_t *emu) if(box64_wine && !box64_is32bits) { //64bits only here... uintptr_t ret_addr = R_RIP-2; - if(/*ret_addr<0x700000000000LL &&*/ (my_context->signals[SIGSYS]>2) && !FindElfAddress(my_context, ret_addr)) { + if(/*ret_addr<0x700000000000LL &&*/ (my_context->signals[X64_SIGSYS]>2) && !FindElfAddress(my_context, ret_addr)) { // not a linux elf, not a syscall to setup x86_64 arch. Signal SIGSYS - EmitSignal(emu, SIGSYS, (void*)ret_addr, R_EAX&0xffff); // what are the parameters? + EmitSignal(emu, X64_SIGSYS, (void*)ret_addr, R_EAX&0xffff); // what are the parameters? return; } } @@ -825,6 +826,7 @@ void EXPORT x64Syscall(x64emu_t *emu) case 282: // sys_signalfd // need to mask SIGSEGV { + //TODO: convert the sigset from x64! sigset_t * set = (sigset_t *)R_RSI; if(sigismember(set, SIGSEGV)) { sigdelset(set, SIGSEGV); @@ -1132,6 +1134,7 @@ long EXPORT my_syscall(x64emu_t *emu) case 282: // sys_signalfd // need to mask SIGSEGV { + //TODO: convert sigset from x64 sigset_t * set = (sigset_t *)R_RDX; if(sigismember(set, SIGSEGV)) { sigdelset(set, SIGSEGV); diff --git a/src/emu/x86int3.c b/src/emu/x86int3.c index 72d218bb..15f5edc0 100755 --- a/src/emu/x86int3.c +++ b/src/emu/x86int3.c @@ -9,9 +9,9 @@ #include <sys/syscall.h> #include <sys/types.h> #include <pthread.h> -#include <signal.h> #include <inttypes.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64stack.h" @@ -484,9 +484,9 @@ void x86Int3(x64emu_t* emu, uintptr_t* addr) } return; } - if(!BOX64ENV(ignoreint3) && my_context->signals[SIGTRAP]) { + if(!BOX64ENV(ignoreint3) && my_context->signals[X64_SIGTRAP]) { R_RIP = *addr; // update RIP - EmitSignal(emu, SIGTRAP, NULL, 3); + EmitSignal(emu, X64_SIGTRAP, NULL, 3); } else { printf_log(LOG_DEBUG, "%04d|Warning, ignoring unsupported Int 3 call @%p\n", GetTID(), (void*)R_RIP); R_RIP = *addr; diff --git a/src/include/signals.h b/src/include/signals.h index 497a5310..9c8bba19 100644 --- a/src/include/signals.h +++ b/src/include/signals.h @@ -1,8 +1,8 @@ #ifndef __SIGNALS_H__ #define __SIGNALS_H__ #include <stdint.h> -#include <signal.h> +#include "x64_signals.h" #include "box64context.h" typedef void (*sighandler_t)(int); diff --git a/src/include/x64_signals.h b/src/include/x64_signals.h new file mode 100644 index 00000000..08583b91 --- /dev/null +++ b/src/include/x64_signals.h @@ -0,0 +1,177 @@ +#ifndef __X64_SIGNALS_H__ +#define __X64_SIGNALS_H__ + +#include <signal.h> + +#define X64_SIGHUP 1 +#define X64_SIGINT 2 +#define X64_SIGQUIT 3 +#define X64_SIGILL 4 +#define X64_SIGTRAP 5 +#define X64_SIGABRT 6 +#define X64_SIGIOT 6 +#define X64_SIGBUS 7 +#define X64_SIGFPE 8 +#define X64_SIGKILL 9 +#define X64_SIGUSR1 10 +#define X64_SIGSEGV 11 +#define X64_SIGUSR2 12 +#define X64_SIGPIPE 13 +#define X64_SIGALRM 14 +#define X64_SIGTERM 15 +#define X64_SIGSTKFLT 16 +#define X64_SIGCHLD 17 +#define X64_SIGCONT 18 +#define X64_SIGSTOP 19 +#define X64_SIGTSTP 20 +#define X64_SIGTTIN 21 +#define X64_SIGTTOU 22 +#define X64_SIGURG 23 +#define X64_SIGXCPU 24 +#define X64_SIGXFSZ 25 +#define X64_SIGVTALRM 26 +#define X64_SIGPROF 27 +#define X64_SIGWINCH 28 +#define X64_SIGIO 29 +#define X64_SIGPWR 30 +#define X64_SIGSYS 31 + +#if !defined(NEED_SIG_CONV) && X64_SIGHUP != SIGHUP + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGINT != SIGINT + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGQUIT != SIGQUIT + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGILL != SIGILL + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGTRAP != SIGTRAP + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGABRT != SIGABRT + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGIOT != SIGIOT + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGBUS != SIGBUS + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGFPE != SIGFPE + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGKILL != SIGKILL + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGUSR1 != SIGUSR1 + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGSEGV != SIGSEGV + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGUSR2 != SIGUSR2 + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGPIPE != SIGPIPE + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGALRM != SIGALRM + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGTERM != SIGTERM + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGSTKFLT != SIGSTKFLT + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGCHLD != SIGCHLD + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGCONT != SIGCONT + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGSTOP != SIGSTOP + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGTSTP != SIGTSTP + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGTTIN != SIGTTIN + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGTTOU != SIGTTOU + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGURG != SIGURG + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGXCPU != SIGXCPU + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGXFSZ != SIGXFSZ + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGVTALRM != SIGVTALRM + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGPROF != SIGPROF + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGWINCH != SIGWINCH + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGIO != SIGIO + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGPWR != SIGPWR + #define NEED_SIG_CONV +#endif +#if !defined(NEED_SIG_CONV) && X64_SIGSYS != SIGSYS + #define NEED_SIG_CONV +#endif + +#ifdef NEED_SIG_CONV +int signal_to_x64(int sig); +int signal_from_x64(int sig); +#define SUPER_SIGNAL \ +GO(SIGHUP) \ +GO(SIGINT) \ +GO(SIGQUIT) \ +GO(SIGILL) \ +GO(SIGTRAP) \ +GO(SIGABRT) \ +GO(SIGIOT) \ +GO(SIGBUS) \ +GO(SIGFPE) \ +GO(SIGKILL) \ +GO(SIGUSR1) \ +GO(SIGSEGV) \ +GO(SIGUSR2) \ +GO(SIGPIPE) \ +GO(SIGALRM) \ +GO(SIGTERM) \ +GO(SIGSTKFLT) \ +GO(SIGCHLD) \ +GO(SIGCONT) \ +GO(SIGSTOP) \ +GO(SIGTSTP) \ +GO(SIGTTIN) \ +GO(SIGTTOU) \ +GO(SIGURG) \ +GO(SIGXCPU) \ +GO(SIGXFSZ) \ +GO(SIGVTALRM) \ +GO(SIGPROF) \ +GO(SIGWINCH) \ +GO(SIGIO) \ +GO(SIGPWR) \ +GO(SIGSYS) +#else +#define signal_to_x64(A) A +#define signal_from_x64(A) A +#endif + +#endif //__X64_SIGNALS_H__ \ No newline at end of file diff --git a/src/libtools/signal32.c b/src/libtools/signal32.c index d34cff1f..11dd55e6 100644 --- a/src/libtools/signal32.c +++ b/src/libtools/signal32.c @@ -2,7 +2,6 @@ #include <stdlib.h> #include <stdio.h> #include <stdint.h> -#include <signal.h> #include <errno.h> #include <string.h> #include <unistd.h> @@ -17,6 +16,7 @@ #include <execinfo.h> #endif +#include "x64_signals.h" #include "os.h" #include "box32context.h" #include "debug.h" @@ -466,9 +466,9 @@ void convert_siginfo_to_32(void* d, void* s, int sig) siginfo_t* src = s; memcpy(dst, src, sizeof(my_siginfo32_t)); - if(sig==SIGILL || sig==SIGFPE || sig==SIGSEGV || sig==SIGBUS) + if(sig==X64_SIGILL || sig==X64_SIGFPE || sig==X64_SIGSEGV || sig==X64_SIGBUS) dst->_sifields._sigfault.__si_addr = to_ptrv(src->si_addr); - if(sig==SIGCHLD) { + if(sig==X64_SIGCHLD) { dst->_sifields._sigchld.__si_pid = src->si_pid; dst->_sifields._sigchld.__si_uid = src->si_uid; dst->_sifields._sigchld.__si_status = src->si_status; @@ -486,7 +486,7 @@ int write_opcode(uintptr_t rip, uintptr_t native_ip, int is32bits); void my_sigactionhandler_oldcode_32(x64emu_t* emu, int32_t sig, int simple, siginfo_t* info, void * ucntx, int* old_code, void* cur_db) { int Locks = unlockMutex(); - int log_minimum = (BOX64ENV(showsegv))?LOG_NONE:((sig==SIGSEGV && my_context->is_sigaction[sig])?LOG_DEBUG:LOG_INFO); + int log_minimum = (BOX64ENV(showsegv))?LOG_NONE:((sig==X64_SIGSEGV && my_context->is_sigaction[sig])?LOG_DEBUG:LOG_INFO); printf_log(LOG_DEBUG, "Sigactionhanlder32 for signal #%d called (jump to %p/%s)\n", sig, (void*)my_context->signals[sig], GetNativeName((void*)my_context->signals[sig])); @@ -600,9 +600,9 @@ void my_sigactionhandler_oldcode_32(x64emu_t* emu, int32_t sig, int simple, sigi if(prot&PROT_DYNAREC) real_prot|=PROT_WRITE; sigcontext->uc_mcontext.gregs[I386_ERR] = 0; sigcontext->uc_mcontext.gregs[I386_TRAPNO] = 0; - if(sig==SIGBUS) + if(sig==X64_SIGBUS) sigcontext->uc_mcontext.gregs[I386_TRAPNO] = 17; - else if(sig==SIGSEGV) { + else if(sig==X64_SIGSEGV) { if((uintptr_t)info->si_addr == sigcontext->uc_mcontext.gregs[I386_EIP]) { if(info->si_errno==0xbad0) { //bad opcode @@ -642,7 +642,7 @@ void my_sigactionhandler_oldcode_32(x64emu_t* emu, int32_t sig, int simple, sigi // some special cases... if(int_n==3) { - info2->si_signo = SIGTRAP; + info2->si_signo = X64_SIGTRAP; sigcontext->uc_mcontext.gregs[I386_TRAPNO] = 3; sigcontext->uc_mcontext.gregs[I386_ERR] = 0; } else if(int_n==0x04) { @@ -658,17 +658,17 @@ void my_sigactionhandler_oldcode_32(x64emu_t* emu, int32_t sig, int simple, sigi info2->si_errno = 0; sigcontext->uc_mcontext.gregs[I386_ERR] = 0; sigcontext->uc_mcontext.gregs[I386_TRAPNO] = 0; - info2->si_signo = SIGFPE; + info2->si_signo = X64_SIGFPE; } - } else if(sig==SIGFPE) { + } else if(sig==X64_SIGFPE) { if (info->si_code == FPE_INTOVF) sigcontext->uc_mcontext.gregs[I386_TRAPNO] = 4; else sigcontext->uc_mcontext.gregs[I386_TRAPNO] = 19; - } else if(sig==SIGILL) { + } else if(sig==X64_SIGILL) { info2->si_code = 2; sigcontext->uc_mcontext.gregs[I386_TRAPNO] = 6; - } else if(sig==SIGTRAP) { + } else if(sig==X64_SIGTRAP) { if(info->si_code==1) { //single step info2->si_code = 2; info2->_sifields._sigfault.__si_addr = sigcontext->uc_mcontext.gregs[I386_EIP]; @@ -699,7 +699,7 @@ void my_sigactionhandler_oldcode_32(x64emu_t* emu, int32_t sig, int simple, sigi int ret; int dynarec = 0; #ifdef DYNAREC - if(sig!=SIGSEGV && !(Locks&is_dyndump_locked) && !(Locks&is_memprot_locked)) + if(sig!=X64_SIGSEGV && !(Locks&is_dyndump_locked) && !(Locks&is_memprot_locked)) dynarec = 1; #endif ret = RunFunctionHandler32(&exits, dynarec, sigcontext, my_context->signals[info2->si_signo], 3, info2->si_signo, info2, sigcontext); @@ -825,10 +825,10 @@ EXPORT int my32_sigaction(x64emu_t* emu, int signum, const i386_sigaction_t *act return -1; } - if(signum==SIGSEGV && emu->context->no_sigsegv) + if(signum==X64_SIGSEGV && emu->context->no_sigsegv) return 0; - if(signum==SIGILL && emu->context->no_sigill) + if(signum==X64_SIGILL && emu->context->no_sigill) return 0; struct sigaction newact = {0}; struct sigaction old = {0}; @@ -856,8 +856,8 @@ EXPORT int my32_sigaction(x64emu_t* emu, int signum, const i386_sigaction_t *act my_context->onstack[signum] = (act->sa_flags&SA_ONSTACK)?1:0; } int ret = 0; - if(signum!=SIGSEGV && signum!=SIGBUS && signum!=SIGILL && signum!=SIGABRT) - ret = sigaction(signum, act?&newact:NULL, oldact?&old:NULL); + if(signum!=X64_SIGSEGV && signum!=X64_SIGBUS && signum!=X64_SIGILL && signum!=X64_SIGABRT) + ret = sigaction(signal_from_x64(signum), act?&newact:NULL, oldact?&old:NULL); if(oldact) { oldact->sa_flags = old.sa_flags; oldact->sa_mask = old.sa_mask; diff --git a/src/libtools/signals.c b/src/libtools/signals.c index dc805a59..efa20c67 100644 --- a/src/libtools/signals.c +++ b/src/libtools/signals.c @@ -2,7 +2,6 @@ #include <stdlib.h> #include <stdio.h> #include <stdint.h> -#include <signal.h> #include <errno.h> #include <string.h> #include <unistd.h> @@ -17,6 +16,7 @@ #include <execinfo.h> #endif +#include "x64_signals.h" #include "os.h" #include "backtrace.h" #include "box64context.h" @@ -996,9 +996,9 @@ void my_sigactionhandler_oldcode_64(x64emu_t* emu, int32_t sig, int simple, sigi if(prot&PROT_DYNAREC) real_prot|=PROT_WRITE; sigcontext->uc_mcontext.gregs[X64_ERR] = 0; sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 0; - if(sig==SIGBUS) + if(sig==X64_SIGBUS) sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 17; - else if(sig==SIGSEGV) { + else if(sig==X64_SIGSEGV) { if((uintptr_t)info->si_addr == sigcontext->uc_mcontext.gregs[X64_RIP]) { if(info->si_errno==0xbad0) { //bad opcode @@ -1041,7 +1041,7 @@ void my_sigactionhandler_oldcode_64(x64emu_t* emu, int32_t sig, int simple, sigi sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 13; // some special cases... if(int_n==3) { - info2->si_signo = SIGTRAP; + info2->si_signo = X64_SIGTRAP; sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 3; sigcontext->uc_mcontext.gregs[X64_ERR] = 0; } else if(int_n==0x04) { @@ -1057,17 +1057,17 @@ void my_sigactionhandler_oldcode_64(x64emu_t* emu, int32_t sig, int simple, sigi info2->si_errno = 0; sigcontext->uc_mcontext.gregs[X64_ERR] = 0; sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 0; - info2->si_signo = SIGFPE; + info2->si_signo = X64_SIGFPE; } - } else if(sig==SIGFPE) { + } else if(sig==X64_SIGFPE) { if (info->si_code == FPE_INTOVF) sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 4; else sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 19; - } else if(sig==SIGILL) { + } else if(sig==X64_SIGILL) { info2->si_code = 2; sigcontext->uc_mcontext.gregs[X64_TRAPNO] = 6; - } else if(sig==SIGTRAP) { + } else if(sig==X64_SIGTRAP) { if(info->si_code==1) { //single step info2->si_code = 2; info2->si_addr = (void*)sigcontext->uc_mcontext.gregs[X64_RIP]; @@ -1104,7 +1104,7 @@ void my_sigactionhandler_oldcode_64(x64emu_t* emu, int32_t sig, int simple, sigi int ret; int dynarec = 0; #ifdef DYNAREC - if(sig!=SIGSEGV && !(Locks&is_dyndump_locked) && !(Locks&is_memprot_locked)) + if(sig!=X64_SIGSEGV && !(Locks&is_dyndump_locked) && !(Locks&is_memprot_locked)) dynarec = 1; #endif ret = RunFunctionHandler(emu, &exits, dynarec, sigcontext, my_context->signals[info2->si_signo], 3, info2->si_signo, info2, sigcontext); @@ -1333,8 +1333,9 @@ extern int box64_exit_code; void my_box64signalhandler(int32_t sig, siginfo_t* info, void * ucntx) { - // sig==SIGSEGV || sig==SIGBUS || sig==SIGILL || sig==SIGABRT here! - int log_minimum = (BOX64ENV(showsegv))?LOG_NONE:((sig==SIGSEGV && my_context->is_sigaction[sig])?LOG_DEBUG:LOG_INFO); + sig = signal_from_x64(sig); + // sig==X64_SIGSEGV || sig==X64_SIGBUS || sig==X64_SIGILL || sig==X64_SIGABRT here! + int log_minimum = (BOX64ENV(showsegv))?LOG_NONE:((sig==X64_SIGSEGV && my_context->is_sigaction[sig])?LOG_DEBUG:LOG_INFO); if(signal_jmpbuf_active) { signal_jmpbuf_active = 0; longjmp(SIG_JMPBUF, 1); @@ -1381,7 +1382,7 @@ void my_box64signalhandler(int32_t sig, siginfo_t* info, void * ucntx) int db_searched = 0; uintptr_t x64pc = (uintptr_t)-1; x64pc = R_RIP; - if((sig==SIGBUS) && (addr!=pc) || ((sig==SIGSEGV)) && emu->segs[_CS]==0x23 && ((uintptr_t)addr>>32)==0xffffffff) { + if((sig==X64_SIGBUS) && (addr!=pc) || ((sig==X64_SIGSEGV)) && emu->segs[_CS]==0x23 && ((uintptr_t)addr>>32)==0xffffffff) { db = FindDynablockFromNativeAddress(pc); if(db) x64pc = getX64Address(db, (uintptr_t)pc); @@ -1407,7 +1408,7 @@ void my_box64signalhandler(int32_t sig, siginfo_t* info, void * ucntx) } } #ifdef ARCH_NOP - if(sig==SIGILL) { + if(sig==X64_SIGILL) { if(!db_searched) { db = FindDynablockFromNativeAddress(pc); if(db) @@ -1476,13 +1477,13 @@ void my_box64signalhandler(int32_t sig, siginfo_t* info, void * ucntx) #ifdef BAD_SIGNAL // try to see if the si_code makes sense // the RK3588 tend to need a special Kernel that seems to have a weird behaviour sometimes - if((sig==SIGSEGV) && (addr) && (info->si_code == 1) && getMmapped((uintptr_t)addr)) { + if((sig==X64_SIGSEGV) && (addr) && (info->si_code == 1) && getMmapped((uintptr_t)addr)) { printf_log(LOG_DEBUG, "Workaround for suspicious si_code for %p / prot=0x%hhx\n", addr, prot); info->si_code = 2; } #endif #ifdef RV64 - if((sig==SIGSEGV) && (addr==pc) && (info->si_code==2) && (prot==(PROT_READ|PROT_WRITE|PROT_EXEC))) { + if((sig==X64_SIGSEGV) && (addr==pc) && (info->si_code==2) && (prot==(PROT_READ|PROT_WRITE|PROT_EXEC))) { if(!db_searched) { db = FindDynablockFromNativeAddress(pc); if(db) @@ -1508,14 +1509,14 @@ void my_box64signalhandler(int32_t sig, siginfo_t* info, void * ucntx) } #endif #ifdef DYNAREC - if((Locks & is_dyndump_locked) && ((sig==SIGSEGV) || (sig==SIGBUS)) && current_helper) { - printf_log(LOG_INFO, "FillBlock triggered a %s at %p from %p\n", (sig==SIGSEGV)?"segfault":"bus error", addr, pc); + if((Locks & is_dyndump_locked) && ((sig==X64_SIGSEGV) || (sig==X64_SIGBUS)) && current_helper) { + printf_log(LOG_INFO, "FillBlock triggered a %s at %p from %p\n", (sig==X64_SIGSEGV)?"segfault":"bus error", addr, pc); CancelBlock64(0); relockMutex(Locks); cancelFillBlock(); // Segfault inside a Fillblock, cancel it's creation... // cancelFillBlock does not return } - if ((sig==SIGSEGV) && (addr) && (info->si_code == SEGV_ACCERR) && (prot&PROT_DYNAREC)) { + if ((sig==X64_SIGSEGV) && (addr) && (info->si_code == SEGV_ACCERR) && (prot&PROT_DYNAREC)) { lock_signal(); // check if SMC inside block if(!db_searched) { @@ -1560,7 +1561,7 @@ void my_box64signalhandler(int32_t sig, siginfo_t* info, void * ucntx) return; } unlock_signal(); - } else if ((sig==SIGSEGV) && (addr) && (info->si_code == SEGV_ACCERR) && ((prot&(PROT_READ|PROT_WRITE))==(PROT_READ|PROT_WRITE))) { + } else if ((sig==X64_SIGSEGV) && (addr) && (info->si_code == SEGV_ACCERR) && ((prot&(PROT_READ|PROT_WRITE))==(PROT_READ|PROT_WRITE))) { lock_signal(); if(!db_searched) { db = FindDynablockFromNativeAddress(pc); @@ -1618,7 +1619,7 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on % glitch2_prot = 0; } unlock_signal(); - } else if ((sig==SIGSEGV) && (addr) && (info->si_code == SEGV_ACCERR) && (prot&PROT_DYNAREC_R)) { + } else if ((sig==X64_SIGSEGV) && (addr) && (info->si_code == SEGV_ACCERR) && (prot&PROT_DYNAREC_R)) { // unprotect and continue to signal handler, because Write is not there on purpose unprotectDB((uintptr_t)addr, 1, 1); // unprotect 1 byte... But then, the whole page will be unprotected } @@ -1629,7 +1630,7 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on % db_searched = 1; } #endif - if((sig==SIGSEGV || sig==SIGBUS) && box64_quit) { + if((sig==X64_SIGSEGV || sig==X64_SIGBUS) && box64_quit) { printf_log(LOG_INFO, "Sigfault/Segbus while quitting, exiting silently\n"); _exit(box64_exit_code); // Hack, segfault while quiting, exit silently } @@ -1639,7 +1640,7 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on % static int old_tid = 0; static uint32_t old_prot = 0; int mapped = memExist((uintptr_t)addr); - const char* signame = (sig==SIGSEGV)?"SIGSEGV":((sig==SIGBUS)?"SIGBUS":((sig==SIGILL)?"SIGILL":"SIGABRT")); + const char* signame = (sig==X64_SIGSEGV)?"SIGSEGV":((sig==X64_SIGBUS)?"SIGBUS":((sig==X64_SIGILL)?"SIGILL":"SIGABRT")); rsp = (void*)R_RSP; #if defined(DYNAREC) if(db && CONTEXT_REG(p, xEmu)>0x10000) { @@ -1649,13 +1650,13 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on % rsp = (void*)CONTEXT_REG(p, xRSP); } #endif //DYNAREC - if(!db && (sig==SIGSEGV) && ((uintptr_t)addr==(x64pc-1))) + if(!db && (sig==X64_SIGSEGV) && ((uintptr_t)addr==(x64pc-1))) x64pc--; if(old_code==info->si_code && old_pc==pc && old_addr==addr && old_tid==tid && old_prot==prot) { printf_log(log_minimum, "%04d|Double %s (code=%d, pc=%p, x64pc=%p, addr=%p, prot=%02x)!\n", tid, signame, old_code, old_pc, x64pc, old_addr, prot); exit(-1); } else { - if((sig==SIGSEGV) && (info->si_code == SEGV_ACCERR) && ((prot&~PROT_CUSTOM)==(PROT_READ|PROT_WRITE) || (prot&~PROT_CUSTOM)==(PROT_READ|PROT_WRITE|PROT_EXEC))) { + if((sig==X64_SIGSEGV) && (info->si_code == SEGV_ACCERR) && ((prot&~PROT_CUSTOM)==(PROT_READ|PROT_WRITE) || (prot&~PROT_CUSTOM)==(PROT_READ|PROT_WRITE|PROT_EXEC))) { static uintptr_t old_addr = 0; #ifdef DYNAREC if(prot==(PROT_READ|PROT_WRITE|PROT_EXEC)) @@ -1694,7 +1695,7 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on % signal_jmpbuf_active = 0; } // Adjust RIP for special case of NULL function run - if(sig==SIGSEGV && R_RIP==0x1 && (uintptr_t)info->si_addr==0x0) + if(sig==X64_SIGSEGV && R_RIP==0x1 && (uintptr_t)info->si_addr==0x0) R_RIP = 0x0; if(log_minimum<=BOX64ENV(log)) { elfheader_t* elf = FindElfAddress(my_context, x64pc); @@ -1735,7 +1736,7 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on % } print_rolling_log(log_minimum); - if((BOX64ENV(showbt) || sig==SIGABRT) && log_minimum<=BOX64ENV(log)) { + if((BOX64ENV(showbt) || sig==X64_SIGABRT) && log_minimum<=BOX64ENV(log)) { // show native bt ShowNativeBT(log_minimum); @@ -1846,13 +1847,13 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on % printf_log_prefix(0, log_minimum, "%s:0x%04x ", seg_name[i], emu->segs[i]); } zydis_dec_t* dec = emu->segs[_CS] == 0x23 ? my_context->dec32 : my_context->dec; - if(sig==SIGILL) { + if(sig==X64_SIGILL) { printf_log_prefix(0, log_minimum, " opcode=%02X %02X %02X %02X %02X %02X %02X %02X ", ((uint8_t*)pc)[0], ((uint8_t*)pc)[1], ((uint8_t*)pc)[2], ((uint8_t*)pc)[3], ((uint8_t*)pc)[4], ((uint8_t*)pc)[5], ((uint8_t*)pc)[6], ((uint8_t*)pc)[7]); if (dec) printf_log_prefix(0, log_minimum, "(%s)\n", DecodeX64Trace(dec, x64pc, 1)); else printf_log_prefix(0, log_minimum, "(%02X %02X %02X %02X %02X)\n", ((uint8_t*)x64pc)[0], ((uint8_t*)x64pc)[1], ((uint8_t*)x64pc)[2], ((uint8_t*)x64pc)[3], ((uint8_t*)x64pc)[4]); - } else if(sig==SIGBUS || (sig==SIGSEGV && (x64pc!=(uintptr_t)addr) && (pc!=addr)) && (getProtection_fast(x64pc)&PROT_READ) && (getProtection_fast((uintptr_t)pc)&PROT_READ)) { + } else if(sig==X64_SIGBUS || (sig==X64_SIGSEGV && (x64pc!=(uintptr_t)addr) && (pc!=addr)) && (getProtection_fast(x64pc)&PROT_READ) && (getProtection_fast((uintptr_t)pc)&PROT_READ)) { if (dec) printf_log_prefix(0, log_minimum, " %sopcode=%s; native opcode=%08x\n", (emu->segs[_CS] == 0x23) ? "x86" : "x64", DecodeX64Trace(dec, x64pc, 1), *(uint32_t*)pc); else @@ -1869,13 +1870,14 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on % } // no handler (or double identical segfault) // set default and that's it, instruction will restart and default segfault handler will be called... - if(my_context->signals[sig]!=1 || sig==SIGSEGV || sig==SIGILL || sig==SIGFPE || sig==SIGABRT) { - signal(sig, (void*)my_context->signals[sig]); + if(my_context->signals[sig]!=1 || sig==X64_SIGSEGV || sig==X64_SIGILL || sig==X64_SIGFPE || sig==X64_SIGABRT) { + signal(signal_from_x64(sig), (void*)my_context->signals[sig]); } } void my_sigactionhandler(int32_t sig, siginfo_t* info, void * ucntx) { + sig = signal_from_x64(sig); void* pc = NULL; #ifdef DYNAREC ucontext_t *p = (ucontext_t *)ucntx; @@ -1908,7 +1910,7 @@ EXPORT sighandler_t my_signal(x64emu_t* emu, int signum, sighandler_t handler) if(signum<0 || signum>MAX_SIGNAL) return SIG_ERR; - if(signum==SIGSEGV && emu->context->no_sigsegv) + if(signum==X64_SIGSEGV && emu->context->no_sigsegv) return 0; // create a new handler @@ -1917,7 +1919,7 @@ EXPORT sighandler_t my_signal(x64emu_t* emu, int signum, sighandler_t handler) my_context->restorer[signum] = 0; my_context->onstack[signum] = 0; - if(signum==SIGSEGV || signum==SIGBUS || signum==SIGILL || signum==SIGABRT) + if(signum==X64_SIGSEGV || signum==X64_SIGBUS || signum==X64_SIGILL || signum==X64_SIGABRT) return 0; if(handler!=NULL && handler!=(sighandler_t)1) { @@ -1925,10 +1927,10 @@ EXPORT sighandler_t my_signal(x64emu_t* emu, int signum, sighandler_t handler) struct sigaction oldact = {0}; newact.sa_flags = 0x04; newact.sa_sigaction = my_sigactionhandler; - sigaction(signum, &newact, &oldact); + sigaction(signal_from_x64(signum), &newact, &oldact); return oldact.sa_handler; } else - return signal(signum, handler); + return signal(signal_from_x64(signum), handler); } EXPORT sighandler_t my___sysv_signal(x64emu_t* emu, int signum, sighandler_t handler) __attribute__((alias("my_signal"))); EXPORT sighandler_t my_sysv_signal(x64emu_t* emu, int signum, sighandler_t handler) __attribute__((alias("my_signal"))); // not completely exact @@ -1941,10 +1943,10 @@ int EXPORT my_sigaction(x64emu_t* emu, int signum, const x64_sigaction_t *act, x return -1; } - if(signum==SIGSEGV && emu->context->no_sigsegv) + if(signum==X64_SIGSEGV && emu->context->no_sigsegv) return 0; - if(signum==SIGILL && emu->context->no_sigill) + if(signum==X64_SIGILL && emu->context->no_sigill) return 0; struct sigaction newact = {0}; struct sigaction old = {0}; @@ -1972,8 +1974,8 @@ int EXPORT my_sigaction(x64emu_t* emu, int signum, const x64_sigaction_t *act, x my_context->onstack[signum] = (act->sa_flags&SA_ONSTACK)?1:0; } int ret = 0; - if(signum!=SIGSEGV && signum!=SIGBUS && signum!=SIGILL && signum!=SIGABRT) - ret = sigaction(signum, act?&newact:NULL, oldact?&old:NULL); + if(signum!=X64_SIGSEGV && signum!=X64_SIGBUS && signum!=X64_SIGILL && signum!=X64_SIGABRT) + ret = sigaction(signal_from_x64(signum), act?&newact:NULL, oldact?&old:NULL); if(oldact) { oldact->sa_flags = old.sa_flags; oldact->sa_mask = old.sa_mask; @@ -1998,7 +2000,7 @@ int EXPORT my_syscall_rt_sigaction(x64emu_t* emu, int signum, const x64_sigactio return -1; } - if(signum==SIGSEGV && emu->context->no_sigsegv) + if(signum==X64_SIGSEGV && emu->context->no_sigsegv) return 0; // TODO, how to handle sigsetsize>4?! if(signum==32 || signum==33) { @@ -2079,8 +2081,8 @@ int EXPORT my_syscall_rt_sigaction(x64emu_t* emu, int signum, const x64_sigactio } int ret = 0; - if(signum!=SIGSEGV && signum!=SIGBUS && signum!=SIGILL && signum!=SIGABRT) - ret = sigaction(signum, act?&newact:NULL, oldact?&old:NULL); + if(signum!=X64_SIGSEGV && signum!=X64_SIGBUS && signum!=X64_SIGILL && signum!=X64_SIGABRT) + ret = sigaction(signal_from_x64(signum), act?&newact:NULL, oldact?&old:NULL); if(oldact && ret==0) { oldact->sa_flags = old.sa_flags; memcpy(&oldact->sa_mask, &old.sa_mask, (sigsetsize>8)?8:sigsetsize); @@ -2095,6 +2097,7 @@ int EXPORT my_syscall_rt_sigaction(x64emu_t* emu, int signum, const x64_sigactio EXPORT sighandler_t my_sigset(x64emu_t* emu, int signum, sighandler_t handler) { + signum = signal_from_x64(signum); // emulated SIG_HOLD if(handler == (sighandler_t)2) { x64_sigaction_t oact; @@ -2333,3 +2336,24 @@ void fini_signal_helper() signal(SIGILL, SIG_DFL); signal(SIGABRT, SIG_DFL); } + +#ifdef NEED_SIG_CONV +int signal_to_x64(int sig) +{ + #define GO(A) case A: return X64_##A; + switch(sig) { + SUPER_SIGNAL + } + #undef GO + return sig; +} +int signal_from_x64(int sig) +{ + #define GO(A) case X64_##A: return A; + switch(sig) { + SUPER_SIGNAL + } + #undef GO + return sig; +} +#endif \ No newline at end of file diff --git a/src/libtools/threads.c b/src/libtools/threads.c index 3ba83ba0..aa0cbe08 100644 --- a/src/libtools/threads.c +++ b/src/libtools/threads.c @@ -4,10 +4,10 @@ #include <stdio.h> #include <stdlib.h> #include <pthread.h> -#include <signal.h> #include <errno.h> #include <setjmp.h> +#include "x64_signals.h" #include "os.h" #include "debug.h" #include "box64context.h" @@ -834,6 +834,7 @@ EXPORT int my_pthread_setaffinity_np_old(x64emu_t* emu, pthread_t thread, void* EXPORT int my_pthread_kill(x64emu_t* emu, void* thread, int sig) { + sig = signal_from_x64(sig); // should ESCHR result be filtered, as this is expected to be the 2.34 behaviour? (void)emu; // check for old "is everything ok?" @@ -844,6 +845,7 @@ EXPORT int my_pthread_kill(x64emu_t* emu, void* thread, int sig) EXPORT int my_pthread_kill_old(x64emu_t* emu, void* thread, int sig) { + sig = signal_from_x64(sig); // check for old "is everything ok?" if((thread==NULL) && (sig==0)) return real_phtread_kill_old(pthread_self(), 0); diff --git a/src/os/emit_signal_wine.c b/src/os/emit_signal_wine.c index ef0a0f65..6f8ee126 100644 --- a/src/os/emit_signal_wine.c +++ b/src/os/emit_signal_wine.c @@ -2,10 +2,10 @@ * Copyright 2022-2025 André Zwing * Copyright 2023 Alexandre Julliard */ -#include <signal.h> #include <windows.h> #include <winternl.h> +#include "x64_signals.h" #include "x64emu.h" #include "debug.h" #include "custommem.h" @@ -16,11 +16,11 @@ void EmitSignal(x64emu_t* emu, int sig, void* addr, int code) EXCEPTION_RECORD rec; switch (sig) { - case SIGILL: + case X64_SIGILL: printf_log(LOG_DEBUG, "SIGILL at %p with code %d\n", addr, code); rec.ExceptionCode = STATUS_ILLEGAL_INSTRUCTION; break; - case SIGSEGV: + case X64_SIGSEGV: printf_log(LOG_DEBUG, "SIGSEGV at %p with code %d\n", addr, code); rec.ExceptionCode = STATUS_ACCESS_VIOLATION; break; diff --git a/src/os/emit_signals_linux.c b/src/os/emit_signals_linux.c index e14c4c83..4e7f6c77 100644 --- a/src/os/emit_signals_linux.c +++ b/src/os/emit_signals_linux.c @@ -6,12 +6,11 @@ #include <sys/mman.h> #include <ucontext.h> #include <setjmp.h> -#include <signal.h> #ifndef ANDROID #include <execinfo.h> #endif - +#include "x64_signals.h" #include "box64context.h" #include "custommem.h" #include "debug.h" @@ -29,15 +28,15 @@ void EmitSignal(x64emu_t* emu, int sig, void* addr, int code) { siginfo_t info = { 0 }; info.si_signo = sig; - info.si_errno = (sig == SIGSEGV) ? 0x1234 : 0; // Mark as a sign this is a #GP(0) (like privileged instruction) + info.si_errno = (sig == X64_SIGSEGV) ? 0x1234 : 0; // Mark as a sign this is a #GP(0) (like privileged instruction) info.si_code = code; - if (sig == SIGSEGV && code == 0xbad0) { + if (sig == X64_SIGSEGV && code == 0xbad0) { info.si_errno = 0xbad0; info.si_code = 0; - } else if (sig == SIGSEGV && code == 0xecec) { + } else if (sig == X64_SIGSEGV && code == 0xecec) { info.si_errno = 0xecec; info.si_code = SEGV_ACCERR; - } else if (sig == SIGSEGV && code == 0xb09d) { + } else if (sig == X64_SIGSEGV && code == 0xb09d) { info.si_errno = 0xb09d; info.si_code = 0; } @@ -52,7 +51,7 @@ void EmitSignal(x64emu_t* emu, int sig, void* addr, int code) printf_log(LOG_NONE, "Emit Signal %d at IP=%p(%s / %s) / addr=%p, code=0x%x\n", sig, (void*)R_RIP, x64name ? x64name : "???", elfname ? elfname : "?", addr, code); print_rolling_log(LOG_INFO); - if ((BOX64ENV(showbt) || sig == SIGABRT) && BOX64ENV(log) >= LOG_INFO) { + if ((BOX64ENV(showbt) || sig == X64_SIGABRT) && BOX64ENV(log) >= LOG_INFO) { // show native bt #define BT_BUF_SIZE 100 int nptrs; @@ -94,7 +93,7 @@ void EmitSignal(x64emu_t* emu, int sig, void* addr, int code) // fclose(f); // } // } - if (sig == SIGILL) { + if (sig == X64_SIGILL) { uint8_t* mem = (uint8_t*)R_RIP; printf_log(LOG_NONE, "SIGILL: Opcode at ip is %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx\n", mem[0], mem[1], mem[2], mem[3], mem[4], mem[5]); } @@ -108,14 +107,14 @@ void CheckExec(x64emu_t* emu, uintptr_t addr) return; // disabling the test, 4K pagesize simlation isn't good enough for this while ((getProtection/*_fast*/(addr) & (PROT_EXEC | PROT_READ)) != (PROT_EXEC | PROT_READ)) { R_RIP = addr; // incase there is a slight difference - EmitSignal(emu, SIGSEGV, (void*)addr, 0xecec); + EmitSignal(emu, X64_SIGSEGV, (void*)addr, 0xecec); } } void EmitInterruption(x64emu_t* emu, int num, void* addr) { siginfo_t info = { 0 }; - info.si_signo = SIGSEGV; + info.si_signo = X64_SIGSEGV; info.si_errno = 0xdead; info.si_code = num; info.si_addr = NULL; // addr; @@ -128,13 +127,13 @@ void EmitInterruption(x64emu_t* emu, int num, void* addr) elfname = ElfName(elf); printf_log(LOG_NONE, "Emit Interruption 0x%x at IP=%p(%s / %s) / addr=%p\n", num, (void*)R_RIP, x64name ? x64name : "???", elfname ? elfname : "?", addr); } - my_sigactionhandler_oldcode(emu, SIGSEGV, 0, &info, NULL, NULL, NULL, R_RIP); + my_sigactionhandler_oldcode(emu, X64_SIGSEGV, 0, &info, NULL, NULL, NULL, R_RIP); } void EmitDiv0(x64emu_t* emu, void* addr, int code) { siginfo_t info = { 0 }; - info.si_signo = SIGSEGV; + info.si_signo = X64_SIGSEGV; info.si_errno = 0xcafe; info.si_code = code; info.si_addr = addr; @@ -147,13 +146,13 @@ void EmitDiv0(x64emu_t* emu, void* addr, int code) 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(emu, SIGSEGV, 0, &info, NULL, NULL, NULL, R_RIP); + my_sigactionhandler_oldcode(emu, X64_SIGSEGV, 0, &info, NULL, NULL, NULL, R_RIP); } void EmitWineInt(x64emu_t* emu, int num, void* addr) { siginfo_t info = { 0 }; - info.si_signo = SIGSEGV; + info.si_signo = X64_SIGSEGV; info.si_errno = 0xdead; info.si_code = num; info.si_addr = NULL; // addr; @@ -167,10 +166,10 @@ void EmitWineInt(x64emu_t* emu, int num, void* addr) printf_log(LOG_NONE, "Emit Interruption 0x%x at IP=%p(%s / %s) / addr=%p\n", num, (void*)R_RIP, x64name ? x64name : "???", elfname ? elfname : "?", addr); } if(box64_is32bits) - my_sigactionhandler_oldcode(emu, SIGSEGV, 0, &info, NULL, NULL, NULL, R_RIP); + my_sigactionhandler_oldcode(emu, X64_SIGSEGV, 0, &info, NULL, NULL, NULL, R_RIP); else { uintptr_t frame = R_RSP; - int sig = SIGSEGV; + int sig = X64_SIGSEGV; // stack tracking x64_stack_t *new_ss = my_context->onstack[sig]?sigstack_getstack():NULL; int used_stack = 0; diff --git a/src/wrapped32/wrappedlibc.c b/src/wrapped32/wrappedlibc.c index 004a99ca..618c8a3f 100755 --- a/src/wrapped32/wrappedlibc.c +++ b/src/wrapped32/wrappedlibc.c @@ -3370,7 +3370,7 @@ EXPORT int my32_waitid(x64emu_t* emu, uint32_t idtype, uint32_t id, void* siginf { siginfo_t siginfo_l; int ret = waitid(idtype, id, siginfo?(&siginfo_l):NULL, options); - convert_siginfo_to_32(siginfo, &siginfo_l, SIGCHLD); + convert_siginfo_to_32(siginfo, &siginfo_l, X64_SIGCHLD); return ret; } |