diff --git a/mesosphere/include/mesosphere/interrupts/KInterruptBottomHalfGuard.hpp b/mesosphere/include/mesosphere/interrupts/KInterruptBottomHalfGuard.hpp new file mode 100644 index 000000000..fd16e1158 --- /dev/null +++ b/mesosphere/include/mesosphere/interrupts/KInterruptBottomHalfGuard.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include + +namespace mesosphere +{ + +class KThread; +inline void IncrementThreadInterruptBottomHalfLockCount(KThread &thread); +inline void DecrementThreadInterruptBottomHalfLockCount(KThread &thread); + +class KInterruptBottomHalfGuard final { + public: + KInterruptBottomHalfGuard() + { + KThread *curThread = KCoreContext::GetCurrentInstance().GetCurrentThread(); + IncrementInterruptBottomHalfLockCount(*curThread); + } + + ~KInterruptBottomHalfGuard() + { + KThread *curThread = KCoreContext::GetCurrentInstance().GetCurrentThread(); + DecrementInterruptBottomHalfLockCount(*curThread); + } + + KInterruptBottomHalfGuard(const KInterruptBottomHalfGuard &) = delete; + KInterruptBottomHalfGuard(KInterruptBottomHalfGuard &&) = delete; + KInterruptBottomHalfGuard &operator=(const KInterruptBottomHalfGuard &) = delete; + KInterruptBottomHalfGuard &operator=(KInterruptBottomHalfGuard &&) = delete; +}; + +} \ No newline at end of file diff --git a/mesosphere/include/mesosphere/threading/KThread.hpp b/mesosphere/include/mesosphere/threading/KThread.hpp index bd58619b5..e335ceedd 100644 --- a/mesosphere/include/mesosphere/threading/KThread.hpp +++ b/mesosphere/include/mesosphere/threading/KThread.hpp @@ -33,7 +33,7 @@ class KThread final : MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Thread); MESOSPHERE_LIMITED_RESOURCE_TRAITS(100ms); - class StackParameters { + class StackParameters final { public: StackParameters(std::array svcPermissionMask, KThreadContext *threadCtx) : svcPermissionMask{svcPermissionMask}, threadCtx{threadCtx} {} @@ -46,19 +46,19 @@ class KThread final : constexpr bool IsExecutingSvc() const { return isExecutingSvc; } constexpr u8 GetCurrentSvcId() const { return currentSvcId; } - constexpr uint GetBottomHalfLockCount() const { return bottomHalfLockCount; } - void IncrementBottomHalfLockCount() { ++bottomHalfLockCount; } - void DecrementBottomHalfLockCount() { --bottomHalfLockCount; } + constexpr uint GetInterruptBottomHalfLockCount() const { return interruptBottomHalfLockCount; } + void IncrementInterruptBottomHalfLockCount() { ++interruptBottomHalfLockCount; } + void DecrementInterruptBottomHalfLockCount() { --interruptBottomHalfLockCount; } 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; + uint interruptBottomHalfLockCount = 1; KThreadContext *threadCtx = nullptr; }; @@ -265,6 +265,15 @@ class KThread final : KThread(KProcess *owner, u64 id, uint priority) : KAutoObject(), owner(owner), schedulerNodes(), id(id), basePriority(priority), priority(priority), currentCoreId(0), affinityMask(15) {}; + + friend void IncrementThreadInterruptBottomHalfLockCount(KThread &thread) + { + thread.GetStackParameters().IncrementInterruptBottomHalfLockCount(); + } + friend void DecrementThreadInterruptBottomHalfLockCount(KThread &thread) + { + thread.GetStackParameters().DecrementInterruptBottomHalfLockCount(); + } private: Result WaitSynchronizationImpl(int &outId, KSynchronizationObject **syncObjs, int numSyncObjs, const KSystemClock::time_point &timeoutTime); diff --git a/mesosphere/source/core/KSynchronizationObject.cpp b/mesosphere/source/core/KSynchronizationObject.cpp index c8a179493..c58cb992e 100644 --- a/mesosphere/source/core/KSynchronizationObject.cpp +++ b/mesosphere/source/core/KSynchronizationObject.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include diff --git a/mesosphere/source/interrupts/KAlarm.cpp b/mesosphere/source/interrupts/KAlarm.cpp index 63b6990a3..14f1d13d6 100644 --- a/mesosphere/source/interrupts/KAlarm.cpp +++ b/mesosphere/source/interrupts/KAlarm.cpp @@ -1,5 +1,4 @@ #include -#include #include #include diff --git a/mesosphere/source/processes/KEvent.cpp b/mesosphere/source/processes/KEvent.cpp index ade62a12f..251459037 100644 --- a/mesosphere/source/processes/KEvent.cpp +++ b/mesosphere/source/processes/KEvent.cpp @@ -1,5 +1,4 @@ #include -#include #include namespace mesosphere diff --git a/mesosphere/source/processes/KHandleTable.cpp b/mesosphere/source/processes/KHandleTable.cpp index 8ab203dec..a31e1a693 100644 --- a/mesosphere/source/processes/KHandleTable.cpp +++ b/mesosphere/source/processes/KHandleTable.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include namespace mesosphere diff --git a/mesosphere/source/threading/KThread.cpp b/mesosphere/source/threading/KThread.cpp index 7e2a5d1af..856d90ae9 100644 --- a/mesosphere/source/threading/KThread.cpp +++ b/mesosphere/source/threading/KThread.cpp @@ -4,7 +4,6 @@ #include #include -#include namespace mesosphere {