Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
Panic.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <cstdio>
10#include <cstdlib>
11
12namespace corium {
13
16using PanicHandlerFn = void (*)(const char* file, int line, const char* message) noexcept;
17
18namespace internal {
19
20inline PanicHandlerFn& getPanicHandler() noexcept {
21 static PanicHandlerFn handler = nullptr;
22 return handler;
23}
24
25inline void panic(const char* file, int line, const char* message) noexcept {
26 if (auto fn = getPanicHandler()) {
27 fn(file, line, message);
28 return;
29 }
30#if defined(CORIUM_CUSTOM_PANIC)
31 CORIUM_CUSTOM_PANIC(file, line, message);
32#elif defined(__arm__) || defined(__thumb__)
33 __asm volatile("bkpt #0");
34 for (;;) {}
35#else
36 (void)std::fprintf(stderr, "Corium Panic: %s (%s:%d)\n", message, file, line);
37 std::abort();
38#endif
39}
40
41} // namespace internal
42
45inline void setPanicHandler(PanicHandlerFn fn) noexcept {
47}
48
49} // namespace corium
50
51#if defined(CORIUM_ENABLE_ASSERTIONS) || !defined(NDEBUG)
52#define CORIUM_ASSERT(cond, msg) \
53 do { \
54 if (!(cond)) [[unlikely]] { \
55 ::corium::internal::panic(__FILE__, __LINE__, msg); \
56 } \
57 } while (0)
58#else
59#define CORIUM_ASSERT(cond, msg) do { (void)sizeof(cond); } while (0)
60#endif
61
62#define CORIUM_PANIC(msg) ::corium::internal::panic(__FILE__, __LINE__, msg)
void setPanicHandler(PanicHandlerFn fn) noexcept
Configure the global bare-metal panic handler hook (e.g. for Hardware Fault logging).
Definition Panic.hpp:45
void(*)(const char *file, int line, const char *message) noexcept PanicHandlerFn
Signature of the custom bare-metal panic handler callback.
Definition Panic.hpp:16
void panic(const char *file, int line, const char *message) noexcept
Definition Panic.hpp:25
PanicHandlerFn & getPanicHandler() noexcept
Definition Panic.hpp:20
Definition Application.hpp:16