Changeset 109032 in vbox for trunk/src/VBox/Runtime/r3/win/RTMpGetDescription-win.cpp
- Timestamp:
- Apr 21, 2025 12:44:58 AM (4 weeks ago)
- svn:sync-xref-src-repo-rev:
- 168561
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/RTMpGetDescription-win.cpp
r108997 r109032 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - Multiprocessor, Generic RTMpGetDescription stub.3 * IPRT - Multiprocessor, RTMpGetDescription, edition for newer Windows versions. 4 4 */ 5 5 … … 39 39 * Header Files * 40 40 *********************************************************************************************************************************/ 41 #include <iprt/win/windows.h> 41 42 #include <iprt/mp.h> 42 43 #include "internal/iprt.h" 43 44 44 45 #include <iprt/string.h> 46 #include <iprt/utf16.h> 45 47 #include <iprt/err.h> 46 48 … … 48 50 RTDECL(int) RTMpGetDescription(RTCPUID idCpu, char *pszBuf, size_t cbBuf) 49 51 { 50 static const char s_szUnknown[] = "Unknown";51 52 52 if (idCpu != NIL_RTCPUID && !RTMpIsCpuOnline(idCpu)) 53 53 return RTMpIsCpuPossible(idCpu) … … 55 55 : VERR_CPU_NOT_FOUND; 56 56 57 if (cbBuf < sizeof(s_szUnknown)) 58 return VERR_BUFFER_OVERFLOW; 57 /* 58 * Newer windows versions (at least 11), keeps info about the CPU in the 59 * registry. 60 * 61 * 'Get-WmiObject win32_processor' queries this information for instance 62 * (probably by way of cimwin32.dll and framedynos.dll). 63 */ 64 HKEY hKeyCpuRoot = NULL; 65 LSTATUS lrc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor", 0 /* ulOptions*/, 66 KEY_ENUMERATE_SUB_KEYS | KEY_READ, &hKeyCpuRoot); 67 AssertMsg(lrc == ERROR_SUCCESS, ("lrc=%u\n", lrc)); 68 if (lrc == ERROR_SUCCESS) 69 { 70 HKEY hKeyCpu = NULL; 71 if (idCpu == NIL_RTCPUID) 72 { 73 lrc = RegOpenKeyExW(hKeyCpuRoot, L"0", 0 /* ulOptions*/, KEY_ENUMERATE_SUB_KEYS | KEY_READ, &hKeyCpu); 74 AssertMsg(lrc == ERROR_SUCCESS, ("lrc=%u\n", lrc)); 75 /** @todo if (lrc != ERROR_SUCCESS) enumerate subkeys */ 76 } 77 else 78 { 79 WCHAR wszCpuNo[32]; 80 RTUtf16Printf(wszCpuNo, RT_ELEMENTS(wszCpuNo), "%u", idCpu); 81 lrc = RegOpenKeyExW(hKeyCpuRoot, wszCpuNo, 0 /* ulOptions*/, KEY_ENUMERATE_SUB_KEYS | KEY_READ, &hKeyCpu); 82 AssertMsg(lrc == ERROR_SUCCESS, ("lrc=%u\n", lrc)); 83 } 84 if (lrc == ERROR_SUCCESS) 85 { 86 WCHAR wszBuf[1536] = {0}; /* reasonable buffer size, right... */ 87 DWORD dwType = REG_NONE; 88 DWORD cbData = sizeof(wszBuf) - sizeof(WCHAR); 89 lrc = RegQueryValueExW(hKeyCpu, L"ProcessorNameString", NULL /*lpReserved*/, &dwType, (PBYTE)&wszBuf[0], &cbData); 90 if (lrc == ERROR_SUCCESS) 91 { 92 if (dwType == REG_SZ) 93 { 94 if (cbBuf != 0 && pszBuf) 95 return RTUtf16ToUtf8Ex(wszBuf, cbData / sizeof(WCHAR), &pszBuf, cbBuf, NULL); 96 return VERR_BUFFER_OVERFLOW; 97 } 98 } 99 } 100 } 59 101 60 memcpy(pszBuf, s_szUnknown, sizeof(s_szUnknown));61 return VINF_SUCCESS;102 /* Fallback... */ 103 return RTStrCopy(pszBuf, cbBuf, "Unknown"); 62 104 } 63 105 RT_EXPORT_SYMBOL(RTMpGetDescription);
Note:
See TracChangeset
for help on using the changeset viewer.