From d3892e80f787f86062733bd8ad3e725fb548d6fe Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 30 Nov 2025 09:51:43 -0500 Subject: chore: added new aliases for OwnPtr and ErrorOr (OwnOr) chore: use STATIC_PASS instead of static_assert in /src/kernel. Signed-off-by: Amlal El Mahrouss --- src/boot/BootKit/Qr.h | 4 ++-- src/boot/BootKit/QrPrelude.h | 8 ++++++++ src/kernel/KernelKit/PCI/Device.h | 6 ++++-- src/kernel/NeKit/KernelPanic.h | 8 +++----- src/kernel/NeKit/OwnPtr.h | 6 +++++- src/kernel/SignalKit/Signals.h | 8 +++++--- 6 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/boot/BootKit/Qr.h b/src/boot/BootKit/Qr.h index f5ac5f2e..ab4696cc 100644 --- a/src/boot/BootKit/Qr.h +++ b/src/boot/BootKit/Qr.h @@ -3,7 +3,7 @@ #include #include - +#include #include #include #include @@ -265,7 +265,7 @@ struct Qr { void apply_mask(int mask, uint8_t* patterns); private: - static_assert(V >= 1 && V <= 40, "invalid version"); + STATIC_PASS(V >= 1 && V <= 40, "invalid version"); static constexpr int SIDE = 17 + V * 4; static constexpr int N_BITS = SIDE * SIDE; static constexpr int N_ALIGN = V == 1 ? 0 : V / 7 + 2; diff --git a/src/boot/BootKit/QrPrelude.h b/src/boot/BootKit/QrPrelude.h index e89fad7a..7b09fdb0 100644 --- a/src/boot/BootKit/QrPrelude.h +++ b/src/boot/BootKit/QrPrelude.h @@ -1 +1,9 @@ +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + #include \ No newline at end of file diff --git a/src/kernel/KernelKit/PCI/Device.h b/src/kernel/KernelKit/PCI/Device.h index c8caf67c..e9c5a683 100644 --- a/src/kernel/KernelKit/PCI/Device.h +++ b/src/kernel/KernelKit/PCI/Device.h @@ -3,9 +3,11 @@ Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. ======================================== */ + #pragma once #include +#include namespace Kernel::PCI { enum class PciConfigKind : UShort { @@ -38,13 +40,13 @@ class Device final { public: template UInt Read(UInt bar) { - static_assert(sizeof(T) <= sizeof(UInt32), "64-bit PCI addressing is unsupported"); + STATIC_PASS(sizeof(T) <= sizeof(UInt32), "64-bit PCI addressing is unsupported"); return Read(bar, sizeof(T)); } template void Write(UInt bar, UIntPtr data) { - static_assert(sizeof(T) <= sizeof(UInt32), "64-bit PCI addressing is unsupported"); + STATIC_PASS(sizeof(T) <= sizeof(UInt32), "64-bit PCI addressing is unsupported"); Write(bar, data, sizeof(T)); } diff --git a/src/kernel/NeKit/KernelPanic.h b/src/kernel/NeKit/KernelPanic.h index cba8897c..a12ff73c 100644 --- a/src/kernel/NeKit/KernelPanic.h +++ b/src/kernel/NeKit/KernelPanic.h @@ -9,11 +9,8 @@ #include -namespace Kernel { -void ke_runtime_check(bool expr, const Char* file, const Char* line); -} - -#define MUST_PASS_COMPILER(EXPR, MSG) static_assert(EXPR, MSG) +/// @brief Checks during compile time whether a condition passes. +#define STATIC_PASS(EXPR, MSG) static_assert(EXPR, MSG) #ifdef TRY #undef TRY @@ -65,5 +62,6 @@ enum RUNTIME_CHECK { typedef enum RUNTIME_CHECK RTL_RUNTIME_CHECK; namespace Kernel { +void ke_runtime_check(bool expr, const Char* file, const Char* line); void ke_panic(const Int32& id, const Char* message = nullptr); } // namespace Kernel diff --git a/src/kernel/NeKit/OwnPtr.h b/src/kernel/NeKit/OwnPtr.h index 2c493b1b..18a31bd1 100644 --- a/src/kernel/NeKit/OwnPtr.h +++ b/src/kernel/NeKit/OwnPtr.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace Kernel { template @@ -56,8 +57,11 @@ class OwnPtr final { T* fCls{nullptr}; }; +template +using OwnOr = ErrorOr>; + template -inline OwnPtr make_ptr(Args... args) { +inline OwnPtr make_ptr(Args&&... args) { OwnPtr ret; ret.template New(forward(args)...); diff --git a/src/kernel/SignalKit/Signals.h b/src/kernel/SignalKit/Signals.h index cb7abfa1..700a4f41 100644 --- a/src/kernel/SignalKit/Signals.h +++ b/src/kernel/SignalKit/Signals.h @@ -7,7 +7,9 @@ #pragma once #include +#include +#define SIGBAD 0 /* bad signal*/ #define SIGKILL 1 /* kill */ #define SIGPAUS 2 /* pause */ #define SIGEXEC 3 /* execute */ @@ -34,7 +36,7 @@ inline constexpr auto kKernelSignalSeed = 0x0895034f9fUL; /// @brief Generate signal from **Sig** template inline rt_signal_kind sig_generate_unique() { - static_assert(Sig > 0, "Signal is zero (invalid)"); + STATIC_PASS(Sig > SIGBAD, "Signal is zero (invalid)"); return Sig ^ Seed; } @@ -44,8 +46,8 @@ inline BOOL sig_matches_seed(rt_signal_kind sig) { return (sig & 0xFF000000) == (Seed & 0xFF000000); } -/// @brief Validate signal from **sig** +/// @brief Validate signal from **sig** and whtether the signal is greater than SIGDTCH. inline BOOL sig_validate_unique(rt_signal_kind sig) { - return sig > 0; + return sig > SIGBAD && sig > SIGDTCH; } } // namespace Kernel -- cgit v1.2.3