2 // RuntimeInformation.cs
5 // Alexander Köplinger (alexander.koeplinger@xamarin.com)
7 // (C) 2016 Xamarin, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Reflection
;
33 using System
.Runtime
.CompilerServices
;
35 namespace System
.Runtime
.InteropServices
37 public static class RuntimeInformation
39 static readonly Architecture _osArchitecture
;
40 static readonly Architecture _processArchitecture
;
41 static readonly OSPlatform _osPlatform
;
43 static RuntimeInformation ()
45 // we can use the runtime's compiled config options for DllMaps here
46 // process architecure for us is runtime architecture
47 // see for values: mono-config.c
48 var runtimeArchitecture
= GetRuntimeArchitecture ();
49 var osName
= GetOSName ();
51 // check OS/process architecture
52 switch (runtimeArchitecture
) {
54 _osArchitecture
= Environment
.Is64BitOperatingSystem
? Architecture
.Arm64
: Architecture
.Arm
;
55 _processArchitecture
= Architecture
.Arm
;
58 _osArchitecture
= Environment
.Is64BitOperatingSystem
? Architecture
.Arm64
: Architecture
.Arm
;
59 _processArchitecture
= Architecture
.Arm64
;
62 _osArchitecture
= Environment
.Is64BitOperatingSystem
? Architecture
.X64
: Architecture
.X86
;
63 _processArchitecture
= Architecture
.X86
;
66 _osArchitecture
= Environment
.Is64BitOperatingSystem
? Architecture
.X64
: Architecture
.X86
;
67 _processArchitecture
= Architecture
.X64
;
69 // upstream only has these values; try to pretend we're x86 if nothing matches
70 // want more? bug: https://github.com/dotnet/corefx/issues/30706
72 _osArchitecture
= Environment
.Is64BitOperatingSystem
? Architecture
.X64
: Architecture
.X86
;
73 _processArchitecture
= Environment
.Is64BitProcess
? Architecture
.X64
: Architecture
.X86
;
80 _osPlatform
= OSPlatform
.Linux
;
83 _osPlatform
= OSPlatform
.OSX
;
86 _osPlatform
= OSPlatform
.Windows
;
89 _osPlatform
= OSPlatform
.Create ("SOLARIS");
92 _osPlatform
= OSPlatform
.Create ("FREEBSD");
95 _osPlatform
= OSPlatform
.Create ("NETBSD");
98 _osPlatform
= OSPlatform
.Create ("OPENBSD");
101 _osPlatform
= OSPlatform
.Create ("AIX");
104 _osPlatform
= OSPlatform
.Create ("HPUX");
107 _osPlatform
= OSPlatform
.Create ("HAIKU");
110 _osPlatform
= OSPlatform
.Create ("WEBASSEMBLY");
113 _osPlatform
= OSPlatform
.Create ("UNKNOWN");
118 /* gets the runtime's arch from the value it uses for DllMap */
119 [MethodImpl (MethodImplOptions
.InternalCall
)]
120 static extern string GetRuntimeArchitecture ();
122 /* gets the runtime's OS from the value it uses for DllMap */
123 [MethodImpl (MethodImplOptions
.InternalCall
)]
124 static extern string GetOSName ();
126 public static string FrameworkDescription
{
128 return "Mono " + Mono
.Runtime
.GetDisplayName ();
132 public static bool IsOSPlatform (OSPlatform osPlatform
)
134 return _osPlatform
== osPlatform
;
137 public static string OSDescription
142 return "web"; //yes, hardcoded as right now we don't really support other environments
144 return Environment
.OSVersion
.VersionString
;
149 public static Architecture OSArchitecture
153 return _osArchitecture
;
157 public static Architecture ProcessArchitecture
161 return _processArchitecture
;