From 30392143708689bd11c23f26010219185c61a4b8 Mon Sep 17 00:00:00 2001 From: qiao Date: Fri, 9 Mar 2007 07:19:31 -0800 Subject: 6531693 timeout_common completely broken on 32-bit systems --- usr/src/uts/common/os/callout.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/usr/src/uts/common/os/callout.c b/usr/src/uts/common/os/callout.c index 92b52e27af..e477155b76 100644 --- a/usr/src/uts/common/os/callout.c +++ b/usr/src/uts/common/os/callout.c @@ -173,9 +173,14 @@ timeout_common(void (*func)(void *), void *arg, clock_t delta, 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 @@ callout_execute(callout_table_t *ct) 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 @@ callout_schedule_1(callout_table_t *ct) 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) { -- cgit v1.2.3