6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE

Wed, 10 Dec 2008 15:14:29 -0800

author
coleenp
date
Wed, 10 Dec 2008 15:14:29 -0800
changeset 912
24fda36852ce
parent 908
3ad2b8576c4a
child 913
a7fac4381b50

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

src/os/linux/vm/os_linux.cpp file | annotate | diff | comparison | revisions
src/os/solaris/vm/os_solaris.cpp file | annotate | diff | comparison | revisions
src/os/windows/vm/os_windows.cpp file | annotate | diff | comparison | revisions
src/os_cpu/linux_x86/vm/os_linux_x86.cpp file | annotate | diff | comparison | revisions
src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp file | annotate | diff | comparison | revisions
src/share/vm/prims/jni.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/os.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/os.hpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/os/linux/vm/os_linux.cpp	Tue Dec 09 09:55:39 2008 -0500
     1.2 +++ b/src/os/linux/vm/os_linux.cpp	Wed Dec 10 15:14:29 2008 -0800
     1.3 @@ -2500,7 +2500,7 @@
     1.4  }
     1.5  
     1.6  bool os::unguard_memory(char* addr, size_t size) {
     1.7 -  return linux_mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC);
     1.8 +  return linux_mprotect(addr, size, PROT_READ|PROT_WRITE);
     1.9  }
    1.10  
    1.11  // Large page support
     2.1 --- a/src/os/solaris/vm/os_solaris.cpp	Tue Dec 09 09:55:39 2008 -0500
     2.2 +++ b/src/os/solaris/vm/os_solaris.cpp	Wed Dec 10 15:14:29 2008 -0800
     2.3 @@ -3026,6 +3026,8 @@
     2.4  
     2.5  // Protect memory (Used to pass readonly pages through
     2.6  // JNI GetArray<type>Elements with empty arrays.)
     2.7 +// Also, used for serialization page and for compressed oops null pointer
     2.8 +// checking.
     2.9  bool os::protect_memory(char* addr, size_t bytes, ProtType prot,
    2.10                          bool is_committed) {
    2.11    unsigned int p = 0;
    2.12 @@ -3049,7 +3051,7 @@
    2.13  }
    2.14  
    2.15  bool os::unguard_memory(char* addr, size_t bytes) {
    2.16 -  return solaris_mprotect(addr, bytes, PROT_READ|PROT_WRITE|PROT_EXEC);
    2.17 +  return solaris_mprotect(addr, bytes, PROT_READ|PROT_WRITE);
    2.18  }
    2.19  
    2.20  // Large page support
     3.1 --- a/src/os/windows/vm/os_windows.cpp	Tue Dec 09 09:55:39 2008 -0500
     3.2 +++ b/src/os/windows/vm/os_windows.cpp	Wed Dec 10 15:14:29 2008 -0800
     3.3 @@ -2020,10 +2020,11 @@
     3.4          if (UnguardOnExecutionViolation > 0 && addr != last_addr &&
     3.5              (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
     3.6  
     3.7 -          // Unguard and retry
     3.8 +          // Set memory to RWX and retry
     3.9            address page_start =
    3.10              (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
    3.11 -          bool res = os::unguard_memory((char*) page_start, page_size);
    3.12 +          bool res = os::protect_memory((char*) page_start, page_size,
    3.13 +                                        os::MEM_PROT_RWX);
    3.14  
    3.15            if (PrintMiscellaneous && Verbose) {
    3.16              char buf[256];
    3.17 @@ -2755,12 +2756,12 @@
    3.18  
    3.19  bool os::guard_memory(char* addr, size_t bytes) {
    3.20    DWORD old_status;
    3.21 -  return VirtualProtect(addr, bytes, PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_status) != 0;
    3.22 +  return VirtualProtect(addr, bytes, PAGE_READWRITE | PAGE_GUARD, &old_status) != 0;
    3.23  }
    3.24  
    3.25  bool os::unguard_memory(char* addr, size_t bytes) {
    3.26    DWORD old_status;
    3.27 -  return VirtualProtect(addr, bytes, PAGE_EXECUTE_READWRITE, &old_status) != 0;
    3.28 +  return VirtualProtect(addr, bytes, PAGE_READWRITE, &old_status) != 0;
    3.29  }
    3.30  
    3.31  void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) { }
     4.1 --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Tue Dec 09 09:55:39 2008 -0500
     4.2 +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Wed Dec 10 15:14:29 2008 -0800
     4.3 @@ -422,10 +422,11 @@
     4.4        if (addr != last_addr &&
     4.5            (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
     4.6  
     4.7 -        // Unguard and retry
     4.8 +        // Set memory to RWX and retry
     4.9          address page_start =
    4.10            (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
    4.11 -        bool res = os::unguard_memory((char*) page_start, page_size);
    4.12 +        bool res = os::protect_memory((char*) page_start, page_size,
    4.13 +                                      os::MEM_PROT_RWX);
    4.14  
    4.15          if (PrintMiscellaneous && Verbose) {
    4.16            char buf[256];
     5.1 --- a/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Tue Dec 09 09:55:39 2008 -0500
     5.2 +++ b/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Wed Dec 10 15:14:29 2008 -0800
     5.3 @@ -576,10 +576,11 @@
     5.4        if (addr != last_addr &&
     5.5            (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
     5.6  
     5.7 -        // Unguard and retry
     5.8 +        // Make memory rwx and retry
     5.9          address page_start =
    5.10            (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
    5.11 -        bool res = os::unguard_memory((char*) page_start, page_size);
    5.12 +        bool res = os::protect_memory((char*) page_start, page_size,
    5.13 +                                      os::MEM_PROT_RWX);
    5.14  
    5.15          if (PrintMiscellaneous && Verbose) {
    5.16            char buf[256];
     6.1 --- a/src/share/vm/prims/jni.cpp	Tue Dec 09 09:55:39 2008 -0500
     6.2 +++ b/src/share/vm/prims/jni.cpp	Wed Dec 10 15:14:29 2008 -0800
     6.3 @@ -2173,7 +2173,8 @@
     6.4      size_t size = os::vm_allocation_granularity();
     6.5      bad_address = os::reserve_memory(size);
     6.6      if (bad_address != NULL) {
     6.7 -      os::protect_memory(bad_address, size, os::MEM_PROT_READ);
     6.8 +      os::protect_memory(bad_address, size, os::MEM_PROT_READ,
     6.9 +                         /*is_committed*/false);
    6.10      }
    6.11    }
    6.12    return bad_address;
     7.1 --- a/src/share/vm/runtime/os.cpp	Tue Dec 09 09:55:39 2008 -0500
     7.2 +++ b/src/share/vm/runtime/os.cpp	Wed Dec 10 15:14:29 2008 -0800
     7.3 @@ -932,8 +932,9 @@
     7.4    // the mutator thread if such case is encountered. See bug 6546278 for details.
     7.5    Thread::muxAcquire(&SerializePageLock, "serialize_thread_states");
     7.6    os::protect_memory((char *)os::get_memory_serialize_page(),
     7.7 -                     os::vm_page_size(), MEM_PROT_READ, /*is_committed*/true );
     7.8 -  os::unguard_memory((char *)os::get_memory_serialize_page(), os::vm_page_size());
     7.9 +                     os::vm_page_size(), MEM_PROT_READ);
    7.10 +  os::protect_memory((char *)os::get_memory_serialize_page(),
    7.11 +                     os::vm_page_size(), MEM_PROT_RW);
    7.12    Thread::muxRelease(&SerializePageLock);
    7.13  }
    7.14  
     8.1 --- a/src/share/vm/runtime/os.hpp	Tue Dec 09 09:55:39 2008 -0500
     8.2 +++ b/src/share/vm/runtime/os.hpp	Wed Dec 10 15:14:29 2008 -0800
     8.3 @@ -208,7 +208,7 @@
     8.4  
     8.5    enum ProtType { MEM_PROT_NONE, MEM_PROT_READ, MEM_PROT_RW, MEM_PROT_RWX };
     8.6    static bool   protect_memory(char* addr, size_t bytes, ProtType prot,
     8.7 -                               bool is_committed = false);
     8.8 +                               bool is_committed = true);
     8.9  
    8.10    static bool   guard_memory(char* addr, size_t bytes);
    8.11    static bool   unguard_memory(char* addr, size_t bytes);

mercurial