diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-13 15:29:55 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-13 15:29:55 +0200 |
| commit | 7477a0f942c374b652da4f80cdb36d4661aac3c8 (patch) | |
| tree | d06627de4689b5661f4b95c4fa15f932b004ad13 /dev/zka/src | |
| parent | 182f2baa4d38a286d3453cc0da90ebec5fb25266 (diff) | |
IMP: Delete the memory list when exiting process.
IMP: Add Allocation (and delete) of MemoryList.
IMP: BitMap allocator must now allocate directories as well.
IMP: Add Handover arch to check if executable is an AMD64 executable or
ARM64 executable.
FIX: Add ::EFI::Stop, when a thread doesn't load correctly.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/zka/src')
| -rw-r--r-- | dev/zka/src/BitMapMgr.cxx | 19 | ||||
| -rw-r--r-- | dev/zka/src/DriveMgr.cxx | 4 | ||||
| -rw-r--r-- | dev/zka/src/FS/NeFS.cxx | 2 | ||||
| -rw-r--r-- | dev/zka/src/FileMgr.cxx | 138 | ||||
| -rw-r--r-- | dev/zka/src/NeFS+FileMgr.cxx | 138 | ||||
| -rw-r--r-- | dev/zka/src/PageMgr.cxx | 2 | ||||
| -rw-r--r-- | dev/zka/src/UserProcessScheduler.cxx | 34 |
7 files changed, 183 insertions, 154 deletions
diff --git a/dev/zka/src/BitMapMgr.cxx b/dev/zka/src/BitMapMgr.cxx index e577bd7e..8e8a2208 100644 --- a/dev/zka/src/BitMapMgr.cxx +++ b/dev/zka/src/BitMapMgr.cxx @@ -6,7 +6,7 @@ #include <ArchKit/ArchKit.hxx> -#define cBitMpMagic ((Kernel::UIntPtr)0x10210) +#define kBitMapMagic (0x10210) #ifdef __ZKA_AMD64__ #include <HALKit/AMD64/Paging.hxx> @@ -44,7 +44,7 @@ namespace Kernel UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(page_ptr); if (!ptr_bit_set[cBitMapMagIdx] || - ptr_bit_set[cBitMapMagIdx] != cBitMpMagic) + ptr_bit_set[cBitMapMagIdx] != kBitMapMagic) return No; return Yes; @@ -57,7 +57,7 @@ namespace Kernel UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(page_ptr); - ptr_bit_set[cBitMapMagIdx] = cBitMpMagic; + ptr_bit_set[cBitMapMagIdx] = kBitMapMagic; ptr_bit_set[cBitMapUsedIdx] = No; this->GetBitMapStatus(ptr_bit_set); @@ -93,7 +93,7 @@ namespace Kernel { UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base); - if (ptr_bit_set[cBitMapMagIdx] == cBitMpMagic && + if (ptr_bit_set[cBitMapMagIdx] == kBitMapMagic && ptr_bit_set[cBitMapSizeIdx] <= size) { if (ptr_bit_set[cBitMapUsedIdx] == No) @@ -109,11 +109,11 @@ namespace Kernel return (VoidPtr)ptr_bit_set; } } - else if (ptr_bit_set[cBitMapMagIdx] != cBitMpMagic) + else if (ptr_bit_set[cBitMapMagIdx] != kBitMapMagic) { UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base_ptr); - ptr_bit_set[cBitMapMagIdx] = cBitMpMagic; + ptr_bit_set[cBitMapMagIdx] = kBitMapMagic; ptr_bit_set[cBitMapSizeIdx] = size; ptr_bit_set[cBitMapUsedIdx] = Yes; @@ -125,7 +125,7 @@ namespace Kernel return (VoidPtr)ptr_bit_set; } - base = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base_ptr) + (ptr_bit_set[0] != cBitMpMagic ? size : ptr_bit_set[1])); + base = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base_ptr) + (ptr_bit_set[0] != kBitMapMagic ? size : ptr_bit_set[1])); if ((UIntPtr)base_ptr < (reinterpret_cast<UIntPtr>(base) + kHandoverHeader->f_BitMapSize)) return nullptr; @@ -158,8 +158,8 @@ namespace Kernel /// @brief Allocate a new page to be used by the OS. /// @param wr read/write bit. /// @param user user bit. - /// @return - auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size) -> VoidPtr + /// @return a new bitmap allocated pointer. + auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page) -> VoidPtr { VoidPtr ptr_new = nullptr; Detail::IBitMapAllocator traits; @@ -183,6 +183,7 @@ namespace Kernel return (UIntPtr*)ptr_new; } + /// @brief Free Bitmap, and mark it a absent in page terms. auto mm_free_bitmap(VoidPtr page_ptr) -> Bool { if (!page_ptr) diff --git a/dev/zka/src/DriveMgr.cxx b/dev/zka/src/DriveMgr.cxx index adb21693..77412d12 100644 --- a/dev/zka/src/DriveMgr.cxx +++ b/dev/zka/src/DriveMgr.cxx @@ -115,7 +115,7 @@ namespace Kernel /// @return the new drive. DriveTrait io_construct_drive() noexcept { - DriveTrait trait{}; + DriveTrait trait; rt_copy_memory((VoidPtr) "\\Mount\\NUL:", trait.fName, rt_string_len("\\Mount\\NUL:")); trait.fKind = kInvalidDrive; @@ -133,7 +133,7 @@ namespace Kernel /// @return the new drive. DriveTrait io_construct_main_drive() noexcept { - DriveTrait trait{}; + DriveTrait trait; rt_copy_memory((VoidPtr) "\\Mount\\MainDisk:", trait.fName, rt_string_len("\\Mount\\MainDisk:")); trait.fKind = kMassStorage; diff --git a/dev/zka/src/FS/NeFS.cxx b/dev/zka/src/FS/NeFS.cxx index 46c5d8b4..ee1e32c6 100644 --- a/dev/zka/src/FS/NeFS.cxx +++ b/dev/zka/src/FS/NeFS.cxx @@ -21,7 +21,7 @@ using namespace Kernel; -#ifdef __ED__ +#ifdef __ZKA_IN_EDITOR__ /***********************************************************************************/ /** Define those external symbols, to make the editor shutup diff --git a/dev/zka/src/FileMgr.cxx b/dev/zka/src/FileMgr.cxx index 66e07ae9..821d830d 100644 --- a/dev/zka/src/FileMgr.cxx +++ b/dev/zka/src/FileMgr.cxx @@ -49,142 +49,4 @@ namespace Kernel return false; } - -#ifdef __FSKIT_USE_NEFS__ - /// @brief Opens a new file. - /// @param path - /// @param r - /// @return - _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) - { - if (!path || *path == 0) - return nullptr; - - if (!r || *r == 0) - return nullptr; - - auto catalog = fImpl->GetCatalog(path); - - return node_cast(catalog); - } - - /// @brief Writes to a catalog's fork. - /// @param node the node ptr. - /// @param data the data. - /// @param flags the size. - /// @return - Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return; - if (!size) - return; - - constexpr auto cDataForkName = kNeFSDataFork; - this->Write(cDataForkName, node, data, flags, size); - } - - /// @brief Read from filesystem fork. - /// @param node the catalog node. - /// @param flags the flags with it. - /// @param sz the size to read. - /// @return - _Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return nullptr; - if (!size) - return nullptr; - - constexpr auto cDataForkName = kNeFSDataFork; - return this->Read(cDataForkName, node, flags, size); - } - - Void NeFileSystemMgr::Write(_Input const Char* name, - _Input NodePtr node, - _Input VoidPtr data, - _Input Int32 flags, - _Input SizeT size) - { - if (!size || - size > kNeFSForkSize) - return; - - if (!data) - return; - - ZKA_UNUSED(flags); - - if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) - fImpl->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & cFileFlagRsrc ? true : false), data, size, - name); - } - - _Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name, - _Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) - { - if (sz > kNeFSForkSize) - return nullptr; - - if (!sz) - return nullptr; - - ZKA_UNUSED(flags); - - if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) - return fImpl->ReadCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & cFileFlagRsrc ? true : false), sz, - name); - - return nullptr; - } - - /// @brief Seek from Catalog. - /// @param node - /// @param off - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) - { - if (!node || off == 0) - return false; - - return fImpl->Seek(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), off); - } - - /// @brief Tell where the catalog is. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output SizeT NeFileSystemMgr::Tell(NodePtr node) - { - if (!node) - return kNPos; - - return fImpl->Tell(reinterpret_cast<NFS_CATALOG_STRUCT*>(node)); - } - - /// @brief Rewinds the catalog. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NeFileSystemMgr::Rewind(NodePtr node) - { - if (!node) - return false; - - return this->Seek(node, 0); - } - - /// @brief Returns the filesystem parser. - /// @return the Filesystem parser class. - _Output NeFSParser* NeFileSystemMgr::GetParser() noexcept - { - return fImpl; - } -#endif // __FSKIT_USE_NEFS__ } // namespace Kernel diff --git a/dev/zka/src/NeFS+FileMgr.cxx b/dev/zka/src/NeFS+FileMgr.cxx index fa14aaae..cee80531 100644 --- a/dev/zka/src/NeFS+FileMgr.cxx +++ b/dev/zka/src/NeFS+FileMgr.cxx @@ -14,6 +14,7 @@ namespace Kernel { +#ifdef __FSKIT_USE_NEFS__ /// @brief C++ constructor NeFileSystemMgr::NeFileSystemMgr() { @@ -105,6 +106,143 @@ namespace Kernel { return kNeFSMetaFilePrefix; } + + /// @brief Opens a new file. + /// @param path + /// @param r + /// @return + _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) + { + if (!path || *path == 0) + return nullptr; + + if (!r || *r == 0) + return nullptr; + + auto catalog = fImpl->GetCatalog(path); + + return node_cast(catalog); + } + + /// @brief Writes to a catalog's fork. + /// @param node the node ptr. + /// @param data the data. + /// @param flags the size. + /// @return + Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) + { + if (!node) + return; + if (!size) + return; + + constexpr auto cDataForkName = kNeFSDataFork; + this->Write(cDataForkName, node, data, flags, size); + } + + /// @brief Read from filesystem fork. + /// @param node the catalog node. + /// @param flags the flags with it. + /// @param sz the size to read. + /// @return + _Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) + { + if (!node) + return nullptr; + if (!size) + return nullptr; + + constexpr auto cDataForkName = kNeFSDataFork; + return this->Read(cDataForkName, node, flags, size); + } + + Void NeFileSystemMgr::Write(_Input const Char* name, + _Input NodePtr node, + _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) + { + if (!size || + size > kNeFSForkSize) + return; + + if (!data) + return; + + ZKA_UNUSED(flags); + + if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) + fImpl->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & cFileFlagRsrc ? true : false), data, size, + name); + } + + _Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) + { + if (sz > kNeFSForkSize) + return nullptr; + + if (!sz) + return nullptr; + + ZKA_UNUSED(flags); + + if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) + return fImpl->ReadCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & cFileFlagRsrc ? true : false), sz, + name); + + return nullptr; + } + + /// @brief Seek from Catalog. + /// @param node + /// @param off + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) + { + if (!node || off == 0) + return false; + + return fImpl->Seek(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), off); + } + + /// @brief Tell where the catalog is. + /// @param node + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output SizeT NeFileSystemMgr::Tell(NodePtr node) + { + if (!node) + return kNPos; + + return fImpl->Tell(reinterpret_cast<NFS_CATALOG_STRUCT*>(node)); + } + + /// @brief Rewinds the catalog. + /// @param node + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output Bool NeFileSystemMgr::Rewind(NodePtr node) + { + if (!node) + return false; + + return this->Seek(node, 0); + } + + /// @brief Returns the filesystem parser. + /// @return the Filesystem parser class. + _Output NeFSParser* NeFileSystemMgr::GetParser() noexcept + { + return fImpl; + } +#endif // __FSKIT_USE_NEFS__ } // namespace Kernel #endif // ifdef __FSKIT_USE_NEFS__ diff --git a/dev/zka/src/PageMgr.cxx b/dev/zka/src/PageMgr.cxx index 5526da00..3a4a743c 100644 --- a/dev/zka/src/PageMgr.cxx +++ b/dev/zka/src/PageMgr.cxx @@ -58,7 +58,7 @@ namespace Kernel PTEWrapper PageMgr::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) { // Store PTE wrapper right after PTE. - VoidPtr ptr = Kernel::HAL::mm_alloc_bitmap(Rw, User, Sz); + VoidPtr ptr = Kernel::HAL::mm_alloc_bitmap(Rw, User, Sz, false); return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast<UIntPtr>(ptr)}; } diff --git a/dev/zka/src/UserProcessScheduler.cxx b/dev/zka/src/UserProcessScheduler.cxx index 00249896..0819e638 100644 --- a/dev/zka/src/UserProcessScheduler.cxx +++ b/dev/zka/src/UserProcessScheduler.cxx @@ -12,6 +12,7 @@ /// @brief User Process scheduler. /***********************************************************************************/ +#include <ArchKit/ArchKit.hxx> #include <KernelKit/UserProcessScheduler.hxx> #include <KernelKit/IPEFDLLObject.hxx> #include <KernelKit/HardwareThreadScheduler.hxx> @@ -169,8 +170,9 @@ namespace Kernel auto pd = hal_read_cr3(); hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD)); - Bool ret = mm_delete_heap(ptr); - hal_write_cr3(reinterpret_cast<VoidPtr>(pd)); + auto ret = mm_delete_heap(entry->MemoryEntry); + + hal_write_cr3(pd); return ret; #else @@ -233,6 +235,32 @@ namespace Kernel fLastExitCode = exit_code; cLastExitCode = exit_code; + auto memory_list = this->MemoryEntryList; + + // Deleting memory lists. Make sure to free all of them. + while (memory_list) + { + if (memory_list->MemoryEntry) + { + auto pd = hal_read_cr3(); + hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD)); + + MUST_PASS(mm_delete_heap(memory_list->MemoryEntry)); + + hal_write_cr3(pd); + } + + auto next = memory_list->MemoryNext; + + mm_delete_heap(memory_list); + memory_list = nullptr; + + memory_list = next; + } + + //! Free the memory's page directory. + HAL::mm_free_bitmap(reinterpret_cast<VoidPtr>(this->MemoryPD)); + //! Delete image if not done already. if (this->Image && mm_is_valid_heap(this->Image)) mm_delete_heap(this->Image); @@ -275,7 +303,7 @@ namespace Kernel return 0; #ifdef __ZKA_AMD64__ - process.MemoryPD = reinterpret_cast<UIntPtr>(hal_read_cr3()); + process.MemoryPD = reinterpret_cast<UIntPtr>(HAL::mm_alloc_bitmap(Yes, Yes, sizeof(PDE), Yes)); #endif // __ZKA_AMD64__ process.Status = ProcessStatusKind::kStarting; |
