Bug 1724749: Consolidate all dllservices code; r=tkikuchi

Per the discussion on governance, the new DLL services module will live in
`toolkit/xre/dllservices`.

Mozglue code will live in `toolkit/xre/dllservices/mozglue` and will be linked
in with `mozglue.dll`.

Differential Revision: https://phabricator.services.mozilla.com/D122384
This commit is contained in:
Aaron Klotz 2021-08-12 20:57:12 +00:00
Родитель 73568f7953
Коммит ac6454a0ed
86 изменённых файлов: 138 добавлений и 68 удалений

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

@ -1414,9 +1414,9 @@ mozilla::ipc::IPCResult ContentChild::RecvRequestMemoryReport(
return IPC_OK();
}
#if defined(XP_WIN)
mozilla::ipc::IPCResult ContentChild::RecvGetUntrustedModulesData(
GetUntrustedModulesDataResolver&& aResolver) {
#if defined(XP_WIN)
RefPtr<DllServices> dllSvc(DllServices::Get());
dllSvc->GetUntrustedModulesData()->Then(
GetMainThreadSerialEventTarget(), __func__,
@ -1425,10 +1425,8 @@ mozilla::ipc::IPCResult ContentChild::RecvGetUntrustedModulesData(
},
[aResolver](nsresult aReason) { aResolver(Nothing()); });
return IPC_OK();
#else
return IPC_FAIL(this, "Unsupported on this platform");
#endif // defined(XP_WIN)
}
#endif // defined(XP_WIN)
PCycleCollectWithLogsChild* ContentChild::AllocPCycleCollectWithLogsChild(
const bool& aDumpAllTraces, const FileDescriptor& aGCLog,

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

@ -529,8 +529,10 @@ class ContentChild final : public PContentChild,
const bool& minimizeMemoryUsage, const Maybe<FileDescriptor>& DMDFile,
const RequestMemoryReportResolver& aResolver);
#if defined(XP_WIN)
mozilla::ipc::IPCResult RecvGetUntrustedModulesData(
GetUntrustedModulesDataResolver&& aResolver);
#endif // defined(XP_WIN)
mozilla::ipc::IPCResult RecvSetXPCOMProcessAttributes(
XPCOMInitData&& aXPCOMInit, const StructuredCloneData& aInitialData,

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

@ -6569,10 +6569,10 @@ mozilla::ipc::IPCResult ContentParent::RecvAddOrRemovePageAwakeRequest(
return IPC_OK();
}
#if defined(XP_WIN)
mozilla::ipc::IPCResult ContentParent::RecvGetModulesTrust(
ModulePaths&& aModPaths, bool aRunAtNormalPriority,
GetModulesTrustResolver&& aResolver) {
#if defined(XP_WIN)
RefPtr<DllServices> dllSvc(DllServices::Get());
dllSvc->GetModulesTrust(std::move(aModPaths), aRunAtNormalPriority)
->Then(
@ -6582,10 +6582,8 @@ mozilla::ipc::IPCResult ContentParent::RecvGetModulesTrust(
},
[aResolver](nsresult aRv) { aResolver(Nothing()); });
return IPC_OK();
#else
return IPC_FAIL(this, "Unsupported on this platform");
#endif // defined(XP_WIN)
}
#endif // defined(XP_WIN)
mozilla::ipc::IPCResult ContentParent::RecvCreateBrowsingContext(
uint64_t aGroupId, BrowsingContext::IPCInitializer&& aInit) {

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

@ -1323,9 +1323,11 @@ class ContentParent final
const MaybeDiscarded<BrowsingContext>& aContext,
const bool& aShouldAddCount);
#if defined(XP_WIN)
mozilla::ipc::IPCResult RecvGetModulesTrust(
ModulePaths&& aModPaths, bool aRunAtNormalPriority,
GetModulesTrustResolver&& aResolver);
#endif // defined(XP_WIN)
mozilla::ipc::IPCResult RecvReportServiceWorkerShutdownProgress(
uint32_t aShutdownStateId,

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

@ -109,9 +109,13 @@ using mozilla::Telemetry::ScalarAction from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::KeyedScalarAction from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::DynamicScalarDefinition from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::ChildEventData from "mozilla/TelemetryComms.h";
#if defined(XP_WIN)
[MoveOnly] using mozilla::UntrustedModulesData from "mozilla/UntrustedModulesData.h";
[MoveOnly] using mozilla::ModulePaths from "mozilla/UntrustedModulesData.h";
[MoveOnly] using mozilla::ModulesMapResult from "mozilla/UntrustedModulesData.h";
#endif // defined(XP_WIN)
using mozilla::Telemetry::DiscardedData from "mozilla/TelemetryComms.h";
using mozilla::CrossProcessMutexHandle from "mozilla/ipc/CrossProcessMutex.h";
using mozilla::dom::MaybeDiscardedBrowsingContext from "mozilla/dom/BrowsingContext.h";
@ -562,11 +566,13 @@ child:
async RequestPerformanceMetrics(nsID aID);
#if defined(XP_WIN)
/**
* Used by third-party modules telemetry (aka "untrusted modules" telemetry)
* to pull data from content processes.
*/
async GetUntrustedModulesData() returns (UntrustedModulesData? data);
#endif // defined(XP_WIN)
/**
* Communication between the PuppetBidiKeyboard and the actual
@ -1665,6 +1671,7 @@ parent:
async AddOrRemovePageAwakeRequest(MaybeDiscardedBrowsingContext aContext,
bool aShouldAddCount);
#if defined(XP_WIN)
/**
* Due to sandboxing, a child process's UntrustedModulesProcessor cannot
* obtain enough information about a DLL file to determine its
@ -1673,6 +1680,7 @@ parent:
*/
async GetModulesTrust(ModulePaths aModPaths, bool aRunAtNormalPriority)
returns (ModulesMapResult? modMapResult);
#endif // defined(XP_WIN)
/**
* Used to route shutdown diagnostic info from the content process

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

@ -16,10 +16,13 @@ include protocol PSandboxTesting;
#endif
using mozilla::dom::NativeThreadId from "mozilla/dom/NativeThreadId.h";
using mozilla::PDMFactory::MediaCodecsSupported from "PDMFactory.h";
#if defined(XP_WIN)
[MoveOnly] using mozilla::UntrustedModulesData from "mozilla/UntrustedModulesData.h";
[MoveOnly] using mozilla::ModulePaths from "mozilla/UntrustedModulesData.h";
[MoveOnly] using mozilla::ModulesMapResult from "mozilla/UntrustedModulesData.h";
using mozilla::PDMFactory::MediaCodecsSupported from "PDMFactory.h";
#endif // defined(XP_WIN)
namespace mozilla {
@ -53,7 +56,9 @@ parent:
bool createHardwareDevice,
ContentDeviceData contentDeviceData);
#if defined(XP_WIN)
async GetUntrustedModulesData() returns (UntrustedModulesData? data);
#endif // defined(XP_WIN)
#if defined(MOZ_SANDBOX) && defined(MOZ_DEBUG) && defined(ENABLE_TESTS)
async InitSandboxTesting(Endpoint<PSandboxTestingChild> aEndpoint);
@ -65,8 +70,10 @@ child:
async AddMemoryReport(MemoryReport aReport);
#if defined(XP_WIN)
async GetModulesTrust(ModulePaths aModPaths, bool aRunAtNormalPriority)
returns (ModulesMapResult? modMapResult);
#endif // defined(XP_WIN)
// Update the cached list of codec supported following a check in the
// RDD parent.

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

@ -117,10 +117,10 @@ mozilla::ipc::IPCResult RDDChild::RecvAddMemoryReport(
return IPC_OK();
}
#if defined(XP_WIN)
mozilla::ipc::IPCResult RDDChild::RecvGetModulesTrust(
ModulePaths&& aModPaths, bool aRunAtNormalPriority,
GetModulesTrustResolver&& aResolver) {
#if defined(XP_WIN)
RefPtr<DllServices> dllSvc(DllServices::Get());
dllSvc->GetModulesTrust(std::move(aModPaths), aRunAtNormalPriority)
->Then(
@ -130,10 +130,8 @@ mozilla::ipc::IPCResult RDDChild::RecvGetModulesTrust(
},
[aResolver](nsresult aRv) { aResolver(Nothing()); });
return IPC_OK();
#else
return IPC_FAIL(this, "Unsupported on this platform");
#endif // defined(XP_WIN)
}
#endif // defined(XP_WIN)
mozilla::ipc::IPCResult RDDChild::RecvUpdateMediaCodecsSupported(
const PDMFactory::MediaCodecsSupported& aSupported) {

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

@ -41,9 +41,11 @@ class RDDChild final : public PRDDChild,
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult RecvAddMemoryReport(const MemoryReport& aReport);
#if defined(XP_WIN)
mozilla::ipc::IPCResult RecvGetModulesTrust(
ModulePaths&& aModPaths, bool aRunAtNormalPriority,
GetModulesTrustResolver&& aResolver);
#endif // defined(XP_WIN)
mozilla::ipc::IPCResult RecvUpdateMediaCodecsSupported(
const PDMFactory::MediaCodecsSupported& aSupported);

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

@ -232,9 +232,9 @@ mozilla::ipc::IPCResult RDDParent::RecvRequestMemoryReport(
return IPC_OK();
}
#if defined(XP_WIN)
mozilla::ipc::IPCResult RDDParent::RecvGetUntrustedModulesData(
GetUntrustedModulesDataResolver&& aResolver) {
#if defined(XP_WIN)
RefPtr<DllServices> dllSvc(DllServices::Get());
dllSvc->GetUntrustedModulesData()->Then(
GetMainThreadSerialEventTarget(), __func__,
@ -243,10 +243,8 @@ mozilla::ipc::IPCResult RDDParent::RecvGetUntrustedModulesData(
},
[aResolver](nsresult aReason) { aResolver(Nothing()); });
return IPC_OK();
#else
return IPC_FAIL(this, "Unsupported on this platform");
#endif // defined(XP_WIN)
}
#endif // defined(XP_WIN)
mozilla::ipc::IPCResult RDDParent::RecvPreferenceUpdate(const Pref& aPref) {
Preferences::SetPreference(aPref);

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

@ -44,8 +44,10 @@ class RDDParent final : public PRDDParent {
const bool& minimizeMemoryUsage,
const Maybe<ipc::FileDescriptor>& DMDFile,
const RequestMemoryReportResolver& aResolver);
#if defined(XP_WIN)
mozilla::ipc::IPCResult RecvGetUntrustedModulesData(
GetUntrustedModulesDataResolver&& aResolver);
#endif // defined(XP_WIN)
mozilla::ipc::IPCResult RecvPreferenceUpdate(const Pref& pref);
mozilla::ipc::IPCResult RecvUpdateVar(const GfxVarUpdate& pref);

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

@ -39,9 +39,10 @@ if CONFIG["OS_TARGET"] == "WINNT":
if CONFIG["MOZ_MEMORY"]:
DEFFILE = "mozglue.def"
# We'll break the DLL blocklist if we immediately load user32.dll.
# For the same reason, we delayload winmm.dll and ole32.dll which
# statically link user32.dll.
# For the same reason, we delayload these other DLLs to avoid eager
# dependencies on user32.dll.
DELAYLOAD_DLLS += [
"oleaut32.dll",
"ole32.dll",
"user32.dll",
"winmm.dll",

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

@ -50,12 +50,6 @@ SOURCES += [
OS_LIBS += CONFIG["REALTIME_LIBS"]
if CONFIG["OS_ARCH"] == "WINNT":
DIRS += [
"interceptor",
]
EXPORTS += [
"nsWindowsDllInterceptor.h",
]
EXPORTS.mozilla += [
"DynamicallyLinkedFunctionPtr.h",
"ImportDir.h",

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

@ -13,9 +13,6 @@ if CONFIG["MOZ_LINKER"] or CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
DIRS += ["android"]
if CONFIG["OS_TARGET"] == "WINNT":
DIRS += ["dllservices"]
DIRS += [
"baseprofiler",
"build",

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

@ -4,17 +4,9 @@
if CONFIG["OS_ARCH"] == "WINNT":
SOURCES += [
"TestDLLBlocklist.cpp",
"TestNativeNtGTest.cpp",
]
TEST_DIRS += [
"TestDllBlocklist_AllowByVersion",
"TestDllBlocklist_MatchByName",
"TestDllBlocklist_MatchByVersion",
"TestDllBlocklist_NoOpEntryPoint",
]
SOURCES += [
"TestStackWalk.cpp",
]

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

@ -36,9 +36,6 @@ if CONFIG["OS_ARCH"] == "WINNT":
],
linkage=None,
)
TEST_DIRS += [
"interceptor",
]
OS_LIBS += [
"ntdll",
"version",

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

@ -22,6 +22,8 @@
#include "nsWindowsHelpers.h"
#include "nsXULAppAPI.h"
namespace mozilla {
// Fills a Vector with keyboard layout DLLs found in the registry.
// These are leaf names only, not full paths. Here we will convert them to
// lowercase before returning, to facilitate case-insensitive searches.
@ -61,8 +63,6 @@ static Vector<nsString> GetKeyboardLayoutDlls() {
return result;
}
namespace mozilla {
/* static */
bool ModuleEvaluator::ResolveKnownFolder(REFKNOWNFOLDERID aFolderId,
nsIFile** aOutFile) {

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

@ -16,6 +16,8 @@
#include "nsIFile.h"
#include "nsString.h"
#include <shtypes.h>
namespace mozilla {
class ModuleRecord;

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

@ -62,6 +62,8 @@ static LONGLONG TimeUnitsToQPC(const LONGLONG aTimeStamp,
return result;
}
namespace mozilla {
static Maybe<double> QPCLoadDurationToMilliseconds(
const ModuleLoadInfo& aNtInfo) {
if (aNtInfo.IsBare()) {
@ -71,8 +73,6 @@ static Maybe<double> QPCLoadDurationToMilliseconds(
return Some(QPCToMilliseconds<double>(aNtInfo.mLoadTimeInfo.QuadPart));
}
namespace mozilla {
ModuleRecord::ModuleRecord() : mTrustFlags(ModuleTrustFlags::None) {}
ModuleRecord::ModuleRecord(const nsAString& aResolvedNtPath)

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

@ -688,12 +688,12 @@ UntrustedModulesProcessor::SendGetModulesTrust(ModulePaths&& aModules,
switch (XRE_GetProcessType()) {
case GeckoProcessType_Content: {
return ::SendGetModulesTrust(dom::ContentChild::GetSingleton(),
std::move(aModules), runNormal);
return ::mozilla::SendGetModulesTrust(dom::ContentChild::GetSingleton(),
std::move(aModules), runNormal);
}
case GeckoProcessType_RDD: {
return ::SendGetModulesTrust(RDDParent::GetSingleton(),
std::move(aModules), runNormal);
return ::mozilla::SendGetModulesTrust(RDDParent::GetSingleton(),
std::move(aModules), runNormal);
}
default: {
MOZ_ASSERT_UNREACHABLE("Unsupported process type");

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

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

@ -0,0 +1,37 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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 http://mozilla.org/MPL/2.0/.
with Files("**"):
BUG_COMPONENT = ("Core", "DLL Services")
Library("dllservices")
FINAL_LIBRARY = "xul"
EXPORTS.mozilla += [
"ModuleVersionInfo.h",
"UntrustedModulesData.h",
"UntrustedModulesProcessor.h",
"WinDllServices.h",
]
DIRS += [
"mozglue",
]
UNIFIED_SOURCES += [
"ModuleEvaluator.cpp",
"ModuleVersionInfo.cpp",
"UntrustedModulesData.cpp",
"UntrustedModulesProcessor.cpp",
"WinDllServices.cpp",
]
TEST_DIRS += [
"tests",
]
include("/ipc/chromium/chromium-config.mozbuild")

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

@ -17,6 +17,8 @@ EXPORTS.mozilla.interceptor += [
]
if CONFIG["CPU_ARCH"] == "aarch64":
Library("interceptor")
FINAL_LIBRARY = "mozglue"
UNIFIED_SOURCES += [

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

@ -4,8 +4,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
if CONFIG["MOZ_WIDGET_TOOLKIT"]:
Library("dllservices_mozglue")
if CONFIG["MOZ_WIDGET_TOOLKIT"]:
SOURCES += [
# This file contains a |using namespace mozilla;| statement
"WindowsDllBlocklist.cpp",
@ -35,6 +36,10 @@ DELAYLOAD_DLLS += [
"wintrust.dll",
]
EXPORTS += [
"nsWindowsDllInterceptor.h",
]
EXPORTS.mozilla += [
"Authenticode.h",
"CacheNtDllThunk.h",
@ -61,6 +66,11 @@ GeneratedFile(
entry_point="gen_blocklists",
inputs=["WindowsDllBlocklistDefs.in"]
)
EXPORTS.mozilla += ["!" + hdr for hdr in blocklist_files]
DIRS += [
"interceptor",
]
FINAL_LIBRARY = "mozglue"

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

@ -16,6 +16,8 @@
#include "UntrustedModulesBackupService.h"
#include "UntrustedModulesDataSerializer.h"
using namespace mozilla;
class ModuleLoadCounter final {
nsTHashMap<nsStringCaseInsensitiveHashKey, int> mCounters;

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

@ -0,0 +1,32 @@
# 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 http://mozilla.org/MPL/2.0/.
Library("dllservicestest")
UNIFIED_SOURCES += [
"TestDLLBlocklist.cpp",
]
if CONFIG["CPU_ARCH"] != "x86":
UNIFIED_SOURCES += [
"TestUntrustedModules.cpp",
]
LOCAL_INCLUDES += [
"/toolkit/components/telemetry/other",
"/toolkit/components/telemetry/tests/gtest",
]
TEST_DIRS += [
"TestDllBlocklist_AllowByVersion",
"TestDllBlocklist_MatchByName",
"TestDllBlocklist_MatchByVersion",
"TestDllBlocklist_NoOpEntryPoint",
"TestUntrustedModules_Dll1",
"TestUntrustedModules_Dll2",
]
include("/ipc/chromium/chromium-config.mozbuild")
FINAL_LIBRARY = "xul-gtest"

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

@ -13,7 +13,7 @@ GeckoCppUnitTests(
linkage=None,
)
if CONFIG["OS_TARGET"] == "WINNT" and CONFIG["CPU_ARCH"] in ("x86", "x86_64"):
if CONFIG["CPU_ARCH"] in ("x86", "x86_64"):
# Cross-process interceptors not yet supported on aarch64
GeckoCppUnitTests(
[
@ -33,8 +33,12 @@ DELAYLOAD_DLLS += [
"shlwapi.dll",
]
if CONFIG["OS_TARGET"] == "WINNT" and CONFIG["CC_TYPE"] in ("gcc", "clang"):
if CONFIG["CC_TYPE"] in ("gcc", "clang"):
# This allows us to use wmain as the entry point on mingw
LDFLAGS += [
"-municode",
]
TEST_DIRS += [
"gtest",
]

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

@ -40,7 +40,6 @@ EXPORTS.mozilla += [
"CmdLineAndEnvUtils.h",
"MultiInstanceLock.h",
"SafeMode.h",
"UntrustedModulesData.h",
]
if CONFIG["MOZ_INSTRUMENT_EVENT_LOOP"]:
@ -50,22 +49,14 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
EXPORTS.mozilla += [
"AssembleCmdLine.h",
"DllPrefetchExperimentRegistryInfo.h",
"ModuleVersionInfo.h",
"PolicyChecks.h",
"UntrustedModulesProcessor.h",
"WinDllServices.h",
"WinTokenUtils.h",
]
UNIFIED_SOURCES += [
"/toolkit/mozapps/update/common/pathhash.cpp",
"/toolkit/mozapps/update/common/updateutils_win.cpp",
"DllPrefetchExperimentRegistryInfo.cpp",
"ModuleEvaluator.cpp",
"ModuleVersionInfo.cpp",
"nsNativeAppSupportWin.cpp",
"UntrustedModulesData.cpp",
"UntrustedModulesProcessor.cpp",
"WinDllServices.cpp",
"WinTokenUtils.cpp",
]
DEFINES["PROXY_PRINTING"] = 1
@ -79,6 +70,9 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
UNIFIED_SOURCES += [
"LauncherRegistryInfo.cpp",
]
DIRS += [
"dllservices",
]
elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
EXPORTS.mozilla += [
"MacRunFromDmgUtils.h",

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

@ -10,22 +10,13 @@ UNIFIED_SOURCES = [
"TestCompatVersionCompare.cpp",
]
include("/ipc/chromium/chromium-config.mozbuild")
LOCAL_INCLUDES += [
"/toolkit/components/remote",
"/toolkit/components/telemetry/other",
"/toolkit/components/telemetry/tests/gtest",
]
if CONFIG["OS_TARGET"] == "WINNT":
UNIFIED_SOURCES += [
"TestAssembleCommandLineWin.cpp",
"TestUntrustedModules.cpp",
]
TEST_DIRS += [
"TestUntrustedModules_Dll1",
"TestUntrustedModules_Dll2",
]
FINAL_LIBRARY = "xul-gtest"