Skip to contentSkip to conversation

timers data structures wrap around fixes.

PATCH New Gilles Chanteperdrix 1 participant 1 message Jul 17, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 timers data structures wrap around fixes.

Hi,

here comes a patch which should make the data structures used to store timers objects safe with regard to tsc/jiffies wrap around.

Signature · 1 line
					    Gilles Chanteperdrix.
nucleus/timer.c +4 -2
Index: ksrc/nucleus/timer.c
===================================================================
@@ -212,7 +212,8 @@
 	while ((holder = xntimerq_head(timerq)) != NULL) {
 		timer = aplink2timer(holder);
 
-		if (xntimerh_date(&timer->aplink) - nklatency > now)
+		if ((xnsticks_t) (xntimerh_date(&timer->aplink) - now)
+		    > nklatency)
 			/* No need to continue in aperiodic mode since timeout
 			   dates are ordered by increasing values. */
 			break;
@@ -407,7 +408,8 @@
 	while ((holder = xntlist_head(timerq)) != NULL) {
 		timer = plink2timer(holder);
 
-		if (xntlholder_date(&timer->plink) > base->jiffies)
+		if ((xnsticks_t) (xntlholder_date(&timer->plink)
+				  - base->jiffies) > 0)
 			break;
 
 		xntimer_dequeue_periodic(timer);
nucleus/timer.h +4 -4
Index: include/nucleus/timer.h
===================================================================
@@ -86,7 +86,7 @@
 	   increased flexibility... */
 
 	for (p = q->head.last; p != &q->head; p = p->last)
-		if (holder->key > link2tlholder(p)->key ||
+		if ((xnsticks_t) (holder->key - link2tlholder(p)->key) > 0 ||
 		    (holder->key == link2tlholder(p)->key &&
 		     holder->prio <= link2tlholder(p)->prio))
 			break;
@@ -174,8 +174,8 @@
 		if ((xntlholder_date(candidate) >> q->date_shift) == q->next_shot)
 			return candidate;
 
-		if (!result
-		    || xntlholder_date(candidate) < xntlholder_date(result))
+		if (!result || (xnsticks_t) (xntlholder_date(candidate)
+					     - xntlholder_date(result)) < 0)
 			result = candidate;
 	}
 
@@ -191,7 +191,7 @@
 	unsigned long long shifted_date = xntlholder_date(h) >> q->date_shift;
 	unsigned bucket = ((unsigned) shifted_date) & XNTIMER_WHEELMASK;
 
-	if (shifted_date < q->next_shot)
+	if ((long long) (shifted_date - q->next_shot) < 0)
 		q->next_shot = shifted_date;
 	xntlist_insert(&q->bucket[bucket], h);
 }
nucleus/bheap.h +2 -2
Index: include/nucleus/bheap.h
===================================================================
@@ -43,8 +43,8 @@
 #define bheaph_key(holder)  ((holder)->key)
 #define bheaph_prio(holder) ((holder)->prio)
 #define bheaph_pos(holder)  ((holder)->pos)
-#define bheaph_lt(h1, h2)   ((h1)->key < (h2)->key ||     \
-                             ((h1)->key == (h2)->key &&   \
+#define bheaph_lt(h1, h2)   ((long long) ((h1)->key - (h2)->key) < 0 ||	\
+                             ((h1)->key == (h2)->key &&			\
                               (h1)->prio > (h2)->prio))
 
 typedef struct bheap {