From baf2afd8cd672dcb9c13d956dfdd73b61dfee558 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 19 Mar 2024 10:05:31 +0100 Subject: unstable, secret: See below. System.Core: - Add RunTime init function. - Add ReadMe.md Kernel: - Improve TLS code, use Encoder class instead of casting directly. - Refactor process team to include processscheduler.hpp instead. ObjectKit: - Rename Object.hxx to ObjectKit.hxx Builtins/AHCI: - Rename API.hxx to Interface.hxx Signed-off-by: Amlal El Mahrouss --- Private/Builtins/AHCI/API.hxx | 24 -------------- Private/Builtins/AHCI/Interface.hxx | 28 ++++++++++++++++ Private/KernelKit/ProcessScheduler.hpp | 1 - Private/KernelKit/ProcessTeam.hpp | 9 ------ Private/KernelKit/SMPManager.hpp | 10 +++--- Private/KernelKit/ThreadLocalStorage.hxx | 15 +++------ .../NewBoot/Source/HEL/AMD64/BootFileReader.cxx | 2 +- Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 2 +- Private/NewBoot/Source/makefile | 2 +- Private/NewKit/Defines.hpp | 28 +++++++++++++--- Private/ObjectKit/Object.hxx | 36 --------------------- Private/ObjectKit/ObjectKit.hxx | 37 ++++++++++++++++++++++ Private/Source/ProcessTeam.cxx | 2 +- Private/Source/ThreadLocalStorage.cxx | 15 +++++---- 14 files changed, 110 insertions(+), 101 deletions(-) delete mode 100644 Private/Builtins/AHCI/API.hxx create mode 100644 Private/Builtins/AHCI/Interface.hxx delete mode 100644 Private/KernelKit/ProcessTeam.hpp delete mode 100644 Private/ObjectKit/Object.hxx create mode 100644 Private/ObjectKit/ObjectKit.hxx (limited to 'Private') diff --git a/Private/Builtins/AHCI/API.hxx b/Private/Builtins/AHCI/API.hxx deleted file mode 100644 index 90e68bad..00000000 --- a/Private/Builtins/AHCI/API.hxx +++ /dev/null @@ -1,24 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - - File: API.hxx - Purpose: AHCI API. - - Revision History: - - 03/17/24: Added file (amlel) - -------------------------------------------- */ - -#pragma once - -#include -#include -#include - -#define kObjectAHCINamespace "AHCI_DRV\\" - -namespace HCore::Builtins { -inline Boolean ke_get_ahci_handle(ObjectPtr* ppAhciObject); -} // namespace HCore::Builtins \ No newline at end of file diff --git a/Private/Builtins/AHCI/Interface.hxx b/Private/Builtins/AHCI/Interface.hxx new file mode 100644 index 00000000..72be3d6a --- /dev/null +++ b/Private/Builtins/AHCI/Interface.hxx @@ -0,0 +1,28 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: Interface.hxx + Purpose: AHCI Interface. + + Revision History: + + 03/17/24: Added file (amlel) + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +#define kObjectAHCINamespace "AHCI\\" + +namespace HCore::Builtins { +/// @brief Returns an AHCI handle. +/// @param pointerAhciObject the handle to pass. +/// @return +inline Boolean HcGetHandleAHCI(_InOut ObjectPtr* pointerAhciObject); +} // namespace HCore::Builtins \ No newline at end of file diff --git a/Private/KernelKit/ProcessScheduler.hpp b/Private/KernelKit/ProcessScheduler.hpp index 733c7c65..fa59be4b 100644 --- a/Private/KernelKit/ProcessScheduler.hpp +++ b/Private/KernelKit/ProcessScheduler.hpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include diff --git a/Private/KernelKit/ProcessTeam.hpp b/Private/KernelKit/ProcessTeam.hpp deleted file mode 100644 index 9538bbae..00000000 --- a/Private/KernelKit/ProcessTeam.hpp +++ /dev/null @@ -1,9 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include diff --git a/Private/KernelKit/SMPManager.hpp b/Private/KernelKit/SMPManager.hpp index 49406f1b..c207be82 100644 --- a/Private/KernelKit/SMPManager.hpp +++ b/Private/KernelKit/SMPManager.hpp @@ -4,8 +4,8 @@ ------------------------------------------- */ -#ifndef _INC_SMP_MANAGER_HPP -#define _INC_SMP_MANAGER_HPP +#ifndef __SMP_MANAGER__ +#define __SMP_MANAGER__ #include #include @@ -112,11 +112,11 @@ class SMPManager final { /// @brief wakes up thread. /// wakes up thread from hang. -void rt_wakeup_thread(HAL::StackFrame* stack); +Void rt_wakeup_thread(HAL::StackFramePtr stack); /// @brief makes thread sleep. /// hooks and hangs thread to prevent code from executing. -void rt_hang_thread(HAL::StackFrame* stack); +Void rt_hang_thread(HAL::StackFramePtr stack); } // namespace HCore -#endif // !_INC_SMP_MANAGER_HPP +#endif // !__SMP_MANAGER__ diff --git a/Private/KernelKit/ThreadLocalStorage.hxx b/Private/KernelKit/ThreadLocalStorage.hxx index 2fab5026..c6be2c2b 100644 --- a/Private/KernelKit/ThreadLocalStorage.hxx +++ b/Private/KernelKit/ThreadLocalStorage.hxx @@ -26,28 +26,21 @@ T *tls_new_class(Args &&...args); #define kTLSCookieLen 3 -typedef HCore::Char* rt_cookie_type; - -#define kTIBNameLen 256 - /// @brief Thread Information Block for Local Storage. /// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) -struct ThreadInformationBlock final { - HCore::Char Name[kTIBNameLen]; // Module Name +struct PACKED ThreadInformationBlock final { + HCore::Char Cookie[kTLSCookieLen]; HCore::UIntPtr StartCode; // Start Address HCore::UIntPtr StartData; // Allocation Heap HCore::UIntPtr StartStack; // Stack Pointer. - HCore::Int32 Arch; // Architecture and/or platform. - HCore::Int32 ID; // Thread execution ID. - rt_cookie_type Cookie; // Not shown in public header, location of the cookie header is store here, this is the way we tell - // something went wrong. + HCore::Int32 ThreadID; // Thread execution ID. }; /// @brief TLS install TIB EXTERN_C void rt_install_tib(ThreadInformationBlock *pTib, HCore::VoidPtr pPib); ///! @brief Cookie Sanity check. -HCore::Boolean tls_check_tib(ThreadInformationBlock *ptr); +HCore::Boolean tls_check_tib(ThreadInformationBlock* ptr); /// @brief TLS check system call EXTERN_C HCore::Void tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcept; diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx index 8418fd4c..350ea0e7 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx @@ -107,7 +107,7 @@ Void BFileReader::ReadAll() { if (auto err = BS->AllocatePool(EfiLoaderCode, mSizeFile, (VoidPtr*)&mBlob) != kEfiOk) { mWriter.Write(L"*** EFI-Code: ").Write(err).Write(L" ***\r\n"); - EFI::RaiseHardError(L"HCoreLdr_PageError", L"Allocation error."); + EFI::RaiseHardError(L"NewBoot_PageError", L"Allocation error."); } } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index cfd58516..a45d12e4 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -45,7 +45,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, for (auto& ch : strDate) writer.WriteCharacter(ch); - writer.Write(L"\r\nHCoreLdr: Firmware Vendor: ") + writer.Write(L"\r\nNewBoot: Firmware Vendor: ") .Write(SystemTable->FirmwareVendor) .Write(L"\r\n"); diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 2eab4a84..fbedfd52 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -33,7 +33,7 @@ invalid-recipe: bootloader-amd64: compile-amd64 $(LD_GNU) $(OBJ) $(LD_FLAGS) -o NewBoot.exe $(COPY) NewBoot.exe CDROM/EFI/BOOT/BOOTX64.EFI - $(COPY) NewBoot.exe CDROM/EFI/BOOT/HCORELDR.EFI + $(COPY) NewBoot.exe CDROM/EFI/BOOT/NEWBOOT.EFI $(ADD_FILE) CDROM/.HCORE .PHONY: compile-amd64 diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp index 563af7d2..c111f80f 100644 --- a/Private/NewKit/Defines.hpp +++ b/Private/NewKit/Defines.hpp @@ -8,10 +8,6 @@ #include -#ifndef __KERNEL__ -# error You are not compiling the kernel. -#endif - #define NEWKIT_VERSION "1.01" #if !defined(_INC_NO_STDC_HEADERS) && defined(__GNUC__) @@ -20,9 +16,11 @@ #ifdef __has_feature #if !__has_feature(cxx_nullptr) +#if !__has_nullptr #error You must at least have nullptr featured on your C++ compiler. #endif #endif +#endif namespace HCore { using voidPtr = void *; @@ -89,6 +87,28 @@ template inline Args &&move(Args &&arg) { return static_cast(arg); } + +/// @brief Encoding class +class Encoder final { +public: + explicit Encoder() = default; + ~Encoder() = default; + + Encoder &operator=(const Encoder &) = default; + Encoder(const Encoder &) = default; + +public: + template + Char* AsBytes(T type) { + return reinterpret_cast(type); + } + + template + Y As(T type) { + return reinterpret_cast(type); + } + +}; } // namespace HCore #define DEDUCE_ENDIAN(address, value) \ diff --git a/Private/ObjectKit/Object.hxx b/Private/ObjectKit/Object.hxx deleted file mode 100644 index dbb7944d..00000000 --- a/Private/ObjectKit/Object.hxx +++ /dev/null @@ -1,36 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include -#include - -#define kObjectGlobalNamespaceSystem "HCORE_ROOT\\" -#define kObjectGlobalNamespaceUser "HCORE_USER_ROOT\\" - -enum { - kObjectTypeProcess, - kObjectTypeFile, - kObjectTypeDevice, - kObjectTypeNetwork, - kObjectTypeInvalid, - kObjectTypeCount, -}; - -/// \brief Object handle. -/// \author Amlal El Mahrouss -typedef struct Object final { - HCore::Char ObjectName[255]; - HCore::Int32 ObjectType; - HCore::Char ObjectNamespace[255]; - - HCore::Void(*Release)(struct Object* Self); - HCore::IntPtr(*Invoke)(struct Object* Self, HCore::Int32 Sel, ...); - HCore::Void(*Query)(struct Object* Self, HCore::VoidPtr* Dst, HCore::SizeT SzDst, HCore::XRN::GUIDSequence GuidOf); -} Object, *ObjectPtr; - -#define object_cast reinterpret_cast diff --git a/Private/ObjectKit/ObjectKit.hxx b/Private/ObjectKit/ObjectKit.hxx new file mode 100644 index 00000000..329b2c78 --- /dev/null +++ b/Private/ObjectKit/ObjectKit.hxx @@ -0,0 +1,37 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include +#include + +#define kObjectGlobalNamespaceSystem "HCORE_ROOT\\" +#define kObjectGlobalNamespaceUser "HCORE_USER_ROOT\\" + +enum { + kObjectTypeProcess, + kObjectTypeFile, + kObjectTypeDevice, + kObjectTypeNetwork, + kObjectTypeInvalid, + KObjectTypeUserDefined = 0xCF, + kObjectTypeCount = 5, +}; + +/// \brief Object handle. +/// \author Amlal El Mahrouss +typedef struct Object final { + HCore::Char ObjectName[255]; + HCore::Int32 ObjectType; + HCore::Char ObjectNamespace[255]; + + HCore::Void(*Release)(struct Object* Self); + HCore::IntPtr(*Invoke)(struct Object* Self, HCore::Int32 Sel, ...); + HCore::Void(*Query)(struct Object* Self, HCore::VoidPtr* Dst, HCore::SizeT SzDst, HCore::XRN::GUIDSequence GuidOf); +} Object, *ObjectPtr; + +#define object_cast reinterpret_cast diff --git a/Private/Source/ProcessTeam.cxx b/Private/Source/ProcessTeam.cxx index 569d417d..9e16c0cd 100644 --- a/Private/Source/ProcessTeam.cxx +++ b/Private/Source/ProcessTeam.cxx @@ -9,7 +9,7 @@ /// @brief Process Team API. /***********************************************************************************/ -#include +#include namespace HCore { MutableArray>& ProcessTeam::AsArray() { return mProcessList; } diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx index 8fd61d5e..30a241ea 100644 --- a/Private/Source/ThreadLocalStorage.cxx +++ b/Private/Source/ThreadLocalStorage.cxx @@ -25,26 +25,27 @@ using namespace HCore; * @return if the cookie is enabled. */ -Boolean tls_check_tib(VoidPtr ptr) { - if (!ptr) return false; +Boolean tls_check_tib(ThreadInformationBlock* tib) { + if (!tib) return false; - const char* _ptr = (const char*)ptr; + HCore::Encoder encoder; + const char* tibAsBytes = encoder.AsBytes(tib); kcout << "HCoreKrnl\\TLS: Checking for a valid cookie...\n"; - return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 && - _ptr[2] == kCookieMag2; + return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && + tibAsBytes[2] == kCookieMag2; } /** - * System call implementation in HCore + * System call implementation of the TLS check. * @param ptr * @return */ EXTERN_C Void tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcept { ThreadInformationBlock* tib = (ThreadInformationBlock*)stackPtr->Gs; - if (!tls_check_tib(tib->Cookie)) { + if (!tls_check_tib(tib)) { kcout << "HCoreKrnl\\TLS: Verification failed, Crashing...\n"; ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); } -- cgit v1.2.3