CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/MemArenaWin32.cpp
Views: 1401
1
// Copyright (C) 2003 Dolphin Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official SVN repository and contact information can be found at
16
// http://code.google.com/p/dolphin-emu/
17
18
#include "ppsspp_config.h"
19
20
#ifdef _WIN32
21
22
#include "MemArena.h"
23
#include "CommonWindows.h"
24
25
// Windows mappings need to be on 64K boundaries, due to Alpha legacy.
26
size_t MemArena::roundup(size_t x) {
27
int gran = sysInfo.dwAllocationGranularity ? sysInfo.dwAllocationGranularity : 0x10000;
28
return (x + gran - 1) & ~(gran - 1);
29
}
30
31
bool MemArena::GrabMemSpace(size_t size) {
32
#if !PPSSPP_PLATFORM(UWP)
33
hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)(size), NULL);
34
GetSystemInfo(&sysInfo);
35
#else
36
hMemoryMapping = 0;
37
#endif
38
return true;
39
}
40
41
void MemArena::ReleaseSpace() {
42
CloseHandle(hMemoryMapping);
43
hMemoryMapping = 0;
44
}
45
46
void *MemArena::CreateView(s64 offset, size_t size, void *viewbase) {
47
size = roundup(size);
48
#if PPSSPP_PLATFORM(UWP)
49
// We just grabbed some RAM before using RESERVE. This commits it.
50
void *ptr = VirtualAllocFromApp(viewbase, size, MEM_COMMIT, PAGE_READWRITE);
51
#else
52
void *ptr = MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, viewbase);
53
#endif
54
return ptr;
55
}
56
57
void MemArena::ReleaseView(s64 offset, void* view, size_t size) {
58
#if PPSSPP_PLATFORM(UWP)
59
#else
60
UnmapViewOfFile(view);
61
#endif
62
}
63
64
bool MemArena::NeedsProbing() {
65
#if PPSSPP_ARCH(32BIT)
66
return true;
67
#else
68
return false;
69
#endif
70
}
71
72
u8* MemArena::Find4GBBase() {
73
// Now, create views in high memory where there's plenty of space.
74
#if PPSSPP_ARCH(32BIT)
75
// Caller will need to find one in a different way.
76
return nullptr;
77
78
#elif PPSSPP_ARCH(64BIT)
79
u8 *base = (u8*)VirtualAlloc(0, 0xE1000000, MEM_RESERVE, PAGE_READWRITE);
80
if (base) {
81
VirtualFree(base, 0, MEM_RELEASE);
82
}
83
return base;
84
#else
85
#error Arch not supported
86
#endif
87
}
88
89
#endif // _WIN32
90
91