mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-22 21:35:51 +12:00
Move away from PCSX2 fastmem
This commit is contained in:
parent
fbddb02ac3
commit
ede3a93cda
10 changed files with 1058 additions and 1023 deletions
47
third_party/host_memory/virtual_buffer.cpp
vendored
Normal file
47
third_party/host_memory/virtual_buffer.cpp
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include "host_memory/virtual_buffer.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
void* AllocateMemoryPages(std::size_t size) noexcept {
|
||||
#ifdef _WIN32
|
||||
void* base{VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE)};
|
||||
#else
|
||||
void* base{mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0)};
|
||||
|
||||
if (base == MAP_FAILED) {
|
||||
base = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!base) {
|
||||
Helpers::panic("Failed to allocate memory pages");
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) noexcept {
|
||||
if (!base) {
|
||||
return;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (!VirtualFree(base, 0, MEM_RELEASE)) {
|
||||
Helpers::panic("Failed to free memory pages");
|
||||
}
|
||||
#else
|
||||
if (munmap(base, size) != 0) {
|
||||
Helpers::panic("Failed to free memory pages");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Common
|
Loading…
Add table
Add a link
Reference in a new issue