summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-02-11 15:42:42 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-02-11 15:42:42 +0100
commite8cebdd573c584dc51c396b35810ca08cb350c82 (patch)
tree266e3cd9af7095cf8b53ace8332827ab80507d83
parent270dfb1ebd40a848bb5c79cf69cf31325457b20c (diff)
feat: CK: Improve codebase and introduce new concepts in DLL.h..
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--include/CompilerKit/PEF.h11
-rw-r--r--include/CompilerKit/Ref.h36
-rw-r--r--include/CompilerKit/Utilities/DLL.h35
-rw-r--r--src/CommandLine/pef-amd64-asm.cc6
-rw-r--r--src/CommandLine/pef-amd64-necdrv.cc6
-rw-r--r--src/CompilerKit/ck-posix.json3
6 files changed, 58 insertions, 39 deletions
diff --git a/include/CompilerKit/PEF.h b/include/CompilerKit/PEF.h
index c142931..0c3fd78 100644
--- a/include/CompilerKit/PEF.h
+++ b/include/CompilerKit/PEF.h
@@ -21,10 +21,17 @@
#define kPefDebugExt ".dbg"
#define kPefDriverExt ".sys"
+/// PEF Specific (128-bit)
#define kPefZero128 ".zero128"
#define kPefCode128 ".code128"
#define kPefData128 ".data128"
+/// JVM Specific
+#define kPefJZero32 ".jzero32"
+#define kPefJCode32 ".jcode32"
+#define kPefJData32 ".jdata32"
+
+/// PEF Specific (64-bit)
#define kPefZero64 ".zero64"
#define kPefCode64 ".code64"
#define kPefData64 ".data64"
@@ -32,7 +39,7 @@
/* @note counting the \0 at the end */
#define kPefMagicLen (5)
-#define kPefVersion (0x0500)
+#define kPefVersion (0x0510)
#define kPefNameLen (255)
#define kPefBaseOrigin (0x40000000)
@@ -41,6 +48,7 @@
#define kPefStart "__ImageStart"
namespace CompilerKit {
+
/* @brief Architecture type. */
enum {
kPefArchIntel86S,
@@ -114,6 +122,7 @@ enum {
kPefLinkerID = 0x1,
kPefCount = 4,
};
+
} // namespace CompilerKit
inline std::ofstream& operator<<(std::ofstream& fp, CompilerKit::PEFContainer& container) {
diff --git a/include/CompilerKit/Ref.h b/include/CompilerKit/Ref.h
index 8690ad1..7ccf040 100644
--- a/include/CompilerKit/Ref.h
+++ b/include/CompilerKit/Ref.h
@@ -17,10 +17,10 @@ class StrongRef {
StrongRef() = default;
virtual ~StrongRef() {
- if (m_Strong) {
- MUST_PASS(m_Class);
- if (m_Class) delete m_Class;
- m_Class = nullptr;
+ if (mStrong) {
+ MUST_PASS(mClass);
+ if (mClass) delete mClass;
+ mClass = nullptr;
}
}
@@ -29,30 +29,30 @@ class StrongRef {
using Type = T;
protected:
- StrongRef(Type* cls, const bool strong) : m_Class(cls), m_Strong(strong) {}
+ StrongRef(Type* cls, const bool strong) : mClass(cls), mStrong(strong) {}
public:
- StrongRef(Type* cls) : m_Class(cls), m_Strong(true) {}
+ StrongRef(Type* cls) : mClass(cls), mStrong(true) {}
StrongRef& operator=(Type* ref) {
- m_Class = ref;
+ mClass = ref;
return *this;
}
public:
- Type* operator->() const { return m_Class; }
+ Type* operator->() const { return mClass; }
- Type* Leak() { return m_Class; }
+ Type* Leak() { return mClass; }
- Type* operator*() { return m_Class; }
+ Type* operator*() { return mClass; }
- bool IsStrong() const { return m_Strong; }
+ bool IsStrong() const { return mStrong; }
- explicit operator bool() { return m_Class != nullptr; }
+ explicit operator bool() { return mClass != nullptr; }
private:
- Type* m_Class{nullptr};
- bool m_Strong{false};
+ Type* mClass{nullptr};
+ bool mStrong{false};
};
template <typename T>
@@ -75,18 +75,18 @@ template <typename Type>
class NonNullRef final {
public:
explicit NonNullRef() = delete;
- NonNullRef(Type* ref) : m_Ref(ref, true) {}
+ NonNullRef(Type* ref) : mRef(ref, true) {}
StrongRef<Type>& operator->() {
- MUST_PASS(m_Ref);
- return m_Ref;
+ MUST_PASS(mRef);
+ return mRef;
}
NonNullRef& operator=(const NonNullRef<Type>& ref) = delete;
NonNullRef(const NonNullRef<Type>& ref) = default;
private:
- StrongRef<Type> m_Ref{nullptr};
+ StrongRef<Type> mRef{nullptr};
};
using StrongAny = StrongRef<VoidPtr>;
diff --git a/include/CompilerKit/Utilities/DLL.h b/include/CompilerKit/Utilities/DLL.h
index 92e6a63..f57ec4f 100644
--- a/include/CompilerKit/Utilities/DLL.h
+++ b/include/CompilerKit/Utilities/DLL.h
@@ -7,11 +7,14 @@
#define NECTAR_COMPILERKIT_UTILITIES_DLL_H
#include <CompilerKit/Detail/Config.h>
+#include <CompilerKit/Ref.h>
#include <dlfcn.h>
#include <mutex>
namespace CompilerKit {
-class DLLLoader final {
+
+#ifdef CK_POSIX
+class ModuleLoader final {
public:
using EntryT = Int32 (*)(Int32 argc, Char const* argv[]);
using HandleT = VoidPtr;
@@ -24,40 +27,39 @@ class DLLLoader final {
MutexT mMutex;
public:
- explicit operator bool() { return this->mDLL; }
+ explicit operator bool() { return this->mDLL != nullptr; }
- DLLLoader& operator()(const Char* path, const Char* entrypoint) {
- if (!path || !entrypoint) return *this;
+ ModuleLoader& operator()(const std::string& path, const std::string& entrypoint) {
+ if (path.empty() || entrypoint.empty()) return *this;
std::lock_guard<MutexT> lock(this->mMutex);
if (this->mDLL) {
- this->Destroy();
+ this->Reset();
}
- this->mDLL = ::dlopen(path, RTLD_LAZY);
+ this->mDLL = ::dlopen(path.data(), RTLD_LAZY);
if (!this->mDLL) {
return *this;
}
- this->fEntrypoint = reinterpret_cast<EntryT>(::dlsym(this->mDLL, entrypoint));
+ this->fEntrypoint = reinterpret_cast<EntryT>(::dlsym(this->mDLL, entrypoint.data()));
if (!this->fEntrypoint) {
- this->Destroy();
+ this->Reset();
return *this;
}
return *this;
}
- NECTAR_COPY_DELETE(DLLLoader)
+ NECTAR_COPY_DELETE(ModuleLoader)
- DLLLoader() = default;
- ~DLLLoader() { this->Destroy(); }
+ ModuleLoader() = default;
+ ~ModuleLoader() { this->Reset(); }
- private:
- void Destroy() noexcept {
+ void Reset() noexcept {
if (this->mDLL) {
::dlclose(this->mDLL);
this->mDLL = nullptr;
@@ -66,6 +68,13 @@ class DLLLoader final {
this->fEntrypoint = nullptr;
}
};
+
+using StrongDLLRef = StrongRef<ModuleLoader>;
+using WeakDLLRef = WeakRef<ModuleLoader>;
+#else
+#error No ModuleLoader defined.
+#endif
+
} // namespace CompilerKit
#endif // NECTAR_COMPILERKIT_UTILITIES_DLL_H
diff --git a/src/CommandLine/pef-amd64-asm.cc b/src/CommandLine/pef-amd64-asm.cc
index 1316d93..3ca4639 100644
--- a/src/CommandLine/pef-amd64-asm.cc
+++ b/src/CommandLine/pef-amd64-asm.cc
@@ -20,11 +20,11 @@ static auto kPath = "/usr/lib/libCompilerKit.so";
static auto kSymbol = "AssemblerMainAMD64";
Int32 main(Int32 argc, Char const* argv[]) {
- CompilerKit::DLLLoader dylib;
+ CompilerKit::ModuleLoader dylib;
dylib(kPath, kSymbol);
- CompilerKit::DLLLoader::EntryT entrypoint_cxx =
- reinterpret_cast<CompilerKit::DLLLoader::EntryT>(dylib.fEntrypoint);
+ CompilerKit::ModuleLoader::EntryT entrypoint_cxx =
+ reinterpret_cast<CompilerKit::ModuleLoader::EntryT>(dylib.fEntrypoint);
if (!entrypoint_cxx) {
kStdOut;
diff --git a/src/CommandLine/pef-amd64-necdrv.cc b/src/CommandLine/pef-amd64-necdrv.cc
index 921c674..c8d8dbe 100644
--- a/src/CommandLine/pef-amd64-necdrv.cc
+++ b/src/CommandLine/pef-amd64-necdrv.cc
@@ -20,11 +20,11 @@ static auto kPath = "/usr/lib/libCompilerKit.so";
static auto kSymbol = "CompilerNectarAMD64";
Int32 main(Int32 argc, Char const* argv[]) {
- CompilerKit::DLLLoader dylib;
+ CompilerKit::ModuleLoader dylib;
dylib(kPath, kSymbol);
- CompilerKit::DLLLoader::EntryT entrypoint_cxx =
- reinterpret_cast<CompilerKit::DLLLoader::EntryT>(dylib.fEntrypoint);
+ CompilerKit::ModuleLoader::EntryT entrypoint_cxx =
+ reinterpret_cast<CompilerKit::ModuleLoader::EntryT>(dylib.fEntrypoint);
if (!entrypoint_cxx) {
kStdOut;
diff --git a/src/CompilerKit/ck-posix.json b/src/CompilerKit/ck-posix.json
index 264a4a6..9694662 100644
--- a/src/CompilerKit/ck-posix.json
+++ b/src/CompilerKit/ck-posix.json
@@ -17,8 +17,9 @@
"-shared"
],
"cpp_macros": [
- "__NECTAR__=202505",
+ "__NECTAR__=202602",
"CK_USE_STRUCTS=1",
+ "CK_POSIX=1",
"kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)"
],
"description": "CompilerKit for POSIX. CK is the framework behind Nectar."