summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-09-04 22:20:17 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-09-04 22:20:17 +0200
commit1069f411d413e2185f6536b01b8993187056fcd8 (patch)
tree2b8bbfd6f2e497bd0e8a533f1fbf1ecd3fef29b6
parent0aaf98a4875893914b3c75cb0eb1eb0971412377 (diff)
[ IMP ] BMP allocator needs more tweaking and fixes, to be usable.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx (renamed from dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx)0
-rw-r--r--dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm34
-rw-r--r--dev/ZKA/HALKit/POWER/HalHardware.cxx19
-rw-r--r--dev/ZKA/KernelKit/CodeMgr.hxx2
-rw-r--r--dev/ZKA/KernelKit/IDLLObject.hxx (renamed from dev/ZKA/KernelKit/DLLInterface.hxx)14
-rw-r--r--dev/ZKA/KernelKit/IPEFDLLObject.hxx (renamed from dev/ZKA/KernelKit/PEFDLLInterface.hxx)18
-rw-r--r--dev/ZKA/KernelKit/UserProcessScheduler.hxx36
-rw-r--r--dev/ZKA/Sources/CodeMgr.cxx2
-rw-r--r--dev/ZKA/Sources/DLLMain.cxx2
-rw-r--r--dev/ZKA/Sources/Heap.cxx16
-rw-r--r--dev/ZKA/Sources/IDLLObject.cxx (renamed from dev/ZKA/Sources/DLLInterface.cxx)2
-rw-r--r--dev/ZKA/Sources/IPEFDLLObject.cxx (renamed from dev/ZKA/Sources/PEFDLLInterface.cxx)10
-rw-r--r--dev/ZKA/Sources/UserProcessScheduler.cxx169
13 files changed, 145 insertions, 179 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
index 7bafd075..7bafd075 100644
--- a/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm
index 1f31c880..c26a346f 100644
--- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm
+++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm
@@ -21,8 +21,6 @@ section .text
;; rcx: code ptr.
;; rdx: stack ptr.
mp_do_context_switch:
- swapgs
-
mov fs, rcx
mov gs, rdx
@@ -36,27 +34,12 @@ mp_do_context_switch:
mov r11, gs
mov r12, fs
- ; Enable SCE that enables sysret and syscall
- mov rcx, 0xc0000082
- wrmsr
- mov rcx, 0xc0000080
- rdmsr
- or eax, 1
- wrmsr
- mov rcx, 0xc0000081
- rdmsr
- mov edx, 0x00180008
- wrmsr
-
mov r11, 0x202
mov fs, [r8 + (8 * 4)]
mov gs, [r8 + (8 * 9)]
mov r8, [r8]
- swapgs
- sti
-
o64 sysret
;; @brief Gets the current stack frame.
@@ -68,8 +51,6 @@ extern hal_system_call_enter
global mp_system_call_handler
mp_system_call_handler:
- swapgs
-
push r8
push r9
push r10
@@ -80,9 +61,6 @@ mp_system_call_handler:
pop r9
pop r8
- swapgs
- sti
-
o64 sysret
mp_do_context_switch_pre:
@@ -96,4 +74,16 @@ mp_do_context_switch_pre:
mov rcx, 0xc0000082
wrmsr
+ ; Enable SCE that enables sysret and syscall
+ mov rcx, 0xc0000082
+ wrmsr
+ mov rcx, 0xc0000080
+ rdmsr
+ or eax, 1
+ wrmsr
+ mov rcx, 0xc0000081
+ rdmsr
+ mov edx, 0x00180008
+ wrmsr
+
ret
diff --git a/dev/ZKA/HALKit/POWER/HalHardware.cxx b/dev/ZKA/HALKit/POWER/HalHardware.cxx
deleted file mode 100644
index eb335d70..00000000
--- a/dev/ZKA/HALKit/POWER/HalHardware.cxx
+++ /dev/null
@@ -1,19 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Technologies.
-
-------------------------------------------- */
-
-#include <HALKit/POWER/Processor.hxx>
-#include <KernelKit/DebugOutput.hxx>
-
-namespace Kernel
-{
- namespace HAL
- {
- UIntPtr mm_alloc_bitmap(bool rw, bool user)
- {
- return 0;
- }
- } // namespace HAL
-} // namespace Kernel
diff --git a/dev/ZKA/KernelKit/CodeMgr.hxx b/dev/ZKA/KernelKit/CodeMgr.hxx
index 8c4f090f..c8f9cca9 100644
--- a/dev/ZKA/KernelKit/CodeMgr.hxx
+++ b/dev/ZKA/KernelKit/CodeMgr.hxx
@@ -16,7 +16,7 @@
#include <KernelKit/PECodeMgr.hxx>
#include <KernelKit/PEFCodeMgr.hxx>
-#include <KernelKit/PEFDLLInterface.hxx>
+#include <KernelKit/IPEFDLLObject.hxx>
namespace Kernel
{
diff --git a/dev/ZKA/KernelKit/DLLInterface.hxx b/dev/ZKA/KernelKit/IDLLObject.hxx
index 13f36b82..39580307 100644
--- a/dev/ZKA/KernelKit/DLLInterface.hxx
+++ b/dev/ZKA/KernelKit/IDLLObject.hxx
@@ -13,11 +13,11 @@
namespace Kernel
{
- class DLLInterface
+ class IDLLObject
{
public:
- explicit DLLInterface() = default;
- virtual ~DLLInterface() = default;
+ explicit IDLLObject() = default;
+ virtual ~IDLLObject() = default;
struct DLL_TRAITS final
{
@@ -30,7 +30,7 @@ namespace Kernel
}
};
- ZKA_COPY_DEFAULT(DLLInterface);
+ ZKA_COPY_DEFAULT(IDLLObject);
virtual DLL_TRAITS** GetAddressOf() = 0;
virtual DLL_TRAITS* Get() = 0;
@@ -38,12 +38,6 @@ namespace Kernel
virtual Void Mount(DLL_TRAITS* to_mount) = 0;
virtual Void Unmount() = 0;
-
- template <typename SymbolType>
- SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind)
- {
- return nullptr;
- }
};
/// @brief Pure implementation, missing method/function handler.
diff --git a/dev/ZKA/KernelKit/PEFDLLInterface.hxx b/dev/ZKA/KernelKit/IPEFDLLObject.hxx
index d664bfd8..013173d1 100644
--- a/dev/ZKA/KernelKit/PEFDLLInterface.hxx
+++ b/dev/ZKA/KernelKit/IPEFDLLObject.hxx
@@ -11,9 +11,9 @@
#define __KERNELKIT_SHARED_OBJECT_HXX__
#include <KernelKit/PEF.hxx>
-#include <KernelKit/PEFCodeMgr.hxx>
#include <NewKit/Defines.hxx>
-#include <KernelKit/DLLInterface.hxx>
+#include <KernelKit/PEFCodeMgr.hxx>
+#include <KernelKit/IDLLObject.hxx>
namespace Kernel
{
@@ -21,14 +21,14 @@ namespace Kernel
* @brief Shared Library class
* Load library from this class
*/
- class PEFDLLInterface final : public DLLInterface
+ class IPEFDLLObject final : public IDLLObject
{
public:
- explicit PEFDLLInterface() = default;
- ~PEFDLLInterface() = default;
+ explicit IPEFDLLObject() = default;
+ ~IPEFDLLObject() = default;
public:
- ZKA_COPY_DEFAULT(PEFDLLInterface);
+ ZKA_COPY_DEFAULT(IPEFDLLObject);
private:
DLL_TRAITS* fMounted{nullptr};
@@ -96,10 +96,10 @@ namespace Kernel
PEFLoader* fLoader{nullptr};
};
- typedef DLLInterface* DLLInterfacePtr;
+ typedef IPEFDLLObject* IDLL;
- EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header);
- EXTERN_C Void rtl_fini_shared_object(UserProcess* header, DLLInterfacePtr lib, Bool* successful);
+ EXTERN_C IDLL rtl_init_shared_object(UserProcess* header);
+ EXTERN_C Void rtl_fini_shared_object(UserProcess* header, IDLL lib, Bool* successful);
} // namespace Kernel
#endif /* ifndef __KERNELKIT_SHARED_OBJECT_HXX__ */
diff --git a/dev/ZKA/KernelKit/UserProcessScheduler.hxx b/dev/ZKA/KernelKit/UserProcessScheduler.hxx
index 78d75af6..d5172fe9 100644
--- a/dev/ZKA/KernelKit/UserProcessScheduler.hxx
+++ b/dev/ZKA/KernelKit/UserProcessScheduler.hxx
@@ -10,12 +10,10 @@
#include <ArchKit/ArchKit.hxx>
#include <KernelKit/LockDelegate.hxx>
#include <KernelKit/User.hxx>
-#include <KernelKit/DLLInterface.hxx>
#include <NewKit/MutableArray.hxx>
#define kSchedMinMicroTime (AffinityKind::kStandard)
#define kSchedInvalidPID (-1)
-#define kSchedMaxStackSz (4096) /* Max stack sz */
#define kSchedProcessLimitPerTeam (16U)
////////////////////////////////////////////////////
@@ -29,7 +27,7 @@ namespace Kernel
//! @note Forward declarations.
class UserProcess;
- class PEFDLLInterface;
+ class IPEFDLLObject;
class UserProcessTeam;
class UserProcessScheduler;
class UserProcessHelper;
@@ -148,24 +146,33 @@ namespace Kernel
User* Owner{nullptr};
HAL::StackFramePtr StackFrame{nullptr};
AffinityKind Affinity{AffinityKind::kStandard};
- ProcessStatusKind Status{ProcessStatusKind::kDead};
+ ProcessStatusKind Status{ProcessStatusKind::kDead};
UInt8* StackReserve{nullptr};
// Memory, images pointers.
- HeapPtrKind HeapCursor{nullptr};
ImagePtr Image{nullptr};
- HeapPtrKind HeapPtr{nullptr};
SizeT StackSize{mib_cast(8)};
- // shared library handle, reserved for kDLLKind types of executables only.
- DLLInterface* DLLPtr{nullptr};
- UserProcess* Parent{nullptr};
+ //! @brief Shared library handle, reserved for kDLLKind types of executables only.
+ IPEFDLLObject* DLLPtr{nullptr};
+
+ /// @brief Parent process, reserved for threads only.
+ UserProcess* Parent{nullptr};
// Memory usage.
- SizeT UsedMemory{0};
- SizeT FreeMemory{0};
- SizeT SizeMemory{mib_cast(64)};
+ SizeT MemoryCursor{0};
+ SizeT MemoryLimit{gib_cast(128)};
+
+ struct PROCESS_MEMORY_ENTRY
+ {
+ VoidPtr MemoryEntry;
+
+ struct PROCESS_MEMORY_ENTRY *MemoryPrev;
+ struct PROCESS_MEMORY_ENTRY *MemoryNext;
+ } * MemoryEntryList{nullptr};
+
+ SizeT MemoryPD{0};
enum
{
@@ -213,9 +220,9 @@ namespace Kernel
//! @return Int32 local error code.
Int32& GetLocalCode() noexcept;
- const User* GetOwner() noexcept;
+ const User* GetOwner() noexcept;
const ProcessStatusKind& GetStatus() noexcept;
- const AffinityKind& GetAffinity() noexcept;
+ const AffinityKind& GetAffinity() noexcept;
private:
UInt32 fLastExitCode{0};
@@ -291,6 +298,7 @@ namespace Kernel
STATIC bool CanBeScheduled(UserProcess& process);
STATIC PID& TheCurrentPID();
STATIC SizeT StartScheduling();
+ STATIC Void Init();
};
const UInt32& sched_get_exit_code(void) noexcept;
diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx
index df5b0917..c4ff2ee3 100644
--- a/dev/ZKA/Sources/CodeMgr.cxx
+++ b/dev/ZKA/Sources/CodeMgr.cxx
@@ -23,7 +23,7 @@ namespace Kernel
proc.SetImageStart(reinterpret_cast<VoidPtr>(main));
proc.Kind = UserProcess::kExeKind;
- proc.StackSize = kib_cast(8);
+ proc.StackSize = kib_cast(4);
rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName));
diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx
index 88887ec3..75fb24ff 100644
--- a/dev/ZKA/Sources/DLLMain.cxx
+++ b/dev/ZKA/Sources/DLLMain.cxx
@@ -189,6 +189,8 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void)
CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Starting ZKA System...", 20, 10, RGB(0, 0, 0));
+ Kernel::UserProcessHelper::Init();
+
Kernel::sched_execute_thread(HangCPU, "HANG TEST");
while (Yes)
diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx
index 615f5664..0b54cbcd 100644
--- a/dev/ZKA/Sources/Heap.cxx
+++ b/dev/ZKA/Sources/Heap.cxx
@@ -63,26 +63,26 @@ namespace Kernel
Detail::HEAP_INFORMATION_BLOCK_PTR kLatestAllocation = nullptr;
- /// @brief Declare a new size for allocatedPtr.
- /// @param allocatedPtr the pointer.
+ /// @brief Declare a new size for ptr_heap.
+ /// @param ptr_heap the pointer.
/// @return
- voidPtr mm_realloc_ke_heap(voidPtr allocatedPtr, SizeT newSz)
+ voidPtr mm_realloc_ke_heap(voidPtr ptr_heap, SizeT new_sz)
{
- if (!allocatedPtr || newSz < 1)
+ if (!ptr_heap || new_sz < 1)
return nullptr;
Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk =
reinterpret_cast<Detail::HEAP_INFORMATION_BLOCK_PTR>(
- (UIntPtr)allocatedPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK));
+ (UIntPtr)ptr_heap - sizeof(Detail::HEAP_INFORMATION_BLOCK));
- heap_blk->fHeapSize = newSz;
+ heap_blk->fHeapSize = new_sz;
if (heap_blk->fCRC32 > 0)
{
- MUST_PASS(mm_protect_ke_heap(allocatedPtr));
+ MUST_PASS(mm_protect_ke_heap(ptr_heap));
}
- return allocatedPtr;
+ return ptr_heap;
}
/// @brief Allocate chunk of memory.
diff --git a/dev/ZKA/Sources/DLLInterface.cxx b/dev/ZKA/Sources/IDLLObject.cxx
index c18f2f00..b6b6a348 100644
--- a/dev/ZKA/Sources/DLLInterface.cxx
+++ b/dev/ZKA/Sources/IDLLObject.cxx
@@ -7,7 +7,7 @@
* ========================================================
*/
-#include <KernelKit/DLLInterface.hxx>
+#include <KernelKit/IDLLObject.hxx>
#include <KernelKit/DebugOutput.hxx>
#include <KernelKit/UserProcessScheduler.hxx>
diff --git a/dev/ZKA/Sources/PEFDLLInterface.cxx b/dev/ZKA/Sources/IPEFDLLObject.cxx
index 70c68783..913912a4 100644
--- a/dev/ZKA/Sources/PEFDLLInterface.cxx
+++ b/dev/ZKA/Sources/IPEFDLLObject.cxx
@@ -9,7 +9,7 @@
#include <KernelKit/DebugOutput.hxx>
#include <KernelKit/PEF.hxx>
-#include <KernelKit/PEFDLLInterface.hxx>
+#include <KernelKit/IPEFDLLObject.hxx>
#include <KernelKit/UserProcessScheduler.hxx>
#include <KernelKit/ThreadLocalStorage.hxx>
#include <NewKit/Defines.hxx>
@@ -37,9 +37,9 @@ using namespace Kernel;
/** @brief Library initializer. */
/***********************************************************************************/
-EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header)
+EXTERN_C IDLL rtl_init_shared_object(UserProcess* header)
{
- DLLInterfacePtr sharedObj = tls_new_class<PEFDLLInterface>();
+ IDLL sharedObj = tls_new_class<IPEFDLLObject>();
if (!sharedObj)
{
@@ -48,7 +48,7 @@ EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header)
return nullptr;
}
- sharedObj->Mount(tls_new_class<PEFDLLInterface::DLL_TRAITS>());
+ sharedObj->Mount(tls_new_class<IPEFDLLObject::DLL_TRAITS>());
if (!sharedObj->Get())
{
@@ -80,7 +80,7 @@ EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header)
/** @param successful Reports if successful or not. */
/***********************************************************************************/
-EXTERN_C Void rtl_fini_shared_object(UserProcess* header, DLLInterfacePtr lib, Bool* successful)
+EXTERN_C Void rtl_fini_shared_object(UserProcess* header, IDLL lib, Bool* successful)
{
MUST_PASS(successful);
diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx
index 48988e57..7c576226 100644
--- a/dev/ZKA/Sources/UserProcessScheduler.cxx
+++ b/dev/ZKA/Sources/UserProcessScheduler.cxx
@@ -6,11 +6,11 @@
/***********************************************************************************/
/// @file UserProcessScheduler.cxx
-/// @brief User UserProcess scheduler.
+/// @brief User Process scheduler.
/***********************************************************************************/
#include <KernelKit/UserProcessScheduler.hxx>
-#include <KernelKit/PEFDLLInterface.hxx>
+#include <KernelKit/IPEFDLLObject.hxx>
#include <KernelKit/MP.hxx>
#include <KernelKit/Heap.hxx>
#include <NewKit/String.hxx>
@@ -19,7 +19,7 @@
///! BUGS: 0
/***********************************************************************************/
-/* TODO: Document more the Kernel, sdk and kits. */
+/* TODO: Document the Kernel, SDK and kits. */
/***********************************************************************************/
namespace Kernel
@@ -53,7 +53,7 @@ namespace Kernel
if (this->Name == 0)
return;
- kcout << this->Name << ": crashed, ID = " << number(kErrorProcessFault) << endl;
+ kcout << this->Name << ": crashed, ID = " << number(kErrorProcessFault) << endl;
this->Exit(kErrorProcessFault);
}
@@ -83,27 +83,45 @@ namespace Kernel
/***********************************************************************************/
+ /** @brief Add pointer to entry. */
VoidPtr UserProcess::New(const SizeT& sz)
{
- if (this->HeapCursor)
+#ifdef __ZKA_AMD64__
+ auto pd = hal_read_cr3();
+ hal_write_cr3(this->MemoryPD);
+
+ auto ptr = mm_new_ke_heap(sz, Yes, Yes);
+
+ hal_write_cr3(reinterpret_cast<UIntPtr>(pd));
+#else
+ auto ptr = mm_new_ke_heap(sz, Yes, Yes);
+#endif
+
+ if (!this->MemoryEntryList)
{
- if (this->FreeMemory < 1)
- {
- ErrLocal() = kErrorHeapOutOfMemory;
+ this->MemoryEntryList = new UserProcess::PROCESS_MEMORY_ENTRY();
+ this->MemoryEntryList->MemoryEntry = ptr;
- /* We're going out of memory! crash... */
- this->Crash();
+ this->MemoryEntryList->MemoryPrev = nullptr;
+ this->MemoryEntryList->MemoryNext = nullptr;
- return nullptr;
- }
+ return ptr;
+ }
+ else
+ {
+ auto entry = this->MemoryEntryList;
- this->HeapCursor = reinterpret_cast<VoidPtr>((UIntPtr)this->HeapCursor + (sizeof(sz)));
- VoidPtr cursor = this->HeapCursor;
+ while (entry->MemoryNext)
+ {
+ if (entry->MemoryNext)
+ entry = entry->MemoryNext;
+ }
- ++this->UsedMemory;
- --this->FreeMemory;
+ entry->MemoryNext = new UserProcess::PROCESS_MEMORY_ENTRY();
+ entry->MemoryNext->MemoryEntry = ptr;
- return cursor;
+ entry->MemoryNext->MemoryPrev = entry;
+ entry->MemoryNext->MemoryNext = nullptr;
}
return nullptr;
@@ -111,39 +129,31 @@ namespace Kernel
/***********************************************************************************/
- /* @brief checks if runtime pointer is in region. */
- bool rt_is_in_pool(VoidPtr pool_ptr, VoidPtr pool, const SizeT& pool_ptr_cur_sz, const SizeT& pool_ptr_used_sz)
- {
- if (pool == nullptr ||
- pool_ptr == nullptr)
- return false;
-
- UIntPtr* uint_pool_ptr = (UIntPtr*)pool_ptr;
- UIntPtr* uint_pool = (UIntPtr*)pool;
-
- return (UIntPtr)&uint_pool > (UIntPtr)&uint_pool_ptr &&
- pool_ptr_cur_sz > pool_ptr_used_sz;
- }
-
- /* @brief free pointer from usage. */
+ /** @brief Free pointer from usage. */
Boolean UserProcess::Delete(VoidPtr ptr, const SizeT& sz)
{
- if (sz < 1 || this->HeapCursor == this->HeapPtr)
- return false;
-
- // also check for the amount of allocations we've done so far.
- if (this->UsedMemory < 1)
- return false;
+ auto entry = this->MemoryEntryList;
- if (rt_is_in_pool(ptr, this->HeapCursor, this->UsedMemory, this->FreeMemory))
+ while (entry->MemoryNext)
{
- this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor - (sizeof(sz)));
- rt_zero_memory(ptr, sz);
+ if (entry->MemoryEntry == ptr)
+ {
+#ifdef __ZKA_AMD64__
+ auto pd = hal_read_cr3();
+ hal_write_cr3(this->MemoryPD);
- ++this->FreeMemory;
- --this->UsedMemory;
+ bool ret = mm_delete_ke_heap(ptr);
+ hal_write_cr3(reinterpret_cast<UIntPtr>(pd));
- return true;
+ return ret;
+#else
+ bool ret = mm_delete_ke_heap(ptr);
+ return ret;
+#endif
+ }
+
+ if (entry->MemoryNext)
+ entry = entry->MemoryNext;
}
return false;
@@ -183,7 +193,7 @@ namespace Kernel
void UserProcess::Exit(const Int32& exit_code)
{
this->Status = ProcessStatusKind::kDead;
-
+
fLastExitCode = exit_code;
cLastExitCode = exit_code;
@@ -211,7 +221,8 @@ namespace Kernel
if (this->StackReserve)
delete[] this->StackReserve;
- cProcessScheduler->Remove(this->ProcessId);
+ if (this->ProcessId > 0)
+ UserProcessScheduler::The().Remove(this->ProcessId);
}
/// @brief Add process to list.
@@ -219,73 +230,50 @@ namespace Kernel
/// @return the process index inside the team.
SizeT UserProcessScheduler::Add(UserProcess& process)
{
- if (!process.Image)
- {
- return -kErrorInvalidData;
- }
+#ifdef __ZKA_AMD64__
+ process.MemoryPD = reinterpret_cast<UIntPtr>(hal_read_cr3());
+#endif // __ZKA_AMD64__
- kcout << "UserProcessScheduler: Adding process to team...\r";
+ process.StackFrame = (HAL::StackFrame*)process.New(sizeof(HAL::StackFrame));
- // Create heap according to type of process.
- if (process.Kind == UserProcess::kExeKind)
- {
- process.HeapPtr = mm_new_ke_heap(process.SizeMemory, true, true);
- }
- else if (process.Kind == UserProcess::kDLLKind)
- {
- process.DLLPtr = rtl_init_shared_object(&process);
- process.HeapPtr = mm_new_ke_heap(process.SizeMemory, true, true);
- }
- else
+ if (!process.StackFrame)
{
- // Something went wrong, do not continue, process may be incorrect.
- process.Crash();
return -kErrorProcessFault;
}
- process.StackFrame = new HAL::StackFrame();
-
- if (!process.StackFrame)
+ // Create heap according to type of process.
+ if (process.Kind == UserProcess::kDLLKind)
{
- process.Crash();
- return -kErrorProcessFault;
+ process.DLLPtr = rtl_init_shared_object(&process);
}
-
+
if (process.Image)
{
// get preferred stack size by app.
const auto cMaxStackSize = process.StackSize;
-
- process.StackReserve = (UInt8*)mm_new_ke_heap(cMaxStackSize, Yes, Yes);
+ process.StackReserve = (UInt8*)process.New(sizeof(UInt8) * cMaxStackSize);
// if stack pointer isn't valid.
if (!process.StackReserve)
{
- process.StackReserve = (UInt8*)mm_new_ke_heap(kSchedMaxStackSz, Yes, Yes);
- kcout << "newoskrnl.exe: Use fallback reserve size.\r";
+ return -kErrorProcessFault;
}
}
else
{
if (process.Kind != UserProcess::kDLLKind)
{
- process.Crash();
return -kErrorProcessFault;
}
}
- process.Status = ProcessStatusKind::kStarting;
-
+ process.Status = ProcessStatusKind::kStarting;
process.ProcessId = mTeam.mProcessAmount;
++mTeam.mProcessAmount;
- process.HeapCursor = process.HeapPtr;
-
mTeam.AsArray()[process.ProcessId] = process;
- kcout << "UserProcessScheduler: Adding process to team [ OK ]...\r";
-
return process.ProcessId;
}
@@ -293,11 +281,6 @@ namespace Kernel
UserProcessScheduler& UserProcessScheduler::The()
{
- if (!cProcessScheduler)
- {
- cProcessScheduler = new UserProcessScheduler();
- }
-
MUST_PASS(cProcessScheduler);
return *cProcessScheduler;
}
@@ -341,7 +324,7 @@ namespace Kernel
if (UserProcessHelper::CanBeScheduled(process))
{
// set the current process.
- mTeam.AsRef() = process;
+ mTeam.AsRef() = mTeam.AsArray()[process.ProcessId];
process.PTime = static_cast<Int32>(process.Affinity);
@@ -349,7 +332,7 @@ namespace Kernel
// tell helper to find a core to schedule on.
if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize], process.StackFrame,
- process.ProcessId))
+ process.ProcessId))
{
process.Crash();
continue;
@@ -393,6 +376,14 @@ namespace Kernel
return cProcessScheduler->CurrentProcess().Leak().ProcessId;
}
+ Void UserProcessHelper::Init()
+ {
+ if (!cProcessScheduler)
+ {
+ cProcessScheduler = new UserProcessScheduler();
+ }
+ }
+
/// @brief Check if process can be schedulded.
/// @param process the process reference.
/// @retval true can be schedulded.
@@ -408,7 +399,7 @@ namespace Kernel
if (auto start = process.DLLPtr->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart), kPefCode);
start)
{
- process.Image = start;
+ process.Image = start;
}
}