diff options
author | bunnei <bunneidev@gmail.com> | 2021-04-04 04:11:46 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2021-05-06 01:40:50 +0200 |
commit | da7e9553dea4b1eaefb71aca8642ccce7c7f50fb (patch) | |
tree | 3da10a60005ddcc4237900eb5e7473fe7b006152 /src/core/hle/kernel/handle_table.h | |
parent | hle: kernel: svc: Migrate GetThreadPriority, StartThread, and ExitThread. (diff) | |
download | yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.tar yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.tar.gz yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.tar.bz2 yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.tar.lz yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.tar.xz yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.tar.zst yuzu-da7e9553dea4b1eaefb71aca8642ccce7c7f50fb.zip |
Diffstat (limited to 'src/core/hle/kernel/handle_table.h')
-rw-r--r-- | src/core/hle/kernel/handle_table.h | 40 |
1 files changed, 39 insertions, 1 deletions
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 <memory> #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<T>(GetGeneric(handle)); } + template <typename T = KAutoObject> + KScopedAutoObject<T> GetObject(Handle handle) const { + if (handle == CurrentThread) { + return kernel.CurrentScheduler()->GetCurrentThread()->DynamicCast<T*>(); + } else if (handle == CurrentProcess) { + return kernel.CurrentProcess()->DynamicCast<T*>(); + } + + if (!IsValid(handle)) { + return nullptr; + } + + auto* obj = objects_new[static_cast<u16>(handle >> 15)]; + return obj->DynamicCast<T*>(); + } + + template <typename T = KAutoObject> + KScopedAutoObject<T> GetObjectWithoutPseudoHandle(Handle handle) const { + if (!IsValid(handle)) { + return nullptr; + } + auto* obj = objects_new[static_cast<u16>(handle >> 15)]; + return obj->DynamicCast<T*>(); + } + /// Closes all handles held in this table. void Clear(); + // NEW IMPL + + template <typename T> + ResultCode Add(Handle* out_handle, T* obj) { + static_assert(std::is_base_of<KAutoObject, T>::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<std::shared_ptr<Object>, MAX_COUNT> objects; + std::array<KAutoObject*, MAX_COUNT> objects_new{}; /** * The value of `next_generation` when the handle was created, used to check for validity. For |