diff options
author | Liam <byteslice@airmail.cc> | 2023-02-17 05:16:08 +0100 |
---|---|---|
committer | Liam <byteslice@airmail.cc> | 2023-02-17 15:16:05 +0100 |
commit | 1773a1039f7422df4faac08aa366b6a6bbd645e4 (patch) | |
tree | 9560360871f1fcd6c12df2e77452cf37658309d3 /src/core/hle/kernel/k_object_name.h | |
parent | Merge pull request #9802 from Kelebek1/wait_data_cache (diff) | |
download | yuzu-1773a1039f7422df4faac08aa366b6a6bbd645e4.tar yuzu-1773a1039f7422df4faac08aa366b6a6bbd645e4.tar.gz yuzu-1773a1039f7422df4faac08aa366b6a6bbd645e4.tar.bz2 yuzu-1773a1039f7422df4faac08aa366b6a6bbd645e4.tar.lz yuzu-1773a1039f7422df4faac08aa366b6a6bbd645e4.tar.xz yuzu-1773a1039f7422df4faac08aa366b6a6bbd645e4.tar.zst yuzu-1773a1039f7422df4faac08aa366b6a6bbd645e4.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/k_object_name.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_object_name.h b/src/core/hle/kernel/k_object_name.h new file mode 100644 index 000000000..b7f943134 --- /dev/null +++ b/src/core/hle/kernel/k_object_name.h @@ -0,0 +1,86 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <array> +#include <memory> +#include <boost/intrusive/list.hpp> + +#include "core/hle/kernel/k_light_lock.h" +#include "core/hle/kernel/slab_helpers.h" +#include "core/hle/kernel/svc_results.h" + +namespace Kernel { + +class KObjectNameGlobalData; + +class KObjectName : public KSlabAllocated<KObjectName>, public boost::intrusive::list_base_hook<> { +public: + explicit KObjectName(KernelCore&) {} + virtual ~KObjectName() = default; + + static constexpr size_t NameLengthMax = 12; + using List = boost::intrusive::list<KObjectName>; + + static Result NewFromName(KernelCore& kernel, KAutoObject* obj, const char* name); + static Result Delete(KernelCore& kernel, KAutoObject* obj, const char* name); + + static KScopedAutoObject<KAutoObject> Find(KernelCore& kernel, const char* name); + + template <typename Derived> + static Result Delete(KernelCore& kernel, const char* name) { + // Find the object. + KScopedAutoObject obj = Find(kernel, name); + R_UNLESS(obj.IsNotNull(), ResultNotFound); + + // Cast the object to the desired type. + Derived* derived = obj->DynamicCast<Derived*>(); + R_UNLESS(derived != nullptr, ResultNotFound); + + // Check that the object is closed. + R_UNLESS(derived->IsServerClosed(), ResultInvalidState); + + return Delete(kernel, obj.GetPointerUnsafe(), name); + } + + template <typename Derived> + requires(std::derived_from<Derived, KAutoObject>) + static KScopedAutoObject<Derived> Find(KernelCore& kernel, const char* name) { + return Find(kernel, name); + } + +private: + static KScopedAutoObject<KAutoObject> FindImpl(KernelCore& kernel, const char* name); + + void Initialize(KAutoObject* obj, const char* name); + + bool MatchesName(const char* name) const; + KAutoObject* GetObject() const { + return m_object; + } + +private: + std::array<char, NameLengthMax> m_name{}; + KAutoObject* m_object{}; +}; + +class KObjectNameGlobalData { +public: + explicit KObjectNameGlobalData(KernelCore& kernel); + ~KObjectNameGlobalData(); + + KLightLock& GetObjectListLock() { + return m_object_list_lock; + } + + KObjectName::List& GetObjectList() { + return m_object_list; + } + +private: + KLightLock m_object_list_lock; + KObjectName::List m_object_list; +}; + +} // namespace Kernel |