Bug 1188408 - Factor out functions to protect/unprotect pages on different architectures r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 30 Jul 2015 10:55:51 +0100
changeset 287104 0592c3a585fb2616eaa84f4ae1c2e282e4558004
parent 287103 a69943dee0b21d1e69ccebd0a62d3c2da564536d
child 287105 ff50a243f1c06fbddce17d334749f24d08b80d59
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1188408
milestone42.0a1
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
Bug 1188408 - Factor out functions to protect/unprotect pages on different architectures r=terrence
js/src/gc/Memory.cpp
js/src/gc/Memory.h
js/src/jsgc.cpp
--- a/js/src/gc/Memory.cpp
+++ b/js/src/gc/Memory.cpp
@@ -746,10 +746,40 @@ DeallocateMappedContent(void* p, size_t 
     if (munmap(pa_start, total_size))
         MOZ_ASSERT(errno == ENOMEM);
 }
 
 #else
 #error "Memory mapping functions are not defined for your OS."
 #endif
 
+void
+ProtectPages(void* p, size_t size)
+{
+    MOZ_ASSERT(size % pageSize == 0);
+#if defined(XP_WIN)
+    DWORD oldProtect;
+    if (!VirtualProtect(p, size, PAGE_NOACCESS, &oldProtect))
+        MOZ_CRASH("VirtualProtect(PAGE_NOACCESS) failed");
+    MOZ_ASSERT(oldProtect == PAGE_READWRITE);
+#else  // assume Unix
+    if (mprotect(p, size, PROT_NONE))
+        MOZ_CRASH("mprotect(PROT_NONE) failed");
+#endif
+}
+
+void
+UnprotectPages(void* p, size_t size)
+{
+    MOZ_ASSERT(size % pageSize == 0);
+#if defined(XP_WIN)
+    DWORD oldProtect;
+    if (!VirtualProtect(p, size, PAGE_READWRITE, &oldProtect))
+        MOZ_CRASH("VirtualProtect(PAGE_READWRITE) failed");
+    MOZ_ASSERT(oldProtect == PAGE_NOACCESS);
+#else  // assume Unix
+    if (mprotect(p, size, PROT_READ | PROT_WRITE))
+        MOZ_CRASH("mprotect(PROT_READ | PROT_WRITE) failed");
+#endif
+}
+
 } // namespace gc
 } // namespace js
--- a/js/src/gc/Memory.h
+++ b/js/src/gc/Memory.h
@@ -38,12 +38,15 @@ size_t GetPageFaultCount();
 // The offset must be aligned according to alignment requirement.
 void* AllocateMappedContent(int fd, size_t offset, size_t length, size_t alignment);
 
 // Deallocate memory mapped content.
 void DeallocateMappedContent(void* p, size_t length);
 
 void* TestMapAlignedPagesLastDitch(size_t size, size_t alignment);
 
+void ProtectPages(void* p, size_t size);
+void UnprotectPages(void* p, size_t size);
+
 } // namespace gc
 } // namespace js
 
 #endif /* gc_Memory_h */
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -2640,41 +2640,26 @@ GCRuntime::updatePointersToRelocatedCell
 }
 
 #ifdef DEBUG
 void
 GCRuntime::protectRelocatedArenas()
 {
     for (ArenaHeader* arena = relocatedArenasToRelease; arena; ) {
         ArenaHeader* next = arena->next;
-#if defined(XP_WIN)
-        DWORD oldProtect;
-        if (!VirtualProtect(arena, ArenaSize, PAGE_NOACCESS, &oldProtect))
-            MOZ_CRASH();
-#else  // assume Unix
-        if (mprotect(arena, ArenaSize, PROT_NONE))
-            MOZ_CRASH();
-#endif
+        ProtectPages(arena, ArenaSize);
         arena = next;
     }
 }
 
 void
 GCRuntime::unprotectRelocatedArenas()
 {
-    for (ArenaHeader* arena = relocatedArenasToRelease; arena; arena = arena->next) {
-#if defined(XP_WIN)
-        DWORD oldProtect;
-        if (!VirtualProtect(arena, ArenaSize, PAGE_READWRITE, &oldProtect))
-            MOZ_CRASH();
-#else  // assume Unix
-        if (mprotect(arena, ArenaSize, PROT_READ | PROT_WRITE))
-            MOZ_CRASH();
-#endif
-    }
+    for (ArenaHeader* arena = relocatedArenasToRelease; arena; arena = arena->next)
+        UnprotectPages(arena, ArenaSize);
 }
 #endif
 
 void
 GCRuntime::releaseRelocatedArenas()
 {
     AutoLockGC lock(rt);
     releaseRelocatedArenasWithoutUnlocking(lock);