VirtualBox

Changeset 70171 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 15, 2017 10:08:07 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119736
Message:

VBoxService: Working on removing TARGET_NT4 here too...

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService-win.cpp

    r69500 r70171  
    2020*   Header Files                                                                                                                 *
    2121*********************************************************************************************************************************/
     22#undef _WIN32_WINNT           /// REMOVE WHEN VBoxServiceNT IS GONE
     23#define _WIN32_WINNT 0x0501   /// REMOVE WHEN VBoxServiceNT IS GONE
    2224#include <iprt/assert.h>
    2325#include <iprt/err.h>
     26#include <iprt/ldr.h>
    2427#include <iprt/system.h> /* For querying OS version. */
    2528#include <VBox/VBoxGuestLib.h>
    26 #include "VBoxServiceInternal.h"
    27 
    28 #include <iprt/win/windows.h>
     29
     30#include <iprt/nt/nt-and-windows.h>
    2931#include <process.h>
    3032#include <aclapi.h>
     33#include <tlhelp32.h>
     34
     35#include "VBoxServiceInternal.h"
    3136
    3237
     
    5156};
    5257
     58/** @name APIs from ADVAPI32.DLL.
     59 * @{ */
     60decltype(RegisterServiceCtrlHandlerExA) *g_pfnRegisterServiceCtrlHandlerExA;    /**< W2K+ */
     61decltype(ChangeServiceConfig2A)         *g_pfnChangeServiceConfig2A;            /**< W2K+ */
     62/** @} */
     63
     64/** @name API from KERNEL32.DLL
     65 * @{ */
     66decltype(CreateToolhelp32Snapshot)      *g_pfnCreateToolhelp32Snapshot;         /**< W2K+, but Geoff says NT4. Hmm. */
     67decltype(Process32First)                *g_pfnProcess32First;                   /**< W2K+, but Geoff says NT4. Hmm. */
     68decltype(Process32Next)                 *g_pfnProcess32Next;                    /**< W2K+, but Geoff says NT4. Hmm. */
     69decltype(Module32First)                 *g_pfnModule32First;                    /**< W2K+, but Geoff says NT4. Hmm. */
     70decltype(Module32Next)                  *g_pfnModule32Next;                     /**< W2K+, but Geoff says NT4. Hmm. */
     71/** @} */
     72
     73/** @name API from NTDLL.DLL
     74 * @{ */
     75decltype(ZwQuerySystemInformation)      *g_pfnZwQuerySystemInformation;         /**< NT4 (where as NtQuerySystemInformation is W2K). */
     76/** @} */
     77
     78
     79/**
     80 * Resolve APIs not present on older windows versions.
     81 */
     82void VGSvcWinResolveApis(void)
     83{
     84    RTLDRMOD hLdrMod;
     85#define RESOLVE_SYMBOL(a_fn) do { RT_CONCAT(g_pfn, a_fn) = (decltype(a_fn) *)RTLdrGetFunction(hLdrMod, #a_fn); } while (0)
     86
     87    /* From ADVAPI32.DLL: */
     88    int rc = RTLdrLoadSystem("advapi32.dll", false /*fNoUnload*/, &hLdrMod);
     89    AssertRC(rc);
     90    if (RT_SUCCESS(rc))
     91    {
     92        RESOLVE_SYMBOL(RegisterServiceCtrlHandlerExA);
     93        RESOLVE_SYMBOL(ChangeServiceConfig2A);
     94        RTLdrClose(hLdrMod);
     95    }
     96
     97    /* From KERNEL32.DLL: */
     98    rc = RTLdrLoadSystem("kernel32.dll", false /*fNoUnload*/, &hLdrMod);
     99    AssertRC(rc);
     100    if (RT_SUCCESS(rc))
     101    {
     102        RESOLVE_SYMBOL(CreateToolhelp32Snapshot);
     103        RESOLVE_SYMBOL(Process32First);
     104        RESOLVE_SYMBOL(Process32Next);
     105        RESOLVE_SYMBOL(Module32First);
     106        RESOLVE_SYMBOL(Module32Next);
     107        RTLdrClose(hLdrMod);
     108    }
     109
     110    /* From NTDLL.DLL: */
     111    rc = RTLdrLoadSystem("ntdll.dll", false /*fNoUnload*/, &hLdrMod);
     112    AssertRC(rc);
     113    if (RT_SUCCESS(rc))
     114    {
     115        RESOLVE_SYMBOL(ZwQuerySystemInformation);
     116        RTLdrClose(hLdrMod);
     117    }
     118}
     119
    53120
    54121/**
     
    58125 */
    59126static DWORD vgsvcWinAddAceToObjectsSecurityDescriptor(LPTSTR pszObjName,
    60                                                              SE_OBJECT_TYPE ObjectType,
    61                                                              LPTSTR pszTrustee,
    62                                                              TRUSTEE_FORM TrusteeForm,
    63                                                              DWORD dwAccessRights,
    64                                                              ACCESS_MODE AccessMode,
    65                                                              DWORD dwInheritance)
    66 {
    67     DWORD dwRes = 0;
     127                                                       SE_OBJECT_TYPE ObjectType,
     128                                                       LPTSTR pszTrustee,
     129                                                       TRUSTEE_FORM TrusteeForm,
     130                                                       DWORD dwAccessRights,
     131                                                       ACCESS_MODE AccessMode,
     132                                                       DWORD dwInheritance)
     133{
    68134    PACL pOldDACL = NULL, pNewDACL = NULL;
    69135    PSECURITY_DESCRIPTOR pSD = NULL;
     
    74140
    75141    /* Get a pointer to the existing DACL. */
    76     dwRes = GetNamedSecurityInfo(pszObjName, ObjectType,
    77                                  DACL_SECURITY_INFORMATION,
    78                                  NULL, NULL, &pOldDACL, NULL, &pSD);
     142    DWORD dwRes = GetNamedSecurityInfo(pszObjName, ObjectType, DACL_SECURITY_INFORMATION, NULL, NULL, &pOldDACL, NULL, &pSD);
    79143    if (ERROR_SUCCESS != dwRes)
    80144    {
     
    103167
    104168    /* Attach the new ACL as the object's DACL. */
    105     dwRes = SetNamedSecurityInfo(pszObjName, ObjectType,
    106                                  DACL_SECURITY_INFORMATION,
    107                                  NULL, NULL, pNewDACL, NULL);
     169    dwRes = SetNamedSecurityInfo(pszObjName, ObjectType, DACL_SECURITY_INFORMATION, NULL, NULL, pNewDACL, NULL);
    108170    if (ERROR_SUCCESS != dwRes)
    109171    {
     
    142204    {
    143205        ss.dwControlsAccepted     = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
    144 #ifndef TARGET_NT4
    145         /* Don't use SERVICE_ACCEPT_SESSIONCHANGE on Windows 2000.
    146          * This makes SCM angry. */
     206
     207        /* Don't use SERVICE_ACCEPT_SESSIONCHANGE on Windows 2000 or earlier.  This makes SCM angry. */
    147208        char szOSVersion[32];
    148         int rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE,
    149                                      szOSVersion, sizeof(szOSVersion));
     209        int rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szOSVersion, sizeof(szOSVersion));
    150210        if (RT_SUCCESS(rc))
    151211        {
     
    155215        else
    156216            VGSvcError("Error determining OS version, rc=%Rrc\n", rc);
    157 #endif
    158217    }
    159218
     
    166225    if (!fStatusSet)
    167226        VGSvcError("Error reporting service status=%ld (controls=%x, checkpoint=%ld) to SCM: %ld\n",
    168                          dwStatus, ss.dwControlsAccepted, dwCheckPoint, GetLastError());
     227                   dwStatus, ss.dwControlsAccepted, dwCheckPoint, GetLastError());
    169228    return fStatusSet;
    170229}
     
    184243static RTEXITCODE vgsvcWinSetDesc(SC_HANDLE hService)
    185244{
    186 #ifndef TARGET_NT4
    187245    /* On W2K+ there's ChangeServiceConfig2() which lets us set some fields
    188246       like a longer service description. */
    189     /** @todo On Vista+ SERVICE_DESCRIPTION also supports localized strings! */
    190     SERVICE_DESCRIPTION desc;
    191     desc.lpDescription = VBOXSERVICE_DESCRIPTION;
    192     if (!ChangeServiceConfig2(hService,
    193                               SERVICE_CONFIG_DESCRIPTION, /* Service info level */
    194                               &desc))
    195     {
    196         VGSvcError("Cannot set the service description! Error: %ld\n", GetLastError());
    197         return RTEXITCODE_FAILURE;
    198     }
    199 #else
    200     RT_NOREF(hService);
    201 #endif
     247    if (g_pfnChangeServiceConfig2A)
     248    {
     249        /** @todo On Vista+ SERVICE_DESCRIPTION also supports localized strings! */
     250        SERVICE_DESCRIPTION desc;
     251        desc.lpDescription = VBOXSERVICE_DESCRIPTION;
     252        if (!g_pfnChangeServiceConfig2A(hService, SERVICE_CONFIG_DESCRIPTION, &desc))
     253        {
     254            VGSvcError("Cannot set the service description! Error: %ld\n", GetLastError());
     255            return RTEXITCODE_FAILURE;
     256        }
     257    }
    202258    return RTEXITCODE_SUCCESS;
    203259}
     
    327383    int rc = VINF_SUCCESS;
    328384
    329 #ifndef TARGET_NT4
    330385    /* Create a well-known SID for the "Builtin Users" group. */
    331     PSID pBuiltinUsersSID = NULL;
    332     SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_LOCAL_SID_AUTHORITY;
    333 
    334     if (!AllocateAndInitializeSid(&SIDAuthWorld, 1,
    335                                   SECURITY_LOCAL_RID,
    336                                   0, 0, 0, 0, 0, 0, 0,
    337                                   &pBuiltinUsersSID))
    338     {
    339         rc = RTErrConvertFromWin32(GetLastError());
    340     }
    341     else
     386    PSID                     pBuiltinUsersSID = NULL;
     387    SID_IDENTIFIER_AUTHORITY SIDAuthWorld     = SECURITY_LOCAL_SID_AUTHORITY;
     388    if (AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_LOCAL_RID, 0, 0, 0, 0, 0, 0, 0, &pBuiltinUsersSID))
    342389    {
    343390        DWORD dwRes = vgsvcWinAddAceToObjectsSecurityDescriptor(TEXT("\\\\.\\VBoxMiniRdrDN"),
    344                                                                       SE_FILE_OBJECT,
    345                                                                       (LPTSTR)pBuiltinUsersSID,
    346                                                                       TRUSTEE_IS_SID,
    347                                                                       FILE_GENERIC_READ | FILE_GENERIC_WRITE,
    348                                                                       SET_ACCESS,
    349                                                                       NO_INHERITANCE);
     391                                                                SE_FILE_OBJECT,
     392                                                                (LPTSTR)pBuiltinUsersSID,
     393                                                                TRUSTEE_IS_SID,
     394                                                                FILE_GENERIC_READ | FILE_GENERIC_WRITE,
     395                                                                SET_ACCESS,
     396                                                                NO_INHERITANCE);
    350397        if (dwRes != ERROR_SUCCESS)
    351398        {
     
    361408        }
    362409    }
    363 #endif
     410    else
     411        rc = RTErrConvertFromWin32(GetLastError());
    364412
    365413    if (RT_SUCCESS(rc))
     
    404452    if (!StartServiceCtrlDispatcher(&g_aServiceTable[0]))
    405453        return VGSvcError("StartServiceCtrlDispatcher: %u. Please start %s with option -f (foreground)!\n",
    406                                 GetLastError(), g_pszProgName);
     454                          GetLastError(), g_pszProgName);
    407455    return RTEXITCODE_SUCCESS;
    408456}
    409457
    410458
    411 #ifndef TARGET_NT4
    412 static const char* vgsvcWTSStateToString(DWORD dwEvent)
     459/**
     460 * Event code to description.
     461 *
     462 * @returns String.
     463 * @param   dwEvent             The event code.
     464 */
     465static const char *vgsvcWTSStateToString(DWORD dwEvent)
    413466{
    414467    switch (dwEvent)
    415468    {
    416         case WTS_CONSOLE_CONNECT:
    417             return "A session was connected to the console terminal";
    418 
    419         case WTS_CONSOLE_DISCONNECT:
    420             return "A session was disconnected from the console terminal";
    421 
    422         case WTS_REMOTE_CONNECT:
    423             return "A session connected to the remote terminal";
    424 
    425         case WTS_REMOTE_DISCONNECT:
    426             return "A session was disconnected from the remote terminal";
    427 
    428         case WTS_SESSION_LOGON:
    429             return "A user has logged on to a session";
    430 
    431         case WTS_SESSION_LOGOFF:
    432             return "A user has logged off the session";
    433 
    434         case WTS_SESSION_LOCK:
    435             return "A session has been locked";
    436 
    437         case WTS_SESSION_UNLOCK:
    438             return "A session has been unlocked";
    439 
    440         case WTS_SESSION_REMOTE_CONTROL:
    441             return "A session has changed its remote controlled status";
    442 #if 0
    443         case WTS_SESSION_CREATE:
    444             return "A session has been created";
    445 
    446         case WTS_SESSION_TERMINATE:
    447             return "The session has been terminated";
     469        case WTS_CONSOLE_CONNECT:           return "A session was connected to the console terminal";
     470        case WTS_CONSOLE_DISCONNECT:        return "A session was disconnected from the console terminal";
     471        case WTS_REMOTE_CONNECT:            return "A session connected to the remote terminal";
     472        case WTS_REMOTE_DISCONNECT:         return "A session was disconnected from the remote terminal";
     473        case WTS_SESSION_LOGON:             return "A user has logged on to a session";
     474        case WTS_SESSION_LOGOFF:            return "A user has logged off the session";
     475        case WTS_SESSION_LOCK:              return "A session has been locked";
     476        case WTS_SESSION_UNLOCK:            return "A session has been unlocked";
     477        case WTS_SESSION_REMOTE_CONTROL:    return "A session has changed its remote controlled status";
     478#ifdef WTS_SESSION_CREATE
     479        case WTS_SESSION_CREATE:            return "A session has been created";
    448480#endif
    449         default:
    450             break;
    451     }
    452 
    453     return "Uknonwn state";
    454 }
    455 #endif /* !TARGET_NT4 */
    456 
    457 
    458 #ifdef TARGET_NT4
    459 static VOID WINAPI vgsvcWinCtrlHandler(DWORD dwControl)
    460 #else
    461 static DWORD WINAPI vgsvcWinCtrlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
     481#ifdef WTS_SESSION_TERMINATE
     482        case WTS_SESSION_TERMINATE:         return "The session has been terminated";
    462483#endif
    463 {
    464 #ifdef TARGET_NT4
    465     VGSvcVerbose(2, "Control handler: Control=%#x\n", dwControl);
    466 #else
    467     RT_NOREF1(lpContext);
    468     VGSvcVerbose(2, "Control handler: Control=%#x, EventType=%#x\n", dwControl, dwEventType);
    469 #endif
    470 
     484        default:                            return "Uknonwn state";
     485    }
     486}
     487
     488
     489/**
     490 * Common control handler.
     491 *
     492 * @returns Return code for NT5+.
     493 * @param   dwControl           The control code.
     494 */
     495static DWORD vgsvcWinCtrlHandlerCommon(DWORD dwControl)
     496{
    471497    DWORD rcRet = NO_ERROR;
    472498    switch (dwControl)
     
    494520        }
    495521
    496 # ifndef TARGET_NT4
    497         case SERVICE_CONTROL_SESSIONCHANGE: /* Only Windows 2000 and up. */
    498         {
    499             AssertPtr(lpEventData);
    500             PWTSSESSION_NOTIFICATION pNotify = (PWTSSESSION_NOTIFICATION)lpEventData;
    501             Assert(pNotify->cbSize == sizeof(WTSSESSION_NOTIFICATION));
    502 
    503             VGSvcVerbose(1, "Control handler: %s (Session=%ld, Event=%#x)\n",
    504                                vgsvcWTSStateToString(dwEventType),
    505                                pNotify->dwSessionId, dwEventType);
    506 
    507             /* Handle all events, regardless of dwEventType. */
    508             int rc2 = VGSvcVMInfoSignal();
    509             AssertRC(rc2);
    510             break;
    511         }
    512 # endif /* !TARGET_NT4 */
    513 
    514522        default:
    515523            VGSvcVerbose(1, "Control handler: Function not implemented: %#x\n", dwControl);
     
    518526    }
    519527
    520 #ifndef TARGET_NT4
    521528    return rcRet;
    522 #endif
     529}
     530
     531
     532/**
     533 * Callback registered by RegisterServiceCtrlHandler on NT4 and earlier.
     534 */
     535static VOID WINAPI vgsvcWinCtrlHandlerNt4(DWORD dwControl)
     536{
     537    VGSvcVerbose(2, "Control handler (NT4): dwControl=%#x\n", dwControl);
     538    vgsvcWinCtrlHandlerCommon(dwControl);
     539}
     540
     541
     542/**
     543 * Callback registered by RegisterServiceCtrlHandler on NT5 and later.
     544 */
     545static DWORD WINAPI vgsvcWinCtrlHandlerNt5Plus(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
     546{
     547    VGSvcVerbose(2, "Control handler: dwControl=%#x, dwEventType=%#x\n", dwControl, dwEventType);
     548    RT_NOREF1(lpContext);
     549
     550    switch (dwControl)
     551    {
     552        default:
     553            return vgsvcWinCtrlHandlerCommon(dwControl);
     554
     555        case SERVICE_CONTROL_SESSIONCHANGE:  /* Only Windows 2000 and up. */
     556        {
     557            AssertPtr(lpEventData);
     558            PWTSSESSION_NOTIFICATION pNotify = (PWTSSESSION_NOTIFICATION)lpEventData;
     559            Assert(pNotify->cbSize == sizeof(WTSSESSION_NOTIFICATION));
     560
     561            VGSvcVerbose(1, "Control handler: %s (Session=%ld, Event=%#x)\n",
     562                         vgsvcWTSStateToString(dwEventType), pNotify->dwSessionId, dwEventType);
     563
     564            /* Handle all events, regardless of dwEventType. */
     565            int rc2 = VGSvcVMInfoSignal();
     566            AssertRC(rc2);
     567
     568            return NO_ERROR;
     569        }
     570    }
    523571}
    524572
     
    528576    RT_NOREF2(argc, argv);
    529577    VGSvcVerbose(2, "Registering service control handler ...\n");
    530 #ifdef TARGET_NT4
    531     g_hWinServiceStatus = RegisterServiceCtrlHandler(VBOXSERVICE_NAME, vgsvcWinCtrlHandler);
    532 #else
    533     g_hWinServiceStatus = RegisterServiceCtrlHandlerEx(VBOXSERVICE_NAME, vgsvcWinCtrlHandler, NULL);
    534 #endif
     578    if (g_pfnRegisterServiceCtrlHandlerExA)
     579        g_hWinServiceStatus = g_pfnRegisterServiceCtrlHandlerExA(VBOXSERVICE_NAME, vgsvcWinCtrlHandlerNt5Plus, NULL);
     580    else
     581        g_hWinServiceStatus = RegisterServiceCtrlHandlerA(VBOXSERVICE_NAME, vgsvcWinCtrlHandlerNt4);
    535582    if (g_hWinServiceStatus != NULL)
    536583    {
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp

    r69997 r70171  
    882882        return RTMsgInitFailure(rc);
    883883    g_pszProgName = RTPathFilename(argv[0]);
     884#ifdef RT_OS_WINDOWS
     885    VGSvcWinResolveApis();
     886#endif
    884887#ifdef DEBUG
    885888    rc = RTCritSectInit(&g_csLog);
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h

    r69997 r70171  
    197197extern int                      VGSvcReportStatus(VBoxGuestFacilityStatus enmStatus);
    198198#ifdef RT_OS_WINDOWS
     199extern void                     VGSvcWinResolveApis(void);
    199200extern RTEXITCODE               VGSvcWinInstall(void);
    200201extern RTEXITCODE               VGSvcWinUninstall(void);
    201202extern RTEXITCODE               VGSvcWinEnterCtrlDispatcher(void);
    202203extern void                     VGSvcWinSetStopPendingStatus(uint32_t uCheckPoint);
     204# ifdef TH32CS_SNAPHEAPLIST
     205extern decltype(CreateToolhelp32Snapshot)      *g_pfnCreateToolhelp32Snapshot;
     206extern decltype(Process32First)                *g_pfnProcess32First;
     207extern decltype(Process32Next)                 *g_pfnProcess32Next;
     208extern decltype(Module32First)                 *g_pfnModule32First;
     209extern decltype(Module32Next)                  *g_pfnModule32Next;
     210# endif
     211# ifdef ___iprt_nt_nt_h___
     212extern decltype(ZwQuerySystemInformation)      *g_pfnZwQuerySystemInformation;
     213# endif
    203214#endif
    204215
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServicePageSharing.cpp

    r69500 r70171  
    4545*   Header Files                                                                                                                 *
    4646*********************************************************************************************************************************/
     47#undef _WIN32_WINNT           /// REMOVE WHEN VBoxServiceNT IS GONE
     48#define _WIN32_WINNT 0x0501   /// REMOVE WHEN VBoxServiceNT IS GONE
    4749#include <iprt/assert.h>
    4850#include <iprt/avl.h>
     
    6264#include <VBox/VMMDev.h>
    6365#include <VBox/VBoxGuestLib.h>
    64 #include "VBoxServiceInternal.h"
    65 #include "VBoxServiceUtils.h"
    66 
    67 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4)
     66
     67#ifdef RT_OS_WINDOWS
     68#include <iprt/nt/nt-and-windows.h>
    6869# include <tlhelp32.h>
    6970# include <psapi.h>
     
    7172#endif
    7273
     74#include "VBoxServiceInternal.h"
     75#include "VBoxServiceUtils.h"
     76
    7377
    7478/*********************************************************************************************************************************
     
    8185    HMODULE         hModule;
    8286    char            szFileVersion[16];
    83 # ifndef TARGET_NT4
    8487    MODULEENTRY32   Info;
    85 # endif
    86 #endif /* RT_OS_WINDOWS */
     88#endif
    8789} VGSVCPGSHKNOWNMOD, *PVGSVCPGSHKNOWNMOD;
    88 
    89 
    90 #ifdef RT_OS_WINDOWS
    91 /* NTDLL API we want to use: */
    92 # define SystemModuleInformation 11
    93 
    94 typedef struct _RTL_PROCESS_MODULE_INFORMATION
    95 {
    96     ULONG Section;
    97     PVOID MappedBase;
    98     PVOID ImageBase;
    99     ULONG ImageSize;
    100     ULONG Flags;
    101     USHORT LoadOrderIndex;
    102     USHORT InitOrderIndex;
    103     USHORT LoadCount;
    104     USHORT OffsetToFileName;
    105     CHAR FullPathName[256];
    106 } RTL_PROCESS_MODULE_INFORMATION, *PRTL_PROCESS_MODULE_INFORMATION;
    107 
    108 typedef struct _RTL_PROCESS_MODULES
    109 {
    110     ULONG NumberOfModules;
    111     RTL_PROCESS_MODULE_INFORMATION Modules[1];
    112 } RTL_PROCESS_MODULES, *PRTL_PROCESS_MODULES;
    113 
    114 typedef NTSTATUS (WINAPI *PFNZWQUERYSYSTEMINFORMATION)(ULONG, PVOID, ULONG, PULONG);
    115 
    116 #endif /* RT_OS_WINDOWS */
    11790
    11891
     
    12093*   Global Variables                                                                                                             *
    12194*********************************************************************************************************************************/
    122 #ifdef RT_OS_WINDOWS
    123 static PFNZWQUERYSYSTEMINFORMATION g_pfnZwQuerySystemInformation = NULL;
    124 #endif
    125 
    12695/** The semaphore we're blocking on. */
    12796static RTSEMEVENTMULTI  g_PageSharingEvent = NIL_RTSEMEVENTMULTI;
    12897
    12998static PAVLPVNODECORE   g_pKnownModuleTree = NULL;
    130 static uint64_t         g_idSession = 0;
     99static uint64_t         g_idSession        = 0;
    131100
    132101
     
    137106
    138107
    139 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4)
     108#ifdef RT_OS_WINDOWS
    140109
    141110/**
     
    149118    DWORD                    dwModuleSize = pModule->Info.modBaseSize;
    150119    BYTE                    *pBaseAddress = pModule->Info.modBaseAddr;
    151     DWORD                    cbVersionSize, dummy;
    152     BYTE                    *pVersionInfo;
    153120
    154121    VGSvcVerbose(3, "vgsvcPageSharingRegisterModule\n");
    155122
    156     cbVersionSize = GetFileVersionInfoSize(pModule->Info.szExePath, &dummy);
    157     if (!cbVersionSize)
     123    DWORD dwDummy;
     124    DWORD cbVersion = GetFileVersionInfoSize(pModule->Info.szExePath, &dwDummy);
     125    if (!cbVersion)
    158126    {
    159127        VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: GetFileVersionInfoSize failed with %d\n", GetLastError());
    160128        return;
    161129    }
    162     pVersionInfo = (BYTE *)RTMemAlloc(cbVersionSize);
     130    BYTE *pVersionInfo = (BYTE *)RTMemAllocZ(cbVersion);
    163131    if (!pVersionInfo)
    164132        return;
    165133
    166     if (!GetFileVersionInfo(pModule->Info.szExePath, 0, cbVersionSize, pVersionInfo))
     134    if (!GetFileVersionInfo(pModule->Info.szExePath, 0, cbVersion, pVersionInfo))
    167135    {
    168136        VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: GetFileVersionInfo failed with %d\n", GetLastError());
     
    177145    } *lpTranslate;
    178146
    179     UINT   cbTranslate;
     147    UINT cbTranslate;
    180148    BOOL fRet = VerQueryValue(pVersionInfo, TEXT("\\VarFileInfo\\Translation"), (LPVOID *)&lpTranslate, &cbTranslate);
    181149    if (   !fRet
     
    322290    }
    323291
    324     HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);
     292    HANDLE hSnapshot = g_pfnCreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);
    325293    if (hSnapshot == INVALID_HANDLE_VALUE)
    326294    {
     
    336304
    337305    ModuleInfo.dwSize = sizeof(ModuleInfo);
    338     bRet = Module32First(hSnapshot, &ModuleInfo);
     306    bRet = g_pfnModule32First(hSnapshot, &ModuleInfo);
    339307    do
    340308    {
     
    375343            Assert(ret); NOREF(ret);
    376344        }
    377     } while (Module32Next(hSnapshot, &ModuleInfo));
     345    } while (g_pfnModule32Next(hSnapshot, &ModuleInfo));
    378346
    379347    CloseHandle(hSnapshot);
     
    389357static void vgsvcPageSharingInspectGuest(void)
    390358{
    391     HANDLE hSnapshot;
     359    VGSvcVerbose(3, "vgsvcPageSharingInspectGuest\n");
    392360    PAVLPVNODECORE pNewTree = NULL;
    393     DWORD dwProcessId = GetCurrentProcessId();
    394 
    395     VGSvcVerbose(3, "vgsvcPageSharingInspectGuest\n");
    396 
    397     hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    398     if (hSnapshot == INVALID_HANDLE_VALUE)
    399     {
    400         VGSvcVerbose(3, "vgsvcPageSharingInspectGuest: CreateToolhelp32Snapshot failed with %d\n", GetLastError());
    401         return;
    402     }
    403 
    404     /* Check loaded modules for all running processes. */
    405     PROCESSENTRY32 ProcessInfo;
    406 
    407     ProcessInfo.dwSize = sizeof(ProcessInfo);
    408     Process32First(hSnapshot, &ProcessInfo);
    409 
    410     do
    411     {
    412         /* Skip our own process. */
    413         if (ProcessInfo.th32ProcessID != dwProcessId)
    414             vgsvcPageSharingInspectModules(ProcessInfo.th32ProcessID, &pNewTree);
    415     }
    416     while (Process32Next(hSnapshot, &ProcessInfo));
    417 
    418     CloseHandle(hSnapshot);
    419 
    420     /* Check all loaded kernel modules. */
     361
     362    /*
     363     * Check loaded modules for all running processes.
     364     */
     365    if (   g_pfnProcess32First
     366        && g_pfnProcess32Next
     367        && g_pfnModule32First
     368        && g_pfnModule32Next
     369        && g_pfnCreateToolhelp32Snapshot)
     370    {
     371        HANDLE hSnapshot = g_pfnCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
     372        if (hSnapshot == INVALID_HANDLE_VALUE)
     373        {
     374            VGSvcVerbose(3, "vgsvcPageSharingInspectGuest: CreateToolhelp32Snapshot failed with %d\n", GetLastError());
     375            return;
     376        }
     377
     378        DWORD const dwProcessId = GetCurrentProcessId();
     379
     380        PROCESSENTRY32 ProcessInfo;
     381        ProcessInfo.dwSize = sizeof(ProcessInfo);
     382        g_pfnProcess32First(hSnapshot, &ProcessInfo);
     383
     384        do
     385        {
     386            /* Skip our own process. */
     387            if (ProcessInfo.th32ProcessID != dwProcessId)
     388                vgsvcPageSharingInspectModules(ProcessInfo.th32ProcessID, &pNewTree);
     389        }
     390        while (g_pfnProcess32Next(hSnapshot, &ProcessInfo));
     391
     392        CloseHandle(hSnapshot);
     393    }
     394
     395    /*
     396     * Check all loaded kernel modules.
     397     */
    421398    if (g_pfnZwQuerySystemInformation)
    422399    {
     
    468445                        break;
    469446
    470 /** @todo Use unicode APIs! */
    471                     strcpy(pModule->Info.szModule, &pSystemModules->Modules[i].FullPathName[pSystemModules->Modules[i].OffsetToFileName]);
     447/** @todo FullPathName not an UTF-8 string is! An ANSI string it is. */
     448                    strcpy(pModule->Info.szModule,
     449                           (const char *)&pSystemModules->Modules[i].FullPathName[pSystemModules->Modules[i].OffsetToFileName]);
    472450                    GetSystemDirectoryA(szFullFilePath, sizeof(szFullFilePath));
    473451
    474452                    /* skip \Systemroot\system32 */
    475                     char *lpPath = strchr(&pSystemModules->Modules[i].FullPathName[1], '\\');
     453                    char *lpPath = strchr((char *)&pSystemModules->Modules[i].FullPathName[1], '\\');
    476454                    if (!lpPath)
    477455                    {
    478456                        /* Seen just file names in XP; try to locate the file in the system32 and system32\drivers directories. */
    479457                        strcat(szFullFilePath, "\\");
    480                         strcat(szFullFilePath, pSystemModules->Modules[i].FullPathName);
     458                        strcat(szFullFilePath, (const char *)pSystemModules->Modules[i].FullPathName);
    481459                        VGSvcVerbose(3, "Unexpected kernel module name try %s\n", szFullFilePath);
    482460                        if (RTFileExists(szFullFilePath) == false)
     
    484462                            GetSystemDirectoryA(szFullFilePath, sizeof(szFullFilePath));
    485463                            strcat(szFullFilePath, "\\drivers\\");
    486                             strcat(szFullFilePath, pSystemModules->Modules[i].FullPathName);
     464                            strcat(szFullFilePath, (const char *)pSystemModules->Modules[i].FullPathName);
    487465                            VGSvcVerbose(3, "Unexpected kernel module name try %s\n", szFullFilePath);
    488466                            if (RTFileExists(szFullFilePath) == false)
     
    496474                    else
    497475                    {
    498                         lpPath = strchr(lpPath+1, '\\');
     476                        lpPath = strchr(lpPath + 1, '\\');
    499477                        if (!lpPath)
    500478                        {
     
    568546
    569547
    570 #elif TARGET_NT4
     548#else  /* !RT_OS_WINDOWS */
    571549
    572550static void vgsvcPageSharingInspectGuest(void)
    573551{
    574     /* not implemented */
    575 }
    576 
    577 #else
    578 
    579 static void vgsvcPageSharingInspectGuest(void)
    580 {
    581552    /** @todo other platforms */
    582553}
    583554
    584 #endif
     555#endif /* !RT_OS_WINDOWS */
    585556
    586557/** @interface_method_impl{VBOXSERVICE,pfnInit} */
     
    592563    AssertRCReturn(rc, rc);
    593564
    594 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4)
    595     g_pfnZwQuerySystemInformation = (PFNZWQUERYSYSTEMINFORMATION)RTLdrGetSystemSymbol("ntdll.dll", "ZwQuerySystemInformation");
    596 
     565#ifdef RT_OS_WINDOWS
    597566    rc = VbglR3GetSessionId(&g_idSession);
    598567    if (RT_FAILURE(rc))
     
    653622            break;
    654623        }
    655 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4)
     624#ifdef RT_OS_WINDOWS
    656625        uint64_t idNewSession = g_idSession;
    657626        rc =  VbglR3GetSessionId(&idNewSession);
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp

    r69500 r70171  
    3131#if defined(RT_OS_WINDOWS)
    3232# ifdef TARGET_NT4
    33 #  undef _WIN32_WINNT
    34 #  define _WIN32_WINNT 0x501
     33#  undef _WIN32_WINNT           /// REMOVE WHEN VBoxServiceNT IS GONE
     34#  define _WIN32_WINNT 0x0501   /// REMOVE WHEN VBoxServiceNT IS GONE
    3535# endif
    3636# include <iprt/win/windows.h>
     
    6363#include <VBox/VMMDev.h> /* For VMMDevReportGuestStats and indirectly VbglR3StatReport. */
    6464#include <VBox/VBoxGuestLib.h>
     65
    6566#include "VBoxServiceInternal.h"
    6667#include "VBoxServiceUtils.h"
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