diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-30 09:51:43 -0500 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-30 09:54:07 -0500 |
| commit | d3892e80f787f86062733bd8ad3e725fb548d6fe (patch) | |
| tree | 25029f4e491e3da39b6ce66760f8742ad73f16d2 /src | |
| parent | ba3cd2194412914936c1c00efe87391d0615cd17 (diff) | |
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 <amlal@nekernel.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/boot/BootKit/Qr.h | 4 | ||||
| -rw-r--r-- | src/boot/BootKit/QrPrelude.h | 8 | ||||
| -rw-r--r-- | src/kernel/KernelKit/PCI/Device.h | 6 | ||||
| -rw-r--r-- | src/kernel/NeKit/KernelPanic.h | 8 | ||||
| -rw-r--r-- | src/kernel/NeKit/OwnPtr.h | 6 | ||||
| -rw-r--r-- | src/kernel/SignalKit/Signals.h | 8 |
6 files changed, 27 insertions, 13 deletions
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 <BootKit/Shared/base.h> #include <BootKit/Shared/bit.h> - +#include <NeKit/KernelPanic.h> #include <BootKit/QrPrelude.h> #include <BootKit/Support.h> #include <CompilerKit/Detail.h> @@ -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 <BootKit/BitManip.h>
\ 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 <NeKit/Config.h> +#include <NeKit/KernelPanic.h> namespace Kernel::PCI { enum class PciConfigKind : UShort { @@ -38,13 +40,13 @@ class Device final { public: template <typename T> 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 <typename T> 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 <NeKit/Config.h> -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 <NeKit/Config.h> #include <NeKit/KernelPanic.h> #include <NeKit/Ref.h> +#include <NeKit/ErrorOr.h> namespace Kernel { template <typename T> @@ -56,8 +57,11 @@ class OwnPtr final { T* fCls{nullptr}; }; +template <typename T> +using OwnOr = ErrorOr<OwnPtr<T>>; + template <typename T, typename... Args> -inline OwnPtr<T> make_ptr(Args... args) { +inline OwnPtr<T> make_ptr(Args&&... args) { OwnPtr<T> ret; ret.template New<Args...>(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 <NeKit/Config.h> +#include <NeKit/KernelPanic.h> +#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 <rt_signal_kind Sig, SizeT Seed = kUserSignalSeed> 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 |
