Allow building JavaScriptCore Mac+arm64 in public SDK build
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Jun 2020 01:28:17 +0000 (01:28 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Jun 2020 01:28:17 +0000 (01:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=213472

Reviewed by Sam Weinig.

.:

* Source/cmake/OptionsFTW.cmake:
* Source/cmake/WebKitFeatures.cmake:

Source/JavaScriptCore:

We used to only builld code for fast permission switching when using the
Apple internal SDK. However, with arm64 on macOS, this is no longer a viable
implementation strategy.

This patch makes it so we can build JSC on macOS+arm64 using the public Xcode
SDK.

- ENABLE_FAST_JIT_PERMISSIONS is removed. We now use runtime checks instead.
- In the new suite of OS betas, pthreads has added API for fast permissions
  switching. We now use this API instead of using the non-public SDK found in
  the kernel headers.
- We fall back to the separated W/X heaps when fast permissions checking is
  not supported. This all happens at runtime.

* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* assembler/ARM64Assembler.h:
(JSC::ARM64Assembler::fillNops):
* assembler/ARMv7Assembler.h:
(JSC::ARMv7Assembler::fillNops):
* assembler/FastJITPermissions.h: Added.
(useFastJITPermissions):
(threadSelfRestrictRWXToRW):
(threadSelfRestrictRWXToRX):
(fastJITPermissionsIsSupported):
* assembler/LinkBuffer.cpp:
(JSC::memcpyWrapper):
(JSC::LinkBuffer::copyCompactAndLinkCode):
* assembler/MIPSAssembler.h:
(JSC::MIPSAssembler::fillNops):
* assembler/MacroAssemblerARM64.h:
(JSC::MacroAssemblerARM64::link):
* assembler/MacroAssemblerARMv7.h:
(JSC::MacroAssemblerARMv7::link):
* jit/ExecutableAllocator.cpp:
(JSC::initializeJITPageReservation):
* jit/ExecutableAllocator.h:
(JSC::performJITMemcpy):
(JSC::useFastJITPermissions): Deleted.
* runtime/JSCConfig.h:
* runtime/Options.cpp:
(JSC::Options::recomputeDependentOptions):
* runtime/OptionsList.h:

Source/WTF:

* wtf/PlatformEnable.h:
* wtf/PlatformEnableCocoa.h:
* wtf/PlatformHave.h:

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

22 files changed:
ChangeLog
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/assembler/ARM64Assembler.h
Source/JavaScriptCore/assembler/ARMv7Assembler.h
Source/JavaScriptCore/assembler/FastJITPermissions.h [new file with mode: 0644]
Source/JavaScriptCore/assembler/LinkBuffer.cpp
Source/JavaScriptCore/assembler/MIPSAssembler.h
Source/JavaScriptCore/assembler/MacroAssemblerARM64.h
Source/JavaScriptCore/assembler/MacroAssemblerARMv7.h
Source/JavaScriptCore/jit/ExecutableAllocator.cpp
Source/JavaScriptCore/jit/ExecutableAllocator.h
Source/JavaScriptCore/runtime/JSCConfig.h
Source/JavaScriptCore/runtime/Options.cpp
Source/JavaScriptCore/runtime/OptionsList.h
Source/WTF/ChangeLog
Source/WTF/wtf/PlatformEnable.h
Source/WTF/wtf/PlatformEnableCocoa.h
Source/WTF/wtf/PlatformHave.h
Source/cmake/OptionsFTW.cmake
Source/cmake/WebKitFeatures.cmake

index e606c86..18be2fd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-06-22  Saam Barati  <sbarati@apple.com>
+
+        Allow building JavaScriptCore Mac+arm64 in public SDK build
+        https://bugs.webkit.org/show_bug.cgi?id=213472
+
+        Reviewed by Sam Weinig.
+
+        * Source/cmake/OptionsFTW.cmake:
+        * Source/cmake/WebKitFeatures.cmake:
+
 2020-06-18  Tim Horton  <timothy_horton@apple.com>
 
         Remove some vestiges of the 32-bit Plugin Process
index 9178d6c..c259108 100644 (file)
@@ -467,6 +467,7 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
     assembler/AssemblerCommon.h
     assembler/CPU.h
     assembler/CodeLocation.h
+    assembler/FastJITPermissions.h
     assembler/LinkBuffer.h
     assembler/MIPSAssembler.h
     assembler/MIPSRegisters.h
index 63529c4..50f8136 100644 (file)
@@ -1,3 +1,54 @@
+2020-06-22  Saam Barati  <sbarati@apple.com>
+
+        Allow building JavaScriptCore Mac+arm64 in public SDK build
+        https://bugs.webkit.org/show_bug.cgi?id=213472
+
+        Reviewed by Sam Weinig.
+
+        We used to only builld code for fast permission switching when using the
+        Apple internal SDK. However, with arm64 on macOS, this is no longer a viable
+        implementation strategy.
+        
+        This patch makes it so we can build JSC on macOS+arm64 using the public Xcode
+        SDK.
+        
+        - ENABLE_FAST_JIT_PERMISSIONS is removed. We now use runtime checks instead.
+        - In the new suite of OS betas, pthreads has added API for fast permissions
+          switching. We now use this API instead of using the non-public SDK found in
+          the kernel headers.
+        - We fall back to the separated W/X heaps when fast permissions checking is
+          not supported. This all happens at runtime.
+
+        * CMakeLists.txt:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * assembler/ARM64Assembler.h:
+        (JSC::ARM64Assembler::fillNops):
+        * assembler/ARMv7Assembler.h:
+        (JSC::ARMv7Assembler::fillNops):
+        * assembler/FastJITPermissions.h: Added.
+        (useFastJITPermissions):
+        (threadSelfRestrictRWXToRW):
+        (threadSelfRestrictRWXToRX):
+        (fastJITPermissionsIsSupported):
+        * assembler/LinkBuffer.cpp:
+        (JSC::memcpyWrapper):
+        (JSC::LinkBuffer::copyCompactAndLinkCode):
+        * assembler/MIPSAssembler.h:
+        (JSC::MIPSAssembler::fillNops):
+        * assembler/MacroAssemblerARM64.h:
+        (JSC::MacroAssemblerARM64::link):
+        * assembler/MacroAssemblerARMv7.h:
+        (JSC::MacroAssemblerARMv7::link):
+        * jit/ExecutableAllocator.cpp:
+        (JSC::initializeJITPageReservation):
+        * jit/ExecutableAllocator.h:
+        (JSC::performJITMemcpy):
+        (JSC::useFastJITPermissions): Deleted.
+        * runtime/JSCConfig.h:
+        * runtime/Options.cpp:
+        (JSC::Options::recomputeDependentOptions):
+        * runtime/OptionsList.h:
+
 2020-06-22  Tim Horton  <timothy_horton@apple.com>
 
         Disable the JS JIT when running in a translated process
index d45d2e7..9f851c1 100644 (file)
                525C9CDF220285830082DBFD /* WasmAirIRGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52847AD921FFB8630061A9DB /* WasmAirIRGenerator.cpp */; };
                52678F8F1A031009006A306D /* BasicBlockLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 52678F8D1A031009006A306D /* BasicBlockLocation.h */; settings = {ATTRIBUTES = (Private, ); }; };
                52678F911A04177C006A306D /* ControlFlowProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52678F901A04177C006A306D /* ControlFlowProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               5267CF82249316B10022BF6D /* FastJITPermissions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5267CF81249316AD0022BF6D /* FastJITPermissions.h */; settings = {ATTRIBUTES = (Private, ); }; };
                526AC4B71E977C5D003500E1 /* WasmCodeBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 526AC4B51E977C5D003500E1 /* WasmCodeBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
                527CE35422555FE500C6F382 /* JSToWasmICCallee.h in Headers */ = {isa = PBXBuildFile; fileRef = 527CE35322555FDD00C6F382 /* JSToWasmICCallee.h */; };
                52847ADC21FFB8690061A9DB /* WasmAirIRGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 52847ADA21FFB8630061A9DB /* WasmAirIRGenerator.h */; };
                52678F8C1A031009006A306D /* BasicBlockLocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BasicBlockLocation.cpp; sourceTree = "<group>"; };
                52678F8D1A031009006A306D /* BasicBlockLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BasicBlockLocation.h; sourceTree = "<group>"; };
                52678F901A04177C006A306D /* ControlFlowProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ControlFlowProfiler.h; sourceTree = "<group>"; };
+               5267CF81249316AD0022BF6D /* FastJITPermissions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FastJITPermissions.h; sourceTree = "<group>"; };
                526AC4B41E977C5D003500E1 /* WasmCodeBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmCodeBlock.cpp; sourceTree = "<group>"; };
                526AC4B51E977C5D003500E1 /* WasmCodeBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmCodeBlock.h; sourceTree = "<group>"; };
                5272987B235FC8BA005C982C /* GCMemoryOperations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GCMemoryOperations.h; sourceTree = "<group>"; };
                                FE1BD0201E72027000134BC9 /* CellProfile.h */,
                                0F4F11E7209BCDA100709654 /* CompilerTimingScope.cpp */,
                                0F4F11E6209BCDA100709654 /* CompilerTimingScope.h */,
