6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
authorcoleenp
Wed, 10 Dec 2008 15:14:29 -0800
changeset 1664 fc9ed50498fb
parent 1660 86be56b9ba46
child 1665 7b9a44b26afd
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE Summary: Make reguard_stack change access to RW, not execute and use os::protect_memory with the new parameter when change needed to X. Reviewed-by: acorn, jcoomes
hotspot/src/os/linux/vm/os_linux.cpp
hotspot/src/os/solaris/vm/os_solaris.cpp
hotspot/src/os/windows/vm/os_windows.cpp
hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp
hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp
hotspot/src/share/vm/prims/jni.cpp
hotspot/src/share/vm/runtime/os.cpp
hotspot/src/share/vm/runtime/os.hpp
--- a/hotspot/src/os/linux/vm/os_linux.cpp	Tue Dec 09 09:55:39 2008 -0500
+++ b/hotspot/src/os/linux/vm/os_linux.cpp	Wed Dec 10 15:14:29 2008 -0800
@@ -2500,7 +2500,7 @@
 }
 
 bool os::unguard_memory(char* addr, size_t size) {
-  return linux_mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC);
+  return linux_mprotect(addr, size, PROT_READ|PROT_WRITE);
 }
 
 // Large page support
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp	Tue Dec 09 09:55:39 2008 -0500
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp	Wed Dec 10 15:14:29 2008 -0800
@@ -3026,6 +3026,8 @@
 
 // Protect memory (Used to pass readonly pages through
 // JNI GetArray<type>Elements with empty arrays.)
+// Also, used for serialization page and for compressed oops null pointer
+// checking.
 bool os::protect_memory(char* addr, size_t bytes, ProtType prot,
                         bool is_committed) {
   unsigned int p = 0;
@@ -3049,7 +3051,7 @@
 }
 
 bool os::unguard_memory(char* addr, size_t bytes) {
-  return solaris_mprotect(addr, bytes, PROT_READ|PROT_WRITE|PROT_EXEC);
+  return solaris_mprotect(addr, bytes, PROT_READ|PROT_WRITE);
 }
 
 // Large page support
--- a/hotspot/src/os/windows/vm/os_windows.cpp	Tue Dec 09 09:55:39 2008 -0500
+++ b/hotspot/src/os/windows/vm/os_windows.cpp	Wed Dec 10 15:14:29 2008 -0800
@@ -2020,10 +2020,11 @@
         if (UnguardOnExecutionViolation > 0 && addr != last_addr &&
             (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
 
-          // Unguard and retry
+          // Set memory to RWX and retry
           address page_start =
             (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
-          bool res = os::unguard_memory((char*) page_start, page_size);
+          bool res = os::protect_memory((char*) page_start, page_size,
+                                        os::MEM_PROT_RWX);
 
           if (PrintMiscellaneous && Verbose) {
             char buf[256];
@@ -2755,12 +2756,12 @@
 
 bool os::guard_memory(char* addr, size_t bytes) {
   DWORD old_status;
-  return VirtualProtect(addr, bytes, PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_status) != 0;
+  return VirtualProtect(addr, bytes, PAGE_READWRITE | PAGE_GUARD, &old_status) != 0;
 }
 
 bool os::unguard_memory(char* addr, size_t bytes) {
   DWORD old_status;
-  return VirtualProtect(addr, bytes, PAGE_EXECUTE_READWRITE, &old_status) != 0;
+  return VirtualProtect(addr, bytes, PAGE_READWRITE, &old_status) != 0;
 }
 
 void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) { }
--- a/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Tue Dec 09 09:55:39 2008 -0500
+++ b/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Wed Dec 10 15:14:29 2008 -0800
@@ -422,10 +422,11 @@
       if (addr != last_addr &&
           (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
 
-        // Unguard and retry
+        // Set memory to RWX and retry
         address page_start =
           (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
-        bool res = os::unguard_memory((char*) page_start, page_size);
+        bool res = os::protect_memory((char*) page_start, page_size,
+                                      os::MEM_PROT_RWX);
 
         if (PrintMiscellaneous && Verbose) {
           char buf[256];
--- a/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Tue Dec 09 09:55:39 2008 -0500
+++ b/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Wed Dec 10 15:14:29 2008 -0800
@@ -576,10 +576,11 @@
       if (addr != last_addr &&
           (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
 
-        // Unguard and retry
+        // Make memory rwx and retry
         address page_start =
           (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
-        bool res = os::unguard_memory((char*) page_start, page_size);
+        bool res = os::protect_memory((char*) page_start, page_size,
+                                      os::MEM_PROT_RWX);
 
         if (PrintMiscellaneous && Verbose) {
           char buf[256];
--- a/hotspot/src/share/vm/prims/jni.cpp	Tue Dec 09 09:55:39 2008 -0500
+++ b/hotspot/src/share/vm/prims/jni.cpp	Wed Dec 10 15:14:29 2008 -0800
@@ -2173,7 +2173,8 @@
     size_t size = os::vm_allocation_granularity();
     bad_address = os::reserve_memory(size);
     if (bad_address != NULL) {
-      os::protect_memory(bad_address, size, os::MEM_PROT_READ);
+      os::protect_memory(bad_address, size, os::MEM_PROT_READ,
+                         /*is_committed*/false);
     }
   }
   return bad_address;
--- a/hotspot/src/share/vm/runtime/os.cpp	Tue Dec 09 09:55:39 2008 -0500
+++ b/hotspot/src/share/vm/runtime/os.cpp	Wed Dec 10 15:14:29 2008 -0800
@@ -932,8 +932,9 @@
   // the mutator thread if such case is encountered. See bug 6546278 for details.
   Thread::muxAcquire(&SerializePageLock, "serialize_thread_states");
   os::protect_memory((char *)os::get_memory_serialize_page(),
-                     os::vm_page_size(), MEM_PROT_READ, /*is_committed*/true );
-  os::unguard_memory((char *)os::get_memory_serialize_page(), os::vm_page_size());
+                     os::vm_page_size(), MEM_PROT_READ);
+  os::protect_memory((char *)os::get_memory_serialize_page(),
+                     os::vm_page_size(), MEM_PROT_RW);
   Thread::muxRelease(&SerializePageLock);
 }
 
--- a/hotspot/src/share/vm/runtime/os.hpp	Tue Dec 09 09:55:39 2008 -0500
+++ b/hotspot/src/share/vm/runtime/os.hpp	Wed Dec 10 15:14:29 2008 -0800
@@ -208,7 +208,7 @@
 
   enum ProtType { MEM_PROT_NONE, MEM_PROT_READ, MEM_PROT_RW, MEM_PROT_RWX };
   static bool   protect_memory(char* addr, size_t bytes, ProtType prot,
-                               bool is_committed = false);
+                               bool is_committed = true);
 
   static bool   guard_memory(char* addr, size_t bytes);
   static bool   unguard_memory(char* addr, size_t bytes);