Skip to content

Commit

Permalink
Set os.name properly based on OS.
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed Sep 9, 2023
1 parent f31126a commit deb1de0
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions src/IKVM.Runtime/JVM.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
Expand Down Expand Up @@ -359,8 +360,6 @@ static void GetOSProperties(out string osname, out string osversion)

if (RuntimeUtil.IsWindows)
{
const byte VER_NT_DOMAIN_CONTROLLER = 0x0000002;
const byte VER_NT_SERVER = 0x0000003;
const byte VER_NT_WORKSTATION = 0x0000001;

var os = Environment.OSVersion;
Expand Down Expand Up @@ -539,22 +538,47 @@ static void GetOSProperties(out string osname, out string osversion)
/// Gets the platform architecture.
/// </summary>
/// <returns></returns>
static string GetArch()
static unsafe string GetArch()
{
var arch = SafeGetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
if (arch == null)
#if FIRST_PASS || IMPORTER || EXPORTER
throw new NotSupportedException();
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// guess based on OS and bit size
if (IntPtr.Size == 4)
return RuntimeUtil.IsWindows ? "x86" : "i386";
else
return "amd64";
return RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => "amd64",
Architecture.X86 => "x86",
Architecture.Arm => "arm",
Architecture.Arm64 => "arm64",
_ => "unknown",
};
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => "amd64",
Architecture.X86 => "i386",
Architecture.Arm => "arm",
Architecture.Arm64 => "aarch64",
_ => "unknown",
};
}

if (arch.Equals("AMD64", StringComparison.OrdinalIgnoreCase))
return "amd64";
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => "x86_64",
Architecture.Arm64 => "aarch64",
_ => "unknown",
};
}

return null;
return "unknown";
#endif
}

/// <summary>
Expand Down

0 comments on commit deb1de0

Please sign in to comment.