+                               52EED7922492B868008F4C93 /* FunctionAllowlist.cpp */,
+                               52EED7932492B868008F4C93 /* FunctionAllowlist.h */,
                                FE4BFF291AD476E700088F87 /* FunctionOverrides.cpp */,
                                FE4BFF2A1AD476E700088F87 /* FunctionOverrides.h */,
                                FE1BD0221E72052F00134BC9 /* HeapVerifier.cpp */,
                                FE1BD0231E72052F00134BC9 /* HeapVerifier.h */,
-                               52EED7922492B868008F4C93 /* FunctionAllowlist.cpp */,
-                               52EED7932492B868008F4C93 /* FunctionAllowlist.h */,
                                FEC5797423105F4200BCA83F /* Integrity.cpp */,
                                FEC5797523105F4300BCA83F /* Integrity.h */,
                                FEC579772310954B00BCA83F /* IntegrityInlines.h */,
                                52335628225EB8E900268BD2 /* CPU.cpp */,
                                0F30D7BF1D95D62F0053089D /* CPU.h */,
                                0F37308E1C0CD68500052BFA /* DisallowMacroScratchRegisterUsage.h */,
+                               5267CF81249316AD0022BF6D /* FastJITPermissions.h */,
                                0FF4275615914A20004CB9FF /* LinkBuffer.cpp */,
                                86D3B3C110159D7F002865E7 /* LinkBuffer.h */,
                                0FEB3ECE16237F6700AB67AD /* MacroAssembler.cpp */,
                                A767B5B617A0B9650063D940 /* DFGLoopPreHeaderCreationPhase.h in Headers */,
                                0F5874EE194FEB1200AAB2C1 /* DFGMayExit.h in Headers */,
                                0F2BDC451522801B00CD8910 /* DFGMinifiedGraph.h in Headers */,
