Skip to content

Commit

Permalink
Add emulation info to mididiag
Browse files Browse the repository at this point in the history
  • Loading branch information
Psychlist1972 committed Nov 28, 2024
1 parent f2d04f7 commit a642d69
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
72 changes: 66 additions & 6 deletions src/app-sdk/mididiag/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,21 @@ std::wstring GetProcessorArchitectureString(WORD const arch)

}

#define ENV_PROCESSOR_ARCHITECTURE L"PROCESSOR_ARCHITECTURE"
#define ENV_PROCESSOR_IDENTIFIER L"PROCESSOR_IDENTIFIER"
#define ENV_PROCESSOR_LEVEL L"PROCESSOR_LEVEL"
#define ENV_PROCESSOR_REVISION L"PROCESSOR_REVISION"


void OutputProcessorEnvVariables()
{
OutputStringField(ENV_PROCESSOR_ARCHITECTURE, std::wstring{ _wgetenv(ENV_PROCESSOR_ARCHITECTURE)});
OutputStringField(ENV_PROCESSOR_IDENTIFIER, std::wstring{ _wgetenv(ENV_PROCESSOR_IDENTIFIER) });
OutputStringField(ENV_PROCESSOR_LEVEL, std::wstring{ _wgetenv(ENV_PROCESSOR_LEVEL) });
OutputStringField(ENV_PROCESSOR_REVISION, std::wstring{ _wgetenv(ENV_PROCESSOR_REVISION) });
}


void OutputSystemInfo(_In_ SYSTEM_INFO const& sysinfo)
{
// that sysinfo.dwNumberOfProcessors can return some strange results.
Expand All @@ -969,6 +984,51 @@ void OutputSystemInfo(_In_ SYSTEM_INFO const& sysinfo)
OutputHexNumericField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_REVISION, sysinfo.wProcessorRevision);
}

void OutputProcessAndNativeMachine()
{
USHORT processMachine;
USHORT nativeMachine;

HANDLE hProcess = ::GetCurrentProcess();

if (hProcess)
{
auto worked = ::IsWow64Process2(hProcess, &processMachine, &nativeMachine);

if (worked)
{
// if not running emulated, IsWow64Process2 returns machine unknown for the process.
if ((processMachine == IMAGE_FILE_MACHINE_UNKNOWN || processMachine == IMAGE_FILE_MACHINE_ARM64) && nativeMachine == IMAGE_FILE_MACHINE_ARM64)
{
OutputStringField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION, std::wstring{ L"Native Arm64 process on Arm64 PC (Note Emulated)" });
}
else if ((processMachine == IMAGE_FILE_MACHINE_UNKNOWN || processMachine == IMAGE_FILE_MACHINE_AMD64) && nativeMachine == IMAGE_FILE_MACHINE_AMD64)
{
OutputStringField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION, std::wstring{ L"Native Intel/AMD x64 on x64 PC (Not Emulated)" });
}
else if (processMachine == IMAGE_FILE_MACHINE_AMD64 && nativeMachine == IMAGE_FILE_MACHINE_ARM64)
{
OutputStringField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION, std::wstring{ L"Intel/AMD x64 process on Arm64 PC (Emulated)" });
}
else if (processMachine == IMAGE_FILE_MACHINE_ARM64 && nativeMachine == IMAGE_FILE_MACHINE_AMD64)
{
// not supported today, but here in case it is some day
OutputStringField(MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION, std::wstring{ L"Arm64 process on Intel/AMD x64 PC (Emulated)" });
}
else
{
OutputError(L"Unidentified process and/or machine architecture");
}
}
else
{
OutputError(L"Unable to query process and machine architecture.");
}

}
}


bool DoSectionSystemInfo(_In_ bool verbose)
{
UNREFERENCED_PARAMETER(verbose);
Expand All @@ -978,19 +1038,19 @@ bool DoSectionSystemInfo(_In_ bool verbose)


// if running under emulation on Arm64, this is going to return the emulated sys info
OutputSectionHeader(MIDIDIAG_SECTION_LABEL_APPARENT_SYSTEM_INFO);
OutputSectionHeader(MIDIDIAG_SECTION_LABEL_PROCESSOR_ENV);
OutputProcessorEnvVariables();

SYSTEM_INFO sysinfo;
::GetNativeSystemInfo(&sysinfo);
OutputSystemInfo(sysinfo);

// if running under emulation on Arm64, this is going to return the Arm info
OutputSectionHeader(MIDIDIAG_SECTION_LABEL_NATIVE_SYSTEM_INFO);

SYSTEM_INFO sysinfoNative;
::GetNativeSystemInfo(&sysinfoNative);
OutputSystemInfo(sysinfoNative);

OutputItemSeparator();
OutputProcessAndNativeMachine();
OutputItemSeparator();

TIMECAPS timecaps;
auto tcresult = ::timeGetDevCaps(&timecaps, sizeof(timecaps));

Expand Down
4 changes: 3 additions & 1 deletion src/app-sdk/mididiag/mididiag_field_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@
#define MIDIDIAG_SECTION_LABEL_OS L"os"
#define MIDIDIAG_FIELD_LABEL_OS_VERSION L"os_version"

#define MIDIDIAG_SECTION_LABEL_APPARENT_SYSTEM_INFO L"apparent_system_info"
#define MIDIDIAG_SECTION_LABEL_PROCESSOR_ENV L"processor_env"
#define MIDIDIAG_SECTION_LABEL_NATIVE_SYSTEM_INFO L"native_system_info"
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_ARCH L"processor_architecture"
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_LEVEL L"processor_level"
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_REVISION L"processor_revision"
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_PROCESSOR_EMULATION L"running_emulated"


#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_TIMECAPS_ERROR L"timecaps_error"
#define MIDIDIAG_FIELD_LABEL_SYSTEM_INFO_TIMECAPS_MIN_PERIOD L"timecaps_min_period"
Expand Down

0 comments on commit a642d69

Please sign in to comment.