Skip to content

Commit

Permalink
Detect Arm/Arm64 in RuntimeInformation
Browse files Browse the repository at this point in the history
	* For ProcessArchitecture, use the DllMap arch of the runtime.

	* For OSArchitecture, make an educated guess combining
	  ProcessArchitecture and Environment.Is64BitOperatingSystem.

	* For non-Intel/ARM architectures, (supported by Mono and not
	  on the chopping block are PPC32/64, z, and WebAssembly)
	  please dogpile onto dotnet/corefx#30706.
  • Loading branch information
NattyNarwhal committed Aug 14, 2018
1 parent 2bf8bb5 commit 048be40
Showing 1 changed file with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace System.Runtime.InteropServices
{
public static class RuntimeInformation
{
[DllImport("__Internal", CharSet = CharSet.Auto)]
static extern string mono_config_get_cpu ();

public static string FrameworkDescription {
get {
return "Mono " + Mono.Runtime.GetDisplayName ();
Expand Down Expand Up @@ -75,17 +78,40 @@ public static Architecture OSArchitecture
{
get
{
// TODO: very barebones implementation, doesn't respect ARM
return Environment.Is64BitOperatingSystem ? Architecture.X64 : Architecture.X86;
switch (mono_config_get_cpu ()) {
case "arm":
case "armv8":
return Environment.Is64BitOperatingSystem ? Architecture.Arm64 : Architecture.Arm;
case "x86":
case "x86-64":
// upstream only has these values; try to pretend we're x86 if nothing matches
// want more? bug: https://github.com/dotnet/corefx/issues/30706
default:
return Environment.Is64BitOperatingSystem ? Architecture.X64 : Architecture.X86;
}
}
}

public static Architecture ProcessArchitecture
{
get
{
// TODO: very barebones implementation, doesn't respect ARM
return Environment.Is64BitProcess ? Architecture.X64 : Architecture.X86;
// we can use the runtime's compiled config options for DllMaps here
// process architecure for us is runtime architecture (OS is much harder)
// see for values: mono-config.c
switch (mono_config_get_cpu ()) {
case "x86":
return Architecture.X86;
case "x86-64":
return Architecture.X64;
case "arm":
return Architecture.Arm;
case "armv8":
return Architecture.Arm64;
// see comment in OSArchiteture default case
default:
return Environment.Is64BitProcess ? Architecture.X64 : Architecture.X86;
}
}
}
}
Expand Down

0 comments on commit 048be40

Please sign in to comment.