Warning, /graphics/krita/3rdparty/ext_qt/0136-JIT-When-making-memory-writable-include-the-exceptio.patch is written in an unsupported language. File is not indexed.
0001 From 017bed2aab7f4d48984a21b5ab927ab999bf005b Mon Sep 17 00:00:00 2001 0002 From: Ulf Hermann <ulf.hermann@qt.io> 0003 Date: Wed, 16 Dec 2020 16:45:36 +0100 0004 Subject: [PATCH 136/139] JIT: When making memory writable, include the 0005 exception handler 0006 0007 makeWritable() rounds the memory down to the next page boundary. Usually 0008 we include the exception handler this way, unless the offset from the 0009 page boundary is less than the exception handler size. Make it explicit 0010 that we do want the exception handler to be writable, too. 0011 0012 Fixes: QTBUG-89513 0013 Change-Id: I2fb8fb0e1dcc3450b036924463dc1b40d2020c46 0014 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> 0015 (cherry picked from commit 86a595b126bc6794380dc00af80ec4802f7d058c) 0016 Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> 0017 (cherry picked from commit 35614462443c100b6753b335b58a134fed4b5c35) 0018 Signed-off-by: L. E. Segovia <amy@amyspark.me> 0019 --- 0020 src/3rdparty/masm/assembler/AssemblerBuffer.h | 4 ++-- 0021 src/3rdparty/masm/assembler/LinkBuffer.h | 9 +++++---- 0022 .../masm/assembler/MacroAssemblerCodeRef.h | 6 +++--- 0023 src/3rdparty/masm/stubs/ExecutableAllocator.h | 11 ++++++++--- 0024 src/qml/jsruntime/qv4executableallocator.cpp | 14 ++++++++++++-- 0025 src/qml/jsruntime/qv4executableallocator_p.h | 10 ++++++++-- 0026 src/qml/jsruntime/qv4functiontable_win64.cpp | 4 ++-- 0027 7 files changed, 40 insertions(+), 18 deletions(-) 0028 0029 diff --git a/src/3rdparty/masm/assembler/AssemblerBuffer.h b/src/3rdparty/masm/assembler/AssemblerBuffer.h 0030 index 45874235..2292a4c2 100644 0031 --- a/src/3rdparty/masm/assembler/AssemblerBuffer.h 0032 +++ b/src/3rdparty/masm/assembler/AssemblerBuffer.h 0033 @@ -140,9 +140,9 @@ namespace JSC { 0034 if (!result) 0035 return 0; 0036 0037 - ExecutableAllocator::makeWritable(result->start(), result->sizeInBytes()); 0038 + ExecutableAllocator::makeWritable(result->memoryStart(), result->memorySize()); 0039 0040 - memcpy(result->start(), m_buffer, m_index); 0041 + memcpy(result->codeStart(), m_buffer, m_index); 0042 0043 return result.release(); 0044 } 0045 diff --git a/src/3rdparty/masm/assembler/LinkBuffer.h b/src/3rdparty/masm/assembler/LinkBuffer.h 0046 index a1bb046d..aef35662 100644 0047 --- a/src/3rdparty/masm/assembler/LinkBuffer.h 0048 +++ b/src/3rdparty/masm/assembler/LinkBuffer.h 0049 @@ -338,7 +338,7 @@ inline void LinkBufferBase<MacroAssembler, ExecutableOffsetCalculator>::linkCode 0050 m_executableMemory = m_assembler->m_assembler.executableCopy(*m_globalData, ownerUID, effort); 0051 if (!m_executableMemory) 0052 return; 0053 - m_code = m_executableMemory->start(); 0054 + m_code = m_executableMemory->codeStart(); 0055 m_size = m_assembler->m_assembler.codeSize(); 0056 ASSERT(m_code); 0057 } 0058 @@ -360,7 +360,8 @@ void LinkBufferBase<MacroAssembler, ExecutableOffsetCalculator>::performFinaliza 0059 template <typename MacroAssembler, template <typename T> class ExecutableOffsetCalculator> 0060 inline void LinkBufferBase<MacroAssembler, ExecutableOffsetCalculator>::makeExecutable() 0061 { 0062 - ExecutableAllocator::makeExecutable(code(), static_cast<int>(m_size)); 0063 + ExecutableAllocator::makeExecutable(m_executableMemory->memoryStart(), 0064 + m_executableMemory->memorySize()); 0065 } 0066 0067 template <typename MacroAssembler> 0068 @@ -447,9 +448,9 @@ inline void BranchCompactingLinkBuffer<MacroAssembler>::linkCode(void* ownerUID, 0069 m_executableMemory = m_globalData->executableAllocator.allocate(*m_globalData, m_initialSize, ownerUID, effort); 0070 if (!m_executableMemory) 0071 return; 0072 - m_code = (uint8_t*)m_executableMemory->start(); 0073 + m_code = (uint8_t*)m_executableMemory->codeStart(); 0074 ASSERT(m_code); 0075 - ExecutableAllocator::makeWritable(m_code, m_initialSize); 0076 + ExecutableAllocator::makeWritable(m_executableMemory->memoryStart(), m_executableMemory->memorySize()); 0077 uint8_t* inData = (uint8_t*)m_assembler->unlinkedCode(); 0078 uint8_t* outData = reinterpret_cast<uint8_t*>(m_code); 0079 int readPtr = 0; 0080 diff --git a/src/3rdparty/masm/assembler/MacroAssemblerCodeRef.h b/src/3rdparty/masm/assembler/MacroAssemblerCodeRef.h 0081 index a7e78ad7..cde97511 100644 0082 --- a/src/3rdparty/masm/assembler/MacroAssemblerCodeRef.h 0083 +++ b/src/3rdparty/masm/assembler/MacroAssemblerCodeRef.h 0084 @@ -357,11 +357,11 @@ public: 0085 } 0086 0087 MacroAssemblerCodeRef(PassRefPtr<ExecutableMemoryHandle> executableMemory) 0088 - : m_codePtr(executableMemory->start()) 0089 + : m_codePtr(executableMemory->codeStart()) 0090 , m_executableMemory(executableMemory) 0091 { 0092 ASSERT(m_executableMemory->isManaged()); 0093 - ASSERT(m_executableMemory->start()); 0094 + ASSERT(m_executableMemory->codeStart()); 0095 ASSERT(m_codePtr); 0096 } 0097 0098 @@ -395,7 +395,7 @@ public: 0099 { 0100 if (!m_executableMemory) 0101 return 0; 0102 - return m_executableMemory->sizeInBytes(); 0103 + return m_executableMemory->codeSize(); 0104 } 0105 0106 bool tryToDisassemble(const char* prefix) const 0107 diff --git a/src/3rdparty/masm/stubs/ExecutableAllocator.h b/src/3rdparty/masm/stubs/ExecutableAllocator.h 0108 index a439c538..f9847040 100644 0109 --- a/src/3rdparty/masm/stubs/ExecutableAllocator.h 0110 +++ b/src/3rdparty/masm/stubs/ExecutableAllocator.h 0111 @@ -82,9 +82,14 @@ struct ExecutableMemoryHandle : public RefCounted<ExecutableMemoryHandle> { 0112 0113 inline bool isManaged() const { return true; } 0114 0115 - void *exceptionHandler() { return m_allocation->exceptionHandler(); } 0116 - void *start() { return m_allocation->start(); } 0117 - size_t sizeInBytes() { return m_size; } 0118 + void *memoryStart() { return m_allocation->memoryStart(); } 0119 + size_t memorySize() { return m_allocation->memorySize(); } 0120 + 0121 + void *exceptionHandlerStart() { return m_allocation->exceptionHandlerStart(); } 0122 + size_t exceptionHandlerSize() { return m_allocation->exceptionHandlerSize(); } 0123 + 0124 + void *codeStart() { return m_allocation->codeStart(); } 0125 + size_t codeSize() { return m_size; } 0126 0127 QV4::ExecutableAllocator::ChunkOfPages *chunk() const 0128 { return m_allocator->chunkForAllocation(m_allocation); } 0129 diff --git a/src/qml/jsruntime/qv4executableallocator.cpp b/src/qml/jsruntime/qv4executableallocator.cpp 0130 index c836d121..8d7206e7 100644 0131 --- a/src/qml/jsruntime/qv4executableallocator.cpp 0132 +++ b/src/qml/jsruntime/qv4executableallocator.cpp 0133 @@ -45,12 +45,22 @@ 0134 0135 using namespace QV4; 0136 0137 -void *ExecutableAllocator::Allocation::exceptionHandler() const 0138 +void *ExecutableAllocator::Allocation::exceptionHandlerStart() const 0139 { 0140 return reinterpret_cast<void*>(addr); 0141 } 0142 0143 -void *ExecutableAllocator::Allocation::start() const 0144 +size_t ExecutableAllocator::Allocation::exceptionHandlerSize() const 0145 +{ 0146 + return QV4::exceptionHandlerSize(); 0147 +} 0148 + 0149 +void *ExecutableAllocator::Allocation::memoryStart() const 0150 +{ 0151 + return reinterpret_cast<void*>(addr); 0152 +} 0153 + 0154 +void *ExecutableAllocator::Allocation::codeStart() const 0155 { 0156 return reinterpret_cast<void*>(addr + exceptionHandlerSize()); 0157 } 0158 diff --git a/src/qml/jsruntime/qv4executableallocator_p.h b/src/qml/jsruntime/qv4executableallocator_p.h 0159 index 013c6d71..5c1f5101 100644 0160 --- a/src/qml/jsruntime/qv4executableallocator_p.h 0161 +++ b/src/qml/jsruntime/qv4executableallocator_p.h 0162 @@ -86,8 +86,14 @@ public: 0163 , free(true) 0164 {} 0165 0166 - void *exceptionHandler() const; 0167 - void *start() const; 0168 + void *memoryStart() const; 0169 + size_t memorySize() const { return size; } 0170 + 0171 + void *exceptionHandlerStart() const; 0172 + size_t exceptionHandlerSize() const; 0173 + 0174 + void *codeStart() const; 0175 + 0176 void invalidate() { addr = 0; } 0177 bool isValid() const { return addr != 0; } 0178 void deallocate(ExecutableAllocator *allocator); 0179 diff --git a/src/qml/jsruntime/qv4functiontable_win64.cpp b/src/qml/jsruntime/qv4functiontable_win64.cpp 0180 index fc13dc26..0cb98641 100644 0181 --- a/src/qml/jsruntime/qv4functiontable_win64.cpp 0182 +++ b/src/qml/jsruntime/qv4functiontable_win64.cpp 0183 @@ -106,7 +106,7 @@ struct ExceptionHandlerRecord 0184 void generateFunctionTable(Function *, JSC::MacroAssemblerCodeRef *codeRef) 0185 { 0186 ExceptionHandlerRecord *record = reinterpret_cast<ExceptionHandlerRecord *>( 0187 - codeRef->executableMemory()->exceptionHandler()); 0188 + codeRef->executableMemory()->exceptionHandlerStart()); 0189 0190 record->info.Version = 1; 0191 record->info.Flags = 0; 0192 @@ -136,7 +136,7 @@ void generateFunctionTable(Function *, JSC::MacroAssemblerCodeRef *codeRef) 0193 void destroyFunctionTable(Function *, JSC::MacroAssemblerCodeRef *codeRef) 0194 { 0195 ExceptionHandlerRecord *record = reinterpret_cast<ExceptionHandlerRecord *>( 0196 - codeRef->executableMemory()->exceptionHandler()); 0197 + codeRef->executableMemory()->exceptionHandlerStart()); 0198 if (!RtlDeleteFunctionTable(&record->handler)) { 0199 const unsigned int errorCode = GetLastError(); 0200 qWarning() << "Failed to remove win64 unwind hook. Error code:" << errorCode; 0201 -- 0202 2.37.3 0203