ZXFoundation™ 26h2
Loading...
Searching...
No Matches
core.cxxm
1/// SPDX-License-Identifier: Apache-2.0
2/// @file zxfoundation/sys/syschk.cxxm
3/// @brief Last-resort global system teardown (system check).
4
5export module zxfoundation.sys.syschk.core;
6import zxfoundation.sys.syschk.types;
7import arch.s390x.init.zxfl.protocol;
8import lib.error;
9import lib.format;
10import std;
11
12export {
13
14namespace zxfoundation::sys::syschk {
15
16 /// @brief Initialize the system-check subsystem.
17 /// @param[in] proto The ZXFL boot protocol.
18 auto init(const arch::s390x::init::zxfl::protocol& proto) noexcept -> void;
19
20 /// @brief Record a kernel error. Conditionally halt.
21 /// @param[in] err The @c lib::kernel_error that triggered this check.
22 /// Its @c category and @c code are stored verbatim in the
23 /// crash record — no translation occurs.
24 /// @param[in] sev Severity annotation. Affects the log level used and the
25 /// @c severity byte of the crash record. All severity levels
26 /// currently result in an unconditional halt.
27 /// @param[in] msg Human-readable reason string. Truncated to
28 /// @c ZX_CRASH_MSG_LEN - 1 bytes.
29 /// @param[in] location Source location of the call site.
30 auto system_check(
31 lib::kernel_error err,
32 syschk_severity sev,
33 std::string_view msg,
34 std::source_location location
35 ) noexcept -> void;;
36
37 /// @brief Issue a fatal system check with a formatted message.
38 /// @param[in] err The @c lib::kernel_error that triggered the check.
39 /// @param[in] fl Format string literal and call-site source location.
40 /// Implicitly constructed from a string literal; the
41 /// source_location is captured at the call site.
42 /// @param[in] args Format arguments forwarded to @c lib::format::format_to.
43 /// @note The formatted output is truncated to @c ZX_CRASH_MSG_LEN - 1
44 /// bytes. No allocation occurs — the buffer is stack-local.
45 template <typename... Args>
46 [[noreturn]] auto syschk_fatal(
47 lib::kernel_error err,
48 fmt_loc fl,
49 Args&&... args
50 ) noexcept -> void {
51 char buf[ZX_CRASH_MSG_LEN];
52 lib::format::format_to(std::span(buf, ZX_CRASH_MSG_LEN), fl.fmt, args...);
53 system_check(err, syschk_severity::fatal, std::string_view(buf), fl.loc);
54 __builtin_unreachable();
55 }
56
57 /// @brief Issue a critical system check with a formatted message.
58 /// @param[in] err The @c lib::kernel_error that triggered the check.
59 /// @param[in] fl Format string literal and call-site source location.
60 /// @param[in] args Format arguments forwarded to @c lib::format::format_to.
61 /// @note The formatted output is truncated to @c ZX_CRASH_MSG_LEN - 1 bytes.
62 template <typename... Args>
63 [[noreturn]] auto syschk_critical(
64 lib::kernel_error err,
65 fmt_loc fl,
66 Args&&... args
67 ) noexcept -> void {
68 char buf[ZX_CRASH_MSG_LEN];
69 lib::format::format_to(std::span<char>(buf, ZX_CRASH_MSG_LEN), fl.fmt, args...);
70 system_check(err, syschk_severity::critical, std::string_view(buf), fl.loc);
71 __builtin_unreachable();
72 }
73
74 /// @brief Issue a warning-level system check with a formatted message.
75 /// @param[in] err The @c lib::kernel_error that triggered the check.
76 /// @param[in] fl Format string literal and call-site source location.
77 /// @param[in] args Format arguments forwarded to @c lib::format::format_to.
78 /// @note The formatted output is truncated to @c ZX_CRASH_MSG_LEN - 1 bytes.
79 template <typename... Args>
80 auto syschk_warning(
81 lib::kernel_error err,
82 fmt_loc fl,
83 Args&&... args
84 ) noexcept -> void {
85 char buf[ZX_CRASH_MSG_LEN];
86 lib::format::format_to(std::span<char>(buf, ZX_CRASH_MSG_LEN), fl.fmt, args...);
87 system_check(err, syschk_severity::warning, std::string_view(buf), fl.loc);
88 }
89
90 /// @brief Issue a notice-level system check with a formatted message.
91 /// @param[in] err The @c lib::kernel_error that triggered the check.
92 /// @param[in] fl Format string literal and call-site source location.
93 /// @param[in] args Format arguments forwarded to @c lib::format::format_to.
94 /// @note The formatted output is truncated to @c ZX_CRASH_MSG_LEN - 1 bytes.
95 template <typename... Args>
96 auto syschk_notice(
97 lib::kernel_error err,
98 fmt_loc fl,
99 Args&&... args
100 ) noexcept -> void {
101 char buf[ZX_CRASH_MSG_LEN];
102 lib::format::format_to(std::span<char>(buf, ZX_CRASH_MSG_LEN), fl.fmt, args...);
103 system_check(err, syschk_severity::notice, std::string_view(buf), fl.loc);
104 }
105
106} // namespace zxfoundation::sys::syschk
107
108} // end export