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/MemoryUtilHorizon.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
#if PPSSPP_PLATFORM(SWITCH)
21
#include <cstring>
22
#include <cstdlib>
23
24
#include "Common/CommonTypes.h"
25
#include "Common/Log.h"
26
#include "Common/MemoryUtil.h"
27
#include "Common/StringUtils.h"
28
#include "Common/SysError.h"
29
30
#include <errno.h>
31
#include <stdio.h>
32
33
#include <malloc.h> // memalign
34
35
#define MEM_PAGE_SIZE (0x1000)
36
#define MEM_PAGE_MASK ((MEM_PAGE_SIZE)-1)
37
#define ppsspp_round_page(x) ((((uintptr_t)(x)) + MEM_PAGE_MASK) & ~(MEM_PAGE_MASK))
38
39
// On Switch we dont support allocating executable memory here
40
// See CodeBlock.h
41
void *AllocateExecutableMemory(size_t size) {
42
return nullptr;
43
}
44
45
void *AllocateMemoryPages(size_t size, uint32_t memProtFlags) {
46
void* ptr = nullptr;
47
size = ppsspp_round_page(size);
48
ptr = memalign(MEM_PAGE_SIZE, size);
49
return ptr;
50
}
51
52
void *AllocateAlignedMemory(size_t size, size_t alignment) {
53
void* ptr = memalign(alignment, size);
54
55
_assert_msg_(ptr != nullptr, "Failed to allocate aligned memory of size %lu", size);
56
return ptr;
57
}
58
59
void FreeMemoryPages(void *ptr, size_t size) {
60
if (!ptr)
61
return;
62
63
free(ptr);
64
return;
65
}
66
67
void FreeExecutableMemory(void *ptr, size_t size) {
68
return; // Not supported on Switch
69
}
70
71
void FreeAlignedMemory(void* ptr) {
72
if (!ptr)
73
return;
74
75
free(ptr);
76
}
77
78
bool PlatformIsWXExclusive() {
79
return false; // Switch technically is W^X but we use dual mappings instead of reprotecting the pages to allow a W and X mapping
80
}
81
82
bool ProtectMemoryPages(const void* ptr, size_t size, uint32_t memProtFlags) {
83
return true;
84
}
85
86
int GetMemoryProtectPageSize() {
87
return MEM_PAGE_SIZE;
88
}
89
#endif // PPSSPP_PLATFORM(SWITCH)
90
91