summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/boot/BootKit/Qr.h4
-rw-r--r--src/boot/BootKit/QrPrelude.h8
-rw-r--r--src/kernel/KernelKit/PCI/Device.h6
-rw-r--r--src/kernel/NeKit/KernelPanic.h8
-rw-r--r--src/kernel/NeKit/OwnPtr.h6
-rw-r--r--src/kernel/SignalKit/Signals.h8
-rw-r--r--src/libDDK/DriverKit/c++/driver_base.h8
-rw-r--r--src/libSystem/SystemKit/Verify.h2
8 files changed, 33 insertions, 17 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
diff --git a/src/libDDK/DriverKit/c++/driver_base.h b/src/libDDK/DriverKit/c++/driver_base.h
index c130ba8b..97f07f2a 100644
--- a/src/libDDK/DriverKit/c++/driver_base.h
+++ b/src/libDDK/DriverKit/c++/driver_base.h
@@ -20,6 +20,8 @@
/// @author Amlal El Mahrouss
namespace Kernel::DDK {
+constexpr auto kInvalidType = 0;
+
class IDriverBase {
public:
explicit IDriverBase() = default;
@@ -32,17 +34,17 @@ class IDriverBase {
virtual BOOL IsCastable() { return NO; }
virtual constexpr BOOL IsActive() { return NO; }
virtual PtrType Leak() { return nullptr; }
- virtual constexpr Int32 Type() { return 0; }
+ virtual constexpr Int32 Type() { return kInvalidType; }
};
/// @brief This concept requires the Driver to be IDriverBase compliant.
template <typename T>
concept IsValidDriver = requires(T driver_base) {
- { driver_base.IsActive() && driver_base.Type() > 0 };
+ { driver_base.IsActive() && driver_base.Type() > kInvalidType };
};
/// @brief Consteval helper to detect whether a template is truly based on IDriverBase.
/// @note This helper is consteval only.
template <IsValidDriver T>
-inline consteval void ce_ddk_is_valid(T) {}
+consteval void ce_ddk_is_valid(T) {}
} // namespace Kernel::DDK
diff --git a/src/libSystem/SystemKit/Verify.h b/src/libSystem/SystemKit/Verify.h
index 7d15435a..b99dbecc 100644
--- a/src/libSystem/SystemKit/Verify.h
+++ b/src/libSystem/SystemKit/Verify.h
@@ -33,7 +33,7 @@ struct must_cast_traits<T, T> {
/// @author Amlal El Mahrouss
/// @brief Safe constexpr cast.
template <typename T, typename R>
-inline constexpr R* sys_constexpr_cast(T* ptr) {
+constexpr R* sys_constexpr_cast(T* ptr) {
static_assert(must_cast_traits<T, R>::value, "constexpr cast failed! types are mismatching!");
return static_cast<R*>(ptr);
}