diff options
| author | Admiral H. Curtiss <pikachu025@gmail.com> | 2021-06-21 01:17:07 +0200 |
|---|---|---|
| committer | Admiral H. Curtiss <pikachu025@gmail.com> | 2021-12-25 20:20:36 +0100 |
| commit | 812cc8b6322fa72982a3084bb3de4bdb564331fe (patch) | |
| tree | 72ace490d57b9e0d2947b052ee2b65ad0e333ae8 /Source/Core/Common/MemArenaWin.cpp | |
| parent | a29d7625ddb67f29f6dc46858b2b1488b72fd42b (diff) | |
MemArena: Split into three separate files for each OS.
Diffstat (limited to 'Source/Core/Common/MemArenaWin.cpp')
| -rw-r--r-- | Source/Core/Common/MemArenaWin.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Source/Core/Common/MemArenaWin.cpp b/Source/Core/Common/MemArenaWin.cpp new file mode 100644 index 0000000000..e65e642028 --- /dev/null +++ b/Source/Core/Common/MemArenaWin.cpp @@ -0,0 +1,61 @@ +// Copyright 2008 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "Common/MemArena.h" + +#include <cstddef> +#include <cstdlib> +#include <set> +#include <string> + +#include <windows.h> + +#include "Common/CommonFuncs.h" +#include "Common/CommonTypes.h" +#include "Common/Logging/Log.h" +#include "Common/MsgHandler.h" +#include "Common/StringUtil.h" + +namespace Common +{ +void MemArena::GrabSHMSegment(size_t size) +{ + const std::string name = "dolphin-emu." + std::to_string(GetCurrentProcessId()); + hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, + static_cast<DWORD>(size), UTF8ToTStr(name).c_str()); +} + +void MemArena::ReleaseSHMSegment() +{ + CloseHandle(hMemoryMapping); + hMemoryMapping = 0; +} + +void* MemArena::CreateView(s64 offset, size_t size, void* base) +{ + return MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base); +} + +void MemArena::ReleaseView(void* view, size_t size) +{ + UnmapViewOfFile(view); +} + +u8* MemArena::FindMemoryBase() +{ +#if _ARCH_32 + const size_t memory_size = 0x31000000; +#else + const size_t memory_size = 0x400000000; +#endif + + u8* base = static_cast<u8*>(VirtualAlloc(nullptr, memory_size, MEM_RESERVE, PAGE_READWRITE)); + if (!base) + { + PanicAlertFmt("Failed to map enough memory space: {}", GetLastErrorString()); + return nullptr; + } + VirtualFree(base, 0, MEM_RELEASE); + return base; +} +} // namespace Common |
