From 908b70ab00fb03ea62d1c74b0dc07bc9c8df8cc0 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Fri, 6 Nov 2026 05:49:23 +0300 Subject: feat(unw): add stack unwinding --- src/unw.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/unw.c (limited to 'src/unw.c') diff --git a/src/unw.c b/src/unw.c new file mode 100644 index 0000000..abd31ec --- /dev/null +++ b/src/unw.c @@ -0,0 +1,43 @@ +// unw.c --- stack unwinding -*- C -*- +// +// Copyright (c) 2026 Martin Michalec +// +// SPDX-License-Identifier: MIT +// +// This file is part of COSMOS Codebase. +// +// Commentary: +// +// Code: + +#include "unw.h" +#include "dbg.h" +#include "lgr.h" + +#include + +UNW_DEFINE_REASON (INVAL, "Invalid argument"); + +THREAD_LOCAL const struct unw_reason *_unw_reason; +THREAD_LOCAL int _unw_code; +THREAD_LOCAL struct unw_frame *_unw_top; + +void +_unw (const struct unw_reason *reason, int code) +{ + DBG_ASSERT_NN (reason); + DBG_ASSERT_NN (reason->sym); + DBG_ASSERT_NN (reason->msg); + DBG_ASSERT_NZ (code, "%d"); + + _unw_reason = reason; + _unw_code = code; + + if (_unw_top) + longjmp (_unw_top->jmp, code); + + CTX_FATAL ("Unhandled %s (%s) with code: %d", reason->sym, reason->msg, code); + abort (); +} + +// unw.c ends here -- cgit v1.3.1