summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-01-19 12:45:37 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-17 11:42:39 +0000
commit557b2c3894b84f53b589893c2ff4166d37e69745 (patch)
treef32da5477731548d16d48cc18f7264db21bc3f52 /src
parent6a533065110b639105c84330c1668ebd4acea266 (diff)
macOS: Don't print stack trace via lldb on test failure if SIP prevents it
If the CSR_ALLOW_UNRESTRICTED_FS bit of System Integrity Protection (SIP) is enabled lldb will fail to print a valid stack trace when launched from the crashed process, and might also resulting in hanging or crashing the parent process (Terminal e.g.): https://github.com/llvm/llvm-project/issues/53254 We detect this situation and avoid printing a stack trace if so. Change-Id: Iad8cab5fcdc545d810ca4d4e985aefc0988d0234 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> (cherry picked from commit 985f0e9ca5905af7791f39fddd005f0c9f8fe081) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qcore_mac.mm33
-rw-r--r--src/corelib/kernel/qcore_mac_p.h1
-rw-r--r--src/testlib/qtestcase.cpp9
3 files changed, 42 insertions, 1 deletions
diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm
index 435b2a6150..162e55fa0d 100644
--- a/src/corelib/kernel/qcore_mac.mm
+++ b/src/corelib/kernel/qcore_mac.mm
@@ -58,6 +58,7 @@
#include <qdebug.h>
+#include "qendian.h"
#include "qhash.h"
#include "qpair.h"
#include "qmutex.h"
@@ -376,6 +377,38 @@ bool qt_mac_runningUnderRosetta()
return translated;
return false;
}
+
+std::optional<uint32_t> qt_mac_sipConfiguration()
+{
+ static auto configuration = []() -> std::optional<uint32_t> {
+ QIOType<io_registry_entry_t> nvram = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options");
+ if (!nvram) {
+ qWarning("Failed to locate NVRAM entry in IO registry");
+ return {};
+ }
+
+ QCFType<CFTypeRef> csrConfig = IORegistryEntryCreateCFProperty(nvram,
+ CFSTR("csr-active-config"), kCFAllocatorDefault, IOOptionBits{});
+ if (!csrConfig) {
+ qWarning("Failed to locate SIP config in NVRAM");
+ return {};
+ }
+
+ if (auto type = CFGetTypeID(csrConfig); type != CFDataGetTypeID()) {
+ qWarning() << "Unexpected SIP config type" << CFCopyTypeIDDescription(type);
+ return {};
+ }
+
+ QByteArray data = QByteArray::fromRawCFData(csrConfig.as<CFDataRef>());
+ if (data.size() != sizeof(uint32_t)) {
+ qWarning() << "Unexpected SIP config size" << data.size();
+ return {};
+ }
+
+ return qFromLittleEndian<uint32_t>(data.constData());
+ }();
+ return configuration;
+}
#endif
bool qt_apple_isApplicationExtension()
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 05bd5b7baa..0000f3b656 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -207,6 +207,7 @@ private:
#ifdef Q_OS_MACOS
Q_CORE_EXPORT bool qt_mac_applicationIsInDarkMode();
Q_CORE_EXPORT bool qt_mac_runningUnderRosetta();
+Q_CORE_EXPORT std::optional<uint32_t> qt_mac_sipConfiguration();
#endif
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index db3c42a9fa..b93a0ee7c6 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -213,7 +213,14 @@ static void stackTrace()
if (debuggerPresent() || hasSystemCrashReporter())
return;
-#if defined(Q_OS_LINUX) || (defined(Q_OS_MACOS) && !defined(Q_PROCESSOR_ARM_64))
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
+
+#if defined(Q_OS_MACOS)
+ #define CSR_ALLOW_UNRESTRICTED_FS (1 << 1)
+ std::optional<uint32_t> sipConfiguration = qt_mac_sipConfiguration();
+ if (!sipConfiguration || !(*sipConfiguration & CSR_ALLOW_UNRESTRICTED_FS))
+ return; // LLDB will fail to provide a valid stack trace
+#endif
const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());