Backed out changeset fe716ee1a126 (bug 1723505) for causing build bustages. CLOSED TREE

This commit is contained in:
Marian-Vasile Laza 2021-10-26 20:45:47 +03:00
Родитель 6a1834810c
Коммит f8576fec48
16 изменённых файлов: 360 добавлений и 184 удалений

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

@ -15,7 +15,6 @@
#include "ContentParent.h"
#include "mozilla/ipc/ProcessUtils.h"
#include "mozilla/CmdLineAndEnvUtils.h"
#include "BrowserParent.h"
#include "chrome/common/process_watcher.h"
@ -59,7 +58,6 @@
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/FOGIPC.h"
#include "mozilla/GlobalStyleSheetCache.h"
#include "mozilla/GeckoArgs.h"
#include "mozilla/HangDetails.h"
#include "mozilla/LoginReputationIPC.h"
#include "mozilla/LookAndFeel.h"
@ -2511,9 +2509,11 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {
}
std::vector<std::string> extraArgs;
geckoargs::sChildID.Put(mChildID, extraArgs);
geckoargs::sIsForBrowser.Put(IsForBrowser(), extraArgs);
geckoargs::sNotForBrowser.Put(!IsForBrowser(), extraArgs);
extraArgs.push_back("-childID");
char idStr[21];
SprintfLiteral(idStr, "%" PRId64, static_cast<uint64_t>(mChildID));
extraArgs.push_back(idStr);
extraArgs.push_back(IsForBrowser() ? "-isForBrowser" : "-notForBrowser");
// Prefs information is passed via anonymous shared memory to avoid bloating
// the command line.
@ -2540,7 +2540,7 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {
Preferences::AddStrongObserver(this, "");
if (gSafeMode) {
geckoargs::sSafeMode.Put(extraArgs);
extraArgs.push_back("-safeMode");
}
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
@ -2551,7 +2551,8 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {
#endif
nsCString parentBuildID(mozilla::PlatformBuildID());
geckoargs::sParentBuildID.Put(parentBuildID.get(), extraArgs);
extraArgs.push_back("-parentBuildID");
extraArgs.push_back(parentBuildID.get());
#ifdef MOZ_WIDGET_GTK
// This is X11-only pending a solution for WebGL in Wayland mode.

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

@ -29,7 +29,6 @@
#include "nsAppRunner.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/ProcessUtils.h"
#include "mozilla/GeckoArgs.h"
using mozilla::ipc::IOThreadChild;
@ -86,55 +85,106 @@ static void SetUpSandboxEnvironment() {
#endif
bool ContentProcess::Init(int aArgc, char* aArgv[]) {
Maybe<uint64_t> childID = geckoargs::sChildID.Get(aArgc, aArgv);
Maybe<bool> isForBrowser = Nothing();
Maybe<const char*> parentBuildID =
geckoargs::sParentBuildID.Get(aArgc, aArgv);
Maybe<uint64_t> jsInitHandle;
Maybe<uint64_t> jsInitLen = geckoargs::sJsInitLen.Get(aArgc, aArgv);
Maybe<uint64_t> childID;
Maybe<bool> isForBrowser;
Maybe<const char*> parentBuildID;
char* prefsHandle = nullptr;
char* prefMapHandle = nullptr;
char* prefsLen = nullptr;
char* prefMapSize = nullptr;
char* jsInitHandle = nullptr;
char* jsInitLen = nullptr;
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
nsCOMPtr<nsIFile> profileDir;
#endif
Maybe<const char*> appDir = geckoargs::sAppDir.Get(aArgc, aArgv);
if (appDir.isSome()) {
mXREEmbed.SetAppDir(nsDependentCString(*appDir));
}
for (int i = 1; i < aArgc; i++) {
if (!aArgv[i]) {
continue;
}
Maybe<bool> safeMode = geckoargs::sSafeMode.Get(aArgc, aArgv);
if (safeMode.isSome()) {
gSafeMode = *safeMode;
}
if (strcmp(aArgv[i], "-appdir") == 0) {
if (++i == aArgc) {
return false;
}
nsDependentCString appDir(aArgv[i]);
mXREEmbed.SetAppDir(appDir);
Maybe<bool> isForBrowerParam = geckoargs::sIsForBrowser.Get(aArgc, aArgv);
Maybe<bool> notForBrowserParam = geckoargs::sNotForBrowser.Get(aArgc, aArgv);
if (isForBrowerParam.isSome()) {
isForBrowser = Some(true);
}
if (notForBrowserParam.isSome()) {
isForBrowser = Some(false);
}
} else if (strcmp(aArgv[i], "-childID") == 0) {
if (++i == aArgc) {
return false;
}
char* str = aArgv[i];
childID = Some(strtoull(str, &str, 10));
if (str[0] != '\0') {
return false;
}
} else if (strcmp(aArgv[i], "-isForBrowser") == 0) {
isForBrowser = Some(true);
} else if (strcmp(aArgv[i], "-notForBrowser") == 0) {
isForBrowser = Some(false);
// command line: [-jsInitHandle handle] -jsInitLen length
#ifdef XP_WIN
jsInitHandle = geckoargs::sJsInitHandle.Get(aArgc, aArgv);
} else if (strcmp(aArgv[i], "-prefsHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefsHandle = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefMapHandle = aArgv[i];
#endif
} else if (strcmp(aArgv[i], "-prefsLen") == 0) {
if (++i == aArgc) {
return false;
}
prefsLen = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapSize") == 0) {
if (++i == aArgc) {
return false;
}
prefMapSize = aArgv[i];
} else if (strcmp(aArgv[i], "-jsInit") == 0) {
// command line: -jsInit [handle] length
#ifdef XP_WIN
if (++i == aArgc) {
return false;
}
jsInitHandle = aArgv[i];
#endif
if (++i == aArgc) {
return false;
}
jsInitLen = aArgv[i];
} else if (strcmp(aArgv[i], "-safeMode") == 0) {
gSafeMode = true;
} else if (strcmp(aArgv[i], "-parentBuildID") == 0) {
if (++i == aArgc) {
return false;
}
parentBuildID = Some(aArgv[i]);
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
bool flag;
Maybe<const char*> profile = geckoargs::sProfile.Get(aArgc, aArgv);
// xpcshell self-test on macOS will hit this, so check isSome() otherwise
// Maybe<> assertions will MOZ_CRASH() us.
if (profile.isSome()) {
nsresult rv = XRE_GetFileFromPath(*profile, getter_AddRefs(profileDir));
if (NS_FAILED(rv) || NS_FAILED(profileDir->Exists(&flag)) || !flag) {
NS_WARNING("Invalid profile directory passed to content process.");
profileDir = nullptr;
}
} else {
NS_WARNING("No profile directory passed to content process.");
}
} else if (strcmp(aArgv[i], "-profile") == 0) {
if (++i == aArgc) {
return false;
}
bool flag;
nsresult rv = XRE_GetFileFromPath(aArgv[i], getter_AddRefs(profileDir));
if (NS_FAILED(rv) || NS_FAILED(profileDir->Exists(&flag)) || !flag) {
NS_WARNING("Invalid profile directory passed to content process.");
profileDir = nullptr;
}
#endif /* XP_MACOSX && MOZ_SANDBOX */
}
}
// Did we find all the mandatory flags?
if (childID.isNothing() || isForBrowser.isNothing() ||
@ -142,12 +192,13 @@ bool ContentProcess::Init(int aArgc, char* aArgv[]) {
return false;
}
if (!ProcessChild::InitPrefs(aArgc, aArgv)) {
::mozilla::ipc::SharedPreferenceDeserializer deserializer;
if (!deserializer.DeserializeFromSharedMemory(prefsHandle, prefMapHandle,
prefsLen, prefMapSize)) {
return false;
}
if (!::mozilla::ipc::ImportSharedJSInit(jsInitHandle.valueOr(0),
jsInitLen.valueOr(0))) {
if (!::mozilla::ipc::ImportSharedJSInit(jsInitHandle, jsInitLen)) {
return false;
}

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

@ -6,7 +6,6 @@
#include "RDDProcessImpl.h"
#include "mozilla/ipc/IOThreadChild.h"
#include "mozilla/GeckoArgs.h"
#if defined(OS_WIN) && defined(MOZ_SANDBOX)
# include "mozilla/sandboxTarget.h"
@ -38,17 +37,50 @@ bool RDDProcessImpl::Init(int aArgc, char* aArgv[]) {
PR_LoadLibrary("libmozavutil.so");
StartOpenBSDSandbox(GeckoProcessType_RDD);
#endif
Maybe<const char*> parentBuildID =
geckoargs::sParentBuildID.Get(aArgc, aArgv);
if (parentBuildID.isNothing()) {
char* parentBuildID = nullptr;
char* prefsHandle = nullptr;
char* prefMapHandle = nullptr;
char* prefsLen = nullptr;
char* prefMapSize = nullptr;
for (int i = 1; i < aArgc; i++) {
if (!aArgv[i]) {
continue;
}
if (strcmp(aArgv[i], "-parentBuildID") == 0) {
parentBuildID = aArgv[i + 1];
#ifdef XP_WIN
} else if (strcmp(aArgv[i], "-prefsHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefsHandle = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefMapHandle = aArgv[i];
#endif
} else if (strcmp(aArgv[i], "-prefsLen") == 0) {
if (++i == aArgc) {
return false;
}
prefsLen = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapSize") == 0) {
if (++i == aArgc) {
return false;
}
prefMapSize = aArgv[i];
}
}
SharedPreferenceDeserializer deserializer;
if (!deserializer.DeserializeFromSharedMemory(prefsHandle, prefMapHandle,
prefsLen, prefMapSize)) {
return false;
}
if (!ProcessChild::InitPrefs(aArgc, aArgv)) {
return false;
}
return mRDD.Init(ParentPid(), *parentBuildID,
return mRDD.Init(ParentPid(), parentBuildID,
IOThreadChild::TakeInitialPort());
}

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

@ -16,7 +16,6 @@
#include "mozilla/dom/ContentParent.h"
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/layers/CompositorThread.h"
#include "mozilla/layers/VideoBridgeParent.h"
#include "nsAppRunner.h"
@ -129,7 +128,9 @@ RefPtr<GenericNonExclusivePromise> RDDProcessManager::LaunchRDDProcess() {
}
std::vector<std::string> extraArgs;
ipc::ProcessChild::AddPlatformBuildID(extraArgs);
nsCString parentBuildID(mozilla::PlatformBuildID());
extraArgs.push_back("-parentBuildID");
extraArgs.push_back(parentBuildID.get());
// The subprocess is launched asynchronously, so we
// wait for the promise to be resolved to acquire the IPDL actor.

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

@ -7,7 +7,6 @@
#include "mozilla/ipc/IOThreadChild.h"
#include "nsXPCOM.h"
#include "mozilla/ipc/ProcessUtils.h"
#include "mozilla/GeckoArgs.h"
#if defined(OS_WIN) && defined(MOZ_SANDBOX)
# include "mozilla/sandboxTarget.h"
@ -31,18 +30,50 @@ bool GPUProcessImpl::Init(int aArgc, char* aArgv[]) {
#elif defined(__OpenBSD__) && defined(MOZ_SANDBOX)
StartOpenBSDSandbox(GeckoProcessType_GPU);
#endif
char* parentBuildID = nullptr;
char* prefsHandle = nullptr;
char* prefMapHandle = nullptr;
char* prefsLen = nullptr;
char* prefMapSize = nullptr;
for (int i = 1; i < aArgc; i++) {
if (!aArgv[i]) {
continue;
}
if (strcmp(aArgv[i], "-parentBuildID") == 0) {
parentBuildID = aArgv[i + 1];
Maybe<const char*> parentBuildID =
geckoargs::sParentBuildID.Get(aArgc, aArgv);
if (parentBuildID.isNothing()) {
#ifdef XP_WIN
} else if (strcmp(aArgv[i], "-prefsHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefsHandle = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefMapHandle = aArgv[i];
#endif
} else if (strcmp(aArgv[i], "-prefsLen") == 0) {
if (++i == aArgc) {
return false;
}
prefsLen = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapSize") == 0) {
if (++i == aArgc) {
return false;
}
prefMapSize = aArgv[i];
}
}
SharedPreferenceDeserializer deserializer;
if (!deserializer.DeserializeFromSharedMemory(prefsHandle, prefMapHandle,
prefsLen, prefMapSize)) {
return false;
}
if (!ProcessChild::InitPrefs(aArgc, aArgv)) {
return false;
}
return mGPU.Init(ParentPid(), *parentBuildID,
return mGPU.Init(ParentPid(), parentBuildID,
IOThreadChild::TakeInitialPort());
}

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

@ -24,7 +24,6 @@
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/gfx/GPUChild.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/layers/APZCTreeManagerChild.h"
#include "mozilla/layers/APZInputBridgeChild.h"
#include "mozilla/layers/CompositorBridgeChild.h"
@ -192,7 +191,9 @@ void GPUProcessManager::LaunchGPUProcess() {
mProcessStable = false;
std::vector<std::string> extraArgs;
ipc::ProcessChild::AddPlatformBuildID(extraArgs);
nsCString parentBuildID(mozilla::PlatformBuildID());
extraArgs.push_back("-parentBuildID");
extraArgs.push_back(parentBuildID.get());
// The subprocess is launched asynchronously, so we wait for a callback to
// acquire the IPDL actor.

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

@ -7,7 +7,6 @@
#include "VRProcessChild.h"
#include "mozilla/BackgroundHangMonitor.h"
#include "mozilla/GeckoArgs.h"
#include "mozilla/ipc/IOThreadChild.h"
#include "mozilla/ipc/ProcessUtils.h"
@ -29,19 +28,51 @@ VRParent* VRProcessChild::GetVRParent() {
}
bool VRProcessChild::Init(int aArgc, char* aArgv[]) {
Maybe<const char*> parentBuildID =
geckoargs::sParentBuildID.Get(aArgc, aArgv);
if (parentBuildID.isNothing()) {
return false;
char* parentBuildID = nullptr;
char* prefsHandle = nullptr;
char* prefMapHandle = nullptr;
char* prefsLen = nullptr;
char* prefMapSize = nullptr;
for (int i = 1; i < aArgc; i++) {
if (!aArgv[i]) {
continue;
}
if (strcmp(aArgv[i], "-parentBuildID") == 0) {
parentBuildID = aArgv[i + 1];
#ifdef XP_WIN
} else if (strcmp(aArgv[i], "-prefsHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefsHandle = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefMapHandle = aArgv[i];
#endif
} else if (strcmp(aArgv[i], "-prefsLen") == 0) {
if (++i == aArgc) {
return false;
}
prefsLen = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapSize") == 0) {
if (++i == aArgc) {
return false;
}
prefMapSize = aArgv[i];
}
}
if (!ProcessChild::InitPrefs(aArgc, aArgv)) {
ipc::SharedPreferenceDeserializer deserializer;
if (!deserializer.DeserializeFromSharedMemory(prefsHandle, prefMapHandle,
prefsLen, prefMapSize)) {
return false;
}
sVRParent = new VRParent();
sVRParent->Init(ParentPid(), *parentBuildID,
IOThreadChild::TakeInitialPort());
sVRParent->Init(ParentPid(), parentBuildID, IOThreadChild::TakeInitialPort());
return true;
}

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

@ -11,7 +11,6 @@
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/gfx/GPUChild.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/ipc/ProcessUtils.h"
#include "mozilla/ipc/ProtocolTypes.h"
#include "mozilla/ipc/ProtocolUtils.h" // for IToplevelProtocol
@ -60,7 +59,9 @@ bool VRProcessParent::Launch() {
mLaunchPhase = LaunchPhase::Waiting;
std::vector<std::string> extraArgs;
ProcessChild::AddPlatformBuildID(extraArgs);
nsCString parentBuildID(mozilla::PlatformBuildID());
extraArgs.push_back("-parentBuildID");
extraArgs.push_back(parentBuildID.get());
mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
if (!mPrefSerializer->SerializeToSharedMemory()) {

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

@ -36,7 +36,6 @@
#include "mozilla/LinkedList.h"
#include "mozilla/Logging.h"
#include "mozilla/Maybe.h"
#include "mozilla/GeckoArgs.h"
#include "mozilla/Omnijar.h"
#include "mozilla/RDDProcessHost.h"
#include "mozilla/Scoped.h"
@ -985,13 +984,14 @@ AddAppDirToCommandLine(std::vector<std::string>& aCmdLine, nsIFile* aAppDir,
#if defined(XP_WIN)
nsString path;
MOZ_ALWAYS_SUCCEEDS(aAppDir->GetPath(path));
aCmdLine.AppendLooseValue(UTF8ToWide(geckoargs::sAppDir.Name()));
aCmdLine.AppendLooseValue(UTF8ToWide("-appdir"));
std::wstring wpath(path.get());
aCmdLine.AppendLooseValue(wpath);
#else
nsAutoCString path;
MOZ_ALWAYS_SUCCEEDS(aAppDir->GetNativePath(path));
geckoargs::sAppDir.Put(path.get(), aCmdLine);
aCmdLine.push_back("-appdir");
aCmdLine.push_back(path.get());
#endif
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
@ -1005,7 +1005,8 @@ AddAppDirToCommandLine(std::vector<std::string>& aCmdLine, nsIFile* aAppDir,
mozilla::Unused << aProfileDir->Normalize();
nsAutoCString path;
MOZ_ALWAYS_SUCCEEDS(aProfileDir->GetNativePath(path));
geckoargs::sProfile.Put(path.get(), aCmdLine);
aCmdLine.push_back("-profile");
aCmdLine.push_back(path.get());
}
#endif
}

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

@ -14,10 +14,8 @@
# include <unistd.h> // for _exit()
#endif
#include "nsAppRunner.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/ipc/IOThreadChild.h"
#include "mozilla/GeckoArgs.h"
namespace mozilla {
namespace ipc {
@ -35,37 +33,6 @@ ProcessChild::ProcessChild(ProcessId aParentPid)
gProcessChild = this;
}
/* static */
void ProcessChild::AddPlatformBuildID(std::vector<std::string>& aExtraArgs) {
nsCString parentBuildID(mozilla::PlatformBuildID());
geckoargs::sParentBuildID.Put(parentBuildID.get(), aExtraArgs);
}
/* static */
bool ProcessChild::InitPrefs(int aArgc, char* aArgv[]) {
Maybe<uint64_t> prefsHandle = Some(0);
Maybe<uint64_t> prefMapHandle = Some(0);
Maybe<uint64_t> prefsLen = geckoargs::sPrefsLen.Get(aArgc, aArgv);
Maybe<uint64_t> prefMapSize = geckoargs::sPrefMapSize.Get(aArgc, aArgv);
if (prefsLen.isNothing() || prefMapSize.isNothing()) {
return false;
}
#ifdef XP_WIN
prefsHandle = geckoargs::sPrefsHandle.Get(aArgc, aArgv);
prefMapHandle = geckoargs::sPrefMapHandle.Get(aArgc, aArgv);
if (prefsHandle.isNothing() || prefMapHandle.isNothing()) {
return false;
}
#endif
SharedPreferenceDeserializer deserializer;
return deserializer.DeserializeFromSharedMemory(*prefsHandle, *prefMapHandle,
*prefsLen, *prefMapSize);
}
ProcessChild::~ProcessChild() { gProcessChild = nullptr; }
/* static */

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

@ -12,8 +12,6 @@
#include "chrome/common/child_process.h"
#include "mozilla/ipc/ProcessUtils.h"
// ProcessChild is the base class for all subprocesses of the main
// browser process. Its code runs on the thread that started in
// main().
@ -30,11 +28,6 @@ class ProcessChild : public ChildProcess {
virtual ~ProcessChild();
virtual bool Init(int aArgc, char* aArgv[]) = 0;
static void AddPlatformBuildID(std::vector<std::string>& aExtraArgs);
static bool InitPrefs(int aArgc, char* aArgv[]);
virtual void CleanUp() {}
static MessageLoop* message_loop() { return gProcessChild->mUILoop; }

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

@ -53,9 +53,9 @@ class SharedPreferenceDeserializer final {
SharedPreferenceDeserializer();
~SharedPreferenceDeserializer();
bool DeserializeFromSharedMemory(uint64_t aPrefsHandle,
uint64_t aPrefMapHandle, uint64_t aPrefsLen,
uint64_t aPrefMapSize);
bool DeserializeFromSharedMemory(char* aPrefsHandleStr,
char* aPrefMapHandleStr, char* aPrefsLenStr,
char* aPrefMapSizeStr);
const base::SharedMemoryHandle& GetPrefsHandle() const;
const FileDescriptor& GetPrefMapHandle() const;
@ -83,7 +83,7 @@ void ExportSharedJSInit(GeckoChildProcessHost& procHost,
// Initialize the content used by the JS engine during the initialization of a
// JS::Runtime.
bool ImportSharedJSInit(uint64_t aJsInitHandle, uint64_t aJsInitLen);
bool ImportSharedJSInit(char* aJsInitHandleStr, char* aJsInitLenStr);
} // namespace ipc
} // namespace mozilla

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

@ -7,7 +7,6 @@
#include "ProcessUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/GeckoArgs.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/UniquePtrExtensions.h"
#include "nsPrintfCString.h"
@ -64,14 +63,21 @@ bool SharedPreferenceSerializer::SerializeToSharedMemory() {
void SharedPreferenceSerializer::AddSharedPrefCmdLineArgs(
mozilla::ipc::GeckoChildProcessHost& procHost,
std::vector<std::string>& aExtraOpts) const {
// Formats a pointer or pointer-sized-integer as a string suitable for passing
// in an arguments list.
auto formatPtrArg = [](auto arg) {
return nsPrintfCString("%zu", uintptr_t(arg));
};
#if defined(XP_WIN)
// Record the handle as to-be-shared, and pass it via a command flag. This
// works because Windows handles are system-wide.
procHost.AddHandleToShare(GetPrefsHandle().get());
procHost.AddHandleToShare(GetPrefMapHandle().get());
geckoargs::sPrefsHandle.Put((uintptr_t)(GetPrefsHandle().get()), aExtraOpts);
geckoargs::sPrefMapHandle.Put((uintptr_t)(GetPrefMapHandle().get()),
aExtraOpts);
aExtraOpts.push_back("-prefsHandle");
aExtraOpts.push_back(formatPtrArg(GetPrefsHandle().get()).get());
aExtraOpts.push_back("-prefMapHandle");
aExtraOpts.push_back(formatPtrArg(GetPrefMapHandle().get()).get());
#else
// In contrast, Unix fds are per-process. So remap the fd to a fixed one that
// will be used in the child.
@ -85,8 +91,10 @@ void SharedPreferenceSerializer::AddSharedPrefCmdLineArgs(
#endif
// Pass the lengths via command line flags.
geckoargs::sPrefsLen.Put((uintptr_t)(GetPrefsLength()), aExtraOpts);
geckoargs::sPrefMapSize.Put((uintptr_t)(GetPrefMapSize()), aExtraOpts);
aExtraOpts.push_back("-prefsLen");
aExtraOpts.push_back(formatPtrArg(GetPrefsLength()).get());
aExtraOpts.push_back("-prefMapSize");
aExtraOpts.push_back(formatPtrArg(GetPrefMapSize()).get());
}
#ifdef ANDROID
@ -107,30 +115,47 @@ SharedPreferenceDeserializer::~SharedPreferenceDeserializer() {
}
bool SharedPreferenceDeserializer::DeserializeFromSharedMemory(
uint64_t aPrefsHandle, uint64_t aPrefMapHandle, uint64_t aPrefsLen,
uint64_t aPrefMapSize) {
char* aPrefsHandleStr, char* aPrefMapHandleStr, char* aPrefsLenStr,
char* aPrefMapSizeStr) {
#ifdef XP_WIN
mPrefsHandle = Some(HANDLE((uintptr_t)(aPrefsHandle)));
if (!aPrefsHandle) {
MOZ_ASSERT(aPrefsHandleStr && aPrefMapHandleStr, "Can't be null");
#endif
MOZ_ASSERT(aPrefsLenStr && aPrefMapSizeStr, "Can't be null");
// Parses an arg containing a pointer-sized-integer.
auto parseUIntPtrArg = [](char*& aArg) {
// ContentParent uses %zu to print a word-sized unsigned integer. So
// even though strtoull() returns a long long int, it will fit in a
// uintptr_t.
return uintptr_t(strtoull(aArg, &aArg, 10));
};
#ifdef XP_WIN
auto parseHandleArg = [&](char*& aArg) {
return HANDLE(parseUIntPtrArg(aArg));
};
mPrefsHandle = Some(parseHandleArg(aPrefsHandleStr));
if (!aPrefsHandleStr || aPrefsHandleStr[0] != '\0') {
return false;
}
FileDescriptor::UniquePlatformHandle handle(
HANDLE((uintptr_t)(aPrefMapHandle)));
if (!aPrefMapHandle) {
parseHandleArg(aPrefMapHandleStr));
if (!aPrefMapHandleStr || aPrefMapHandleStr[0] != '\0') {
return false;
}
mPrefMapHandle.emplace(std::move(handle));
#endif
mPrefsLen = Some((uintptr_t)(aPrefsLen));
if (!aPrefsLen) {
mPrefsLen = Some(parseUIntPtrArg(aPrefsLenStr));
if (!aPrefsLenStr || aPrefsLenStr[0] != '\0') {
return false;
}
mPrefMapSize = Some((uintptr_t)(aPrefMapSize));
if (!aPrefMapSize) {
mPrefMapSize = Some(parseUIntPtrArg(aPrefMapSizeStr));
if (!aPrefMapSizeStr || aPrefMapSizeStr[0] != '\0') {
return false;
}
@ -196,6 +221,12 @@ void ExportSharedJSInit(mozilla::ipc::GeckoChildProcessHost& procHost,
// The code to support Android is added in a follow-up patch.
return;
#else
// Formats a pointer or pointer-sized-integer as a string suitable for passing
// in an arguments list.
auto formatPtrArg = [](auto arg) {
return nsPrintfCString("%zu", uintptr_t(arg));
};
auto& shmem = xpc::SelfHostedShmem::GetSingleton();
const mozilla::UniqueFileHandle& uniqHandle = shmem.Handle();
size_t len = shmem.Content().Length();
@ -207,11 +238,14 @@ void ExportSharedJSInit(mozilla::ipc::GeckoChildProcessHost& procHost,
}
mozilla::detail::FileHandleType handle = uniqHandle.get();
// command line: [-jsInitHandle handle] -jsInitLen length
// command line: -jsInit [handle] length
aExtraOpts.push_back("-jsInit");
# if defined(XP_WIN)
// Record the handle as to-be-shared, and pass it via a command flag.
procHost.AddHandleToShare(HANDLE(handle));
geckoargs::sJsInitHandle.Put((uintptr_t)(HANDLE(handle)), aExtraOpts);
aExtraOpts.push_back(formatPtrArg(HANDLE(handle)).get());
# else
// In contrast, Unix fds are per-process. So remap the fd to a fixed one that
// will be used in the child.
@ -224,32 +258,44 @@ void ExportSharedJSInit(mozilla::ipc::GeckoChildProcessHost& procHost,
# endif
// Pass the lengths via command line flags.
geckoargs::sJsInitLen.Put((uintptr_t)(len), aExtraOpts);
aExtraOpts.push_back(formatPtrArg(len).get());
#endif
}
bool ImportSharedJSInit(uint64_t aJsInitHandle, uint64_t aJsInitLen) {
bool ImportSharedJSInit(char* aJsInitHandleStr, char* aJsInitLenStr) {
// This is an optimization, and as such we can safely recover if the command
// line argument are not provided.
if (!aJsInitLen) {
if (!aJsInitLenStr) {
return true;
}
#ifdef XP_WIN
if (!aJsInitHandle) {
if (!aJsInitHandleStr) {
return true;
}
#endif
// Parses an arg containing a pointer-sized-integer.
auto parseUIntPtrArg = [](char*& aArg) {
// ContentParent uses %zu to print a word-sized unsigned integer. So even
// though strtoull() returns an unsigned long long int, it will fit in a
// uintptr_t.
return uintptr_t(strtoull(aArg, &aArg, 10));
};
#ifdef XP_WIN
base::SharedMemoryHandle handle(HANDLE((uintptr_t)(aJsInitHandle)));
if (!aJsInitHandle) {
auto parseHandleArg = [&](char*& aArg) {
return HANDLE(parseUIntPtrArg(aArg));
};
base::SharedMemoryHandle handle(parseHandleArg(aJsInitHandleStr));
if (aJsInitHandleStr[0] != '\0') {
return false;
}
#endif
size_t len = (uintptr_t)(aJsInitLen);
if (!aJsInitLen) {
size_t len = parseUIntPtrArg(aJsInitLenStr);
if (aJsInitLenStr[0] != '\0') {
return false;
}

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

@ -60,7 +60,10 @@ bool SocketProcessHost::Launch() {
MOZ_ASSERT(NS_IsMainThread());
std::vector<std::string> extraArgs;
ProcessChild::AddPlatformBuildID(extraArgs);
nsAutoCString parentBuildID(mozilla::PlatformBuildID());
extraArgs.push_back("-parentBuildID");
extraArgs.push_back(parentBuildID.get());
SharedPreferenceSerializer prefSerializer;
if (!prefSerializer.SerializeToSharedMemory()) {

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

@ -10,7 +10,6 @@
#include "base/string_util.h"
#include "mozilla/BackgroundHangMonitor.h"
#include "mozilla/Preferences.h"
#include "mozilla/GeckoArgs.h"
#include "mozilla/ipc/ProcessUtils.h"
#include "mozilla/ipc/IOThreadChild.h"
@ -56,18 +55,56 @@ bool SocketProcessImpl::Init(int aArgc, char* aArgv[]) {
PR_LoadLibrary("libfreebl3.so");
StartOpenBSDSandbox(GeckoProcessType_Socket);
#endif
char* parentBuildID = nullptr;
char* prefsHandle = nullptr;
char* prefMapHandle = nullptr;
char* prefsLen = nullptr;
char* prefMapSize = nullptr;
Maybe<const char*> parentBuildID =
geckoargs::sParentBuildID.Get(aArgc, aArgv);
if (parentBuildID.isNothing()) {
for (int i = 1; i < aArgc; i++) {
if (!aArgv[i]) {
continue;
}
if (strcmp(aArgv[i], "-parentBuildID") == 0) {
if (++i == aArgc) {
return false;
}
parentBuildID = aArgv[i];
#ifdef XP_WIN
} else if (strcmp(aArgv[i], "-prefsHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefsHandle = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapHandle") == 0) {
if (++i == aArgc) {
return false;
}
prefMapHandle = aArgv[i];
#endif
} else if (strcmp(aArgv[i], "-prefsLen") == 0) {
if (++i == aArgc) {
return false;
}
prefsLen = aArgv[i];
} else if (strcmp(aArgv[i], "-prefMapSize") == 0) {
if (++i == aArgc) {
return false;
}
prefMapSize = aArgv[i];
}
}
ipc::SharedPreferenceDeserializer deserializer;
if (!deserializer.DeserializeFromSharedMemory(prefsHandle, prefMapHandle,
prefsLen, prefMapSize)) {
return false;
}
if (!ProcessChild::InitPrefs(aArgc, aArgv)) {
return false;
}
return mSocketProcessChild.Init(ParentPid(), *parentBuildID,
return mSocketProcessChild.Init(ParentPid(), parentBuildID,
IOThreadChild::TakeInitialPort());
}

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

@ -101,26 +101,6 @@ inline void CommandLineArg<uint64_t>::Put(uint64_t aValue,
aArgs.push_back(std::to_string(aValue));
}
static CommandLineArg<const char*> sParentBuildID{"-parentBuildID",
"parentbuildid"};
static CommandLineArg<const char*> sAppDir{"-appDir", "appdir"};
static CommandLineArg<const char*> sProfile{"-profile", "profile"};
static CommandLineArg<uint64_t> sJsInitHandle{"-jsInitHandle", "jsinithandle"};
static CommandLineArg<uint64_t> sJsInitLen{"-jsInitLen", "jsinitlen"};
static CommandLineArg<uint64_t> sPrefsHandle{"-prefsHandle", "prefshandle"};
static CommandLineArg<uint64_t> sPrefsLen{"-prefsLen", "prefslen"};
static CommandLineArg<uint64_t> sPrefMapHandle{"-prefMapHandle",
"prefmaphandle"};
static CommandLineArg<uint64_t> sPrefMapSize{"-prefMapSize", "prefmapsize"};
static CommandLineArg<uint64_t> sChildID{"-childID", "childid"};
static CommandLineArg<bool> sSafeMode{"-safeMode", "safemode"};
static CommandLineArg<bool> sIsForBrowser{"-isForBrowser", "isforbrowser"};
static CommandLineArg<bool> sNotForBrowser{"-notForBrowser", "notforbrowser"};
} // namespace geckoargs
} // namespace mozilla