Title: [249556] trunk/Source
Revision
249556
Author
mark....@apple.com
Date
2019-09-05 17:03:52 -0700 (Thu, 05 Sep 2019)

Log Message

Refactor the Gigacage code to require less pointer casting.
https://bugs.webkit.org/show_bug.cgi?id=201521

Reviewed by Saam Barati.

Source/bmalloc:

1. Define a Gigacage::Config struct instead of hacking around a g_gigacageBasePtrs
   array of bytes.
2. Change Gigacage::basePtr() to return a pointer instead of a reference to the
   requested basePtr.  Instead, make it explicit when the client is trying to
   take the address of the basePtr, or setting it.
3. Renamed wasEnabled() to isEnabled() because it returns the present state of the
   flag, not some past state.

* bmalloc/Gigacage.cpp:
(Gigacage::bmalloc::protectGigacageBasePtrs):
(Gigacage::bmalloc::unprotectGigacageBasePtrs):
(Gigacage::bmalloc::runwaySize):
(Gigacage::ensureGigacage):
(Gigacage::disablePrimitiveGigacage):
(Gigacage::addPrimitiveDisableCallback):
(Gigacage::primitiveGigacageDisabled):
* bmalloc/Gigacage.h:
(Gigacage::name):
(Gigacage::Config::basePtr const):
(Gigacage::Config::setBasePtr):
(Gigacage::isEnabled):
(Gigacage::basePtr):
(Gigacage::addressOfBasePtr):
(Gigacage::size):
(Gigacage::caged):
(Gigacage::wasEnabled): Deleted.
(Gigacage::setWasEnabled): Deleted.
(Gigacage::basePtrs): Deleted.
* bmalloc/HeapKind.h:
(bmalloc::heapKind):
(bmalloc::isActiveHeapKindAfterEnsuringGigacage):
(bmalloc::mapToActiveHeapKindAfterEnsuringGigacage):

Source/_javascript_Core:

Change LLInt's loadCagedJSValue() to skip the caging if Gigacage is not enabled
in the build.  This allows us to remove the unneeded stubs in WTF Gigacage.h.

* jit/AssemblyHelpers.h:
(JSC::AssemblyHelpers::cageConditionally):
* llint/LowLevelInterpreter.asm:
* llint/LowLevelInterpreter64.asm:
* runtime/VM.h:
(JSC::VM::gigacageAuxiliarySpace):

Source/WTF:

Remove some unneeded stubs in WTF Gigacage.h.

* wtf/Gigacage.cpp:
* wtf/Gigacage.h:
(Gigacage::name):
(Gigacage::isEnabled):
(Gigacage::basePtr): Deleted.
(Gigacage::basePtrs): Deleted.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (249555 => 249556)


--- trunk/Source/_javascript_Core/ChangeLog	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-09-06 00:03:52 UTC (rev 249556)
@@ -1,3 +1,20 @@
+2019-09-05  Mark Lam  <mark....@apple.com>
+
+        Refactor the Gigacage code to require less pointer casting.
+        https://bugs.webkit.org/show_bug.cgi?id=201521
+
+        Reviewed by Saam Barati.
+
+        Change LLInt's loadCagedJSValue() to skip the caging if Gigacage is not enabled
+        in the build.  This allows us to remove the unneeded stubs in WTF Gigacage.h.
+
+        * jit/AssemblyHelpers.h:
+        (JSC::AssemblyHelpers::cageConditionally):
+        * llint/LowLevelInterpreter.asm:
+        * llint/LowLevelInterpreter64.asm:
+        * runtime/VM.h:
+        (JSC::VM::gigacageAuxiliarySpace):
+
 2019-09-05  Yusuke Suzuki  <ysuz...@apple.com>
 
         Unreviewed, follow-up after r249530 and r249509

Modified: trunk/Source/_javascript_Core/jit/AssemblyHelpers.h (249555 => 249556)


--- trunk/Source/_javascript_Core/jit/AssemblyHelpers.h	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/_javascript_Core/jit/AssemblyHelpers.h	2019-09-06 00:03:52 UTC (rev 249556)
@@ -1595,7 +1595,7 @@
                 if (length == scratch)
                     scratch = getCachedMemoryTempRegisterIDAndInvalidate();
 #endif
