static void tstCheckNativeMsCrtToArgv(const char *pszCmdLine, int cExpectedArgs, const char * const *papszExpectedArgs) { #ifdef RT_OS_WINDOWS /* * Resolve APIs. */ static void *(__stdcall * s_pfnLocalFree)(void *pvFree); static PRTUTF16 *(__stdcall * s_pfnCommandLineToArgvW)(PCRTUTF16 pwszCmdLine, int *pcArgs); if (!s_pfnCommandLineToArgvW) { *(void **)&s_pfnLocalFree = RTLdrGetSystemSymbol("kernel32.dll", "LocalFree"); RTTESTI_CHECK_RETV(s_pfnLocalFree != NULL); *(void **)&s_pfnCommandLineToArgvW = RTLdrGetSystemSymbol("shell32.dll", "CommandLineToArgvW"); RTTESTI_CHECK_RETV(s_pfnCommandLineToArgvW != NULL); } /* * Calc expected arguments if needed. */ if (cExpectedArgs == -1) for (cExpectedArgs = 0; papszExpectedArgs[cExpectedArgs]; cExpectedArgs++) { /* nothing */ } /* * Convert input command line to UTF-16 and call native API. */ RTUTF16 wszCmdLine[1024]; PRTUTF16 pwszCmdLine = &wszCmdLine[1]; RTTESTI_CHECK_RC_RETV(RTStrToUtf16Ex(pszCmdLine, RTSTR_MAX, &pwszCmdLine, 1023, NULL), VINF_SUCCESS); wszCmdLine[0] = ' '; int cArgs = -2; PRTUTF16 *papwszArgs = s_pfnCommandLineToArgvW(wszCmdLine, &cArgs); /* * Check the result. */ if (cArgs - 1 != cExpectedArgs) RTTestIFailed("Native returns cArgs=%d, expected %d (cmdline=|%s|)", cArgs - 1, cExpectedArgs, pszCmdLine); int cArgsCheck = RT_MIN(cArgs - 1, cExpectedArgs); for (int i = 0; i < cArgsCheck; i++) { char *pszArg = NULL; RTTESTI_CHECK_RC_RETV(RTUtf16ToUtf8(papwszArgs[i + 1], &pszArg), VINF_SUCCESS); if (strcmp(pszArg, papszExpectedArgs[i])) RTTestIFailed("Native returns argv[%i]='%s', expected '%s' (cmdline=|%s|)", i, pszArg, papszExpectedArgs[i], pszCmdLine); RTStrFree(pszArg); } if (papwszArgs) s_pfnLocalFree(papwszArgs); #else NOREF(pszCmdLine); NOREF(cExpectedArgs); NOREF(papszExpectedArgs); #endif }
/** @copydoc VBOXSERVICE::pfnInit */ static DECLCALLBACK(int) VBoxServiceVMStatsInit(void) { VBoxServiceVerbose(3, "VBoxServiceVMStatsInit\n"); int rc = RTSemEventMultiCreate(&g_VMStatEvent); AssertRCReturn(rc, rc); gCtx.cMsStatInterval = 0; /* default; update disabled */ RT_ZERO(gCtx.au64LastCpuLoad_Idle); RT_ZERO(gCtx.au64LastCpuLoad_Kernel); RT_ZERO(gCtx.au64LastCpuLoad_User); RT_ZERO(gCtx.au64LastCpuLoad_Nice); rc = VbglR3StatQueryInterval(&gCtx.cMsStatInterval); if (RT_SUCCESS(rc)) VBoxServiceVerbose(3, "VBoxStatsInit: New statistics interval %u seconds\n", gCtx.cMsStatInterval); else VBoxServiceVerbose(3, "VBoxStatsInit: DeviceIoControl failed with %d\n", rc); #ifdef RT_OS_WINDOWS /* NtQuerySystemInformation might be dropped in future releases, so load it dynamically as per Microsoft's recommendation. */ *(void **)&gCtx.pfnNtQuerySystemInformation = RTLdrGetSystemSymbol("ntdll.dll", "NtQuerySystemInformation"); if (gCtx.pfnNtQuerySystemInformation) VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnNtQuerySystemInformation = %x\n", gCtx.pfnNtQuerySystemInformation); else { VBoxServiceVerbose(3, "VBoxStatsInit: ntdll.NtQuerySystemInformation not found!\n"); return VERR_SERVICE_DISABLED; } /* GlobalMemoryStatus is win2k and up, so load it dynamically */ *(void **)&gCtx.pfnGlobalMemoryStatusEx = RTLdrGetSystemSymbol("kernel32.dll", "GlobalMemoryStatusEx"); if (gCtx.pfnGlobalMemoryStatusEx) VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.GlobalMemoryStatusEx = %x\n", gCtx.pfnGlobalMemoryStatusEx); else { /** @todo Now fails in NT4; do we care? */ VBoxServiceVerbose(3, "VBoxStatsInit: kernel32.GlobalMemoryStatusEx not found!\n"); return VERR_SERVICE_DISABLED; } /* GetPerformanceInfo is xp and up, so load it dynamically */ *(void **)&gCtx.pfnGetPerformanceInfo = RTLdrGetSystemSymbol("psapi.dll", "GetPerformanceInfo"); if (gCtx.pfnGetPerformanceInfo) VBoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnGetPerformanceInfo= %x\n", gCtx.pfnGetPerformanceInfo); #endif /* RT_OS_WINDOWS */ return VINF_SUCCESS; }
CollectorWin::CollectorWin() : CollectorHAL(), mpfnNtQuerySystemInformation(NULL) { /* Note! Both kernel32.dll and ntdll.dll can be assumed to always be present. */ mpfnGetSystemTimes = (PFNGST)RTLdrGetSystemSymbol("kernel32.dll", "GetSystemTimes"); if (!mpfnGetSystemTimes) { /* Fall back to deprecated NtQuerySystemInformation */ mpfnNtQuerySystemInformation = (PFNNQSI)RTLdrGetSystemSymbol("ntdll.dll", "NtQuerySystemInformation"); if (!mpfnNtQuerySystemInformation) LogRel(("Warning! Neither GetSystemTimes() nor NtQuerySystemInformation() is not available.\n" " CPU and VM metrics will not be collected! (lasterr %u)\n", GetLastError())); } uint64_t cb; int rc = RTSystemQueryTotalRam(&cb); if (RT_FAILURE(rc)) totalRAM = 0; else totalRAM = (ULONG)(cb / 1024); }
QSize QILineEdit::featTextWidth (const QString &aText) const { QStyleOptionFrame sof; sof.initFrom (this); sof.rect = contentsRect(); sof.lineWidth = hasFrame() ? style()->pixelMetric (QStyle::PM_DefaultFrameWidth) : 0; sof.midLineWidth = 0; sof.state |= QStyle::State_Sunken; /* The margins are based on qlineedit.cpp of Qt. Maybe they where changed * at some time in the future. */ QSize sc (fontMetrics().width (aText) + 2*2, fontMetrics().xHeight() + 2*1); QSize sa = style()->sizeFromContents (QStyle::CT_LineEdit, &sof, sc, this); #if defined (Q_WS_WIN32) /* Vista l&f style has a bug where the last parameter of sizeFromContents * function ('widget' what corresponds to 'this' in our class) is ignored. * Due to it QLineEdit processed as QComboBox and size calculation includes * non-existing combo-box button of 23 pix in width. So fixing it here: */ if (qobject_cast <QWindowsVistaStyle*> (style())) { /* Check if l&f style theme is really active else painting performed by * Windows Classic theme and there is no such shifting error. */ typedef BOOL (WINAPI *PFNISAPPTHEMED)(VOID); static PFNISAPPTHEMED s_pfnIsAppThemed = (PFNISAPPTHEMED)~(uintptr_t)0; if (s_pfnIsAppThemed == (PFNISAPPTHEMED)~(uintptr_t)0 ) s_pfnIsAppThemed = (PFNISAPPTHEMED)RTLdrGetSystemSymbol("uxtheme.dll", "IsAppThemed"); if (s_pfnIsAppThemed && s_pfnIsAppThemed()) sa -= QSize(23, 0); } #endif return sa; }
RTDECL(RTCPUID) RTMpGetCoreCount(void) { /* * Resolve the API dynamically (one try) as it requires XP w/ sp3 or later. */ typedef BOOL (WINAPI *PFNGETLOGICALPROCINFO)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD); static PFNGETLOGICALPROCINFO s_pfnGetLogicalProcInfo = (PFNGETLOGICALPROCINFO)~(uintptr_t)0; if (s_pfnGetLogicalProcInfo == (PFNGETLOGICALPROCINFO)~(uintptr_t)0) s_pfnGetLogicalProcInfo = (PFNGETLOGICALPROCINFO)RTLdrGetSystemSymbol("kernel32.dll", "GetLogicalProcessorInformation"); /* * Sadly, on XP and Server 2003, even if the API is present, it does not tell us * how many physical cores there are (any package will look like a single core). * That is worse than not using the API at all, so just skip it unless it's Vista+. */ bool fIsVistaOrLater = false; OSVERSIONINFOEX OSInfoEx = { 0 }; OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if ( GetVersionEx((LPOSVERSIONINFO) &OSInfoEx) && (OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT) && (OSInfoEx.dwMajorVersion >= 6)) fIsVistaOrLater = true; if (s_pfnGetLogicalProcInfo && fIsVistaOrLater) { /* * Query the information. This unfortunately requires a buffer, so we * start with a guess and let windows advice us if it's too small. */ DWORD cbSysProcInfo = _4K; PSYSTEM_LOGICAL_PROCESSOR_INFORMATION paSysInfo = NULL; BOOL fRc = FALSE; do { cbSysProcInfo = RT_ALIGN_32(cbSysProcInfo, 256); void *pv = RTMemRealloc(paSysInfo, cbSysProcInfo); if (!pv) break; paSysInfo = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)pv; fRc = s_pfnGetLogicalProcInfo(paSysInfo, &cbSysProcInfo); } while (!fRc && GetLastError() == ERROR_INSUFFICIENT_BUFFER); if (fRc) { /* * Parse the result. */ uint32_t cCores = 0; uint32_t i = cbSysProcInfo / sizeof(paSysInfo[0]); while (i-- > 0) if (paSysInfo[i].Relationship == RelationProcessorCore) cCores++; RTMemFree(paSysInfo); Assert(cCores > 0); return cCores; } RTMemFree(paSysInfo); } /* If we don't have the necessary API or if it failed, return the same value as the generic implementation. */ return RTMpGetCount(); }