Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IMAGE_FILE_MACHINE_ARM64X and IMAGE_FILE_MACHINE_ARM64EC #2858

Merged
merged 9 commits into from
Sep 19, 2024
23 changes: 22 additions & 1 deletion diagnostics.sln
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "inc", "inc", "{41BDFD6D-D16
src\shared\inc\readytoruninstructionset.h = src\shared\inc\readytoruninstructionset.h
src\shared\inc\regdisp.h = src\shared\inc\regdisp.h
src\shared\inc\registrywrapper.h = src\shared\inc\registrywrapper.h
src\shared\inc\releaseholder.h = src\shared\inc\releaseholder.h
src\shared\inc\resource.h = src\shared\inc\resource.h
src\shared\inc\runtimeinfo.h = src\shared\inc\runtimeinfo.h
src\shared\inc\safemath.h = src\shared\inc\safemath.h
Expand Down Expand Up @@ -333,6 +332,26 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "minipal", "minipal", "{D9A9
src\shared\native\minipal\utils.h = src\shared\native\minipal\utils.h
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "inc", "inc", "{9E51C821-4095-4250-BD8A-2A29396DB1B4}"
ProjectSection(SolutionItems) = preProject
src\inc\corcompile.h = src\inc\corcompile.h
src\inc\ntimageex.h = src\inc\ntimageex.h
src\inc\releaseholder.h = src\inc\releaseholder.h
src\inc\stacktrace.h = src\inc\stacktrace.h
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "rt", "rt", "{D2D76252-D225-4B79-9DDB-A36867A4720E}"
ProjectSection(SolutionItems) = preProject
src\inc\rt\intsafe.h = src\inc\rt\intsafe.h
src\inc\rt\oaidl.h = src\inc\rt\oaidl.h
src\inc\rt\psapi.h = src\inc\rt\psapi.h
src\inc\rt\tchar.h = src\inc\rt\tchar.h
src\inc\rt\tlhelp32.h = src\inc\rt\tlhelp32.h
src\inc\rt\winapifamily.h = src\inc\rt\winapifamily.h
src\inc\rt\winternl.h = src\inc\rt\winternl.h
src\inc\rt\winver.h = src\inc\rt\winver.h
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Checked|Any CPU = Checked|Any CPU
Expand Down Expand Up @@ -2365,6 +2384,8 @@ Global
{06FB18BC-F4DD-4DB9-A566-551254CD1064} = {795B7A50-1B1F-406E-94E0-F9B35104EF22}
{641F00F0-2693-451B-A96A-13E4E115BF0F} = {7852EDE4-93DF-4DB1-8A86-C521703811AF}
{D9A91544-CDF8-4C68-BAD2-47F4968A8652} = {641F00F0-2693-451B-A96A-13E4E115BF0F}
{9E51C821-4095-4250-BD8A-2A29396DB1B4} = {19FAB78C-3351-4911-8F0C-8C6056401740}
{D2D76252-D225-4B79-9DDB-A36867A4720E} = {9E51C821-4095-4250-BD8A-2A29396DB1B4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46465737-C938-44FC-BE1A-4CE139EBB5E0}
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<MicrosoftDotNetCodeAnalysisVersion>10.0.0-beta.24459.1</MicrosoftDotNetCodeAnalysisVersion>
<StyleCopAnalyzersVersion>1.2.0-beta.406</StyleCopAnalyzersVersion>
<MicrosoftDotNetRemoteExecutorVersion>7.0.0-beta.22316.2</MicrosoftDotNetRemoteExecutorVersion>
<cdbsosversion>10.0.18362</cdbsosversion>
<cdbsosversion>10.0.26100.1</cdbsosversion>
<NewtonSoftJsonVersion>13.0.1</NewtonSoftJsonVersion>
<MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>10.0.0-alpha.1.24459.1</MicrosoftSourceBuildIntermediatesourcebuildreferencepackagesPackageVersion>
<!-- Roslyn and analyzers -->
Expand Down
4 changes: 2 additions & 2 deletions src/SOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ if(CLR_CMAKE_HOST_WIN32)
add_compile_options(/Zl) # omit default library name in .OBJ

