Skip to content

Commit b2d9af5

Browse files
authored
browser(firefox): properly initialize debugging pipe on windows (#5514)
browser(firefox): properly initialize debugging pipe on windows Firefox on Windows has 2 launch modes: - default: a special "launcher process" is used to start browser as a sub-process - non-default: browser process starts right away Firefox has a logic to detect how successful was the use of the launcher process to do self-recovery when things go wrong. Namely: - when attempting to use launcher process, firefox records a timestamp of the attempt beginning - once the launcher process successfully launches browser sub-process, firefox records another timestamp of the completion On a new launch, firefox checks what timestamps are present. If there's a timestamp that signifies start of launcher process, but no successful timestamp, it decides that last "launcher process" use was not successful and falls back to launching browser right away. When launching 2 firefox processes right away, the first process uses attempts to use launcher process and records the first timestamp. At the same time, the second instance sees the first timestamp and doesn't see the second timestamp, and falls back to launching browser right away. Our debugging pipe code, however, does not support non-launcher-process code path. This patch adds support for remote debugging pipe in case of non-launcher-process startup. Drive-by: - disable crashreporter altogether - remove stray dcheck that breaks firefox debug compilation - disable compilation of firefox update agent - do not use WIN32_DISTRIB flag unless doing full builds since it kills incremental compilation References #4660
1 parent 48f7a37 commit b2d9af5

File tree

4 files changed

+63
-24
lines changed

4 files changed

+63
-24
lines changed

browser_patches/checkout_build_archive_upload.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ elif [[ "$BUILD_FLAVOR" == "firefox-mac-11.0-arm64" ]]; then
172172
BUILD_BLOB_NAME="firefox-mac-11.0-arm64.zip"
173173
elif [[ "$BUILD_FLAVOR" == "firefox-win32" ]]; then
174174
BROWSER_NAME="firefox"
175+
EXTRA_BUILD_ARGS="--full"
175176
EXPECTED_HOST_OS="MINGW"
176177
BUILD_BLOB_NAME="firefox-win32.zip"
177178
elif [[ "$BUILD_FLAVOR" == "firefox-win64" ]]; then
178179
BROWSER_NAME="firefox"
179-
EXTRA_BUILD_ARGS="--win64"
180+
EXTRA_BUILD_ARGS="--win64 --full"
180181
EXPECTED_HOST_OS="MINGW"
181182
BUILD_BLOB_NAME="firefox-win64.zip"
182183

browser_patches/firefox/BUILD_NUMBER

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1230
2-
Changed: [email protected] Sat Feb 13 10:15:07 PST 2021
1+
1231
2+
Changed: [email protected] Fri Feb 19 10:28:40 MST 2021

browser_patches/firefox/build.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ else
2222
fi
2323

2424

25+
rm .mozconfig
26+
2527
if [[ "$(uname)" == "Darwin" ]]; then
2628
if [[ $(uname -m) == "arm64" ]]; then
2729
# Building on Apple Silicon requires XCode12.2 and does not require any extra SDKs.
@@ -45,18 +47,21 @@ if [[ "$(uname)" == "Darwin" ]]; then
4547
exit 1
4648
else
4749
echo "-- configuting .mozconfig with ${MACOS_SDK_VERSION} SDK path"
48-
echo "ac_add_options --with-macos-sdk=$HOME/SDK-archive/MacOSX${MACOS_SDK_VERSION}.sdk/" > .mozconfig
50+
echo "ac_add_options --with-macos-sdk=$HOME/SDK-archive/MacOSX${MACOS_SDK_VERSION}.sdk/" >> .mozconfig
4951
fi
5052
fi
5153
echo "-- building on Mac"
5254
elif [[ "$(uname)" == "Linux" ]]; then
5355
echo "-- building on Linux"
54-
echo "ac_add_options --disable-av1" > .mozconfig
56+
echo "ac_add_options --disable-av1" >> .mozconfig
5557
elif [[ "$(uname)" == MINGW* ]]; then
58+
echo "ac_add_options --disable-update-agent" >> .mozconfig
59+
echo "ac_add_options --disable-default-browser-agent" >> .mozconfig
60+
5661
DLL_FILE=""
5762
if [[ $1 == "--win64" ]]; then
5863
echo "-- building win64 build on MINGW"
59-
echo "ac_add_options --target=x86_64-pc-mingw32" > .mozconfig
64+
echo "ac_add_options --target=x86_64-pc-mingw32" >> .mozconfig
6065
echo "ac_add_options --host=x86_64-pc-mingw32" >> .mozconfig
6166
DLL_FILE=$("C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -find '**\Redist\MSVC\*\x64\**\vcruntime140.dll')
6267
else
@@ -68,23 +73,27 @@ elif [[ "$(uname)" == MINGW* ]]; then
6873
echo "ERROR: cannot find MS VS C++ redistributable $WIN32_REDIST_DIR"
6974
exit 1;
7075
fi
71-
echo "export WIN32_REDIST_DIR=\"$WIN32_REDIST_DIR\"" >> .mozconfig
7276
else
7377
echo "ERROR: cannot upload on this platform!" 1>&2
7478
exit 1;
7579
fi
7680

7781
OBJ_FOLDER="obj-build-playwright"
7882
echo "mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/${OBJ_FOLDER}" >> .mozconfig
83+
echo "ac_add_options --disable-crashreporter" >> .mozconfig
7984

80-
if [[ $1 == "--full" ]]; then
85+
if [[ $1 == "--full" || $2 == "--full" ]]; then
8186
if [[ "$(uname)" == "Darwin" && "$(uname -m)" == "arm64" ]]; then
8287
./mach artifact toolchain --from-build macosx64-node
8388
rm -rf "$HOME/.mozbuild/node"
8489
mv node "$HOME/.mozbuild/"
8590
elif [[ "$(uname)" == "Darwin" || "$(uname)" == "Linux" ]]; then
8691
SHELL=/bin/sh ./mach bootstrap --application-choice=browser --no-interactive --no-system-changes
8792
fi
93+
if [[ ! -z "${WIN32_REDIST_DIR}" ]]; then
94+
# Having this option in .mozconfig kills incremental compilation.
95+
echo "export WIN32_REDIST_DIR=\"$WIN32_REDIST_DIR\"" >> .mozconfig
96+
fi
8897
fi
8998

9099
if ! [[ -f "$HOME/.mozbuild/_virtualenvs/mach/bin/python" ]]; then

browser_patches/firefox/patches/bootstrap.diff

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ index f042cc1081850ac60e329b70b5569f8b97d4e4dc..65bcff9b41b9471ef1427e3ea330481c
5959
* Return XPCOM wrapper for the internal accessible.
6060
*/
6161
diff --git a/browser/app/winlauncher/LauncherProcessWin.cpp b/browser/app/winlauncher/LauncherProcessWin.cpp
62-
index faf53eff9a46f958890d2c50de4c741fce75f1b1..7ad4b9f2203dbf1706518a0ba372d424673c9d64 100644
62+
index faf53eff9a46f958890d2c50de4c741fce75f1b1..63a102074664f972bfb16ba7f57af730abad9eea 100644
6363
--- a/browser/app/winlauncher/LauncherProcessWin.cpp
6464
+++ b/browser/app/winlauncher/LauncherProcessWin.cpp
6565
@@ -23,6 +23,7 @@
@@ -70,7 +70,7 @@ index faf53eff9a46f958890d2c50de4c741fce75f1b1..7ad4b9f2203dbf1706518a0ba372d424
7070
#include <windows.h>
7171
#include <processthreadsapi.h>
7272

73-
@@ -324,8 +325,25 @@ Maybe<int> LauncherMain(int& argc, wchar_t* argv[],
73+
@@ -324,8 +325,19 @@ Maybe<int> LauncherMain(int& argc, wchar_t* argv[],
7474
HANDLE stdHandles[] = {::GetStdHandle(STD_INPUT_HANDLE),
7575
::GetStdHandle(STD_OUTPUT_HANDLE),
7676
::GetStdHandle(STD_ERROR_HANDLE)};
@@ -81,15 +81,9 @@ index faf53eff9a46f958890d2c50de4c741fce75f1b1..7ad4b9f2203dbf1706518a0ba372d424
8181
+ mozilla::CheckArg(argc, argv, L"juggler-pipe",
8282
+ static_cast<const wchar_t**>(nullptr),
8383
+ mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND;
84-
+ if (hasJugglerPipe && !mozilla::EnvHasValue("PW_PIPE_READ")) {
84+
+ if (hasJugglerPipe) {
8585
+ intptr_t stdio3 = _get_osfhandle(3);
8686
+ intptr_t stdio4 = _get_osfhandle(4);
87-
+ CHAR stdio3str[20];
88-
+ CHAR stdio4str[20];
89-
+ itoa(stdio3, stdio3str, 10);
90-
+ itoa(stdio4, stdio4str, 10);
91-
+ SetEnvironmentVariable("PW_PIPE_READ", stdio3str);
92-
+ SetEnvironmentVariable("PW_PIPE_WRITE", stdio4str);
9387
+ HANDLE pipeHandles[] = {reinterpret_cast<HANDLE>(stdio3),
9488
+ reinterpret_cast<HANDLE>(stdio4)};
9589
+ attrs.AddInheritableHandles(pipeHandles);
@@ -178,7 +172,7 @@ index 040c7b124dec6bb254563bbe74fe50012cb077a3..b4e6b8132786af70e8ad0dce88b67c28
178172
const transportProvider = {
179173
setListener(upgradeListener) {
180174
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
181-
index ee271e6d7fd265aea278d841f66340a9c70e59f9..80665230adf04130e5bf79a3a2b09bec2c117442 100644
175+
index ee271e6d7fd265aea278d841f66340a9c70e59f9..0b3cbdd0a2d1c78c2f1356994a72d2bacb45afc6 100644
182176
--- a/docshell/base/nsDocShell.cpp
183177
+++ b/docshell/base/nsDocShell.cpp
184178
@@ -15,6 +15,12 @@
@@ -247,7 +241,7 @@ index ee271e6d7fd265aea278d841f66340a9c70e59f9..80665230adf04130e5bf79a3a2b09bec
247241
if (!isSubFrame && !isRoot) {
248242
/*
249243
* We don't want to send OnLocationChange notifications when
250-
@@ -3256,6 +3273,204 @@ nsDocShell::GetMessageManager(ContentFrameMessageManager** aMessageManager) {
244+
@@ -3256,6 +3273,203 @@ nsDocShell::GetMessageManager(ContentFrameMessageManager** aMessageManager) {
251245
return NS_OK;
252246
}
253247

@@ -310,7 +304,6 @@ index ee271e6d7fd265aea278d841f66340a9c70e59f9..80665230adf04130e5bf79a3a2b09bec
310304
+
311305
+NS_IMETHODIMP
312306
+nsDocShell::GetLanguageOverride(nsAString& aLanguageOverride) {
313-
+ MOZ_ASSERT(aEnabled);
314307
+ aLanguageOverride = GetRootDocShell()->mLanguageOverride;
315308
+ return NS_OK;
316309
+}
@@ -452,7 +445,7 @@ index ee271e6d7fd265aea278d841f66340a9c70e59f9..80665230adf04130e5bf79a3a2b09bec
452445
NS_IMETHODIMP
453446
nsDocShell::GetIsNavigating(bool* aOut) {
454447
*aOut = mIsNavigating;
455-
@@ -4864,7 +5079,7 @@ nsDocShell::GetIsOffScreenBrowser(bool* aIsOffScreen) {
448+
@@ -4864,7 +5078,7 @@ nsDocShell::GetIsOffScreenBrowser(bool* aIsOffScreen) {
456449
}
457450

458451
void nsDocShell::ActivenessMaybeChanged() {
@@ -461,7 +454,7 @@ index ee271e6d7fd265aea278d841f66340a9c70e59f9..80665230adf04130e5bf79a3a2b09bec
461454
if (RefPtr<PresShell> presShell = GetPresShell()) {
462455
presShell->SetIsActive(isActive);
463456
}
464-
@@ -8589,6 +8804,12 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
457+
@@ -8589,6 +8803,12 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
465458
true, // aForceNoOpener
466459
getter_AddRefs(newBC));
467460
MOZ_ASSERT(!newBC);
@@ -474,7 +467,7 @@ index ee271e6d7fd265aea278d841f66340a9c70e59f9..80665230adf04130e5bf79a3a2b09bec
474467
return rv;
475468
}
476469

477-
@@ -12548,6 +12769,9 @@ class OnLinkClickEvent : public Runnable {
470+
@@ -12548,6 +12768,9 @@ class OnLinkClickEvent : public Runnable {
478471
mHandler->OnLinkClickSync(mContent, mLoadState, mNoOpenerImplied,
479472
mTriggeringPrincipal);
480473
}
@@ -484,7 +477,7 @@ index ee271e6d7fd265aea278d841f66340a9c70e59f9..80665230adf04130e5bf79a3a2b09bec
484477
return NS_OK;
485478
}
486479

487-
@@ -12633,6 +12857,8 @@ nsresult nsDocShell::OnLinkClick(
480+
@@ -12633,6 +12856,8 @@ nsresult nsDocShell::OnLinkClick(
488481
nsCOMPtr<nsIRunnable> ev =
489482
new OnLinkClickEvent(this, aContent, loadState, noOpenerImplied,
490483
aIsTrusted, aTriggeringPrincipal);
@@ -1868,6 +1861,42 @@ index bbc3c98e4885f23f03f83b7c2aa00e4eb4faaef5..45dcb084904c1d2729ef1e2cd1bef1a4
18681861
'/toolkit/components/telemetry/tests/marionette',
18691862
]
18701863

1864+
diff --git a/toolkit/xre/nsWindowsWMain.cpp b/toolkit/xre/nsWindowsWMain.cpp
1865+
index 109c53cac98302d657d2a5a997f2ba687db14515..4d3c4beddaf627441e28f2a49d793d56fe4e2447 100644
1866+
--- a/toolkit/xre/nsWindowsWMain.cpp
1867+
+++ b/toolkit/xre/nsWindowsWMain.cpp
1868+
@@ -14,8 +14,10 @@
1869+
#endif
1870+
1871+
#include "mozilla/Char16.h"
1872+
+#include "mozilla/CmdLineAndEnvUtils.h"
1873+
#include "nsUTF8Utils.h"
1874+
1875+
+#include <io.h>
1876+
#include <windows.h>
1877+
1878+
#ifdef __MINGW32__
1879+
@@ -94,6 +96,20 @@ static void FreeAllocStrings(int argc, char** argv) {
1880+
int wmain(int argc, WCHAR** argv) {
1881+
SanitizeEnvironmentVariables();
1882+
SetDllDirectoryW(L"");
1883+
+ bool hasJugglerPipe =
1884+
+ mozilla::CheckArg(argc, argv, L"juggler-pipe",
1885+
+ static_cast<const wchar_t**>(nullptr),
1886+
+ mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND;
1887+
+ if (hasJugglerPipe && !mozilla::EnvHasValue("PW_PIPE_READ")) {
1888+
+ intptr_t stdio3 = _get_osfhandle(3);
1889+
+ intptr_t stdio4 = _get_osfhandle(4);
1890+
+ CHAR stdio3str[20];
1891+
+ CHAR stdio4str[20];
1892+
+ itoa(stdio3, stdio3str, 10);
1893+
+ itoa(stdio4, stdio4str, 10);
1894+
+ SetEnvironmentVariableA("PW_PIPE_READ", stdio3str);
1895+
+ SetEnvironmentVariableA("PW_PIPE_WRITE", stdio4str);
1896+
+ }
1897+
1898+
// Only run this code if LauncherProcessWin.h was included beforehand, thus
1899+
// signalling that the hosting process should support launcher mode.
18711900
diff --git a/uriloader/base/nsDocLoader.cpp b/uriloader/base/nsDocLoader.cpp
18721901
index bf7902f5dd642e2800b3fa83f4d379ab1ac9fda0..b94c24f9534cc19a5c2828e035e33c95f671d181 100644
18731902
--- a/uriloader/base/nsDocLoader.cpp

0 commit comments

Comments
 (0)