Backed out changeset 98eadcb92105 (Bug 1878993) for causing bug 1892612. r=#win-reviewers CLOSED TREE

Differential Revision: https://phabricator.services.mozilla.com/D208112
This commit is contained in:
Yannis Juglaret 2024-04-22 09:39:15 +00:00
Родитель 08f3efaa54
Коммит ebe4314873
3 изменённых файлов: 3 добавлений и 128 удалений

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

@ -401,12 +401,8 @@ Maybe<int> LauncherMain(int& argc, wchar_t* argv[],
} }
#endif // defined(MOZ_LAUNCHER_PROCESS) #endif // defined(MOZ_LAUNCHER_PROCESS)
// Now proceed with setting up the parameters for process creation. // Now proceed with setting up the parameters for process creation
constexpr static const wchar_t* extraArgs[] = { UniquePtr<wchar_t[]> cmdLine(MakeCommandLine(argc, argv));
L"/prefetch:1", // for APFL; see ipc/glue/GeckoChildProcessHost.cpp
};
UniquePtr<wchar_t[]> cmdLine(
MakeCommandLine(argc, argv, ARRAYSIZE(extraArgs), extraArgs));
if (!cmdLine) { if (!cmdLine) {
HandleLauncherError(LAUNCHER_ERROR_GENERIC()); HandleLauncherError(LAUNCHER_ERROR_GENERIC());
return Nothing(); return Nothing();

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

@ -68,7 +68,6 @@
#ifdef XP_WIN #ifdef XP_WIN
# include <stdlib.h> # include <stdlib.h>
# include "mozilla/WindowsVersion.h"
# include "nsIWinTaskbar.h" # include "nsIWinTaskbar.h"
# define NS_TASKBAR_CONTRACTID "@mozilla.org/windows-taskbar;1" # define NS_TASKBAR_CONTRACTID "@mozilla.org/windows-taskbar;1"
@ -257,7 +256,7 @@ class BaseProcessLauncher {
}; };
#ifdef XP_WIN #ifdef XP_WIN
class WindowsProcessLauncher final : public BaseProcessLauncher { class WindowsProcessLauncher : public BaseProcessLauncher {
public: public:
WindowsProcessLauncher(GeckoChildProcessHost* aHost, WindowsProcessLauncher(GeckoChildProcessHost* aHost,
std::vector<std::string>&& aExtraOpts) std::vector<std::string>&& aExtraOpts)
@ -269,9 +268,6 @@ class WindowsProcessLauncher final : public BaseProcessLauncher {
virtual RefPtr<ProcessHandlePromise> DoLaunch() override; virtual RefPtr<ProcessHandlePromise> DoLaunch() override;
virtual Result<Ok, LaunchError> DoFinishLaunch() override; virtual Result<Ok, LaunchError> DoFinishLaunch() override;
private:
void AddApplicationPrefetchArgument();
mozilla::Maybe<CommandLine> mCmdLine; mozilla::Maybe<CommandLine> mCmdLine;
# ifdef MOZ_SANDBOX # ifdef MOZ_SANDBOX
bool mUseSandbox = false; bool mUseSandbox = false;
@ -1566,97 +1562,6 @@ Result<Ok, LaunchError> MacProcessLauncher::DoFinishLaunch() {
#endif // XP_MACOSX #endif // XP_MACOSX
#ifdef XP_WIN #ifdef XP_WIN
void WindowsProcessLauncher::AddApplicationPrefetchArgument() {
// The Application Launch Prefetcher (ALPF) is an ill-documented Windows
// subsystem that's intended to speed up process launching, apparently mostly
// by assuming that a binary is going to want to load the same DLLs as it did
// the last time it launched, and getting those prepped for loading as well.
//
// For most applications, that's a good bet. For Firefox, it's less so, since
// we use the same binary with different arguments to do completely different
// things. Windows does allow applications to take up multiple slots in this
// cache, but the "which bucket does this invocation go in?" mechanism is
// highly unusual: the OS scans the command line and looks for a command-line
// switch of a particular form.
//
// (There is allegedly a way to do this without involving the command line,
// OVERRIDE_PREFETCH_PARAMETER, but it's even more poorly documented.)
// Applications' different prefetch-cache buckets are named with numbers from
// "1" to some OS-version-determined limit, with an additional implicit "0"
// cache bucket which is used when no valid prefetch cache slot is named.
//
// (The "0" bucket's existence and behavior is not documented, but has been
// confirmed by observing the creation and enumeration of cache files in the
// C:\Windows\Prefetch folder.)
static size_t const kMaxSlotNo = IsWin1122H2OrLater() ? 16 : 8;
// Determine the prefetch-slot number to be used for the process we're about
// to launch.
//
// This may be changed freely between Firefox versions, as a Firefox update
// will completely invalidate the prefetch cache anyway.
size_t const prefetchSlot = [&]() -> size_t {
switch (mProcessType) {
// This code path is not used when starting the main process...
case GeckoProcessType_Default:
// ...ForkServer is not used on Windows...
case GeckoProcessType_ForkServer:
// ..."End" isn't a process-type, just a limit...
case GeckoProcessType_End:
// ...and any new process-types should be considered explicitly here.
default:
MOZ_ASSERT_UNREACHABLE("Invalid process type");
return 0;
// We reserve 1 for the main process as started by the launcher process.
// (See LauncherProcessWin.cpp.) Otherwise, we mostly match the process-
// type enumeration.
case GeckoProcessType_Content:
return 2;
case GeckoProcessType_Socket:
return 3; // usurps IPDLUnitTest
case GeckoProcessType_GMPlugin:
return 4;
case GeckoProcessType_GPU:
return 5;
case GeckoProcessType_RemoteSandboxBroker:
return 6; // usurps VR
case GeckoProcessType_RDD:
return 7;
case GeckoProcessType_Utility: {
// Continue the enumeration, using the SandboxingKind as a
// probably-passably-precise proxy for the process's purpose.
//
// (On Win10 and earlier, or when sandboxing is not used, this will lump
// all utility processes into slot 8.)
# ifndef MOZ_SANDBOX
size_t const val = 0;
# else
size_t const val = static_cast<size_t>(mSandbox);
# endif
return std::min(kMaxSlotNo, 8 + val);
}
// These process types are started so rarely that we're not concerned
// about their interaction with the prefetch cache. Lump them together at
// the end (possibly alongside other process types).
case GeckoProcessType_IPDLUnitTest:
case GeckoProcessType_VR:
return kMaxSlotNo;
}
}();
MOZ_ASSERT(prefetchSlot <= kMaxSlotNo);
if (prefetchSlot == 0) {
// default; no explicit argument needed
return;
}
mCmdLine->AppendLooseValue(StringPrintf(L"/prefetch:%zu", prefetchSlot));
}
Result<Ok, LaunchError> WindowsProcessLauncher::DoSetup() { Result<Ok, LaunchError> WindowsProcessLauncher::DoSetup() {
Result<Ok, LaunchError> aError = BaseProcessLauncher::DoSetup(); Result<Ok, LaunchError> aError = BaseProcessLauncher::DoSetup();
if (aError.isErr()) { if (aError.isErr()) {
@ -1837,9 +1742,6 @@ Result<Ok, LaunchError> WindowsProcessLauncher::DoSetup() {
// Process type // Process type
mCmdLine->AppendLooseValue(UTF8ToWide(ChildProcessType())); mCmdLine->AppendLooseValue(UTF8ToWide(ChildProcessType()));
// Prefetch cache hint
AddApplicationPrefetchArgument();
# ifdef MOZ_SANDBOX # ifdef MOZ_SANDBOX
if (mUseSandbox) { if (mUseSandbox) {
// Mark the handles to inherit as inheritable. // Mark the handles to inherit as inheritable.

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

@ -111,32 +111,9 @@ static void FreeAllocStrings(int argc, char** argv) {
delete[] argv; delete[] argv;
} }
// Remove "/prefetch:##" argument from the command line, if present. (See
// GeckoChildProcessHost.cpp for details.)
//
// Colons are not permitted in path-elements on Windows, so a string of this
// form is extremely unlikely to appear with the intent of being a legitimate
// path-argument.
void RemovePrefetchArguments(int& argc, WCHAR** argv) {
size_t prefetchArgsCount [[maybe_unused]] = 0;
for (int i = 0; i < argc; ++i) {
constexpr const wchar_t prefix[] = L"/prefetch:";
auto const cmp = wcsncmp(argv[i], prefix, ARRAYSIZE(prefix) - 1);
if (cmp == 0) {
std::copy(argv + i + 1, argv + argc, argv + i);
--argc;
--i;
prefetchArgsCount++;
}
}
MOZ_ASSERT(prefetchArgsCount <= 1,
"at most one /prefetch:## argument should be present");
}
int wmain(int argc, WCHAR** argv) { int wmain(int argc, WCHAR** argv) {
SanitizeEnvironmentVariables(); SanitizeEnvironmentVariables();
SetDllDirectoryW(L""); SetDllDirectoryW(L"");
RemovePrefetchArguments(argc, argv);
// Only run this code if LauncherProcessWin.h was included beforehand, thus // Only run this code if LauncherProcessWin.h was included beforehand, thus
// signalling that the hosting process should support launcher mode. // signalling that the hosting process should support launcher mode.