add_subdirectory(runcommand)
if(NOT CLR_CMAKE_TARGET_ARCH_ARM64 AND NOT CLR_CMAKE_TARGET_ARCH_ARM)
if(NOT CLR_CMAKE_TARGET_ARCH_ARM)
add_subdirectory(SOS.UnitTests/Debuggees/DesktopClrHost)
endif(NOT CLR_CMAKE_TARGET_ARCH_ARM64 AND NOT CLR_CMAKE_TARGET_ARCH_ARM)
endif(NOT CLR_CMAKE_TARGET_ARCH_ARM)
endif(CLR_CMAKE_HOST_WIN32)

add_compile_definitions(STRESS_LOG_ANALYZER)
Expand Down
6 changes: 3 additions & 3 deletions src/SOS/SOS.Extensions/DebuggerServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public HResult GetDebuggeeType(out DEBUG_CLASS debugClass, out DEBUG_CLASS_QUALI
return VTable.GetDebuggeeType(Self, out debugClass, out qualifier);
}

public HResult GetExecutingProcessorType(out IMAGE_FILE_MACHINE type)
public HResult GetProcessorType(out IMAGE_FILE_MACHINE type)
mikem8361 marked this conversation as resolved.
Show resolved Hide resolved
{
return VTable.GetExecutingProcessorType(Self, out type);
return VTable.GetProcessorType(Self, out type);
}

