diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-31 19:36:16 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-31 19:36:16 +0100 |
| commit | 8621867b0e4b38dedc8556e6c483e3575d776af0 (patch) | |
| tree | ae8e9d271db301dc3f9433b909cd80636a8196e5 /Private/KernelKit | |
| parent | 8f7904569a60721cfd051a359dd17cc86ea67cfe (diff) | |
Kernel: Many improvements done to the kernel and it's HAL and protocols.
Will implement BFileReader on next commit.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/KernelKit')
| -rw-r--r-- | Private/KernelKit/CodeManager.hpp | 76 | ||||
| -rw-r--r-- | Private/KernelKit/DriveManager.hpp | 5 | ||||
| -rw-r--r-- | Private/KernelKit/PE.hpp | 49 | ||||
| -rw-r--r-- | Private/KernelKit/PEF.hpp | 2 | ||||
| -rw-r--r-- | Private/KernelKit/PEFCodeManager.hxx | 72 | ||||
| -rw-r--r-- | Private/KernelKit/PEFSharedObject.hxx (renamed from Private/KernelKit/SharedObjectCore.hxx) | 16 |
6 files changed, 148 insertions, 72 deletions
diff --git a/Private/KernelKit/CodeManager.hpp b/Private/KernelKit/CodeManager.hpp index afb1a33e..fcb0d46b 100644 --- a/Private/KernelKit/CodeManager.hpp +++ b/Private/KernelKit/CodeManager.hpp @@ -1,72 +1,18 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ +/* ------------------------------------------- -#ifndef _INC_CODE_MANAGER_ -#define _INC_CODE_MANAGER_ + Copyright Mahrouss Logic -#include <KernelKit/PEF.hpp> -#include <NewKit/ErrorOr.hpp> -#include <NewKit/String.hpp> + File: CodeManager.hpp + Purpose: Code Manager and Shared Objects. -#include "NewKit/Defines.hpp" + Revision History: -namespace HCore { -/// -/// \name PEFLoader -/// \brief PEF loader class. -/// -class PEFLoader : public Loader { - private: - explicit PEFLoader() = delete; + 30/01/24: Added file (amlel) - public: - explicit PEFLoader(const VoidPtr blob); - explicit PEFLoader(const char *path); - ~PEFLoader() override; +------------------------------------------- */ - public: - HCORE_COPY_DEFAULT(PEFLoader); +#pragma once - public: - typedef void (*MainKind)(void); - - public: - const char *Path() override; - const char *Format() override; - const char *MIME() override; - - public: - ErrorOr<VoidPtr> LoadStart() override; - VoidPtr FindSymbol(const char *name, Int32 kind) override; - - public: - bool IsLoaded() noexcept; - - private: - Ref<StringView> fPath; - VoidPtr fCachedBlob; - bool fBad; -}; - -namespace Utils { -/// \brief Much like Mac OS's UPP. -/// This is read-only by design. -/// It handles different kind of code. -/// ARM <-> AMD64 for example. -typedef struct UniversalProcedureTable final { - const Char NAME[kPefNameLen]; - const VoidPtr TRAP; - const SizeT ARCH; -} __attribute__((packed)) UniversalProcedureTableType; - -bool execute_from_image(PEFLoader &exec) noexcept; -} // namespace Utils -} // namespace HCore - -#endif // ifndef _INC_CODE_MANAGER_ +#include <KernelKit/PEFCodeManager.hxx> +// #include <KernelKit/PECodeManager.hpp> +#include <KernelKit/PEFSharedObject.hxx> diff --git a/Private/KernelKit/DriveManager.hpp b/Private/KernelKit/DriveManager.hpp index 3c960d07..da478a45 100644 --- a/Private/KernelKit/DriveManager.hpp +++ b/Private/KernelKit/DriveManager.hpp @@ -7,7 +7,8 @@ * ======================================================== */ -#pragma once +#ifndef __DRIVE_MANAGER__ +#define __DRIVE_MANAGER__ #include <CompilerKit/CompilerKit.hpp> #include <KernelKit/Device.hpp> @@ -78,3 +79,5 @@ class DriveSelector final { DriveTraits *fDrive; }; } // namespace HCore + +#endif /* ifndef __DRIVE_MANAGER__ */ diff --git a/Private/KernelKit/PE.hpp b/Private/KernelKit/PE.hpp index 5bb5d831..5d8ac9f8 100644 --- a/Private/KernelKit/PE.hpp +++ b/Private/KernelKit/PE.hpp @@ -11,7 +11,7 @@ ------------------------------------------- */ -#ifdef __PE__ +#ifndef __PE__ #define __PE__ #include <NewKit/Defines.hpp> @@ -19,6 +19,7 @@ typedef HCore::UInt32 U32; typedef HCore::UInt16 U16; typedef HCore::UInt8 U8; +typedef char CHAR; #define kPeMagic 0x00004550 @@ -36,7 +37,7 @@ struct ExecHeader final { #define kMagPE32 0x010b #define kMagPE64 0x020b -struct ExecOptionalHeader final { +typedef struct ExecOptionalHeader final { U16 mMagic; // 0x010b - PE32, 0x020b - PE32+ (64 bit) U8 mMajorLinkerVersion; U8 mMinorLinkerVersion; @@ -67,6 +68,50 @@ struct ExecOptionalHeader final { U32 mSizeOfHeapCommit; U32 mLoaderFlags; U32 mNumberOfRvaAndSizes; +} ExecOptionalHeader, *ExecOptionalHeaderPtr; + +typedef struct ExecSectionHeader final { + CHAR mName[8]; + U32 mVirtualSize; + U32 mVirtualAddress; + U32 mSizeOfRawData; + U32 mPointerToRawData; + U32 mPointerToRelocations; + U32 mPointerToLinenumbers; + U16 mNumberOfRelocations; + U16 mNumberOfLinenumbers; + U32 mCharacteristics; +} ExecSectionHeader, *ExecSectionHeaderPtr; + +enum kExecDataDirParams { + kExecExport, + kExecImport, + kExecCnt, }; +typedef struct ExecExportDirectory { + U32 mCharacteristics; + U32 mTimeDateStamp; + U16 mMajorVersion; + U16 mMinorVersion; + U32 mName; + U32 mBase; + U32 mNumberOfFunctions; + U32 mNumberOfNames; + U32 mAddressOfFunctions; // export table rva + U32 mAddressOfNames; + U32 mAddressOfNameOrdinal; // ordinal table rva +} ExecExportDirectory, *ExecExportDirectoryPtr; + +typedef struct ExecImportDirectory { + union { + U32 mCharacteristics; + U32 mOriginalFirstThunk; + }; + U32 mTimeDateStamp; + U32 mForwarderChain; + U32 mNameRva; + U32 mThunkTableRva; +} ExecImportDirectory, *ExecImportDirectoryPtr; + #endif /* ifndef __PE__ */ diff --git a/Private/KernelKit/PEF.hpp b/Private/KernelKit/PEF.hpp index 3d15a3aa..afa43968 100644 --- a/Private/KernelKit/PEF.hpp +++ b/Private/KernelKit/PEF.hpp @@ -39,6 +39,8 @@ enum { kPefKindSharedObject = 2, /* .lib */ kPefKindObject = 4, /* .obj */ kPefKindDebug = 5, /* .debug */ + kPefKindDriver = 6, + kPefKindCount, }; typedef struct PEFContainer final { diff --git a/Private/KernelKit/PEFCodeManager.hxx b/Private/KernelKit/PEFCodeManager.hxx new file mode 100644 index 00000000..3541d11b --- /dev/null +++ b/Private/KernelKit/PEFCodeManager.hxx @@ -0,0 +1,72 @@ +/* + * ======================================================== + * + * HCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#ifndef _INC_CODE_MANAGER_PEF_ +#define _INC_CODE_MANAGER_PEF_ + +#include <KernelKit/PEF.hpp> +#include <NewKit/ErrorOr.hpp> +#include <NewKit/String.hpp> + +#include "NewKit/Defines.hpp" + +namespace HCore { +/// +/// \name PEFLoader +/// \brief PEF loader class. +/// +class PEFLoader : public Loader { + private: + explicit PEFLoader() = delete; + + public: + explicit PEFLoader(const VoidPtr blob); + explicit PEFLoader(const char *path); + ~PEFLoader() override; + + public: + HCORE_COPY_DEFAULT(PEFLoader); + + public: + typedef void (*MainKind)(void); + + public: + const char *Path() override; + const char *Format() override; + const char *MIME() override; + + public: + ErrorOr<VoidPtr> LoadStart() override; + VoidPtr FindSymbol(const char *name, Int32 kind) override; + + public: + bool IsLoaded() noexcept; + + private: + Ref<StringView> fPath; + VoidPtr fCachedBlob; + bool fBad; +}; + +namespace Utils { +/// \brief Much like Mac OS's UPP. +/// This is read-only by design. +/// It handles different kind of code. +/// ARM <-> AMD64 for example. +typedef struct UniversalProcedureTable final { + const Char NAME[kPefNameLen]; + const VoidPtr TRAP; + const SizeT ARCH; +} __attribute__((packed)) UniversalProcedureTableType; + +bool execute_from_image(PEFLoader &exec) noexcept; +} // namespace Utils +} // namespace HCore + +#endif // ifndef _INC_CODE_MANAGER_PEF_ diff --git a/Private/KernelKit/SharedObjectCore.hxx b/Private/KernelKit/PEFSharedObject.hxx index aea3c0cb..af90858e 100644 --- a/Private/KernelKit/SharedObjectCore.hxx +++ b/Private/KernelKit/PEFSharedObject.hxx @@ -7,15 +7,19 @@ * ======================================================== */ -#ifndef __KERNELKIT_SHARED_OBJECT_CORE_HXX__ -#define __KERNELKIT_SHARED_OBJECT_CORE_HXX__ +#ifndef __KERNELKIT_SHARED_OBJECT_HXX__ +#define __KERNELKIT_SHARED_OBJECT_HXX__ -#include <KernelKit/CodeManager.hpp> #include <KernelKit/Loader.hpp> #include <KernelKit/PEF.hpp> +#include <KernelKit/PEFCodeManager.hxx> #include <NewKit/Defines.hpp> namespace HCore { + /** + * @brief Shared Library class + * Load library from this class + */ class SharedObject final { public: struct SharedObjectTraits final { @@ -40,6 +44,10 @@ class SharedObject final { public: void Mount(SharedObjectTraits *to_mount) { + if (!to_mount || + !to_mount->fImageObject) + return; + fMounted = to_mount; if (fLoader && to_mount) { @@ -82,4 +90,4 @@ inline void hcore_pure_call(void) { } } // namespace HCore -#endif /* ifndef __KERNELKIT_SHARED_OBJECT_CORE_HXX__ */ +#endif /* ifndef __KERNELKIT_SHARED_OBJECT_HXX__ */ |
