VirtualBox

Ignore:
Timestamp:
Jun 17, 2013 2:32:51 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86471
Message:

updates

File:
1 edited

Legend:

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

    r44528 r46593  
    4444#include <iprt/assert.h>
    4545#include <iprt/mem.h>
     46#include <iprt/ldr.h>
    4647#include <VBox/param.h>
    4748#include <iprt/semaphore.h>
     
    124125
    125126#ifdef RT_OS_WINDOWS
    126     /** @todo Use RTLdr instead of LoadLibrary/GetProcAddress here! */
    127 
    128     /* NtQuerySystemInformation might be dropped in future releases, so load it dynamically as per Microsoft's recommendation */
    129     HMODULE hMod = LoadLibrary("NTDLL.DLL");
    130     if (hMod)
    131     {
    132         *(uintptr_t *)&gCtx.pfnNtQuerySystemInformation = (uintptr_t)GetProcAddress(hMod, "NtQuerySystemInformation");
    133         if (gCtx.pfnNtQuerySystemInformation)
    134             VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnNtQuerySystemInformation = %x\n", gCtx.pfnNtQuerySystemInformation);
    135         else
    136         {
    137             VBoxServiceVerbose(3, "VBoxStatsInit: NTDLL.NtQuerySystemInformation not found!\n");
    138             return VERR_SERVICE_DISABLED;
    139         }
     127    /* NtQuerySystemInformation might be dropped in future releases, so load
     128       it dynamically as per Microsoft's recommendation. */
     129    *(void **)&gCtx.pfnNtQuerySystemInformation = RTLdrGetSystemSymbol("NTDLL.DLL", "NtQuerySystemInformation");
     130    if (gCtx.pfnNtQuerySystemInformation)
     131        VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnNtQuerySystemInformation = %x\n", gCtx.pfnNtQuerySystemInformation);
     132    else
     133    {
     134        VBoxServiceVerbose(3, "VBoxStatsInit: NTDLL.NtQuerySystemInformation not found!\n");
     135        return VERR_SERVICE_DISABLED;
    140136    }
    141137
    142138    /* GlobalMemoryStatus is win2k and up, so load it dynamically */
    143     hMod = LoadLibrary("KERNEL32.DLL");
    144     if (hMod)
    145     {
    146         *(uintptr_t *)&gCtx.pfnGlobalMemoryStatusEx = (uintptr_t)GetProcAddress(hMod, "GlobalMemoryStatusEx");
    147         if (gCtx.pfnGlobalMemoryStatusEx)
    148             VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.GlobalMemoryStatusEx = %x\n", gCtx.pfnGlobalMemoryStatusEx);
    149         else
    150         {
    151             /** @todo Now fails in NT4; do we care? */
    152             VBoxServiceVerbose(3, "VBoxStatsInit: KERNEL32.GlobalMemoryStatusEx not found!\n");
    153             return VERR_SERVICE_DISABLED;
    154         }
    155     }
     139    *(void **)&gCtx.pfnGlobalMemoryStatusEx = RTLdrGetSystemSymbol("KERNEL32.DLL", "GlobalMemoryStatusEx");
     140    if (gCtx.pfnGlobalMemoryStatusEx)
     141        VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.GlobalMemoryStatusEx = %x\n", gCtx.pfnGlobalMemoryStatusEx);
     142    else
     143    {
     144        /** @todo Now fails in NT4; do we care? */
     145        VBoxServiceVerbose(3, "VBoxStatsInit: KERNEL32.GlobalMemoryStatusEx not found!\n");
     146        return VERR_SERVICE_DISABLED;
     147    }
     148
    156149    /* GetPerformanceInfo is xp and up, so load it dynamically */
    157     hMod = LoadLibrary("PSAPI.DLL");
    158     if (hMod)
    159     {
    160         *(uintptr_t *)&gCtx.pfnGetPerformanceInfo = (uintptr_t)GetProcAddress(hMod, "GetPerformanceInfo");
    161         if (gCtx.pfnGetPerformanceInfo)
    162             VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnGetPerformanceInfo= %x\n", gCtx.pfnGetPerformanceInfo);
    163         /* failure is not fatal */
    164     }
     150    *(void **)&gCtx.pfnGetPerformanceInfo = RTLdrGetSystemSymbol("PSAPI.DLL", "GetPerformanceInfo");
     151    if (gCtx.pfnGetPerformanceInfo)
     152        VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnGetPerformanceInfo= %x\n", gCtx.pfnGetPerformanceInfo);
    165153#endif /* RT_OS_WINDOWS */
    166154
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