From 68d9504a046f40ce4ada54b0eba7228e659970de Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Fri, 5 Nov 2021 02:11:46 +0100 Subject: [PATCH] NVMAP: Fix the Free return parameters. --- src/core/hle/service/nvdrv/core/nvmap.cpp | 4 ++- src/core/hle/service/nvdrv/core/nvmap.h | 1 + src/core/hle/service/nvdrv/devices/nvmap.cpp | 28 ++++++++++---------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/core/hle/service/nvdrv/core/nvmap.cpp b/src/core/hle/service/nvdrv/core/nvmap.cpp index 281381cc41..1126daeb5e 100644 --- a/src/core/hle/service/nvdrv/core/nvmap.cpp +++ b/src/core/hle/service/nvdrv/core/nvmap.cpp @@ -11,7 +11,9 @@ using Core::Memory::YUZU_PAGESIZE; namespace Service::Nvidia::NvCore { -NvMap::Handle::Handle(u64 size, Id id) : size(size), aligned_size(size), orig_size(size), id(id) {} +NvMap::Handle::Handle(u64 size, Id id) : size(size), aligned_size(size), orig_size(size), id(id) { + flags.raw = 0; +} NvResult NvMap::Handle::Alloc(Flags pFlags, u32 pAlign, u8 pKind, u64 pAddress) { std::scoped_lock lock(mutex); diff --git a/src/core/hle/service/nvdrv/core/nvmap.h b/src/core/hle/service/nvdrv/core/nvmap.h index 994c70e6fa..5e6c73589a 100644 --- a/src/core/hle/service/nvdrv/core/nvmap.h +++ b/src/core/hle/service/nvdrv/core/nvmap.h @@ -44,6 +44,7 @@ public: std::optional>::iterator> unmap_queue_entry{}; union Flags { + u32 raw; BitField<0, 1, u32> map_uncached; //!< If the handle should be mapped as uncached BitField<2, 1, u32> keep_uncached_after_free; //!< Only applicable when the handle was //!< allocated with a fixed address diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp index 2aee68f5cb..57f58055d3 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.cpp +++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp @@ -82,7 +82,7 @@ std::shared_ptr nvmap::GetObject(u32 handle) const { NvResult nvmap::IocCreate(const std::vector& input, std::vector& output) { IocCreateParams params; std::memcpy(¶ms, input.data(), sizeof(params)); - LOG_WARNING(Service_NVDRV, "called, size=0x{:08X}", params.size); + LOG_DEBUG(Service_NVDRV, "called, size=0x{:08X}", params.size); std::shared_ptr handle_description{}; auto result = @@ -102,7 +102,7 @@ NvResult nvmap::IocCreate(const std::vector& input, std::vector& output) NvResult nvmap::IocAlloc(const std::vector& input, std::vector& output) { IocAllocParams params; std::memcpy(¶ms, input.data(), sizeof(params)); - LOG_WARNING(Service_NVDRV, "called, addr={:X}", params.address); + LOG_DEBUG(Service_NVDRV, "called, addr={:X}", params.address); if (!params.handle) { LOG_CRITICAL(Service_NVDRV, "Handle is 0"); @@ -144,7 +144,7 @@ NvResult nvmap::IocGetId(const std::vector& input, std::vector& output) IocGetIdParams params; std::memcpy(¶ms, input.data(), sizeof(params)); - LOG_WARNING(Service_NVDRV, "called"); + LOG_DEBUG(Service_NVDRV, "called"); // See the comment in FromId for extra info on this function if (!params.handle) { @@ -168,26 +168,26 @@ NvResult nvmap::IocFromId(const std::vector& input, std::vector& output) IocFromIdParams params; std::memcpy(¶ms, input.data(), sizeof(params)); - LOG_WARNING(Service_NVDRV, "called, id:{}"); + LOG_DEBUG(Service_NVDRV, "called, id:{}"); // Handles and IDs are always the same value in nvmap however IDs can be used globally given the // right permissions. // Since we don't plan on ever supporting multiprocess we can skip implementing handle refs and // so this function just does simple validation and passes through the handle id. if (!params.id) { - LOG_CRITICAL(Service_NVDRV, "Error!"); + LOG_CRITICAL(Service_NVDRV, "Zero Id is invalid!"); return NvResult::BadValue; } auto handle_description{file.GetHandle(params.id)}; if (!handle_description) { - LOG_CRITICAL(Service_NVDRV, "Error!"); + LOG_CRITICAL(Service_NVDRV, "Unregistered handle!"); return NvResult::BadValue; } auto result = handle_description->Duplicate(false); if (result != NvResult::Success) { - LOG_CRITICAL(Service_NVDRV, "Error!"); + LOG_CRITICAL(Service_NVDRV, "Could not duplicate handle!"); return result; } params.handle = handle_description->id; @@ -201,16 +201,16 @@ NvResult nvmap::IocParam(const std::vector& input, std::vector& output) IocParamParams params; std::memcpy(¶ms, input.data(), sizeof(params)); - LOG_WARNING(Service_NVDRV, "called type={}", params.param); + LOG_DEBUG(Service_NVDRV, "called type={}", params.param); if (!params.handle) { - LOG_CRITICAL(Service_NVDRV, "Error!"); + LOG_CRITICAL(Service_NVDRV, "Invalid handle!"); return NvResult::BadValue; } auto handle_description{file.GetHandle(params.handle)}; if (!handle_description) { - LOG_CRITICAL(Service_NVDRV, "Error!"); + LOG_CRITICAL(Service_NVDRV, "Not registered handle!"); return NvResult::BadValue; } @@ -228,7 +228,7 @@ NvResult nvmap::IocParam(const std::vector& input, std::vector& output) if (handle_description->allocated) params.result = 0x40000000; else - params.result = 0x40000000; + params.result = 0; break; case HandleParameterType::Kind: params.result = handle_description->kind; @@ -248,7 +248,7 @@ NvResult nvmap::IocFree(const std::vector& input, std::vector& output) { IocFreeParams params; std::memcpy(¶ms, input.data(), sizeof(params)); - LOG_WARNING(Service_NVDRV, "called"); + LOG_DEBUG(Service_NVDRV, "called"); if (!params.handle) { LOG_CRITICAL(Service_NVDRV, "Handle null freed?"); @@ -258,10 +258,10 @@ NvResult nvmap::IocFree(const std::vector& input, std::vector& output) { if (auto freeInfo{file.FreeHandle(params.handle, false)}) { params.address = freeInfo->address; params.size = static_cast(freeInfo->size); - params.flags = NvCore::NvMap::Handle::Flags{.map_uncached = freeInfo->was_uncached}; + params.flags.raw = 0; + params.flags.map_uncached = freeInfo->was_uncached; } else { // This is possible when there's internel dups or other duplicates. - LOG_CRITICAL(Service_NVDRV, "Not freed"); } std::memcpy(output.data(), ¶ms, sizeof(params));