From 5bfb723f07fde2caafa90cb40c102a4e36dfea9e Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Fri, 13 Apr 2012 19:35:02 +0100 Subject: timers: the rearm function should be able to handle delta = INT64_MAX Fix win32_rearm_timer and mm_rearm_timer: they should be able to handle INT64_MAX as a delta parameter without overflowing. Also, the next deadline in ms should be calculated rounding down rather than up (see unix_rearm_timer and dynticks_rearm_timer). Finally ChangeTimerQueueTimer takes an unsigned long and timeSetEvent takes an unsigned int as delta, so cast the ms delta to the appropriate unsigned integer. Signed-off-by: Stefano Stabellini Signed-off-by: Anthony Liguori --- qemu-timer.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 17915df22d..3cdb012bcf 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -696,13 +696,17 @@ static void mm_stop_timer(struct qemu_alarm_timer *t) static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta) { - int nearest_delta_ms = (delta + 999999) / 1000000; + int64_t nearest_delta_ms = delta / 1000000; if (nearest_delta_ms < 1) { nearest_delta_ms = 1; } + /* UINT_MAX can be 32 bit */ + if (nearest_delta_ms > UINT_MAX) { + nearest_delta_ms = UINT_MAX; + } timeKillEvent(mm_timer); - mm_timer = timeSetEvent(nearest_delta_ms, + mm_timer = timeSetEvent((unsigned int) nearest_delta_ms, mm_period, mm_alarm_handler, (DWORD_PTR)t, @@ -757,16 +761,20 @@ static void win32_rearm_timer(struct qemu_alarm_timer *t, int64_t nearest_delta_ns) { HANDLE hTimer = t->timer; - int nearest_delta_ms; + int64_t nearest_delta_ms; BOOLEAN success; - nearest_delta_ms = (nearest_delta_ns + 999999) / 1000000; + nearest_delta_ms = nearest_delta_ns / 1000000; if (nearest_delta_ms < 1) { nearest_delta_ms = 1; } + /* ULONG_MAX can be 32 bit */ + if (nearest_delta_ms > ULONG_MAX) { + nearest_delta_ms = ULONG_MAX; + } success = ChangeTimerQueueTimer(NULL, hTimer, - nearest_delta_ms, + (unsigned long) nearest_delta_ms, 3600000); if (!success) { -- cgit v1.2.1