summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Sources
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-07-31 00:13:51 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-07-31 00:13:51 +0200
commit3bfb95803ba25a04ddb57ebbc0f25e4dec29d7e0 (patch)
tree94fc17899142c1631797b9b6257b04359282741b /Kernel/Sources
parent659435af7da4ffb15a309063c892b518707fa9d0 (diff)
[IMP] Can now pass arguments to kernel via handover, new version 0x0113.
[IMP] Timeout functions for heap allocation. [IMP] new mp_ and sched_ category of functions. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Sources')
-rw-r--r--Kernel/Sources/Heap.cxx36
-rw-r--r--Kernel/Sources/MPManager.cxx4
-rw-r--r--Kernel/Sources/Main.cxx55
-rw-r--r--Kernel/Sources/ProcessScheduler.cxx2
-rw-r--r--Kernel/Sources/User.cxx32
5 files changed, 72 insertions, 57 deletions
diff --git a/Kernel/Sources/Heap.cxx b/Kernel/Sources/Heap.cxx
index f24eda56..94406d1d 100644
--- a/Kernel/Sources/Heap.cxx
+++ b/Kernel/Sources/Heap.cxx
@@ -21,6 +21,8 @@ namespace Kernel
STATIC SizeT kHeapCount = 0UL;
STATIC PageManager kHeapPageManager;
+ STATIC Bool kOperationInProgress = No;
+
namespace Detail
{
/// @brief Kernel heap information block.
@@ -45,6 +47,26 @@ namespace Kernel
};
typedef HEAP_INFORMATION_BLOCK* HEAP_INFORMATION_BLOCK_PTR;
+
+ Bool mm_alloc_init_timeout(Void) noexcept
+ {
+ SizeT timOut = 0U;
+
+ while (kOperationInProgress)
+ {
+ ++timOut;
+ if (timOut > 10000000)
+ return false;
+ }
+
+ kOperationInProgress = Yes;
+ return true;
+ }
+
+ Void mm_alloc_fini_timeout(Void) noexcept
+ {
+ kOperationInProgress = No;
+ }
} // namespace Detail
/// @brief Declare a new size for allocatedPtr.
@@ -76,6 +98,8 @@ namespace Kernel
/// @return the pointer
VoidPtr mm_new_ke_heap(const SizeT sz, const bool rw, const bool user)
{
+ Detail::mm_alloc_init_timeout();
+
auto szFix = sz;
if (szFix == 0)
@@ -95,6 +119,8 @@ namespace Kernel
++kHeapCount;
+ Detail::mm_alloc_fini_timeout();
+
return reinterpret_cast<VoidPtr>(wrapper.VirtualAddress() +
sizeof(Detail::HEAP_INFORMATION_BLOCK));
}
@@ -111,12 +137,16 @@ namespace Kernel
if (((IntPtr)heapPtr - 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));
heapInfoBlk->fPagePtr = 1;
+ Detail::mm_alloc_fini_timeout();
+
return 0;
}
@@ -132,6 +162,8 @@ namespace Kernel
if (((IntPtr)heapPtr - 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));
@@ -140,6 +172,7 @@ namespace Kernel
{
if (!heapInfoBlk->fPresent)
{
+ Detail::mm_alloc_fini_timeout();
return -kErrorHeapNotPresent;
}
@@ -165,6 +198,9 @@ namespace Kernel
kHeapPageManager.Free(pteAddress);
--kHeapCount;
+
+ Detail::mm_alloc_fini_timeout();
+
return 0;
}
diff --git a/Kernel/Sources/MPManager.cxx b/Kernel/Sources/MPManager.cxx
index d8faa983..3ad1e8aa 100644
--- a/Kernel/Sources/MPManager.cxx
+++ b/Kernel/Sources/MPManager.cxx
@@ -71,9 +71,9 @@ namespace Kernel
fWakeup = wakeup;
if (!fWakeup)
- rt_hang_thread(fStack);
+ mp_hang_thread(fStack);
else
- rt_wakeup_thread(fStack);
+ mp_wakeup_thread(fStack);
}
EXTERN Bool rt_check_stack(HAL::StackFramePtr stackPtr);
diff --git a/Kernel/Sources/Main.cxx b/Kernel/Sources/Main.cxx
index 79febc15..145598ac 100644
--- a/Kernel/Sources/Main.cxx
+++ b/Kernel/Sources/Main.cxx
@@ -60,10 +60,10 @@ namespace Kernel::Detail
if (fNewFS->GetParser())
{
constexpr auto cFolderInfo = "META-INF";
- const auto cDirCount = 9;
+ const auto cDirCount = 7;
const char* cDirStr[cDirCount] = {
"\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\",
- "\\Users\\", "\\Library\\", "\\Mounted\\", "\\DCIM\\", "\\Applications\\Store\\"};
+ "\\Users\\", "\\Library\\", "\\Mounted\\"};
for (Kernel::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx)
{
@@ -102,7 +102,7 @@ namespace Kernel::Detail
metadataFolder +=
"<!properties/>\r<p>Kind: folder</p>\r<p>Created by: system</p>\r<p>Edited by: "
- "system</p>\r<p>Volume Type: Zeta</p>\r";
+ "system</p>\r<p>Volume Type: ZKA Filesystem</p>\r";
metadataFolder += "<p>Path: ";
metadataFolder += cDirStr[dirIndx];
@@ -121,53 +121,6 @@ namespace Kernel::Detail
delete catalogSystem;
}
}
-
- NFS_CATALOG_STRUCT* catalogDisk =
- this->fNewFS->GetParser()->GetCatalog("\\Mount\\SIM:");
-
- const Kernel::Char* cSrcName = "DISK-INF";
-
- if (catalogDisk)
- {
- delete catalogDisk;
- }
- else
- {
- catalogDisk =
- (NFS_CATALOG_STRUCT*)this->Leak()->CreateAlias("\\Mount\\SIM:");
-
- Kernel::StringView diskFolder(kNewFSSectorSz);
-
- diskFolder +=
- "<!properties/><p>Kind: alias to SIM Card</p>\r<p>Created by: system</p>\r<p>Edited "
- "by: "
- "system</p>\r<p>Volume Type: SIM Card</p>\r";
-
- diskFolder += "<p>Root: ";
- diskFolder += Kernel::NewFilesystemHelper::Root();
- diskFolder += "</p>\r";
-
- NFS_FORK_STRUCT theDiskFork{0};
-
- Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName,
- Kernel::rt_string_len(cSrcName));
-
- Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name),
- theDiskFork.CatalogName,
- Kernel::rt_string_len(catalogDisk->Name));
-
- theDiskFork.DataSize = kNewFSForkSize;
- theDiskFork.ResourceId = 0;
- theDiskFork.ResourceKind = Kernel::kNewFSRsrcForkKind;
- theDiskFork.Kind = Kernel::kNewFSDataForkKind;
-
- fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork);
- fNewFS->GetParser()->WriteCatalog(catalogDisk,
- (Kernel::VoidPtr)diskFolder.CData(),
- kNewFSSectorSz, cSrcName);
-
- delete catalogDisk;
- }
}
}
@@ -190,7 +143,7 @@ namespace Kernel::Detail
{
Kernel::UserView::The()->fRootUser = new User(RingKind::kRingSuperUser, kSuperUser);
- Kernel::UserView::The()->LogIn(Kernel::UserView::The()->fRootUser, "");
+ Kernel::UserView::The()->LogIn(Kernel::UserView::The()->fRootUser, "root");
Kernel::kcout << "newoskrnl: " << cKernelVersion.GetKey().CData() << ": " << Kernel::number(cKernelVersion.GetValue()) << Kernel::endl;
}
diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx
index 7002bd1f..3301588a 100644
--- a/Kernel/Sources/ProcessScheduler.cxx
+++ b/Kernel/Sources/ProcessScheduler.cxx
@@ -32,7 +32,7 @@ namespace Kernel
/// @brief Gets the last exit code.
/// @note Not thread-safe.
/// @return Int32 the last exit code.
- const Int32& rt_get_exit_code() noexcept
+ const Int32& sched_get_exit_code(void) noexcept
{
return cLastExitCode;
}
diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx
index 92acba97..49c5cad9 100644
--- a/Kernel/Sources/User.cxx
+++ b/Kernel/Sources/User.cxx
@@ -15,6 +15,8 @@
#include <KernelKit/FileManager.hpp>
#include <KernelKit/ProcessScheduler.hxx>
+#include <KernelKit/Heap.hxx>
+
/// bugs 0
namespace Kernel
@@ -77,18 +79,24 @@ namespace Kernel
return view;
}
- Void UserView::LogIn(User* user, const Char* password) noexcept
+ Bool UserView::LogIn(User* user, const Char* password) noexcept
{
if (!password ||
!user)
{
ErrLocal() = kErrorInvalidData;
- return;
+ kcout << "newoskrnl: Incorrect data given.\r";
+
+ return false;
}
FileStreamUTF8 file(kUsersFile, "rb");
+ // ------------------------------------------ //
+ // Retrieve token from a specific file fork.
+ // ------------------------------------------ //
+
auto token = file.Read(password);
if (!token)
@@ -96,9 +104,25 @@ namespace Kernel
ErrLocal() = kErrorInvalidCreds;
kcout << "newoskrnl: Incorrect credentials.\r";
- return;
+ return false;
+ }
+ else
+ {
+ if (rt_string_cmp((Char*)token, const_cast<Char*>(password), rt_string_len(password)))
+ {
+ kcout << "newoskrnl: Incorrect credentials.\r";
+
+ mm_delete_ke_heap(token);
+ return false;
+ }
+
+ kcout << "newoskrnl: Correct credentials, moving on.\r";
}
+ // ------------------------------------------ //
+ // This was successful, continue.
+ // ------------------------------------------ //
+
user->fUserToken = token;
if (fCurrentUser)
@@ -115,6 +139,8 @@ namespace Kernel
fCurrentUser = user;
Kernel::kcout << "newoskrnl: logged in as: " << fCurrentUser->Name().CData() << Kernel::endl;
+
+ return true;
}
Void UserView::LogOff() noexcept