diff options
Diffstat (limited to 'src/3rdparty/masm/wtf')
-rw-r--r-- | src/3rdparty/masm/wtf/OSAllocator.h | 2 | ||||
-rw-r--r-- | src/3rdparty/masm/wtf/OSAllocatorPosix.cpp | 5 | ||||
-rw-r--r-- | src/3rdparty/masm/wtf/OSAllocatorWin.cpp | 5 | ||||
-rw-r--r-- | src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp | 104 | ||||
-rw-r--r-- | src/3rdparty/masm/wtf/Platform.h | 19 |
5 files changed, 121 insertions, 14 deletions
diff --git a/src/3rdparty/masm/wtf/OSAllocator.h b/src/3rdparty/masm/wtf/OSAllocator.h index 494f8bc3c7..933b3cda0a 100644 --- a/src/3rdparty/masm/wtf/OSAllocator.h +++ b/src/3rdparty/masm/wtf/OSAllocator.h @@ -71,6 +71,8 @@ public: // This interface is provided since it may be possible to optimize this operation on some platforms. template<typename T> static T* reallocateCommitted(T*, size_t oldSize, size_t newSize, Usage = UnknownUsage, bool writable = true, bool executable = false); + + static bool canAllocateExecutableMemory(); }; inline void* OSAllocator::reserveAndCommit(size_t reserveSize, size_t commitSize, Usage usage, bool writable, bool executable) diff --git a/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp b/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp index f52c22f7fa..bbf11e4488 100644 --- a/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp +++ b/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp @@ -189,6 +189,11 @@ void OSAllocator::releaseDecommitted(void* address, size_t bytes) CRASH(); } +bool OSAllocator::canAllocateExecutableMemory() +{ + return true; +} + } // namespace WTF #endif // OS(UNIX) diff --git a/src/3rdparty/masm/wtf/OSAllocatorWin.cpp b/src/3rdparty/masm/wtf/OSAllocatorWin.cpp index 259fc67324..bb934264ab 100644 --- a/src/3rdparty/masm/wtf/OSAllocatorWin.cpp +++ b/src/3rdparty/masm/wtf/OSAllocatorWin.cpp @@ -90,6 +90,11 @@ void OSAllocator::releaseDecommitted(void* address, size_t bytes) CRASH(); } +bool OSAllocator::canAllocateExecutableMemory() +{ + return true; +} + } // namespace WTF #endif // OS(WINDOWS) diff --git a/src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp b/src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp index d684367ec6..b7ad723f07 100644 --- a/src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp +++ b/src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp @@ -25,12 +25,27 @@ #include "config.h" #include "OSAllocator.h" +#include "PageBlock.h" #if OS(WINRT) #include "windows.h" #include <wtf/Assertions.h> +#if _MSC_VER >= 1900 +// Try to use JIT by default and fallback to non-JIT on first error +static bool qt_winrt_use_jit = true; +#else // _MSC_VER < 1900 +# define PAGE_EXECUTE 0x10 +# define PAGE_EXECUTE_READ 0x20 +# define PAGE_EXECUTE_READWRITE 0x40 +# define MEM_RELEASE 0x8000 +inline void* VirtualAllocFromApp(void*, size_t, int, int) { return 0; } +inline bool VirtualProtectFromApp(void *, size_t, int, DWORD*) { return false; } +inline bool VirtualFree(void *, size_t, DWORD) { return false; } +static bool qt_winrt_use_jit = false; +#endif // _MSC_VER < 1900 + namespace WTF { inline size_t getPageSize() @@ -40,19 +55,58 @@ inline size_t getPageSize() return info.dwPageSize; } -void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool, bool) +static inline DWORD protection(bool writable, bool executable) { - static const size_t pageSize = getPageSize(); - void* result = _aligned_malloc(bytes, pageSize); - if (!result) - CRASH(); - memset(result, 0, bytes); + if (writable && executable) + qFatal("read/write executable areas are not allowed on WinRT"); + return executable ? + (writable ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ) : + (writable ? PAGE_READWRITE : PAGE_READONLY); +} + +void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable) +{ + void *result; + if (qt_winrt_use_jit) { + result = VirtualAllocFromApp(0, bytes, MEM_RESERVE, protection(writable, executable)); + if (!result) { + qt_winrt_use_jit = false; + return reserveUncommitted(bytes, UnknownUsage, writable, executable); + } + } else { + static const size_t pageSize = getPageSize(); + result = _aligned_malloc(bytes, pageSize); + if (!result) + CRASH(); + memset(result, 0, bytes); + } return result; } -void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable, bool) +void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable, bool includesGuardPages) { - return reserveUncommitted(bytes, usage, writable, executable); + void *result; + if (qt_winrt_use_jit) { + result = VirtualAllocFromApp(0, bytes, MEM_RESERVE | MEM_COMMIT, + protection(writable, executable)); + if (!result) { + qt_winrt_use_jit = false; + return reserveAndCommit(bytes, usage, writable, executable, includesGuardPages); + } + + if (includesGuardPages) { + size_t guardSize = pageSize(); + DWORD oldProtect; + if (!VirtualProtectFromApp(result, guardSize, protection(false, false), &oldProtect) || + !VirtualProtectFromApp(static_cast<char*>(result) + bytes - guardSize, guardSize, + protection(false, false), &oldProtect)) { + CRASH(); + } + } + } else { + result = reserveUncommitted(bytes, usage, writable, executable); + } + return result; } void OSAllocator::commit(void*, size_t, bool, bool) @@ -62,14 +116,44 @@ void OSAllocator::commit(void*, size_t, bool, bool) void OSAllocator::decommit(void* address, size_t) { - _aligned_free(address); + if (qt_winrt_use_jit) + Q_UNREACHABLE(); + else + _aligned_free(address); } void OSAllocator::releaseDecommitted(void* address, size_t bytes) { - decommit(address, bytes); + if (qt_winrt_use_jit) { + bool result = VirtualFree(address, 0, MEM_RELEASE); + if (!result) + CRASH(); + } else { + decommit(address, bytes); + } } +bool OSAllocator::canAllocateExecutableMemory() +{ + if (qt_winrt_use_jit) { + // For WinRT we first check if code generation is enabled. If successful + // we allow to use JIT, otherwise fallback to the interpreter + const size_t pageSize = getPageSize(); + void *all = VirtualAllocFromApp(0, pageSize, MEM_RESERVE | MEM_COMMIT, + protection(true, false)); + DWORD oldProtect; + bool res = VirtualProtectFromApp(all, pageSize, PAGE_EXECUTE, &oldProtect); + VirtualFree(all, 0, MEM_RELEASE); + if (!res) { + qt_winrt_use_jit = false; + qWarning("Could not enable JIT, fallback to interpreter mode. " + "Consider setting the code-generation capability"); + } + } + return qt_winrt_use_jit; +} + + } // namespace WTF #endif // OS(WINRT) diff --git a/src/3rdparty/masm/wtf/Platform.h b/src/3rdparty/masm/wtf/Platform.h index f0612fe50e..3f480d344a 100644 --- a/src/3rdparty/masm/wtf/Platform.h +++ b/src/3rdparty/masm/wtf/Platform.h @@ -166,6 +166,11 @@ #define WTF_CPU_X86_64 1 #endif +/* CPU(ARM64) - Apple */ +#if (defined(__arm64__) && defined(__APPLE__)) || defined(__aarch64__) +#define WTF_CPU_ARM64 1 +#endif + /* CPU(ARM) - ARM, any version*/ #define WTF_ARM_ARCH_AT_LEAST(N) (CPU(ARM) && WTF_ARM_ARCH_VERSION >= N) @@ -348,6 +353,11 @@ || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) \ || (defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR)) #define WTF_OS_IOS 1 +#elif OS(DARWIN) && ((defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED) \ + || (defined(TARGET_OS_APPLETV) && TARGET_OS_APPLETV) \ + || (defined(TARGET_APPLETV_SIMULATOR) && TARGET_APPLETV_SIMULATOR)) +#define WTF_OS_IOS 1 +#define WTF_OS_TVOS 1 #elif OS(DARWIN) && defined(TARGET_OS_MAC) && TARGET_OS_MAC #define WTF_OS_MAC_OS_X 1 @@ -700,6 +710,7 @@ #if (CPU(X86_64) && (OS(UNIX) || OS(WINDOWS))) \ || (CPU(IA64) && !CPU(IA64_32)) \ || CPU(ALPHA) \ + || CPU(ARM64) \ || CPU(SPARC64) \ || CPU(S390X) \ || CPU(PPC64) @@ -720,7 +731,7 @@ /* The JIT is enabled by default on all x86, x86-64, ARM & MIPS platforms. */ #if !defined(ENABLE_JIT) \ - && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(MIPS)) \ + && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(MIPS) || CPU(ARM64)) \ && (OS(DARWIN) || !COMPILER(GCC) || GCC_VERSION_AT_LEAST(4, 1, 0)) \ && !OS(WINCE) \ && !(OS(QNX) && !PLATFORM(QT)) /* We use JIT in QNX Qt */ @@ -735,7 +746,7 @@ #define WTF_USE_UDIS86 1 #endif -#if !defined(ENABLE_DISASSEMBLER) && (USE(UDIS86) || USE(ARMV7_DISASSEMBLER) || USE(MIPS32_DISASSEMBLER)) +#if !defined(ENABLE_DISASSEMBLER) && (USE(UDIS86) || USE(ARMV7_DISASSEMBLER) || USE(ARM64_DISASSEMBLER) || USE(MIPS32_DISASSEMBLER)) #define ENABLE_DISASSEMBLER 1 #endif @@ -869,7 +880,7 @@ /* Pick which allocator to use; we only need an executable allocator if the assembler is compiled in. On x86-64 we use a single fixed mmap, on other platforms we mmap on demand. */ #if ENABLE(ASSEMBLER) -#if CPU(X86_64) && !OS(WINDOWS) || PLATFORM(IOS) +#if CPU(X86_64) && !OS(WINDOWS) || PLATFORM(IOS) || CPU(ARM64) #define ENABLE_EXECUTABLE_ALLOCATOR_FIXED 1 #else #define ENABLE_EXECUTABLE_ALLOCATOR_DEMAND 1 @@ -928,7 +939,7 @@ #define WTF_USE_ACCESSIBILITY_CONTEXT_MENUS 1 #endif -#if CPU(ARM_THUMB2) +#if CPU(ARM_THUMB2) || CPU(ARM64) #define ENABLE_BRANCH_COMPACTION 1 #endif |