diff --git a/src/system/kernel/arch/x86/64/int.cpp b/src/system/kernel/arch/x86/64/int.cpp index 6f0ad2992b..86681bdf52 100644 --- a/src/system/kernel/arch/x86/64/int.cpp +++ b/src/system/kernel/arch/x86/64/int.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -29,6 +30,25 @@ interrupt_handler_function* gInterruptHandlerTable[kInterruptHandlerTableSize]; extern uint8 isr_array[kInterruptHandlerTableSize][16]; +static void +x86_64_general_protection_fault(iframe* frame) +{ + if (debug_debugger_running()) { + // Handle GPFs if there is a debugger fault handler installed, for + // non-canonical address accesses. + cpu_ent* cpu = &gCPU[smp_get_current_cpu()]; + if (cpu->fault_handler != 0) { + debug_set_page_fault_info(0, frame->ip, DEBUG_PAGE_FAULT_NO_INFO); + frame->ip = cpu->fault_handler; + frame->bp = cpu->fault_handler_stack_pointer; + return; + } + } + + x86_unexpected_exception(frame); +} + + /*! Returns the virtual IDT address for CPU \a cpu. */ void* x86_get_idt(int32 cpu) @@ -87,7 +107,7 @@ arch_int_init(kernel_args* args) table[10] = x86_fatal_exception; // Invalid TSS Exception (#TS) table[11] = x86_fatal_exception; // Segment Not Present (#NP) table[12] = x86_fatal_exception; // Stack Fault Exception (#SS) - table[13] = x86_unexpected_exception; // General Protection Exception (#GP) + table[13] = x86_64_general_protection_fault; // General Protection Exception (#GP) table[14] = x86_page_fault_exception; // Page-Fault Exception (#PF) table[16] = x86_unexpected_exception; // x87 FPU Floating-Point Error (#MF) table[17] = x86_unexpected_exception; // Alignment Check Exception (#AC)