diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-06 09:38:00 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-06 09:38:00 +0200 |
| commit | 507b3a76de36e41bdfd1c14d94a397990b26a423 (patch) | |
| tree | e087051b51d36828fbca98d9e9e74cb1381a4def /dev/ZKA/HALKit | |
| parent | 98f504c442b1a0f769e2f20e4fb251813dd5dd67 (diff) | |
[ IMP ] A first set of software patches regarding the OS kernel and it's components.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/ZKA/HALKit')
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx | 70 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/ARM64/HalKernelMain.cxx | 2 |
3 files changed, 53 insertions, 21 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx index 221cb044..800d8b3d 100644 --- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx +++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx @@ -6,7 +6,7 @@ #include <ArchKit/ArchKit.hxx> -#define cVMHMagic ((Kernel::UIntPtr)0x10210) +#define cBitMpMagic ((Kernel::UIntPtr)0x10210) #ifdef __ZKA_AMD64__ #include <HALKit/AMD64/HalPageAlloc.hxx> @@ -29,21 +29,47 @@ namespace Kernel /// @return The new address which was found. VoidPtr FindBitMap(VoidPtr base_ptr, SizeT size, Bool rw, Bool user) noexcept { + auto base = reinterpret_cast<UIntPtr>(base_ptr); + while (base_ptr && size) { UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base_ptr); - if (ptr_bit_set[0] != cVMHMagic) + if (ptr_bit_set[0] == cBitMpMagic) + { + if (ptr_bit_set[1] != 0 && + ptr_bit_set[1] <= size && + ptr_bit_set[2] == No) + { + ptr_bit_set[1] = size; + ptr_bit_set[2] = Yes; + + kcout << "BMPMgr: Allocated pointer!\r"; + kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "Size of pointer: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl; + + if (rw) + mm_update_pte(base_ptr, eFlagsRw); + + if (user) + mm_update_pte(base_ptr, eFlagsUser); + + return (VoidPtr)ptr_bit_set; + } + } + else { - ptr_bit_set[0] = cVMHMagic; + UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base_ptr); + + ptr_bit_set[0] = cBitMpMagic; ptr_bit_set[1] = size; - ptr_bit_set[2] = __BIGGEST_ALIGNMENT__; + ptr_bit_set[2] = Yes; - kcout << "ALLOC STATUS\r"; - kcout << "MAG: " << hex_number(ptr_bit_set[0]) << endl; - kcout << "ADDRESS: " << hex_number((UIntPtr)ptr_bit_set) << endl; - kcout << "SIZE: " << hex_number(ptr_bit_set[1]) << endl; - kcout << "ALLOC STATUS\r"; + kcout << "BMPMgr: Allocated pointer!\r"; + kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "Size of pointer: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl; if (rw) mm_update_pte(base_ptr, eFlagsRw); @@ -54,7 +80,10 @@ namespace Kernel return (VoidPtr)ptr_bit_set; } - base_ptr = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base_ptr) + __BIGGEST_ALIGNMENT__ + ptr_bit_set[1]); + base_ptr = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base_ptr) + (ptr_bit_set[0] != cBitMpMagic ? size : ptr_bit_set[1])); + + if (reinterpret_cast<UIntPtr>(base_ptr) >= (kHandoverHeader->f_BitMapSize + base)) + break; } return nullptr; @@ -73,6 +102,11 @@ namespace Kernel ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); + if (!ptr_new) + { + ke_stop(RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM); + } + return ((UIntPtr*)ptr_new); } @@ -84,18 +118,16 @@ namespace Kernel UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(page_ptr); if (!ptr_bit_set[0] || - ptr_bit_set[0] != cVMHMagic) + ptr_bit_set[0] != cBitMpMagic) return false; - kcout << "FREE STATUS\r"; - kcout << "MAG: " << hex_number(ptr_bit_set[0]) << endl; - kcout << "ADDRESSS: " << hex_number((UIntPtr)ptr_bit_set) << endl; - kcout << "SIZE: " << hex_number(ptr_bit_set[1]) << endl; - kcout << "FREE STATUS\r"; + kcout << "BMPMgr: Freed pointer!\r"; + kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "Size of pointer: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl; - ptr_bit_set[0] = 0UL; - ptr_bit_set[1] = 0UL; - ptr_bit_set[2] = __BIGGEST_ALIGNMENT__; + ptr_bit_set[0] = cBitMpMagic; + ptr_bit_set[2] = No; return true; } diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 79d9c097..c73eed5f 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -93,7 +93,7 @@ EXTERN_C void hal_init_platform( Kernel::Void hal_real_init(Kernel::Void) noexcept { // get page size. - kKernelVirtualSize = kHandoverHeader->f_VirtualSize; + kKernelVirtualSize = kHandoverHeader->f_BitMapSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( diff --git a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx index 140c3370..d6bed3ba 100644 --- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx @@ -77,7 +77,7 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept kAllocationInProgress = false; // get page size. - kKernelVirtualSize = kHandoverHeader->f_VirtualSize; + kKernelVirtualSize = kHandoverHeader->f_BitMapSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( |