-                loadPtr(&Gigacage::basePtr(kind), scratch);
+                loadPtr(Gigacage::addressOfBasePtr(kind), scratch);
                 Jump done = branchTest64(Zero, scratch);
 #if CPU(ARM64E)
                 GPRReg tempReg = getCachedDataTempRegisterIDAndInvalidate();

Modified: trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm (249555 => 249556)


--- trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm	2019-09-06 00:03:52 UTC (rev 249556)
@@ -298,6 +298,11 @@
     end
 end
 
+if GIGACAGE_ENABLED
+    const GigacagePrimitiveBasePtrOffset = constexpr Gigacage::offsetOfPrimitiveGigacageBasePtr
+    const GigacageJSValueBasePtrOffset = constexpr Gigacage::offsetOfJSValueGigacageBasePtr
+end
+
 macro dispatch(advanceReg)
     addp advanceReg, PC
     nextInstruction()

Modified: trunk/Source/_javascript_Core/llint/LowLevelInterpreter64.asm (249555 => 249556)


--- trunk/Source/_javascript_Core/llint/LowLevelInterpreter64.asm	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/_javascript_Core/llint/LowLevelInterpreter64.asm	2019-09-06 00:03:52 UTC (rev 249556)
@@ -440,7 +440,7 @@
         const source = ptr
     end
     if GIGACAGE_ENABLED
-        cage(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, source, scratch)
+        cage(_g_gigacageConfig + Gigacage::Config::basePtrs + GigacagePrimitiveBasePtrOffset, constexpr Gigacage::primitiveGigacageMask, source, scratch)
         if ARM64E
             const numberOfPACBits = constexpr MacroAssembler::numberOfPACBits
             bfiq scratch2, 0, 64 - numberOfPACBits, ptr
@@ -453,7 +453,9 @@
 
 macro loadCagedJSValue(source, dest, scratchOrLength)
     loadp source, dest
-    cage(_g_gigacageBasePtrs + Gigacage::BasePtrs::jsValue, constexpr Gigacage::jsValueGigacageMask, dest, scratchOrLength)
+    if GIGACAGE_ENABLED
+        cage(_g_gigacageConfig + Gigacage::Config::basePtrs + GigacageJSValueBasePtrOffset, constexpr Gigacage::jsValueGigacageMask, dest, scratchOrLength)
+    end
 end
 
 macro loadVariable(get, fieldName, valueReg)

Modified: trunk/Source/_javascript_Core/runtime/VM.h (249555 => 249556)