-                               52EED7942492B870008F4C93 /* FunctionAllowlist.h in Headers */,
                                0F2E892D16D02BAF009E4FD2 /* DFGMinifiedID.h in Headers */,
                                E3850B15226ED641009ABF9C /* DFGMinifiedIDInlines.h in Headers */,
                                0F2BDC461522802000CD8910 /* DFGMinifiedNode.h in Headers */,
                                0F3AC754188E5EC80032029F /* ExitingJITType.h in Headers */,
                                0FB105861675481200F8AB6E /* ExitKind.h in Headers */,
                                0F0B83AB14BCF5BB00885B4F /* ExpressionRangeInfo.h in Headers */,
+                               5267CF82249316B10022BF6D /* FastJITPermissions.h in Headers */,
                                0FEC3C571F33A45300F59B6C /* FastMallocAlignedMemoryAllocator.h in Headers */,
                                CECFAD372372DAD400291599 /* FileBasedFuzzerAgent.h in Headers */,
                                CE20BD05237D3E230046E520 /* FileBasedFuzzerAgentBase.h in Headers */,
                                0F666EC1183566F900D017F1 /* FullBytecodeLiveness.h in Headers */,
                                AD4252511E5D0E14009D2A97 /* FullCodeOrigin.h in Headers */,
                                2A83638A18D7D0FE0000EBCC /* FullGCActivityCallback.h in Headers */,
+                               52EED7942492B870008F4C93 /* FunctionAllowlist.h in Headers */,
                                14AD910D1DCA92940014F9FE /* FunctionCodeBlock.h in Headers */,
                                BC18C4040E16F5CD00B34460 /* FunctionConstructor.h in Headers */,
                                147341D81DC02F9900AA29BA /* FunctionExecutable.h in Headers */,
index 3599fe6..63cbb18 100644 (file)
@@ -1490,7 +1490,7 @@ public:
     using CopyFunction = void*(&)(void*, const void*, size_t);
 
     template <CopyFunction copy>
