From f997140c00b7b4cd1a80521eb00e921439b5fd6a Mon Sep 17 00:00:00 2001
From: Brindusan Cristian <cbrindusan@mozilla.com>
Date: Mon, 24 Sep 2018 17:10:58 +0300
Subject: [PATCH] Backed out changeset 628ebca30ce3 (bug 1490240) for bustages
 on [Unified_cpp_crashreporter0.obj]. CLOSED TREE

---
 mozglue/misc/interceptor/PatcherNopSpace.h    |   9 +-
 mozglue/misc/interceptor/TargetFunction.h     | 119 +++++++++---------
 .../breakpad-client/linux/moz.build           |   3 +
 .../breakpad-client/mac/handler/moz.build     |   3 +
 .../client/crashreporter_win.cpp              |  15 ++-
 toolkit/crashreporter/client/moz.build        |   3 +
 .../google-breakpad/src/common/mac/moz.build  |   3 +
 .../google-breakpad/src/common/moz.build      |   3 +
 toolkit/crashreporter/moz.build               |   3 +
 toolkit/crashreporter/nsExceptionHandler.cpp  |  16 +--
 toolkit/crashreporter/test/moz.build          |   3 +
 toolkit/crashreporter/test/nsTestCrasher.cpp  |   2 +-
 12 files changed, 102 insertions(+), 80 deletions(-)

diff --git a/mozglue/misc/interceptor/PatcherNopSpace.h b/mozglue/misc/interceptor/PatcherNopSpace.h
index 3382e7dabdd55..6ebf9a0b59fe7 100644
--- a/mozglue/misc/interceptor/PatcherNopSpace.h
+++ b/mozglue/misc/interceptor/PatcherNopSpace.h
@@ -152,8 +152,8 @@ public:
       return false;
     }
 
