svn commit: r334621 - in head/sys: kern vm

Alan Cox alc at FreeBSD.org
Mon Jun 4 16:28:07 UTC 2018


Author: alc
Date: Mon Jun  4 16:28:06 2018
New Revision: 334621
URL: https://svnweb.freebsd.org/changeset/base/334621

Log:
  Use a single, consistent approach to returning success versus failure in
  vm_map_madvise().  Previously, vm_map_madvise() used a traditional Unix-
  style "return (0);" to indicate success in the common case, but Mach-
  style return values in the edge cases.  Since KERN_SUCCESS equals zero,
  the only problem with this inconsistency was stylistic.  vm_map_madvise()
  has exactly two callers in the entire source tree, and only one of them
  cares about the return value.  That caller, kern_madvise(), can be
  simplified if vm_map_madvise() consistently uses Unix-style return
  values.
  
  Since vm_map_madvise() uses the variable modify_map as a Boolean, make it
  one.
  
  Eliminate a redundant error check from kern_madvise().  Add a comment
  explaining where the check is performed.
  
  Explicitly note that exec_release_args_kva() doesn't care about
  vm_map_madvise()'s return value.  Since MADV_FREE is passed as the
  behavior, the return value will always be zero.
  
  Reviewed by:	kib, markj
  MFC after:	7 days

Modified:
  head/sys/kern/kern_exec.c
  head/sys/vm/vm_map.c
  head/sys/vm/vm_mmap.c

Modified: head/sys/kern/kern_exec.c
==============================================================================
--- head/sys/kern/kern_exec.c	Mon Jun  4 16:21:18 2018	(r334620)
+++ head/sys/kern/kern_exec.c	Mon Jun  4 16:28:06 2018	(r334621)
@@ -1380,7 +1380,7 @@ exec_release_args_kva(struct exec_args_kva *argkva, u_
 
 	base = argkva->addr;
 	if (argkva->gen != gen) {
-		vm_map_madvise(exec_map, base, base + exec_map_entry_size,
+		(void)vm_map_madvise(exec_map, base, base + exec_map_entry_size,
 		    MADV_FREE);
 		argkva->gen = gen;
 	}

Modified: head/sys/vm/vm_map.c
==============================================================================
--- head/sys/vm/vm_map.c	Mon Jun  4 16:21:18 2018	(r334620)
+++ head/sys/vm/vm_map.c	Mon Jun  4 16:28:06 2018	(r334621)
@@ -2215,7 +2215,7 @@ vm_map_madvise(
 	int behav)
 {
 	vm_map_entry_t current, entry;
-	int modify_map = 0;
+	bool modify_map;
 
 	/*
 	 * Some madvise calls directly modify the vm_map_entry, in which case
@@ -2232,19 +2232,20 @@ vm_map_madvise(
 	case MADV_NOCORE:
 	case MADV_CORE:
 		if (start == end)
-			return (KERN_SUCCESS);
-		modify_map = 1;
+			return (0);
+		modify_map = true;
 		vm_map_lock(map);
 		break;
 	case MADV_WILLNEED:
 	case MADV_DONTNEED:
 	case MADV_FREE:
 		if (start == end)
-			return (KERN_SUCCESS);
+			return (0);
+		modify_map = false;
 		vm_map_lock_read(map);
 		break;
 	default:
-		return (KERN_INVALID_ARGUMENT);
+		return (EINVAL);
 	}
 
 	/*

Modified: head/sys/vm/vm_mmap.c
==============================================================================
--- head/sys/vm/vm_mmap.c	Mon Jun  4 16:21:18 2018	(r334620)
+++ head/sys/vm/vm_mmap.c	Mon Jun  4 16:28:06 2018	(r334621)
@@ -683,11 +683,6 @@ kern_madvise(struct thread *td, uintptr_t addr0, size_
 	}
 
 	/*
-	 * Check for illegal behavior
-	 */
-	if (behav < 0 || behav > MADV_CORE)
-		return (EINVAL);
-	/*
 	 * Check for illegal addresses.  Watch out for address wrap... Note
 	 * that VM_*_ADDRESS are not constants due to casts (argh).
 	 */
@@ -705,9 +700,10 @@ kern_madvise(struct thread *td, uintptr_t addr0, size_
 	start = trunc_page(addr);
 	end = round_page(addr + len);
 
-	if (vm_map_madvise(map, start, end, behav))
-		return (EINVAL);
-	return (0);
+	/*
+	 * vm_map_madvise() checks for illegal values of behav.
+	 */
+	return (vm_map_madvise(map, start, end, behav));
 }
 
 #ifndef _SYS_SYSPROTO_H_


More information about the svn-src-head mailing list