Bug 1915998 - Check for Omnijar::Init failure more consistently, r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D220748
This commit is contained in:
Nika Layzell 2024-08-30 22:40:25 +00:00
Родитель 2a648b5196
Коммит bf0c416c45
4 изменённых файлов: 25 добавлений и 7 удалений

Просмотреть файл

@ -6168,6 +6168,7 @@ nsresult XRE_InitCommandLine(int aArgc, char* aArgv[]) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
mozilla::Omnijar::Init(greOmni, greOmni); mozilla::Omnijar::Init(greOmni, greOmni);
MOZ_RELEASE_ASSERT(IsPackagedBuild(), "Android builds are always packaged");
} }
#endif #endif

Просмотреть файл

@ -104,7 +104,7 @@ nsresult Omnijar::InitOne(nsIFile* aPath, Type aType) {
return NS_OK; return NS_OK;
} }
nsresult Omnijar::Init(nsIFile* aGrePath, nsIFile* aAppPath) { nsresult Omnijar::FallibleInit(nsIFile* aGrePath, nsIFile* aAppPath) {
// Even on error we do not want to come here again. // Even on error we do not want to come here again.
sInitialized = true; sInitialized = true;
@ -118,6 +118,14 @@ nsresult Omnijar::Init(nsIFile* aGrePath, nsIFile* aAppPath) {
return NS_OK; return NS_OK;
} }
void Omnijar::Init(nsIFile* aGrePath, nsIFile* aAppPath) {
nsresult rv = FallibleInit(aGrePath, aAppPath);
if (NS_FAILED(rv)) {
MOZ_CRASH_UNSAFE_PRINTF("Omnijar::Init failed: %s",
mozilla::GetStaticErrorName(rv));
}
}
void Omnijar::CleanUp() { void Omnijar::CleanUp() {
CleanUpOne(GRE); CleanUpOne(GRE);
CleanUpOne(APP); CleanUpOne(APP);
@ -226,6 +234,10 @@ void Omnijar::ChildProcessInit(int& aArgc, char** aArgv) {
} }
} }
#if defined(MOZ_WIDGET_ANDROID)
MOZ_RELEASE_ASSERT(greOmni, "Android builds are always packaged");
#endif
// If we're unified, then only the -greomni flag is present // If we're unified, then only the -greomni flag is present
// (reflecting the state of sPath in the parent process) but that // (reflecting the state of sPath in the parent process) but that
// path should be used for both (not nullptr, which will try to // path should be used for both (not nullptr, which will try to

Просмотреть файл

@ -85,8 +85,13 @@ class Omnijar {
* - a directory path, pointing to a directory containing an "omni.jar" file, * - a directory path, pointing to a directory containing an "omni.jar" file,
* - nullptr for autodetection of an "omni.jar" file. * - nullptr for autodetection of an "omni.jar" file.
*/ */
static nsresult Init(nsIFile* aGrePath = nullptr, static void Init(nsIFile* aGrePath = nullptr, nsIFile* aAppPath = nullptr);
nsIFile* aAppPath = nullptr);
/**
* Like `Init`, but returns a failed nsresult instead of crashing on failure.
*/
static nsresult FallibleInit(nsIFile* aGrePath = nullptr,
nsIFile* aAppPath = nullptr);
/** /**
* Initializes the Omnijar API for a child process, given its argument * Initializes the Omnijar API for a child process, given its argument

Просмотреть файл

@ -391,10 +391,10 @@ NS_InitXPCOM(nsIServiceManager** aResult, nsIFile* aBinDirectory,
// GeckoChildProcessHost.cpp which sets the greomni/appomni flags. // GeckoChildProcessHost.cpp which sets the greomni/appomni flags.
MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsContentProcess()); MOZ_ASSERT(XRE_IsParentProcess() || XRE_IsContentProcess());
// Note that the Omnijar::Init does not fail but returns NS_OK if the file // Note that the Omnijar::FallibleInit does not fail but returns NS_OK if
// is not found at all, as this is an expected possible way of running // the file is not found at all, as this is an expected possible way of
// with an unpacked modules directory. // running with an unpacked modules directory.
nsresult rv = mozilla::Omnijar::Init(); nsresult rv = mozilla::Omnijar::FallibleInit();
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
XPCOM_INIT_FATAL("Omnijar::Init()", NS_ERROR_OMNIJAR_CORRUPT) XPCOM_INIT_FATAL("Omnijar::Init()", NS_ERROR_OMNIJAR_CORRUPT)
} }