From 98d96fd64953aefae9806d3226e428df44c7a0f3 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 25 Mar 2017 18:56:09 +0300 Subject: [PATCH] util::memory_reserve fixed --- Utilities/VirtualMemory.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Utilities/VirtualMemory.cpp b/Utilities/VirtualMemory.cpp index c52539ef7f..5aad6ef062 100644 --- a/Utilities/VirtualMemory.cpp +++ b/Utilities/VirtualMemory.cpp @@ -44,9 +44,17 @@ namespace utils void* memory_reserve(std::size_t size, void* use_addr) { #ifdef _WIN32 - return verify("reserve_memory" HERE, ::VirtualAlloc(use_addr, size, MEM_RESERVE, PAGE_NOACCESS)); + return ::VirtualAlloc(use_addr, size, MEM_RESERVE, PAGE_NOACCESS); #else - return verify("reserve_memory" HERE, ::mmap(use_addr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE | (use_addr ? MAP_FIXED : 0), -1, 0)); + auto ptr = ::mmap(use_addr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); + + if (use_addr && ptr != use_addr) + { + ::munmap(ptr, size); + return nullptr; + } + + return ptr; #endif }