-    return mPatchedFns.append(
-      reinterpret_cast<void*>(readOnlyTargetFn.GetBaseAddress()));
+    mPatchedFns.append(reinterpret_cast<void*>(readOnlyTargetFn.GetBaseAddress()));
+    return true;
   }
 
   bool WriteHook(const ReadOnlyTargetFunction<MMPolicyT>& aFn,
@@ -169,7 +169,7 @@ public:
 
     // Check that the 5 bytes before the function are NOP's or INT 3's,
     const uint8_t nopOrBp[] = { 0x90, 0xCC };
-    if (!writableFn.template VerifyValuesAreOneOf<uint8_t, 5>(nopOrBp)) {
+    if (!writableFn.VerifyValuesAreOneOf<uint8_t, 5>(nopOrBp)) {
       return false;
     }
 
@@ -184,8 +184,7 @@ public:
 
     // (These look backwards because little-endian)
     const uint16_t possibleEncodings[] = { 0xFF8B, 0xFF89 };
-    if (!writableFn.template VerifyValuesAreOneOf<uint16_t, 1>(
-            possibleEncodings, 5)) {
+    if (!writableFn.VerifyValuesAreOneOf<uint16_t, 1>(possibleEncodings, 5)) {
       return false;
     }
 
diff --git a/mozglue/misc/interceptor/TargetFunction.h b/mozglue/misc/interceptor/TargetFunction.h
index 2a0e63f0f4823..2d7202df6d5ea 100644
--- a/mozglue/misc/interceptor/TargetFunction.h
+++ b/mozglue/misc/interceptor/TargetFunction.h
@@ -595,81 +595,82 @@ private:
   uint8_t const * const           mBase;
 };
 
-template <typename TargetMMPolicy> class TargetBytesPtr;
-
-template<>
-class TargetBytesPtr<MMPolicyInProcess>
+template <typename MMPolicy>
+class MOZ_STACK_CLASS ReadOnlyTargetFunction final
 {
-public:
-  typedef TargetBytesPtr<MMPolicyInProcess> Type;
+  template <typename TargetMMPolicy>
+  class TargetBytesPtr;
 
-  static Type Make(const MMPolicyInProcess& aMMPolicy, const void* aFunc)
+  template<>
+  class TargetBytesPtr<MMPolicyInProcess>
   {
-    return TargetBytesPtr(aMMPolicy, aFunc);
-  }
+  public:
+    typedef TargetBytesPtr<MMPolicyInProcess> Type;
 
-  static Type CopyFromOffset(const TargetBytesPtr& aOther,
-                             const uint32_t aOffsetFromOther)
-  {
-    return TargetBytesPtr(aOther, aOffsetFromOther);
-  }
+    static Type Make(const MMPolicyInProcess& aMMPolicy, const void* aFunc)
+    {
+      return std::move(TargetBytesPtr(aMMPolicy, aFunc));
+    }
 
-  ReadOnlyTargetBytes<MMPolicyInProcess>* operator->()
-  {
-    return &mTargetBytes;
-  }
+    static Type CopyFromOffset(const TargetBytesPtr& aOther,
+                               const uint32_t aOffsetFromOther)
+    {
+      return std::move(TargetBytesPtr(aOther, aOffsetFromOther));
+    }
 
-  TargetBytesPtr(TargetBytesPtr&& aOther)
-    : mTargetBytes(std::move(aOther.mTargetBytes))
-  {
-  }
+    ReadOnlyTargetBytes<MMPolicyInProcess>* operator->()
+    {
+      return &mTargetBytes;
+    }
 
-  TargetBytesPtr(const TargetBytesPtr& aOther)
-    : mTargetBytes(aOther.mTargetBytes)
-  {
-  }
+    TargetBytesPtr(TargetBytesPtr&& aOther)
+      : mTargetBytes(std::move(aOther.mTargetBytes))
+    {
+    }
 
-  TargetBytesPtr& operator=(const TargetBytesPtr&) = delete;
-  TargetBytesPtr& operator=(TargetBytesPtr&&) = delete;
+    TargetBytesPtr(const TargetBytesPtr& aOther)
+      : mTargetBytes(aOther.mTargetBytes)
+    {
+    }
 
-private:
-  TargetBytesPtr(const MMPolicyInProcess& aMMPolicy, const void* aFunc)
-    : mTargetBytes(aMMPolicy, aFunc)
-  {
-  }
+    TargetBytesPtr& operator=(const TargetBytesPtr&) = delete;
+    TargetBytesPtr& operator=(TargetBytesPtr&&) = delete;
 
-  TargetBytesPtr(const TargetBytesPtr& aOther,
-                 const uint32_t aOffsetFromOther)
-    : mTargetBytes(aOther.mTargetBytes, aOffsetFromOther)
-  {
-  }
+  private:
+    TargetBytesPtr(const MMPolicyInProcess& aMMPolicy, const void* aFunc)
+      : mTargetBytes(aMMPolicy, aFunc)
+    {
+    }
 
-  ReadOnlyTargetBytes<MMPolicyInProcess> mTargetBytes;
-};
+    TargetBytesPtr(const TargetBytesPtr& aOther,
+                   const uint32_t aOffsetFromOther)
+      : mTargetBytes(aOther.mTargetBytes, aOffsetFromOther)
+    {
+    }
 
-template <>
-class TargetBytesPtr<MMPolicyOutOfProcess>
-{
-public:
-  typedef std::shared_ptr<ReadOnlyTargetBytes<MMPolicyOutOfProcess>> Type;
+    ReadOnlyTargetBytes<MMPolicyInProcess> mTargetBytes;
+  };
 
-  static Type Make(const MMPolicyOutOfProcess& aMMPolicy, const void* aFunc)
+  template <>
+  class TargetBytesPtr<MMPolicyOutOfProcess>
   {
-    return std::make_shared<ReadOnlyTargetBytes<MMPolicyOutOfProcess>>(
-                  aMMPolicy, aFunc);
-  }
+  public:
+    typedef std::shared_ptr<ReadOnlyTargetBytes<MMPolicyOutOfProcess>> Type;
 
-  static Type CopyFromOffset(const Type& aOther,
-                             const uint32_t aOffsetFromOther)
-  {
-    return std::make_shared<ReadOnlyTargetBytes<MMPolicyOutOfProcess>>(
-                  *aOther, aOffsetFromOther);
-  }
-};
+    static Type Make(const MMPolicyOutOfProcess& aMMPolicy, const void* aFunc)
+    {
+      return std::move(std::make_shared<ReadOnlyTargetBytes<MMPolicyOutOfProcess>>(
+                    aMMPolicy, aFunc));
+    }
+
+    static Type CopyFromOffset(const Type& aOther,
+                               const uint32_t aOffsetFromOther)
+    {
+      return std::move(std::make_shared<ReadOnlyTargetBytes<MMPolicyOutOfProcess>>(
+                    *aOther, aOffsetFromOther));
+    }
+  };
 
