1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Diagnostics; 6 7 namespace System.Runtime.InteropServices 8 { 9 public static partial class RuntimeInformation 10 { 11 private static readonly object s_osLock = new object(); 12 private static readonly object s_processLock = new object(); 13 private static readonly bool s_is64BitProcess = IntPtr.Size == 8; 14 private static string s_osPlatformName; 15 private static string s_osDescription; 16 private static Architecture? s_osArch; 17 private static Architecture? s_processArch; 18 IsOSPlatform(OSPlatform osPlatform)19 public static bool IsOSPlatform(OSPlatform osPlatform) 20 { 21 string name = s_osPlatformName ?? (s_osPlatformName = Interop.Sys.GetUnixName()); 22 return osPlatform.Equals(name); 23 } 24 25 public static string OSDescription 26 { 27 get 28 { 29 if (null == s_osDescription) 30 { 31 s_osDescription = Interop.Sys.GetUnixVersion(); 32 } 33 34 return s_osDescription; 35 } 36 } 37 38 public static Architecture OSArchitecture 39 { 40 get 41 { 42 lock (s_osLock) 43 { 44 if (null == s_osArch) 45 { 46 Interop.Sys.ProcessorArchitecture arch = (Interop.Sys.ProcessorArchitecture)Interop.Sys.GetOSArchitecture(); 47 switch (arch) 48 { 49 case Interop.Sys.ProcessorArchitecture.ARM: 50 s_osArch = Architecture.Arm; 51 break; 52 53 case Interop.Sys.ProcessorArchitecture.x64: 54 s_osArch = Architecture.X64; 55 break; 56 57 case Interop.Sys.ProcessorArchitecture.x86: 58 s_osArch = Architecture.X86; 59 break; 60 61 case Interop.Sys.ProcessorArchitecture.ARM64: 62 s_osArch = Architecture.Arm64; 63 break; 64 } 65 } 66 } 67 68 Debug.Assert(s_osArch != null); 69 return s_osArch.Value; 70 } 71 } 72 73 public static Architecture ProcessArchitecture 74 { 75 get 76 { 77 lock (s_processLock) 78 { 79 if (null == s_processArch) 80 { 81 Interop.Sys.ProcessorArchitecture arch = (Interop.Sys.ProcessorArchitecture)Interop.Sys.GetProcessArchitecture(); 82 switch (arch) 83 { 84 case Interop.Sys.ProcessorArchitecture.ARM: 85 s_processArch = Architecture.Arm; 86 break; 87 88 case Interop.Sys.ProcessorArchitecture.x64: 89 s_processArch = Architecture.X64; 90 break; 91 92 case Interop.Sys.ProcessorArchitecture.x86: 93 s_processArch = Architecture.X86; 94 break; 95 96 case Interop.Sys.ProcessorArchitecture.ARM64: 97 s_processArch = Architecture.Arm64; 98 break; 99 } 100 } 101 } 102 103 Debug.Assert(s_processArch != null); 104 return s_processArch.Value; 105 } 106 } 107 } 108 } 109