summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/CompilerKit/PEF.h11
-rw-r--r--include/CompilerKit/Ref.h36
-rw-r--r--include/CompilerKit/Utilities/DLL.h35
3 files changed, 50 insertions, 32 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