2018-11-14 21:06:24 +03:00
|
|
|
/* -*- 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 http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "RDDParent.h"
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
2021-01-04 08:43:08 +03:00
|
|
|
# include "mozilla/gfx/DeviceManagerDx.h"
|
2021-01-04 02:21:54 +03:00
|
|
|
# include "WMF.h"
|
2021-01-04 08:43:08 +03:00
|
|
|
# include <process.h>
|
|
|
|
# include <dwrite.h>
|
2019-12-07 01:12:22 +03:00
|
|
|
# include "mozilla/WinDllServices.h"
|
2020-02-13 15:35:40 +03:00
|
|
|
#else
|
|
|
|
# include <unistd.h>
|
2018-11-14 21:06:24 +03:00
|
|
|
#endif
|
|
|
|
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "chrome/common/ipc_channel.h"
|
2018-11-14 21:06:24 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/HangDetails.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2018-11-14 21:06:24 +03:00
|
|
|
#include "mozilla/RemoteDecoderManagerChild.h"
|
|
|
|
#include "mozilla/RemoteDecoderManagerParent.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/dom/MemoryReportRequest.h"
|
|
|
|
#include "mozilla/ipc/CrashReporterClient.h"
|
|
|
|
#include "mozilla/ipc/ProcessChild.h"
|
2021-01-04 08:43:08 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
|
|
|
#include "gfxConfig.h"
|
2018-11-14 21:06:24 +03:00
|
|
|
|
2019-02-27 23:14:54 +03:00
|
|
|
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
|
|
|
|
# include "mozilla/Sandbox.h"
|
|
|
|
#endif
|
|
|
|
|
2018-11-14 21:06:24 +03:00
|
|
|
#ifdef MOZ_GECKO_PROFILER
|
|
|
|
# include "ChildProfilerController.h"
|
|
|
|
#endif
|
2018-11-21 03:11:20 +03:00
|
|
|
|
|
|
|
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
|
|
|
|
# include "mozilla/Sandbox.h"
|
|
|
|
# include "nsMacUtilsImpl.h"
|
2021-01-04 08:43:08 +03:00
|
|
|
# include "RDDProcessHost.h"
|
2018-11-21 03:11:20 +03:00
|
|
|
#endif
|
|
|
|
|
2018-11-14 21:06:24 +03:00
|
|
|
#include "nsDebugImpl.h"
|
|
|
|
#include "nsThreadManager.h"
|
2021-01-04 08:43:08 +03:00
|
|
|
#include "ProcessUtils.h"
|
2018-11-14 21:06:24 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace ipc;
|
2019-06-28 10:08:43 +03:00
|
|
|
using namespace gfx;
|
2018-11-14 21:06:24 +03:00
|
|
|
|
|
|
|
static RDDParent* sRDDParent;
|
|
|
|
|
|
|
|
RDDParent::RDDParent() : mLaunchTime(TimeStamp::Now()) { sRDDParent = this; }
|
|
|
|
|
|
|
|
RDDParent::~RDDParent() { sRDDParent = nullptr; }
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
2020-09-18 14:07:13 +03:00
|
|
|
RDDParent* RDDParent::GetSingleton() {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(sRDDParent);
|
|
|
|
return sRDDParent;
|
|
|
|
}
|
2018-11-14 21:06:24 +03:00
|
|
|
|
|
|
|
bool RDDParent::Init(base::ProcessId aParentPid, const char* aParentBuildID,
|
2020-02-07 01:41:56 +03:00
|
|
|
MessageLoop* aIOLoop, UniquePtr<IPC::Channel> aChannel) {
|
2018-11-14 21:06:24 +03:00
|
|
|
// Initialize the thread manager before starting IPC. Otherwise, messages
|
|
|
|
// may be posted to the main thread and we won't be able to process them.
|
|
|
|
if (NS_WARN_IF(NS_FAILED(nsThreadManager::get().Init()))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now it's safe to start IPC.
|
2020-02-07 01:41:56 +03:00
|
|
|
if (NS_WARN_IF(!Open(std::move(aChannel), aParentPid, aIOLoop))) {
|
2018-11-14 21:06:24 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDebugImpl::SetMultiprocessMode("RDD");
|
|
|
|
|
|
|
|
// This must be checked before any IPDL message, which may hit sentinel
|
|
|
|
// errors due to parent and content processes having different
|
|
|
|
// versions.
|
|
|
|
MessageChannel* channel = GetIPCChannel();
|
|
|
|
if (channel && !channel->SendBuildIDsMatchMessage(aParentBuildID)) {
|
|
|
|
// We need to quit this process if the buildID doesn't match the parent's.
|
|
|
|
// This can occur when an update occurred in the background.
|
|
|
|
ProcessChild::QuickExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init crash reporter support.
|
|
|
|
CrashReporterClient::InitSingleton(this);
|
|
|
|
|
|
|
|
if (NS_FAILED(NS_InitMinimalXPCOM())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-21 02:26:52 +03:00
|
|
|
gfxConfig::Init();
|
2019-06-28 10:08:43 +03:00
|
|
|
gfxVars::Initialize();
|
2020-10-21 02:26:52 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
DeviceManagerDx::Init();
|
|
|
|
wmf::MFStartup();
|
|
|
|
#endif
|
2019-06-28 10:08:43 +03:00
|
|
|
|
2018-11-14 21:06:24 +03:00
|
|
|
mozilla::ipc::SetThisProcessName("RDD Process");
|
2019-12-07 01:12:22 +03:00
|
|
|
|
2018-11-14 21:06:24 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-21 03:11:20 +03:00
|
|
|
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
|
|
|
|
extern "C" {
|
|
|
|
void CGSShutdownServerConnections();
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2019-03-01 00:20:40 +03:00
|
|
|
mozilla::ipc::IPCResult RDDParent::RecvInit(
|
2020-02-06 08:53:19 +03:00
|
|
|
nsTArray<GfxVarUpdate>&& vars, const Maybe<FileDescriptor>& aBrokerFd,
|
|
|
|
const bool& aCanRecordReleaseTelemetry) {
|
2019-06-28 10:08:43 +03:00
|
|
|
for (const auto& var : vars) {
|
|
|
|
gfxVars::ApplyUpdate(var);
|
|
|
|
}
|
|
|
|
|
2019-02-27 23:14:54 +03:00
|
|
|
#if defined(MOZ_SANDBOX)
|
|
|
|
# if defined(XP_MACOSX)
|
2019-03-28 05:25:50 +03:00
|
|
|
// Close all current connections to the WindowServer. This ensures that the
|
|
|
|
// Activity Monitor will not label the content process as "Not responding"
|
|
|
|
// because it's not running a native event loop. See bug 1384336.
|
|
|
|
CGSShutdownServerConnections();
|
|
|
|
|
2019-02-27 23:14:54 +03:00
|
|
|
# elif defined(XP_LINUX)
|
|
|
|
int fd = -1;
|
2019-03-01 00:20:40 +03:00
|
|
|
if (aBrokerFd.isSome()) {
|
|
|
|
fd = aBrokerFd.value().ClonePlatformHandle().release();
|
2019-02-27 23:14:54 +03:00
|
|
|
}
|
|
|
|
SetRemoteDataDecoderSandbox(fd);
|
|
|
|
# endif // XP_MACOSX/XP_LINUX
|
|
|
|
#endif // MOZ_SANDBOX
|
2018-11-21 03:11:20 +03:00
|
|
|
|
2020-02-06 08:53:19 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
if (aCanRecordReleaseTelemetry) {
|
|
|
|
RefPtr<DllServices> dllSvc(DllServices::Get());
|
|
|
|
dllSvc->StartUntrustedModulesProcessor();
|
|
|
|
}
|
|
|
|
#endif // defined(XP_WIN)
|
2018-11-14 21:06:24 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-06-28 10:08:43 +03:00
|
|
|
IPCResult RDDParent::RecvUpdateVar(const GfxVarUpdate& aUpdate) {
|
|
|
|
gfxVars::ApplyUpdate(aUpdate);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-11-14 21:06:24 +03:00
|
|
|
mozilla::ipc::IPCResult RDDParent::RecvInitProfiler(
|
|
|
|
Endpoint<PProfilerChild>&& aEndpoint) {
|
|
|
|
#ifdef MOZ_GECKO_PROFILER
|
|
|
|
mProfilerController = ChildProfilerController::Create(std::move(aEndpoint));
|
|
|
|
#endif
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult RDDParent::RecvNewContentRemoteDecoderManager(
|
|
|
|
Endpoint<PRemoteDecoderManagerParent>&& aEndpoint) {
|
|
|
|
if (!RemoteDecoderManagerParent::CreateForContent(std::move(aEndpoint))) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-11-04 06:41:57 +03:00
|
|
|
mozilla::ipc::IPCResult RDDParent::RecvInitVideoBridge(
|
2020-12-07 13:17:57 +03:00
|
|
|
Endpoint<PVideoBridgeChild>&& aEndpoint, const bool& aCreateHardwareDevice,
|
2020-10-21 02:26:52 +03:00
|
|
|
const ContentDeviceData& aContentDeviceData) {
|
2019-11-04 06:41:57 +03:00
|
|
|
if (!RemoteDecoderManagerParent::CreateVideoBridgeToOtherProcess(
|
2019-06-28 09:32:43 +03:00
|
|
|
std::move(aEndpoint))) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
2020-10-21 02:26:52 +03:00
|
|
|
|
|
|
|
gfxConfig::Inherit(
|
|
|
|
{
|
|
|
|
Feature::HW_COMPOSITING,
|
|
|
|
Feature::D3D11_COMPOSITING,
|
|
|
|
Feature::OPENGL_COMPOSITING,
|
|
|
|
Feature::ADVANCED_LAYERS,
|
|
|
|
Feature::DIRECT2D,
|
|
|
|
Feature::WEBGPU,
|
|
|
|
},
|
|
|
|
aContentDeviceData.prefs());
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING)) {
|
|
|
|
auto* devmgr = DeviceManagerDx::Get();
|
|
|
|
if (devmgr) {
|
|
|
|
devmgr->ImportDeviceInfo(aContentDeviceData.d3d11());
|
2020-11-24 09:38:29 +03:00
|
|
|
if (aCreateHardwareDevice) {
|
|
|
|
devmgr->CreateContentDevices();
|
|
|
|
}
|
2020-10-21 02:26:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-28 09:32:43 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-11-14 21:06:24 +03:00
|
|
|
mozilla::ipc::IPCResult RDDParent::RecvRequestMemoryReport(
|
|
|
|
const uint32_t& aGeneration, const bool& aAnonymize,
|
2020-08-03 21:29:45 +03:00
|
|
|
const bool& aMinimizeMemoryUsage, const Maybe<FileDescriptor>& aDMDFile,
|
|
|
|
const RequestMemoryReportResolver& aResolver) {
|
2018-11-14 21:06:24 +03:00
|
|
|
nsPrintfCString processName("RDD (pid %u)", (unsigned)getpid());
|
|
|
|
|
|
|
|
mozilla::dom::MemoryReportRequestClient::Start(
|
2019-01-03 00:18:13 +03:00
|
|
|
aGeneration, aAnonymize, aMinimizeMemoryUsage, aDMDFile, processName,
|
|
|
|
[&](const MemoryReport& aReport) {
|
|
|
|
Unused << GetSingleton()->SendAddMemoryReport(aReport);
|
|
|
|
},
|
2020-08-03 21:29:45 +03:00
|
|
|
aResolver);
|
2018-11-14 21:06:24 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-12-07 01:12:22 +03:00
|
|
|
mozilla::ipc::IPCResult RDDParent::RecvGetUntrustedModulesData(
|
|
|
|
GetUntrustedModulesDataResolver&& aResolver) {
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
RefPtr<DllServices> dllSvc(DllServices::Get());
|
|
|
|
dllSvc->GetUntrustedModulesData()->Then(
|
|
|
|
GetMainThreadSerialEventTarget(), __func__,
|
|
|
|
[aResolver](Maybe<UntrustedModulesData>&& aData) {
|
|
|
|
aResolver(std::move(aData));
|
|
|
|
},
|
|
|
|
[aResolver](nsresult aReason) { aResolver(Nothing()); });
|
|
|
|
return IPC_OK();
|
|
|
|
#else
|
|
|
|
return IPC_FAIL(this, "Unsupported on this platform");
|
|
|
|
#endif // defined(XP_WIN)
|
|
|
|
}
|
|
|
|
|
2019-05-25 13:12:47 +03:00
|
|
|
mozilla::ipc::IPCResult RDDParent::RecvPreferenceUpdate(const Pref& aPref) {
|
|
|
|
Preferences::SetPreference(aPref);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-11-14 21:06:24 +03:00
|
|
|
void RDDParent::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
if (AbnormalShutdown == aWhy) {
|
|
|
|
NS_WARNING("Shutting down RDD process early due to a crash!");
|
|
|
|
ProcessChild::QuickExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NS_FREE_PERMANENT_DATA
|
2020-10-21 02:26:52 +03:00
|
|
|
# ifdef XP_WIN
|
|
|
|
wmf::MFShutdown();
|
|
|
|
# endif
|
2018-11-14 21:06:24 +03:00
|
|
|
// No point in going through XPCOM shutdown because we don't keep persistent
|
|
|
|
// state.
|
|
|
|
ProcessChild::QuickExit();
|
|
|
|
#endif
|
|
|
|
|
2020-09-18 14:07:13 +03:00
|
|
|
// Wait until all RemoteDecoderManagerParent have closed.
|
|
|
|
mShutdownBlockers.WaitUntilClear(10 * 1000 /* 10s timeout*/)
|
|
|
|
->Then(GetCurrentSerialEventTarget(), __func__, [this]() {
|
|
|
|
|
2020-10-21 02:26:52 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
wmf::MFShutdown();
|
|
|
|
#endif
|
|
|
|
|
2019-12-07 01:12:22 +03:00
|
|
|
#if defined(XP_WIN)
|
2020-09-18 14:07:13 +03:00
|
|
|
RefPtr<DllServices> dllSvc(DllServices::Get());
|
|
|
|
dllSvc->DisableFull();
|
2019-12-07 01:12:22 +03:00
|
|
|
#endif // defined(XP_WIN)
|
|
|
|
|
2018-11-14 21:06:24 +03:00
|
|
|
#ifdef MOZ_GECKO_PROFILER
|
2020-09-18 14:07:13 +03:00
|
|
|
if (mProfilerController) {
|
|
|
|
mProfilerController->Shutdown();
|
|
|
|
mProfilerController = nullptr;
|
|
|
|
}
|
2018-11-14 21:06:24 +03:00
|
|
|
#endif
|
2019-06-27 08:19:28 +03:00
|
|
|
|
2020-09-18 14:07:13 +03:00
|
|
|
RemoteDecoderManagerParent::ShutdownVideoBridge();
|
2019-06-28 09:33:00 +03:00
|
|
|
|
2020-10-21 02:26:52 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
DeviceManagerDx::Shutdown();
|
|
|
|
#endif
|
2020-09-18 14:07:13 +03:00
|
|
|
gfxVars::Shutdown();
|
2020-10-21 02:26:52 +03:00
|
|
|
gfxConfig::Shutdown();
|
2020-09-18 14:07:13 +03:00
|
|
|
CrashReporterClient::DestroySingleton();
|
|
|
|
XRE_ShutdownChildProcess();
|
|
|
|
});
|
2018-11-14 21:06:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|