diff --git a/mesosphere/include/mesosphere/threading/KThread.hpp b/mesosphere/include/mesosphere/threading/KThread.hpp index 293adfbf0..8575e4d5b 100644 --- a/mesosphere/include/mesosphere/threading/KThread.hpp +++ b/mesosphere/include/mesosphere/threading/KThread.hpp @@ -13,6 +13,8 @@ namespace mesosphere { +struct KThreadContext; + struct ThreadWaitListTag; struct ThreadMutexWaitListTag; using ThreadWaitListBaseHook = boost::intrusive::list_base_hook >; @@ -29,9 +31,35 @@ class KThread final : public: MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Thread); - virtual bool IsAlive() const override; - virtual void OnAlarm() override; + class StackParameters { + public: + StackParameters(std::array svcPermissionMask, KThreadContext *threadCtx) : + svcPermissionMask{svcPermissionMask}, threadCtx{threadCtx} {} + + void Initialize(std::array svcPermissionMask, KThreadContext *threadCtx) + { + *this = StackParameters{svcPermissionMask, threadCtx}; + } + + constexpr bool IsExecutingSvc() const { return isExecutingSvc; } + constexpr u8 GetCurrentSvcId() const { return currentSvcId; } + + constexpr uint GetBottomHalfLockCount() const { return bottomHalfLockCount; } + void IncrementBottomHalfLockCount() { ++bottomHalfLockCount; } + void DecrementBottomHalfLockCount() { --bottomHalfLockCount; } + + KThreadContext *GetThreadContext() const { return threadCtx; } + + private: + std::array svcPermissionMask[256/64]{}; + u8 stateFlags = 0; + u8 currentSvcId = 0; + bool isExecutingSvc = false; + bool isNotStarted = true; + uint bottomHalfLockCount = 1; + KThreadContext *threadCtx = nullptr; + }; struct SchedulerValueTraits { using node_traits = boost::intrusive::list_node_traits; @@ -94,6 +122,9 @@ class KThread final : public: + virtual bool IsAlive() const override; + virtual void OnAlarm() override; + static constexpr uint GetPriorityOf(const KThread &thread) { return thread.priority; @@ -105,6 +136,11 @@ class KThread final : constexpr ulong GetAffinityMask() const { return affinityMask; } constexpr long GetLastScheduledTime() const { return lastScheduledTime; } + StackParameters &GetStackParameters() + { + return *(StackParameters *)(kernelStackTop - sizeof(StackParameters)); + } + KProcess *GetOwner() const { return owner; } bool IsSchedulerOperationRedundant() const { return owner != nullptr && owner->GetSchedulerOperationCount() == redundantSchedulerOperationCount; } @@ -256,6 +292,7 @@ private: KThread *wantedMutexOwner = nullptr; MutexWaitList mutexWaitList{}; size_t numKernelMutexWaiters = 0; + uiptr kernelStackTop = 0; KSynchronizationObject *signaledSyncObject = nullptr; Result syncResult = ResultSuccess{};