kernel - Fix sysclock_t comparison in usched code
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 13 Oct 2012 17:11:43 +0000 (10:11 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sat, 13 Oct 2012 17:11:43 +0000 (10:11 -0700)
* Fix a sysclock_t comparison that was attempting to detect an overflow
  by checking if an unsigned field was negative.  The field has
  to be cast to signed for the test to work as expected.

Reported-by: enjolras
sys/kern/usched_bsd4.c
sys/kern/usched_dfly.c
sys/sys/systimer.h

index 37b2c01..1dc67e6 100644 (file)
@@ -1024,7 +1024,7 @@ bsd4_recalculate_estcpu(struct lwp *lp)
                 */
                ttlticks = (cpbase - lp->lwp_cpbase) /
                           gd->gd_schedclock.periodic;
-               if (ttlticks < 0) {
+               if ((ssysclock_t)ttlticks < 0) {
                        ttlticks = 0;
                        lp->lwp_cpbase = cpbase;
                }
index 96b5ccf..4fbe153 100644 (file)
@@ -928,7 +928,7 @@ dfly_recalculate_estcpu(struct lwp *lp)
                 */
                ttlticks = (cpbase - lp->lwp_cpbase) /
                           gd->gd_schedclock.periodic;
-               if (ttlticks < 0) {
+               if ((ssysclock_t)ttlticks < 0) {
                        ttlticks = 0;
                        lp->lwp_cpbase = cpbase;
                }
index 9c3bc16..eb6e5c5 100644 (file)
@@ -57,6 +57,7 @@ typedef       __boolean_t     boolean_t;
 struct intrframe;
 
 typedef __uint32_t     sysclock_t;
+typedef int32_t                ssysclock_t;
 typedef TAILQ_HEAD(systimerq, systimer) *systimerq_t;
 typedef void (*systimer_func_t)(struct systimer *, int, struct intrframe *);