Skip to content

Commit cf95509

Browse files
authored
[NTUSER] IntSetTimer(): Use timer IDs range [256,32767] as on Windows (reactos#7277)
Based on the Doug Lyons' test in reactos#7087, I found that my previous fix stopped working partially. Or rather, it would only work until the 32767 indexes were exhausted. It seems to me that the behavior of the bitfield has changed, because when I published the previous patch, it passed my tests. - Bit array generates free ID cyclically, in the previous code after 32767 indexes expired the same index was returned, because of this the previous fix would stop working after expiration, so change the logic of calculating the next index. - Change the index range to 256-32767 to match Windows, indexes 0-255 can theoretically be used as reserved for system purposes. Addendum to fd327db. CORE-9141
1 parent 551c741 commit cf95509

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

win32ss/user/ntuser/timer.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ static LIST_ENTRY TimersListHead;
1717
static LONG TimeLast = 0;
1818

1919
/* Windows 2000 has room for 32768 window-less timers */
20-
#define NUM_WINDOW_LESS_TIMERS 32768
20+
/* These values give timer IDs [256,32767], same as on Windows */
21+
#define MAX_WINDOW_LESS_TIMER_ID (32768 - 1)
22+
#define NUM_WINDOW_LESS_TIMERS (32768 - 256)
2123

2224
#define HINTINDEX_BEGIN_VALUE 0
2325

@@ -78,11 +80,12 @@ RemoveTimer(PTIMER pTmr)
7880
RemoveEntryList(&pTmr->ptmrList);
7981
if ((pTmr->pWnd == NULL) && (!(pTmr->flags & TMRF_SYSTEM))) // System timers are reusable.
8082
{
81-
UINT_PTR IDEvent;
83+
ULONG ulBitmapIndex;
8284

83-
IDEvent = NUM_WINDOW_LESS_TIMERS - pTmr->nID;
85+
ASSERT(pTmr->nID <= MAX_WINDOW_LESS_TIMER_ID);
86+
ulBitmapIndex = (ULONG)(MAX_WINDOW_LESS_TIMER_ID - pTmr->nID);
8487
IntLockWindowlessTimerBitmap();
85-
RtlClearBit(&WindowLessTimersBitMap, IDEvent);
88+
RtlClearBit(&WindowLessTimersBitMap, ulBitmapIndex);
8689
IntUnlockWindowlessTimerBitmap();
8790
}
8891
UserDereferenceObject(pTmr);
@@ -222,12 +225,8 @@ IntSetTimer( PWND Window,
222225
{
223226
IntLockWindowlessTimerBitmap();
224227

225-
ulBitmapIndex = RtlFindClearBitsAndSet(&WindowLessTimersBitMap, 1, HintIndex++);
226-
if (ulBitmapIndex == ULONG_MAX)
227-
{
228-
HintIndex = HINTINDEX_BEGIN_VALUE;
229-
ulBitmapIndex = RtlFindClearBitsAndSet(&WindowLessTimersBitMap, 1, HintIndex++);
230-
}
228+
ulBitmapIndex = RtlFindClearBitsAndSet(&WindowLessTimersBitMap, 1, HintIndex);
229+
HintIndex = (ulBitmapIndex + 1) % NUM_WINDOW_LESS_TIMERS;
231230
if (ulBitmapIndex == ULONG_MAX)
232231
{
233232
IntUnlockWindowlessTimerBitmap();
@@ -237,7 +236,7 @@ IntSetTimer( PWND Window,
237236
}
238237

239238
ASSERT(ulBitmapIndex < NUM_WINDOW_LESS_TIMERS);
240-
IDEvent = NUM_WINDOW_LESS_TIMERS - ulBitmapIndex;
239+
IDEvent = MAX_WINDOW_LESS_TIMER_ID - ulBitmapIndex;
241240
Ret = IDEvent;
242241

243242
IntUnlockWindowlessTimerBitmap();

0 commit comments

Comments
 (0)