Backed out changeset 7cb86942ed34 (bug 1528963) for bustages at nsEmbedFunctions.cpp on a CLOSED TREE.
authorGurzau Raul <rgurzau@mozilla.com>
Fri, 29 Mar 2019 01:45:01 +0200
changeset 466678 7cfcdf742d19ef55f45ef9150a15908247112f03
parent 466677 fae91b8aa3d7eb88a58918250953dcf5713fe16e
child 466679 b175687d4b291a8510b0d5da84bbe1edd2c5877e
push id81746
push userrgurzau@mozilla.com
push dateThu, 28 Mar 2019 23:45:33 +0000
treeherderautoland@7cfcdf742d19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1528963
milestone68.0a1
backs out7cb86942ed34f38e03e7f2a0eefee0a3141980b5
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 7cb86942ed34 (bug 1528963) for bustages at nsEmbedFunctions.cpp on a CLOSED TREE.
browser/app/winlauncher/LauncherProcessWin.cpp
browser/app/winlauncher/moz.build
toolkit/xre/nsAppRunner.h
toolkit/xre/nsEmbedFunctions.cpp
toolkit/xre/nsNativeAppSupportWin.cpp
widget/windows/WindowsConsole.cpp
widget/windows/WindowsConsole.h
widget/windows/moz.build
--- a/browser/app/winlauncher/LauncherProcessWin.cpp
+++ b/browser/app/winlauncher/LauncherProcessWin.cpp
@@ -12,17 +12,16 @@
 #include "mozilla/CmdLineAndEnvUtils.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/DynamicallyLinkedFunctionPtr.h"
 #include "mozilla/glue/Debug.h"
 #include "mozilla/LauncherResult.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/SafeMode.h"
 #include "mozilla/UniquePtr.h"
-#include "mozilla/WindowsConsole.h"
 #include "mozilla/WindowsVersion.h"
 #include "mozilla/WinHeaderOnlyUtils.h"
 #include "nsWindowsHelpers.h"
 
 #include <windows.h>
 #include <processthreadsapi.h>
 
 #include "DllBlocklistWin.h"
@@ -215,18 +214,16 @@ Maybe<int> LauncherMain(int& argc, wchar
       imgLoadPol.PreferSystem32Images = 1;
 
       DebugOnly<BOOL> setOk = pSetProcessMitigationPolicy(
           ProcessImageLoadPolicy, &imgLoadPol, sizeof(imgLoadPol));
       MOZ_ASSERT(setOk);
     }
   }
 
-  mozilla::UseParentConsole();
-
   if (!SetArgv0ToFullBinaryPath(argv)) {
     HandleLauncherError(LAUNCHER_ERROR_GENERIC());
     return Nothing();
   }
 
   LauncherFlags flags = ProcessCmdLine(argc, argv);
 
   nsAutoHandle mediumIlToken;
