diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2023-12-14 04:39:38 +0100 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2023-12-14 06:24:28 +0100 |
commit | 64f68e96354df3afb9bb563c888793f98ecb5026 (patch) | |
tree | 82a1f3f51902e0a926bae4ae8a84ba1dcf2a145b /src/core/hle/service/hid/controllers/shared_memory_holder.cpp | |
parent | Merge pull request #12342 from FearlessTobi/fix-msvc (diff) | |
download | yuzu-64f68e96354df3afb9bb563c888793f98ecb5026.tar yuzu-64f68e96354df3afb9bb563c888793f98ecb5026.tar.gz yuzu-64f68e96354df3afb9bb563c888793f98ecb5026.tar.bz2 yuzu-64f68e96354df3afb9bb563c888793f98ecb5026.tar.lz yuzu-64f68e96354df3afb9bb563c888793f98ecb5026.tar.xz yuzu-64f68e96354df3afb9bb563c888793f98ecb5026.tar.zst yuzu-64f68e96354df3afb9bb563c888793f98ecb5026.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/service/hid/controllers/shared_memory_holder.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/core/hle/service/hid/controllers/shared_memory_holder.cpp b/src/core/hle/service/hid/controllers/shared_memory_holder.cpp new file mode 100644 index 000000000..223487421 --- /dev/null +++ b/src/core/hle/service/hid/controllers/shared_memory_holder.cpp @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "core/core.h" +#include "core/hle/kernel/k_shared_memory.h" +#include "core/hle/service/hid/controllers/shared_memory_format.h" +#include "core/hle/service/hid/controllers/shared_memory_holder.h" +#include "core/hle/service/hid/errors.h" + +namespace Service::HID { +SharedMemoryHolder::SharedMemoryHolder() {} + +Result SharedMemoryHolder::Initialize(Core::System& system) { + shared_memory = Kernel::KSharedMemory::Create(system.Kernel()); + const Result result = shared_memory->Initialize( + system.DeviceMemory(), nullptr, Kernel::Svc::MemoryPermission::None, + Kernel::Svc::MemoryPermission::Read, sizeof(SharedMemoryFormat)); + if (result.IsError()) { + return result; + } + Kernel::KSharedMemory::Register(system.Kernel(), shared_memory); + + is_created = true; + is_mapped = true; + address = std::construct_at(reinterpret_cast<SharedMemoryFormat*>(shared_memory->GetPointer())); + return ResultSuccess; +} + +void SharedMemoryHolder::Finalize() { + if (address != nullptr) { + shared_memory->Close(); + } + is_created = false; + is_mapped = false; + address = nullptr; +} + +bool SharedMemoryHolder::IsMapped() { + return is_mapped; +} + +SharedMemoryFormat* SharedMemoryHolder::GetAddress() { + return address; +} + +Kernel::KSharedMemory* SharedMemoryHolder::GetHandle() { + return shared_memory; +} +} // namespace Service::HID |