diff --git a/Common/CodeBlock.h b/Common/CodeBlock.h
index 76ee2b5640..f8e5b6be67 100644
--- a/Common/CodeBlock.h
+++ b/Common/CodeBlock.h
@@ -97,6 +97,7 @@ public:
// Call this when shutting down. Don't rely on the destructor, even though it'll do the job.
void FreeCodeSpace() {
+ ProtectMemoryPages(region, region_size, MEM_PROT_READ | MEM_PROT_WRITE);
FreeMemoryPages(region, region_size);
region = nullptr;
region_size = 0;
diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj
index 77b63f204b..c2ed3cd411 100644
--- a/Common/Common.vcxproj
+++ b/Common/Common.vcxproj
@@ -295,6 +295,7 @@
+
@@ -325,4 +326,4 @@
-
\ No newline at end of file
+
diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters
index 2930c66f80..c707726aa0 100644
--- a/Common/Common.vcxproj.filters
+++ b/Common/Common.vcxproj.filters
@@ -134,6 +134,7 @@
+
@@ -149,4 +150,4 @@
{c14d66ef-5f7c-4565-975a-72774e7ccfb9}
-
\ No newline at end of file
+
diff --git a/Common/MemArena.h b/Common/MemArena.h
index 48e1bcece2..0c3b794546 100644
--- a/Common/MemArena.h
+++ b/Common/MemArena.h
@@ -21,6 +21,8 @@
#ifdef _WIN32
#include "CommonWindows.h"
+#elif defined(__APPLE__)
+#include
#endif
#include "Common.h"
@@ -47,9 +49,9 @@ private:
#ifdef _WIN32
HANDLE hMemoryMapping;
SYSTEM_INFO sysInfo;
-#elif defined(IOS) && PPSSPP_ARCH(ARM64)
+#elif defined(__APPLE__)
size_t vm_size;
- uintptr_t vm_mem; // same type as vm_address_t
+ vm_address_t vm_mem; // same type as vm_address_t
#else
int fd;
#endif
diff --git a/Common/MemArenaDarwin.cpp b/Common/MemArenaDarwin.cpp
index 4632670f27..593bb1495e 100644
--- a/Common/MemArenaDarwin.cpp
+++ b/Common/MemArenaDarwin.cpp
@@ -17,7 +17,7 @@
#include "ppsspp_config.h"
-#if defined(IOS) && PPSSPP_ARCH(ARM64)
+#if defined(__APPLE__)
#include
#include
@@ -39,8 +39,7 @@ size_t MemArena::roundup(size_t x) {
return x;
}
-void MemArena::GrabLowMemSpace(size_t size)
-{
+void MemArena::GrabLowMemSpace(size_t size) {
vm_size = size;
kern_return_t retval = vm_allocate(mach_task_self(), &vm_mem, size, VM_FLAGS_ANYWHERE);
if (retval != KERN_SUCCESS) {
@@ -56,8 +55,7 @@ void MemArena::ReleaseSpace() {
vm_mem = 0;
}
-void *MemArena::CreateView(s64 offset, size_t size, void *base)
-{
+void *MemArena::CreateView(s64 offset, size_t size, void *base) {
mach_port_t self = mach_task_self();
vm_address_t target = (vm_address_t)base;
uint64_t mask = 0;
@@ -86,12 +84,34 @@ void MemArena::ReleaseView(void* view, size_t size) {
}
bool MemArena::NeedsProbing() {
+#if defined(IOS) && PPSSPP_ARCH(64BIT)
return true;
+#else
+ return false;
+#endif
}
u8* MemArena::Find4GBBase() {
+#if defined(IOS) && PPSSPP_ARCH(64BIT)
// The caller will need to do probing, like on 32-bit Windows.
return nullptr;
+#else
+ size_t size;
+#if PPSSPP_ARCH(64BIT)
+ size = 0xE1000000;
+#else
+ size = 0x10000000;
+#endif
+
+ vm_address_t addr = 0;
+ kern_return_t retval = vm_allocate(mach_task_self(), &addr, size, VM_FLAGS_ANYWHERE);
+ if (retval == KERN_SUCCESS) {
+ // Don't need the memory now, was just probing.
+ vm_deallocate(mach_task_self(), addr, size);
+ return (u8 *)addr;
+ }
+#endif
+ return nullptr;
}
-#endif // defined(IOS) && PPSSPP_ARCH(ARM64)
+#endif // __APPLE__
diff --git a/Common/MemArenaPosix.cpp b/Common/MemArenaPosix.cpp
index 764edae78f..18151d0b34 100644
--- a/Common/MemArenaPosix.cpp
+++ b/Common/MemArenaPosix.cpp
@@ -17,7 +17,7 @@
#include "ppsspp_config.h"
-#if !defined(_WIN32) && !defined(ANDROID) && !(defined(IOS) && PPSSPP_ARCH(ARM64))
+#if !defined(_WIN32) && !defined(ANDROID) && !defined(__APPLE__)
#include
@@ -107,13 +107,14 @@ u8* MemArena::Find4GBBase() {
// This makes the Windows approach above unusable on Linux, so we will simply pray...
return reinterpret_cast(0x2300000000ULL);
#else
- void* base = mmap(0, 0x10000000, PROT_READ | PROT_WRITE,
+ size_t size = 0x10000000;
+ void* base = mmap(0, size, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_SHARED, -1, 0);
if (base == MAP_FAILED) {
PanicAlert("Failed to map 256 MB of memory space: %s", strerror(errno));
return 0;
}
- munmap(base, 0x10000000);
+ munmap(base, size);
return static_cast(base);
#endif
}
diff --git a/ios/ViewController.mm b/ios/ViewController.mm
index 77cdb6eb60..2d9f46bb5d 100644
--- a/ios/ViewController.mm
+++ b/ios/ViewController.mm
@@ -52,7 +52,6 @@ bool simulateAnalog = false;
extern ScreenManager *screenManager;
InputState input_state;
-extern std::string ram_temp_file;
extern bool iosCanUseJit;
extern bool targetIsJailbroken;
@@ -97,11 +96,6 @@ static GraphicsContext *graphicsContext;
net::Init();
-#if defined(IOS) && PPSSPP_ARCH(ARM64)
-#else
- ram_temp_file = [[NSTemporaryDirectory() stringByAppendingPathComponent:@"ram_tmp.file"] fileSystemRepresentation];
-#endif
-
iosCanUseJit = true;
targetIsJailbroken = false;
NSArray *jailPath = [NSArray arrayWithObjects: