VirtualBox

Changeset 42561 in vbox for trunk/src/VBox/Devices/PC


Ignore:
Timestamp:
Aug 2, 2012 10:34:05 PM (13 years ago)
Author:
vboxsync
Message:

HPET: Use 64-bit arithmetic to avoid rollover/overflow issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevHPET.cpp

    r42555 r42561  
    266266}
    267267
    268 DECLINLINE(uint32_t) hpetTimeAfter32(uint64_t a, uint64_t b)
    269 {
    270     return ((int32_t)(b) - (int32_t)(a) <= 0);
    271 }
    272 
    273 DECLINLINE(uint32_t) hpetTimeAfter64(uint64_t a, uint64_t b)
    274 {
    275     return ((int64_t)(b) - (int64_t)(a) <= 0);
    276 }
    277 
    278268DECLINLINE(uint64_t) hpetTicksToNs(HpetState *pThis, uint64_t value)
    279269{
     
    347337static void hpetAdjustComparator(HpetTimer *pHpetTimer, uint64_t u64Now)
    348338{
    349   uint64_t u64Period = pHpetTimer->u64Period;
    350   if (   (pHpetTimer->u64Config & HPET_TN_PERIODIC)
    351       && u64Period != 0)
    352   {
    353       /* While loop is suboptimal */
    354       if (hpet32bitTimer(pHpetTimer))
    355       {
    356           while (hpetTimeAfter32(u64Now, pHpetTimer->u64Cmp))
    357               pHpetTimer->u64Cmp = (uint32_t)(pHpetTimer->u64Cmp + u64Period);
    358       }
    359       else
    360       {
    361           while (hpetTimeAfter64(u64Now, pHpetTimer->u64Cmp))
    362               pHpetTimer->u64Cmp += u64Period;
    363       }
    364   }
     339    uint64_t    u64Period = pHpetTimer->u64Period;
     340
     341    if ((pHpetTimer->u64Config & HPET_TN_PERIODIC) && u64Period)
     342    {
     343          uint64_t  cPeriods = (u64Now - pHpetTimer->u64Cmp) / u64Period;
     344
     345          pHpetTimer->u64Cmp += (cPeriods + 1) * u64Period;
     346    }
    365347}
    366348
     
    571553
    572554            if (pHpetTimer->u64Config & HPET_TN_PERIODIC)
    573             {
    574                 u32NewValue &= hpetInvalidValue(pHpetTimer) >> 1; /** @todo check this in the docs and add a not why? */
    575555                pHpetTimer->u64Period = RT_MAKE_U64(u32NewValue, RT_HI_U32(pHpetTimer->u64Period));
    576             }
    577556            pHpetTimer->u64Cmp     = RT_MAKE_U64(u32NewValue, RT_HI_U32(pHpetTimer->u64Cmp));
    578557            pHpetTimer->u64Config &= ~HPET_TN_SETVAL;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette