changeset 3783:c865a2700370

6531693 timeout_common completely broken on 32-bit systems
author qiao
date Fri, 09 Mar 2007 07:19:31 -0800
parents d53b92e6d144
children 6185c931da0c
files usr/src/uts/common/os/callout.c
diffstat 1 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/uts/common/os/callout.c	Fri Mar 09 01:04:32 2007 -0800
+++ b/usr/src/uts/common/os/callout.c	Fri Mar 09 07:19:31 2007 -0800
@@ -173,9 +173,14 @@
 		delta = 1;
 	cp->c_runtime = runtime = lbolt + delta;
 
-	/* Calculate the future time in milli-second */
-	hresms = now.tv_sec * MILLISEC + now.tv_nsec / MICROSEC +
-	    TICK_TO_MSEC(delta);
+	/*
+	 * Calculate the future time in millisecond.
+	 * We must cast tv_sec and delta to 64-bit integers
+	 * to avoid integer overflow on 32-platforms.
+	 */
+	hresms = (int64_t)now.tv_sec * MILLISEC + now.tv_nsec / MICROSEC +
+	    TICK_TO_MSEC((int64_t)delta);
+
 	cp->c_hresms = hresms;
 
 	/*
@@ -349,8 +354,12 @@
 
 	gethrestime(&now);
 
-	/* Calculate the current time in milli-second */
-	hresms = now.tv_sec * MILLISEC + now.tv_nsec / MICROSEC;
+	/*
+	 * Calculate the future time in millisecond.
+	 * We must cast tv_sec to 64-bit integer
+	 * to avoid integer overflow on 32-platforms.
+	 */
+	hresms = (int64_t)now.tv_sec * MILLISEC + now.tv_nsec / MICROSEC;
 
 	cp = ct->ct_hresq;
 	while (cp != NULL && hresms >= cp->c_hresms) {
@@ -420,8 +429,12 @@
 
 	gethrestime(&now);
 
-	/* Calculate the current time in milli-second */
-	hresms = now.tv_sec * MILLISEC + now.tv_nsec / MICROSEC;
+	/*
+	 * Calculate the future time in millisecond.
+	 * We must cast tv_sec to 64-bit integer
+	 * to avoid integer overflow on 32-platforms.
+	 */
+	hresms = (int64_t)now.tv_sec * MILLISEC + now.tv_nsec / MICROSEC;
 
 	cp = ct->ct_hresq;
 	while (cp != NULL && hresms >= cp->c_hresms) {