Bug 1840515 - Step 2: Preload the omnijars in the fork server. r=nika

This extends the previous support for `-greomni` and `-appomni` to the
fork server, so that it can pre-open the jar files and thus continue
using the correct versions in forked child processes even if the files on
disk are replaced by an update or deleted.

Differential Revision: https://phabricator.services.mozilla.com/D185331
This commit is contained in:
Jed Davis 2023-08-09 21:35:50 +00:00
Родитель 2ad421aaf8
Коммит 583d256da7
3 изменённых файлов: 28 добавлений и 9 удалений

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

@ -151,8 +151,11 @@ bool ContentProcess::Init(int aArgc, char* aArgv[]) {
return false;
}
// Handle the -greomni/-appomni flags
Omnijar::ChildProcessInit(aArgc, aArgv);
// Handle the -greomni/-appomni flags (unless the forkserver already
// preloaded the jar(s)).
if (!Omnijar::IsInitialized()) {
Omnijar::ChildProcessInit(aArgc, aArgv);
}
rv = NS_InitXPCOM(nullptr, xpcomAppDir, &mDirProvider);
if (NS_FAILED(rv)) {

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

@ -1,21 +1,24 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
/* -*- 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 "mozilla/ipc/ForkServer.h"
#include "mozilla/Logging.h"
#include "chrome/common/chrome_switches.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "mozilla/BlockingResourceBase.h"
#include "mozilla/ipc/ProtocolMessageUtils.h"
#include "mozilla/Logging.h"
#include "mozilla/Omnijar.h"
#include "mozilla/ipc/FileDescriptor.h"
#include "mozilla/ipc/IPDLParamTraits.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "mozilla/ipc/ProtocolMessageUtils.h"
#include "nsTraceRefcnt.h"
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
# include "mozilla/SandboxLaunch.h"
@ -40,6 +43,16 @@ void ForkServer::InitProcess(int* aArgc, char*** aArgv) {
DataBufferClear::AfterReceiving);
}
/**
* Preload any resources that the forked child processes might need,
* and which might change incompatibly or become unavailable by the
* time they're started. For example: the omnijar files, or certain
* shared libraries.
*/
static void ForkServerPreload(int& aArgc, char** aArgv) {
Omnijar::ChildProcessInit(aArgc, aArgv);
}
/**
* Start providing the service at the IPC channel.
*/
@ -251,6 +264,7 @@ bool ForkServer::RunForkServer(int* aArgc, char*** aArgv) {
XRE_SetProcessType("forkserver");
NS_LogInit();
mozilla::LogModule::Init(0, nullptr);
ForkServerPreload(*aArgc, *aArgv);
MOZ_LOG(gForkServiceLog, LogLevel::Verbose, ("Start a fork server"));
{
DebugOnly<base::ProcessHandle> forkserver_pid = base::GetCurrentProcId();

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

@ -1255,7 +1255,9 @@ Result<Ok, LaunchError> PosixProcessLauncher::DoSetup() {
mChildArgv.insert(mChildArgv.end(), mExtraOpts.begin(), mExtraOpts.end());
if (mProcessType == GeckoProcessType_Content && Omnijar::IsInitialized()) {
if ((mProcessType == GeckoProcessType_Content ||
mProcessType == GeckoProcessType_ForkServer) &&
Omnijar::IsInitialized()) {
// Make sure that child processes can find the omnijar, if they
// use full XPCOM. See Omnijar::ChildProcessInit and its callers.
nsAutoCString path;