patch-2.2.12 linux/mm/mlock.c

Next file: linux/mm/mmap.c
Previous file: linux/kernel/fork.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.2.11/linux/mm/mlock.c linux/mm/mlock.c
@@ -129,7 +129,7 @@
 	struct vm_area_struct * vma, * next;
 	int error;
 
-	if (!capable(CAP_IPC_LOCK))
+	if (on && !capable(CAP_IPC_LOCK))
 		return -EPERM;
 	len = (len + ~PAGE_MASK) & PAGE_MASK;
 	end = start + len;
@@ -186,11 +186,13 @@
 	locked += current->mm->locked_vm;
 
 	lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
-	lock_limit >>= PAGE_SHIFT;
+	if (lock_limit < RLIM_INFINITY) {
+		lock_limit >>= PAGE_SHIFT;
 
-	/* check against resource limits */
-	if (locked > lock_limit)
-		goto out;
+		/* check against resource limits */
+		if (locked > lock_limit)
+			goto out;
+	}
 
 	/* we may lock at most half of physical memory... */
 	/* (this check is pretty bogus, but doesn't hurt) */
@@ -257,12 +259,14 @@
 	if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE)))
 		goto out;
 
+	ret = -ENOMEM;
 	lock_limit = current->rlim[RLIMIT_MEMLOCK].rlim_cur;
-	lock_limit >>= PAGE_SHIFT;
+	if (lock_limit < RLIM_INFINITY) {
+		lock_limit >>= PAGE_SHIFT;
 
-	ret = -ENOMEM;
-	if (current->mm->total_vm > lock_limit)
-		goto out;
+		if (current->mm->total_vm > lock_limit)
+			goto out;
+	}
 
 	/* we may lock at most half of physical memory... */
 	/* (this check is pretty bogus, but doesn't hurt) */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)