diff options
| -rw-r--r-- | Private/KernelKit/SMPManager.hpp | 2 | ||||
| -rw-r--r-- | Private/KernelKit/ThreadLocalStorage.hxx | 6 | ||||
| -rw-r--r-- | Private/Source/ProcessManager.cxx | 10 | ||||
| -rw-r--r-- | Private/Source/SMPManager.cxx | 23 | ||||
| -rw-r--r-- | Private/Source/ThreadLocalStorage.cxx | 17 |
5 files changed, 43 insertions, 15 deletions
diff --git a/Private/KernelKit/SMPManager.hpp b/Private/KernelKit/SMPManager.hpp index 61e9ac3f..f4317cc3 100644 --- a/Private/KernelKit/SMPManager.hpp +++ b/Private/KernelKit/SMPManager.hpp @@ -91,7 +91,7 @@ namespace hCore public: bool Switch(HAL::StackFrame* the); - HAL::StackFramePtr GetStack() noexcept; + HAL::StackFramePtr GetStackFrame() noexcept; public: Ref<ProcessorCore> operator[](const SizeT& idx); diff --git a/Private/KernelKit/ThreadLocalStorage.hxx b/Private/KernelKit/ThreadLocalStorage.hxx index 8b3f2c9b..afd0afb3 100644 --- a/Private/KernelKit/ThreadLocalStorage.hxx +++ b/Private/KernelKit/ThreadLocalStorage.hxx @@ -14,9 +14,9 @@ //! @brief TLS implementation in C++ -#define kRTLMag0 'h' -#define kRTLMag1 'C' -#define kRTLMag2 'o' +#define kCookieMag0 'h' +#define kCookieMag1 'C' +#define kCookieMag2 'o' template <typename T> T* hcore_tls_new_ptr(void); diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index 91c1006d..f37badee 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -50,7 +50,7 @@ namespace hCore return ptr; } - //! TODO: Disk to RAM allocation + //! TODO: Disk allocation return nullptr; } @@ -66,18 +66,18 @@ namespace hCore if (&_pool[index] > &_pool_ptr[sz]) continue; - if (_pool[index] != _pool_ptr[index]) - return false; + if (_pool[index] == _pool_ptr[index]) + return true; } - return true; + return false; } /* @brief free pointer from usage. */ Boolean Process::Delete(VoidPtr ptr, const SizeT& sz) { if (sz < 1 || - this->PoolCursor == this->Pool) + this->PoolCursor == this->Pool) return false; if (rt_in_pool_region(ptr, this->PoolCursor, this->UsedMemory)) diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx index 1c73cb82..4897165b 100644 --- a/Private/Source/SMPManager.cxx +++ b/Private/Source/SMPManager.cxx @@ -82,13 +82,15 @@ namespace hCore ///! @brief Default destructor. SMPManager::~SMPManager() = default; + /// @brief Shared singleton function Ref<SMPManager> SMPManager::Shared() { static SMPManager manager; return { manager }; } - HAL::StackFramePtr SMPManager::GetStack() noexcept + /// @brief Get Stack Frame of Core + HAL::StackFramePtr SMPManager::GetStackFrame() noexcept { if (m_ThreadList[m_CurrentThread].Leak() && ProcessHelper::GetCurrentPID() == m_ThreadList[m_CurrentThread].Leak().Leak().m_PID) @@ -97,7 +99,7 @@ namespace hCore return nullptr; } - // @brief Finds and switch to a free core. + /// @brief Finds and switch to a free core. bool SMPManager::Switch(HAL::StackFrame* stack) { if (stack == nullptr) @@ -108,7 +110,7 @@ namespace hCore // stack != nullptr -> if core is used, then continue. if (!m_ThreadList[idx].Leak() || !m_ThreadList[idx].Leak().Leak().IsWakeup() || - !m_ThreadList[idx].Leak().Leak().IsBusy()) + m_ThreadList[idx].Leak().Leak().IsBusy()) continue; m_ThreadList[idx].Leak().Leak().m_ID = idx; @@ -117,7 +119,7 @@ namespace hCore m_ThreadList[idx].Leak().Leak().Busy(true); - bool ret = rt_do_context_switch(rt_get_current_context(), stack) == 0; + Boolean ret = (rt_do_context_switch(rt_get_current_context(), stack) == 0); m_ThreadList[idx].Leak().Leak().Busy(false); @@ -127,9 +129,22 @@ namespace hCore return false; } + /** + * Index hart + * @param idx + * @return + */ Ref<ProcessorCore> SMPManager::operator[](const SizeT& idx) { return m_ThreadList[idx].Leak(); } + /** + * Check if thread pool isn't empty. + * @return + */ SMPManager::operator bool() noexcept { return !m_ThreadList.Empty(); } + /** + * Reverse operator bool + * @return + */ bool SMPManager::operator!() noexcept { return m_ThreadList.Empty(); } } // namespace hCore diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx index 5d231f61..bcafdd10 100644 --- a/Private/Source/ThreadLocalStorage.cxx +++ b/Private/Source/ThreadLocalStorage.cxx @@ -12,15 +12,28 @@ using namespace hCore; +/** + * Check for cookie inside TIB. + * @param ptr + * @return if the cookie is enabled. + */ Boolean hcore_tls_check(VoidPtr ptr) { if (!ptr) return false; - const char *_ptr = (const char *)ptr; - return _ptr[0] == kRTLMag0 && _ptr[1] == kRTLMag1 && _ptr[2] == kRTLMag2; + const char* _ptr = (const char*)ptr; + + kcout << "TLS: Check for cookie...\n"; + + return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 && _ptr[2] == kCookieMag2; } +/** + * System call implementation in hCore + * @param ptr + * @return + */ Void hcore_tls_check_syscall_impl(ThreadInformationBlock ptr) noexcept { if (!hcore_tls_check(ptr.Cookie)) |
