diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-10 10:35:44 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-10 10:35:44 +0200 |
| commit | 192892221333113b28353fbe428adfc1bf6bbaae (patch) | |
| tree | 04f2da30b021880ea3c5ca1bac030fcd206c5c52 | |
| parent | 80039963ff08d1810e22a0ae41497b156e861db0 (diff) | |
[FIX] [newoskrnl.dll] Fixed it's heap and improved it as well.
[FIX] Fix memory leak in TrySave. (\Kernel\Sources\User.cxx)
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
| -rw-r--r-- | Boot/Sources/HEL/AMD64/BootMain.cxx | 10 | ||||
| -rw-r--r-- | Boot/Sources/KernelLoader.cxx | 2 | ||||
| -rw-r--r-- | Boot/amd64-efi.make | 5 | ||||
| -rw-r--r-- | GXKit/build.json | 10 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/HalKernelMain.cxx | 9 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/Processor.hxx | 5 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx | 17 | ||||
| -rw-r--r-- | Kernel/KernelKit/ProcessScheduler.hxx | 8 | ||||
| -rw-r--r-- | Kernel/Sources/DriveManager.cxx | 6 | ||||
| -rw-r--r-- | Kernel/Sources/FS/NewFS.cxx | 21 | ||||
| -rw-r--r-- | Kernel/Sources/HalPageAlloc.cxx | 28 | ||||
| -rw-r--r-- | Kernel/Sources/NewFS+FileManager.cxx | 2 | ||||
| -rw-r--r-- | Kernel/Sources/User.cxx | 15 |
13 files changed, 88 insertions, 50 deletions
diff --git a/Boot/Sources/HEL/AMD64/BootMain.cxx b/Boot/Sources/HEL/AMD64/BootMain.cxx index 0e2be7ac..53587e40 100644 --- a/Boot/Sources/HEL/AMD64/BootMain.cxx +++ b/Boot/Sources/HEL/AMD64/BootMain.cxx @@ -118,7 +118,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, vendorTable[4] == 'P' && vendorTable[5] == 'T' && vendorTable[6] == 'R' && vendorTable[7] == ' ') { - writer.Write(L"newosldr: Filling rsdptr...\r"); + writer.Write(L"newosldr: Filling RSD PTR...\r"); handoverHdrPtr->f_HardwareTables.f_VendorPtr = (VoidPtr)vendorTable; break; @@ -163,6 +163,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handoverHdrPtr->f_VirtualStart = (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart; + handoverHdrPtr->f_VirtualSize = Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */ @@ -195,6 +196,13 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), handoverHdrPtr->f_GOP.f_Height, handoverHdrPtr->f_GOP.f_Width, 0, 0); CGFini(); + BDiskFormatFactory<BootDeviceATA> checkPart; + + if (!checkPart.IsPartitionValid()) + { + writer.Write("newosldr: Warning, partition isn't valid! Need to repartition it.\r"); + } + // ---------------------------------------------------- // // The following checks for an exisiting partition // inside the disk, if it doesn't have one, diff --git a/Boot/Sources/KernelLoader.cxx b/Boot/Sources/KernelLoader.cxx index 02fa97e4..aaabddc3 100644 --- a/Boot/Sources/KernelLoader.cxx +++ b/Boot/Sources/KernelLoader.cxx @@ -93,7 +93,7 @@ namespace Boot UInt64 HandoverMagic; UInt32 HandoverType; - }* structHandover = (struct HANDOVER_INFORMATION_STUB*)(fBlob + sect->mPointerToRawData); + }* structHandover = (struct HANDOVER_INFORMATION_STUB*)((UIntPtr)fBlob + sect->mPointerToRawData); if (structHandover->HandoverMagic != kHandoverMagic || structHandover->HandoverType != kHOTypeKernel) diff --git a/Boot/amd64-efi.make b/Boot/amd64-efi.make index c5f51112..4cf707bd 100644 --- a/Boot/amd64-efi.make +++ b/Boot/amd64-efi.make @@ -29,12 +29,11 @@ IMG=epm-master-1.img IMG_2=epm-slave.img IMG_3=epm-master-2.img -EMU_FLAGS=-net none -smp 2 -m 6G -M q35 \ +EMU_FLAGS=-net none -smp 2 -m 8G -M q35 \ -bios $(BIOS) -device piix3-ide,id=ide \ -drive id=disk,file=$(IMG),format=raw,if=none \ -device ide-hd,drive=disk,bus=ide.0 -drive \ - file=fat:rw:Sources/Root/,index=2,format=raw -d int -hdd $(IMG_2) \ - -drive file=$(IMG_3),if=none,id=nvm -device nvme,serial=Zeta,drive=nvm + file=fat:rw:Sources/Root/,index=2,format=raw -d int -hdd $(IMG_2) LD_FLAGS=-e Main --subsystem=10 diff --git a/GXKit/build.json b/GXKit/build.json new file mode 100644 index 00000000..284fb1b9 --- /dev/null +++ b/GXKit/build.json @@ -0,0 +1,10 @@ +{
+ "compiler_path": "x86_64-w64-mingw32-gcc",
+ "compiler_std": "c++20",
+ "headers_path": ["../", "./"],
+ "sources_path": ["*.c", "*.cxx", "*.S"],
+ "output_name": "gx.dll",
+ "compiler_flags": ["-ffreestanding", "-shared", "-std=c17", "-std=c++20", "-fno-rtti", "-fno-exceptions", " -Wl,--subsystem=17"],
+ "cpp_macros": ["__NEWOSKRNL__", "__DDK_AMD64__", "cGXVersionHighest=1", "cGXVersionLowest=1"]
+ }
+
\ No newline at end of file diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index d24099f2..495cb0be 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -89,7 +89,7 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( - reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_VirtualStart) + cHeapStartOffset); + reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_VirtualStart)); // get physical address start. kKernelPhysicalStart = reinterpret_cast<Kernel::VoidPtr>( @@ -210,6 +210,12 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept kSyscalls[cShutdownInterrupt].Leak().Leak()->fHooked = true; kSyscalls[cRebootInterrupt].Leak().Leak()->fHooked = true; + Kernel::kcout << "newoskrnl: Creating Filesystem and Super User...\r"; + + auto fs = new Kernel::NewFilesystemManager(); + + Kernel::NewFilesystemManager::Mount(fs); + cRoot = new Kernel::User(Kernel::RingKind::kRingSuperUser, kSuperUser); #ifdef __DEBUG__ @@ -218,6 +224,7 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept const auto cPassword = "password"; #endif + cRoot->TrySave(cPassword); Kernel::UserManager::The()->TryLogIn(cRoot, cPassword); diff --git a/Kernel/HALKit/AMD64/Processor.hxx b/Kernel/HALKit/AMD64/Processor.hxx index 53addd46..432d799d 100644 --- a/Kernel/HALKit/AMD64/Processor.hxx +++ b/Kernel/HALKit/AMD64/Processor.hxx @@ -40,7 +40,7 @@ EXTERN_C #define kTaskGate (0b10001100) #define kGdtCodeSelector (0x08) #define kGdtUserCodeSelector (0x10) -#define cHeapStartOffset (0x4000000) +#define cHeapStartOffset (0x80000000) namespace Kernel { @@ -340,7 +340,8 @@ EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr); #define kKernelIdtSize 0x100 #define kKernelInterruptId 0x32 -inline Kernel::VoidPtr kKernelVirtualStart = (Kernel::VoidPtr)cHeapStartOffset; +inline Kernel::VoidPtr kKernelVMTStart = (Kernel::VoidPtr)cHeapStartOffset; +inline Kernel::VoidPtr kKernelVirtualStart = nullptr; inline Kernel::UIntPtr kKernelVirtualSize = 0UL; inline Kernel::VoidPtr kKernelPhysicalStart = nullptr; diff --git a/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx b/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx index fe47ce76..9d141aba 100644 --- a/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -64,27 +64,32 @@ Void drv_std_select(UInt16 Bus) Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { - if (drv_std_detected()) - return true; - UInt16 IO = Bus; drv_std_select(IO); + + Kernel::kcout << "newoskrnl: Initializing drive...\r"; +ATAInit_Retry: // Bus init, NEIN bit. Out8(IO + ATA_REG_NEIN, 1); - // identify until it's good. -ATAInit_Retry: + // identify until it's good + auto statRdy = In8(IO + ATA_REG_STATUS); if (statRdy & ATA_SR_ERR) { + Kernel::kcout << "newoskrnl: Failing drive...\r"; + return false; } if ((statRdy & ATA_SR_BSY)) + { + kcout << "Retrying..."; goto ATAInit_Retry; + } Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); @@ -102,6 +107,8 @@ ATAInit_Retry: OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; + Kernel::kcout << "newoskrnl: Create ATA module.\r"; + return true; } diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index cd0a7a93..c47c562d 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -150,15 +150,13 @@ namespace Kernel AffinityKind Affinity{AffinityKind::kStandard}; ProcessStatus Status{ProcessStatus::kDead}; - // Memory, images. + // Memory, images pointers. HeapPtrKind HeapCursor{nullptr}; ImagePtr Image{nullptr}; HeapPtrKind HeapPtr{nullptr}; - typedef PEFSharedObjectInterface ProcessDLLInterface; - - // shared library handle, reserved for kSharedLib only. - ProcessDLLInterface* DLLPtr{nullptr}; + // shared library handle, reserved for kSharedObjectKind types of executables only. + PEFSharedObjectInterface* DLLPtr{nullptr}; // Memory usage. SizeT UsedMemory{0}; diff --git a/Kernel/Sources/DriveManager.cxx b/Kernel/Sources/DriveManager.cxx index 80df09bf..fae54314 100644 --- a/Kernel/Sources/DriveManager.cxx +++ b/Kernel/Sources/DriveManager.cxx @@ -136,14 +136,16 @@ namespace Kernel { DriveTrait trait; - rt_copy_memory((VoidPtr) "/Mount/MainDisk/", trait.fName, rt_string_len("/Mount/MainDisk/")); - trait.fKind = kMassStorage | kEPMDrive; + rt_copy_memory((VoidPtr) "MainDisk", trait.fName, rt_string_len("MainDisk")); + trait.fKind = kMassStorage; trait.fInput = ke_drv_input; trait.fOutput = ke_drv_output; trait.fVerify = ke_drv_check_disk; trait.fDriveKind = io_drive_kind; + kcout << "newoskrnl: Construct drive with success.\r"; + return trait; } } // namespace Kernel diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx index 23d2867f..83c39e4b 100644 --- a/Kernel/Sources/FS/NewFS.cxx +++ b/Kernel/Sources/FS/NewFS.cxx @@ -1029,26 +1029,11 @@ namespace Kernel::Detail sMountpointInterface.C() = io_construct_drive(); sMountpointInterface.D() = io_construct_drive(); - sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); - - Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0}; - - sMountpointInterface.A().fPacket.fLba = kNewFSStartLba; - sMountpointInterface.A().fPacket.fPacketContent = partitionBlockBuf; - sMountpointInterface.A().fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); - - sMountpointInterface.A().fInput(&sMountpointInterface.A().fPacket); - - NFS_ROOT_PARTITION_BLOCK* partBlock = - reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf); + kcout << "newoskrnl: Testing drive...\r"; - if (!StringBuilder::Equals(partBlock->Ident, kNewFSIdent)) - { - kcout << "newoskrnl: New FS Partition is corrupt.\r"; - return false; - } + sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); - kcout << "newoskrnl: Read partition: " << partBlock->PartitionName << ", with success!\r"; + kcout << "newoskrnl: Testing drive [ OK ]...\r"; return true; } diff --git a/Kernel/Sources/HalPageAlloc.cxx b/Kernel/Sources/HalPageAlloc.cxx index f22db98a..d1fe83a7 100644 --- a/Kernel/Sources/HalPageAlloc.cxx +++ b/Kernel/Sources/HalPageAlloc.cxx @@ -19,11 +19,13 @@ Kernel::Boolean kAllocationInProgress = false; namespace Kernel { + constexpr auto cVMTMagic = 0xDEEFD00D; + namespace HAL { namespace Detail { - struct VirtualMemoryHeader + struct VIRTUAL_MEMORY_HEADER { UInt32 Magic; Boolean Present; @@ -32,22 +34,28 @@ namespace Kernel SizeT Size; }; - struct VirtualMemoryHeaderTraits + struct VirtualMemoryHeaderTraits final { /// @brief Get next header. /// @param current /// @return - VirtualMemoryHeader* Next(VirtualMemoryHeader* current) + VIRTUAL_MEMORY_HEADER* Next(VIRTUAL_MEMORY_HEADER* current) { - return current + sizeof(VirtualMemoryHeader) + current->Size; + if (current->Magic != cVMTMagic) + current->Size = 8196; + + return current + sizeof(VIRTUAL_MEMORY_HEADER) + current->Size; } /// @brief Get previous header. /// @param current /// @return - VirtualMemoryHeader* Prev(VirtualMemoryHeader* current) + VIRTUAL_MEMORY_HEADER* Prev(VIRTUAL_MEMORY_HEADER* current) { - return current - sizeof(VirtualMemoryHeader) - current->Size; + if (current->Magic != cVMTMagic) + current->Size = 8196; + + return current - sizeof(VIRTUAL_MEMORY_HEADER) - current->Size; } }; } // namespace Detail @@ -64,14 +72,12 @@ namespace Kernel kAllocationInProgress = true; - constexpr auto cVMTMagic = 0xDEEFD00D; - ///! fetch from the start. - Detail::VirtualMemoryHeader* vmHeader = reinterpret_cast<Detail::VirtualMemoryHeader*>(kKernelVirtualStart); + Detail::VIRTUAL_MEMORY_HEADER* vmHeader = reinterpret_cast<Detail::VIRTUAL_MEMORY_HEADER*>(kKernelVMTStart); Detail::VirtualMemoryHeaderTraits traits; while (vmHeader->Present && - vmHeader->Magic != cVMTMagic) + vmHeader->Magic == cVMTMagic) { vmHeader = traits.Next(vmHeader); } @@ -84,7 +90,7 @@ namespace Kernel kAllocationInProgress = false; - return reinterpret_cast<VoidPtr>(vmHeader); + return reinterpret_cast<VoidPtr>(vmHeader + sizeof(Detail::VIRTUAL_MEMORY_HEADER)); } /// @brief Allocate a new page to be used by the OS. diff --git a/Kernel/Sources/NewFS+FileManager.cxx b/Kernel/Sources/NewFS+FileManager.cxx index 0018a7ff..b1622f77 100644 --- a/Kernel/Sources/NewFS+FileManager.cxx +++ b/Kernel/Sources/NewFS+FileManager.cxx @@ -19,6 +19,8 @@ namespace Kernel { MUST_PASS(Detail::fs_init_newfs()); fImpl = new NewFSParser(); + + kcout << "We are done here... (NewFilesystemManager).\r"; } NewFilesystemManager::~NewFilesystemManager() diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx index 46dd0d76..ee825400 100644 --- a/Kernel/Sources/User.cxx +++ b/Kernel/Sources/User.cxx @@ -58,6 +58,8 @@ namespace Kernel Bool User::TrySave(const Char* password) noexcept { + kcout << "Trying to save password...\r"; + SizeT len = rt_string_len(password); Char* token = new Char[len]; @@ -70,17 +72,28 @@ namespace Kernel if (NewFilesystemManager::GetMounted()) { - if (auto dir = NewFilesystemManager::GetMounted()->CreateDirectory("\\Users")) + if (auto dir = NewFilesystemManager::GetMounted()->CreateDirectory("\\Users"); + dir) + { delete dir; + } + else + { + delete token; + return false; + } auto node = NewFilesystemManager::GetMounted()->Create(kUsersFile); NewFilesystemManager::GetMounted()->Write(this->fUserName.CData(), node, (VoidPtr)token, this->IsStdUser() ? 0xCF : 0xEF, len); delete node; + delete token; return true; } + delete token; + return false; } |
