VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/RTMpGetDescription-win.cpp

Last change on this file was 109032, checked in by vboxsync, 3 weeks ago

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: RTMpGetDescription-win.cpp 109032 2025-04-21 00:44:58Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor, RTMpGetDescription, edition for newer Windows versions.
4 */
5
6/*
7 * Copyright (C) 2009-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.215389.xyz.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/win/windows.h>
42#include <iprt/mp.h>
43#include "internal/iprt.h"
44
45#include <iprt/string.h>
46#include <iprt/utf16.h>
47#include <iprt/err.h>
48
49
50RTDECL(int) RTMpGetDescription(RTCPUID idCpu, char *pszBuf, size_t cbBuf)
51{
52 if (idCpu != NIL_RTCPUID && !RTMpIsCpuOnline(idCpu))
53 return RTMpIsCpuPossible(idCpu)
54 ? VERR_CPU_OFFLINE
55 : VERR_CPU_NOT_FOUND;
56
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 }
101
102 /* Fallback... */
103 return RTStrCopy(pszBuf, cbBuf, "Unknown");
104}
105RT_EXPORT_SYMBOL(RTMpGetDescription);
106
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette