mirror of
https://github.com/yuzu-mirror/oaknut.git
synced 2026-02-23 21:34:13 +01:00
oaknut: Add support for iOS memory protection.
This commit is contained in:
parent
14207278af
commit
dc54784b87
|
|
@ -16,6 +16,7 @@
|
|||
# include <pthread.h>
|
||||
# include <sys/mman.h>
|
||||
# include <unistd.h>
|
||||
# include <TargetConditionals.h>
|
||||
#else
|
||||
# include <sys/mman.h>
|
||||
#endif
|
||||
|
|
@ -30,7 +31,11 @@ public:
|
|||
#if defined(_WIN32)
|
||||
m_memory = (std::uint32_t*)VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||
#elif defined(__APPLE__)
|
||||
#if TARGET_OS_IPHONE
|
||||
m_memory = (std::uint32_t*)mmap(nullptr, size, PROT_READ | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
#else
|
||||
m_memory = (std::uint32_t*)mmap(nullptr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE | MAP_JIT, -1, 0);
|
||||
#endif
|
||||
#else
|
||||
m_memory = (std::uint32_t*)mmap(nullptr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
#endif
|
||||
|
|
@ -64,14 +69,22 @@ public:
|
|||
void protect()
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
#if TARGET_OS_IPHONE
|
||||
mprotect(m_memory, m_size, PROT_READ | PROT_EXEC);
|
||||
#else
|
||||
pthread_jit_write_protect_np(1);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void unprotect()
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
#if TARGET_OS_IPHONE
|
||||
mprotect(m_memory, m_size, PROT_READ | PROT_WRITE);
|
||||
#else
|
||||
pthread_jit_write_protect_np(0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue