summaryrefslogtreecommitdiffhomepage
path: root/src/libDDK/DriverKit/ObjectKit
diff options
context:
space:
mode:
Diffstat (limited to 'src/libDDK/DriverKit/ObjectKit')
-rw-r--r--src/libDDK/DriverKit/ObjectKit/checksum.h39
-rw-r--r--src/libDDK/DriverKit/ObjectKit/ddk.h11
-rw-r--r--src/libDDK/DriverKit/ObjectKit/driver_base.h48
3 files changed, 98 insertions, 0 deletions
diff --git a/src/libDDK/DriverKit/ObjectKit/checksum.h b/src/libDDK/DriverKit/ObjectKit/checksum.h
new file mode 100644
index 00000000..5f9859e2
--- /dev/null
+++ b/src/libDDK/DriverKit/ObjectKit/checksum.h
@@ -0,0 +1,39 @@
+// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org)
+// Licensed under the Apache License, Version 2.0 (see LICENSE file)
+// Official repository: https://github.com/nekernel-org/nekernel
+
+#ifndef DRIVERKIT_CHECKSUM_H
+#define DRIVERKIT_CHECKSUM_H
+
+#include <DriverKit/ObjectKit/driver_base.h>
+
+namespace Kernel::DDK {
+
+using IndexableBlob = char*;
+using Indexable = char;
+
+/// @note This uses the FNV 64-bit variant.
+/// @brief Performs a checksum computation for a memory region.
+inline uintptr_t rtl_checksum(const IndexableBlob path) {
+ if (!path || *path == 0) return 0;
+
+ const uintptr_t kFNVSeed = 0xcbf29ce484222325ULL;
+ const uintptr_t kFNVPrime = 0x100000001b3ULL;
+
+ uintptr_t hash = kFNVSeed;
+
+ IndexableBlob path_ = path;
+
+ while (*path_) {
+ hash ^= (Indexable) (*path_++);
+ hash *= kFNVPrime;
+ }
+
+ return hash;
+}
+
+using Blob = void*;
+
+} // namespace Kernel::DDK
+
+#endif
diff --git a/src/libDDK/DriverKit/ObjectKit/ddk.h b/src/libDDK/DriverKit/ObjectKit/ddk.h
new file mode 100644
index 00000000..2d6dec75
--- /dev/null
+++ b/src/libDDK/DriverKit/ObjectKit/ddk.h
@@ -0,0 +1,11 @@
+// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org)
+// Licensed under the Apache License, Version 2.0 (see LICENSE file)
+// Official repository: https://github.com/nekernel-org/nekernel
+
+#ifndef DRIVERKIT_DDK_H
+#define DRIVERKIT_DDK_H
+
+#include <DriverKit/ObjectKit/checksum.h>
+#include <DriverKit/ObjectKit/driver_base.h>
+
+#endif
diff --git a/src/libDDK/DriverKit/ObjectKit/driver_base.h b/src/libDDK/DriverKit/ObjectKit/driver_base.h
new file mode 100644
index 00000000..909bfe7b
--- /dev/null
+++ b/src/libDDK/DriverKit/ObjectKit/driver_base.h
@@ -0,0 +1,48 @@
+// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
+// Licensed under the Apache License, Version 2.0 (see LICENSE file)
+// Official repository: https://github.com/nekernel-org/nekernel
+
+#ifndef DRIVERKIT_DRIVER_BASE_H
+#define DRIVERKIT_DRIVER_BASE_H
+
+#include <libDDK/DriverKit/macros.h>
+
+#define DDK_DRIVER_IMPL \
+ final: \
+ public \
+ ::Kernel::DDK::IDriverBase
+
+/// @author Amlal El Mahrouss
+/// @brief The DDK C++ API.
+
+namespace Kernel::DDK {
+
+inline constexpr auto kInvalidType = 0;
+
+/// @brief Driver interface type.
+class IDriverBase {
+ public:
+ IDriverBase() = default;
+ virtual ~IDriverBase() = default;
+
+ IDriverBase& operator=(const IDriverBase&) = delete;
+ IDriverBase(const IDriverBase&) = delete;
+
+ using PtrType = void*;
+
+ virtual constexpr bool IsCastable() { return false; }
+ virtual constexpr bool IsActive() { return false; }
+ virtual PtrType Leak() { return nullptr; }
+ virtual constexpr int32_t Type() { return kInvalidType; }
+};
+
+/// @brief This concept requires the Driver to be IDriverBase compliant.
+/// @author @amlel-el-mahrouss
+template <typename Driver>
+concept IsValidDriver = requires(Driver drv) {
+ { drv.IsActive() && drv.Type() > kInvalidType };
+};
+
+} // namespace Kernel::DDK
+
+#endif