[Zion] Add a way to unwind the stack and recover from user-space faults.

This commit is contained in:
Drew Galbraith 2023-11-22 18:25:08 -08:00
parent 8ceab2ad23
commit 941d7c8d59
6 changed files with 63 additions and 0 deletions

View file

@ -0,0 +1,20 @@
#include "common/stack_unwind.h"
#include "debug/debug.h"
namespace {
bool IsValid(uint64_t* rbp) { return rbp && *rbp != kStackBaseSentinel; }
} // namespace
void StackUnwind(uint64_t rbp) {
dbgln("-- Begin Stack --");
uint64_t* rbp_ptr = reinterpret_cast<uint64_t*>(rbp);
while (IsValid(rbp_ptr)) {
uint64_t rip = *(rbp_ptr + 1);
dbgln("RIP: {x}", rip);
rbp_ptr = reinterpret_cast<uint64_t*>(*rbp_ptr);
}
dbgln("-- End Stack --");
}

View file

@ -0,0 +1,7 @@
#pragma once
#include <stdint.h>
const uint64_t kStackBaseSentinel = 0xABBACDCD'12345678;
void StackUnwind(uint64_t rbp);