diff options
Diffstat (limited to 'Kernel/Sources')
| -rw-r--r-- | Kernel/Sources/Heap.cxx (renamed from Kernel/Sources/KernelHeap.cxx) | 2 | ||||
| -rw-r--r-- | Kernel/Sources/Main.cxx (renamed from Kernel/Sources/KeMain.cxx) | 23 | ||||
| -rw-r--r-- | Kernel/Sources/New+Delete.cxx | 2 | ||||
| -rw-r--r-- | Kernel/Sources/NewFS+FileManager.cxx | 2 | ||||
| -rw-r--r-- | Kernel/Sources/PEFCodeManager.cxx | 2 | ||||
| -rw-r--r-- | Kernel/Sources/ProcessScheduler.cxx | 43 | ||||
| -rw-r--r-- | Kernel/Sources/Property.cxx | 16 | ||||
| -rw-r--r-- | Kernel/Sources/String.cxx | 29 | ||||
| -rw-r--r-- | Kernel/Sources/ThreadLocalStorage.cxx | 30 | ||||
| -rw-r--r-- | Kernel/Sources/Utils.cxx | 7 |
10 files changed, 83 insertions, 73 deletions
diff --git a/Kernel/Sources/KernelHeap.cxx b/Kernel/Sources/Heap.cxx index 510584dd..6ac91448 100644 --- a/Kernel/Sources/KernelHeap.cxx +++ b/Kernel/Sources/Heap.cxx @@ -6,7 +6,7 @@ #include <KernelKit/DebugOutput.hpp> #include <KernelKit/HError.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <NewKit/Crc32.hpp> #include <NewKit/PageManager.hpp> diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/Main.cxx index c06325ba..8c80d70c 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/Main.cxx @@ -2,18 +2,19 @@ Copyright ZKA Technologies - File: KeMain.cxx - Purpose: Kernel main loop. + File: Main.cxx + Purpose: Main entrypoint of kernel. ------------------------------------------- */ +#include "KernelKit/DebugOutput.hpp" #include <ArchKit/ArchKit.hpp> #include <Modules/CoreCG/CoreCG.hxx> #include <CompilerKit/Detail.hxx> #include <FirmwareKit/Handover.hxx> #include <KernelKit/FileManager.hpp> #include <KernelKit/Framebuffer.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <KernelKit/PEF.hpp> #include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessScheduler.hxx> @@ -23,6 +24,9 @@ #include <NewKit/String.hpp> #include <NewKit/Utils.hpp> #include <KernelKit/CodeManager.hpp> +#include <CFKit/Property.hpp> + +EXTERN Kernel::Property cKernelVersion; namespace Kernel::Detail { @@ -39,7 +43,7 @@ namespace Kernel::Detail { /// Mounted partition, cool! Kernel::kcout - << "newoskrnl: No need to create for a NewFS partition here...\r"; + << "newoskrnl: No need to create for a NewFS+EPM partition here...\r"; } else { @@ -63,7 +67,7 @@ namespace Kernel::Detail if (catalogDir) { - Kernel::kcout << "newoskrnl: already here.\r"; + Kernel::kcout << "newoskrnl: already exists.\r"; delete catalogDir; continue; @@ -121,11 +125,6 @@ namespace Kernel::Detail if (catalogDisk) { - auto bufferInfoDisk = (Kernel::Char*)this->fNewFS->GetParser()->ReadCatalog(catalogDisk, kNewFSSectorSz, cSrcName); - Kernel::kcout << bufferInfoDisk; - Kernel::end_line(); - - delete bufferInfoDisk; delete catalogDisk; } else @@ -163,9 +162,6 @@ namespace Kernel::Detail (Kernel::VoidPtr)diskFolder.CData(), kNewFSSectorSz, cSrcName); - Kernel::kcout << diskFolder.CData(); - Kernel::end_line(); - delete catalogDisk; } } @@ -188,6 +184,7 @@ namespace Kernel::Detail /// @return void no return value. STATIC Kernel::Void ke_user_switch(Kernel::Void) { + Kernel::kcout << "newoskrnl: " << cKernelVersion.GetKey().CData() << ": " << Kernel::number(cKernelVersion.GetValue()) << Kernel::endl; } } // namespace Kernel::Detail diff --git a/Kernel/Sources/New+Delete.cxx b/Kernel/Sources/New+Delete.cxx index 32a76769..2921e079 100644 --- a/Kernel/Sources/New+Delete.cxx +++ b/Kernel/Sources/New+Delete.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <NewKit/New.hpp> void* operator new[](size_t sz) diff --git a/Kernel/Sources/NewFS+FileManager.cxx b/Kernel/Sources/NewFS+FileManager.cxx index 3ff675bc..146f721d 100644 --- a/Kernel/Sources/NewFS+FileManager.cxx +++ b/Kernel/Sources/NewFS+FileManager.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <KernelKit/FileManager.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #ifdef __FSKIT_USE_NEWFS__ diff --git a/Kernel/Sources/PEFCodeManager.cxx b/Kernel/Sources/PEFCodeManager.cxx index a39dc158..8b1918ef 100644 --- a/Kernel/Sources/PEFCodeManager.cxx +++ b/Kernel/Sources/PEFCodeManager.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <KernelKit/DebugOutput.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessScheduler.hxx> #include <NewKit/Defines.hpp> diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index 42e7285a..a536bf52 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -11,7 +11,7 @@ #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/SMPManager.hpp> -#include <KernelKit/KernelHeap.hpp> +#include <KernelKit/Heap.hxx> #include <NewKit/String.hpp> #include <KernelKit/HError.hpp> @@ -29,14 +29,9 @@ namespace Kernel STATIC Int32 cLastExitCode = 0U; - /// @brief Gets the latest exit code. + /// @brief Gets the last exit code. /// @note Not thread-safe. /// @return Int32 the last exit code. - const Int32& ProcessHeader::GetExitCode() noexcept - { - return fLastExitCode; - } - const Int32& rt_get_exit_code() noexcept { return cLastExitCode; @@ -55,6 +50,14 @@ namespace Kernel this->Exit(kErrorProcessFault); } + /// @brief Gets the local last exit code. + /// @note Not thread-safe. + /// @return Int32 the last exit code. + const Int32& ProcessHeader::GetExitCode() noexcept + { + return this->fLastExitCode; + } + Int32& ProcessHeader::GetLocalCode() noexcept { return fLocalCode; @@ -76,13 +79,13 @@ namespace Kernel { ErrLocal() = kErrorHeapOutOfMemory; - /* we're going out of memory */ + /* We're going out of memory! crash... */ this->Crash(); return nullptr; } - this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor + (sizeof(sz))); + this->HeapCursor = reinterpret_cast<VoidPtr>((UIntPtr)this->HeapCursor + (sizeof(sz))); VoidPtr ptr = this->HeapCursor; ++this->UsedMemory; @@ -97,21 +100,17 @@ namespace Kernel /***********************************************************************************/ /* @brief checks if runtime pointer is in region. */ - bool rt_is_in_pool(VoidPtr pool_ptr, VoidPtr pool, const SizeT& sz) + bool rt_is_in_pool(VoidPtr pool_ptr, VoidPtr pool, const SizeT& pool_ptr_cur_sz, const SizeT& pool_ptr_used_sz) { - UIntPtr* _pool_ptr = (UIntPtr*)pool_ptr; - UIntPtr* _pool = (UIntPtr*)pool; - - for (SizeT index = sz; _pool[sz] != kUserHeapMag; --index) - { - if (&_pool[index] > &_pool_ptr[sz]) - continue; + if (pool == nullptr || + pool_ptr == nullptr) + return false; - if (_pool[index] == _pool_ptr[index]) - return true; - } + UIntPtr* uint_pool_ptr = (UIntPtr*)pool_ptr; + UIntPtr* uint_pool = (UIntPtr*)pool; - return false; + return (UIntPtr)&uint_pool > (UIntPtr)&uint_pool_ptr && + pool_ptr_cur_sz > pool_ptr_used_sz; } /* @brief free pointer from usage. */ @@ -124,7 +123,7 @@ namespace Kernel if (this->UsedMemory < 1) return false; - if (rt_is_in_pool(ptr, this->HeapCursor, this->UsedMemory)) + if (rt_is_in_pool(ptr, this->HeapCursor, this->UsedMemory, this->FreeMemory)) { this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor - (sizeof(sz))); rt_zero_memory(ptr, sz); diff --git a/Kernel/Sources/Property.cxx b/Kernel/Sources/Property.cxx index 47969bd5..60bd03da 100644 --- a/Kernel/Sources/Property.cxx +++ b/Kernel/Sources/Property.cxx @@ -8,21 +8,19 @@ namespace Kernel { - Property::Property(const StringView& sw) - : fName(sw) - { - kcout << "newoskrnl: Property created: " << sw.CData(); - endl; - } - Property::~Property() = default; bool Property::StringEquals(StringView& name) { - return fName && this->fName == name; + return this->fName && this->fName == name; + } + + StringView& Property::GetKey() + { + return this->fName; } - const PropertyId& Property::GetPropertyById() + PropertyId& Property::GetValue() { return fAction; } diff --git a/Kernel/Sources/String.cxx b/Kernel/Sources/String.cxx index 2b58d551..2ed52029 100644 --- a/Kernel/Sources/String.cxx +++ b/Kernel/Sources/String.cxx @@ -22,7 +22,7 @@ namespace Kernel Size StringView::Length() const { - return rt_string_len(fData); + return fSz; } bool StringView::operator==(const StringView& rhs) const @@ -214,22 +214,25 @@ namespace Kernel return ret; } - static void string_append(char* lhs, char* rhs, int cur) + STATIC void rt_string_append(Char* lhs, Char* rhs, Int cur) { - if (lhs && rhs) - { - SizeT sz_rhs = rt_string_len(rhs); - - if (sz_rhs == 0) - return; + SizeT sz_rhs = rt_string_len(rhs); + SizeT rhs_i = 0; - rt_copy_memory(rhs, lhs + cur, sz_rhs); + for (; rhs_i < sz_rhs; ++rhs_i) + { + lhs[rhs_i + cur] = rhs[rhs_i]; } + + lhs[rhs_i + cur] = 0; } StringView& StringView::operator+=(const Char* rhs) { - string_append(this->fData, const_cast<char*>(rhs), this->fCur); + if (rt_string_len(rhs) > this->Length()) + return *this; + + rt_string_append(this->fData, const_cast<Char*>(rhs), this->fCur); this->fCur += rt_string_len(rhs); return *this; @@ -237,11 +240,11 @@ namespace Kernel StringView& StringView::operator+=(const StringView& rhs) { - if (rt_string_len(rhs.fData) > rt_string_len(this->fData)) + if (rt_string_len(rhs.fData) > this->Length()) return *this; - string_append(this->fData, const_cast<char*>(rhs.fData), this->fCur); - this->fCur += rt_string_len(const_cast<char*>(rhs.fData)); + rt_string_append(this->fData, const_cast<Char*>(rhs.fData), this->fCur); + this->fCur += rt_string_len(const_cast<Char*>(rhs.fData)); return *this; } diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx index f5fc2d3e..245ffa1c 100644 --- a/Kernel/Sources/ThreadLocalStorage.cxx +++ b/Kernel/Sources/ThreadLocalStorage.cxx @@ -7,6 +7,8 @@ * ======================================================== */ +#include <NewKit/String.hpp> +#include <CFKit/Property.hpp> #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/ThreadLocalStorage.hxx> @@ -14,11 +16,13 @@ /***********************************************************************************/ /// @file ThreadLocalStorage.cxx -/// @brief TLS implementation in kernel. +/// @brief TLS inside the kernel. /***********************************************************************************/ using namespace Kernel; +Kernel::Property cTLSEnforceCheck; + /** * @brief Check for cookie inside TIB. * @param tib the TIB to check. @@ -33,7 +37,7 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) Encoder encoder; const char* tibAsBytes = encoder.AsBytes(tib); - kcout << "newoskrnl: Checking for a valid cookie...\r"; + kcout << "newoskrnl: checking for a valid cookie...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -44,18 +48,28 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) * @param stackPtr The call frame. * @return */ -EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept +EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept { - if (!TIB) - return; + if (!tib_ptr) + { + if (cTLSEnforceCheck.GetValue() == No) + { + return; + } + else + { + kcout << "newoskrnl: crashing because of an invalid TIB...\r"; + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + } + } - ThreadInformationBlock* tib = (ThreadInformationBlock*)TIB; + ThreadInformationBlock* tib_struct = (ThreadInformationBlock*)tib_ptr; - if (!tls_check_tib(tib)) + if (!tls_check_tib(tib_struct)) { kcout << "newoskrnl: crashing because of an invalid TIB...\r"; ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } - kcout << "newoskrnl: Verification succeeded! Keeping on...\r"; + kcout << "newoskrnl: Verification succeeded! staying alive...\r"; } diff --git a/Kernel/Sources/Utils.cxx b/Kernel/Sources/Utils.cxx index b152888b..12e2e2a8 100644 --- a/Kernel/Sources/Utils.cxx +++ b/Kernel/Sources/Utils.cxx @@ -48,15 +48,14 @@ namespace Kernel Size rt_string_len(const Char* ptr) { - if (!ptr) + if (*ptr == 0) return 0; SizeT cnt = 0; - while (*ptr != (Char)0) + while (ptr[cnt] != (Char)0) { - ++ptr; - ++cnt; + cnt++; } return cnt; |
