aboutsummaryrefslogtreecommitdiff
path: root/src/unw.c
blob: abd31ec7a6838baba1670fcb69841a1100ef92e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// unw.c --- stack unwinding                                           -*- C -*-
//
// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
//
// SPDX-License-Identifier: MIT
//
// This file is part of COSMOS Codebase.
//
// Commentary:
//
// Code:

#include "unw.h"
#include "dbg.h"
#include "lgr.h"

#include <stdlib.h>

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