svn commit: r314773 - head/sys/kern

Konstantin Belousov kib at FreeBSD.org
Mon Mar 6 14:09:56 UTC 2017


Author: kib
Date: Mon Mar  6 14:09:54 2017
New Revision: 314773
URL: https://svnweb.freebsd.org/changeset/base/314773

Log:
  Instead of direct use of vm_map_insert(), call vm_map_fixed(MAP_CHECK_EXCL).
  
  This KPI explicitely indicates the intent of creating the mapping at
  the fixed address, and incorporates the map locking into the callee.
  
  Suggested and reviewed by:	alc
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Modified:
  head/sys/kern/imgact_elf.c

Modified: head/sys/kern/imgact_elf.c
==============================================================================
--- head/sys/kern/imgact_elf.c	Mon Mar  6 12:22:05 2017	(r314772)
+++ head/sys/kern/imgact_elf.c	Mon Mar  6 14:09:54 2017	(r314773)
@@ -397,10 +397,8 @@ __elfN(map_partial)(vm_map_t map, vm_obj
 	/*
 	 * Create the page if it doesn't exist yet. Ignore errors.
 	 */
-	vm_map_lock(map);
-	vm_map_insert(map, NULL, 0, trunc_page(start), round_page(end),
-	    VM_PROT_ALL, VM_PROT_ALL, 0);
-	vm_map_unlock(map);
+	vm_map_fixed(map, NULL, 0, trunc_page(start), round_page(end) -
+	    trunc_page(start), VM_PROT_ALL, VM_PROT_ALL, MAP_CHECK_EXCL);
 
 	/*
 	 * Find the page from the underlying object.
@@ -451,10 +449,8 @@ __elfN(map_insert)(struct image_params *
 			 * The mapping is not page aligned. This means we have
 			 * to copy the data. Sigh.
 			 */
-			vm_map_lock(map);
-			rv = vm_map_insert(map, NULL, 0, start, end,
-			    prot | VM_PROT_WRITE, VM_PROT_ALL, 0);
-			vm_map_unlock(map);
+			rv = vm_map_fixed(map, NULL, 0, start, end - start,
+			    prot | VM_PROT_WRITE, VM_PROT_ALL, MAP_CHECK_EXCL);
 			if (rv != KERN_SUCCESS)
 				return (rv);
 			if (object == NULL)
@@ -477,10 +473,9 @@ __elfN(map_insert)(struct image_params *
 			rv = KERN_SUCCESS;
 		} else {
 			vm_object_reference(object);
-			vm_map_lock(map);
-			rv = vm_map_insert(map, object, offset, start, end,
-			    prot, VM_PROT_ALL, cow);
-			vm_map_unlock(map);
+			rv = vm_map_fixed(map, object, offset, start,
+			    end - start, prot, VM_PROT_ALL,
+			    cow | MAP_CHECK_EXCL);
 			if (rv != KERN_SUCCESS) {
 				locked = VOP_ISLOCKED(imgp->vp);
 				VOP_UNLOCK(imgp->vp, 0);


More information about the svn-src-head mailing list