FastJITPermissions.h [plain text]
#pragma once
#if OS(DARWIN) && CPU(ARM64)
#include <wtf/Platform.h>
#if USE(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 USE(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 USE(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 USE(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 ALWAYS_INLINE void threadSelfRestrictRWXToRW()
{
CRASH();
}
NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void threadSelfRestrictRWXToRX()
{
CRASH();
}
#endif // OS(DARWIN) && CPU(ARM64)