CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/MemArenaWin32.cpp
Views: 1401
// Copyright (C) 2003 Dolphin Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official SVN repository and contact information can be found at15// http://code.google.com/p/dolphin-emu/1617#include "ppsspp_config.h"1819#ifdef _WIN322021#include "MemArena.h"22#include "CommonWindows.h"2324// Windows mappings need to be on 64K boundaries, due to Alpha legacy.25size_t MemArena::roundup(size_t x) {26int gran = sysInfo.dwAllocationGranularity ? sysInfo.dwAllocationGranularity : 0x10000;27return (x + gran - 1) & ~(gran - 1);28}2930bool MemArena::GrabMemSpace(size_t size) {31#if !PPSSPP_PLATFORM(UWP)32hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)(size), NULL);33GetSystemInfo(&sysInfo);34#else35hMemoryMapping = 0;36#endif37return true;38}3940void MemArena::ReleaseSpace() {41CloseHandle(hMemoryMapping);42hMemoryMapping = 0;43}4445void *MemArena::CreateView(s64 offset, size_t size, void *viewbase) {46size = roundup(size);47#if PPSSPP_PLATFORM(UWP)48// We just grabbed some RAM before using RESERVE. This commits it.49void *ptr = VirtualAllocFromApp(viewbase, size, MEM_COMMIT, PAGE_READWRITE);50#else51void *ptr = MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, viewbase);52#endif53return ptr;54}5556void MemArena::ReleaseView(s64 offset, void* view, size_t size) {57#if PPSSPP_PLATFORM(UWP)58#else59UnmapViewOfFile(view);60#endif61}6263bool MemArena::NeedsProbing() {64#if PPSSPP_ARCH(32BIT)65return true;66#else67return false;68#endif69}7071u8* MemArena::Find4GBBase() {72// Now, create views in high memory where there's plenty of space.73#if PPSSPP_ARCH(32BIT)74// Caller will need to find one in a different way.75return nullptr;7677#elif PPSSPP_ARCH(64BIT)78u8 *base = (u8*)VirtualAlloc(0, 0xE1000000, MEM_RESERVE, PAGE_READWRITE);79if (base) {80VirtualFree(base, 0, MEM_RELEASE);81}82return base;83#else84#error Arch not supported85#endif86}8788#endif // _WIN32899091