Module Name:    src
Committed By:   dholland
Date:           Mon Jun 13 03:42:15 UTC 2011

Modified Files:
        src/bin/ps: print.c

Log Message:
When converting from pages to kilobytes, cast the return value of
getpagesize() to size_t. For some reason getpagesize() is defined to
return int, and several of the page counts we get come back from the
kernel as int32_t; in LP64 without the cast the byte count will be
computed in a 32-bit value and for large processes will overflow and
become negative... and then remain negative when divided by 1024 to
convert to kilobytes.

Fixes a problem I hit the other day where I saw negative RSS, which
turns out also to be PR 40642.

Note: other logic in here will break down when we first get >2TB
processes... and int32 page counts will break on >8TB processes. But
hopefully we won't see any of that for a few years yet.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/bin/ps/print.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/ps/print.c
diff -u src/bin/ps/print.c:1.117 src/bin/ps/print.c:1.118
--- src/bin/ps/print.c:1.117	Sat Jan 22 21:09:51 2011
+++ src/bin/ps/print.c	Mon Jun 13 03:42:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: print.c,v 1.117 2011/01/22 21:09:51 christos Exp $	*/
+/*	$NetBSD: print.c,v 1.118 2011/06/13 03:42:15 dholland Exp $	*/
 
 /*
  * Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #if 0
 static char sccsid[] = "@(#)print.c	8.6 (Berkeley) 4/16/94";
 #else
-__RCSID("$NetBSD: print.c,v 1.117 2011/01/22 21:09:51 christos Exp $");
+__RCSID("$NetBSD: print.c,v 1.118 2011/06/13 03:42:15 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -967,7 +967,7 @@
 	}
 }
 
-#define	pgtok(a)        (((a)*getpagesize())/1024)
+#define	pgtok(a)        (((a)*(size_t)getpagesize())/1024)
 
 void
 vsize(void *arg, VARENT *ve, int mode)

Reply via email to