-    static void fillNops(void* base, size_t size)
+    ALWAYS_INLINE static void fillNops(void* base, size_t size)
     {
         RELEASE_ASSERT(!(size % sizeof(int32_t)));
         size_t n = size / sizeof(int32_t);
index bed30cc..3144a29 100644 (file)
@@ -1976,7 +1976,7 @@ public:
     using CopyFunction = void*(&)(void*, const void*, size_t);
 
     template <CopyFunction copy>
-    static void fillNops(void* base, size_t size)
+    ALWAYS_INLINE static void fillNops(void* base, size_t size)
     {
         RELEASE_ASSERT(!(size % sizeof(int16_t)));
 
diff --git a/Source/JavaScriptCore/assembler/FastJITPermissions.h b/Source/JavaScriptCore/assembler/FastJITPermissions.h
new file mode 100644 (file)
index 0000000..a563d09
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if OS(DARWIN) && CPU(ARM64)
+
+#include <wtf/Platform.h>
+
+#if HAVE(PTHREAD_JIT_PERMISSIONS_API)
+#include <pthread.h>
+#elif USE(APPLE_INTERNAL_SDK)
+#include <os/thread_self_restrict.h> 
+#endif
+
+static ALWAYS_INLINE bool useFastJITPermissions()
+{
+#if CPU(ARM64E)
+    return true;
+#elif HAVE(PTHREAD_JIT_PERMISSIONS_API) 
+    return !!pthread_jit_write_protect_supported_np();
+#elif USE(APPLE_INTERNAL_SDK)
+    return !!os_thread_self_restrict_rwx_is_supported();
+#else
+    return false;
+#endif
+}
+
+static ALWAYS_INLINE void threadSelfRestrictRWXToRW()
+{
+    ASSERT(useFastJITPermissions());
+
+#if HAVE(PTHREAD_JIT_PERMISSIONS_API) 
+    pthread_jit_write_protect_np(false);
+#elif USE(APPLE_INTERNAL_SDK)
+    os_thread_self_restrict_rwx_to_rw();
+#else
+    bool tautologyToIgnoreWarning = true;
+    if (tautologyToIgnoreWarning)
+        RELEASE_ASSERT_NOT_REACHED();
+#endif
+}
+
+static ALWAYS_INLINE void threadSelfRestrictRWXToRX()
+{
+    ASSERT(useFastJITPermissions());
+
+#if HAVE(PTHREAD_JIT_PERMISSIONS_API) 
+    pthread_jit_write_protect_np(true);
+#elif USE(APPLE_INTERNAL_SDK)
+    os_thread_self_restrict_rwx_to_rx();
+#else
+    bool tautologyToIgnoreWarning = true;
+    if (tautologyToIgnoreWarning)
+        RELEASE_ASSERT_NOT_REACHED();
+#endif
+}
+
+#else // Not OS(DARWIN) && CPU(ARM64)
+
+constexpr bool fastJITPermissionsIsSupported()
+{
+    return false;
+}
+
+constexpr bool useFastJITPermissions()
+{
+    return false;
+}
+
+NO_RETURN_DUE_TO_CRASH static void threadSelfRestrictRWXToRW()
+{
+    CRASH();
+}
+
+NO_RETURN_DUE_TO_CRASH static void threadSelfRestrictRWXToRX()
+{
+    CRASH();
+}
+
+#endif // OS(DARWIN) && CPU(ARM64)
index 902189a..b6577a9 100644 (file)
@@ -119,27 +119,13 @@ LinkBuffer::CodeRef<LinkBufferPtrTag> LinkBuffer::finalizeCodeWithDisassemblyImp
 }
 
 #if ENABLE(BRANCH_COMPACTION)
+
 #if CPU(ARM64E)
 #define ENABLE_VERIFY_JIT_HASH 1
 #else
 #define ENABLE_VERIFY_JIT_HASH 0
 #endif
 
-#if ENABLE(FAST_JIT_PERMISSIONS) && !ENABLE(SEPARATED_WX_HEAP)
-#   define IF_FAST_JIT_PERMISSIONS(thenStmt) thenStmt
-#   define IF_FAST_JIT_PERMISSIONS_ELSE(thenStmt, elseStmt) thenStmt
-#elif ENABLE(FAST_JIT_PERMISSIONS)
-#   define IF_FAST_JIT_PERMISSIONS(thenStmt) if (useFastJITPermissions()) \
-        thenStmt
-#   define IF_FAST_JIT_PERMISSIONS_ELSE(thenStmt, elseStmt) if (useFastJITPermissions()) \
-            thenStmt; \
-        else \
-            elseStmt
-#else
-#   define IF_FAST_JIT_PERMISSIONS(thenStmt)
-#   define IF_FAST_JIT_PERMISSIONS_ELSE(thenStmt, elseStmt) elseStmt
-#endif
-
 class BranchCompactionLinkBuffer;
 
 using ThreadSpecificBranchCompactionLinkBuffer = ThreadSpecific<BranchCompactionLinkBuffer, WTF::CanBeGCThread::True>;
@@ -237,6 +223,13 @@ static ALWAYS_INLINE void recordLinkOffsets(AssemblerData& assemblerData, int32_
         offsets[ptr++] = offset;
 }
 
+// We use this to prevent compile errors on some platforms that are unhappy
+// about the signature of the system's memcpy.
+ALWAYS_INLINE void* memcpyWrapper(void* dst, const void* src, size_t bytes)
+{
+    return memcpy(dst, src, bytes);
+}
+
 template <typename InstructionType>
 void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, JITCompilationEffort effort)
 {
@@ -268,7 +261,8 @@ void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, JITCompi
     int writePtr = 0;
     unsigned jumpCount = jumpsToLink.size();
 
-    IF_FAST_JIT_PERMISSIONS(os_thread_self_restrict_rwx_to_rw());
+    if (useFastJITPermissions())
+        threadSelfRestrictRWXToRW();
 
     if (m_shouldPerformBranchCompaction) {
         for (unsigned i = 0; i < jumpCount; ++i) {
@@ -356,18 +350,24 @@ void LinkBuffer::copyCompactAndLinkCode(MacroAssembler& macroAssembler, JITCompi
     for (unsigned i = 0; i < jumpCount; ++i) {
         uint8_t* location = codeOutData + jumpsToLink[i].from();
         uint8_t* target = codeOutData + jumpsToLink[i].to() - executableOffsetFor(jumpsToLink[i].to());
-        IF_FAST_JIT_PERMISSIONS_ELSE(MacroAssembler::link<memcpy>(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target), \
-            MacroAssembler::link<performJITMemcpy>(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target));
+        if (useFastJITPermissions())
+            MacroAssembler::link<memcpyWrapper>(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target);
+        else
+            MacroAssembler::link<performJITMemcpy>(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target);
     }
 
     size_t compactSize = writePtr + initialSize - readPtr;
     if (!m_executableMemory) {
         size_t nopSizeInBytes = initialSize - compactSize;
-        IF_FAST_JIT_PERMISSIONS_ELSE(Assembler::fillNops<memcpy>(outData + compactSize, nopSizeInBytes), \
-            Assembler::fillNops<performJITMemcpy>(outData + compactSize, nopSizeInBytes));
+
+        if (useFastJITPermissions())
+            Assembler::fillNops<memcpyWrapper>(outData + compactSize, nopSizeInBytes);
+        else
+            Assembler::fillNops<performJITMemcpy>(outData + compactSize, nopSizeInBytes);
     }
 
-    IF_FAST_JIT_PERMISSIONS(os_thread_self_restrict_rwx_to_rx());
+    if (useFastJITPermissions())
+        threadSelfRestrictRWXToRX();
 
     if (m_executableMemory) {
         m_size = compactSize;
index bf8ba89..1824c52 100644 (file)
@@ -165,7 +165,7 @@ public:
     using CopyFunction = void*(&)(void*, const void*, size_t);
 
     template <CopyFunction copy>
-    static void fillNops(void* base, size_t size)
+    ALWAYS_INLINE static void fillNops(void* base, size_t size)
     {
         UNUSED_PARAM(copy);
         RELEASE_ASSERT(!(size % sizeof(int32_t)));
index 3bd2bac..53a099c 100644 (file)
@@ -86,8 +86,9 @@ public:
     static JumpLinkType computeJumpType(JumpType jumpType, const uint8_t* from, const uint8_t* to) { return Assembler::computeJumpType(jumpType, from, to); }
     static JumpLinkType computeJumpType(LinkRecord& record, const uint8_t* from, const uint8_t* to) { return Assembler::computeJumpType(record, from, to); }
     static int jumpSizeDelta(JumpType jumpType, JumpLinkType jumpLinkType) { return Assembler::jumpSizeDelta(jumpType, jumpLinkType); }
+
     template <Assembler::CopyFunction copy>
-    static void link(LinkRecord& record, uint8_t* from, const uint8_t* fromInstruction, uint8_t* to) { return Assembler::link<copy>(record, from, fromInstruction, to); }
+    ALWAYS_INLINE static void link(LinkRecord& record, uint8_t* from, const uint8_t* fromInstruction, uint8_t* to) { return Assembler::link<copy>(record, from, fromInstruction, to); }
 
     static bool isCompactPtrAlignedAddressOffset(ptrdiff_t value)
     {
index 399c70d..704036c 100644 (file)
@@ -71,8 +71,9 @@ public:
     static JumpLinkType computeJumpType(JumpType jumpType, const uint8_t* from, const uint8_t* to) { return ARMv7Assembler::computeJumpType(jumpType, from, to); }
     static JumpLinkType computeJumpType(LinkRecord& record, const uint8_t* from, const uint8_t* to) { return ARMv7Assembler::computeJumpType(record, from, to); }
     static int jumpSizeDelta(JumpType jumpType, JumpLinkType jumpLinkType) { return ARMv7Assembler::jumpSizeDelta(jumpType, jumpLinkType); }
+
     template <Assembler::CopyFunction copy>
-    static void link(LinkRecord& record, uint8_t* from, const uint8_t* fromInstruction, uint8_t* to) { return ARMv7Assembler::link<copy>(record, from, fromInstruction, to); }
+    ALWAYS_INLINE static void link(LinkRecord& record, uint8_t* from, const uint8_t* fromInstruction, uint8_t* to) { return ARMv7Assembler::link<copy>(record, from, fromInstruction, to); }
 
     struct ArmAddress {
         enum AddressType {
index e9771b9..ff9a8af 100644 (file)
@@ -334,27 +334,21 @@ static ALWAYS_INLINE JITReservation initializeJITPageReservation()
         ASSERT(reservation.pageReservation.size() == reservation.size);
         reservation.base = reservation.pageReservation.base();
 
-#if ENABLE(FAST_JIT_PERMISSIONS) && !ENABLE(SEPARATED_WX_HEAP)
-        RELEASE_ASSERT(os_thread_self_restrict_rwx_is_supported());
-        os_thread_self_restrict_rwx_to_rx();
-
-#else // not ENABLE(FAST_JIT_PERMISSIONS) or ENABLE(SEPARATED_WX_HEAP)
-#if ENABLE(FAST_JIT_PERMISSIONS)
-        if (os_thread_self_restrict_rwx_is_supported()) {
-            g_jscConfig.useFastPermisionsJITCopy = true;
-            os_thread_self_restrict_rwx_to_rx();
-        } else
-#endif
-        if (Options::useSeparatedWXHeap()) {
+        bool fastJITPermissionsIsSupported = useFastJITPermissions();
+        if (fastJITPermissionsIsSupported)
+            threadSelfRestrictRWXToRX();
+
+#if ENABLE(SEPARATED_WX_HEAP)
+        if (!fastJITPermissionsIsSupported) {
             // First page of our JIT allocation is reserved.
             ASSERT(reservation.size >= pageSize() * 2);
             reservation.base = (void*)((uintptr_t)(reservation.base) + pageSize());
             reservation.size -= pageSize();
             initializeSeparatedWXHeaps(reservation.pageReservation.base(), pageSize(), reservation.base, reservation.size);
         }
-#endif // not ENABLE(FAST_JIT_PERMISSIONS) or ENABLE(SEPARATED_WX_HEAP)
-        void* reservationEnd = reinterpret_cast<uint8_t*>(reservation.base) + reservation.size;
+#endif
 
+        void* reservationEnd = reinterpret_cast<uint8_t*>(reservation.base) + reservation.size;
         g_jscConfig.startExecutableMemory = tagCodePtr<ExecutableMemoryPtrTag>(reservation.base);
         g_jscConfig.endExecutableMemory = tagCodePtr<ExecutableMemoryPtrTag>(reservationEnd);
     }
index 5bc3665..2a54432 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "FastJITPermissions.h"
 #include "JITCompilationEffort.h"
 #include "JSCConfig.h"
 #include "JSCPtrTag.h"
@@ -46,9 +47,6 @@
 #include <sys/cachectl.h>
 #endif
 
-#if ENABLE(FAST_JIT_PERMISSIONS)
-#include <os/thread_self_restrict.h> 
-#endif
 #define JIT_ALLOCATOR_LARGE_ALLOC_SIZE (pageSize() * 4)
 
 #define EXECUTABLE_POOL_WRITABLE true
@@ -113,17 +111,6 @@ JS_EXPORT_PRIVATE bool isJITPC(void* pc);
 
 JS_EXPORT_PRIVATE void dumpJITMemory(const void*, const void*, size_t);
 
-static ALWAYS_INLINE bool useFastJITPermissions()
-{
-#if ENABLE(FAST_JIT_PERMISSIONS) && !ENABLE(SEPARATED_WX_HEAP)
-    return true;
-#elif ENABLE(FAST_JIT_PERMISSIONS)
-    return g_jscConfig.useFastPermisionsJITCopy;
-#else
-    return false;
-#endif
-}
-
 static ALWAYS_INLINE void* performJITMemcpy(void *dst, const void *src, size_t n)
 {
 #if CPU(ARM64)
@@ -132,20 +119,18 @@ static ALWAYS_INLINE void* performJITMemcpy(void *dst, const void *src, size_t n
     RELEASE_ASSERT(roundUpToMultipleOf<instructionSize>(src) == src);
 #endif
     if (isJITPC(dst)) {
+        RELEASE_ASSERT(!Gigacage::contains(src));
         RELEASE_ASSERT(reinterpret_cast<uint8_t*>(dst) + n <= endOfFixedExecutableMemoryPool());
 
         if (UNLIKELY(Options::dumpJITMemoryPath()))
             dumpJITMemory(dst, src, n);
-#if ENABLE(FAST_JIT_PERMISSIONS)
-        if (useFastJITPermissions())
-        {
-            os_thread_self_restrict_rwx_to_rw();
+
+        if (useFastJITPermissions()) {
+            threadSelfRestrictRWXToRW();
             memcpy(dst, src, n);
-            RELEASE_ASSERT(!Gigacage::contains(src));
-            os_thread_self_restrict_rwx_to_rx();
+            threadSelfRestrictRWXToRX();
             return dst;
         }
-#endif // ENABLE(FAST_JIT_PERMISSIONS)
 
 #if ENABLE(SEPARATED_WX_HEAP)
         if (g_jscConfig.jitWriteSeparateHeaps) {
index d2cbbe4..c72dac0 100644 (file)
@@ -79,7 +79,6 @@ struct Config {
 
 #if ENABLE(SEPARATED_WX_HEAP)
     JITWriteSeparateHeapsFunction jitWriteSeparateHeaps;
-    bool useFastPermisionsJITCopy;
 #endif
 
     OptionsStorage options;
index d6fc29a..0c75f49 100644 (file)
@@ -482,14 +482,6 @@ void Options::recomputeDependentOptions()
         Options::maximumEvalCacheableSourceLength() = 150000;
         Options::useConcurrentJIT() = false;
     }
-#if ENABLE(SEPARATED_WX_HEAP)
-    // Override globally for now. Longer term we'll just make the default
-    // be to have this option enabled, and have platforms that don't support
-    // it just silently use a single mapping.
-    Options::useSeparatedWXHeap() = true;
-#else
-    Options::useSeparatedWXHeap() = false;
-#endif
 
     if (Options::alwaysUseShadowChicken())
         Options::maximumInliningDepth() = 1;
index f12e11c..5dcf428 100644 (file)
@@ -96,7 +96,6 @@ constexpr bool enableWebAssemblyStreamingApi = false;
     \
     v(Bool, crashIfCantAllocateJITMemory, false, Normal, nullptr) \
     v(Unsigned, jitMemoryReservationSize, 0, Normal, "Set this number to change the executable allocation size in ExecutableAllocatorFixedVMPool. (In bytes.)") \
-    v(Bool, useSeparatedWXHeap, false, Normal, nullptr) \
     \
     v(Bool, forceCodeBlockLiveness, false, Normal, nullptr) \
     v(Bool, forceICFailure, false, Normal, nullptr) \
index a2ee202..07eb4af 100644 (file)
@@ -1,3 +1,14 @@
+2020-06-22  Saam Barati  <sbarati@apple.com>
+
+        Allow building JavaScriptCore Mac+arm64 in public SDK build
+        https://bugs.webkit.org/show_bug.cgi?id=213472
+
+        Reviewed by Sam Weinig.
+
+        * wtf/PlatformEnable.h:
+        * wtf/PlatformEnableCocoa.h:
+        * wtf/PlatformHave.h:
+
 2020-06-22  Timothy Horton  <timothy_horton@apple.com>
 
         Fix the build
index f70cfc0..71cd512 100644 (file)
 #define ENABLE_ENCRYPTED_MEDIA 0
 #endif
 
-#if !defined(ENABLE_FAST_JIT_PERMISSIONS)
-#define ENABLE_FAST_JIT_PERMISSIONS 0
-#endif
-
 #if !defined(ENABLE_FILTERS_LEVEL_2)
 #define ENABLE_FILTERS_LEVEL_2 0
 #endif
index b957d3f..fcaf60e 100644 (file)
 #define ENABLE_DRAG_SUPPORT 0
 #endif
 
-/* FIXME: This should probably be HAVE_FAST_JIT_PERMISSIONS and may be entirely unnecessary due to runtime checking support via os_thread_self_restrict_rwx_is_supported(). */
-#if !defined(ENABLE_FAST_JIT_PERMISSIONS) && CPU(ARM64) && !(OS(TVOS) || OS(WATCHOS)) && USE(APPLE_INTERNAL_SDK)
-#define ENABLE_FAST_JIT_PERMISSIONS 1
-#endif
-
 #if !defined(ENABLE_FILE_REPLACEMENT)
 #define ENABLE_FILE_REPLACEMENT 1
 #endif
 #define ENABLE_SEC_ITEM_SHIM 1
 #endif
 
-#if !defined(ENABLE_SEPARATED_WX_HEAP) && PLATFORM(IOS_FAMILY) && CPU(ARM64) && (!ENABLE(FAST_JIT_PERMISSIONS) || !CPU(ARM64E))
+#if !defined(ENABLE_SEPARATED_WX_HEAP) && PLATFORM(IOS_FAMILY) && CPU(ARM64) && !CPU(ARM64E)
 #define ENABLE_SEPARATED_WX_HEAP 1
 #endif
 
index 52563be..48c0df3 100644 (file)
 #if OS(DARWIN) && CPU(X86_64) && ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101600) || (PLATFORM(MACCATALYST) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000))
 #define HAVE_CPU_TRANSLATION_CAPABILITY 1
 #endif
+
+#if (((PLATFORM(IOS) || PLATFORM(MACCATALYST)) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000) \
+    || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 70000) \
+    || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 140000) \
+    || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000))
+#define HAVE_PTHREAD_JIT_PERMISSIONS_API 1
+#endif
index a8be554..5a73e6c 100644 (file)
@@ -76,7 +76,6 @@ WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS_PAINTING_API PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS_SELECTORS_LEVEL4 PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CURSOR_VISIBILITY PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_DRAG_SUPPORT PRIVATE ON)
-WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FAST_JIT_PERMISSIONS PRIVATE OFF)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FILTERS_LEVEL_2 PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FTL_JIT PRIVATE OFF)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FTPDIR PRIVATE ON)
index c934cab..e2aa396 100644 (file)
@@ -136,7 +136,6 @@ macro(WEBKIT_OPTION_BEGIN)
     WEBKIT_OPTION_DEFINE(ENABLE_DRAG_SUPPORT "Toggle support of drag actions (including selection of text with mouse)" PRIVATE OFF)
     WEBKIT_OPTION_DEFINE(ENABLE_ENCRYPTED_MEDIA "Toggle EME V3 support" PRIVATE OFF)
     WEBKIT_OPTION_DEFINE(ENABLE_EXPERIMENTAL_FEATURES "Enable experimental features" PRIVATE OFF)
-    WEBKIT_OPTION_DEFINE(ENABLE_FAST_JIT_PERMISSIONS "Toggle fast JIT permissions support" PRIVATE OFF)
     WEBKIT_OPTION_DEFINE(ENABLE_FILTERS_LEVEL_2 "Toggle Filters Module Level 2" PRIVATE OFF)
     WEBKIT_OPTION_DEFINE(ENABLE_FTL_JIT "Toggle FTL JIT support" PRIVATE ${ENABLE_FTL_DEFAULT})
     WEBKIT_OPTION_DEFINE(ENABLE_FTPDIR "Toggle FTP Directory support" PRIVATE ON)