diff --git a/src/Common/SCardManager.cpp b/src/Common/SCardManager.cpp index cb97c1a0..3a714b73 100644 --- a/src/Common/SCardManager.cpp +++ b/src/Common/SCardManager.cpp @@ -7,9 +7,13 @@ namespace VeraCrypt SCardManager::SCardManager() { -#ifndef TC_OPENBSD - loader->Initialize(); -#endif + // The PC/SC library is loaded lazily on first use (see GetReaders/GetReader). + // SCardManager instances are static objects, so initializing here would run + // before main(). On macOS, establishing a PC/SC context opens an XPC connection, + // which starts a helper thread and marks libdispatch as fork-unsafe. The core + // service fork() would then happen in a multithreaded process, and the FUSE + // service (which libfuse runs after fork() without exec()) would inherit + // poisoned dispatch queues and armed Objective-C fork-safety checks. } SCardManager::~SCardManager() @@ -28,6 +32,8 @@ namespace VeraCrypt SCARDCONTEXT hScardContext = 0; LONG lRet = SCARD_S_SUCCESS; + loader->Initialize(); + hScardContext = loader->GetSCardContext(); lRet = loader->SCardIsValidContext(hScardContext); if (SCARD_S_SUCCESS != lRet)