summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Sources
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-01 18:25:14 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-01 18:25:14 +0200
commit86e291120d124dec7244202b1766901a59dfb2e6 (patch)
tree1aa92d3b8a05216941986cf2724ff20ad01b3884 /Kernel/Sources
parentf9579f444b1791d2b73d4d841569728fb203cb29 (diff)
[IMP] newoskrnl: Add symbol for cred_construct_token, reworked
ProcessHeap, new SCI.hxx for SCI and SCM. [IMP] newosldr: Loads the kernel correctly and can launch it, improved erorr handling. [META] newoskrnl, newosldr: Improved code and refactors. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Sources')
-rw-r--r--Kernel/Sources/ProcessHeap.cxx26
-rw-r--r--Kernel/Sources/ThreadLocalStorage.cxx23
-rw-r--r--Kernel/Sources/User.cxx17
-rw-r--r--Kernel/Sources/Utils.cxx4
4 files changed, 51 insertions, 19 deletions
diff --git a/Kernel/Sources/ProcessHeap.cxx b/Kernel/Sources/ProcessHeap.cxx
index 414cd934..fe54be4b 100644
--- a/Kernel/Sources/ProcessHeap.cxx
+++ b/Kernel/Sources/ProcessHeap.cxx
@@ -92,19 +92,35 @@ namespace Kernel
/// @return VoidPtr the heap pointer.
STATIC VoidPtr ke_find_unused_heap(Int32 flags)
{
- for (SizeT index = 0; index < kUserHeapMaxSz; ++index)
+ SizeT index = 0UL;
+
+ while (true)
{
+ /* ************************************ */
+ /* allocate if it doesnt exist. */
+ /* ************************************ */
+ if (!ProcessHeapHelper::The()[index])
+ {
+ ProcessHeapHelper::The().Add(Kernel::Ref<Kernel::PTEWrapper>());
+ }
+
if (ProcessHeapHelper::The()[index] &&
!ProcessHeapHelper::The()[index].Leak().Leak().Present())
{
ProcessHeapHelper::Leak().Leak().TogglePresent(
ProcessHeapHelper::The()[index].Leak().Leak(), true);
+
+ ProcessHeapHelper::Leak().Leak().ToggleUser(
+ ProcessHeapHelper::The()[index].Leak().Leak(), true);
+
kcout << "[ke_find_unused_heap] Done, trying to make a pool now...\r";
return ke_make_heap_internal(
(VoidPtr)ProcessHeapHelper::The()[index].Leak().Leak().VirtualAddress(),
flags);
}
+
+ ++index;
}
return nullptr;
@@ -131,7 +147,8 @@ namespace Kernel
poolHdr->fMagic = kUserHeapMag;
poolHdr->fFree = false;
- kcout << "[ke_make_heap_internal] New allocation has been done.\n";
+ kcout << "[ke_make_heap_internal] New allocation has been done, returning new chunk.\n";
+
return reinterpret_cast<VoidPtr>(
(reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(PROCESS_HEAP_HEADER)));
}
@@ -204,9 +221,6 @@ namespace Kernel
if (!ProcessHeapHelper::IsEnabled())
return nullptr;
- if (ProcessHeapHelper::Count() > kUserHeapMaxSz)
- return nullptr;
-
if (VoidPtr ret = ke_find_unused_heap(flags))
return ret;
@@ -245,7 +259,7 @@ namespace Kernel
if (ke_check_and_free_heap(base, ptr))
return 0;
- for (SizeT index = 0; index < kUserHeapMaxSz; ++index)
+ for (SizeT index = 0; index < ProcessHeapHelper::The().Count(); ++index)
{
if (ke_check_and_free_heap(index, ptr))
return 0;
diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx
index 245ffa1c..aac6f9ce 100644
--- a/Kernel/Sources/ThreadLocalStorage.cxx
+++ b/Kernel/Sources/ThreadLocalStorage.cxx
@@ -24,20 +24,20 @@ using namespace Kernel;
Kernel::Property cTLSEnforceCheck;
/**
- * @brief Check for cookie inside TIB.
+ * @brief Checks for cookie inside the TIB.
* @param tib the TIB to check.
* @return if the cookie is enabled.
*/
-Boolean tls_check_tib(ThreadInformationBlock* tib)
+Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib)
{
- if (!tib)
+ if (!the_tib)
return false;
Encoder encoder;
- const char* tibAsBytes = encoder.AsBytes(tib);
+ const char* tibAsBytes = encoder.AsBytes(the_tib);
- kcout << "newoskrnl: checking for a valid cookie...\r";
+ kcout << "newoskrnl: checking for a valid cookie inside the TIB...\r";
return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 &&
tibAsBytes[2] == kCookieMag2;
@@ -48,28 +48,29 @@ Boolean tls_check_tib(ThreadInformationBlock* tib)
* @param stackPtr The call frame.
* @return
*/
-EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept
+EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept
{
if (!tib_ptr)
{
if (cTLSEnforceCheck.GetValue() == No)
{
- return;
+ return true;
}
else
{
- kcout << "newoskrnl: crashing because of an invalid TIB...\r";
- ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
+ kcout << "newoskrnl: failing because of an invalid TIB...\r";
+ return false;
}
}
- ThreadInformationBlock* tib_struct = (ThreadInformationBlock*)tib_ptr;
+ THREAD_INFORMATION_BLOCK* tib_struct = (THREAD_INFORMATION_BLOCK*)tib_ptr;
if (!tls_check_tib(tib_struct))
{
kcout << "newoskrnl: crashing because of an invalid TIB...\r";
- ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
+ return false;
}
kcout << "newoskrnl: Verification succeeded! staying alive...\r";
+ return true;
}
diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx
index e546dd81..40723f27 100644
--- a/Kernel/Sources/User.cxx
+++ b/Kernel/Sources/User.cxx
@@ -17,10 +17,21 @@
#include <KernelKit/Heap.hxx>
-/// bugs 0
+/// BUGS: 0
namespace Kernel
{
+ namespace Detail
+ {
+ /// \brief Constructs a token by hashing the password.
+ /// \param password password to hash.
+ /// \return the hashed password
+ const Char* cred_construct_token(const Char* password)
+ {
+ return nullptr;
+ }
+ }
+
User::User(const Int32& sel, const Char* userName)
: fRing((RingKind)sel)
{
@@ -108,7 +119,9 @@ namespace Kernel
}
else
{
- if (rt_string_cmp((Char*)token, const_cast<Char*>(password), rt_string_len(password)))
+ auto tok = Detail::cred_construct_token(password);
+
+ if (rt_string_cmp((Char*)token, tok, rt_string_len(tok)))
{
kcout << "newoskrnl: Incorrect credentials.\r";
diff --git a/Kernel/Sources/Utils.cxx b/Kernel/Sources/Utils.cxx
index 152f28fa..2132e80d 100644
--- a/Kernel/Sources/Utils.cxx
+++ b/Kernel/Sources/Utils.cxx
@@ -11,6 +11,10 @@ namespace Kernel
{
Int rt_string_cmp(const Char* src, const Char* cmp, Size size)
{
+ if (!cmp ||
+ !src)
+ return 1;
+
Int32 counter = 0;
for (Size index = 0; index < size; ++index)