aboutsummaryrefslogtreecommitdiff
path: root/src/unw.c
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-06 02:49:23 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-06 02:49:23 +0000
commit908b70ab00fb03ea62d1c74b0dc07bc9c8df8cc0 (patch)
tree7d7c8f41dd19513c412759e49a44890c51d8eeb0 /src/unw.c
parentfeat(lgr): add logger (diff)
downloadcodebase-908b70ab00fb03ea62d1c74b0dc07bc9c8df8cc0.tar.gz
feat(unw): add stack unwinding
Diffstat (limited to 'src/unw.c')
-rw-r--r--src/unw.c43
1 files changed, 43 insertions, 0 deletions
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 @@
1// unw.c --- stack unwinding -*- C -*-
2//
3// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
4//
5// SPDX-License-Identifier: MIT
6//
7// This file is part of COSMOS Codebase.
8//
9// Commentary:
10//
11// Code:
12
13#include "unw.h"
14#include "dbg.h"
15#include "lgr.h"
16
17#include <stdlib.h>
18
19UNW_DEFINE_REASON (INVAL, "Invalid argument");
20
21THREAD_LOCAL const struct unw_reason *_unw_reason;
22THREAD_LOCAL int _unw_code;
23THREAD_LOCAL struct unw_frame *_unw_top;
24
25void
26_unw (const struct unw_reason *reason, int code)
27{
28 DBG_ASSERT_NN (reason);
29 DBG_ASSERT_NN (reason->sym);
30 DBG_ASSERT_NN (reason->msg);
31 DBG_ASSERT_NZ (code, "%d");
32
33 _unw_reason = reason;
34 _unw_code = code;
35
36 if (_unw_top)
37 longjmp (_unw_top->jmp, code);
38
39 CTX_FATAL ("Unhandled %s (%s) with code: %d", reason->sym, reason->msg, code);
40 abort ();
41}
42
43// unw.c ends here