feat: add support for console sessions to crashpad and crash handling in kernel
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* main.cpp
|
||||
* MontaukOS Crashpad — displays crash reports in a popup window
|
||||
* MontaukOS Crashpad - renders process crash information
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,20 @@
|
||||
|
||||
using namespace gui;
|
||||
|
||||
static bool is_desktop_running() {
|
||||
static montauk::abi::ProcInfo procs[256];
|
||||
int count = montauk::proclist(procs, 256);
|
||||
if (count <= 0) return false;
|
||||
|
||||
int self_pid = montauk::getpid();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (montauk::streq(procs[i].name, "0:/os/desktop.elf")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static constexpr int WINDOW_W = 460;
|
||||
static constexpr int WINDOW_H = 480;
|
||||
static constexpr int PADDING = 12;
|
||||
@@ -201,6 +215,42 @@ static void render() {
|
||||
g_win.present();
|
||||
}
|
||||
|
||||
// ==== Console (no-desktop) crash report ====
|
||||
// When no desktop is running, the crashpad is spawned with its stdout
|
||||
// redirected to the same out-stream as the crashed process (wired up by the
|
||||
// kernel in SpawnCrashPad), so montauk::print() lands in the console terminal.
|
||||
static void emit(const char* s) { montauk::print(s); }
|
||||
|
||||
static void emit_kv_hex(const char* key, uint64_t val) {
|
||||
char buf[32];
|
||||
emit(" ");
|
||||
emit(key);
|
||||
emit(": ");
|
||||
format_hex16(buf, val);
|
||||
emit(buf);
|
||||
emit("\n");
|
||||
}
|
||||
|
||||
static void render_console() {
|
||||
char num[16];
|
||||
emit("\n\033[1;31m*** Process crashed ***\033[0m\n");
|
||||
emit("Process: ");
|
||||
emit(g_report.processName);
|
||||
emit(" (pid ");
|
||||
format_decimal(num, g_report.pid);
|
||||
emit(num);
|
||||
emit(")\n");
|
||||
emit("Exception: ");
|
||||
emit(g_report.exceptionName);
|
||||
emit("\n");
|
||||
emit_kv_hex("RIP", g_report.instructionPointer);
|
||||
emit_kv_hex("RSP", g_report.stackPointer);
|
||||
emit_kv_hex("RFLAGS", g_report.flags);
|
||||
if (g_report.exceptionVector == 0x0E)
|
||||
emit_kv_hex("CR2 (fault addr)", g_report.faultingAddress);
|
||||
emit("\n");
|
||||
}
|
||||
|
||||
extern "C" void _start() {
|
||||
fonts::init();
|
||||
|
||||
@@ -208,42 +258,48 @@ extern "C" void _start() {
|
||||
int available = montauk::crash_report(&g_report);
|
||||
if (available <= 0) montauk::exit(1);
|
||||
|
||||
if (!g_win.create("Process Crashed", WINDOW_W, WINDOW_H)) montauk::exit(1);
|
||||
if (is_desktop_running()) {
|
||||
if (!g_win.create("Process Crashed", WINDOW_W, WINDOW_H)) montauk::exit(1);
|
||||
|
||||
render();
|
||||
render();
|
||||
|
||||
while (true) {
|
||||
montauk::abi::WinEvent ev;
|
||||
int r = g_win.poll(&ev);
|
||||
if (r < 0) break;
|
||||
if (r == 0) {
|
||||
montauk::sleep_ms(16);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ev.type == 3) break; // close
|
||||
|
||||
if (ev.type == 0 && ev.key.pressed) {
|
||||
if (ev.key.scancode == 0x01) break; // Escape
|
||||
if (ev.key.scancode == 0x51) {
|
||||
// Page Down: scroll down
|
||||
g_scroll += 60;
|
||||
render();
|
||||
while (true) {
|
||||
montauk::abi::WinEvent ev;
|
||||
int r = g_win.poll(&ev);
|
||||
if (r < 0) break;
|
||||
if (r == 0) {
|
||||
montauk::sleep_ms(16);
|
||||
continue;
|
||||
}
|
||||
if (ev.key.scancode == 0x49) {
|
||||
// Page Up: scroll up
|
||||
g_scroll -= 60;
|
||||
if (g_scroll < 0) g_scroll = 0;
|
||||
|
||||
if (ev.type == 3) break; // close
|
||||
|
||||
if (ev.type == 0 && ev.key.pressed) {
|
||||
if (ev.key.scancode == 0x01) break; // Escape
|
||||
if (ev.key.scancode == 0x51) {
|
||||
// Page Down: scroll down
|
||||
g_scroll += 60;
|
||||
render();
|
||||
}
|
||||
if (ev.key.scancode == 0x49) {
|
||||
// Page Up: scroll up
|
||||
g_scroll -= 60;
|
||||
if (g_scroll < 0) g_scroll = 0;
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
if (ev.type == 2) {
|
||||
// Resize
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
if (ev.type == 2) {
|
||||
// Resize
|
||||
render();
|
||||
}
|
||||
g_win.destroy();
|
||||
} else {
|
||||
// No desktop: print a textual report to the redirected console.
|
||||
render_console();
|
||||
}
|
||||
|
||||
g_win.destroy();
|
||||
montauk::exit(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user