summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 10:38:58 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 10:38:58 +0200
commit98403fe342c8c2795de34e922958ee8d02c94e04 (patch)
tree30624c77cb63fcfc1b606d6264205b415af8fea8
parent7a43990192e13a7b32bc1f99a7dd02efe6f71e4e (diff)
[IMP] MHR-28:
+ Fixed VMH allocator, which was hanging because of a unitialized global field. + Working on fixing User save method for authorization purposes. + If .bss -> Zero memory region. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--CRTKit/__ndk_new_delete.hxx33
-rw-r--r--Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx7
-rw-r--r--Kernel/HALKit/AMD64/HalKernelMain.cxx19
-rw-r--r--Kernel/HALKit/AMD64/HalPageAlloc.cxx7
-rw-r--r--Kernel/Sources/FS/NewFS.cxx6
-rw-r--r--Kernel/Sources/Heap.cxx50
-rw-r--r--Kernel/Sources/PageManager.cxx2
-rw-r--r--Kernel/Sources/User.cxx9
8 files changed, 92 insertions, 41 deletions
diff --git a/CRTKit/__ndk_new_delete.hxx b/CRTKit/__ndk_new_delete.hxx
index cde972cc..7b30c9ab 100644
--- a/CRTKit/__ndk_new_delete.hxx
+++ b/CRTKit/__ndk_new_delete.hxx
@@ -7,6 +7,7 @@
#pragma once
#include <CRTKit/__ndk_defines.hxx>
+#include <SCIKit/SCIBase.hxx>
namespace stdx
{
@@ -26,3 +27,35 @@ namespace stdx
delete ptr;
}
} // namespace stdx
+
+void* operator new(size_type len)
+{
+ if (!len)
+ ++len;
+
+ return RtlCreateHeap(len, 0);
+}
+
+void operator delete(void* ptr)
+{
+ if (!ptr)
+ return;
+
+ RtlDestroyHeap(ptr);
+}
+
+void* operator new[](size_type len)
+{
+ if (!len)
+ ++len;
+
+ return RtlCreateHeap(len, 0);
+}
+
+void operator delete[](void* ptr)
+{
+ if (!ptr)
+ return;
+
+ RtlDestroyHeap(ptr);
+} \ No newline at end of file
diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx
index 9de1b5b4..6018d20f 100644
--- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx
+++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx
@@ -81,9 +81,12 @@ namespace Kernel::HAL
struct MADT_TABLE final : public SDT
{
UInt32 Address; // Madt address
- UInt8 Flags; // Madt flags
+ UInt32 Flags; // Madt flags
- VoidPtr Records[]; // Records List
+ struct {
+ UInt8 Type;
+ UInt8 Len;
+ } Records[]; // Records List
};
///////////////////////////////////////////////////////////////////////////////////////
diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx
index 1fff99e2..49ddfa6c 100644
--- a/Kernel/HALKit/AMD64/HalKernelMain.cxx
+++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx
@@ -24,6 +24,8 @@
Kernel::Property cKernelVersion;
Kernel::Property cAutoFormatDisk;
+EXTERN Kernel::Boolean kAllocationInProgress;
+
EXTERN_C Kernel::VoidPtr kInterruptVectorTable[];
struct HEAP_ALLOC_INFO final
@@ -84,7 +86,11 @@ EXTERN_C void hal_init_platform(
}
Kernel::Void hal_real_init(Kernel::Void) noexcept
-{ // get page size.
+{
+ // reset kAllocationInProgress field to zero.
+ kAllocationInProgress = false;
+
+ // get page size.
kKernelVirtualSize = kHandoverHeader->f_VirtualSize;
// get virtual address start (for the heap)
@@ -210,15 +216,20 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept
kSyscalls[cShutdownInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cRebootInterrupt].Leak().Leak()->fHooked = true;
- auto fs = new Kernel::NewFilesystemManager();
+ Kernel::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
- Kernel::NewFilesystemManager::Mount(fs);
+ Kernel::kcout << "newoskrnl: Creating filesystem and such.\r";
+ auto fs = new Kernel::NewFilesystemManager();
+
+ MUST_PASS(fs);
MUST_PASS(fs->GetParser());
+ Kernel::NewFilesystemManager::Mount(fs);
+
delete fs->GetParser()->CreateCatalog("\\Users\\", 0, kNewFSCatalogKindDir);
- Kernel::kcout << "newoskrnl: Creating filesystem and " << kSuperUser << "..." << Kernel::endl;
+ Kernel::kcout << "newoskrnl: Created filesystem and now creating " << kSuperUser << "..." << Kernel::endl;
cRoot = new Kernel::User(Kernel::RingKind::kRingSuperUser, kSuperUser);
diff --git a/Kernel/HALKit/AMD64/HalPageAlloc.cxx b/Kernel/HALKit/AMD64/HalPageAlloc.cxx
index b554e211..0e39a0f1 100644
--- a/Kernel/HALKit/AMD64/HalPageAlloc.cxx
+++ b/Kernel/HALKit/AMD64/HalPageAlloc.cxx
@@ -6,6 +6,8 @@
#include <ArchKit/ArchKit.hxx>
+#define cVMHMagic (0xDEEFD00D)
+
#ifdef __NEWOS_AMD64__
#include <HALKit/AMD64/HalPageAlloc.hxx>
#elif defined(__NEWOS_ARM64__)
@@ -19,7 +21,6 @@ Kernel::Boolean kAllocationInProgress = false;
namespace Kernel
{
- constexpr auto cVMHMagic = 0xDEEFD00D;
namespace HAL
{
@@ -99,12 +100,16 @@ namespace Kernel
/// @return
auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr
{
+ kcout << "Waiting now...";
+
// Wait for a ongoing allocation to complete.
while (kAllocationInProgress)
{
(void)0;
}
+ kcout << ", done waiting, allocating...\r";
+
if (size == 0)
++size;
diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx
index 3382aa04..90f48eb2 100644
--- a/Kernel/Sources/FS/NewFS.cxx
+++ b/Kernel/Sources/FS/NewFS.cxx
@@ -1034,16 +1034,18 @@ namespace Kernel::Detail
/***********************************************************************************/
Boolean fs_init_newfs(Void) noexcept
{
+ kcout << "newoskrnl: Creating drives...\r";
+
sMountpointInterface.A() = io_construct_main_drive();
sMountpointInterface.B() = io_construct_drive();
sMountpointInterface.C() = io_construct_drive();
sMountpointInterface.D() = io_construct_drive();
- kcout << "newoskrnl: Testing drive...\r";
+ kcout << "newoskrnl: Testing main drive...\r";
sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket);
- kcout << "newoskrnl: Testing drive [ OK ]...\r";
+ kcout << "newoskrnl: Testing main drive [ OK ]...\r";
return true;
}
diff --git a/Kernel/Sources/Heap.cxx b/Kernel/Sources/Heap.cxx
index 5b004880..de0c8a5c 100644
--- a/Kernel/Sources/Heap.cxx
+++ b/Kernel/Sources/Heap.cxx
@@ -94,17 +94,19 @@ namespace Kernel
if (szFix == 0)
++szFix;
+ kcout << "newoskrnl: allocating VMH page...\r";
+
auto wrapper = kHeapPageManager.Request(rw, user, false, szFix);
- Detail::HEAP_INFORMATION_BLOCK_PTR heapInfo =
+ Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
wrapper.VirtualAddress());
- heapInfo->fTargetPtrSize = szFix;
- heapInfo->fMagic = kKernelHeapMagic;
- heapInfo->fCRC32 = 0; // dont fill it for now.
- heapInfo->fTargetPtr = wrapper.VirtualAddress();
- heapInfo->fPagePtr = 0;
+ heap_info_ptr->fTargetPtrSize = szFix;
+ heap_info_ptr->fMagic = kKernelHeapMagic;
+ heap_info_ptr->fCRC32 = 0; // dont fill it for now.
+ heap_info_ptr->fTargetPtr = wrapper.VirtualAddress();
+ heap_info_ptr->fPagePtr = 0;
++kHeapCount;
@@ -115,22 +117,22 @@ namespace Kernel
}
/// @brief Makes a page heap.
- /// @param heapPtr
+ /// @param heap_ptr
/// @return
- Int32 mm_make_ke_page(VoidPtr heapPtr)
+ Int32 mm_make_ke_page(VoidPtr heap_ptr)
{
if (kHeapCount < 1)
return -kErrorInternal;
- if (((IntPtr)heapPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0)
+ if (((IntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0)
return -kErrorInternal;
- if (((IntPtr)heapPtr - kBadPtr) < 0)
+ if (((IntPtr)heap_ptr - kBadPtr) < 0)
return -kErrorInternal;
Detail::mm_alloc_init_timeout();
Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
- (UIntPtr)heapPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+ (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
heapInfoBlk->fPagePtr = 1;
@@ -140,22 +142,22 @@ namespace Kernel
}
/// @brief Declare pointer as free.
- /// @param heapPtr the pointer.
+ /// @param heap_ptr the pointer.
/// @return
- Int32 mm_delete_ke_heap(VoidPtr heapPtr)
+ Int32 mm_delete_ke_heap(VoidPtr heap_ptr)
{
if (kHeapCount < 1)
return -kErrorInternal;
- if (((IntPtr)heapPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0)
+ if (((IntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0)
return -kErrorInternal;
- if (((IntPtr)heapPtr - kBadPtr) < 0)
+ if (((IntPtr)heap_ptr - kBadPtr) < 0)
return -kErrorInternal;
Detail::mm_alloc_init_timeout();
Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
- (UIntPtr)heapPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+ (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
if (heapInfoBlk && heapInfoBlk->fMagic == kKernelHeapMagic)
{
@@ -197,18 +199,18 @@ namespace Kernel
}
/// @brief Check if pointer is a valid kernel pointer.
- /// @param heapPtr the pointer
+ /// @param heap_ptr the pointer
/// @return if it exists.
- Boolean mm_is_valid_heap(VoidPtr heapPtr)
+ Boolean mm_is_valid_heap(VoidPtr heap_ptr)
{
if (kHeapCount < 1)
return false;
- if (heapPtr)
+ if (heap_ptr)
{
Detail::HEAP_INFORMATION_BLOCK_PTR virtualAddress =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
- (UIntPtr)heapPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+ (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
if (virtualAddress->fPresent && virtualAddress->fMagic == kKernelHeapMagic)
{
@@ -220,15 +222,15 @@ namespace Kernel
}
/// @brief Protect the heap with a CRC value.
- /// @param heapPtr HIB pointer.
+ /// @param heap_ptr HIB pointer.
/// @return if it valid: point has crc now., otherwise fail.
- Boolean mm_protect_ke_heap(VoidPtr heapPtr)
+ Boolean mm_protect_ke_heap(VoidPtr heap_ptr)
{
- if (heapPtr)
+ if (heap_ptr)
{
Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
- (UIntPtr)heapPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+ (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
if (heapInfoBlk->fPresent && kKernelHeapMagic == heapInfoBlk->fMagic)
{
diff --git a/Kernel/Sources/PageManager.cxx b/Kernel/Sources/PageManager.cxx
index 8e9e77cc..7e0ef67b 100644
--- a/Kernel/Sources/PageManager.cxx
+++ b/Kernel/Sources/PageManager.cxx
@@ -63,6 +63,8 @@ namespace Kernel
/// @return
PTEWrapper PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz)
{
+ kcout << "newoskrnl: Allocating VMH page from PageManager...\r";
+
// Store PTE wrapper right after PTE.
VoidPtr ptr = Kernel::HAL::hal_alloc_page(Rw, User, Sz);
diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx
index 22dda57e..4109864a 100644
--- a/Kernel/Sources/User.cxx
+++ b/Kernel/Sources/User.cxx
@@ -75,12 +75,7 @@ namespace Kernel
if (NewFilesystemManager::GetMounted())
{
- auto node = NewFilesystemManager::GetMounted()->Open(kUsersFile, "wb");
-
- if (!node)
- {
- NewFilesystemManager::GetMounted()->Create(kUsersFile);
- }
+ auto node = NewFilesystemManager::GetMounted()->Create(kUsersFile);
if (node)
{
@@ -89,12 +84,10 @@ namespace Kernel
}
delete token;
-
return true;
}
delete token;
-
return false;
}