Refactor the Gigacage code to require less pointer casting.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Sep 2019 00:03:52 +0000 (00:03 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Sep 2019 00:03:52 +0000 (00:03 +0000)
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/JavaScriptCore:

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.

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

12 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/jit/AssemblyHelpers.h
Source/JavaScriptCore/llint/LowLevelInterpreter.asm
Source/JavaScriptCore/llint/LowLevelInterpreter64.asm
Source/JavaScriptCore/runtime/VM.h
Source/WTF/ChangeLog
Source/WTF/wtf/Gigacage.cpp
Source/WTF/wtf/Gigacage.h
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc/Gigacage.cpp
Source/bmalloc/bmalloc/Gigacage.h
Source/bmalloc/bmalloc/HeapKind.h

index c12cbc1..631fa8e 100644 (file)
@@ -1,3 +1,20 @@
+2019-09-05  Mark Lam  <mark.lam@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  <ysuzuki@apple.com>
 
         Unreviewed, follow-up after r249530 and r249509
index 0d8bb23..ea91383 100644 (file)
@@ -1595,7 +1595,7 @@ public:
                 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();
index 743e2ab..d204b40 100644 (file)
@@ -298,6 +298,11 @@ else
     end
 end
 
+if GIGACAGE_ENABLED
+    const GigacagePrimitiveBasePtrOffset = constexpr Gigacage::offsetOfPrimitiveGigacageBasePtr
+    const GigacageJSValueBasePtrOffset = constexpr Gigacage::offsetOfJSValueGigacageBasePtr
+end
+
 macro dispatch(advanceReg)
     addp advanceReg, PC
     nextInstruction()
index 8d71ced..2689e24 100644 (file)
@@ -440,7 +440,7 @@ macro cagedPrimitive(ptr, length, scratch, scratch2)
         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 @@ end
 
 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)
index e07d865..b152be5 100644 (file)
@@ -353,12 +353,12 @@ public:
     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;
index 6d28225..8d3e309 100644 (file)
@@ -1,3 +1,19 @@
+2019-09-05  Mark Lam  <mark.lam@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  <achristensen@webkit.org>
 
         Remove HAVE_CFNETWORK_WITH_AUTO_ADDED_HTTP_HEADER_SUPPRESSION_SUPPORT conditional
index 1b10e33..6952cad 100644 (file)
@@ -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);
index 227f647..df82bfe 100644 (file)
@@ -35,25 +35,13 @@ namespace Gigacage {
 
 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 @@ inline bool canPrimitiveGigacageBeDisabled() { return true; }
 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>
index 4e1b168..51d9a36 100644 (file)
@@ -1,3 +1,43 @@
+2019-09-05  Mark Lam  <mark.lam@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  <ysuzuki@apple.com>
 
         [bmalloc] IsoTLSLayout and AllIsoHeaps registration is racy with derived class initialization with virtual functions
index 8209831..9c4d84d 100644 (file)
@@ -75,11 +75,7 @@ namespace Gigacage {
 // 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 @@ bool s_isDisablingPrimitiveGigacageDisabled;
 
 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 @@ public:
 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 @@ void ensureGigacage()
             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 @@ void ensureGigacage()
             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 @@ void ensureGigacage()
             }
             
             vmDeallocatePhysicalPages(base, totalSize);
-            setWasEnabled();
+            g_gigacageConfig.isEnabled = true;
             protectGigacageBasePtrs();
         });
 }
@@ -203,7 +198,7 @@ void ensureGigacage()
 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 @@ void disablePrimitiveGigacage()
         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 @@ void removePrimitiveDisableCallback(void (*function)(void*), void* argument)
 
 static void primitiveGigacageDisabled(void*)
 {
-    if (GIGACAGE_ALLOCATION_CAN_FAIL && !wasEnabled())
+    if (GIGACAGE_ALLOCATION_CAN_FAIL && !isEnabled())
         return;
 
     static bool s_false;
index c730493..7e25aaf 100644 (file)
 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 @@ BINLINE const char* name(Kind kind)
 #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,21 +98,37 @@ constexpr size_t gigacageSizeToMask(size_t size) { return size - 1; }
 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");
+
+extern "C" alignas(configSizeToProtect) BEXPORT Config g_gigacageConfig;
 
-static_assert(offsetof(BasePtrs, primitive) == Kind::Primitive * sizeof(void*), "");
-static_assert(offsetof(BasePtrs, jsValue) == Kind::JSValue * sizeof(void*), "");
+// These constants are needed by the LLInt.
+constexpr ptrdiff_t offsetOfPrimitiveGigacageBasePtr = Kind::Primitive * sizeof(void*);
+constexpr ptrdiff_t offsetOfJSValueGigacageBasePtr = Kind::JSValue * sizeof(void*);
 
-constexpr unsigned numKinds = 2;
+
+BINLINE bool isEnabled() { return g_gigacageConfig.isEnabled; }
 
 BEXPORT void ensureGigacage();
 
@@ -128,44 +144,31 @@ BEXPORT bool isDisablingPrimitiveGigacageDisabled();
 inline bool isPrimitiveGigacagePermanentlyEnabled() { return isDisablingPrimitiveGigacageDisabled(); }
 inline bool canPrimitiveGigacageBeDisabled() { return !isDisablingPrimitiveGigacageDisabled(); }
 
-BINLINE void*& basePtr(BasePtrs& basePtrs, Kind kind)
-{
-    switch (kind) {
-    case ReservedForFlagsAndNotABasePtr:
-        RELEASE_BASSERT_NOT_REACHED();
-    case Primitive:
-        return basePtrs.primitive;
-    case JSValue:
-        return basePtrs.jsValue;
-    }
-    BCRASH();
-    return basePtrs.primitive;
-}
-
-BINLINE BasePtrs& basePtrs()
+BINLINE void* basePtr(Kind kind)
 {
-    return *reinterpret_cast<BasePtrs*>(reinterpret_cast<void*>(g_gigacageBasePtrs));
+    return g_gigacageConfig.basePtr(kind);
 }
 
-BINLINE void*& basePtr(Kind kind)
+BINLINE void* addressOfBasePtr(Kind kind)
 {
-    return basePtr(basePtrs(), kind);
+    RELEASE_BASSERT(kind < NumberOfKinds);
+    return &g_gigacageConfig.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 @@ template<typename T>
 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 @@ BEXPORT bool shouldBeEnabled();
 
 #else // GIGACAGE_ENABLED
 
-BINLINE void*& basePtr(Kind)
+BINLINE void* basePtr(Kind)
 {
     BCRASH();
     static void* unreachable;
@@ -225,7 +228,7 @@ BINLINE void*& basePtr(Kind)
 }
 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; }
index 7d7c9ba..07aa73d 100644 (file)
@@ -70,12 +70,12 @@ BINLINE Gigacage::Kind gigacageKind(HeapKind kind)
 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 @@ BINLINE bool isActiveHeapKindAfterEnsuringGigacage(HeapKind kind)
     switch (kind) {
     case HeapKind::PrimitiveGigacage:
     case HeapKind::JSValueGigacage:
-        if (Gigacage::wasEnabled())
+        if (Gigacage::isEnabled())
             return true;
         return false;
     default:
@@ -101,7 +101,7 @@ BINLINE HeapKind mapToActiveHeapKindAfterEnsuringGigacage(HeapKind kind)
     switch (kind) {
     case HeapKind::PrimitiveGigacage:
     case HeapKind::JSValueGigacage:
-        if (Gigacage::wasEnabled())
+        if (Gigacage::isEnabled())
             return kind;
         return HeapKind::Primary;
     default: