summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKAKit/src
diff options
context:
space:
mode:
authorAmlal <amlal.elmahrouss@icloud.com>2024-11-02 07:46:45 +0100
committerAmlal <amlal.elmahrouss@icloud.com>2024-11-02 07:49:04 +0100
commitf5e656424dc41ff93c67bcc8139a76d40f525efc (patch)
treef701847fb8d2bec8a31c1f24f86afc5f2f338e64 /dev/ZKAKit/src
parent358379efc79bdda8b5742b82b95c45063184d76f (diff)
IMP: minOSKrnl commit 1039.
- KernelKit: New allocation limit in Heap.cc - KernelKit: Add Matches method for password validation. - KernelKit: Scheduler and Thread have been improved with new validations on frame. - META: Ran format command. - NewKit: Add new Ptr8 type for UInt8* types. - MBCI: Fix codestyle. Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/src')
-rw-r--r--dev/ZKAKit/src/DriveMgr.cc10
-rw-r--r--dev/ZKAKit/src/HardwareThreadScheduler.cc9
-rw-r--r--dev/ZKAKit/src/Heap.cc17
-rw-r--r--dev/ZKAKit/src/User.cc32
-rw-r--r--dev/ZKAKit/src/UserProcessScheduler.cc23
5 files changed, 66 insertions, 25 deletions
diff --git a/dev/ZKAKit/src/DriveMgr.cc b/dev/ZKAKit/src/DriveMgr.cc
index c8ab9b6c..3d11600b 100644
--- a/dev/ZKAKit/src/DriveMgr.cc
+++ b/dev/ZKAKit/src/DriveMgr.cc
@@ -147,8 +147,8 @@ namespace Kernel
{
_BOOT_BLOCK_STRUCT block_struct;
- trait.fPacket.fLba = kEPMBaseLba;
- trait.fPacket.fPacketSize = sizeof(_BOOT_BLOCK_STRUCT);
+ trait.fPacket.fLba = kEPMBaseLba;
+ trait.fPacket.fPacketSize = sizeof(_BOOT_BLOCK_STRUCT);
trait.fPacket.fPacketContent = &block_struct;
io_drv_input(&trait.fPacket);
@@ -164,11 +164,11 @@ namespace Kernel
trait.fKind |= kUnformattedDrive;
}
- trait.fPacket.fLba = 0;
- trait.fPacket.fPacketSize = 0UL;
+ trait.fPacket.fLba = 0;
+ trait.fPacket.fPacketSize = 0UL;
trait.fPacket.fPacketContent = nullptr;
}
- }
+ } // namespace Detail
/// @brief Fetches the main drive.
/// @return the new drive. (returns kEPMDrive if EPM formatted)
diff --git a/dev/ZKAKit/src/HardwareThreadScheduler.cc b/dev/ZKAKit/src/HardwareThreadScheduler.cc
index 5c75853c..5c5b8f15 100644
--- a/dev/ZKAKit/src/HardwareThreadScheduler.cc
+++ b/dev/ZKAKit/src/HardwareThreadScheduler.cc
@@ -89,14 +89,14 @@ namespace Kernel
/// @note Those symbols are needed in order to switch and validate the stack.
- EXTERN Bool hal_check_stack(HAL::StackFramePtr stackPtr);
- EXTERN_C Bool mp_register_process(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame_ptr);
+ EXTERN Bool hal_check_stack(HAL::StackFramePtr frame_ptr);
+ EXTERN_C Bool mp_register_process(VoidPtr image, Ptr8 stack_ptr, HAL::StackFramePtr frame_ptr);
/// @brief Switch to hardware thread.
/// @param stack the new hardware thread.
/// @retval true stack was changed, code is running.
/// @retval false stack is invalid, previous code is running.
- Bool HardwareThread::Switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame)
+ Bool HardwareThread::Switch(VoidPtr image, Ptr8 stack_ptr, HAL::StackFramePtr frame)
{
if (!frame ||
!image ||
@@ -109,6 +109,9 @@ namespace Kernel
if (this->IsBusy())
return No;
+ if (!hal_check_stack(frame))
+ return No;
+
fStack = frame;
Bool ret = mp_register_process(image, stack_ptr, fStack);
diff --git a/dev/ZKAKit/src/Heap.cc b/dev/ZKAKit/src/Heap.cc
index 65781f0e..fc3f7051 100644
--- a/dev/ZKAKit/src/Heap.cc
+++ b/dev/ZKAKit/src/Heap.cc
@@ -102,7 +102,7 @@ namespace Kernel
if (!ptr_heap || new_sz < 1)
return nullptr;
- kcout << "This function is not implemented by the MicroKernel, please use the BSD layer realloc instead.\r";
+ kcout << "This function is not implemented by minOSKrnl, please use the BSD's realloc instead.\r";
ke_stop(RUNTIME_CHECK_PROCESS);
return nullptr;
@@ -120,6 +120,9 @@ namespace Kernel
if (sz_fix == 0)
return nullptr;
+ // We can't allocate that big now.
+ MUST_PASS(sz <= gib_cast(2));
+
sz_fix += sizeof(Detail::HEAP_INFORMATION_BLOCK);
PageMgr heap_mgr;
@@ -236,12 +239,12 @@ namespace Kernel
}
heap_info_ptr->fHeapSize = 0UL;
- heap_info_ptr->fPresent = No;
- heap_info_ptr->fHeapPtr = 0;
- heap_info_ptr->fCRC32 = 0;
- heap_info_ptr->fWr = No;
- heap_info_ptr->fUser = No;
- heap_info_ptr->fMagic = 0;
+ heap_info_ptr->fPresent = No;
+ heap_info_ptr->fHeapPtr = 0;
+ heap_info_ptr->fCRC32 = 0;
+ heap_info_ptr->fWr = No;
+ heap_info_ptr->fUser = No;
+ heap_info_ptr->fMagic = 0;
PTEWrapper pageWrapper(No, No, No, reinterpret_cast<UIntPtr>(heap_info_ptr) - sizeof(Detail::HEAP_INFORMATION_BLOCK));
Ref<PTEWrapper> pteAddress{pageWrapper};
diff --git a/dev/ZKAKit/src/User.cc b/dev/ZKAKit/src/User.cc
index 189d80cf..9ac154f1 100644
--- a/dev/ZKAKit/src/User.cc
+++ b/dev/ZKAKit/src/User.cc
@@ -17,8 +17,8 @@
#include <KernelKit/UserProcessScheduler.h>
#include <KernelKit/Heap.h>
-#define kStdUserType (0xCEEF)
-#define kSuperUserType (0xECCF)
+#define kStdUserType (0xCE)
+#define kSuperUserType (0xEC)
/// BUGS: 0
@@ -43,7 +43,7 @@ namespace Kernel
if (cur_chr == 0)
break;
- password[i_pass] = cur_chr + (user->IsStdUser() ? kStdUserType : kSuperUserType);
+ password[i_pass] = cur_chr | (user->IsStdUser() ? kStdUserType : kSuperUserType);
}
kcout << "Done hashing password!\r";
@@ -67,7 +67,7 @@ namespace Kernel
User::~User() = default;
- Bool User::TrySave(const UserPublicKey password_to_fill) noexcept
+ Bool User::Save(const UserPublicKey password_to_fill) noexcept
{
if (!password_to_fill ||
*password_to_fill == 0)
@@ -103,6 +103,30 @@ namespace Kernel
return Yes;
}
+ Bool User::Matches(const UserPublicKey password_to_fill) noexcept
+ {
+ Char* password = new Char[len];
+ MUST_PASS(password);
+
+ // fill data first, generate hash.
+ // return false on error.
+
+ rt_copy_memory((VoidPtr)password_to_fill, password, len);
+
+ if (!Detail::cred_construct_token(password, password_to_fill, this, len))
+ {
+ delete[] password;
+ password = nullptr;
+
+ return No;
+ }
+
+ kcout << "Validating hashed passwords...\r";
+
+ // now check if the password matches.
+ return rt_string_cmp(password, this->fUserToken, rt_string_len(this->fUserToken)) == 0;
+ }
+
Bool User::operator==(const User& lhs)
{
return lhs.fRing == this->fRing;
diff --git a/dev/ZKAKit/src/UserProcessScheduler.cc b/dev/ZKAKit/src/UserProcessScheduler.cc
index c3e85716..b2fed635 100644
--- a/dev/ZKAKit/src/UserProcessScheduler.cc
+++ b/dev/ZKAKit/src/UserProcessScheduler.cc
@@ -38,9 +38,12 @@ namespace Kernel
/// @brief User Process scheduler global and external reference of thread scheduler.
/***********************************************************************************/
- UserProcessScheduler kProcessScheduler;
+ UserProcessScheduler kProcessScheduler;
- UserProcess::UserProcess(VoidPtr start_image) : Image(start_image) {}
+ UserProcess::UserProcess(VoidPtr start_image)
+ : Image(start_image)
+ {
+ }
UserProcess::~UserProcess() = default;
@@ -127,9 +130,9 @@ namespace Kernel
if (!this->MemoryHeap)
{
- this->MemoryHeap = new UserProcess::USER_PROCESS_HEAP();
+ this->MemoryHeap = new UserProcess::USER_PROCESS_HEAP();
- this->MemoryHeap->MemoryEntryPad = pad_amount;
+ this->MemoryHeap->MemoryEntryPad = pad_amount;
this->MemoryHeap->MemoryEntrySize = sz;
this->MemoryHeap->MemoryEntry = ptr;
@@ -141,7 +144,7 @@ namespace Kernel
}
else
{
- USER_PROCESS_HEAP* entry = this->MemoryHeap;
+ USER_PROCESS_HEAP* entry = this->MemoryHeap;
USER_PROCESS_HEAP* prev_entry = nullptr;
while (!entry)
@@ -439,7 +442,7 @@ namespace Kernel
process.PTime = static_cast<Int32>(process.Affinity);
UserProcessScheduler::The().GetCurrentProcess().Leak().Status = ProcessStatusKind::kFrozen;
- UserProcessScheduler::The().GetCurrentProcess() = process;
+ UserProcessScheduler::The().GetCurrentProcess() = process;
kcout << "Switch to '" << process.Name << "'.\r";
@@ -541,10 +544,18 @@ namespace Kernel
PID prev_pid = UserProcessHelper::TheCurrentPID();
UserProcessHelper::TheCurrentPID() = new_pid;
+ ////////////////////////////////////////////////////////////
+ /// Prepare task switch. ///
+ ////////////////////////////////////////////////////////////
+
auto prev_ptime = HardwareThreadScheduler::The()[index].Leak()->fPTime;
HardwareThreadScheduler::The()[index].Leak()->fPTime = UserProcessScheduler::The().CurrentTeam().AsArray()[new_pid].ProcessId;
Bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(image_ptr, stack, frame_ptr);
+ ////////////////////////////////////////////////////////////
+ /// Rollback on fail. ///
+ ////////////////////////////////////////////////////////////
+ ///
if (!ret)
{
HardwareThreadScheduler::The()[index].Leak()->fPTime = prev_ptime;