-template <typename MMPolicy>
-class MOZ_STACK_CLASS ReadOnlyTargetFunction final
-{
 public:
   ReadOnlyTargetFunction(const MMPolicy& aMMPolicy, const void* aFunc)
     : mTargetBytes(TargetBytesPtr<MMPolicy>::Make(aMMPolicy, aFunc))
diff --git a/toolkit/crashreporter/breakpad-client/linux/moz.build b/toolkit/crashreporter/breakpad-client/linux/moz.build
index 047f78c6f3e65..c7aa654406ad5 100644
--- a/toolkit/crashreporter/breakpad-client/linux/moz.build
+++ b/toolkit/crashreporter/breakpad-client/linux/moz.build
@@ -30,6 +30,9 @@ if CONFIG['OS_TARGET'] == 'Android':
         '/toolkit/crashreporter/google-breakpad/src/common/android/include',
     ]
 
+# We allow warnings for third-party code that can be updated from upstream.
+AllowCompilerWarnings()
+
 FINAL_LIBRARY = 'xul'
 
 include('/toolkit/crashreporter/crashreporter.mozbuild')
diff --git a/toolkit/crashreporter/breakpad-client/mac/handler/moz.build b/toolkit/crashreporter/breakpad-client/mac/handler/moz.build
index b0bac75a85041..6c0cf495d08c8 100644
--- a/toolkit/crashreporter/breakpad-client/mac/handler/moz.build
+++ b/toolkit/crashreporter/breakpad-client/mac/handler/moz.build
@@ -11,6 +11,9 @@ UNIFIED_SOURCES += [
     'minidump_generator.cc',
 ]
 
+# We allow warnings for third-party code that can be updated from upstream.
+AllowCompilerWarnings()
+
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
diff --git a/toolkit/crashreporter/client/crashreporter_win.cpp b/toolkit/crashreporter/client/crashreporter_win.cpp
index 873d25c82244c..c4b94a3fcfc17 100644
--- a/toolkit/crashreporter/client/crashreporter_win.cpp
+++ b/toolkit/crashreporter/client/crashreporter_win.cpp
@@ -283,8 +283,7 @@ static string FormatLastError()
   }
   else {
     char buf[64];
-    sprintf(buf, "Unknown error, error code: 0x%08x",
-            static_cast<unsigned int>(err));
+    sprintf(buf, "Unknown error, error code: 0x%08x", err);
     message += buf;
   }
   return message;
@@ -349,6 +348,18 @@ static void SetDlgItemVisible(HWND hwndDlg, UINT item, bool visible)
   ShowWindow(hwnd, visible ? SW_SHOW : SW_HIDE);
 }
 
+static void SetDlgItemDisabled(HWND hwndDlg, UINT item, bool disabled)
+{
+  HWND hwnd = GetDlgItem(hwndDlg, item);
+  LONG style = GetWindowLong(hwnd, GWL_STYLE);
+  if (!disabled)
+    style |= WS_DISABLED;
+  else
+    style &= ~WS_DISABLED;
+
+  SetWindowLong(hwnd, GWL_STYLE, style);
+}
+
 /* === Crash Reporting Dialog === */
 
 static void StretchDialog(HWND hwndDlg, int ydiff)
diff --git a/toolkit/crashreporter/client/moz.build b/toolkit/crashreporter/client/moz.build
index dae264c177933..99eb9b0cb0201 100644
--- a/toolkit/crashreporter/client/moz.build
+++ b/toolkit/crashreporter/client/moz.build
@@ -99,3 +99,6 @@ RCINCLUDE = 'crashreporter.rc'
 DisableStlWrapping()
 
 include('/toolkit/crashreporter/crashreporter.mozbuild')
