Skip to content

Commit

Permalink
Add IMAGE_FILE_MACHINE_ARM64X and IMAGE_FILE_MACHINE_ARM64EC
Browse files Browse the repository at this point in the history
  • Loading branch information
hoyosjs authored and mikem8361 committed Sep 3, 2024
1 parent 73f3a28 commit 7daba79
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 62 deletions.
2 changes: 2 additions & 0 deletions src/SOS/SOS.Extensions/TargetFromFromDebuggerServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ internal TargetFromDebuggerServices(DebuggerServices debuggerServices, IHost hos
IMAGE_FILE_MACHINE.ARMNT => Architecture.Arm,
IMAGE_FILE_MACHINE.AMD64 => Architecture.X64,
IMAGE_FILE_MACHINE.ARM64 => Architecture.Arm64,
IMAGE_FILE_MACHINE.ARM64X => Architecture.Arm64,
IMAGE_FILE_MACHINE.ARM64EC => Architecture.Arm64,
IMAGE_FILE_MACHINE.LOONGARCH64 => (Architecture)6 /* Architecture.LoongArch64 */,
IMAGE_FILE_MACHINE.RISCV64 => (Architecture)9 /* Architecture.RiscV64 */,
_ => throw new PlatformNotSupportedException($"Machine type not supported: {type}"),
Expand Down
2 changes: 2 additions & 0 deletions src/SOS/SOS.Hosting/DbgEng/Interop/Enums/ImageFileMachine.cs
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
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
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
10 changes: 8 additions & 2 deletions src/SOS/Strike/exts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@ GetTargetMachine(ULONG processorType)
}
#endif // SOS_TARGET_ARM
#ifdef SOS_TARGET_ARM64
if (processorType == IMAGE_FILE_MACHINE_ARM64)
switch (processorType)
{
targetMachine = ARM64Machine::GetInstance();
case IMAGE_FILE_MACHINE_ARM64:
case IMAGE_FILE_MACHINE_ARM64X:
case IMAGE_FILE_MACHINE_ARM64EC:
targetMachine = ARM64Machine::GetInstance();
break;
}
#endif // SOS_TARGET_ARM64
#ifdef SOS_TARGET_RISCV64
Expand Down Expand Up @@ -191,6 +195,8 @@ ArchQuery(void)
architecture = "arm32";
break;
case IMAGE_FILE_MACHINE_ARM64:
case IMAGE_FILE_MACHINE_ARM64EC:
case IMAGE_FILE_MACHINE_ARM64X:
architecture = "arm64";
break;
case IMAGE_FILE_MACHINE_RISCV64:
Expand Down
10 changes: 1 addition & 9 deletions src/SOS/Strike/exts.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@
// printing CDA values.
#define CDA_TO_UL64(cda) ((ULONG64)(TO_TADDR(cda)))

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

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

typedef struct _TADDR_RANGE
{
TADDR start;
Expand Down Expand Up @@ -417,7 +409,7 @@ extern IMachine* g_targetMachine;
inline BOOL IsDbgTargetX86() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_I386; }
inline BOOL IsDbgTargetAmd64() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_AMD64; }
inline BOOL IsDbgTargetArm() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARMNT; }
inline BOOL IsDbgTargetArm64() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARM64; }
inline BOOL IsDbgTargetArm64() { return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARM64 || g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARM64EC || g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_ARM64X; }
inline BOOL IsDbgTargetRiscV64(){ return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_RISCV64; }
inline BOOL IsDbgTargetLoongArch64(){ return g_targetMachine->GetPlatform() == IMAGE_FILE_MACHINE_LOONGARCH64; }
inline BOOL IsDbgTargetWin64() { return IsDbgTargetAmd64(); }
Expand Down
9 changes: 1 addition & 8 deletions src/SOS/Strike/platformspecific.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// The main debugger code already has target platform definitions for CONTEXT.
#include <dbgtargetcontext.h>
#include <ntimageex.h>

#ifndef FEATURE_PAL

Expand Down Expand Up @@ -42,14 +43,6 @@ struct DT_UNICODE_STRING
#define DT_GDI_HANDLE_BUFFER_SIZE32 34
#define DT_GDI_HANDLE_BUFFER_SIZE64 60

#ifndef IMAGE_FILE_MACHINE_ARMNT
#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian
#endif

#ifndef IMAGE_FILE_MACHINE_ARM64
#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian
#endif

#ifdef _TARGET_WIN64_
typedef ULONG DT_GDI_HANDLE_BUFFER[DT_GDI_HANDLE_BUFFER_SIZE64];
#else
Expand Down
19 changes: 10 additions & 9 deletions src/dbgshim/debugshim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@
#include "dbgutil.h"
#include <crtdbg.h>
#include <clrinternal.h> //has the CLR_ID_V4_DESKTOP guid in it
#include <ntimageex.h>
#include "palclr.h"

#ifndef IMAGE_FILE_MACHINE_ARMNT
#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian
#endif

#ifndef IMAGE_FILE_MACHINE_ARM64
#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian
#endif

//*****************************************************************************
// CLRDebuggingImpl implementation (ICLRDebugging)
//*****************************************************************************
Expand Down Expand Up @@ -789,10 +782,18 @@ HRESULT CLRDebuggingImpl::FormatLongDacModuleName(_Inout_updates_z_(cchBuffer) W
{
pTargetArch = W("arm");
}
else if(targetImageFileMachine == IMAGE_FILE_MACHINE_ARM64)
else if(targetImageFileMachine == IMAGE_FILE_MACHINE_ARM64 || targetImageFileMachine == IMAGE_FILE_MACHINE_ARM64X || targetImageFileMachine == IMAGE_FILE_MACHINE_ARM64EC)
{
pTargetArch = W("arm64");
}
else if (targetImageFileMachine == IMAGE_FILE_MACHINE_RISCV64)
{
pTargetArch = W("riscv64");
}
else if (targetImageFileMachine == IMAGE_FILE_MACHINE_LOONGARCH64)
{
pTargetArch = W("loongarch64");
}
else
{
_ASSERTE(!"Unknown target image file machine type");
Expand Down
29 changes: 29 additions & 0 deletions src/inc/ntimageex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma once

#ifndef IMAGE_FILE_MACHINE_ARMNT
#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian
#endif

#ifndef IMAGE_FILE_MACHINE_ARM64
#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian
#endif

#ifndef IMAGE_FILE_MACHINE_ARM64EC
#define IMAGE_FILE_MACHINE_ARM64EC 0xA641
#endif

#ifndef IMAGE_FILE_MACHINE_ARM64X
#define IMAGE_FILE_MACHINE_ARM64X 0xA64E
#endif

#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

0 comments on commit 7daba79

Please sign in to comment.