1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:37:46 +00:00

Kernel+Userland: Add x86_64 registers to RegisterState/PtraceRegisters

This commit is contained in:
Gunnar Beutner 2021-06-26 14:56:28 +02:00 committed by Andreas Kling
parent 10ca7f18a7
commit 233ef26e4d
13 changed files with 265 additions and 23 deletions

View file

@ -117,6 +117,7 @@ asm( \
static void dump(const RegisterState& regs)
{
#if ARCH(I386)
u16 ss;
u32 esp;
@ -127,14 +128,33 @@ static void dump(const RegisterState& regs)
ss = regs.userspace_ss;
esp = regs.userspace_esp;
}
#else
u64 rsp;
if (!(regs.cs & 3))
rsp = regs.rsp;
else
rsp = regs.userspace_rsp;
#endif
dbgln("Exception code: {:04x} (isr: {:04x})", regs.exception_code, regs.isr_number);
#if ARCH(I386)
dbgln(" pc={:04x}:{:08x} eflags={:08x}", (u16)regs.cs, regs.eip, regs.eflags);
dbgln(" stack={:04x}:{:08x}", ss, esp);
dbgln(" ds={:04x} es={:04x} fs={:04x} gs={:04x}", (u16)regs.ds, (u16)regs.es, (u16)regs.fs, (u16)regs.gs);
dbgln(" eax={:08x} ebx={:08x} ecx={:08x} edx={:08x}", regs.eax, regs.ebx, regs.ecx, regs.edx);
dbgln(" ebp={:08x} esp={:08x} esi={:08x} edi={:08x}", regs.ebp, regs.esp, regs.esi, regs.edi);
dbgln(" cr0={:08x} cr2={:08x} cr3={:08x} cr4={:08x}", read_cr0(), read_cr2(), read_cr3(), read_cr4());
#else
dbgln(" pc={:04x}:{:16x} rflags={:16x}", (u16)regs.cs, regs.rip, regs.rflags);
dbgln(" stack={:16x}", rsp);
// FIXME: Add fs_base and gs_base here
dbgln(" rax={:16x} rbx={:16x} rcx={:16x} rdx={:16x}", regs.rax, regs.rbx, regs.rcx, regs.rdx);
dbgln(" rbp={:16x} rsp={:16x} rsi={:16x} rdi={:16x}", regs.rbp, regs.rsp, regs.rsi, regs.rdi);
dbgln(" r8={:16x} r9={:16x} r10={:16x} r11={:16x}", regs.r8, regs.r9, regs.r10, regs.r11);
dbgln(" r12={:16x} r13={:16x} r14={:16x} r15={:16x}", regs.r12, regs.r13, regs.r14, regs.r15);
dbgln(" cr0={:16x} cr2={:16x} cr3={:16x} cr4={:16x}", read_cr0(), read_cr2(), read_cr3(), read_cr4());
#endif
}
void handle_crash(RegisterState& regs, const char* description, int signal, bool out_of_memory)
@ -155,7 +175,13 @@ void handle_crash(RegisterState& regs, const char* description, int signal, bool
PANIC("Crash in ring 0");
}
process->crash(signal, regs.eip, out_of_memory);
FlatPtr ip;
#if ARCH(I386)
ip = regs.eip;
#else
ip = regs.rip;
#endif
process->crash(signal, ip, out_of_memory);
}
EH_ENTRY_NO_CODE(6, illegal_instruction);
@ -237,8 +263,14 @@ void page_fault_handler(TrapFrame* trap)
current_thread->set_handling_page_fault(false);
};
if (!faulted_in_kernel && !MM.validate_user_stack(current_thread->process(), VirtualAddress(regs.userspace_esp))) {
dbgln("Invalid stack pointer: {}", VirtualAddress(regs.userspace_esp));
VirtualAddress userspace_sp;
#if ARCH(I386)
userspace_sp = VirtualAddress { regs.userspace_esp };
#else
userspace_sp = VirtualAddress { regs.userspace_rsp };
#endif
if (!faulted_in_kernel && !MM.validate_user_stack(current_thread->process(), userspace_sp)) {
dbgln("Invalid stack pointer: {}", userspace_sp);
handle_crash(regs, "Bad stack on page fault", SIGSTKFLT);
}