Bug 1663315 - Don't load new JSMs during shutdown. r=kmag

Under unknown circumstances, we can end up running chrome
JS during thread manager shutdown. Sometimes this ends up
trying to load new JSMs, but gJarHandler has already been
cleared, leading to a crash.

To avoid this and other issues, this patch forbids the
importing of new JSMs after we're late enough in shutdown
to have cleared the ClearOnShutdown pointers. I allow the
importing of JSMs that have already been loaded, as that
seems like it should be okay.

Differential Revision: https://phabricator.services.mozilla.com/D89477
This commit is contained in:
Andrew McCreight 2020-09-08 19:36:27 +00:00
Родитель 9aae0f1df6
Коммит ff2f7c0866
1 изменённых файлов: 12 добавлений и 0 удалений

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

@ -49,6 +49,7 @@
#include "mozilla/scache/StartupCache.h"
#include "mozilla/scache/StartupCacheUtils.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/MacroForEach.h"
#include "mozilla/Preferences.h"
#include "mozilla/Omnijar.h"
@ -308,6 +309,9 @@ mozJSComponentLoader::~mozJSComponentLoader() {
StaticRefPtr<mozJSComponentLoader> mozJSComponentLoader::sSelf;
// True if ShutdownPhase::ShutdownFinal has been reached.
static bool sShutdownFinal = false;
nsresult mozJSComponentLoader::ReallyInit() {
MOZ_ASSERT(!mInitialized);
@ -517,6 +521,8 @@ void mozJSComponentLoader::FindTargetObject(JSContext* aCx,
void mozJSComponentLoader::InitStatics() {
MOZ_ASSERT(!sSelf);
sSelf = new mozJSComponentLoader();
RunOnShutdown([&] { sShutdownFinal = true; });
}
void mozJSComponentLoader::Unload() {
@ -1230,6 +1236,12 @@ nsresult mozJSComponentLoader::Import(JSContext* aCx,
UniquePtr<ModuleEntry> newEntry;
if (!mImports.Get(info.Key(), &mod) &&
!mInProgressImports.Get(info.Key(), &mod)) {
// We're trying to import a new JSM, but we're late in shutdown and this
// will likely not succeed and might even crash, so fail here.
if (sShutdownFinal) {
return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
}
newEntry = MakeUnique<ModuleEntry>(RootingContext::get(aCx));
// Note: This implies EnsureURI().