summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Sources
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-07-09 20:51:20 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-07-09 20:52:00 +0200
commitdfaf137915094e7ba72f7d7f1f57dc5158d1b6ab (patch)
tree802a5bf263d606b59bb52d5e7434a04c8644d07e /Kernel/Sources
parent891245c6c9a78cea6074e336d1b04a2264b2fcce (diff)
MHR-36: A set of major fixes for bootloader and kernel alongside new
implementations. - Implement realloc for kernel scheduler improvements. - Fixed readAll on bootloader's BFileReader. - Add resources for zeta installation. - Add STB header. - Process Heap which replaced the previous User Heap. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Sources')
-rw-r--r--Kernel/Sources/KeMain.cxx2
-rw-r--r--Kernel/Sources/KernelHeap.cxx36
-rw-r--r--Kernel/Sources/ProcessHeap.cxx (renamed from Kernel/Sources/UserHeap.cxx)4
-rw-r--r--Kernel/Sources/ProcessScheduler.cxx34
4 files changed, 57 insertions, 19 deletions
diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx
index 0ba882af..d4c02990 100644
--- a/Kernel/Sources/KeMain.cxx
+++ b/Kernel/Sources/KeMain.cxx
@@ -17,7 +17,7 @@
#include <KernelKit/PEF.hpp>
#include <KernelKit/PEFCodeManager.hxx>
#include <KernelKit/ProcessScheduler.hxx>
-#include <KernelKit/UserHeap.hpp>
+#include <KernelKit/ProcessHeap.hpp>
#include <NewKit/Json.hpp>
#include <NewKit/KernelCheck.hpp>
#include <NewKit/String.hpp>
diff --git a/Kernel/Sources/KernelHeap.cxx b/Kernel/Sources/KernelHeap.cxx
index 295c4e76..2cf89480 100644
--- a/Kernel/Sources/KernelHeap.cxx
+++ b/Kernel/Sources/KernelHeap.cxx
@@ -11,7 +11,7 @@
#include <NewKit/PageManager.hpp>
//! @file KernelHeap.cxx
-//! @brief Kernel allocator.
+//! @brief Kernel heap allocator.
#define kKernelHeapMagic (0xD4D7D5)
#define kKernelHeapHeaderPaddingSz (16U)
@@ -47,23 +47,47 @@ namespace Kernel
typedef HeapInformationBlock* HeapInformationBlockPtr;
} // namespace Detail
+ /// @brief Declare a new size for allocatedPtr.
+ /// @param allocatedPtr the pointer.
+ /// @return
+ voidPtr ke_realloc_ke_heap(voidPtr allocatedPtr, SizeT newSz)
+ {
+ if (!allocatedPtr || newSz < 1)
+ return nullptr;
+
+ Detail::HeapInformationBlockPtr heapInfoBlk =
+ reinterpret_cast<Detail::HeapInformationBlockPtr>(
+ (UIntPtr)allocatedPtr - sizeof(Detail::HeapInformationBlock));
+
+ heapInfoBlk->fTargetPtrSize = newSz;
+
+ if (heapInfoBlk->fCRC32 > 0)
+ {
+ MUST_PASS(ke_protect_ke_heap(allocatedPtr));
+ }
+
+ return allocatedPtr;
+ }
+
/// @brief allocate chunk of memory.
/// @param sz size of pointer
/// @param rw read write (true to enable it)
/// @param user is it accesible by user processes?
/// @return the pointer
- VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user)
+ VoidPtr ke_new_ke_heap(const SizeT sz, const bool rw, const bool user)
{
- if (sz == 0)
- ++sz;
+ auto szFix = sz;
+
+ if (szFix == 0)
+ ++szFix;
- auto wrapper = kHeapPageManager.Request(rw, user, false, sz);
+ auto wrapper = kHeapPageManager.Request(rw, user, false, szFix);
Detail::HeapInformationBlockPtr heapInfo =
reinterpret_cast<Detail::HeapInformationBlockPtr>(
wrapper.VirtualAddress());
- heapInfo->fTargetPtrSize = sz;
+ heapInfo->fTargetPtrSize = szFix;
heapInfo->fMagic = kKernelHeapMagic;
heapInfo->fCRC32 = 0; // dont fill it for now.
heapInfo->fTargetPtr = wrapper.VirtualAddress();
diff --git a/Kernel/Sources/UserHeap.cxx b/Kernel/Sources/ProcessHeap.cxx
index 453d1f30..b5988c5f 100644
--- a/Kernel/Sources/UserHeap.cxx
+++ b/Kernel/Sources/ProcessHeap.cxx
@@ -5,12 +5,12 @@
------------------------------------------- */
#include <KernelKit/ProcessScheduler.hxx>
-#include <KernelKit/UserHeap.hpp>
+#include <KernelKit/ProcessHeap.hpp>
#include <NewKit/PageManager.hpp>
#define kHeapHeaderPaddingSz (16U)
-/// @file UserHeap.cxx
+/// @file ProcessHeap.cxx
/// @brief User Heap Manager, Process heap allocator.
/// @note if you want to look at the kernel allocator, please look for
/// KernelHeap.cxx
diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx
index 98851d41..f8330ae8 100644
--- a/Kernel/Sources/ProcessScheduler.cxx
+++ b/Kernel/Sources/ProcessScheduler.cxx
@@ -206,15 +206,23 @@ namespace Kernel
if (mTeam.AsArray().Count() > kSchedProcessLimitPerTeam)
return -kErrorOutOfTeamSlot;
- kcout << "ProcessScheduler::Add(Ref<ProcessHeader>& process)\r";
+ kcout << "ProcessScheduler:: adding process to team...\r";
/// Create heap according to type of process.
if (process.Leak().Kind == ProcessHeader::kAppKind)
+ {
process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw);
+ }
else if (process.Leak().Kind == ProcessHeader::kShLibKind)
+ {
process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw | kUserHeapShared);
+ }
else
- process.Leak().HeapPtr = rt_new_heap(kUserHeapDriver | kUserHeapRw);
+ {
+ // something went wrong, do not continue, process kind is incorrect.
+ process.Leak().Crash();
+ return -kErrorProcessFault;
+ }
process.Leak().StackFrame = reinterpret_cast<HAL::StackFrame*>(
ke_new_ke_heap(sizeof(HAL::StackFrame), true, false));
@@ -226,22 +234,28 @@ namespace Kernel
process.Leak().ProcessId = (mTeam.AsArray().Count() - 1);
process.Leak().HeapCursor = process.Leak().HeapPtr;
- mTeam.AsArray().Add(process);
+ MUST_PASS(mTeam.AsArray().Add(process));
- return mTeam.AsArray().Count() - 1;
+ return (mTeam.AsArray().Count() - 1);
}
/// @brief Remove process from list.
- /// @param process
- /// @return
- bool ProcessScheduler::Remove(SizeT process)
+ /// @param processSlot process slot inside team.
+ /// @retval true process was removed.
+ /// @retval false process doesn't exist in team.
+ Bool ProcessScheduler::Remove(SizeT processSlot)
{
- if (process > mTeam.AsArray().Count())
+ // check if process is within range.
+ if (processSlot > mTeam.AsArray().Count())
+ return false;
+
+ // also check if the process isn't a dummy one.
+ if (mTeam.AsArray()[processSlot].Leak().Leak().Image == nullptr)
return false;
- kcout << "ProcessScheduler::Remove(SizeT process)\r";
+ kcout << "ProcessScheduler: removing process\r";
- return mTeam.AsArray().Remove(process);
+ return mTeam.AsArray().Remove(processSlot);
}
/// @brief Run scheduler.