Bug 1338574 - Part 4: Use MOZ_CRASH_UNSAFE_OOL and MOZ_CRASH_UNSAFE_PRINTF in SpiderMonkey. r=jandem
authorEmanuel Hoogeveen <emanuel.hoogeveen@gmail.com>
Tue, 21 Feb 2017 18:01:52 +0100
changeset 373190 2a7baab53d6920e2ed024aa80e3c04344885d971
parent 373189 02ca86a397be7609ecf96bda5b162f6598906884
child 373191 32194844a42a211631255bc39b16fe5f6153b1ff
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1338574
milestone54.0a1
Bug 1338574 - Part 4: Use MOZ_CRASH_UNSAFE_OOL and MOZ_CRASH_UNSAFE_PRINTF in SpiderMonkey. r=jandem
js/src/gc/Memory.cpp
js/src/shell/js.cpp
js/src/vm/TypeInference.cpp
js/src/vm/TypeInference.h
--- a/js/src/gc/Memory.cpp
+++ b/js/src/gc/Memory.cpp
@@ -838,33 +838,27 @@ DeallocateMappedContent(void* p, size_t 
     size_t alignedLength = length + (uintptr_t(p) % allocGranularity);
     UnmapPages(reinterpret_cast<void*>(map), alignedLength);
 }
 
 #else
 #error "Memory mapping functions are not defined for your OS."
 #endif
 
-#ifdef XP_WIN
-static char sCrashReason[256];
-#endif
-
 void
 ProtectPages(void* p, size_t size)
 {
     MOZ_ASSERT(size % pageSize == 0);
     MOZ_RELEASE_ASSERT(size > 0);
     MOZ_RELEASE_ASSERT(p);
 #if defined(XP_WIN)
     DWORD oldProtect;
     if (!VirtualProtect(p, size, PAGE_NOACCESS, &oldProtect)) {
-        SprintfLiteral(sCrashReason,
-            "MOZ_CRASH(VirtualProtect(PAGE_NOACCESS) failed! Error code: %u)", GetLastError());
-        MOZ_CRASH_ANNOTATE(sCrashReason);
-        MOZ_REALLY_CRASH();
+        MOZ_CRASH_UNSAFE_PRINTF("VirtualProtect(PAGE_NOACCESS) failed! Error code: %u",
+                                GetLastError());
     }
     MOZ_ASSERT(oldProtect == PAGE_READWRITE);
 #else  // assume Unix
     if (mprotect(p, size, PROT_NONE))
         MOZ_CRASH("mprotect(PROT_NONE) failed");
 #endif
 }
 
@@ -872,20 +866,18 @@ void
 MakePagesReadOnly(void* p, size_t size)
 {
     MOZ_ASSERT(size % pageSize == 0);
     MOZ_RELEASE_ASSERT(size > 0);
     MOZ_RELEASE_ASSERT(p);
 #if defined(XP_WIN)
     DWORD oldProtect;
     if (!VirtualProtect(p, size, PAGE_READONLY, &oldProtect)) {
-        SprintfLiteral(sCrashReason,
-            "MOZ_CRASH(VirtualProtect(PAGE_READONLY) failed! Error code: %u)", GetLastError());
-        MOZ_CRASH_ANNOTATE(sCrashReason);
-        MOZ_REALLY_CRASH();
+        MOZ_CRASH_UNSAFE_PRINTF("VirtualProtect(PAGE_READONLY) failed! Error code: %u",
+                                GetLastError());
     }
     MOZ_ASSERT(oldProtect == PAGE_READWRITE);
 #else  // assume Unix
     if (mprotect(p, size, PROT_READ))
         MOZ_CRASH("mprotect(PROT_READ) failed");
 #endif
 }
 
