From 196f8dff084b7229982af214617d55ca084dfed2 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 7 Feb 2018 21:53:31 -0500 Subject: [PATCH] nvmap: Refactor to expose nvmap objects. --- src/core/hle/service/nvdrv/devices/nvmap.cpp | 27 ++++++++------------ src/core/hle/service/nvdrv/devices/nvmap.h | 14 +++++++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp index cb3692689..02b33374a 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.cpp +++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp @@ -13,10 +13,8 @@ namespace Nvidia { namespace Devices { VAddr nvmap::GetObjectAddress(u32 handle) const { - auto itr = handles.find(handle); - ASSERT(itr != handles.end()); - - auto object = itr->second; + auto object = GetObject(handle); + ASSERT(object); ASSERT(object->status == Object::Status::Allocated); return object->addr; } @@ -52,7 +50,7 @@ u32 nvmap::IocCreate(const std::vector& input, std::vector& output) { u32 handle = next_handle++; handles[handle] = std::move(object); - LOG_WARNING(Service_NVDRV, "(STUBBED) size 0x%08X", params.size); + LOG_DEBUG(Service_NVDRV, "size=0x%08X", params.size); params.handle = handle; @@ -64,17 +62,16 @@ u32 nvmap::IocAlloc(const std::vector& input, std::vector& output) { IocAllocParams params; std::memcpy(¶ms, input.data(), sizeof(params)); - auto itr = handles.find(params.handle); - ASSERT(itr != handles.end()); + auto object = GetObject(params.handle); + ASSERT(object); - auto object = itr->second; object->flags = params.flags; object->align = params.align; object->kind = params.kind; object->addr = params.addr; object->status = Object::Status::Allocated; - LOG_WARNING(Service_NVDRV, "(STUBBED) Allocated address 0x%llx", params.addr); + LOG_DEBUG(Service_NVDRV, "called, addr=0x%llx", params.addr); std::memcpy(output.data(), ¶ms, sizeof(params)); return 0; @@ -86,10 +83,10 @@ u32 nvmap::IocGetId(const std::vector& input, std::vector& output) { LOG_WARNING(Service_NVDRV, "called"); - auto itr = handles.find(params.handle); - ASSERT(itr != handles.end()); + auto object = GetObject(params.handle); + ASSERT(object); - params.id = itr->second->id; + params.id = object->id; std::memcpy(output.data(), ¶ms, sizeof(params)); return 0; @@ -123,10 +120,8 @@ u32 nvmap::IocParam(const std::vector& input, std::vector& output) { LOG_WARNING(Service_NVDRV, "(STUBBED) called type=%u", params.type); - auto itr = handles.find(params.handle); - ASSERT(itr != handles.end()); - - auto object = itr->second; + auto object = GetObject(params.handle); + ASSERT(object); ASSERT(object->status == Object::Status::Allocated); switch (static_cast(params.type)) { diff --git a/src/core/hle/service/nvdrv/devices/nvmap.h b/src/core/hle/service/nvdrv/devices/nvmap.h index 1591ac8ff..4681e438b 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.h +++ b/src/core/hle/service/nvdrv/devices/nvmap.h @@ -26,8 +26,7 @@ public: u32 ioctl(Ioctl command, const std::vector& input, std::vector& output) override; -private: - // Represents an nvmap object. + /// Represents an nvmap object. struct Object { enum class Status { Created, Allocated }; u32 id; @@ -39,10 +38,19 @@ private: Status status; }; + std::shared_ptr GetObject(u32 handle) const { + auto itr = handles.find(handle); + if (itr != handles.end()) { + return itr->second; + } + return {}; + } + +private: /// Id to use for the next handle that is created. u32 next_handle = 1; - // Id to use for the next object that is created. + /// Id to use for the next object that is created. u32 next_id = 1; /// Mapping of currently allocated handles to the objects they represent.