VirtualBox

Ignore:
Timestamp:
Apr 21, 2025 12:44:58 AM (4 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168561
Message:

IPRT: Reimplemented RTMpGetDescription for windows/arm taking info from the registry. jiraref:VBP-1598

File:
1 copied

Legend:

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

    r108997 r109032  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Multiprocessor, Generic RTMpGetDescription stub.
     3 * IPRT - Multiprocessor, RTMpGetDescription, edition for newer Windows versions.
    44 */
    55
     
    3939*   Header Files                                                                                                                 *
    4040*********************************************************************************************************************************/
     41#include <iprt/win/windows.h>
    4142#include <iprt/mp.h>
    4243#include "internal/iprt.h"
    4344
    4445#include <iprt/string.h>
     46#include <iprt/utf16.h>
    4547#include <iprt/err.h>
    4648
     
    4850RTDECL(int) RTMpGetDescription(RTCPUID idCpu, char *pszBuf, size_t cbBuf)
    4951{
    50     static const char s_szUnknown[] = "Unknown";
    51 
    5252    if (idCpu != NIL_RTCPUID && !RTMpIsCpuOnline(idCpu))
    5353        return RTMpIsCpuPossible(idCpu)
     
    5555             : VERR_CPU_NOT_FOUND;
    5656
    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    }
    59101
    60     memcpy(pszBuf, s_szUnknown, sizeof(s_szUnknown));
    61     return VINF_SUCCESS;
     102    /* Fallback... */
     103    return RTStrCopy(pszBuf, cbBuf, "Unknown");
    62104}
    63105RT_EXPORT_SYMBOL(RTMpGetDescription);
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