Skip to content

Commit 04939b5

Browse files
committed
feat: Add Windows ARM64 support
Fixed the process architecture to host image machine type code. Now ARM64 `.dll`s should be loadable by MemoryModule.
1 parent 54df80c commit 04939b5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

MemoryModule/Windows/Image.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public static class Image
1111
public const int NTSignature = 0x00004550;
1212
public const int FileMachinei386 = 0x14c;
1313
public const int FileMachineAMD64 = 0x8664;
14+
public const int FileMachineARMv7 = 0x01c4;
15+
public const int FileMachineARM64 = 0xaa64;
1416
public const int FileDll = 0x2000;
1517
public const int SizeOfBaseRelocation = 8;
1618
public const ulong OrdinalFlag64 = 0x8000000000000000;

MemoryModule/Windows/NativeAssemblyImpl.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,22 @@ internal static bool MemoryDefaultFreeLibrary(void* module, void* userdata)
186186
}
187187
#endregion
188188

189-
private static readonly uint HostMachine =
190-
(uint)(Environment.Is64BitProcess ?
191-
Image.FileMachineAMD64 :
192-
Image.FileMachinei386);
189+
private static readonly uint HostMachine = ((Func<uint>)(() =>
190+
{
191+
switch (RuntimeInformation.ProcessArchitecture)
192+
{
193+
case Architecture.X86:
194+
return Image.FileMachinei386;
195+
case Architecture.X64:
196+
return Image.FileMachineAMD64;
197+
case Architecture.Arm:
198+
return Image.FileMachineARMv7;
199+
case Architecture.Arm64:
200+
return Image.FileMachineARM64;
201+
default:
202+
throw new PlatformNotSupportedException();
203+
}
204+
}))();
193205

194206
// Protection flags for memory pages (Executable, Readable, Writeable)
195207
private static readonly PageProtection[][][] ProtectionFlags = new PageProtection[][][]

0 commit comments

Comments
 (0)