LinkBuffer::copyCompactAndLinkCode() needs to be aware of ENABLE(SEPARATED_WX_HEAP).
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Dec 2018 23:14:31 +0000 (23:14 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Dec 2018 23:14:31 +0000 (23:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192569
<rdar://problem/45615617>

Reviewed by Saam Barati.

* assembler/LinkBuffer.cpp:
(JSC::LinkBuffer::copyCompactAndLinkCode):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239055 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/assembler/LinkBuffer.cpp

index 1c79958..327678e 100644 (file)
@@ -1,3 +1,14 @@
+2018-12-10  Mark Lam  <mark.lam@apple.com>
+
+        LinkBuffer::copyCompactAndLinkCode() needs to be aware of ENABLE(SEPARATED_WX_HEAP).
+        https://bugs.webkit.org/show_bug.cgi?id=192569
+        <rdar://problem/45615617>
+
+        Reviewed by Saam Barati.
+
+        * assembler/LinkBuffer.cpp:
+        (JSC::LinkBuffer::copyCompactAndLinkCode):
+
 2018-12-10  Caio Lima  <ticaiolima@gmail.com>
 
         [BigInt] Add ValueMul into DFG
index b236a5c..7f38521 100644 (file)
 
 namespace JSC {
 
+#if ENABLE(SEPARATED_WX_HEAP)
+extern JS_EXPORT_PRIVATE bool useFastPermisionsJITCopy;
+#endif // ENABLE(SEPARATED_WX_HEAP)
+
 bool shouldDumpDisassemblyFor(CodeBlock* codeBlock)
 {
     if (codeBlock && JITCode::isOptimizingJIT(codeBlock->jitType()) && Options::dumpDFGDisassembly())
@@ -116,6 +120,14 @@ static ALWAYS_INLINE void recordLinkOffsets(AssemblerData& assemblerData, int32_
 template <typename InstructionType>
 void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, void* ownerUID, JITCompilationEffort effort)
 {
+#if CPU(ARM64E) && ENABLE(FAST_JIT_PERMISSIONS)
+#if ENABLE(SEPARATED_WX_HEAP)
+    const bool isUsingFastPermissionsJITCopy = useFastPermisionsJITCopy;
+#else
+    const bool isUsingFastPermissionsJITCopy = true;
+#endif
+#endif
+
     allocate(macroAssembler, ownerUID, effort);
     const size_t initialSize = macroAssembler.m_assembler.codeSize();
     if (didFailToAllocate())
@@ -130,6 +142,11 @@ void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, void* ow
     const ARM64EHash assemblerBufferHash = macroAssembler.m_assembler.buffer().hash();
     ARM64EHash verifyUncompactedHash(assemblerBufferHash.randomSeed());
     uint8_t* outData = codeOutData;
+#if ENABLE(SEPARATED_WX_HEAP)
+    AssemblerData outBuffer(m_size);
+    if (!isUsingFastPermissionsJITCopy)
+        outData = reinterpret_cast<uint8_t*>(outBuffer.buffer());
+#endif // ENABLE(SEPARATED_WX_HEAP)
 #else
     AssemblerData outBuffer(m_size);
     uint8_t* outData = reinterpret_cast<uint8_t*>(outBuffer.buffer());
@@ -144,7 +161,8 @@ void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, void* ow
     unsigned jumpCount = jumpsToLink.size();
 
 #if CPU(ARM64E) && ENABLE(FAST_JIT_PERMISSIONS)
-    os_thread_self_restrict_rwx_to_rw();
+    if (isUsingFastPermissionsJITCopy)
+        os_thread_self_restrict_rwx_to_rw();
 #endif
 
     if (m_shouldPerformBranchCompaction) {
@@ -240,6 +258,8 @@ void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, void* ow
     for (unsigned i = 0; i < jumpCount; ++i) {
 #if CPU(ARM64E) && ENABLE(FAST_JIT_PERMISSIONS)
         auto memcpyFunction = memcpy;
+        if (!isUsingFastPermissionsJITCopy)
+            memcpyFunction = performJITMemcpy;
 #else
         auto memcpyFunction = performJITMemcpy;
 #endif
@@ -256,7 +276,8 @@ void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, void* ow
     }
 
 #if CPU(ARM64E) && ENABLE(FAST_JIT_PERMISSIONS)
-    os_thread_self_restrict_rwx_to_rx();
+    if (isUsingFastPermissionsJITCopy)
+        os_thread_self_restrict_rwx_to_rx();
 #endif
 
     if (m_executableMemory) {
@@ -268,7 +289,12 @@ void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, void* ow
     ASSERT(codeOutData != outData);
     performJITMemcpy(codeOutData, outData, m_size);
 #else
-    ASSERT(codeOutData == outData);
+    if (isUsingFastPermissionsJITCopy)
+        ASSERT(codeOutData == outData);
+    else {
+        ASSERT(codeOutData != outData);
+        performJITMemcpy(codeOutData, outData, m_size);
+    }
 #endif
 
     jumpsToLink.clear();
@@ -280,7 +306,7 @@ void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, void* ow
     dumpCode(codeOutData, m_size);
 #endif
 }
-#endif
+#endif // ENABLE(BRANCH_COMPACTION)
 
 
 void LinkBuffer::linkCode(MacroAssembler& macroAssembler, void* ownerUID, JITCompilationEffort effort)