use B2 sigsegv API instead of rewriting yet another sigsegv handler for x86

This commit is contained in:
gbeauche 2003-09-29 07:05:15 +00:00
parent a48a804c15
commit 1c2fa89e31

View File

@ -21,6 +21,7 @@
#include "sysdeps.h" #include "sysdeps.h"
#include "cpu_emulation.h" #include "cpu_emulation.h"
#include "main.h" #include "main.h"
#include "prefs.h"
#include "xlowmem.h" #include "xlowmem.h"
#include "emul_op.h" #include "emul_op.h"
#include "rom_patches.h" #include "rom_patches.h"
@ -536,47 +537,38 @@ static void dump_log(void)
* Initialize CPU emulation * Initialize CPU emulation
*/ */
static struct sigaction sigsegv_action; static sigsegv_return_t sigsegv_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction)
#if defined(__powerpc__)
#include <sys/ucontext.h>
#endif
static void sigsegv_handler(int sig, siginfo_t *sip, void *scp)
{ {
const uintptr addr = (uintptr)sip->si_addr;
#if ENABLE_VOSF #if ENABLE_VOSF
// Handle screen fault. // Handle screen fault
extern bool Screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction); extern bool Screen_fault_handler(sigsegv_address_t, sigsegv_address_t);
if (Screen_fault_handler((sigsegv_address_t)addr, SIGSEGV_INVALID_PC)) if (Screen_fault_handler(fault_address, fault_instruction))
return; return SIGSEGV_RETURN_SUCCESS;
#endif #endif
#if defined(__powerpc__)
if (addr >= ROM_BASE && addr < ROM_BASE + ROM_SIZE) { const uintptr addr = (uintptr)fault_address;
printf("IGNORE write access to ROM at %08x\n", addr); #if HAVE_SIGSEGV_SKIP_INSTRUCTION
(((ucontext_t *)scp)->uc_mcontext.regs)->nip += 4; // Ignore writes to ROM
return; if ((addr - ROM_BASE) < ROM_SIZE)
} return SIGSEGV_RETURN_SKIP_INSTRUCTION;
if (addr >= 0xf3012000 && addr < 0xf3014000 && 0) {
printf("IGNORE write access to ROM at %08x\n", addr); // Ignore all other faults, if requested
(((ucontext_t *)scp)->uc_mcontext.regs)->nip += 4; if (PrefsFindBool("ignoresegv"))
return; return SIGSEGV_RETURN_FAILURE;
}
#endif
printf("Caught SIGSEGV at address %p\n", sip->si_addr);
printf("Native PC: %08x\n", (((ucontext_t *)scp)->uc_mcontext.regs)->nip);
printf("Current CPU: %s\n", current_cpu == main_cpu ? "main" : "interrupts");
#if 1
dump_registers();
#else #else
printf("Main CPU context\n"); #error "FIXME: You don't have the capability to skip instruction within signal handlers"
main_cpu->dump_registers();
printf("Interrupts CPU context\n");
interrupt_cpu->dump_registers();
#endif #endif
printf("SIGSEGV\n");
printf(" pc %p\n", fault_instruction);
printf(" ea %p\n", fault_address);
printf(" cpu %s\n", current_cpu == main_cpu ? "main" : "interrupts");
dump_registers();
current_cpu->dump_log(); current_cpu->dump_log();
enter_mon(); enter_mon();
QuitEmulator(); QuitEmulator();
return SIGSEGV_RETURN_FAILURE;
} }
void init_emul_ppc(void) void init_emul_ppc(void)
@ -591,12 +583,8 @@ void init_emul_ppc(void)
interrupt_cpu = new sheepshaver_cpu(); interrupt_cpu = new sheepshaver_cpu();
#endif #endif
// Install SIGSEGV handler // Install the handler for SIGSEGV
sigemptyset(&sigsegv_action.sa_mask); sigsegv_install_handler(sigsegv_handler);
sigsegv_action.sa_sigaction = sigsegv_handler;
sigsegv_action.sa_flags = SA_SIGINFO;
sigsegv_action.sa_restorer = NULL;
sigaction(SIGSEGV, &sigsegv_action, NULL);
#if ENABLE_MON #if ENABLE_MON
// Install "regs" command in cxmon // Install "regs" command in cxmon