diff options
author | Ian Moffett <ian@osmora.org> | 2025-05-28 21:47:25 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-05-28 21:48:31 -0400 |
commit | 3dc995e1eb82022453da9ed9d3b639b989e485cf (patch) | |
tree | 977a0928fcb2b732941b089e86cddaf58d8498fe | |
parent | 8e047cfdf4911fad56edc222531cd21a88376a4a (diff) |
kernel/amd64: trap: Log page fault flags
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | sys/arch/amd64/amd64/trap.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sys/arch/amd64/amd64/trap.c b/sys/arch/amd64/amd64/trap.c index 6492a29..84a6a77 100644 --- a/sys/arch/amd64/amd64/trap.c +++ b/sys/arch/amd64/amd64/trap.c @@ -60,6 +60,17 @@ static const char *trap_type[] = { [TRAP_SS] = "stack-segment fault" }; +/* Page-fault flags */ +static const char pf_flags[] = { + 'p', /* Present */ + 'w', /* Write */ + 'u', /* User */ + 'r', /* Reserved write */ + 'x', /* Instruction fetch */ + 'k', /* Protection key violation */ + 's' /* Shadow stack access */ +}; + static inline uintptr_t pf_faultaddr(void) { @@ -69,6 +80,23 @@ pf_faultaddr(void) } static void +pf_code(uint64_t error_code) +{ + char tab[8] = { + '-', '-', '-', + '-', '-', '-', + '-', '\0' + }; + + for (int i = 0; i < 7; ++i) { + if (ISSET(error_code, BIT(i))) { + tab[i] = pf_flags[i]; + } + } + kprintf("code=[%s]\n", tab); +} + +static void regdump(struct trapframe *tf) { uintptr_t cr3, cr2 = pf_faultaddr(); @@ -79,6 +107,10 @@ regdump(struct trapframe *tf) : "memory" ); + if (tf->trapno == TRAP_PAGEFLT) { + pf_code(tf->error_code); + } + kprintf(OMIT_TIMESTAMP "RAX=%p RCX=%p RDX=%p\n" "RBX=%p RSI=%p RDI=%p\n" @@ -101,6 +133,9 @@ trap_user(struct trapframe *tf) switch (tf->trapno) { case TRAP_PROTFLT: case TRAP_PAGEFLT: + if (tf->trapno == TRAP_PAGEFLT) { + pf_code(tf->error_code); + } sigaddset(&sigset, SIGSEGV); break; case TRAP_ARITH_ERR: |