From 51739da3cbe24caa066408c0562deb2d4f80a5b9 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Wed, 21 Aug 2019 17:23:03 +0000 Subject: [PATCH] Bug 1163103 - stop using NS_GetSpecialDirectory off the main thread within the cycle collector (via nsDumpUtils.cpp), r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D42856 --HG-- extra : moz-landing-system : lando --- xpcom/base/moz.build | 7 +++++-- xpcom/base/nsDumpUtils.cpp | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/xpcom/base/moz.build b/xpcom/base/moz.build index 8d83dcd1677d..b57ee3f1ec96 100644 --- a/xpcom/base/moz.build +++ b/xpcom/base/moz.build @@ -133,10 +133,14 @@ EXPORTS.mozilla += [ 'TupleCycleCollection.h', ] +SOURCES += [ # nsDebugImpl isn't unified because we disable PGO so that NS_ABORT_OOM isn't # optimized away oddly. -SOURCES += [ 'nsDebugImpl.cpp', +# nsDumpUtils.cpp includes SpecialSystemDirectory.h which includes +# nsLocalFileMac.h which upsets other files in this dir that have a different +# idea about what `TextRange` means. + 'nsDumpUtils.cpp', ] SOURCES['nsDebugImpl.cpp'].no_pgo = True @@ -164,7 +168,6 @@ UNIFIED_SOURCES += [ 'nsCycleCollectionParticipant.cpp', 'nsCycleCollector.cpp', 'nsCycleCollectorTraceJSHelpers.cpp', - 'nsDumpUtils.cpp', 'nsErrorService.cpp', 'nsGZFileWriter.cpp', 'nsID.cpp', diff --git a/xpcom/base/nsDumpUtils.cpp b/xpcom/base/nsDumpUtils.cpp index f9b4e302b005..365f189616b9 100644 --- a/xpcom/base/nsDumpUtils.cpp +++ b/xpcom/base/nsDumpUtils.cpp @@ -13,6 +13,7 @@ #include "nsIObserverService.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/Unused.h" +#include "SpecialSystemDirectory.h" #ifdef XP_UNIX // { # include "mozilla/Preferences.h" @@ -417,7 +418,12 @@ nsresult nsDumpUtils::OpenTempFile(const nsACString& aFilename, nsIFile** aFile, #endif nsresult rv; if (!*aFile) { - rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, aFile); + if (NS_IsMainThread()) { + // This allows tests to override, but isn't safe off-mainthread. + rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, aFile); + } else { + rv = GetSpecialSystemDirectory(OS_TemporaryDirectory, aFile); + } if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }