From 6d60157da042a2c9105db83908ffec037a22a775 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Thu, 9 Mar 2023 00:43:15 +0100 Subject: [PATCH] fix (stack-tracing): fixed symbol name resolve bug when function is extern / assembly --- kernel/inc/utils/symbol.h | 2 +- kernel/src/mm/stack.c | 2 +- kernel/src/utils/panic.c | 2 +- kernel/src/utils/symbol.c | 5 ++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/inc/utils/symbol.h b/kernel/inc/utils/symbol.h index 21b3ac5..1ff062e 100644 --- a/kernel/inc/utils/symbol.h +++ b/kernel/inc/utils/symbol.h @@ -39,6 +39,6 @@ typedef struct { } symbol_T; symbol_T* symbol_resolve_from_name (symbol_T* symbols, uint64_t num_symbols, string_t name); -symbol_T* symbol_resolve_function_from_rip (symbol_T* symbols, uint64_t num_symbols, uint64_t rip); +symbol_T* symbol_resolve_from_rip (symbol_T* symbols, uint64_t num_symbols, uint64_t rip); #endif //NOX_SYMBOLS_H diff --git a/kernel/src/mm/stack.c b/kernel/src/mm/stack.c index 47be71f..6770e0e 100644 --- a/kernel/src/mm/stack.c +++ b/kernel/src/mm/stack.c @@ -36,7 +36,7 @@ void stack_trace_call_stack(uint64_t rbp) { log(LOG_NONE, " 0x%x -> (process NULL reference)", rip); return; } - symbol_T* symbol = symbol_resolve_function_from_rip(process->executable->symbols, process->executable->num_symbols, rip); + symbol_T* symbol = symbol_resolve_from_rip(process->executable->symbols, process->executable->num_symbols, rip); if (symbol == NULL) { log(LOG_NONE, " 0x%x -> (symbol NULL reference)", rip); diff --git a/kernel/src/utils/panic.c b/kernel/src/utils/panic.c index 01daadf..e8d1a3f 100644 --- a/kernel/src/utils/panic.c +++ b/kernel/src/utils/panic.c @@ -89,7 +89,7 @@ void panic_log_call_stack(cpu_state_T* state) { log(LOG_NONE, "Call Stack:"); stack_trace_call_stack(state->rbp); - symbol_T* symbol = symbol_resolve_function_from_rip(process->executable->symbols, process->executable->num_symbols, state->rip); + symbol_T* symbol = symbol_resolve_from_rip(process->executable->symbols, process->executable->num_symbols,state->rip); if (symbol == NULL) { log(LOG_NONE, " 0x%x -> (symbol NULL reference)", state->rip); return; diff --git a/kernel/src/utils/symbol.c b/kernel/src/utils/symbol.c index 63fc4cd..a8feb33 100644 --- a/kernel/src/utils/symbol.c +++ b/kernel/src/utils/symbol.c @@ -33,13 +33,12 @@ symbol_T* symbol_resolve_from_name(symbol_T* symbols, uint64_t num_symbols, stri return NULL; } -symbol_T* symbol_resolve_function_from_rip(symbol_T* symbols, uint64_t num_symbols, uint64_t rip) { +symbol_T* symbol_resolve_from_rip(symbol_T* symbols, uint64_t num_symbols, uint64_t rip) { symbol_T* symbol = NULL; for (uint64_t i = 0; i < num_symbols; i++) { if (symbols[i].address <= rip && - (symbol == NULL || symbols[i].address > symbol->address) && - symbols[i].type == SYMBOL_FUNCTION) + (symbol == NULL || symbols[i].address > symbol->address)) { symbol = &symbols[i]; }