Bug 1092855 - Work around bad interaction between jemalloc and Apple uninitialized memory bug. r=spohl, a=lsblakk
authorSteven Michaud <smichaud@pobox.com>
Tue, 11 Nov 2014 15:28:18 -0600
changeset 226040 4bdf71e69d10
parent 226039 609915862295
child 226041 f2dd9f2a084a
push id4119
push userryanvm@gmail.com
push date2014-11-12 22:22 +0000
treeherdermozilla-beta@f2dd9f2a084a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl, lsblakk
bugs1092855
milestone34.0
Bug 1092855 - Work around bad interaction between jemalloc and Apple uninitialized memory bug. r=spohl, a=lsblakk
dom/plugins/ipc/PluginProcessChild.cpp
widget/cocoa/nsAppShell.mm
--- a/dom/plugins/ipc/PluginProcessChild.cpp
+++ b/dom/plugins/ipc/PluginProcessChild.cpp
@@ -8,16 +8,23 @@
 #include "mozilla/plugins/PluginProcessChild.h"
 
 #include "prlink.h"
 
 #include "base/command_line.h"
 #include "base/string_util.h"
 #include "chrome/common/chrome_switches.h"
 
+#if defined(XP_MACOSX)
+#include "nsCocoaFeatures.h"
+// An undocumented CoreGraphics framework method, present in the same form
+// since at least OS X 10.5.
+extern "C" CGError CGSSetDebugOptions(int options);
+#endif
+
 #ifdef XP_WIN
 #include <objbase.h>
 bool ShouldProtectPluginCurrentDirectory(char16ptr_t pluginFilePath);
 #endif
 
 using mozilla::ipc::IOThreadChild;
 
 #ifdef OS_WIN
@@ -114,19 +121,31 @@ PluginProcessChild::Init()
 #  error Sorry
 #endif
 
     if (NS_FAILED(nsRegion::InitStatic())) {
       NS_ERROR("Could not initialize nsRegion");
       return false;
     }
 
-    return mPlugin.Init(pluginFilename, ParentHandle(),
-                        IOThreadChild::message_loop(),
-                        IOThreadChild::channel());
+    bool retval = mPlugin.Init(pluginFilename, ParentHandle(),
+                               IOThreadChild::message_loop(),
+                               IOThreadChild::channel());
+#if defined(XP_MACOSX)
+    if (nsCocoaFeatures::OnYosemiteOrLater()) {
+      // Explicitly turn off CGEvent logging.  This works around bug 1092855.
+      // If there are already CGEvents in the log, turning off logging also
+      // causes those events to be written to disk.  But at this point no
+      // CGEvents have yet been processed.  CGEvents are events (usually
+      // input events) pulled from the WindowServer.  An option of 0x80000008
+      // turns on CGEvent logging.
+      CGSSetDebugOptions(0x80000007);
+    }
+#endif
+    return retval;
 }
 
 void
 PluginProcessChild::CleanUp()
 {
 #ifdef XP_WIN
     ::OleUninitialize();
 #endif
--- a/widget/cocoa/nsAppShell.mm
+++ b/widget/cocoa/nsAppShell.mm
@@ -216,16 +216,21 @@ RemoveScreenWakeLockListener()
   nsCOMPtr<nsIPowerManagerService> sPowerManagerService = do_GetService(
                                                           POWERMANAGERSERVICE_CONTRACTID);
   if (sPowerManagerService) {
     sPowerManagerService->RemoveWakeLockListener(sWakeLockListener);
     sPowerManagerService = nullptr;
     sWakeLockListener = nullptr;
   }
 }
+
+// An undocumented CoreGraphics framework method, present in the same form
+// since at least OS X 10.5.
+extern "C" CGError CGSSetDebugOptions(int options);
+
 // Init
 //
 // Loads the nib (see bug 316076c21) and sets up the CFRunLoopSource used to
 // interrupt the main native run loop.
 //
 // public
 nsresult
 nsAppShell::Init()
@@ -300,16 +305,26 @@ nsAppShell::Init()
     // running in a Cocoa embedder (like Camino).  See bug 604901.
     if (!mRunningCocoaEmbedded) {
       nsToolkit::SwizzleMethods([NSApplication class], @selector(terminate:),
                                 @selector(nsAppShell_NSApplication_terminate:));
     }
     gAppShellMethodsSwizzled = true;
   }
 
+  if (nsCocoaFeatures::OnYosemiteOrLater()) {
+    // Explicitly turn off CGEvent logging.  This works around bug 1092855.
+    // If there are already CGEvents in the log, turning off logging also
+    // causes those events to be written to disk.  But at this point no
+    // CGEvents have yet been processed.  CGEvents are events (usually
+    // input events) pulled from the WindowServer.  An option of 0x80000008
+    // turns on CGEvent logging.
+    CGSSetDebugOptions(0x80000007);
+  }
+
   [localPool release];
 
   return rv;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 // ProcessGeckoEvents