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 string? s_osDescription;
11 private static readonly object s_osLock = new object();
12 private static readonly object s_processLock = new object();
13 private static Architecture? s_osArch;
14 private static Architecture? s_processArch;
16 public static bool IsOSPlatform(OSPlatform osPlatform)
18 return OSPlatform.Windows == osPlatform;
21 public static string OSDescription
25 string? osDescription = s_osDescription;
26 if (osDescription is null)
28 OperatingSystem os = Environment.OSVersion;
29 Version v = os.Version;
31 const string Version = "Microsoft Windows";
32 s_osDescription = osDescription = string.IsNullOrEmpty(os.ServicePack) ?
33 $"{Version} {(uint)v.Major}.{(uint)v.Minor}.{(uint)v.Build}" :
34 $"{Version} {(uint)v.Major}.{(uint)v.Minor}.{(uint)v.Build} {os.ServicePack}";
41 public static Architecture OSArchitecture
49 Interop.Kernel32.SYSTEM_INFO sysInfo;
50 Interop.Kernel32.GetNativeSystemInfo(out sysInfo);
52 switch ((Interop.Kernel32.ProcessorArchitecture)sysInfo.wProcessorArchitecture)
54 case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_ARM64:
55 s_osArch = Architecture.Arm64;
57 case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_ARM:
58 s_osArch = Architecture.Arm;
60 case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_AMD64:
61 s_osArch = Architecture.X64;
63 case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_INTEL:
64 s_osArch = Architecture.X86;
71 Debug.Assert(s_osArch != null);
72 return s_osArch.Value;
76 public static Architecture ProcessArchitecture
82 if (null == s_processArch)
84 Interop.Kernel32.SYSTEM_INFO sysInfo;
85 Interop.Kernel32.GetSystemInfo(out sysInfo);
87 switch ((Interop.Kernel32.ProcessorArchitecture)sysInfo.wProcessorArchitecture)
89 case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_ARM64:
90 s_processArch = Architecture.Arm64;
92 case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_ARM:
93 s_processArch = Architecture.Arm;
95 case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_AMD64:
96 s_processArch = Architecture.X64;
98 case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_INTEL:
99 s_processArch = Architecture.X86;
105 Debug.Assert(s_processArch != null);
106 return s_processArch.Value;