Skip to content

Commit a642d69

Browse files
committed
Add emulation info to mididiag
1 parent f2d04f7 commit a642d69

File tree

2 files changed

+69
-7
lines changed

2 files changed

+69
-7
lines changed

src/app-sdk/mididiag/main.cpp

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,21 @@ std::wstring GetProcessorArchitectureString(WORD const arch)
957957

958958
}
959959

960+
#define ENV_PROCESSOR_ARCHITECTURE L"PROCESSOR_ARCHITECTURE"
961+
#define ENV_PROCESSOR_IDENTIFIER L"PROCESSOR_IDENTIFIER"
962+
#define ENV_PROCESSOR_LEVEL L"PROCESSOR_LEVEL"
963+
#define ENV_PROCESSOR_REVISION L"PROCESSOR_REVISION"
964+
965+
966+
void OutputProcessorEnvVariables()
967+
{
968+
OutputStringField(ENV_PROCESSOR_ARCHITECTURE, std::wstring{ _wgetenv(ENV_PROCESSOR_ARCHITECTURE)});
969+
OutputStringField(ENV_PROCESSOR_IDENTIFIER, std::wstring{ _wgetenv(ENV_PROCESSOR_IDENTIFIER) });
970+
OutputStringField(ENV_PROCESSOR_LEVEL, std::wstring{ _wgetenv(ENV_PROCESSOR_LEVEL) });
971+
OutputStringField(ENV_PROCESSOR_REVISION, std::wstring{ _wgetenv(ENV_PROCESSOR_REVISION) });
972+
}
973+
974+
960975
void OutputSystemInfo(_In_ SYSTEM_INFO const& sysinfo)
961976
{
962977
// that sysinfo.dwNumberOfProcessors can return some strange results.
@@ -969,6 +984,51 @@ void OutputSystemInfo(_In_ SYSTEM_INFO const& sysinfo)
969984
OutputHexNumericField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_REVISION, sysinfo.wProcessorRevision);
970985
}
971986

987+
void OutputProcessAndNativeMachine()
988+
{
989+
USHORT processMachine;
990+
USHORT nativeMachine;
991+
992+
HANDLE hProcess = ::GetCurrentProcess();
993+
994+
if (hProcess)
995+
{
996+
auto worked = ::IsWow64Process2(hProcess, &processMachine, &nativeMachine);
997+
998+
if (worked)
999+
{
1000+
// if not running emulated, IsWow64Process2 returns machine unknown for the process.
1001+
if ((processMachine == IMAGE_FILE_MACHINE_UNKNOWN || processMachine == IMAGE_FILE_MACHINE_ARM64) && nativeMachine == IMAGE_FILE_MACHINE_ARM64)
1002+
{
1003+
OutputStringField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION, std::wstring{ L"Native Arm64 process on Arm64 PC (Note Emulated)" });
1004+
}
1005+
else if ((processMachine == IMAGE_FILE_MACHINE_UNKNOWN || processMachine == IMAGE_FILE_MACHINE_AMD64) && nativeMachine == IMAGE_FILE_MACHINE_AMD64)
1006+
{
1007+
OutputStringField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION, std::wstring{ L"Native Intel/AMD x64 on x64 PC (Not Emulated)" });
1008+
}
1009+
else if (processMachine == IMAGE_FILE_MACHINE_AMD64 && nativeMachine == IMAGE_FILE_MACHINE_ARM64)
1010+
{
1011+
OutputStringField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION, std::wstring{ L"Intel/AMD x64 process on Arm64 PC (Emulated)" });
1012+
}
1013+
else if (processMachine == IMAGE_FILE_MACHINE_ARM64 && nativeMachine == IMAGE_FILE_MACHINE_AMD64)
1014+
{
1015+
// not supported today, but here in case it is some day
1016+
OutputStringField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION, std::wstring{ L"Arm64 process on Intel/AMD x64 PC (Emulated)" });
1017+
}
1018+
else
1019+
{
1020+
OutputError(L"Unidentified process and/or machine architecture");
1021+
}
1022+
}
1023+
else
1024+
{
1025+
OutputError(L"Unable to query process and machine architecture.");
1026+
}
1027+
1028+
}
1029+
}
1030+
1031+
9721032
bool DoSectionSystemInfo(_In_ bool verbose)
9731033
{
9741034
UNREFERENCED_PARAMETER(verbose);
@@ -978,19 +1038,19 @@ bool DoSectionSystemInfo(_In_ bool verbose)
9781038

9791039

9801040
// if running under emulation on Arm64, this is going to return the emulated sys info
981-
OutputSectionHeader(MIDIDIAG_SECTION_LABEL_APPARENT_SYSTEM_INFO);
1041+
OutputSectionHeader(MIDIDIAG_SECTION_LABEL_PROCESSOR_ENV);
1042+
OutputProcessorEnvVariables();
9821043

983-
SYSTEM_INFO sysinfo;
984-
::GetNativeSystemInfo(&sysinfo);
985-
OutputSystemInfo(sysinfo);
986-
987-
// if running under emulation on Arm64, this is going to return the Arm info
9881044
OutputSectionHeader(MIDIDIAG_SECTION_LABEL_NATIVE_SYSTEM_INFO);
9891045

9901046
SYSTEM_INFO sysinfoNative;
9911047
::GetNativeSystemInfo(&sysinfoNative);
9921048
OutputSystemInfo(sysinfoNative);
9931049

1050+
OutputItemSeparator();
1051+
OutputProcessAndNativeMachine();
1052+
OutputItemSeparator();
1053+
9941054
TIMECAPS timecaps;
9951055
auto tcresult = ::timeGetDevCaps(&timecaps, sizeof(timecaps));
9961056

src/app-sdk/mididiag/mididiag_field_defs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@
110110
#define MIDIDIAG_SECTION_LABEL_OS L"os"
111111
#define MIDIDIAG_FIELD_LABEL_OS_VERSION L"os_version"
112112

113-
#define MIDIDIAG_SECTION_LABEL_APPARENT_SYSTEM_INFO L"apparent_system_info"
113+
#define MIDIDIAG_SECTION_LABEL_PROCESSOR_ENV L"processor_env"
114114
#define MIDIDIAG_SECTION_LABEL_NATIVE_SYSTEM_INFO L"native_system_info"
115115
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_ARCH L"processor_architecture"
116116
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_LEVEL L"processor_level"
117117
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_REVISION L"processor_revision"
118+
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION L"running_emulated"
119+
118120

119121
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_TIMECAPS_ERROR L"timecaps_error"
120122
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_TIMECAPS_MIN_PERIOD L"timecaps_min_period"

0 commit comments

Comments
 (0)