From 5535e51f82e641cdf198100f460c4a37533336f8 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 3 Sep 2024 20:21:38 -0400 Subject: [PATCH] fix memory direct query i wish there were tests for this --- src/core/memory.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 640751477..752aadbb5 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -332,13 +332,17 @@ int MemoryManager::DirectMemoryQuery(PAddr addr, bool find_next, std::scoped_lock lk{mutex}; auto dmem_area = FindDmemArea(addr); - while (dmem_area != dmem_map.end() && dmem_area->second.is_free && find_next) { - dmem_area++; - } + if (addr >= dmem_area->second.base + dmem_area->second.size) { + if (!find_next) { + LOG_ERROR(Core, "Unable to find allocated direct memory region to query!"); + return ORBIS_KERNEL_ERROR_EACCES; + } - if (dmem_area == dmem_map.end() || dmem_area->second.is_free) { - LOG_ERROR(Core, "Unable to find allocated direct memory region to query!"); - return ORBIS_KERNEL_ERROR_EACCES; + dmem_area++; + if (dmem_area == dmem_map.end()) { + LOG_ERROR(Core, "Unable to find allocated direct memory region to query!"); + return ORBIS_KERNEL_ERROR_EACCES; + } } const auto& area = dmem_area->second;