VirtualBox

Changeset 96476 in vbox for trunk/src/VBox/Runtime/r3/win


Ignore:
Timestamp:
Aug 25, 2022 2:46:22 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
153324
Message:

IPRT: Resolve IsDebuggerPresent and GetSystemTimeAsFileTime dynamically as they are not present on windows version before NT4. bugref:10261

Location:
trunk/src/VBox/Runtime/r3/win
Files:
4 edited

Legend:

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

    r96475 r96476  
    9292DECL_HIDDEN_DATA(decltype(GetHandleInformation) *)              g_pfnGetHandleInformation = NULL;
    9393DECL_HIDDEN_DATA(decltype(SetHandleInformation) *)              g_pfnSetHandleInformation = NULL;
     94DECL_HIDDEN_DATA(decltype(IsDebuggerPresent) *)                 g_pfnIsDebuggerPresent = NULL;
     95DECL_HIDDEN_DATA(decltype(GetSystemTimeAsFileTime) *)           g_pfnGetSystemTimeAsFileTime = NULL;
    9496
    9597/** The native ntdll.dll handle. */
     
    566568        g_pfnGetSystemWindowsDirectoryW  = (PFNGETWINSYSDIR)GetProcAddress(g_hModKernel32, "GetWindowsDirectoryW");
    567569    g_pfnSystemTimeToTzSpecificLocalTime = (decltype(SystemTimeToTzSpecificLocalTime) *)GetProcAddress(g_hModKernel32, "SystemTimeToTzSpecificLocalTime");
    568     g_pfnCreateWaitableTimerExW     = (PFNCREATEWAITABLETIMEREX)        GetProcAddress(g_hModKernel32, "CreateWaitableTimerExW");
    569     g_pfnGetHandleInformation       = (decltype(GetHandleInformation) *)GetProcAddress(g_hModKernel32, "GetHandleInformation");
    570     g_pfnSetHandleInformation       = (decltype(SetHandleInformation) *)GetProcAddress(g_hModKernel32, "SetHandleInformation");
    571     Assert(g_pfnSetHandleInformation || g_enmWinVer < kRTWinOSType_NT351);
    572     Assert(g_pfnGetHandleInformation || g_enmWinVer < kRTWinOSType_NT351);
     570    g_pfnCreateWaitableTimerExW     = (PFNCREATEWAITABLETIMEREX)           GetProcAddress(g_hModKernel32, "CreateWaitableTimerExW");
     571    g_pfnGetHandleInformation       = (decltype(GetHandleInformation) *)   GetProcAddress(g_hModKernel32, "GetHandleInformation");
     572    g_pfnSetHandleInformation       = (decltype(SetHandleInformation) *)   GetProcAddress(g_hModKernel32, "SetHandleInformation");
     573    g_pfnIsDebuggerPresent          = (decltype(IsDebuggerPresent) *)      GetProcAddress(g_hModKernel32, "IsDebuggerPresent");
     574    g_pfnGetSystemTimeAsFileTime    = (decltype(GetSystemTimeAsFileTime) *)GetProcAddress(g_hModKernel32, "GetSystemTimeAsFileTime");
     575    Assert(g_pfnSetHandleInformation    || g_enmWinVer < kRTWinOSType_NT351);
     576    Assert(g_pfnGetHandleInformation    || g_enmWinVer < kRTWinOSType_NT351);
     577    Assert(g_pfnIsDebuggerPresent       || g_enmWinVer < kRTWinOSType_NT4);
     578    Assert(g_pfnGetSystemTimeAsFileTime || g_enmWinVer < kRTWinOSType_NT4);
    573579
    574580    /*
  • trunk/src/VBox/Runtime/r3/win/internal-r3-win.h

    r96475 r96476  
    116116extern DECL_HIDDEN_DATA(HMODULE)                        g_hModKernel32;
    117117typedef UINT (WINAPI *PFNGETWINSYSDIR)(LPWSTR,UINT);
    118 extern DECL_HIDDEN_DATA(PFNGETWINSYSDIR)                g_pfnGetSystemWindowsDirectoryW;
     118extern DECL_HIDDEN_DATA(PFNGETWINSYSDIR)                                g_pfnGetSystemWindowsDirectoryW;
    119119extern DECL_HIDDEN_DATA(decltype(SystemTimeToTzSpecificLocalTime) *)    g_pfnSystemTimeToTzSpecificLocalTime;
    120120typedef HANDLE (WINAPI *PFNCREATEWAITABLETIMEREX)(LPSECURITY_ATTRIBUTES, LPCWSTR, DWORD, DWORD);
    121 extern DECL_HIDDEN_DATA(PFNCREATEWAITABLETIMEREX)       g_pfnCreateWaitableTimerExW;
     121extern DECL_HIDDEN_DATA(PFNCREATEWAITABLETIMEREX)                       g_pfnCreateWaitableTimerExW;
    122122extern DECL_HIDDEN_DATA(decltype(GetHandleInformation) *)               g_pfnGetHandleInformation;
    123123extern DECL_HIDDEN_DATA(decltype(SetHandleInformation) *)               g_pfnSetHandleInformation;
     124extern DECL_HIDDEN_DATA(decltype(IsDebuggerPresent) *)                  g_pfnIsDebuggerPresent;
     125extern DECL_HIDDEN_DATA(decltype(GetSystemTimeAsFileTime) *)            g_pfnGetSystemTimeAsFileTime;
    124126typedef UINT (WINAPI *PFNGETWINSYSDIR)(LPWSTR,UINT);
    125 extern DECL_HIDDEN_DATA(PFNGETWINSYSDIR)                g_pfnGetSystemWindowsDirectoryW;
     127extern DECL_HIDDEN_DATA(PFNGETWINSYSDIR)                                g_pfnGetSystemWindowsDirectoryW;
    126128
    127129
  • trunk/src/VBox/Runtime/r3/win/thread-win.cpp

    r96407 r96476  
    195195DECLINLINE(void) rtThreadWinSetThreadName(PRTTHREADINT pThread, DWORD idThread)
    196196{
    197     if (IsDebuggerPresent())
     197    if (g_pfnIsDebuggerPresent && g_pfnIsDebuggerPresent())
    198198        rtThreadWinTellDebuggerThreadName(idThread, &pThread->szName[0]);
    199199
  • trunk/src/VBox/Runtime/r3/win/time-win.cpp

    r96407 r96476  
    178178    uint64_t u64;
    179179    AssertCompile(sizeof(u64) == sizeof(FILETIME));
    180     GetSystemTimeAsFileTime((LPFILETIME)&u64);
     180    if (g_pfnGetSystemTimeAsFileTime)
     181        g_pfnGetSystemTimeAsFileTime((LPFILETIME)&u64);
     182    else
     183    {
     184        SYSTEMTIME SysTime = {0};
     185        GetSystemTime(&SysTime);
     186        BOOL fRet = SystemTimeToFileTime(&SysTime, (LPFILETIME)&u64);
     187        Assert(fRet); RT_NOREF(fRet);
     188    }
    181189    return RTTimeSpecSetNtTime(pTime, u64);
     190
    182191}
    183192
     
    185194RTDECL(PRTTIMESPEC) RTTimeLocalNow(PRTTIMESPEC pTime)
    186195{
    187     uint64_t u64;
    188     AssertCompile(sizeof(u64) == sizeof(FILETIME));
    189     GetSystemTimeAsFileTime((LPFILETIME)&u64);
    190196    uint64_t u64Local;
    191     if (!FileTimeToLocalFileTime((FILETIME const *)&u64, (LPFILETIME)&u64Local))
    192         u64Local = u64;
     197    if (g_pfnGetSystemTimeAsFileTime)
     198    {
     199        uint64_t u64;
     200        AssertCompile(sizeof(u64) == sizeof(FILETIME));
     201        g_pfnGetSystemTimeAsFileTime((LPFILETIME)&u64);
     202        if (!FileTimeToLocalFileTime((FILETIME const *)&u64, (LPFILETIME)&u64Local))
     203            u64Local = u64;
     204    }
     205    else
     206    {
     207        SYSTEMTIME SysTime = {0};
     208        GetLocalTime(&SysTime);
     209        BOOL fRet = SystemTimeToFileTime(&SysTime, (LPFILETIME)&u64Local);
     210        Assert(fRet); RT_NOREF(fRet);
     211    }
    193212    return RTTimeSpecSetNtTime(pTime, u64Local);
    194213}
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