From 447354e13ccb83e0baeaaf6158f52b9033fba117 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sat, 3 Dec 2011 23:03:15 +0000 Subject: [PATCH] * mmap.cc (mlock): Drop requesting SE_LOCK_MEMORY_PRIVILEGE. Drop outdated comment. Call NtLockVirtualMemory with LOCK_VM_IN_WSL flag. (munlock): Drop requesting SE_LOCK_MEMORY_PRIVILEGE. Call NtUnlockVirtualMemory with LOCK_VM_IN_WSL flag. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/mmap.cc | 18 ++---------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index a66c13a6c..99b56d0ad 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2011-12-03 Corinna Vinschen + + * mmap.cc (mlock): Drop requesting SE_LOCK_MEMORY_PRIVILEGE. Drop + outdated comment. Call NtLockVirtualMemory with LOCK_VM_IN_WSL flag. + (munlock): Drop requesting SE_LOCK_MEMORY_PRIVILEGE. Call + NtUnlockVirtualMemory with LOCK_VM_IN_WSL flag. + 2011-12-03 Christopher Faylor Throughout, remove extra space after function name from debugging diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index afbeb7a3a..97f0dad6f 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -1346,14 +1346,6 @@ mlock (const void *addr, size_t len) { int ret = -1; - /* Instead of using VirtualLock, which does not guarantee that the pages - aren't swapped out when the process is inactive, we're using - ZwLockVirtualMemory with the LOCK_VM_IN_RAM flag to do what mlock on - POSIX systems does. On NT, this requires SeLockMemoryPrivilege, - which is given only to SYSTEM by default. */ - - push_thread_privilege (SE_LOCK_MEMORY_PRIVILEGE, true); - /* Align address and length values to page size. */ size_t pagesize = getpagesize (); PVOID base = (PVOID) rounddown((uintptr_t) addr, pagesize); @@ -1362,7 +1354,7 @@ mlock (const void *addr, size_t len) do { status = NtLockVirtualMemory (NtCurrentProcess (), &base, &size, - LOCK_VM_IN_RAM); + LOCK_VM_IN_WSL); if (status == STATUS_WORKING_SET_QUOTA) { /* The working set is too small, try to increase it so that the @@ -1402,8 +1394,6 @@ mlock (const void *addr, size_t len) } while (status == STATUS_WORKING_SET_QUOTA); - pop_thread_privilege (); - return ret; } @@ -1412,21 +1402,17 @@ munlock (const void *addr, size_t len) { int ret = -1; - push_thread_privilege (SE_LOCK_MEMORY_PRIVILEGE, true); - /* Align address and length values to page size. */ size_t pagesize = getpagesize (); PVOID base = (PVOID) rounddown((uintptr_t) addr, pagesize); ULONG size = roundup2 (((uintptr_t) addr - (uintptr_t) base) + len, pagesize); NTSTATUS status = NtUnlockVirtualMemory (NtCurrentProcess (), &base, &size, - LOCK_VM_IN_RAM); + LOCK_VM_IN_WSL); if (!NT_SUCCESS (status)) __seterrno_from_nt_status (status); else ret = 0; - pop_thread_privilege (); - return ret; }