2786 2787 bool os::commit_memory(char* addr, size_t size, size_t alignment_hint, 2788 bool exec) { 2789 return commit_memory(addr, size, exec); 2790 } 2791 2792 bool os::uncommit_memory(char* addr, size_t bytes) { 2793 if (bytes == 0) { 2794 // Don't bother the OS with noops. 2795 return true; 2796 } 2797 assert((size_t) addr % os::vm_page_size() == 0, "uncommit on page boundaries"); 2798 assert(bytes % os::vm_page_size() == 0, "uncommit in page-sized chunks"); 2799 return VirtualFree(addr, bytes, MEM_DECOMMIT) != 0; 2800 } 2801 2802 bool os::release_memory(char* addr, size_t bytes) { 2803 return VirtualFree(addr, 0, MEM_RELEASE) != 0; 2804 } 2805 2806 // Set protections specified 2807 bool os::protect_memory(char* addr, size_t bytes, ProtType prot, 2808 bool is_committed) { 2809 unsigned int p = 0; 2810 switch (prot) { 2811 case MEM_PROT_NONE: p = PAGE_NOACCESS; break; 2812 case MEM_PROT_READ: p = PAGE_READONLY; break; 2813 case MEM_PROT_RW: p = PAGE_READWRITE; break; 2814 case MEM_PROT_RWX: p = PAGE_EXECUTE_READWRITE; break; 2815 default: 2816 ShouldNotReachHere(); 2817 } 2818 2819 DWORD old_status; 2820 2821 // Strange enough, but on Win32 one can change protection only for committed 2822 // memory, not a big deal anyway, as bytes less or equal than 64K 2823 if (!is_committed && !commit_memory(addr, bytes, prot == MEM_PROT_RWX)) { 2824 fatal("cannot commit protection page"); 2825 } | 2786 2787 bool os::commit_memory(char* addr, size_t size, size_t alignment_hint, 2788 bool exec) { 2789 return commit_memory(addr, size, exec); 2790 } 2791 2792 bool os::uncommit_memory(char* addr, size_t bytes) { 2793 if (bytes == 0) { 2794 // Don't bother the OS with noops. 2795 return true; 2796 } 2797 assert((size_t) addr % os::vm_page_size() == 0, "uncommit on page boundaries"); 2798 assert(bytes % os::vm_page_size() == 0, "uncommit in page-sized chunks"); 2799 return VirtualFree(addr, bytes, MEM_DECOMMIT) != 0; 2800 } 2801 2802 bool os::release_memory(char* addr, size_t bytes) { 2803 return VirtualFree(addr, 0, MEM_RELEASE) != 0; 2804 } 2805 2806 bool os::create_stack_guard_pages(char* addr, size_t size) { 2807 return os::commit_memory(addr, size); 2808 } 2809 2810 bool os::remove_stack_guard_pages(char* addr, size_t size) { 2811 return os::uncommit_memory(addr, size); 2812 } 2813 2814 // Set protections specified 2815 bool os::protect_memory(char* addr, size_t bytes, ProtType prot, 2816 bool is_committed) { 2817 unsigned int p = 0; 2818 switch (prot) { 2819 case MEM_PROT_NONE: p = PAGE_NOACCESS; break; 2820 case MEM_PROT_READ: p = PAGE_READONLY; break; 2821 case MEM_PROT_RW: p = PAGE_READWRITE; break; 2822 case MEM_PROT_RWX: p = PAGE_EXECUTE_READWRITE; break; 2823 default: 2824 ShouldNotReachHere(); 2825 } 2826 2827 DWORD old_status; 2828 2829 // Strange enough, but on Win32 one can change protection only for committed 2830 // memory, not a big deal anyway, as bytes less or equal than 64K 2831 if (!is_committed && !commit_memory(addr, bytes, prot == MEM_PROT_RWX)) { 2832 fatal("cannot commit protection page"); 2833 } |