1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
4 using System.Diagnostics;
6 namespace System.Runtime.InteropServices
8 public static partial class RuntimeInformation
10 private static readonly object s_osLock = new object();
11 private static readonly object s_processLock = new object();
12 private static string? s_osPlatformName;
13 private static string? s_osDescription;
14 private static Architecture? s_osArch;
15 private static Architecture? s_processArch;
17 public static bool IsOSPlatform(OSPlatform osPlatform)
19 string name = s_osPlatformName ??= Interop.Sys.GetUnixName();
20 return osPlatform.Equals(name);
23 public static string OSDescription => s_osDescription ??= Interop.Sys.GetUnixVersion();
25 public static Architecture OSArchitecture
33 Interop.Sys.ProcessorArchitecture arch = (Interop.Sys.ProcessorArchitecture)Interop.Sys.GetOSArchitecture();
36 case Interop.Sys.ProcessorArchitecture.ARM:
37 s_osArch = Architecture.Arm;
40 case Interop.Sys.ProcessorArchitecture.x64:
41 s_osArch = Architecture.X64;
44 case Interop.Sys.ProcessorArchitecture.x86:
45 s_osArch = Architecture.X86;
48 case Interop.Sys.ProcessorArchitecture.ARM64:
49 s_osArch = Architecture.Arm64;
55 Debug.Assert(s_osArch != null);
56 return s_osArch.Value;
60 public static Architecture ProcessArchitecture
66 if (null == s_processArch)
68 Interop.Sys.ProcessorArchitecture arch = (Interop.Sys.ProcessorArchitecture)Interop.Sys.GetProcessArchitecture();
71 case Interop.Sys.ProcessorArchitecture.ARM:
72 s_processArch = Architecture.Arm;
75 case Interop.Sys.ProcessorArchitecture.x64:
76 s_processArch = Architecture.X64;
79 case Interop.Sys.ProcessorArchitecture.x86:
80 s_processArch = Architecture.X86;
83 case Interop.Sys.ProcessorArchitecture.ARM64:
84 s_processArch = Architecture.Arm64;
90 Debug.Assert(s_processArch != null);
91 return s_processArch.Value;