From da7e9553dea4b1eaefb71aca8642ccce7c7f50fb Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 3 Apr 2021 19:11:46 -0700 Subject: hle: kernel: Migrate more of KThread to KAutoObject. --- src/core/hle/kernel/handle_table.h | 40 +++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/core/hle/kernel/handle_table.h') diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h index c9dab8cdd..555fb20e5 100644 --- a/src/core/hle/kernel/handle_table.h +++ b/src/core/hle/kernel/handle_table.h @@ -9,6 +9,8 @@ #include #include "common/common_types.h" +#include "core/hle/kernel/k_auto_object.h" +#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/object.h" #include "core/hle/result.h" @@ -87,7 +89,7 @@ public: * @return `RESULT_SUCCESS` or one of the following errors: * - `ERR_INVALID_HANDLE`: an invalid handle was passed in. */ - ResultCode Close(Handle handle); + bool Remove(Handle handle); /// Checks if a handle is valid and points to an existing object. bool IsValid(Handle handle) const; @@ -108,12 +110,48 @@ public: return DynamicObjectCast(GetGeneric(handle)); } + template + KScopedAutoObject GetObject(Handle handle) const { + if (handle == CurrentThread) { + return kernel.CurrentScheduler()->GetCurrentThread()->DynamicCast(); + } else if (handle == CurrentProcess) { + return kernel.CurrentProcess()->DynamicCast(); + } + + if (!IsValid(handle)) { + return nullptr; + } + + auto* obj = objects_new[static_cast(handle >> 15)]; + return obj->DynamicCast(); + } + + template + KScopedAutoObject GetObjectWithoutPseudoHandle(Handle handle) const { + if (!IsValid(handle)) { + return nullptr; + } + auto* obj = objects_new[static_cast(handle >> 15)]; + return obj->DynamicCast(); + } + /// Closes all handles held in this table. void Clear(); + // NEW IMPL + + template + ResultCode Add(Handle* out_handle, T* obj) { + static_assert(std::is_base_of::value); + return this->Add(out_handle, obj, obj->GetTypeObj().GetClassToken()); + } + + ResultCode Add(Handle* out_handle, KAutoObject* obj, u16 type); + private: /// Stores the Object referenced by the handle or null if the slot is empty. std::array, MAX_COUNT> objects; + std::array objects_new{}; /** * The value of `next_generation` when the handle was created, used to check for validity. For -- cgit v1.2.3