+
+if CONFIG['CC_TYPE'] == 'clang-cl':
+    AllowCompilerWarnings()  # workaround for bug 1090497
diff --git a/toolkit/crashreporter/google-breakpad/src/common/mac/moz.build b/toolkit/crashreporter/google-breakpad/src/common/mac/moz.build
index 2a1e168fccd1f..4ace7bc6287ef 100644
--- a/toolkit/crashreporter/google-breakpad/src/common/mac/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/common/mac/moz.build
@@ -42,6 +42,9 @@ SOURCES += [
 
 Library('breakpad_mac_common_s')
 
+# We allow warnings for third-party code that can be updated from upstream.
+AllowCompilerWarnings()
+
 FINAL_LIBRARY = 'xul'
 
 CMFLAGS += ['-std=c99']
diff --git a/toolkit/crashreporter/google-breakpad/src/common/moz.build b/toolkit/crashreporter/google-breakpad/src/common/moz.build
index 725ff06cc18a6..8bbd071666ae5 100644
--- a/toolkit/crashreporter/google-breakpad/src/common/moz.build
+++ b/toolkit/crashreporter/google-breakpad/src/common/moz.build
@@ -70,6 +70,9 @@ if CONFIG['OS_TARGET'] == 'Android':
 
 Library('breakpad_common_s')
 
+# We allow warnings for third-party code that can be updated from upstream.
+AllowCompilerWarnings()
+
 FINAL_LIBRARY = 'xul'
 
 include('/toolkit/crashreporter/crashreporter.mozbuild')
diff --git a/toolkit/crashreporter/moz.build b/toolkit/crashreporter/moz.build
index dba5bffe82d4d..0b710b8348ef1 100644
--- a/toolkit/crashreporter/moz.build
+++ b/toolkit/crashreporter/moz.build
@@ -141,3 +141,6 @@ crash_annotations.inputs = [
 
 with Files('**'):
     BUG_COMPONENT = ('Toolkit', 'Crash Reporting')
+
+if CONFIG['CC_TYPE'] == 'clang-cl':
+    AllowCompilerWarnings()  # workaround for bug 1090497
diff --git a/toolkit/crashreporter/nsExceptionHandler.cpp b/toolkit/crashreporter/nsExceptionHandler.cpp
index 2fce7b27876e7..21227ec723849 100644
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -12,7 +12,6 @@
 #include "nsDirectoryService.h"
 #include "nsDataHashtable.h"
 #include "mozilla/ArrayUtils.h"
-#include "mozilla/DebugOnly.h"
 #include "mozilla/EnumeratedRange.h"
 #include "mozilla/Services.h"
 #include "nsIObserverService.h"
@@ -1330,8 +1329,6 @@ FreeBreakpadVM()
   }
 }
 
-#if defined(XP_WIN)
-
 /**
  * Filters out floating point exceptions which are handled by nsSigHandlers.cpp
  * and should not be handled as crashes.
@@ -1382,8 +1379,6 @@ ChildFPEFilter(void* context, EXCEPTION_POINTERS* exinfo,
   return result;
 }
 
-#endif // defined(XP_WIN)
-
 static MINIDUMP_TYPE
 GetMinidumpType()
 {
@@ -1433,8 +1428,6 @@ static bool ShouldReport()
   return true;
 }
 
-#if !defined(XP_WIN)
-
 static bool
 Filter(void* context)
 {
@@ -1455,8 +1448,6 @@ ChildFilter(void* context)
   return result;
 }
 
-#endif // !defined(XP_WIN)
-
 static void
 TerminateHandler()
 {
@@ -1671,10 +1662,9 @@ nsresult SetExceptionHandler(nsIFile* aXREDirectory,
   // protect the crash reporter from being unloaded
   gBlockUnhandledExceptionFilter = true;
   gKernel32Intercept.Init("kernel32.dll");
-  DebugOnly<bool> ok =
-    stub_SetUnhandledExceptionFilter.Set(gKernel32Intercept,
-                                         "SetUnhandledExceptionFilter",
-                                         &patched_SetUnhandledExceptionFilter);
+  bool ok = stub_SetUnhandledExceptionFilter.Set(gKernel32Intercept,
+                                                 "SetUnhandledExceptionFilter",
+                                                 &patched_SetUnhandledExceptionFilter);
 
 #ifdef DEBUG
   if (!ok)
diff --git a/toolkit/crashreporter/test/moz.build b/toolkit/crashreporter/test/moz.build
index abea73981f45c..c62600a00b0df 100755
--- a/toolkit/crashreporter/test/moz.build
+++ b/toolkit/crashreporter/test/moz.build
@@ -59,3 +59,6 @@ NO_PGO = True
 # Temporary workaround for an issue in upstream breakpad
 if CONFIG['CC_TYPE'] in ('msvc', 'clang-cl'):
     CXXFLAGS += ['-wd4334']
+
+if CONFIG['CC_TYPE'] == 'clang-cl':
+    AllowCompilerWarnings()  # workaround for bug 1090497
diff --git a/toolkit/crashreporter/test/nsTestCrasher.cpp b/toolkit/crashreporter/test/nsTestCrasher.cpp
index 7b63d2de045bb..ac76387423300 100755
--- a/toolkit/crashreporter/test/nsTestCrasher.cpp
+++ b/toolkit/crashreporter/test/nsTestCrasher.cpp
@@ -176,7 +176,7 @@ void Crash(int16_t how)
     auto pfnTest = m[how];
     auto pfnLauncher = m[CRASH_X64CFI_LAUNCHER];
     ReserveStack();
-    pfnLauncher(0, reinterpret_cast<void*>(pfnTest));
+    pfnLauncher(0, pfnTest);
     break;
   }
 #endif // XP_WIN && HAVE_64BIT_BUILD && !defined(__MINGW32__)
-- 
GitLab