diff options
| -rw-r--r-- | dev/crt/crt.json | 2 | ||||
| -rw-r--r-- | dev/crt/defines.hxx | 22 | ||||
| -rw-r--r-- | dev/crt/exit.hxx | 4 | ||||
| -rw-r--r-- | dev/crt/src/alloca.cxx | 9 | ||||
| -rw-r--r-- | dev/crt/src/base_exception.cxx (renamed from dev/crt/src/crt_lib.cxx) | 4 | ||||
| -rw-r--r-- | dev/crt/src/new+delete.cxx | 52 | ||||
| -rw-r--r-- | dev/sci/makefile | 2 | ||||
| -rw-r--r-- | dev/sci/sci.json | 2 | ||||
| -rw-r--r-- | dev/sci/src/sci_mm.cxx | 7 | ||||
| -rw-r--r-- | dev/zba/amd64-efi.make | 8 | ||||
| -rw-r--r-- | dev/zba/arm64-efi.make | 8 | ||||
| -rw-r--r-- | dev/zba/src/Thread.cxx | 39 | ||||
| -rw-r--r-- | dev/zka/HALKit/AMD64/CPUID.hxx | 4 | ||||
| -rw-r--r-- | dev/zka/HALKit/AMD64/HalBoot.asm | 10 | ||||
| -rw-r--r-- | dev/zka/HALKit/AMD64/Paging.hxx | 2 | ||||
| -rw-r--r-- | dev/zka/HALKit/ARM64/Paging.hxx | 2 | ||||
| -rw-r--r-- | dev/zka/KernelKit/UserProcessScheduler.hxx | 2 | ||||
| -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 |
24 files changed, 304 insertions, 212 deletions
diff --git a/dev/crt/crt.json b/dev/crt/crt.json index 07368550..fbd54bf8 100644 --- a/dev/crt/crt.json +++ b/dev/crt/crt.json @@ -3,7 +3,7 @@ "compiler_std": "c++20", "headers_path": ["../", "./"], "sources_path": ["src/*.cxx"], - "output_name": "zka-crt-cxx.dll", + "output_name": "crt.dll", "compiler_flags": [ "-ffreestanding", "-shared", diff --git a/dev/crt/defines.hxx b/dev/crt/defines.hxx index d9670ac1..5636c337 100644 --- a/dev/crt/defines.hxx +++ b/dev/crt/defines.hxx @@ -10,21 +10,11 @@ #include <stdint.h> #include <stddef.h> -#ifndef __GNUC__ - -typedef __SIZE_TYPE__ size_t; - -#ifdef __LP64__ -typedef long int ssize_t; -#else -typedef int ssize_t; -#endif // __LP64__ +#ifdef __GNUC__ typedef void* ptr_type; typedef __SIZE_TYPE__ size_type; -typedef size_t ptrdiff_t; -typedef size_t uintptr_t; typedef void* voidptr_t; typedef void* any_t; typedef char* caddr_t; @@ -53,16 +43,6 @@ typedef char* caddr_t; #define __fini_decl() #endif -#if __has_builtin(__builtin_alloca) -#define alloca(sz) __builtin_alloca(sz) -#ifdef __alloca -#undef __alloca -#endif -#define __alloca alloca -#else -#warning ! alloca not detected ! -#endif - typedef long long off_t; typedef unsigned long long uoff_t; diff --git a/dev/crt/exit.hxx b/dev/crt/exit.hxx index a699cacd..7f64ebd5 100644 --- a/dev/crt/exit.hxx +++ b/dev/crt/exit.hxx @@ -13,6 +13,6 @@ namespace std { inline int exit(int code) { - exit(code); + return exit(code); } -} // namespace std
\ No newline at end of file +} // namespace std diff --git a/dev/crt/src/alloca.cxx b/dev/crt/src/alloca.cxx new file mode 100644 index 00000000..d2f684b3 --- /dev/null +++ b/dev/crt/src/alloca.cxx @@ -0,0 +1,9 @@ +/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <crt/alloca.hxx>
+
+/// @note Just here for building.
diff --git a/dev/crt/src/crt_lib.cxx b/dev/crt/src/base_exception.cxx index 530e40db..a8a43ac7 100644 --- a/dev/crt/src/crt_lib.cxx +++ b/dev/crt/src/base_exception.cxx @@ -4,10 +4,6 @@ ------------------------------------------- */
-#include <crt/alloca.hxx>
-#include <crt/defines.hxx>
#include <crt/base_exception.hxx>
-#include <crt/math.hxx>
-#include <crt/base_alloc.hxx>
/// @note Just here for building.
diff --git a/dev/crt/src/new+delete.cxx b/dev/crt/src/new+delete.cxx new file mode 100644 index 00000000..1241bf66 --- /dev/null +++ b/dev/crt/src/new+delete.cxx @@ -0,0 +1,52 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include <crt/base_alloc.hxx> + +#define kAllocSyscallId "mov $10, %%r9\n\t" +#define kFreeSyscallId "mov $11, %%r9\n\t" + +void* operator new(size_t length) +{ + void* ptr = nullptr; + + // do syscall according to PEF convention. + asm ("mov %0, %%r8\n\t" + kAllocSyscallId + "syscall" + : "=r" (ptr)); + + return ptr; +} + +void* operator new[](size_t length) +{ + ptr_type ptr = nullptr; + + // do syscall according to PEF convention. + asm ("mov %0, %%r8\n\t" + kAllocSyscallId + "syscall" + : "=r" (ptr)); + + return ptr; +} + +void operator delete(void* ptr) noexcept +{ + asm ("mov %0, %%r8\n\t" + kFreeSyscallId + "syscall" + : "=r" (ptr)); +} + +void operator delete[](void* ptr) noexcept +{ + asm ("mov %0, %%r8\n\t" + kFreeSyscallId + "syscall" + : "=r" (ptr)); +} diff --git a/dev/sci/makefile b/dev/sci/makefile index c66d7a78..05593216 100644 --- a/dev/sci/makefile +++ b/dev/sci/makefile @@ -5,7 +5,7 @@ CC=g++
FLAGS=-I../ -shared -fPIC -D__ZKA_SYMS__
-OUTPUT=zka-sci-cxx.dll
+OUTPUT=sci.dll
.PHONY: build-sci
build-sci:
diff --git a/dev/sci/sci.json b/dev/sci/sci.json index 0bc6cdcf..e67671ce 100644 --- a/dev/sci/sci.json +++ b/dev/sci/sci.json @@ -3,7 +3,7 @@ "compiler_std": "c++20", "headers_path": ["../"], "sources_path": ["src/*.cxx"], - "output_name": "zka-sci-cxx.dll", + "output_name": "sci.dll", "compiler_flags": [ "-fPIC", "-ffreestanding", diff --git a/dev/sci/src/sci_mm.cxx b/dev/sci/src/sci_mm.cxx index 34bf4936..d7665ddd 100644 --- a/dev/sci/src/sci_mm.cxx +++ b/dev/sci/src/sci_mm.cxx @@ -9,11 +9,6 @@ /// @file sci_base.cxx
/// @brief Base Memory Manager functions for SCI.dll
-/// @brief Debug error prompt, when a function misbehaves.
-/// @param msg
-/// @return
-IMPORT_C Void __RtlRaiseSoftError(const char* msg);
-
/// @brief Copy memory region.
IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len)
{
@@ -21,7 +16,6 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si !dest ||
!src)
{
- __RtlRaiseSoftError("Debug Error, MmCopyMemory contains one or more invalid arguments.");
return nullptr;
}
@@ -39,7 +33,6 @@ IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt if (!len ||
!dest)
{
- __RtlRaiseSoftError("Debug Error, MmFillMemory contains one or more invalid arguments.");
return nullptr;
}
diff --git a/dev/zba/amd64-efi.make b/dev/zba/amd64-efi.make index efe528e7..f2121f85 100644 --- a/dev/zba/amd64-efi.make +++ b/dev/zba/amd64-efi.make @@ -54,8 +54,8 @@ FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__NEWOSKRNL__ -D__NEWOSL BOOT_LOADER=newosldr.exe KERNEL=minoskrnl.exe DDK=ddk.dll -SCI=zka-sci-cxx.dll -CRT=zka-crt-cxx.dll +SCI=sci.dll +CRT=crt.dll SYS_CHK=syschk.sys STARTUP=startup.sys @@ -72,8 +72,8 @@ all: compile-amd64 $(COPY) ../zka/$(KERNEL) src/Root/$(KERNEL) $(COPY) ../sci/$(SCI) src/Root/$(SCI) $(COPY) ../ddk/$(DDK) src/Root/$(DDK) - $(COPY) ./modules/SysChk/$(SYS_CHK) src/Root/$(SYS_CHK) - $(COPY) ./modules/SysChk/$(SYS_CHK) src/Root/zka/$(STARTUP) + $(COPY) ./Modules/SysChk/$(SYS_CHK) src/Root/$(SYS_CHK) + $(COPY) ./Modules/SysChk/$(SYS_CHK) src/Root/zka/$(STARTUP) $(COPY) ../crt/$(CRT) src/Root/$(CRT) $(COPY) src/$(BOOT_LOADER) src/Root/$(BOOT_LOADER) diff --git a/dev/zba/arm64-efi.make b/dev/zba/arm64-efi.make index aae20a2b..9ea31d83 100644 --- a/dev/zba/arm64-efi.make +++ b/dev/zba/arm64-efi.make @@ -50,8 +50,8 @@ FLAG_GNU=-fshort-wchar -c -ffreestanding -MMD -mno-red-zone -D__ZKA_ARM64__ -fno BOOT_LOADER=newosldr.exe KERNEL=minoskrnl.exe DDK=ddk.dll -SCI=zka-sci-cxx.dll -CRT=zka-crt-cxx.dll +SCI=sci.dll +CRT=crt.dll SYS_CHK=syschk.sys STARTUP=startup.sys @@ -68,8 +68,8 @@ all: compile-amd64 $(COPY) ../zka/$(KERNEL) src/Root/$(KERNEL) $(COPY) ../sci/$(SCI) src/Root/$(SCI) $(COPY) ../ddk/$(DDK) src/Root/$(DDK) - $(COPY) ./modules/SysChk/$(SYS_CHK) src/Root/$(SYS_CHK) - $(COPY) ./modules/SysChk/$(SYS_CHK) src/Root/zka/$(STARTUP) + $(COPY) ./Modules/SysChk/$(SYS_CHK) src/Root/$(SYS_CHK) + $(COPY) ./Modules/SysChk/$(SYS_CHK) src/Root/zka/$(STARTUP) $(COPY) ../crt/$(CRT) src/Root/$(CRT) $(COPY) src/$(BOOT_LOADER) src/Root/$(BOOT_LOADER) diff --git a/dev/zba/src/Thread.cxx b/dev/zba/src/Thread.cxx index 2383d675..2c1ee173 100644 --- a/dev/zba/src/Thread.cxx +++ b/dev/zba/src/Thread.cxx @@ -90,7 +90,7 @@ namespace Boot if (StrCmp(sectionForCode, sect->mName) == 0) { fStartAddress = (VoidPtr)((UIntPtr)loadStartAddress + optHdr->mAddressOfEntryPoint); - writer.Write("NEWOSLDR: Entrypoint of DLL: ").Write((UIntPtr)fStartAddress).Write("\r"); + writer.Write("NEWOSLDR: ENTRY OF EXE: ").Write((UIntPtr)fStartAddress).Write("\r"); } else if (StrCmp(sectionForNewLdr, sect->mName) == 0) { @@ -98,17 +98,42 @@ namespace Boot { UInt64 HandoverMagic; UInt32 HandoverType; - }* structHandover = (struct HANDOVER_INFORMATION_STUB*)((UIntPtr)fBlob + sect->mPointerToRawData); + UInt32 HandoverPad; + UInt32 HandoverArch; + }* handover_struc = (struct HANDOVER_INFORMATION_STUB*)((UIntPtr)fBlob + sect->mPointerToRawData); - if (structHandover->HandoverMagic != kHandoverMagic && - structHandover->HandoverType != HEL::kTypeKernel) + if (handover_struc->HandoverMagic != kHandoverMagic && + handover_struc->HandoverType != HEL::kTypeKernel) { - writer.Write("NEWOSLDR: Entrypoint of EXE: ").Write((UIntPtr)fStartAddress).Write("\r"); +#ifdef __ZKA_AMD64__ + if (handover_struc->HandoverArch != HEL::kArchAMD64) + { + writer.Write("NEWOSLDR: ARCH OF EXE: ").Write(handover_struc->HandoverArch).Write("\r"); + writer.Write("NEWOSLDR: ENTRY OF EXE: ").Write((UIntPtr)fStartAddress).Write("\r"); + CGDrawString("NEWOSLDR: NOT AN HANDOVER IMAGE, BAD ARCHITECTURE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + + ::EFI::Stop(); + } +#endif + +#ifdef __ZKA_ARM64__ + if (handover_struc->HandoverArch != HEL::kArchARM64) + { + writer.Write("NEWOSLDR: ARCH OF EXE: ").Write(handover_struc->HandoverArch).Write("\r"); + writer.Write("NEWOSLDR: ENTRY OF EXE: ").Write((UIntPtr)fStartAddress).Write("\r"); + CGDrawString("NEWOSLDR: NOT AN HANDOVER IMAGE, BAD ARCHITECTURE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + + ::EFI::Stop(); + } +#endif + writer.Write("NEWOSLDR: ENTRY OF EXE: ").Write((UIntPtr)fStartAddress).Write("\r"); CGDrawString("NEWOSLDR: NOT AN HANDOVER IMAGE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + + ::EFI::Stop(); } } - writer.Write("NEWOSLDR: offset ").Write(sect->mPointerToRawData).Write(" of ").Write(sect->mName).Write("\r"); + writer.Write("NEWOSLDR: OFFSET ").Write(sect->mPointerToRawData).Write(" of ").Write(sect->mName).Write("\r"); CopyMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), (VoidPtr)((UIntPtr)fBlob + sect->mPointerToRawData), sect->mSizeOfRawData); } @@ -139,7 +164,7 @@ namespace Boot if (!handover) { - writer.Write("NEWOSLDR: Exec format error.\r"); + writer.Write("NEWOSLDR: EXEC FORMAT ERROR.\r"); return; } diff --git a/dev/zka/HALKit/AMD64/CPUID.hxx b/dev/zka/HALKit/AMD64/CPUID.hxx index 81d3b86d..ea524b1f 100644 --- a/dev/zka/HALKit/AMD64/CPUID.hxx +++ b/dev/zka/HALKit/AMD64/CPUID.hxx @@ -13,6 +13,8 @@ #pragma once +#include <NewKit/Defines.hxx> + enum { eCPUFeatureSSE3 = 1 << 0, @@ -78,4 +80,4 @@ enum eCPUFeaturePBE = 1 << 31 }; -typedef __INT64_TYPE__ hal_cpu_feature_type; +typedef Kernel::Int64 hal_cpu_feature_type; diff --git a/dev/zka/HALKit/AMD64/HalBoot.asm b/dev/zka/HALKit/AMD64/HalBoot.asm index 21f99a49..8044ed40 100644 --- a/dev/zka/HALKit/AMD64/HalBoot.asm +++ b/dev/zka/HALKit/AMD64/HalBoot.asm @@ -18,5 +18,11 @@ section .ldr -HandoverMagic: dq kHandoverMagic -HandoverType: dw kTypeKernel +HandoverMagic: + dq kHandoverMagic +HandoverType: + dw kTypeKernel +HandoverPad: + dw 0 +HandoverArch: + dw kArchAmd64 diff --git a/dev/zka/HALKit/AMD64/Paging.hxx b/dev/zka/HALKit/AMD64/Paging.hxx index 2b78e89d..43af9842 100644 --- a/dev/zka/HALKit/AMD64/Paging.hxx +++ b/dev/zka/HALKit/AMD64/Paging.hxx @@ -88,7 +88,7 @@ namespace Kernel::HAL ZKA_PTE* ALIGN(kPageAlign) fEntries[kPageMax]; }; - auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size) -> VoidPtr; + auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page) -> VoidPtr; auto mm_free_bitmap(VoidPtr page_ptr) -> Bool; } // namespace Kernel::HAL diff --git a/dev/zka/HALKit/ARM64/Paging.hxx b/dev/zka/HALKit/ARM64/Paging.hxx index b6e8708f..3d963d2b 100644 --- a/dev/zka/HALKit/ARM64/Paging.hxx +++ b/dev/zka/HALKit/ARM64/Paging.hxx @@ -107,7 +107,7 @@ namespace Kernel::HAL PTE_4KB ALIGN(kPageAlign) fEntries[kPageMax]; }; - auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size) -> VoidPtr; + auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page) -> VoidPtr; auto mm_free_bitmap(VoidPtr page_ptr) -> Bool; } // namespace Kernel::HAL diff --git a/dev/zka/KernelKit/UserProcessScheduler.hxx b/dev/zka/KernelKit/UserProcessScheduler.hxx index 07ae55c9..6bab5856 100644 --- a/dev/zka/KernelKit/UserProcessScheduler.hxx +++ b/dev/zka/KernelKit/UserProcessScheduler.hxx @@ -174,7 +174,7 @@ namespace Kernel PROCESS_MEMORY_ENTRY* MemoryEntryList{nullptr}; - SizeT MemoryPD{0}; + UIntPtr MemoryPD{0UL}; enum { 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; |
