mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-23 18:26:15 +00:00
a66f824994
* Significant cleanup to `ModuleEvaluator` * `UntrustedModuleData` holds all of the accumulated untrusted module info for a single process. * `ProcessedModuleLoadEvent` holds information about an individual untrusted module load in a Gecko-friendly, sanitized, format. * Since multiple `ProcessModuleLoadEvent` objects may reference the same module, we store module metadata in a shared `ModuleInfo` structure. * The `UntrustedModulesProcessor` receives the events from `mozglue` and processes them on a background thread: ** It does not start background processing until the main thread has gone idle. The idea here is that we do not want to add any more background work until we are reasonably confident that Gecko is no longer starting up or doing other intense activity. ** Background processing runs at a background priority level, *except* when results are requested by telemetry itself. ** Telemetry requests the data via `UntrustedModulesProcessor::GetProcessedData` which runs at normal priority and returns a promise to the caller. Depends on D43159 Differential Revision: https://phabricator.services.mozilla.com/D43160 --HG-- rename : toolkit/xre/ModuleEvaluator_windows.cpp => toolkit/xre/ModuleEvaluator.cpp rename : toolkit/xre/ModuleEvaluator_windows.cpp => toolkit/xre/ModuleEvaluator.h rename : toolkit/xre/ModuleVersionInfo_windows.cpp => toolkit/xre/ModuleVersionInfo.cpp rename : toolkit/xre/ModuleVersionInfo_windows.h => toolkit/xre/ModuleVersionInfo.h rename : toolkit/xre/ModuleEvaluator_windows.cpp => toolkit/xre/UntrustedModulesData.cpp rename : toolkit/xre/ModuleEvaluator_windows.h => toolkit/xre/UntrustedModulesData.h rename : toolkit/xre/ModuleEvaluator_windows.cpp => toolkit/xre/UntrustedModulesProcessor.cpp rename : toolkit/xre/ModuleEvaluator_windows.h => toolkit/xre/UntrustedModulesProcessor.h extra : moz-landing-system : lando
99 lines
2.9 KiB
C++
99 lines
2.9 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "mozilla/WinDllServices.h"
|
|
|
|
#include <windows.h>
|
|
#include <psapi.h>
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
#include "mozilla/Services.h"
|
|
#include "mozilla/StaticLocalPtr.h"
|
|
#include "mozilla/SystemGroup.h"
|
|
#include "mozilla/UntrustedModulesProcessor.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsIObserverService.h"
|
|
#include "nsString.h"
|
|
|
|
namespace mozilla {
|
|
|
|
const char* DllServices::kTopicDllLoadedMainThread = "dll-loaded-main-thread";
|
|
const char* DllServices::kTopicDllLoadedNonMainThread =
|
|
"dll-loaded-non-main-thread";
|
|
|
|
DllServices* DllServices::Get() {
|
|
static StaticLocalRefPtr<DllServices> sInstance(
|
|
[]() -> already_AddRefed<DllServices> {
|
|
RefPtr<DllServices> dllSvc(new DllServices());
|
|
dllSvc->EnableFull();
|
|
|
|
auto setClearOnShutdown = [ptr = &sInstance]() -> void {
|
|
ClearOnShutdown(ptr);
|
|
};
|
|
|
|
if (NS_IsMainThread()) {
|
|
setClearOnShutdown();
|
|
return dllSvc.forget();
|
|
}
|
|
|
|
SystemGroup::Dispatch(
|
|
TaskCategory::Other,
|
|
NS_NewRunnableFunction("mozilla::DllServices::Get",
|
|
std::move(setClearOnShutdown)));
|
|
|
|
return dllSvc.forget();
|
|
}());
|
|
|
|
return sInstance;
|
|
}
|
|
|
|
DllServices::DllServices()
|
|
: mUntrustedModulesProcessor(UntrustedModulesProcessor::Create()) {}
|
|
|
|
RefPtr<UntrustedModulesPromise> DllServices::GetUntrustedModulesData() {
|
|
if (!mUntrustedModulesProcessor) {
|
|
return UntrustedModulesPromise::CreateAndReject(NS_ERROR_NOT_IMPLEMENTED,
|
|
__func__);
|
|
}
|
|
|
|
return mUntrustedModulesProcessor->GetProcessedData();
|
|
}
|
|
|
|
void DllServices::NotifyDllLoad(glue::EnhancedModuleLoadInfo&& aModLoadInfo) {
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
const char* topic;
|
|
|
|
if (aModLoadInfo.mNtLoadInfo.mThreadId == ::GetCurrentThreadId()) {
|
|
topic = kTopicDllLoadedMainThread;
|
|
} else {
|
|
topic = kTopicDllLoadedNonMainThread;
|
|
}
|
|
|
|
// We save the path to a nsAutoString because once we have submitted
|
|
// aModLoadInfo for processing there is no guarantee that the original
|
|
// buffer will continue to be valid.
|
|
nsAutoString dllFilePath(aModLoadInfo.GetSectionName());
|
|
|
|
if (mUntrustedModulesProcessor) {
|
|
mUntrustedModulesProcessor->Enqueue(std::move(aModLoadInfo));
|
|
}
|
|
|
|
nsCOMPtr<nsIObserverService> obsServ(mozilla::services::GetObserverService());
|
|
obsServ->NotifyObservers(nullptr, topic, dllFilePath.get());
|
|
}
|
|
|
|
void DllServices::NotifyModuleLoadBacklog(ModuleLoadInfoVec&& aEvents) {
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
if (!mUntrustedModulesProcessor) {
|
|
return;
|
|
}
|
|
|
|
mUntrustedModulesProcessor->Enqueue(std::move(aEvents));
|
|
}
|
|
|
|
} // namespace mozilla
|