public HResult AddCommand(string command, string help, IEnumerable<string> aliases)
Expand Down Expand Up @@ -519,7 +519,7 @@ private readonly unsafe struct IDebuggerServicesVTable
{
public readonly delegate* unmanaged[Stdcall]<IntPtr, out OperatingSystem, int> GetOperatingSystem;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out DEBUG_CLASS, out DEBUG_CLASS_QUALIFIER, int> GetDebuggeeType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out IMAGE_FILE_MACHINE, int> GetExecutingProcessorType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out IMAGE_FILE_MACHINE, int> GetProcessorType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, byte*, byte*, IntPtr*, int, int> AddCommand;
public readonly delegate* unmanaged[Stdcall]<IntPtr, DEBUG_OUTPUT, byte*, void> OutputString;
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, byte*, uint, out int, int> ReadVirtual;
Expand Down
5 changes: 3 additions & 2 deletions src/SOS/SOS.Extensions/TargetFromFromDebuggerServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ internal TargetFromDebuggerServices(DebuggerServices debuggerServices, IHost hos
IsDump = true;
}

hr = debuggerServices.GetExecutingProcessorType(out IMAGE_FILE_MACHINE type);
hr = debuggerServices.GetProcessorType(out IMAGE_FILE_MACHINE type);
if (hr == HResult.S_OK)
{
Debug.Assert(type is not IMAGE_FILE_MACHINE.ARM64X and not IMAGE_FILE_MACHINE.ARM64EC);
Architecture = type switch
{
IMAGE_FILE_MACHINE.I386 => Architecture.X86,
Expand All @@ -62,7 +63,7 @@ internal TargetFromDebuggerServices(DebuggerServices debuggerServices, IHost hos
}
else
{
throw new PlatformNotSupportedException($"GetExecutingProcessorType() FAILED {hr:X8}");
throw new PlatformNotSupportedException($"GetProcessorType() FAILED {hr:X8}");
}

hr = debuggerServices.GetCurrentProcessId(out uint processId);
Expand Down
2 changes: 1 addition & 1 deletion src/SOS/SOS.Hosting/DbgEng/DebugControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void AddDebugControl(VTableBuilder builder, SOSHost soshost)
builder.AddMethod(new GetReturnOffsetDelegate((self, offset) => DebugClient.NotImplemented));
builder.AddMethod(new OutputStackTraceDelegate((self, outputControl, frames, frameSize, flags) => DebugClient.NotImplemented));
builder.AddMethod(new GetDebuggeeTypeDelegate(soshost.GetDebuggeeType));
builder.AddMethod(new GetActualProcessorTypeDelegate((self, type) => DebugClient.NotImplemented));
builder.AddMethod(new GetActualProcessorTypeDelegate(soshost.GetExecutingProcessorType));
builder.AddMethod(new GetExecutingProcessorTypeDelegate(soshost.GetExecutingProcessorType));
builder.AddMethod(new GetNumberPossibleExecutingProcessorTypesDelegate((self, number) => DebugClient.NotImplemented));
builder.AddMethod(new GetPossibleExecutingProcessorTypesDelegate((self, start, count, types) => DebugClient.NotImplemented));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public enum IMAGE_FILE_MACHINE : uint
AMD64 = 0x8664, // AMD64 (K8)
M32R = 0x9041, // M32R little-endian
ARM64 = 0xAA64, // ARM64 Little-endian
ARM64EC = 0xA641,
ARM64X = 0xA64E,
CEE = 0xC0EE,
LOONGARCH64 = 0x6264,
RISCV64 = 0x5064
Expand Down
34 changes: 10 additions & 24 deletions src/SOS/SOS.Hosting/SOSHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,30 +165,16 @@ internal unsafe int GetExecutingProcessorType(
IntPtr self,
IMAGE_FILE_MACHINE* type)
{
switch (Target.Architecture)
{
case Architecture.X64:
*type = IMAGE_FILE_MACHINE.AMD64;
break;
case Architecture.X86:
*type = IMAGE_FILE_MACHINE.I386;
break;
case Architecture.Arm:
*type = IMAGE_FILE_MACHINE.ARMNT;
break;
case Architecture.Arm64:
*type = IMAGE_FILE_MACHINE.ARM64;
break;
case (Architecture)6 /* Architecture.LoongArch64 */:
*type = IMAGE_FILE_MACHINE.LOONGARCH64;
break;
case (Architecture)9 /* Architecture.RiscV64 */:
*type = IMAGE_FILE_MACHINE.RISCV64;
break;
default:
*type = IMAGE_FILE_MACHINE.UNKNOWN;
break;
}
*type = Target.Architecture switch
{
Architecture.X64 => IMAGE_FILE_MACHINE.AMD64,
Architecture.X86 => IMAGE_FILE_MACHINE.I386,
Architecture.Arm => IMAGE_FILE_MACHINE.ARMNT,
Architecture.Arm64 => IMAGE_FILE_MACHINE.ARM64,
(Architecture)6 /* Architecture.LoongArch64 */=> IMAGE_FILE_MACHINE.LOONGARCH64,
(Architecture)9 /* Architecture.RiscV64 */=> IMAGE_FILE_MACHINE.RISCV64,
_ => IMAGE_FILE_MACHINE.UNKNOWN,
};
return HResult.S_OK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<Option>
<SetHostRuntime>$(DotNetRoot)/shared/Microsoft.NETCore.App/$(RuntimeFrameworkVersion)</SetHostRuntime>
</Option>
<Option>
<Option Condition="'$(TargetArchitecture)' != 'arm64'">
<SetHostRuntime>-netfx</SetHostRuntime>
</Option>
</Options>
Expand Down
20 changes: 0 additions & 20 deletions src/SOS/Strike/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ if(CLR_CMAKE_HOST_ARCH_AMD64)
message(STATUS "CLR_CMAKE_HOST_ARCH_AMD64")
add_definitions(-DSOS_TARGET_AMD64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_AMD64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
if (CLR_CMAKE_HOST_WIN32)
add_definitions(-DSOS_TARGET_ARM64=1)
endif(CLR_CMAKE_HOST_WIN32)
Expand All @@ -43,43 +40,26 @@ elseif(CLR_CMAKE_HOST_ARCH_I386)
add_definitions(-DSOS_TARGET_X86=1)
add_definitions(-D_TARGET_X86_=1)
add_definitions(-DTARGET_X86)
add_definitions(-DDBG_TARGET_X86=1)
add_definitions(-DDBG_TARGET_32BIT=1)
if (CLR_CMAKE_HOST_WIN32)
add_definitions(-DSOS_TARGET_ARM=1)
endif(CLR_CMAKE_HOST_WIN32)
elseif(CLR_CMAKE_HOST_ARCH_ARM)
message(STATUS "CLR_CMAKE_HOST_ARCH_ARM")
add_definitions(-DSOS_TARGET_ARM=1)
add_definitions(-D_TARGET_WIN32_=1)
add_definitions(-D_TARGET_ARM_=1)
add_definitions(-DDBG_TARGET_ARM=1)
add_definitions(-DDBG_TARGET_32BIT=1)
elseif(CLR_CMAKE_HOST_ARCH_ARM64)
message(STATUS "CLR_CMAKE_HOST_ARCH_ARM64")
add_definitions(-DSOS_TARGET_ARM64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_ARM64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
elseif(CLR_CMAKE_HOST_ARCH_MIPS64)
add_definitions(-DSOS_TARGET_MIPS64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_MIPS64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
elseif(CLR_CMAKE_HOST_ARCH_RISCV64)
add_definitions(-DSOS_TARGET_RISCV64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_RISCV64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
elseif(CLR_CMAKE_HOST_ARCH_LOONGARCH64)
add_definitions(-DSOS_TARGET_LOONGARCH64=1)
add_definitions(-D_TARGET_WIN64_=1)
add_definitions(-DDBG_TARGET_64BIT=1)
add_definitions(-DDBG_TARGET_LOONGARCH64=1)
add_definitions(-DDBG_TARGET_WIN64=1)
endif()

add_definitions(-DSTRIKE)
Expand Down
4 changes: 3 additions & 1 deletion src/SOS/Strike/clrma/managedanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ ClrmaManagedAnalysis::QueryDebugClient(IUnknown* pUnknown)
}
switch (m_processorType)
{
case IMAGE_FILE_MACHINE_ARM64:
case IMAGE_FILE_MACHINE_AMD64:
case IMAGE_FILE_MACHINE_ARM64:
case IMAGE_FILE_MACHINE_ARM64X:
case IMAGE_FILE_MACHINE_ARM64EC:
case IMAGE_FILE_MACHINE_LOONGARCH64:
case IMAGE_FILE_MACHINE_RISCV64:
m_pointerSize = 8;
Expand Down
9 changes: 1 addition & 8 deletions src/SOS/Strike/clrma/managedanalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <clrma.h> // IDL
#include <clrmaservice.h>
#include <dbgtargetcontext.h>
#include <ntimageex.h>
#include <corhdr.h>
#include <cordebug.h>
#include <xclrdata.h>
Expand All @@ -21,14 +22,6 @@
#include <runtime.h>
#include <vector>

#ifndef IMAGE_FILE_MACHINE_RISCV64
#define IMAGE_FILE_MACHINE_RISCV64 0x5064 // RISCV64
#endif

#ifndef IMAGE_FILE_MACHINE_LOONGARCH64
#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 // LOONGARCH64
#endif

enum ClrmaGlobalFlags
{
LoggingEnabled = 0x01, // CLRMA logging enabled
Expand Down
18 changes: 16 additions & 2 deletions src/SOS/Strike/dbgengservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,24 @@ DbgEngServices::GetDebuggeeType(
}

HRESULT
DbgEngServices::GetExecutingProcessorType(
DbgEngServices::GetProcessorType(
PULONG type)
{
return m_control->GetExecutingProcessorType(type);
ULONG executingType;
HRESULT hr = m_control->GetExecutingProcessorType(&executingType);
if (FAILED(hr))
{
return hr;
}
_ASSERTE(executingType != IMAGE_FILE_MACHINE_ARM64X);
*type = executingType;
#if defined(SOS_TARGET_AMD64) || defined(SOS_TARGET_ARM64)
if (executingType == IMAGE_FILE_MACHINE_ARM64EC)
{
*type = IMAGE_FILE_MACHINE_AMD64;
}
#endif // defined(SOS_TARGET_AMD64) || defined(SOS_TARGET_ARM64)
return S_OK;
}

HRESULT
Expand Down
2 changes: 1 addition & 1 deletion src/SOS/Strike/dbgengservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DbgEngServices : public IDebuggerServices, public IRemoteMemoryService, pu
PULONG debugClass,
PULONG qualifier);

HRESULT STDMETHODCALLTYPE GetExecutingProcessorType(
HRESULT STDMETHODCALLTYPE GetProcessorType(
PULONG type);

HRESULT STDMETHODCALLTYPE AddCommand(
Expand Down
9 changes: 8 additions & 1 deletion src/SOS/Strike/disasmX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,14 @@ void
//

#ifdef _WIN64
ExtOut("%08x`%08x ", (ULONG)(InstrAddr >> 32), (ULONG)InstrAddr);
if (GetHost()->GetHostType() == IHost::HostType::DbgEng)
{
ExtOut("%08x`%08x ", (ULONG)(InstrAddr >> 32), (ULONG)InstrAddr);
}
else
{
ExtOut("%016llx ", InstrAddr);
}
#else
ExtOut("%08x ", (ULONG)InstrAddr);
#endif
Expand Down
Loading
Loading