On Thu, 2011-02-24 at 10:36 +1100, Bruce Evans wrote:
> 
> I would cast operand(s) in the expression as necessary to prevent overflow
> of subexpressions.  vm_pindex_t would work, but I prefer to use a type
> related to the subexpressions.  Not sure what that is.  Maybe just
> uintmax_t for safety (even that is not safe if the subexpressions have
> large values).  So:
> 
>      (uintmax_t)swap_bcount * SWAP_META_PAGES * n / mumble.

Following Alan's suggestion, I've attached an updated patch which uses a
cast to u_long and returns long.

-- 
Bruce Cran
Index: vm_map.h
===================================================================
--- vm_map.h	(revision 219050)
+++ vm_map.h	(working copy)
@@ -380,6 +380,6 @@
     int flags);
 int vm_map_wire(vm_map_t map, vm_offset_t start, vm_offset_t end,
     int flags);
-vm_offset_t vmspace_swap_count(struct vmspace *vmspace);
+long vmspace_swap_count(struct vmspace *vmspace);
 #endif				/* _KERNEL */
 #endif				/* _VM_MAP_ */
Index: swap_pager.c
===================================================================
--- swap_pager.c	(revision 219050)
+++ swap_pager.c	(working copy)
@@ -2420,13 +2420,13 @@
  *	if the VM object has any swap use at all the associated map entries
  *	count for at least 1 swap page.
  */
-vm_offset_t
+long
 vmspace_swap_count(struct vmspace *vmspace)
 {
 	vm_map_t map;
 	vm_map_entry_t cur;
 	vm_object_t object;
-	vm_offset_t count, n;
+	long count, n;
 
 	map = &vmspace->vm_map;
 	count = 0;
@@ -2438,7 +2438,7 @@
 			if (object->type == OBJT_SWAP &&
 			    object->un_pager.swp.swp_bcount != 0) {
 				n = (cur->end - cur->start) / PAGE_SIZE;
-				count += object->un_pager.swp.swp_bcount *
+				count += (u_long)object->un_pager.swp.swp_bcount *
 				    SWAP_META_PAGES * n / object->size + 1;
 			}
 			VM_OBJECT_UNLOCK(object);
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to