VirtualBox

Changeset 6267 in vbox


Ignore:
Timestamp:
Jan 7, 2008 10:00:46 PM (17 years ago)
Author:
vboxsync
Message:

We have to use InterruptTime like we do for the GIP. (GetSystemTimeAsFileTime isn't monotonic either.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/time-win.cpp

    r5999 r6267  
    3030*******************************************************************************/
    3131#define LOG_GROUP RTLOGGROUP_TIME
    32 //#define USE_TICK_COUNT
    33 //#define USE_PERFORMANCE_COUNTER
    34 #define USE_FILE_TIME
    35 //#define USE_INTERRUPT_TIME
    36 #ifndef USE_INTERRUPT_TIME
    37 # include <Windows.h>
    38 #else
    39 # define _X86_
    40   extern "C" {
    41 # include <ntddk.h>
    42   }
    43 # undef PAGE_SIZE
    44 # undef PAGE_SHIFT
    45 #endif
     32#include <Windows.h>
    4633
    4734#include <iprt/time.h>
     
    5037#include "internal/time.h"
    5138
     39#define USE_TICK_COUNT
     40//#define USE_PERFORMANCE_COUNTER
     41#if 0//defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
     42# define USE_INTERRUPT_TIME
     43#else
     44//# define USE_FILE_TIME
     45#endif
     46
     47
     48#ifdef USE_INTERRUPT_TIME
     49
     50typedef struct _MY_KSYSTEM_TIME
     51{
     52    ULONG LowPart;
     53    LONG High1Time;
     54    LONG High2Time;
     55} MY_KSYSTEM_TIME;
     56
     57typedef struct _MY_KUSER_SHARED_DATA
     58{
     59    ULONG TickCountLowDeprecated;
     60    ULONG TickCountMultiplier;
     61    volatile MY_KSYSTEM_TIME InterruptTime;
     62    /* The rest is not relevant. */
     63} MY_KUSER_SHARED_DATA, *PMY_KUSER_SHARED_DATA;
     64
     65#endif /* USE_INTERRUPT_TIME */
     66
    5267
    5368DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)
    5469{
    5570#if defined USE_TICK_COUNT
     71    /*
     72     * This would work if it didn't flip over every 49 (or so) days.
     73     */
    5674    return (uint64_t)GetTickCount() * (uint64_t)1000000;
    5775
    5876#elif defined USE_PERFORMANCE_COUNTER
     77    /*
     78     * Slow and no derived from InterruptTime.
     79     */
    5980    static LARGE_INTEGER    llFreq;
    6081    static unsigned         uMult;
     
    6485            return (uint64_t)GetTickCount() * (uint64_t)1000000;
    6586        llFreq.QuadPart /=    1000;
    66         uMult            = 1000000;     /* no math genious, but this seemed to help avoiding floating point. */
     87        uMult            = 1000000;     /* no math genius, but this seemed to help avoiding floating point. */
    6788    }
    6889
     
    7495
    7596#elif defined USE_FILE_TIME
     97    /*
     98     * This is SystemTime not InterruptTime.
     99     */
    76100    uint64_t u64; /* manual say larger integer, should be safe to assume it's the same. */
    77101    GetSystemTimeAsFileTime((LPFILETIME)&u64);
     
    79103
    80104#elif defined USE_INTERRUPT_TIME
    81 
    82     /* HACK! HACK! HACK! HACK! HACK! HACK! */
    83     /* HACK! HACK! HACK! HACK! HACK! HACK! */
    84     /* HACK! HACK! HACK! HACK! HACK! HACK! */
    85 # error "don't use this in production"
    86 
    87     static const KUSER_SHARED_DATA *s_pUserSharedData = NULL;
     105    /*
     106     * This is exactly what we want, but we have to obtain it by non-official
     107     * means.
     108     */
     109    static MY_KUSER_SHARED_DATA *s_pUserSharedData = NULL;
    88110    if (!s_pUserSharedData)
    89111    {
    90         /** @todo clever detection algorithm.
    91          * The com debugger class exports this too, windbg knows it too... */
    92         s_pUserSharedData = (const KUSER_SHARED_DATA *)0x7ffe0000;
     112        /** @todo find official way of getting this or some more clever
     113         * detection algorithm if necessary. The com debugger class
     114         * exports this too, windbg knows it too... */
     115        s_pUserSharedData = (MY_ KUSER_SHARED_DATA *)(uintptr_t)0x7ffe0000;
    93116    }
    94117
     
    98121    {
    99122        Time.HighPart = s_pUserSharedData->InterruptTime.High1Time;
    100         Time.LowPart = s_pUserSharedData->InterruptTime.LowPart;
     123        Time.LowPart  = s_pUserSharedData->InterruptTime.LowPart;
    101124    } while (s_pUserSharedData->InterruptTime.High2Time != Time.HighPart);
    102125
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