From 209373b1f5770dc175e06996a152df6484f59af2 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 15:39:40 +0200 Subject: feat: implement `CompilerKitDylibTraits` container for future and current frontend tools. Signed-off-by: Amlal El Mahrouss --- dev/LibC++/__abi+unreachable.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'dev/LibC++') diff --git a/dev/LibC++/__abi+unreachable.cc b/dev/LibC++/__abi+unreachable.cc index fb1d336..f72e749 100644 --- a/dev/LibC++/__abi+unreachable.cc +++ b/dev/LibC++/__abi+unreachable.cc @@ -12,5 +12,6 @@ static const int32_t __unreachable_code = 34; extern "C" void __compilerkit_unreachable(void) { std::base_process::signal(__unreachable_code); - while (1); + while (1) + ; } \ No newline at end of file -- cgit v1.2.3 From bdc13bdc0a163d6839ed19a6077e61c162220826 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 15:46:57 +0200 Subject: feat: c++abi: introduce atexit ptr to cleanup data when exiting program. Signed-off-by: Amlal El Mahrouss --- dev/CompilerKit/utils/DylibHelpers.h | 10 +++++----- dev/LibC++/base_process.h | 12 +++++++++++- tools/pef-amd64-cxxdrv.cc | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'dev/LibC++') diff --git a/dev/CompilerKit/utils/DylibHelpers.h b/dev/CompilerKit/utils/DylibHelpers.h index 31e0b68..fede406 100644 --- a/dev/CompilerKit/utils/DylibHelpers.h +++ b/dev/CompilerKit/utils/DylibHelpers.h @@ -7,8 +7,8 @@ #pragma once #include -#include #include +#include struct CompilerKitDylibTraits; @@ -16,13 +16,13 @@ typedef Int32 (*CompilerKitEntrypoint)(Int32 argc, Char const* argv[]); typedef VoidPtr CompilerKitDylib; struct CompilerKitDylibTraits final { - CompilerKitDylib fDylib{nullptr}; + CompilerKitDylib fDylib{nullptr}; CompilerKitEntrypoint fEntrypoint{nullptr}; - std::mutex fMutex; + std::mutex fMutex; CompilerKitDylibTraits& operator()(const Char* path, const Char* fEntrypoint) { std::lock_guard lock(this->fMutex); - + if (!path || !fEntrypoint) return *this; if (this->fDylib) { @@ -36,7 +36,7 @@ struct CompilerKitDylibTraits final { return *this; } - this->fEntrypoint = (CompilerKitEntrypoint)dlsym(this->fDylib, fEntrypoint); + this->fEntrypoint = (CompilerKitEntrypoint) dlsym(this->fDylib, fEntrypoint); if (!this->fEntrypoint) { dlclose(this->fDylib); diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index 126ac60..900198f 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -12,7 +12,10 @@ /// @param code the exit code. /// @return the return > 0 for non successful. extern "C" int exit_(int code); -extern "C" int signal_(int code); + +/// @brief CRT signal handler. +/// @param code the signal code. +extern "C" void signal_(int code); /// @brief Standard C++ namespace namespace std::base_process { @@ -21,7 +24,14 @@ inline int signal(int code) { return -1; } +extern "C" void (*__atexit_lst_ptr)(void); +extern "C" size_t __atexit_lst_cnt; + inline int exit(int code) { + for (auto i = 0UL; i < __atexit_lst_cnt; ++i) { + __atexit_lst_ptr(); + } + exit_(code); return -1; } diff --git a/tools/pef-amd64-cxxdrv.cc b/tools/pef-amd64-cxxdrv.cc index 515f6ad..ae1653e 100644 --- a/tools/pef-amd64-cxxdrv.cc +++ b/tools/pef-amd64-cxxdrv.cc @@ -25,7 +25,7 @@ Int32 main(Int32 argc, Char const* argv[]) { CompilerKitDylibTraits dylib; dylib(kPath, kSymbol); - CompilerKitEntrypoint entrypoint_cxx = (CompilerKitEntrypoint)dylib.fEntrypoint; + CompilerKitEntrypoint entrypoint_cxx = (CompilerKitEntrypoint) dylib.fEntrypoint; if (!entrypoint_cxx) { kStdOut; -- cgit v1.2.3 From 5823a178acbeee2c5fd0744c042bbcc2f59800c0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 15:47:53 +0200 Subject: fix: atexit: fix atexit list. Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_process.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/LibC++') diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index 900198f..4768c61 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -24,12 +24,12 @@ inline int signal(int code) { return -1; } -extern "C" void (*__atexit_lst_ptr)(void); +extern "C" void (**__atexit_lst_ptr)(void); extern "C" size_t __atexit_lst_cnt; inline int exit(int code) { for (auto i = 0UL; i < __atexit_lst_cnt; ++i) { - __atexit_lst_ptr(); + __atexit_lst_ptr[i](); } exit_(code); -- cgit v1.2.3 From 54f5085758f59beb8395edd9658b99d555356578 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 15:49:07 +0200 Subject: feat: refactor `i` to `idx` for better readbility. Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_process.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/LibC++') diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index 4768c61..77e092e 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -28,8 +28,8 @@ extern "C" void (**__atexit_lst_ptr)(void); extern "C" size_t __atexit_lst_cnt; inline int exit(int code) { - for (auto i = 0UL; i < __atexit_lst_cnt; ++i) { - __atexit_lst_ptr[i](); + for (auto idx = 0UL; idx < __atexit_lst_cnt; ++idx) { + __atexit_lst_ptr[idx](); } exit_(code); -- cgit v1.2.3 From cfde696e68ce91ce776807ff44276136cb84e5ba Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 15:54:05 +0200 Subject: feat: introduce `__atexit__cdecl_ptr` to `std::atexit` Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_process.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'dev/LibC++') diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index 77e092e..a30ccca 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -24,6 +24,7 @@ inline int signal(int code) { return -1; } +extern "C" void (*__atexit__cdecl_ptr)(void); extern "C" void (**__atexit_lst_ptr)(void); extern "C" size_t __atexit_lst_cnt; @@ -32,6 +33,8 @@ inline int exit(int code) { __atexit_lst_ptr[idx](); } + if (__atexit__cdecl_ptr) __atexit__cdecl_ptr(); + exit_(code); return -1; } -- cgit v1.2.3 From b112e21f9017b90e3fc48c85383eb368033a97d0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 24 Aug 2025 22:19:39 +0200 Subject: feat: LibC++: improve `exit` function. Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_process.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dev/LibC++') diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index a30ccca..034240f 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -24,16 +24,16 @@ inline int signal(int code) { return -1; } -extern "C" void (*__atexit__cdecl_ptr)(void); +extern "C" void (*__atexit_cdecl_ptr)(void); extern "C" void (**__atexit_lst_ptr)(void); extern "C" size_t __atexit_lst_cnt; -inline int exit(int code) { +inline int32_t exit(const int32_t& code) { for (auto idx = 0UL; idx < __atexit_lst_cnt; ++idx) { __atexit_lst_ptr[idx](); } - if (__atexit__cdecl_ptr) __atexit__cdecl_ptr(); + if (__atexit_cdecl_ptr) __atexit_cdecl_ptr(); exit_(code); return -1; -- cgit v1.2.3 From a7b43769b2f6dae5abdda4cb2649e43b02fbeea7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 28 Aug 2025 09:00:15 +0200 Subject: feat: v0.0.3e1 (Ogre) Signed-off-by: Amlal El Mahrouss --- dev/DebuggerKit/POSIXMachContract.h | 2 +- dev/DebuggerKit/dk-nekernel.json | 17 +++++++++++++++++ dev/DebuggerKit/dk-osx.json | 18 ++++++++++++++++++ dev/DebuggerKit/ld-nekernel.json | 17 ----------------- dev/DebuggerKit/ld-osx.json | 18 ------------------ dev/DebuggerKit/src/NeKernelContract.cc | 5 ++--- dev/LibC++/utility.h | 12 ++++++------ 7 files changed, 44 insertions(+), 45 deletions(-) create mode 100644 dev/DebuggerKit/dk-nekernel.json create mode 100644 dev/DebuggerKit/dk-osx.json delete mode 100644 dev/DebuggerKit/ld-nekernel.json delete mode 100644 dev/DebuggerKit/ld-osx.json (limited to 'dev/LibC++') diff --git a/dev/DebuggerKit/POSIXMachContract.h b/dev/DebuggerKit/POSIXMachContract.h index b04a13a..931852a 100644 --- a/dev/DebuggerKit/POSIXMachContract.h +++ b/dev/DebuggerKit/POSIXMachContract.h @@ -93,7 +93,7 @@ class POSIXMachContract : public DebuggerContract { BOOL BreakAt(std::string symbol) noexcept override { if (!m_path.empty() && std::filesystem::exists(m_path) && std::filesystem::is_regular_file(m_path)) { - auto handle = dlopen(m_path.c_str(), RTDK_LAZY); + auto handle = dlopen(m_path.c_str(), RTLD_LAZY); if (handle == nullptr) { return false; diff --git a/dev/DebuggerKit/dk-nekernel.json b/dev/DebuggerKit/dk-nekernel.json new file mode 100644 index 0000000..45ee51d --- /dev/null +++ b/dev/DebuggerKit/dk-nekernel.json @@ -0,0 +1,17 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": [ + "../DebuggerKit", + "../" + ], + "sources_path": ["src/*.cc"], + "output_name": "/usr/local/lib/libDebuggerKit.dylib", + "compiler_flags": ["-fPIC", "-shared"], + "cpp_macros": [ + "__NECTI__=202505", + "CK_USE_STRUCTS=1", + "DK_NEKERNEL_DEBUGGER", + "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" + ] +} diff --git a/dev/DebuggerKit/dk-osx.json b/dev/DebuggerKit/dk-osx.json new file mode 100644 index 0000000..c220756 --- /dev/null +++ b/dev/DebuggerKit/dk-osx.json @@ -0,0 +1,18 @@ +{ + "compiler_path": "clang++", + "compiler_std": "c++20", + "headers_path": [ + "../DebuggerKit", + "../" + ], + "sources_path": ["src/*.cc"], + "output_name": "/usr/local/lib/libDebuggerKit.dylib", + "compiler_flags": ["-fPIC", "-shared"], + "cpp_macros": [ + "__NECTI__=202505", + "CK_USE_STRUCTS=1", + "DEBUGGERKIT_POSIX", + "DK_MACH_DEBUGGER", + "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" + ] +} diff --git a/dev/DebuggerKit/ld-nekernel.json b/dev/DebuggerKit/ld-nekernel.json deleted file mode 100644 index 45ee51d..0000000 --- a/dev/DebuggerKit/ld-nekernel.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "compiler_path": "g++", - "compiler_std": "c++20", - "headers_path": [ - "../DebuggerKit", - "../" - ], - "sources_path": ["src/*.cc"], - "output_name": "/usr/local/lib/libDebuggerKit.dylib", - "compiler_flags": ["-fPIC", "-shared"], - "cpp_macros": [ - "__NECTI__=202505", - "CK_USE_STRUCTS=1", - "DK_NEKERNEL_DEBUGGER", - "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" - ] -} diff --git a/dev/DebuggerKit/ld-osx.json b/dev/DebuggerKit/ld-osx.json deleted file mode 100644 index c220756..0000000 --- a/dev/DebuggerKit/ld-osx.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "compiler_path": "clang++", - "compiler_std": "c++20", - "headers_path": [ - "../DebuggerKit", - "../" - ], - "sources_path": ["src/*.cc"], - "output_name": "/usr/local/lib/libDebuggerKit.dylib", - "compiler_flags": ["-fPIC", "-shared"], - "cpp_macros": [ - "__NECTI__=202505", - "CK_USE_STRUCTS=1", - "DEBUGGERKIT_POSIX", - "DK_MACH_DEBUGGER", - "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" - ] -} diff --git a/dev/DebuggerKit/src/NeKernelContract.cc b/dev/DebuggerKit/src/NeKernelContract.cc index a469e46..a071431 100644 --- a/dev/DebuggerKit/src/NeKernelContract.cc +++ b/dev/DebuggerKit/src/NeKernelContract.cc @@ -12,9 +12,8 @@ #include #include -#include - #include +#include using namespace DebuggerKit::NeKernel; @@ -44,4 +43,4 @@ BOOL NeKernelContract::Detach() noexcept { return NO; } -#endif // DK_NEKERNEL_DEBUGGER \ No newline at end of file +#endif // DK_NEKERNEL_DEBUGGER diff --git a/dev/LibC++/utility.h b/dev/LibC++/utility.h index 4f1d2d7..082d73d 100644 --- a/dev/LibC++/utility.h +++ b/dev/LibC++/utility.h @@ -1,7 +1,7 @@ /* ------------------------------------------- - \ - Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. \ - \ + + Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. + ------------------------------------------- */ #ifndef LIBCXX_UTILITY_H @@ -13,8 +13,8 @@ namespace std { /// @param arg the object. /// @return object's rvalue template -inline Args&& forward(Args& arg) { - return static_cast(arg); +inline auto forward(Args& arg) -> Args&& { + return static_cast(arg); } /// @brief Move object. @@ -22,7 +22,7 @@ inline Args&& forward(Args& arg) { /// @param arg the object. /// @return object's rvalue template -inline Args&& move(Args&& arg) { +inline auto move(Args&& arg) -> Args&& { return static_cast(arg); } } // namespace std -- cgit v1.2.3