--- trunk/Source/_javascript_Core/runtime/VM.h	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2019-09-06 00:03:52 UTC (rev 249556)
@@ -353,12 +353,12 @@
     ALWAYS_INLINE CompleteSubspace& gigacageAuxiliarySpace(Gigacage::Kind kind)
     {
         switch (kind) {
-        case Gigacage::ReservedForFlagsAndNotABasePtr:
-            RELEASE_ASSERT_NOT_REACHED();
         case Gigacage::Primitive:
             return primitiveGigacageAuxiliarySpace;
         case Gigacage::JSValue:
             return jsValueGigacageAuxiliarySpace;
+        case Gigacage::NumberOfKinds:
+            break;
         }
         RELEASE_ASSERT_NOT_REACHED();
         return primitiveGigacageAuxiliarySpace;

Modified: trunk/Source/WTF/ChangeLog (249555 => 249556)


--- trunk/Source/WTF/ChangeLog	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/WTF/ChangeLog	2019-09-06 00:03:52 UTC (rev 249556)
@@ -1,3 +1,19 @@
+2019-09-05  Mark Lam  <mark....@apple.com>
+
+        Refactor the Gigacage code to require less pointer casting.
+        https://bugs.webkit.org/show_bug.cgi?id=201521
+
+        Reviewed by Saam Barati.
+
+        Remove some unneeded stubs in WTF Gigacage.h.
+
+        * wtf/Gigacage.cpp:
+        * wtf/Gigacage.h:
+        (Gigacage::name):
+        (Gigacage::isEnabled):
+        (Gigacage::basePtr): Deleted.
+        (Gigacage::basePtrs): Deleted.
+
 2019-08-30  Alex Christensen  <achristen...@webkit.org>
 
         Remove HAVE_CFNETWORK_WITH_AUTO_ADDED_HTTP_HEADER_SUPPRESSION_SUPPORT conditional

Modified: trunk/Source/WTF/wtf/Gigacage.cpp (249555 => 249556)


--- trunk/Source/WTF/wtf/Gigacage.cpp	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/WTF/wtf/Gigacage.cpp	2019-09-06 00:03:52 UTC (rev 249556)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -34,8 +34,6 @@
 
 namespace Gigacage {
 
-alignas(void*) char g_gigacageBasePtrs[gigacageBasePtrsSize];
-
 void* tryMalloc(Kind, size_t size)
 {
     return FastMalloc::tryMalloc(size);

Modified: trunk/Source/WTF/wtf/Gigacage.h (249555 => 249556)


--- trunk/Source/WTF/wtf/Gigacage.h	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/WTF/wtf/Gigacage.h	2019-09-06 00:03:52 UTC (rev 249556)
@@ -35,25 +35,13 @@
 
 const size_t primitiveGigacageMask = 0;
 const size_t jsValueGigacageMask = 0;
-const size_t gigacageBasePtrsSize = 8 * KB;
 
-extern "C" alignas(void*) WTF_EXPORT_PRIVATE char g_gigacageBasePtrs[gigacageBasePtrsSize];
-
-struct BasePtrs {
-    uintptr_t reservedForFlags;
-    void* primitive;
-    void* jsValue;
-};
-
 enum Kind {
-    ReservedForFlagsAndNotABasePtr = 0,
     Primitive,
     JSValue,
+    NumberOfKinds
 };
 
-static_assert(offsetof(BasePtrs, primitive) == Kind::Primitive * sizeof(void*), "");
-static_assert(offsetof(BasePtrs, jsValue) == Kind::JSValue * sizeof(void*), "");
-
 inline void ensureGigacage() { }
 inline void disablePrimitiveGigacage() { }
 inline bool shouldBeEnabled() { return false; }
@@ -70,46 +58,18 @@
 ALWAYS_INLINE const char* name(Kind kind)
 {
     switch (kind) {
-    case ReservedForFlagsAndNotABasePtr:
-        RELEASE_ASSERT_NOT_REACHED();
     case Primitive:
         return "Primitive";
     case JSValue:
         return "JSValue";
+    case NumberOfKinds:
+        break;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-ALWAYS_INLINE void*& basePtr(BasePtrs& basePtrs, Kind kind)
-{
-    switch (kind) {
-    case ReservedForFlagsAndNotABasePtr:
-        RELEASE_ASSERT_NOT_REACHED();
-    case Primitive:
-        return basePtrs.primitive;
-    case JSValue:
-        return basePtrs.jsValue;
-    }
-    RELEASE_ASSERT_NOT_REACHED();
-    return basePtrs.primitive;
-}
-
-ALWAYS_INLINE BasePtrs& basePtrs()
-{
-    return *reinterpret_cast<BasePtrs*>(reinterpret_cast<void*>(g_gigacageBasePtrs));
-}
-
-ALWAYS_INLINE void*& basePtr(Kind kind)
-{
-    return basePtr(basePtrs(), kind);
-}
-
-ALWAYS_INLINE bool isEnabled(Kind kind)
-{
-    return !!basePtr(kind);
-}
-
+ALWAYS_INLINE bool isEnabled(Kind) { return false; }
 ALWAYS_INLINE size_t mask(Kind) { return 0; }
 
 template<typename T>

Modified: trunk/Source/bmalloc/ChangeLog (249555 => 249556)


--- trunk/Source/bmalloc/ChangeLog	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/bmalloc/ChangeLog	2019-09-06 00:03:52 UTC (rev 249556)
@@ -1,3 +1,43 @@
+2019-09-05  Mark Lam  <mark....@apple.com>
+
+        Refactor the Gigacage code to require less pointer casting.
+        https://bugs.webkit.org/show_bug.cgi?id=201521
+
+        Reviewed by Saam Barati.
+
+        1. Define a Gigacage::Config struct instead of hacking around a g_gigacageBasePtrs
+           array of bytes.
+        2. Change Gigacage::basePtr() to return a pointer instead of a reference to the
+           requested basePtr.  Instead, make it explicit when the client is trying to
+           take the address of the basePtr, or setting it.
+        3. Renamed wasEnabled() to isEnabled() because it returns the present state of the
+           flag, not some past state.
+
+        * bmalloc/Gigacage.cpp:
+        (Gigacage::bmalloc::protectGigacageBasePtrs):
+        (Gigacage::bmalloc::unprotectGigacageBasePtrs):
+        (Gigacage::bmalloc::runwaySize):
+        (Gigacage::ensureGigacage):
+        (Gigacage::disablePrimitiveGigacage):
+        (Gigacage::addPrimitiveDisableCallback):
+        (Gigacage::primitiveGigacageDisabled):
+        * bmalloc/Gigacage.h:
+        (Gigacage::name):
+        (Gigacage::Config::basePtr const):
+        (Gigacage::Config::setBasePtr):
+        (Gigacage::isEnabled):
+        (Gigacage::basePtr):
+        (Gigacage::addressOfBasePtr):
+        (Gigacage::size):
+        (Gigacage::caged):
+        (Gigacage::wasEnabled): Deleted.
+        (Gigacage::setWasEnabled): Deleted.
+        (Gigacage::basePtrs): Deleted.
+        * bmalloc/HeapKind.h:
+        (bmalloc::heapKind):
+        (bmalloc::isActiveHeapKindAfterEnsuringGigacage):
+        (bmalloc::mapToActiveHeapKindAfterEnsuringGigacage):
+
 2019-09-03  Yusuke Suzuki  <ysuz...@apple.com>
 
         [bmalloc] IsoTLSLayout and AllIsoHeaps registration is racy with derived class initialization with virtual functions

Modified: trunk/Source/bmalloc/bmalloc/Gigacage.cpp (249555 => 249556)


--- trunk/Source/bmalloc/bmalloc/Gigacage.cpp	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/bmalloc/bmalloc/Gigacage.cpp	2019-09-06 00:03:52 UTC (rev 249556)
@@ -75,11 +75,7 @@
 // If this were less than 32GB, those OOB accesses could reach outside of the cage.
 constexpr size_t gigacageRunway = 32llu * 1024 * 1024 * 1024;
 
-// Note: g_gigacageBasePtrs[0] is reserved for storing the wasEnabled flag.
-// The first gigacageBasePtr will start at g_gigacageBasePtrs[sizeof(void*)].
-// This is done so that the wasEnabled flag will also be protected along with the
-// gigacageBasePtrs.
-alignas(gigacageBasePtrsSize) char g_gigacageBasePtrs[gigacageBasePtrsSize];
+alignas(configSizeToProtect) Config g_gigacageConfig;
 
 using namespace bmalloc;
 
@@ -89,15 +85,14 @@
 
 void protectGigacageBasePtrs()
 {
-    uintptr_t basePtrs = reinterpret_cast<uintptr_t>(g_gigacageBasePtrs);
     // We might only get page size alignment, but that's also the minimum we need.
-    RELEASE_BASSERT(!(basePtrs & (vmPageSize() - 1)));
-    mprotect(g_gigacageBasePtrs, gigacageBasePtrsSize, PROT_READ);
+    RELEASE_BASSERT(!(reinterpret_cast<size_t>(&g_gigacageConfig) & (vmPageSize() - 1)));
+    mprotect(&g_gigacageConfig, configSizeToProtect, PROT_READ);
 }
 
 void unprotectGigacageBasePtrs()
 {
-    mprotect(g_gigacageBasePtrs, gigacageBasePtrsSize, PROT_READ | PROT_WRITE);
+    mprotect(&g_gigacageConfig, configSizeToProtect, PROT_READ | PROT_WRITE);
 }
 
 class UnprotectGigacageBasePtrsScope {
@@ -116,12 +111,12 @@
 size_t runwaySize(Kind kind)
 {
     switch (kind) {
-    case Kind::ReservedForFlagsAndNotABasePtr:
-        RELEASE_BASSERT_NOT_REACHED();
     case Kind::Primitive:
         return gigacageRunway;
     case Kind::JSValue:
         return 0;
+    case Kind::NumberOfKinds:
+        RELEASE_BASSERT_NOT_REACHED();
     }
     return 0;
 }
@@ -137,17 +132,17 @@
             if (!shouldBeEnabled())
                 return;
             
-            Kind shuffledKinds[numKinds];
-            for (unsigned i = 0; i < numKinds; ++i)
-                shuffledKinds[i] = static_cast<Kind>(i + 1); // + 1 to skip Kind::ReservedForFlagsAndNotABasePtr.
+            Kind shuffledKinds[NumberOfKinds];
+            for (unsigned i = 0; i < NumberOfKinds; ++i)
+                shuffledKinds[i] = static_cast<Kind>(i);
             
             // We just go ahead and assume that 64 bits is enough randomness. That's trivially true right
             // now, but would stop being true if we went crazy with gigacages. Based on my math, 21 is the
             // largest value of n so that n! <= 2^64.
-            static_assert(numKinds <= 21, "too many kinds");
+            static_assert(NumberOfKinds <= 21, "too many kinds");
             uint64_t random;
             cryptoRandom(reinterpret_cast<unsigned char*>(&random), sizeof(random));
-            for (unsigned i = numKinds; i--;) {
+            for (unsigned i = NumberOfKinds; i--;) {
                 unsigned limit = i + 1;
                 unsigned j = static_cast<unsigned>(random % limit);
                 random /= limit;
@@ -184,7 +179,7 @@
             size_t nextCage = 0;
             for (Kind kind : shuffledKinds) {
                 nextCage = alignTo(kind, nextCage);
-                basePtr(kind) = reinterpret_cast<char*>(base) + nextCage;
+                g_gigacageConfig.setBasePtr(kind, reinterpret_cast<char*>(base) + nextCage);
                 nextCage = bump(kind, nextCage);
                 if (runwaySize(kind) > 0) {
                     char* runway = reinterpret_cast<char*>(base) + nextCage;
@@ -195,7 +190,7 @@
             }
             
             vmDeallocatePhysicalPages(base, totalSize);
-            setWasEnabled();
+            g_gigacageConfig.isEnabled = true;
             protectGigacageBasePtrs();
         });
 }
@@ -203,7 +198,7 @@
 void disablePrimitiveGigacage()
 {
     ensureGigacage();
-    if (!basePtrs().primitive) {
+    if (!g_gigacageConfig.basePtrs[Primitive]) {
         // It was never enabled. That means that we never even saved any callbacks. Or, we had already disabled
         // it before, and already called the callbacks.
         return;
@@ -215,13 +210,13 @@
         callback.function(callback.argument);
     callbacks.callbacks.shrink(0);
     UnprotectGigacageBasePtrsScope unprotectScope;
-    basePtrs().primitive = nullptr;
+    g_gigacageConfig.basePtrs[Primitive] = nullptr;
 }
 
 void addPrimitiveDisableCallback(void (*function)(void*), void* argument)
 {
     ensureGigacage();
-    if (!basePtrs().primitive) {
+    if (!g_gigacageConfig.basePtrs[Primitive]) {
         // It was already disabled or we were never able to enable it.
         function(argument);
         return;
@@ -248,7 +243,7 @@
 
 static void primitiveGigacageDisabled(void*)
 {
-    if (GIGACAGE_ALLOCATION_CAN_FAIL && !wasEnabled())
+    if (GIGACAGE_ALLOCATION_CAN_FAIL && !isEnabled())
         return;
 
     static bool s_false;

Modified: trunk/Source/bmalloc/bmalloc/Gigacage.h (249555 => 249556)


--- trunk/Source/bmalloc/bmalloc/Gigacage.h	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/bmalloc/bmalloc/Gigacage.h	2019-09-06 00:03:52 UTC (rev 249556)
@@ -45,20 +45,20 @@
 namespace Gigacage {
 
 enum Kind {
-    ReservedForFlagsAndNotABasePtr = 0,
     Primitive,
     JSValue,
+    NumberOfKinds
 };
 
 BINLINE const char* name(Kind kind)
 {
     switch (kind) {
-    case ReservedForFlagsAndNotABasePtr:
-        RELEASE_BASSERT_NOT_REACHED();
     case Primitive:
         return "Primitive";
     case JSValue:
         return "JSValue";
+    case NumberOfKinds:
+        break;
     }
     BCRASH();
     return nullptr;
@@ -69,14 +69,14 @@
 #if BCPU(ARM64)
 constexpr size_t primitiveGigacageSize = 2 * bmalloc::Sizes::GB;
 constexpr size_t jsValueGigacageSize = 2 * bmalloc::Sizes::GB;
-constexpr size_t gigacageBasePtrsSize = 16 * bmalloc::Sizes::kB;
 constexpr size_t maximumCageSizeReductionForSlide = bmalloc::Sizes::GB / 4;
+constexpr size_t configSizeToProtect = 16 * bmalloc::Sizes::kB;
 #define GIGACAGE_ALLOCATION_CAN_FAIL 1
 #else
 constexpr size_t primitiveGigacageSize = 32 * bmalloc::Sizes::GB;
 constexpr size_t jsValueGigacageSize = 16 * bmalloc::Sizes::GB;
-constexpr size_t gigacageBasePtrsSize = 4 * bmalloc::Sizes::kB;
 constexpr size_t maximumCageSizeReductionForSlide = 4 * bmalloc::Sizes::GB;
+constexpr size_t configSizeToProtect = 4 * bmalloc::Sizes::kB;
 #define GIGACAGE_ALLOCATION_CAN_FAIL 0
 #endif
 
@@ -98,22 +98,38 @@
 constexpr size_t primitiveGigacageMask = gigacageSizeToMask(primitiveGigacageSize);
 constexpr size_t jsValueGigacageMask = gigacageSizeToMask(jsValueGigacageSize);
 
-extern "C" alignas(gigacageBasePtrsSize) BEXPORT char g_gigacageBasePtrs[gigacageBasePtrsSize];
+struct Config {
+    void* basePtr(Kind kind) const
+    {
+        RELEASE_BASSERT(kind < NumberOfKinds);
+        return basePtrs[kind];
+    }
 
-BINLINE bool wasEnabled() { return g_gigacageBasePtrs[0]; }
-BINLINE void setWasEnabled() { g_gigacageBasePtrs[0] = true; }
+    void setBasePtr(Kind kind, void* ptr)
+    {
+        RELEASE_BASSERT(kind < NumberOfKinds);
+        basePtrs[kind] = ptr;
+    }
 
-struct BasePtrs {
-    uintptr_t reservedForFlags;
-    void* primitive;
-    void* jsValue;
+    union {
+        struct {
+            bool isEnabled;
+            void* basePtrs[NumberOfKinds];
+        };
+        char ensureSize[configSizeToProtect];
+    };
 };
+static_assert(sizeof(Config) == configSizeToProtect, "Gigacage Config must fit in configSizeToProtect");
 
-static_assert(offsetof(BasePtrs, primitive) == Kind::Primitive * sizeof(void*), "");
-static_assert(offsetof(BasePtrs, jsValue) == Kind::JSValue * sizeof(void*), "");
+extern "C" alignas(configSizeToProtect) BEXPORT Config g_gigacageConfig;
 
-constexpr unsigned numKinds = 2;
+// These constants are needed by the LLInt.
+constexpr ptrdiff_t offsetOfPrimitiveGigacageBasePtr = Kind::Primitive * sizeof(void*);
+constexpr ptrdiff_t offsetOfJSValueGigacageBasePtr = Kind::JSValue * sizeof(void*);
 
+
+BINLINE bool isEnabled() { return g_gigacageConfig.isEnabled; }
+
 BEXPORT void ensureGigacage();
 
 BEXPORT void disablePrimitiveGigacage();
@@ -128,44 +144,31 @@
 inline bool isPrimitiveGigacagePermanentlyEnabled() { return isDisablingPrimitiveGigacageDisabled(); }
 inline bool canPrimitiveGigacageBeDisabled() { return !isDisablingPrimitiveGigacageDisabled(); }
 
-BINLINE void*& basePtr(BasePtrs& basePtrs, Kind kind)
+BINLINE void* basePtr(Kind kind)
 {
-    switch (kind) {
-    case ReservedForFlagsAndNotABasePtr:
-        RELEASE_BASSERT_NOT_REACHED();
-    case Primitive:
-        return basePtrs.primitive;
-    case JSValue:
-        return basePtrs.jsValue;
-    }
-    BCRASH();
-    return basePtrs.primitive;
+    return g_gigacageConfig.basePtr(kind);
 }
 
-BINLINE BasePtrs& basePtrs()
+BINLINE void* addressOfBasePtr(Kind kind)
 {
-    return *reinterpret_cast<BasePtrs*>(reinterpret_cast<void*>(g_gigacageBasePtrs));
+    RELEASE_BASSERT(kind < NumberOfKinds);
+    return &g_gigacageConfig.basePtrs[kind];
 }
 
-BINLINE void*& basePtr(Kind kind)
-{
-    return basePtr(basePtrs(), kind);
-}
-
 BINLINE bool isEnabled(Kind kind)
 {
-    return !!basePtr(kind);
+    return !!g_gigacageConfig.basePtr(kind);
 }
 
 BINLINE size_t size(Kind kind)
 {
     switch (kind) {
-    case ReservedForFlagsAndNotABasePtr:
-        RELEASE_BASSERT_NOT_REACHED();
     case Primitive:
         return static_cast<size_t>(primitiveGigacageSize);
     case JSValue:
         return static_cast<size_t>(jsValueGigacageSize);
+    case NumberOfKinds:
+        break;
     }
     BCRASH();
     return 0;
@@ -192,7 +195,7 @@
 BINLINE T* caged(Kind kind, T* ptr)
 {
     BASSERT(ptr);
-    void* gigacageBasePtr = basePtr(kind);
+    void* gigacageBasePtr = g_gigacageConfig.basePtr(kind);
     if (!gigacageBasePtr)
         return ptr;
     return reinterpret_cast<T*>(
@@ -217,7 +220,7 @@
 
 #else // GIGACAGE_ENABLED
 
-BINLINE void*& basePtr(Kind)
+BINLINE void* basePtr(Kind)
 {
     BCRASH();
     static void* unreachable;
@@ -225,7 +228,7 @@
 }
 BINLINE size_t size(Kind) { BCRASH(); return 0; }
 BINLINE void ensureGigacage() { }
-BINLINE bool wasEnabled() { return false; }
+BINLINE bool isEnabled() { return false; }
 BINLINE bool isCaged(Kind, const void*) { return true; }
 BINLINE bool isEnabled(Kind) { return false; }
 template<typename T> BINLINE T* caged(Kind, T* ptr) { return ptr; }

Modified: trunk/Source/bmalloc/bmalloc/HeapKind.h (249555 => 249556)


--- trunk/Source/bmalloc/bmalloc/HeapKind.h	2019-09-05 23:42:52 UTC (rev 249555)
+++ trunk/Source/bmalloc/bmalloc/HeapKind.h	2019-09-06 00:03:52 UTC (rev 249556)
@@ -70,12 +70,12 @@
 BINLINE HeapKind heapKind(Gigacage::Kind kind)
 {
     switch (kind) {
-    case Gigacage::ReservedForFlagsAndNotABasePtr:
-        RELEASE_BASSERT_NOT_REACHED();
     case Gigacage::Primitive:
         return HeapKind::PrimitiveGigacage;
     case Gigacage::JSValue:
         return HeapKind::JSValueGigacage;
+    case Gigacage::NumberOfKinds:
+        break;
     }
     BCRASH();
     return HeapKind::Primary;
@@ -86,7 +86,7 @@
     switch (kind) {
     case HeapKind::PrimitiveGigacage:
     case HeapKind::JSValueGigacage:
-        if (Gigacage::wasEnabled())
+        if (Gigacage::isEnabled())
             return true;
         return false;
     default:
@@ -101,7 +101,7 @@
     switch (kind) {
     case HeapKind::PrimitiveGigacage:
     case HeapKind::JSValueGigacage:
-        if (Gigacage::wasEnabled())
+        if (Gigacage::isEnabled())
             return kind;
         return HeapKind::Primary;
     default:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to