#pragma once
#include <wtf/Assertions.h>
#include <wtf/Atomics.h>
#include <wtf/ExportMacros.h>
#include <wtf/PageBlock.h>
#include <wtf/PtrTag.h>
#include <wtf/StdLibExtras.h>
#include <wtf/threads/Signals.h>
#if defined(USE_SYSTEM_MALLOC) && USE_SYSTEM_MALLOC
namespace Gigacage {
constexpr size_t reservedSlotsForGigacageConfig = 0;
constexpr size_t reservedBytesForGigacageConfig = 0;
}
#else
#include <bmalloc/GigacageConfig.h>
#endif
#if ENABLE(UNIFIED_AND_FREEZABLE_CONFIG_RECORD)
namespace WebConfig {
using Slot = uint64_t;
extern "C" WTF_EXPORT_PRIVATE Slot g_config[];
} #endif // ENABLE(UNIFIED_AND_FREEZABLE_CONFIG_RECORD)
namespace WTF {
constexpr size_t ConfigAlignment = CeilingOnPageSize;
constexpr size_t ConfigSizeToProtect = std::max(CeilingOnPageSize, 16 * KB);
struct Config {
WTF_EXPORT_PRIVATE static void permanentlyFreeze();
struct AssertNotFrozenScope {
AssertNotFrozenScope();
~AssertNotFrozenScope();
};
bool isPermanentlyFrozen;
#if OS(UNIX)
SignalHandlers signalHandlers;
#endif
PtrTagLookup* ptrTagLookupHead;
uint64_t spaceForExtensions[1];
};
#if ENABLE(UNIFIED_AND_FREEZABLE_CONFIG_RECORD)
constexpr size_t startSlotOfWTFConfig = Gigacage::reservedSlotsForGigacageConfig;
constexpr size_t startOffsetOfWTFConfig = startSlotOfWTFConfig * sizeof(WebConfig::Slot);
constexpr size_t offsetOfWTFConfigExtension = startOffsetOfWTFConfig + offsetof(WTF::Config, spaceForExtensions);
constexpr size_t alignmentOfWTFConfig = std::alignment_of<WTF::Config>::value;
static_assert(Gigacage::reservedBytesForGigacageConfig + sizeof(WTF::Config) <= ConfigSizeToProtect);
static_assert(roundUpToMultipleOf<alignmentOfWTFConfig>(startOffsetOfWTFConfig) == startOffsetOfWTFConfig);
WTF_EXPORT_PRIVATE void setPermissionsOfConfigPage();
#define g_wtfConfig (*bitwise_cast<WTF::Config*>(&WebConfig::g_config[WTF::startSlotOfWTFConfig]))
#else // not ENABLE(UNIFIED_AND_FREEZABLE_CONFIG_RECORD)
inline void setPermissionsOfConfigPage() { }
extern "C" WTF_EXPORT_PRIVATE Config g_wtfConfig;
#endif // ENABLE(UNIFIED_AND_FREEZABLE_CONFIG_RECORD)
ALWAYS_INLINE Config::AssertNotFrozenScope::AssertNotFrozenScope()
{
RELEASE_ASSERT(!g_wtfConfig.isPermanentlyFrozen);
compilerFence();
};
ALWAYS_INLINE Config::AssertNotFrozenScope::~AssertNotFrozenScope()
{
compilerFence();
RELEASE_ASSERT(!g_wtfConfig.isPermanentlyFrozen);
};
}
#if !ENABLE(UNIFIED_AND_FREEZABLE_CONFIG_RECORD)
using WTF::g_wtfConfig;
#endif