diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2016-01-15 15:33:00 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2016-01-15 15:20:31 +0000 |
commit | f2dc1ef7390c4dd05a54958da1942399e26e3fde (patch) | |
tree | bc13791e6ef2245785019cc62d92af89b90e055f /src/3rdparty/masm/stubs/ExecutableAllocator.h | |
parent | 8d0d5053addd1ba1bef131335160bd91449644e1 (diff) |
V4 JIT: Switch all platforms to W^X for the ExecutableAllocator.
This also fixes makeWritable, which needs to work in order to add more
c0d3 to used pages. Also finish the WinRT parts.
Change-Id: Idaa4187b1ec256e65c881285a608f3a51fdbeebd
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/3rdparty/masm/stubs/ExecutableAllocator.h')
-rw-r--r-- | src/3rdparty/masm/stubs/ExecutableAllocator.h | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/src/3rdparty/masm/stubs/ExecutableAllocator.h b/src/3rdparty/masm/stubs/ExecutableAllocator.h index 5f7d5678ab..578a944bf9 100644 --- a/src/3rdparty/masm/stubs/ExecutableAllocator.h +++ b/src/3rdparty/masm/stubs/ExecutableAllocator.h @@ -89,15 +89,34 @@ struct ExecutableAllocator { return adoptRef(new ExecutableMemoryHandle(realAllocator, size)); } - static void makeWritable(void* addr, int size) + static void makeWritable(void* addr, size_t size) { -#if ENABLE(ASSEMBLER_WX_EXCLUSIVE) - size_t pageSize = WTF::pageSize(); - size_t iaddr = reinterpret_cast<size_t>(addr); - size_t roundAddr = iaddr & ~(pageSize - static_cast<size_t>(1)); + quintptr pageSize = WTF::pageSize(); + quintptr iaddr = reinterpret_cast<quintptr>(addr); + quintptr roundAddr = iaddr & ~(pageSize - 1); + size = size + (iaddr - roundAddr); + addr = reinterpret_cast<void*>(roundAddr); +#if ENABLE(ASSEMBLER_WX_EXCLUSIVE) +# if OS(WINDOWS) + DWORD oldProtect; +# if !OS(WINRT) + VirtualProtect(addr, size, PAGE_READWRITE, &oldProtect); +# elif _MSC_VER >= 1900 + bool hr = VirtualProtectFromApp(addr, size, PAGE_READWRITE, &oldProtect); + if (!hr) { + Q_UNREACHABLE(); + } +# else + (void)oldProtect; +# endif +# else int mode = PROT_READ | PROT_WRITE; - mprotect(reinterpret_cast<void*>(roundAddr), size + (iaddr - roundAddr), mode); + if (mprotect(addr, size, mode) != 0) { + perror("mprotect failed in ExecutableAllocator::makeWritable"); + Q_UNREACHABLE(); + } +# endif #else // We assume we already have RWX (void)addr; // suppress unused parameter warning @@ -105,25 +124,36 @@ struct ExecutableAllocator { #endif } - static void makeExecutable(void* addr, int size) + static void makeExecutable(void* addr, size_t size) { - size_t pageSize = WTF::pageSize(); - size_t iaddr = reinterpret_cast<size_t>(addr); - size_t roundAddr = iaddr & ~(pageSize - static_cast<size_t>(1)); -#if OS(WINDOWS) -#if !OS(WINRT) + quintptr pageSize = WTF::pageSize(); + quintptr iaddr = reinterpret_cast<quintptr>(addr); + quintptr roundAddr = iaddr & ~(pageSize - 1); + size = size + (iaddr - roundAddr); + addr = reinterpret_cast<void*>(roundAddr); + +#if ENABLE(ASSEMBLER_WX_EXCLUSIVE) +# if OS(WINDOWS) DWORD oldProtect; - VirtualProtect(reinterpret_cast<void*>(roundAddr), size + (iaddr - roundAddr), PAGE_EXECUTE_READWRITE, &oldProtect); -#else - (void)size; // suppress unused parameter warning - (void)roundAddr; // suppress unused parameter warning -#endif -#else +# if !OS(WINRT) + VirtualProtect(addr, size, PAGE_EXECUTE_READ, &oldProtect); +# elif _MSC_VER >= 1900 + bool hr = VirtualProtectFromApp(addr, size, PAGE_EXECUTE_READ, &oldProtect); + if (!hr) { + Q_UNREACHABLE(); + } +# else + (void)oldProtect; +# endif +# else int mode = PROT_READ | PROT_EXEC; -#if !ENABLE(ASSEMBLER_WX_EXCLUSIVE) - mode |= PROT_WRITE; -#endif - mprotect(reinterpret_cast<void*>(roundAddr), size + (iaddr - roundAddr), mode); + if (mprotect(addr, size, mode) != 0) { + perror("mprotect failed in ExecutableAllocator::makeExecutable"); + Q_UNREACHABLE(); + } +# endif +#else +# error "Only W^X is supported" #endif } |