From 937c6fb7016ff3bdc8e8525a6e93c05209b7baf1 Mon Sep 17 00:00:00 2001 From: Sparchatus Date: Fri, 20 May 2022 06:32:09 +0000 Subject: [PATCH] Nicer paging panics --- lib/aos/paging.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/aos/paging.c b/lib/aos/paging.c index be8289e..2fa6730 100644 --- a/lib/aos/paging.c +++ b/lib/aos/paging.c @@ -108,7 +108,9 @@ static void pt_exception_handler(enum exception_type type, int subtype, // abort on NULL pointer dereference if(addr < (void *) VADDR_LOWEST_NON_NULL) { - USER_PANIC("[ERROR] NULL pointer dereference"); + static char str[256]; + snprintf(str, sizeof(str), "[ERROR] NULL pointer dereference: addr=%p, ip=%p\n", addr, ip); + USER_PANIC(str); } lvaddr_t page_addr = ROUND_DOWN((lvaddr_t)addr, BASE_PAGE_SIZE); @@ -125,19 +127,22 @@ static void pt_exception_handler(enum exception_type type, int subtype, } } if (vaddr_reg == NULL) { - debug_printf("[pt_exception_handler] type=%s, addr=%p, ip=%p, page_addr=0x%x\n", pt_exception_type_to_string(type, subtype), addr, ip, page_addr); thread_mutex_unlock(&st->lock); - USER_PANIC("[pt_exception_handler][ERROR] Page fault ouside valid virtual address space"); + static char str[256]; + snprintf(str, sizeof(str), "[ERROR] Page fault ouside valid virtual address space: type=%s, addr=%p, ip=%p, page_addr=0x%x\n", pt_exception_type_to_string(type, subtype), addr, ip, page_addr); + USER_PANIC(str); } if (vaddr_reg->free) { - debug_printf("[pt_exception_handler] type=%s, addr=%p, ip=%p, page_addr=0x%x, base=0x%x, size=0x%x\n", pt_exception_type_to_string(type, subtype), addr, ip, page_addr, vaddr_reg->base, vaddr_reg->size); thread_mutex_unlock(&st->lock); - USER_PANIC("[pt_exception_handler][ERROR] Page fault ouside allocated address space"); + static char str[256]; + snprintf(str, sizeof(str), "[ERROR] Page fault ouside allocated address space: type=%s, addr=%p, ip=%p, page_addr=0x%x, base=0x%x, size=0x%x\n", pt_exception_type_to_string(type, subtype), addr, ip, page_addr, vaddr_reg->base, vaddr_reg->size); + USER_PANIC(str); } if (!vaddr_reg->heap) { - debug_printf("[pt_exception_handler] type=%s, addr=%p, ip=%p\n", pt_exception_type_to_string(type, subtype), addr, ip); thread_mutex_unlock(&st->lock); - USER_PANIC("[ERROR] Page fault in allocated address space but outside heap"); + static char str[256]; + snprintf(str, sizeof(str), "[ERROR] Page fault in allocated address space but outside heap: type=%s, addr=%p, ip=%p\n", pt_exception_type_to_string(type, subtype), addr, ip); + USER_PANIC(str); } if (is_mapped(st, page_addr)) {