VirtualBox

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


Ignore:
Timestamp:
Oct 6, 2022 9:57:05 AM (2 years ago)
Author:
vboxsync
Message:

DevHPET: More fixes and optimizations. FS_PER_DAY overflowed after r153962, missing input check before calilng hpetTicksToNs in info handler. bugref:10301

File:
1 edited

Legend:

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

    r97027 r97028  
    101101#define FS_PER_NS                   1000000
    102102
    103 /**
    104  * Femtoseconds in a day. Still fits within uint64_t.
    105  */
    106 #define FS_PER_DAY                  (1000000000ULL * 60 * 60 * 24 * FS_PER_NS)
    107 
    108 /**
    109  * Number of HPET ticks in 100 years, ICH9 frequency.
    110  */
    111 #define HPET_TICKS_IN_100YR_ICH9    (FS_PER_DAY / HPET_CLK_PERIOD_ICH9 * 365 * 100)
    112 
    113 /**
    114  * Number of HPET ticks in 100 years, made-up PIIX frequency.
    115  */
    116 #define HPET_TICKS_IN_100YR_PIIX    (FS_PER_DAY / HPET_CLK_PERIOD_PIIX * 365 * 100)
     103/** Number of HPET ticks per second (Hz), ICH9 frequency.
     104 * Value: 14318179 */
     105#define HPET_TICKS_PER_SEC_ICH9     ((RT_NS_1SEC * FS_PER_NS) / HPET_CLK_PERIOD_ICH9)
     106
     107/** Number of HPET ticks per second (Hz), made-up PIIX frequency.
     108 * Value: 100000000   */
     109#define HPET_TICKS_PER_SEC_PIIX     ((RT_NS_1SEC * FS_PER_NS) / HPET_CLK_PERIOD_PIIX)
     110
     111/** Number of HPET ticks in 100 years, ICH9 frequency.
     112 * Value: 45153809294400000 (0x00A06B26'7B3F9A00) */
     113#define HPET_TICKS_IN_100YR_ICH9    (HPET_TICKS_PER_SEC_ICH9 * RT_SEC_1DAY_64 * 365 * 100)
     114
     115/**  Number of HPET ticks in 100 years, made-up PIIX frequency.
     116 * Value: 315360000000000000 (0x0460623F'C85E0000) */
     117#define HPET_TICKS_IN_100YR_PIIX    (HPET_TICKS_PER_SEC_PIIX * RT_SEC_1DAY_64 * 365 * 100)
    117118
    118119/** @name Interrupt type
     
    385386}
    386387
     388
     389/**
     390 * @note The caller shall do overflow checks! See @bugref{10301}.
     391 */
    387392DECLINLINE(uint64_t) hpetTicksToNs(PHPET pThis, uint64_t value)
    388393{
     
    465470                                           uint64_t fConfig, uint64_t uPeriod)
    466471{
    467     if ((fConfig & HPET_TN_PERIODIC) && uPeriod && (uPeriod < UINT32_MAX))
     472    if (   (fConfig & HPET_TN_PERIODIC)
     473        && uPeriod > 0
     474        && uPeriod < (pThis->fIch9 ? HPET_TICKS_PER_SEC_ICH9 : HPET_TICKS_PER_SEC_PIIX) / 10 /* 100 ns */)
    468475    {
    469476        uint64_t const nsPeriod = hpetTicksToNs(pThis, uPeriod);
    470         if (nsPeriod < RT_NS_100MS)
    471             PDMDevHlpTimerSetFrequencyHint(pDevIns, pHpetTimer->hTimer, RT_NS_1SEC / (uint32_t)nsPeriod);
     477        PDMDevHlpTimerSetFrequencyHint(pDevIns, pHpetTimer->hTimer, RT_NS_1SEC / (uint32_t)nsPeriod);
    472478    }
    473479}
     
    14511457                        pThis->aTimers[i].u64Cmp,
    14521458                        pThis->aTimers[i].u64Period,
    1453                         hpetTicksToNs(pThis, pThis->aTimers[i].u64Period),
     1459                        pThis->aTimers[i].u64Period < (pThis->fIch9 ? HPET_TICKS_IN_100YR_ICH9 : HPET_TICKS_IN_100YR_PIIX)
     1460                        ? hpetTicksToNs(pThis, pThis->aTimers[i].u64Period) : UINT64_MAX,
    14541461                        pThis->aTimers[i].u64Config,
    14551462                        hpetR3TimerGetIrq(pThis, &pThis->aTimers[i], pThis->aTimers[i].u64Config),
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