From fa01e0bd71b42f0887790598106893c558557b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 20 May 2022 11:43:40 +0200 Subject: [PATCH] macOS: Try to get SIP configuration via private syscall if possible The SIP configuration is not available through the NVRAM in all cases, so we try to get it via the private syscall first, if we can, and then skip the warning if we don't find it in NVRAM. Pick-to: 6.2 6.3 Change-Id: I0866d06c329a3ac70bb1f23732d10aab13a4f9c1 Reviewed-by: Timur Pocheptsov --- src/corelib/kernel/qcore_mac.mm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm index e0a4c3dcb50..c2c1f1ac428 100644 --- a/src/corelib/kernel/qcore_mac.mm +++ b/src/corelib/kernel/qcore_mac.mm @@ -29,6 +29,13 @@ #include "qvarlengtharray.h" #include "private/qlocking_p.h" +#if !defined(QT_APPLE_NO_PRIVATE_APIS) +extern "C" { +typedef uint32_t csr_config_t; +extern int csr_get_active_config(csr_config_t *) __attribute__((weak_import)); +} +#endif + QT_BEGIN_NAMESPACE // -------------------------------------------------------------------------- @@ -343,6 +350,12 @@ bool qt_mac_runningUnderRosetta() std::optional qt_mac_sipConfiguration() { static auto configuration = []() -> std::optional { +#if !defined(QT_APPLE_NO_PRIVATE_APIS) + csr_config_t config; + if (csr_get_active_config && csr_get_active_config(&config) == 0) + return config; +#endif + QIOType nvram = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options"); if (!nvram) { qWarning("Failed to locate NVRAM entry in IO registry"); @@ -351,10 +364,8 @@ std::optional qt_mac_sipConfiguration() QCFType csrConfig = IORegistryEntryCreateCFProperty(nvram, CFSTR("csr-active-config"), kCFAllocatorDefault, IOOptionBits{}); - if (!csrConfig) { - qWarning("Failed to locate SIP config in NVRAM"); - return {}; - } + if (!csrConfig) + return {}; // SIP config is not available if (auto type = CFGetTypeID(csrConfig); type != CFDataGetTypeID()) { qWarning() << "Unexpected SIP config type" << CFCopyTypeIDDescription(type);