VirtualBox

Changeset 70335 in vbox


Ignore:
Timestamp:
Dec 24, 2017 2:37:32 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119935
Message:

iprt/time-r0drv-nt.cpp: Cleanups, making it compatible with NT 3.10.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/nt/time-r0drv-nt.cpp

    r69111 r70335  
    3535
    3636
     37/*
     38 * The KeQueryTickCount macro isn't compatible with NT 3.1, use the
     39 * exported KPI instead.
     40 */
     41#ifdef RT_ARCH_X86
     42# undef KeQueryTickCount
     43extern "C" NTKERNELAPI void NTAPI KeQueryTickCount(PLARGE_INTEGER);
     44#endif
     45
     46
    3747DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)
    3848{
     
    5767        InterruptTime.QuadPart = g_pfnrtKeQueryInterruptTimePrecise(&QpcTsIgnored);
    5868    }
    59 # ifdef RT_ARCH_AMD64
    60     else
    61         InterruptTime.QuadPart = KeQueryInterruptTime(); /* macro */
    62 # else
    63     else if (g_pfnrtKeQueryInterruptTime)
     69# ifdef RT_ARCH_X86
     70    else if (g_pfnrtKeQueryInterruptTime) /* W2K+ */
    6471        InterruptTime.QuadPart = g_pfnrtKeQueryInterruptTime();
    65     else
     72    else if (g_uRtNtVersion >= RTNT_MAKE_VERSION(3, 50))
    6673    {
    67         /* NT4 (no API) and pre-init fallback. */
     74        /* NT 3.50 and later, also pre-init: Use the user shared data. */
    6875        do
    6976        {
    7077            InterruptTime.HighPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.High1Time;
    71             InterruptTime.LowPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.LowPart;
     78            InterruptTime.LowPart  = ((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.LowPart;
    7279        } while (((KUSER_SHARED_DATA volatile *)SharedUserData)->InterruptTime.High2Time != InterruptTime.HighPart);
    7380    }
     81    else
     82    {
     83        /*
     84         * There is no KUSER_SHARED_DATA structure on NT 3.1, so we have no choice
     85         * but to use the tick count.  We must also avoid the KeQueryTickCount macro
     86         * in the WDK, since NT 3.1 does have the KeTickCount data export either (see above).
     87         */
     88        static ULONG volatile s_uTimeIncrement = 0;
     89        ULONG uTimeIncrement = s_uTimeIncrement;
     90        if (!uTimeIncrement)
     91        {
     92            uTimeIncrement = KeQueryTimeIncrement();
     93            Assert(uTimeIncrement != 0);
     94            Assert(uTimeIncrement * 100 / 100 == uTimeIncrement);
     95            uTimeIncrement *= 100;
     96            s_uTimeIncrement = uTimeIncrement;
     97        }
     98
     99        KeQueryTickCount(&InterruptTime);
     100        return (uint64_t)InterruptTime.QuadPart * uTimeIncrement;
     101    }
     102# else
     103    else
     104        InterruptTime.QuadPart = KeQueryInterruptTime(); /* Macro on AMD64. */
    74105# endif
    75106    return (uint64_t)InterruptTime.QuadPart * 100;
    76107#else
    77     /* Tick Count (NT4 SP1 has these APIs, haven't got SP0 to check). */
     108    /* Tick count.  Works all the way back to NT 3.1 with #undef above. */
    78109    LARGE_INTEGER Tick;
    79110    KeQueryTickCount(&Tick);
     
    112143    if (g_pfnrtKeQuerySystemTimePrecise)
    113144        g_pfnrtKeQuerySystemTimePrecise(&SystemTime);
    114 #ifdef RT_ARCH_AMD64
    115145    else
    116         KeQuerySystemTime(&SystemTime); /* macro */
    117 #else
    118     else if (g_pfnrtKeQuerySystemTime)
    119         g_pfnrtKeQuerySystemTime(&SystemTime);
    120     else
    121     {
    122         do
    123         {
    124             SystemTime.HighPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->SystemTime.High1Time;
    125             SystemTime.LowPart = ((KUSER_SHARED_DATA volatile *)SharedUserData)->SystemTime.LowPart;
    126         } while (((KUSER_SHARED_DATA volatile *)SharedUserData)->SystemTime.High2Time != SystemTime.HighPart);
    127     }
    128 #endif
     146        KeQuerySystemTime(&SystemTime); /* Macro on AMD64, export on X86.  */
    129147    return RTTimeSpecSetNtTime(pTime, SystemTime.QuadPart);
    130148}
Note: See TracChangeset for help on using the changeset viewer.

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