Bug 946799 part A - annotate the location and size of the breakpad memory reservation, r=ted a=lsblakk
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 06 Dec 2013 09:00:06 -0500
changeset 167712 591ed7a98ced45f98d0e944b7b809e97a3e26037
parent 167711 a05c70a52b9b87cbdc03188e2a4f22d3458585d9
child 167713 79e2ad13871d646e5405e4f3dfe2bd1c6120f831
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted, lsblakk
bugs946799
milestone27.0
Bug 946799 part A - annotate the location and size of the breakpad memory reservation, r=ted a=lsblakk
toolkit/crashreporter/nsExceptionHandler.cpp
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -218,16 +218,26 @@ static const int kAvailablePageFileParam
 static const char kAvailablePhysicalMemoryParameter[] = "AvailablePhysicalMemory=";
 static const int kAvailablePhysicalMemoryParameterLen =
   sizeof(kAvailablePhysicalMemoryParameter)-1;
 
 static const char kIsGarbageCollectingParameter[] = "IsGarbageCollecting=";
 static const int kIsGarbageCollectingParameterLen =
   sizeof(kIsGarbageCollectingParameter)-1;
 
+#ifdef XP_WIN
+static const char kBreakpadReserveAddressParameter[] = "BreakpadReserveAddress=";
+static const int kBreakpadReserveAddressParameterLen =
+  sizeof(kBreakpadReserveAddressParameter)-1;
+
+static const char kBreakpadReserveSizeParameter[] = "BreakpadReserveSize=";
+static const int kBreakpadReserveSizeParameterLen =
+  sizeof(kBreakpadReserveSizeParameter)-1;
+#endif
+
 // this holds additional data sent via the API
 static Mutex* crashReporterAPILock;
 static Mutex* notesFieldLock;
 static AnnotationTable* crashReporterAPIData_Hash;
 static nsCString* crashReporterAPIData = nullptr;
 static nsCString* notesField = nullptr;
 static bool isGarbageCollecting;
 
@@ -319,16 +329,27 @@ patched_SetUnhandledExceptionFilter (LPT
   if (!gBlockUnhandledExceptionFilter) {
     // don't intercept
     return stub_SetUnhandledExceptionFilter(lpTopLevelExceptionFilter);
   }
 
   // intercept attempts to change the filter
   return nullptr;
 }
+
+/**
+ * Reserve some VM space. In the event that we crash because VM space is
+ * being leaked without leaking memory, freeing this space before taking
+ * the minidump will allow us to collect a minidump.
+ *
+ * This size is bigger than xul.dll plus some extra for MinidumpWriteDump
+ * allocations.
+ */
+static const SIZE_T kReserveSize = 0x2400000; // 36 MB
+static void* gBreakpadReservedVM;
 #endif
 
 #ifdef XP_MACOSX
 static cpu_type_t pref_cpu_types[2] = {
 #if defined(__i386__)
                                  CPU_TYPE_X86,
 #elif defined(__x86_64__)
                                  CPU_TYPE_X86_64,
@@ -537,26 +558,38 @@ bool MinidumpCallback(
       }
       if (isGarbageCollecting) {
         WriteFile(hFile, kIsGarbageCollectingParameter, kIsGarbageCollectingParameterLen,
                   &nBytes, nullptr);
         WriteFile(hFile, isGarbageCollecting ? "1" : "0", 1, &nBytes, nullptr);
         WriteFile(hFile, "\n", 1, &nBytes, nullptr);
       }
 
+      char buffer[128];
+      int bufferLen;
+
+      if (gBreakpadReservedVM) {
+        WriteFile(hFile, kBreakpadReserveAddressParameter, kBreakpadReserveAddressParameterLen, &nBytes, nullptr);
+        _ui64toa(uintptr_t(gBreakpadReservedVM), buffer, 10);
+        WriteFile(hFile, buffer, strlen(buffer), &nBytes, nullptr);
+        WriteFile(hFile, "\n", 1, &nBytes, nullptr);
+        WriteFile(hFile, kBreakpadReserveSizeParameter, kBreakpadReserveSizeParameterLen, &nBytes, nullptr);
+        _ui64toa(kReserveSize, buffer, 10);
+        WriteFile(hFile, buffer, strlen(buffer), &nBytes, nullptr);
+        WriteFile(hFile, "\n", 1, &nBytes, nullptr);
+      }
+
 #ifdef HAS_DLL_BLOCKLIST
       DllBlocklist_WriteNotes(hFile);
 #endif
 
       // Try to get some information about memory.
       MEMORYSTATUSEX statex;
       statex.dwLength = sizeof(statex);
       if (GlobalMemoryStatusEx(&statex)) {
-        char buffer[128];
-        int bufferLen;
 
 #define WRITE_STATEX_FIELD(field, paramName, conversionFunc)     \
         WriteFile(hFile, k##paramName##Parameter,                \
                   k##paramName##ParameterLen, &nBytes, nullptr); \
         conversionFunc(statex.field, buffer, 10);                \
         bufferLen = strlen(buffer);                              \
         WriteFile(hFile, buffer, bufferLen, &nBytes, nullptr);   \
         WriteFile(hFile, "\n", 1, &nBytes, nullptr);
@@ -708,28 +741,16 @@ bool MinidumpCallback(
   }
 #endif // XP_MACOSX
 #endif // XP_UNIX
 
   return returnValue;
 }
 
 #ifdef XP_WIN
-static void* gBreakpadReservedVM;
-
-/**
- * Reserve some VM space. In the event that we crash because VM space is
- * being leaked without leaking memory, freeing this space before taking
- * the minidump will allow us to collect a minidump.
- *
- * This size is bigger than xul.dll plus some extra for MinidumpWriteDump
- * allocations.
- */
-static const SIZE_T kReserveSize = 0x2400000; // 36 MB
-
 static void
 ReserveBreakpadVM()
 {
   if (!gBreakpadReservedVM) {
     gBreakpadReservedVM = VirtualAlloc(nullptr, kReserveSize, MEM_RESERVE,
                                        PAGE_NOACCESS);
   }
 }