diff options
| author | 2026-11-06 02:49:23 +0000 | |
|---|---|---|
| committer | 2026-11-06 02:49:23 +0000 | |
| commit | 908b70ab00fb03ea62d1c74b0dc07bc9c8df8cc0 (patch) | |
| tree | 7d7c8f41dd19513c412759e49a44890c51d8eeb0 /src/unw.c | |
| parent | feat(lgr): add logger (diff) | |
| download | codebase-908b70ab00fb03ea62d1c74b0dc07bc9c8df8cc0.tar.gz | |
feat(unw): add stack unwinding
Diffstat (limited to 'src/unw.c')
| -rw-r--r-- | src/unw.c | 43 |
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 | |||
| 19 | UNW_DEFINE_REASON (INVAL, "Invalid argument"); | ||
| 20 | |||
| 21 | THREAD_LOCAL const struct unw_reason *_unw_reason; | ||
| 22 | THREAD_LOCAL int _unw_code; | ||
| 23 | THREAD_LOCAL struct unw_frame *_unw_top; | ||
| 24 | |||
| 25 | void | ||
| 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 | ||
