Fix braces + init_paging args

This commit is contained in:
2026-03-11 19:58:00 +01:00
parent 9d409317e2
commit 8e2a612d88
29 changed files with 147 additions and 229 deletions

View File

@@ -1,3 +1,9 @@
/*
* @author xamidev <xamidev@riseup.net>
* @brief Stack trace tools
* @license GPL-3.0-only
*/
#include <stdint.h>
#include "kernel.h"
@@ -6,45 +12,39 @@ extern struct init_status init;
void debug_stack_trace(unsigned int max_frames)
{
DEBUG("*** begin stack trace ***");
if (init.terminal)
{
if (init.terminal) {
printf("\r\n*** begin stack trace ***\r\n");
}
// Thanks GCC :)
uintptr_t* rbp = (uintptr_t*)__builtin_frame_address(0);
for (unsigned int frame=0; frame<max_frames && rbp != NULL; frame++)
{
for (unsigned int frame=0; frame<max_frames && rbp != NULL; frame++) {
// Return address, 1 word above saved rbp
uintptr_t rip = rbp[1];
uintptr_t offset = 0;
const char* name = debug_find_symbol(rip, &offset);
DEBUG("[%u] <0x%p> (%s+0x%x)", frame, (void*)rip, name, offset);
if (init.terminal)
{
if (init.terminal) {
printf("[%u] <0x%p> (%s+0x%x)\r\n", frame, (void*)rip, name, offset);
}
uintptr_t* next_rbp = (uintptr_t*)rbp[0];
// invalid rbp or we're at the end
if (next_rbp <= rbp || next_rbp == NULL)
{
// Invalid rbp or we're at the end
if (next_rbp <= rbp || next_rbp == NULL) {
break;
}
rbp = next_rbp;
}
if (init.terminal)
{
if (init.terminal) {
printf("*** end stack trace ***");
}
DEBUG("*** end stack trace ***");
}
typedef struct
{
typedef struct {
uint64_t addr;
const char *name;
} __attribute__((packed)) kernel_symbol_t;
@@ -55,8 +55,7 @@ __attribute__((weak)) extern uint64_t symbol_count;
// binary search
const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset)
{
if (!symbol_table || symbol_count == 0)
{
if (!symbol_table || symbol_count == 0) {
if (offset) *offset = 0;
return "???";
}
@@ -64,11 +63,9 @@ const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset)
int low = 0, high = (int)symbol_count - 1;
int best = -1;
while (low <= high)
{
while (low <= high) {
int mid = (low + high) / 2;
if (symbol_table[mid].addr <= rip)
{
if (symbol_table[mid].addr <= rip) {
best = mid;
low = mid + 1;
} else {
@@ -76,15 +73,15 @@ const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset)
}
}
if (best != -1)
{
if (offset)
{
if (best != -1) {
if (offset) {
*offset = rip - symbol_table[best].addr;
}
return symbol_table[best].name;
}
if (offset) *offset = 0;
if (offset) {
*offset = 0;
}
return "unknown";
}