Skip to content

Commit

Permalink
Merge pull request #10758 from shuffle2/x64-on-arm64
Browse files Browse the repository at this point in the history
windows: detect and warn if running x64 dolphin on arm64
  • Loading branch information
delroth committed Jun 23, 2022
2 parents c8e7162 + 29ddd0e commit 2bd72df
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Source/Core/Common/x64CPUDetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@

#include "Common/CPUDetect.h"

#ifdef _WIN32
#include <processthreadsapi.h>
#endif

#include <cstring>
#include <string>
#include <thread>

#include "Common/CommonTypes.h"
#include "Common/Intrinsics.h"
#include "Common/MsgHandler.h"

#ifndef _WIN32

Expand Down Expand Up @@ -48,6 +53,29 @@ static u64 xgetbv(u32 index)
}
constexpr u32 XCR_XFEATURE_ENABLED_MASK = _XCR_XFEATURE_ENABLED_MASK;

static void WarnIfRunningUnderEmulation()
{
// Starting with win11, arm64 windows can run x64 processes under emulation.
// This detects such a scenario and informs the user they probably want to run a native build.
PROCESS_MACHINE_INFORMATION info{};
if (!GetProcessInformation(GetCurrentProcess(), ProcessMachineTypeInfo, &info, sizeof(info)))
{
// Possibly we are running on version of windows which doesn't support ProcessMachineTypeInfo.
return;
}
if (info.MachineAttributes & MACHINE_ATTRIBUTES::KernelEnabled)
{
// KernelEnabled will be set if process arch matches the kernel arch - how we want people to run
// dolphin.
return;
}

// The process is not native; could use IsWow64Process2 to get native machine type, but for now
// we can assume it is arm64.
PanicAlertFmtT("This build of Dolphin is not natively compiled for your CPU.\n"
"Please run the ARM64 build of Dolphin for a better experience.");
}

#else

static u64 xgetbv(u32 index)
Expand All @@ -69,6 +97,10 @@ CPUInfo::CPUInfo()
// Detects the various CPU features
void CPUInfo::Detect()
{
#ifdef _WIN32
WarnIfRunningUnderEmulation();
#endif

#ifdef _M_X86_64
Mode64bit = true;
OS64bit = true;
Expand Down

0 comments on commit 2bd72df

Please sign in to comment.