--- a/browser/app/winlauncher/moz.build
+++ b/browser/app/winlauncher/moz.build
@@ -26,14 +26,13 @@ OS_LIBS += [
 
 TEST_DIRS += [
     'test',
 ]
 
 if CONFIG['MOZ_LAUNCHER_PROCESS']:
     UNIFIED_SOURCES += [
         '/toolkit/xre/LauncherRegistryInfo.cpp',
-        '/widget/windows/WindowsConsole.cpp',
     ]
     for var in ('MOZ_APP_BASENAME', 'MOZ_APP_VENDOR'):
         DEFINES[var] = '"%s"' % CONFIG[var]
 
 DisableStlWrapping()
--- a/toolkit/xre/nsAppRunner.h
+++ b/toolkit/xre/nsAppRunner.h
@@ -3,17 +3,16 @@
  * 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/. */
 
 #ifndef nsAppRunner_h__
 #define nsAppRunner_h__
 
 #ifdef XP_WIN
 #  include <windows.h>
-#  include "mozilla/WindowsConsole.h"
 #else
 #  include <limits.h>
 #endif
 
 #ifndef MAXPATHLEN
 #  ifdef PATH_MAX
 #    define MAXPATHLEN PATH_MAX
 #  elif defined(_MAX_PATH)
@@ -96,16 +95,17 @@ void OverrideDefaultLocaleIfNeeded();
 
 /**
  * Allow exit() calls to complete. This should be done from a proper Gecko
  * shutdown path. Otherwise we aim to catch improper shutdowns.
  */
 void MozExpectedExit();
 
 #ifdef XP_WIN
+void UseParentConsole();
 
 BOOL WinLaunchChild(const wchar_t* exePath, int argc, char** argv,
                     HANDLE userToken = nullptr, HANDLE* hProcess = nullptr);
 
 #  define PREF_WIN_REGISTER_APPLICATION_RESTART \
     "toolkit.winRegisterApplicationRestart"
 
 #  if defined(MOZ_LAUNCHER_PROCESS)
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -75,17 +75,16 @@
 
 #include "mozilla/plugins/PluginProcessChild.h"
 #include "mozilla/dom/ContentProcess.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ContentChild.h"
 
 #include "mozilla/ipc/TestShellParent.h"
 #include "mozilla/ipc/XPCShellEnvironment.h"
-#include "mozilla/WindowsConsole.h"
 #include "mozilla/WindowsDllBlocklist.h"
 
 #include "GMPProcessChild.h"
 #include "mozilla/gfx/GPUProcessImpl.h"
 #include "mozilla/net/SocketProcessImpl.h"
 
 #include "GeckoProfiler.h"
 
@@ -377,17 +376,29 @@ nsresult XRE_InitChildProcess(int aArgc,
 
 #if defined(XP_WIN)
   // From the --attach-console support in nsNativeAppSupportWin.cpp, but
   // here we are a content child process, so we always attempt to attach
   // to the parent's (ie, the browser's) console.
   // Try to attach console to the parent process.
   // It will succeed when the parent process is a command line,
   // so that stdio will be displayed in it.
-  UseParentConsole();
+  if (AttachConsole(ATTACH_PARENT_PROCESS)) {
+    // Change std handles to refer to new console handles.
+    // Before doing so, ensure that stdout/stderr haven't been
+    // redirected to a valid file
+    if (_fileno(stdout) == -1 || _get_osfhandle(fileno(stdout)) == -1)
+      freopen("CONOUT$", "w", stdout);
+    // Merge stderr into CONOUT$ since there isn't any `CONERR$`.
+    // http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx
+    if (_fileno(stderr) == -1 || _get_osfhandle(fileno(stderr)) == -1)
+      freopen("CONOUT$", "w", stderr);
+    if (_fileno(stdin) == -1 || _get_osfhandle(fileno(stdin)) == -1)
+      freopen("CONIN$", "r", stdin);
+  }
 
 #  if defined(MOZ_SANDBOX)
   if (aChildData->sandboxTargetServices) {
     SandboxTarget::Instance()->SetTargetServices(
         aChildData->sandboxTargetServices);
   }
 #  endif
 #endif
--- a/toolkit/xre/nsNativeAppSupportWin.cpp
+++ b/toolkit/xre/nsNativeAppSupportWin.cpp
@@ -1,17 +1,18 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "nsNativeAppSupportBase.h"
 #include "nsNativeAppSupportWin.h"
 
-#include "mozilla/WindowsConsole.h"
+#include <windows.h>
+#include <fcntl.h>
 
 using namespace mozilla;
 
 /*
  * This code attaches the process to the appropriate console.
  */
 
 class nsNativeAppSupportWin : public nsNativeAppSupportBase {
@@ -20,16 +21,35 @@ class nsNativeAppSupportWin : public nsN
   // option: "--console", which dynamically creates a Windows
   // console.
   void CheckConsole();
 
  private:
   ~nsNativeAppSupportWin() {}
 };  // nsNativeAppSupportWin
 
+void UseParentConsole() {
+  if (AttachConsole(ATTACH_PARENT_PROCESS)) {
+    // Redirect the standard streams to the existing console, but
+    // only if they haven't been redirected to a valid file.
+    // Visual Studio's _fileno() returns -2 for the standard
+    // streams if they aren't associated with an output stream.
+    if (_fileno(stdout) == -2) {
+      freopen("CONOUT$", "w", stdout);
+    }
+    // There is no CONERR$, so use CONOUT$ for stderr as well.
+    if (_fileno(stderr) == -2) {
+      freopen("CONOUT$", "w", stderr);
+    }
+    if (_fileno(stdin) == -2) {
+      freopen("CONIN$", "r", stdin);
+    }
+  }
+}
+
 void nsNativeAppSupportWin::CheckConsole() {
   for (int i = 1; i < gArgc; ++i) {
     if (strcmp("-console", gArgv[i]) == 0 ||
         strcmp("--console", gArgv[i]) == 0 ||
         strcmp("/console", gArgv[i]) == 0) {
       if (AllocConsole()) {
         // Redirect the standard streams to the new console, but
         // only if they haven't been redirected to a valid file.
deleted file mode 100644
--- a/widget/windows/WindowsConsole.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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 "WindowsConsole.h"
-
-#include <windows.h>
-#include <fcntl.h>
-
-namespace mozilla {
-
-// This code attaches the process to the appropriate console.
-void UseParentConsole() {
-  if (AttachConsole(ATTACH_PARENT_PROCESS)) {
-    // Redirect the standard streams to the existing console, but
-    // only if they haven't been redirected to a valid file.
-    // Visual Studio's _fileno() returns -2 for the standard
-    // streams if they aren't associated with an output stream.
-    if (_fileno(stdout) == -2) {
-      freopen("CONOUT$", "w", stdout);
-    }
-    // There is no CONERR$, so use CONOUT$ for stderr as well.
-    if (_fileno(stderr) == -2) {
-      freopen("CONOUT$", "w", stderr);
-    }
-    if (_fileno(stdin) == -2) {
-      freopen("CONIN$", "r", stdin);
-    }
-  }
-}
-
-}  // namespace mozilla
deleted file mode 100644
--- a/widget/windows/WindowsConsole.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_WindowsConsole_h
-#define mozilla_WindowsConsole_h
-
-namespace mozilla {
-
-// This code attaches the process to the appropriate console.
-void UseParentConsole();
-
-}  // namespace mozilla
-
-#endif  // mozilla_WindowsConsole_h
--- a/widget/windows/moz.build
+++ b/widget/windows/moz.build
@@ -14,17 +14,16 @@ TEST_DIRS += ['tests']
 
 EXPORTS += [
     'nsdefs.h',
     'WindowHook.h',
     'WinUtils.h',
 ]
 
 EXPORTS.mozilla += [
-    'WindowsConsole.h',
     'WinHeaderOnlyUtils.h',
 ]
 
 EXPORTS.mozilla.widget += [
     'AudioSession.h',
     'CompositorWidgetChild.h',
     'CompositorWidgetParent.h',
     'InProcessWinCompositorWidget.h',
@@ -71,17 +70,16 @@ UNIFIED_SOURCES += [
     'ScreenHelperWin.cpp',
     'TaskbarPreview.cpp',
     'TaskbarPreviewButton.cpp',
     'TaskbarTabPreview.cpp',
     'TaskbarWindowPreview.cpp',
     'WidgetTraceEvent.cpp',
     'WinCompositorWindowThread.cpp',
     'WindowHook.cpp',
-    'WindowsConsole.cpp',
     'WinIMEHandler.cpp',
     'WinPointerEvents.cpp',
     'WinTaskbar.cpp',
     'WinTextEventDispatcherListener.cpp',
     'WinUtils.cpp',
 ]
 
 # The following files cannot be built in unified mode because of name clashes.