Avoid RWX page allocations on all platforms

As they're off limits on some Apple platforms and we want to have the
same behavior on all platforms supported by Frida.

At some point it would be good to evolve TinyCC to support putting
writable data on separate pages.
This commit is contained in:
Ole André Vadla Ravnås 2020-11-05 01:22:50 +01:00
parent 9c62e25b8b
commit aef0cbabb4

View File

@ -292,7 +292,7 @@ static void set_pages_executable(void *ptr, unsigned long length)
{
#ifdef _WIN32
unsigned long old_protect;
VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
VirtualProtect(ptr, length, PAGE_EXECUTE_READ, &old_protect);
#else
void __clear_cache(void *beginning, void *end);
# ifndef HAVE_SELINUX
@ -310,7 +310,7 @@ static void set_pages_executable(void *ptr, unsigned long length)
start = (addr_t)ptr & ~(pagesize - 1);
end = (addr_t)ptr + length;
end = (end + pagesize - 1) & ~(pagesize - 1);
if (mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC))
if (mprotect((void *)start, end - start, PROT_READ | PROT_EXEC))
tcc_error("mprotect failed: did you mean to configure --with-selinux?");
# endif
# if defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64