From b5adf16a96b9cbb80c74cf30404ed5bcff03ac34 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 22 Nov 2025 09:59:41 +0100 Subject: chore: DebuggerKit cleanup. Signed-off-by: Amlal El Mahrouss --- dev/DebuggerKit/CommonCLI.inl | 13 ++++++------ dev/DebuggerKit/DebuggerContract.h | 14 ++++++------- dev/DebuggerKit/NeKernelContract.h | 7 ++++--- dev/DebuggerKit/POSIXMachContract.h | 25 +++++------------------ dev/DebuggerKit/Platform.h | 31 +++++++++++++++++++++++------ dev/DebuggerKit/src/NeKernelContract.cc | 11 +++++----- dev/DebuggerKit/src/NeKernelContractCLI.cc | 11 +++++----- dev/DebuggerKit/src/POSIXMachContractCLI.cc | 25 +++++++++++------------ dev/LibC++/__abi.h | 8 +++++++- dev/LibC++/base_math.h | 17 ++++++++++++++-- dev/LibC++/base_process.h | 16 +++++++++------ dev/LibC++/defines.h | 10 +++------- 12 files changed, 104 insertions(+), 84 deletions(-) diff --git a/dev/DebuggerKit/CommonCLI.inl b/dev/DebuggerKit/CommonCLI.inl index a118634..e06a9b9 100644 --- a/dev/DebuggerKit/CommonCLI.inl +++ b/dev/DebuggerKit/CommonCLI.inl @@ -1,9 +1,8 @@ -/*** - DebuggerKit - (C) 2025 Amlal El Mahrouss - File: CommonCLI.inl - Purpose: Common Debugger symbols. -*/ +/* ======================================== + + Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license. + +======================================== */ #define kBlank "\e[0;30m" #define kRed "\e[0;31m" @@ -16,7 +15,7 @@ static Bool kKeepRunning = false; #ifdef DK_NEKERNEL_DEBUGGER static DebuggerKit::NeKernel::NeKernelContract kKernelDebugger; #else -static DebuggerKit::POSIX::POSIXMachContract kDebugger; +static DebuggerKit::POSIX::POSIXMachContract kUserDebugger; #endif static DebuggerKit::ProcessID kPID = 0L; diff --git a/dev/DebuggerKit/DebuggerContract.h b/dev/DebuggerKit/DebuggerContract.h index d1c8ed1..2114041 100644 --- a/dev/DebuggerKit/DebuggerContract.h +++ b/dev/DebuggerKit/DebuggerContract.h @@ -1,12 +1,12 @@ -/*** - (C) 2025 Amlal El Mahrouss - */ +/* ======================================== + + Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license. + +======================================== */ #pragma once -#include -#include -#include +#include #define DK_DEBUGGER_CONTRACT : public ::DebuggerKit::DebuggerContract @@ -46,7 +46,7 @@ class DebuggerContract { virtual std::unordered_map& Get() { return m_breakpoints; } protected: - ProcessID m_pid; + ProcessID m_pid{(ProcessID)~0}; std::unordered_map m_breakpoints; }; } // namespace DebuggerKit diff --git a/dev/DebuggerKit/NeKernelContract.h b/dev/DebuggerKit/NeKernelContract.h index 582741a..d048303 100644 --- a/dev/DebuggerKit/NeKernelContract.h +++ b/dev/DebuggerKit/NeKernelContract.h @@ -1,7 +1,8 @@ +/* ======================================== -/*** - (C) 2025 Amlal El Mahrouss, licensed under Apache-2.0. - */ + Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license. + +======================================== */ #ifndef DK_NEKERNEL_CONTRACT_H #define DK_NEKERNEL_CONTRACT_H diff --git a/dev/DebuggerKit/POSIXMachContract.h b/dev/DebuggerKit/POSIXMachContract.h index b1c0e0a..5bd4ba8 100644 --- a/dev/DebuggerKit/POSIXMachContract.h +++ b/dev/DebuggerKit/POSIXMachContract.h @@ -1,6 +1,8 @@ -/*** - (C) 2025 Amlal El Mahrouss, licensed under Apache-2.0. - */ +/* ======================================== + + Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license. + +======================================== */ #pragma once @@ -9,25 +11,8 @@ /// @file POSIXMachContract.h /// @brief POSIX Mach debugger. -#include #include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - CK_IMPORT_C kern_return_t mach_vm_write(vm_map_t target_task, mach_vm_address_t address, vm_offset_t data, mach_msg_type_number_t dataCnt); diff --git a/dev/DebuggerKit/Platform.h b/dev/DebuggerKit/Platform.h index 26f47ff..f878845 100644 --- a/dev/DebuggerKit/Platform.h +++ b/dev/DebuggerKit/Platform.h @@ -1,9 +1,8 @@ -/*** - DebuggerKit - (C) 2025 Amlal El Mahrouss, licensed under Apache-2.0. - File: Platform.h - Purpose: NeCTI Debugger Platform headers. -*/ +/* ======================================== + + Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license. + +======================================== */ #pragma once @@ -11,8 +10,28 @@ /// @author Amlal El Mahrouss /// =========================================================== /// +#include + #include #include #include #include + +#include +#include +#include +#include #include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include \ No newline at end of file diff --git a/dev/DebuggerKit/src/NeKernelContract.cc b/dev/DebuggerKit/src/NeKernelContract.cc index a062493..38f327d 100644 --- a/dev/DebuggerKit/src/NeKernelContract.cc +++ b/dev/DebuggerKit/src/NeKernelContract.cc @@ -1,9 +1,8 @@ -/*** - DebuggerKit - (C) 2025 Amlal El Mahrouss - File: NeKernelContract.cc - Purpose: NeCTI Debugger -*/ +/* ======================================== + + Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license. + +======================================== */ #ifdef DK_NEKERNEL_DEBUGGER diff --git a/dev/DebuggerKit/src/NeKernelContractCLI.cc b/dev/DebuggerKit/src/NeKernelContractCLI.cc index fe8181f..fc13a53 100644 --- a/dev/DebuggerKit/src/NeKernelContractCLI.cc +++ b/dev/DebuggerKit/src/NeKernelContractCLI.cc @@ -1,9 +1,8 @@ -/*** - DebuggerKit - (C) 2025 Amlal El Mahrouss - File: NeKernelContract.cc - Purpose: NeCTI Debugger CLI. -*/ +/* ======================================== + + Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license. + +======================================== */ #ifdef DK_NEKERNEL_DEBUGGER diff --git a/dev/DebuggerKit/src/POSIXMachContractCLI.cc b/dev/DebuggerKit/src/POSIXMachContractCLI.cc index 22a626d..77fe844 100644 --- a/dev/DebuggerKit/src/POSIXMachContractCLI.cc +++ b/dev/DebuggerKit/src/POSIXMachContractCLI.cc @@ -1,9 +1,8 @@ -/*** - DebuggerKit - (C) 2025 Amlal El Mahrouss - File: POSIXMachContract.cc - Purpose: OS X/Darwin Debugger -*/ +/* ======================================== + + Copyright (C) 2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license. + +======================================== */ #ifdef DK_MACH_DEBUGGER @@ -19,7 +18,7 @@ static void dbgi_ctrlc_handler(std::int32_t _) { return; } - kDebugger.Break(); + kUserDebugger.Break(); pfd::notify("Debugger Event", "Breakpoint hit!"); @@ -33,7 +32,7 @@ NECTI_MODULE(DebuggerMachPOSIX) { if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { kPath = argv[2]; - kDebugger.SetPath(kPath); + kUserDebugger.SetPath(kPath); kStdOut << "[+] Image set to: " << kPath << "\n"; } else { @@ -54,7 +53,7 @@ NECTI_MODULE(DebuggerMachPOSIX) { if (!std::getline(std::cin, cmd)) break; if (cmd == "c" || cmd == "cont" || cmd == "continue") { - if (kDebugger.Continue()) { + if (kUserDebugger.Continue()) { kKeepRunning = true; kStdOut << "[+] Continuing...\n"; @@ -63,17 +62,17 @@ NECTI_MODULE(DebuggerMachPOSIX) { } } - if (cmd == "d" || cmd == "detach") kDebugger.Detach(); + if (cmd == "d" || cmd == "detach") kUserDebugger.Detach(); if (cmd == "start") { kStdOut << "[?] Enter a argument to use: "; std::getline(std::cin, cmd); - kDebugger.Attach(kPath, cmd, kPID); + kUserDebugger.Attach(kPath, cmd, kPID); } if (cmd == "exit") { - if (kPID > 0) kDebugger.Detach(); + if (kPID > 0) kUserDebugger.Detach(); break; } @@ -83,7 +82,7 @@ NECTI_MODULE(DebuggerMachPOSIX) { std::getline(std::cin, cmd); - if (kDebugger.BreakAt(cmd)) { + if (kUserDebugger.BreakAt(cmd)) { pfd::notify("Debugger Event", "Add BreakAt at: " + cmd); } } diff --git a/dev/LibC++/__abi.h b/dev/LibC++/__abi.h index d46a9ee..70afae5 100644 --- a/dev/LibC++/__abi.h +++ b/dev/LibC++/__abi.h @@ -6,4 +6,10 @@ #pragma once -extern "C" void __compilerkit_unreachable(void); +#include + +__init_decl() + +extern void __compilerkit_unreachable(void); + +__fini_decl() \ No newline at end of file diff --git a/dev/LibC++/base_math.h b/dev/LibC++/base_math.h index 73cb174..60b260e 100644 --- a/dev/LibC++/base_math.h +++ b/dev/LibC++/base_math.h @@ -8,10 +8,14 @@ #include +#ifndef NAN +#define NAN (__builtin_nanf("")) +#endif // !NAN + /// @file Math.h /// @brief Math functions. -#ifdef __NE_USE_DOUBLE__ +#ifdef __LIBCXX_USE_DOUBLE__ typedef double real_type; #else typedef float real_type; @@ -20,7 +24,9 @@ typedef float real_type; namespace std::base_math { inline constexpr static auto not_a_number = NAN; +/// =========================================================== /// /// @brief Power function, with Repeat argument. +/// =========================================================== /// template inline real_type pow(real_type in) { if (Exponent == 0) return 1; // Any number to the power of 0 is 1. @@ -36,6 +42,9 @@ inline real_type pow(real_type in) { return result; } +/// =========================================================== /// +/// @brief Square root function. +/// =========================================================== /// inline real_type sqrt(real_type in) { if (in == 0) return 0; if (in == not_a_number) return not_a_number; @@ -51,8 +60,10 @@ inline real_type sqrt(real_type in) { return x; } +/// =========================================================== /// /// @brief Square of function, with Base template argument. -/// @param of Base argument to find sqquare of +/// @param of Base argument to find the square of. +/// =========================================================== /// template inline real_type surd(real_type in) { if (in == 0) return 0; @@ -64,10 +75,12 @@ inline real_type surd(real_type in) { return not_a_number; } +/// =========================================================== /// /// @brief Linear interpolation equation solver. /// @param from where? /// @param to to? /// @param Updated diff value according to difference. +/// =========================================================== /// inline real_type lerp(real_type to, real_type from, real_type stat) { real_type diff = (to - from); return from + (diff * stat); diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index abcbf08..f9b0596 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -8,14 +8,22 @@ #include +__init_decl() + /// @brief CRT exit, with exit code (!!! exits all threads. !!!) /// @param code the exit code. /// @return the return > 0 for non successful. -extern "C" int exit_(int code); +extern int exit_(int code); /// @brief CRT signal handler. /// @param code the signal code. -extern "C" void signal_(int code); +extern void signal_(int code); + +extern void (*__atexit_cdecl_ptr)(void); +extern void (**__atexit_lst_ptr)(void); +extern size_t __atexit_lst_cnt; + +__fini_decl() /// @brief Standard C++ namespace namespace std::base_process { @@ -24,10 +32,6 @@ 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; - inline int32_t exit(const int32_t& code) { for (auto idx = 0UL; idx < __atexit_lst_cnt; ++idx) { __atexit_lst_ptr[idx](); diff --git a/dev/LibC++/defines.h b/dev/LibC++/defines.h index e263d9c..b8ef10c 100644 --- a/dev/LibC++/defines.h +++ b/dev/LibC++/defines.h @@ -7,20 +7,16 @@ #ifndef __NECTI_DEFINES_H__ #define __NECTI_DEFINES_H__ -extern "C" { -#include -#include -} - #define __ATTRIBUTE(X) __attribute__((X)) typedef __SIZE_TYPE__ size_t; -typedef __SSIZE_TYPE__ ssize_t; +typedef __INT64_TYPE__ ssize_t; +typedef __INT32_TYPE__ int32_t; typedef void* ptr_type; typedef __SIZE_TYPE__ size_type; -typedef size_t ptrdiff_t; +typedef __INT64_TYPE__ ptrdiff_t; typedef size_t uintptr_t; typedef void* voidptr_t; typedef void* any_t; -- cgit v1.2.3