aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2016-01-15 15:33:00 +0100
committerErik Verbruggen <erik.verbruggen@theqtcompany.com>2016-01-15 15:20:31 +0000
commitf2dc1ef7390c4dd05a54958da1942399e26e3fde (patch)
treebc13791e6ef2245785019cc62d92af89b90e055f
parent8d0d5053addd1ba1bef131335160bd91449644e1 (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>
-rw-r--r--src/3rdparty/masm/masm-defs.pri3
-rw-r--r--src/3rdparty/masm/stubs/ExecutableAllocator.h74
-rw-r--r--src/qml/jsruntime/jsruntime.pri2
3 files changed, 53 insertions, 26 deletions
diff --git a/src/3rdparty/masm/masm-defs.pri b/src/3rdparty/masm/masm-defs.pri
index f09a8329c9..c76eeec724 100644
--- a/src/3rdparty/masm/masm-defs.pri
+++ b/src/3rdparty/masm/masm-defs.pri
@@ -1,6 +1,5 @@
-
-
DEFINES += WTF_EXPORT_PRIVATE="" JS_EXPORT_PRIVATE=""
+DEFINES += ENABLE_ASSEMBLER_WX_EXCLUSIVE=1
# Avoid symbol clashes with QtScript during static linking
DEFINES += WTFReportAssertionFailure=qmlWTFReportAssertionFailure
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
}
diff --git a/src/qml/jsruntime/jsruntime.pri b/src/qml/jsruntime/jsruntime.pri
index 57ad85485a..c61e848bd7 100644
--- a/src/qml/jsruntime/jsruntime.pri
+++ b/src/qml/jsruntime/jsruntime.pri
@@ -110,5 +110,3 @@ SOURCES += \
valgrind {
DEFINES += V4_USE_VALGRIND
}
-
-ios|tvos: DEFINES += ENABLE_ASSEMBLER_WX_EXCLUSIVE=1