diff --git a/kernel/src/mm/stack.c b/kernel/src/mm/stack.c index ef59a5c..fd4be11 100644 --- a/kernel/src/mm/stack.c +++ b/kernel/src/mm/stack.c @@ -23,6 +23,7 @@ #include "mm/stack.h" #include "utils/logger.h" +#include "proc/scheduler.h" void stack_dump_call_info(uint64_t rip, symbol_T* symbol) { log(LOG_NONE, " 0x%x+%xw -> %s", symbol->address, rip - symbol->address, symbol->name); @@ -30,7 +31,8 @@ void stack_dump_call_info(uint64_t rip, symbol_T* symbol) { void stack_trace_call_stack(uint64_t rbp) { uint64_t rip = ((uint64_t*)rbp)[1]; - symbol_T* symbol = symbol_resolve_function_from_rip(g_kernel_executable->symbols, g_kernel_executable->num_symbols, rip); + process_T* process = scheduler_get_current_process(); + symbol_T* symbol = symbol_resolve_function_from_rip(process->executable->symbols, process->executable->num_symbols, rip); if (symbol != NULL && !string_compare(symbol->name, "_start")) { stack_trace_call_stack(((uint64_t*)rbp)[0]); diff --git a/kernel/src/utils/panic.c b/kernel/src/utils/panic.c index 078d3e4..0d327a6 100644 --- a/kernel/src/utils/panic.c +++ b/kernel/src/utils/panic.c @@ -26,6 +26,7 @@ #include "utils/core.h" #include "platform/exceptions.h" #include "mm/stack.h" +#include "proc/scheduler.h" void panic_log_paging_info(cpu_state_T* state) { log(LOG_NONE, "Paging Info:"); @@ -78,15 +79,22 @@ void panic_log_registers(cpu_state_T* state) { } void panic_log_call_stack(cpu_state_T* state) { + process_T* process = scheduler_get_current_process(); + if (process == NULL || process->executable == NULL) { + log(LOG_NONE, "Call Stack not resolvable (no symbol data access)"); + return; + } + log(LOG_NONE, "Call Stack:"); stack_trace_call_stack(state->rbp); - symbol_T* symbol = symbol_resolve_function_from_rip(g_kernel_executable->symbols, g_kernel_executable->num_symbols, state->rip); - if (symbol != NULL) { - stack_dump_call_info(state->rip, symbol); - } else { + symbol_T* symbol = symbol_resolve_function_from_rip(process->executable->symbols, process->executable->num_symbols, state->rip); + if (symbol == NULL) { log(LOG_NONE, " 0x%x -> ", state->rip); + return; } + + stack_dump_call_info(state->rip, symbol); } void panic(cpu_state_T* state, string_t message) {