@@ -893,20 +885,18 @@ void
 UnprotectPages(void* p, size_t size)
 {
     MOZ_ASSERT(size % pageSize == 0);
     MOZ_RELEASE_ASSERT(size > 0);
     MOZ_RELEASE_ASSERT(p);
 #if defined(XP_WIN)
     DWORD oldProtect;
     if (!VirtualProtect(p, size, PAGE_READWRITE, &oldProtect)) {
-        SprintfLiteral(sCrashReason,
-            "MOZ_CRASH(VirtualProtect(PAGE_READWRITE) failed! Error code: %u)", GetLastError());
-        MOZ_CRASH_ANNOTATE(sCrashReason);
-        MOZ_REALLY_CRASH();
+        MOZ_CRASH_UNSAFE_PRINTF("VirtualProtect(PAGE_READWRITE) failed! Error code: %u",
+                                GetLastError());
     }
     MOZ_ASSERT(oldProtect == PAGE_NOACCESS || oldProtect == PAGE_READONLY);
 #else  // assume Unix
     if (mprotect(p, size, PROT_READ | PROT_WRITE))
         MOZ_CRASH("mprotect(PROT_READ | PROT_WRITE) failed");
 #endif
 }
 
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -3171,19 +3171,20 @@ Crash(JSContext* cx, unsigned argc, Valu
     if (args.length() == 0)
         MOZ_CRASH("forced crash");
     RootedString message(cx, JS::ToString(cx, args[0]));
     if (!message)
         return false;
     char* utf8chars = JS_EncodeStringToUTF8(cx, message);
     if (!utf8chars)
         return false;
+#ifndef DEBUG
     MOZ_ReportCrash(utf8chars, __FILE__, __LINE__);
-    MOZ_CRASH_ANNOTATE("MOZ_CRASH(dynamic)");
-    MOZ_REALLY_CRASH();
+#endif
+    MOZ_CRASH_UNSAFE_OOL(utf8chars);
 }
 
 static bool
 GetSLX(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     RootedScript script(cx);
 
--- a/js/src/vm/TypeInference.cpp
+++ b/js/src/vm/TypeInference.cpp
@@ -2603,26 +2603,21 @@ TypeZone::addPendingRecompile(JSContext*
     // When one script is inlined into another the caller listens to state
     // changes on the callee's script, so trigger these to force recompilation
     // of any such callers.
     if (script->functionNonDelazifying() && !script->functionNonDelazifying()->hasLazyGroup())
         ObjectStateChange(cx, script->functionNonDelazifying()->group(), false);
 }
 
 #ifdef JS_CRASH_DIAGNOSTICS
-static char sCrashReason[256];
-
-MOZ_NORETURN MOZ_COLD MOZ_NEVER_INLINE void
+void
 js::ReportMagicWordFailure(uintptr_t actual, uintptr_t expected)
 {
-    SprintfLiteral(sCrashReason,
-                   "MOZ_CRASH(Got 0x%" PRIxPTR " expected magic word 0x%" PRIxPTR ")",
-                   actual, expected);
-    MOZ_CRASH_ANNOTATE(sCrashReason);
-    MOZ_REALLY_CRASH();
+    MOZ_CRASH_UNSAFE_PRINTF("Got 0x%" PRIxPTR " expected magic word 0x%" PRIxPTR,
+                            actual, expected);
 }
 #endif
 
 void
 js::PrintTypes(JSContext* cx, JSCompartment* comp, bool force)
 {
 #ifdef DEBUG
     gc::AutoSuppressGC suppressGC(cx);
--- a/js/src/vm/TypeInference.h
+++ b/js/src/vm/TypeInference.h
@@ -539,17 +539,17 @@ class TypeSet
 static const uintptr_t BaseTypeInferenceMagic = 0xa1a2b3b4;
 #else
 static const uintptr_t BaseTypeInferenceMagic = 0xa1a2b3b4c5c6d7d8;
 #endif
 static const uintptr_t TypeConstraintMagic = BaseTypeInferenceMagic + 1;
 static const uintptr_t ConstraintTypeSetMagic = BaseTypeInferenceMagic + 2;
 
 #ifdef JS_CRASH_DIAGNOSTICS
-extern MOZ_NORETURN MOZ_COLD MOZ_NEVER_INLINE void
+extern void
 ReportMagicWordFailure(uintptr_t actual, uintptr_t expected);
 #endif
 
 /*
  * A constraint which listens to additions to a type set and propagates those
  * changes to other type sets.
  */
 class TypeConstraint