Move System.Runtime.InteropServices.RuntimeInformation to CoreLib (#63140)
authorJan Kotas <jkotas@microsoft.com>
Mon, 27 Dec 2021 18:07:34 +0000 (08:07 -1000)
committerGitHub <noreply@github.com>
Mon, 27 Dec 2021 18:07:34 +0000 (10:07 -0800)
- Makes RuntimeInformation.ProcessArchitecture a JIT/AOT-time constant (constant returning property)
- Eliminates tiny netcoreapp assembly with just a few types

Fixes #57152
Contributes to #2138

28 files changed:
src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
src/coreclr/nativeaot/Directory.Build.props
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetProcessArchitecture.cs [deleted file]
src/libraries/Common/src/Interop/Unix/System.Native/Interop.ProcessorArchitecture.cs [deleted file]
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SYSTEM_INFO.cs
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/ApplicationId.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Architecture.cs [moved from src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/Architecture.cs with 100% similarity]
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/OSPlatform.cs [moved from src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs with 97% similarity]
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Browser.cs [moved from src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.Browser.cs with 82% similarity]
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.ProcessArchitecture.cs [new file with mode: 0644]
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Unix.cs [new file with mode: 0644]
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Windows.cs [moved from src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.Windows.cs with 54% similarity]
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.cs [moved from src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs with 100% similarity]
src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs
src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.Forwards.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.cs [deleted file]
src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.csproj
src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/Resources/Strings.resx [deleted file]
src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System.Runtime.InteropServices.RuntimeInformation.csproj
src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.Unix.cs [deleted file]
src/libraries/System.Runtime/ref/System.Runtime.cs
src/libraries/System.Threading.AccessControl/src/Resources/Strings.resx
src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj
src/native/libs/System.Native/entrypoints.c
src/native/libs/System.Native/pal_runtimeinformation.c
src/native/libs/System.Native/pal_runtimeinformation.h

index fd9a326..f62c8b9 100644 (file)
@@ -68,6 +68,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Platform)' == 'x86'">
     <PlatformTarget>x86</PlatformTarget>
+    <DefineConstants>$(DefineConstants);TARGET_X86</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Platform)' == 'arm'">
     <PlatformTarget>arm</PlatformTarget>
index 8807dca..dddbec1 100644 (file)
@@ -70,7 +70,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Platform)' == 'x86'">
     <PlatformTarget>x86</PlatformTarget>
-    <DefineConstants>TARGET_32BIT;$(DefineConstants)</DefineConstants>
+    <DefineConstants>TARGET_32BIT;TARGET_X86;$(DefineConstants)</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Platform)' == 'arm'">
     <PlatformTarget>arm</PlatformTarget>
diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetProcessArchitecture.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetProcessArchitecture.cs
deleted file mode 100644 (file)
index 2086b4a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
-    internal static partial class Sys
-    {
-        [SuppressGCTransition]
-        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetProcessArchitecture")]
-        internal static partial int GetProcessArchitecture();
-    }
-}
diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.ProcessorArchitecture.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.ProcessorArchitecture.cs
deleted file mode 100644 (file)
index 8b1ad55..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
-    internal static partial class Sys
-    {
-        internal enum ProcessorArchitecture
-        {
-            x86,
-            x64,
-            ARM,
-            ARM64,
-            WASM,
-            S390x
-        }
-    }
-}
index 097c8a3..00c42fc 100644 (file)
@@ -24,14 +24,9 @@ internal static partial class Interop
             internal short wProcessorRevision;
         }
 
-        internal enum ProcessorArchitecture : ushort
-        {
-            Processor_Architecture_INTEL = 0,
-            Processor_Architecture_ARM = 5,
-            Processor_Architecture_IA64 = 6,
-            Processor_Architecture_AMD64 = 9,
-            Processor_Architecture_ARM64 = 12,
-            Processor_Architecture_UNKNOWN = 0xFFFF
-        }
+        internal const int PROCESSOR_ARCHITECTURE_INTEL = 0;
+        internal const int PROCESSOR_ARCHITECTURE_ARM = 5;
+        internal const int PROCESSOR_ARCHITECTURE_AMD64 = 9;
+        internal const int PROCESSOR_ARCHITECTURE_ARM64 = 12;
     }
 }
index 8e4ff90..57a9c28 100644 (file)
   <data name="Argument_BadResourceScopeVisibilityBits" xml:space="preserve">
     <value>Unknown value for the ResourceScope: {0}  Too many resource visibility bits may be set.</value>
   </data>
-  <data name="net_emptystringcall" xml:space="preserve">
-    <value>The parameter '{0}' cannot be an empty string.</value>
-  </data>
-  <data name="Argument_EmptyApplicationName" xml:space="preserve">
-    <value>ApplicationId cannot have an empty string for the name.</value>
+  <data name="Argument_EmptyString" xml:space="preserve">
+    <value>The value cannot be an empty string.</value>
   </data>
   <data name="Argument_FrameworkNameInvalid" xml:space="preserve">
     <value> FrameworkName is invalid.</value>
index bfee74c..24b049b 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\ExceptionServices\HandleProcessCorruptedStateExceptionsAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\GCSettings.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\AllowReversePInvokeCallsAttribute.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Architecture.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ArrayWithOffset.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\BestFitMappingAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\BStrWrapper.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MarshalDirectiveException.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MemoryMarshal.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeMemory.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OSPlatform.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedCallConvAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeLibrary.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\PosixSignalRegistration.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\PreserveSigAttribute.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\ProgIdAttribute.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\RuntimeInformation.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\RuntimeInformation.ProcessArchitecture.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeArrayRankMismatchException.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeArrayTypeMismatchException.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\SafeBuffer.cs" />
     <Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetModuleFileName.cs">
       <Link>Common\Interop\Windows\Kernel32\Interop.GetModuleFileName.cs</Link>
     </Compile>
+    <Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetNativeSystemInfo.cs">
+      <Link>Common\Interop\Windows\Kernel32\Interop.GetNativeSystemInfo.cs</Link>
+    </Compile>
     <Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetOverlappedResult.cs">
       <Link>Common\Interop\Windows\Kernel32\Interop.GetOverlappedResult.cs</Link>
     </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeMemory.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\PosixSignalRegistration.Windows.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\RuntimeInformation.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StandardOleMarshalObject.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Windows.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelMonitor.Windows.cs" />
     <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetHostName.cs">
       <Link>Common\Interop\Unix\System.Native\Interop.GetHostName.cs</Link>
     </Compile>
+    <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetOSArchitecture.cs">
+      <Link>Common\Interop\Unix\System.Native\Interop.GetOSArchitecture.cs</Link>
+    </Compile>
     <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetProcessPath.cs">
       <Link>Common\Interop\Unix\System.Native\Interop.GetProcessPath.cs</Link>
     </Compile>
     <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetUnixName.cs">
       <Link>Common\Interop\Unix\System.Native\Interop.GetUnixName.cs</Link>
     </Compile>
+    <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetUnixVersion.cs">
+      <Link>Common\Interop\Unix\System.Native\Interop.GetUnixVersion.cs</Link>
+    </Compile>
     <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetUnixRelease.cs">
       <Link>Common\Interop\Unix\System.Native\Interop.GetUnixRelease.cs</Link>
     </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\MemoryFailPoint.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeMemory.Unix.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\RuntimeInformation.Unix.cs" Condition="'$(TargetsBrowser)' != 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\StandardOleMarshalObject.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelMonitor.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Environment.Browser.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Browser.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\PersistedFiles.Browser.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\RuntimeInformation.Browser.cs" />
   </ItemGroup>
   <ItemGroup Condition="'$(UseMinimalGlobalizationData)' == 'true'">
     <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.MinimalGlobalizationData.cs" />
index 97c6338..ed537c2 100644 (file)
@@ -13,7 +13,7 @@ namespace System
         public ApplicationId(byte[] publicKeyToken, string name, Version version, string? processorArchitecture, string? culture)
         {
             if (name == null) throw new ArgumentNullException(nameof(name));
-            if (name.Length == 0) throw new ArgumentException(SR.Argument_EmptyApplicationName);
+            if (name.Length == 0) throw new ArgumentException(SR.Argument_EmptyString, nameof(name));
             if (version == null) throw new ArgumentNullException(nameof(version));
             if (publicKeyToken == null) throw new ArgumentNullException(nameof(publicKeyToken));
 
@@ -20,7 +20,7 @@ namespace System.Runtime.InteropServices
         private OSPlatform(string osPlatform)
         {
             if (osPlatform == null) throw new ArgumentNullException(nameof(osPlatform));
-            if (osPlatform.Length == 0) throw new ArgumentException(SR.Argument_EmptyValue, nameof(osPlatform));
+            if (osPlatform.Length == 0) throw new ArgumentException(SR.Argument_EmptyString, nameof(osPlatform));
 
             Name = osPlatform;
         }
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.ProcessArchitecture.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.ProcessArchitecture.cs
new file mode 100644 (file)
index 0000000..298d039
--- /dev/null
@@ -0,0 +1,25 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace System.Runtime.InteropServices
+{
+    public static partial class RuntimeInformation
+    {
+        public static Architecture ProcessArchitecture
+#if TARGET_X86
+            => Architecture.X86;
+#elif TARGET_AMD64
+            => Architecture.X64;
+#elif TARGET_ARM
+            => Architecture.Arm;
+#elif TARGET_ARM64
+            => Architecture.Arm64;
+#elif TARGET_WASM
+            => Architecture.Wasm;
+#elif TARGET_S390X
+            => Architecture.S390x;
+#else
+#error Unknown Architecture
+#endif
+    }
+}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Unix.cs
new file mode 100644 (file)
index 0000000..1dac29e
--- /dev/null
@@ -0,0 +1,34 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Diagnostics;
+
+namespace System.Runtime.InteropServices
+{
+    public static partial class RuntimeInformation
+    {
+        private static string? s_osDescription;
+        private static volatile int s_osArchPlusOne;
+
+        public static string OSDescription => s_osDescription ??= Interop.Sys.GetUnixVersion();
+
+        public static Architecture OSArchitecture
+        {
+            get
+            {
+                int osArch = s_osArchPlusOne - 1;
+
+                if (osArch < 0)
+                {
+                    osArch = Interop.Sys.GetOSArchitecture();
+                    if (osArch < 0)
+                        osArch = (int)ProcessArchitecture;
+                    s_osArchPlusOne = osArch + 1;
+                }
+
+                Debug.Assert(osArch >= 0);
+                return (Architecture)osArch;
+            }
+        }
+    }
+}
@@ -8,8 +8,7 @@ namespace System.Runtime.InteropServices
     public static partial class RuntimeInformation
     {
         private static string? s_osDescription;
-        private static volatile int s_osArch = -1;
-        private static volatile int s_processArch = -1;
+        private static volatile int s_osArchPlusOne;
 
         public static string OSDescription
         {
@@ -36,61 +35,38 @@ namespace System.Runtime.InteropServices
         {
             get
             {
-                Debug.Assert(sizeof(Architecture) == sizeof(int));
+                int osArch = s_osArchPlusOne - 1;
 
-                int osArch = s_osArch;
-
-                if (osArch == -1)
+                if (osArch < 0)
                 {
                     Interop.Kernel32.SYSTEM_INFO sysInfo;
                     unsafe
                     {
                         Interop.Kernel32.GetNativeSystemInfo(&sysInfo);
                     }
+                    osArch = (int)Map(sysInfo.wProcessorArchitecture);
 
-                    osArch = s_osArch = (int)Map((Interop.Kernel32.ProcessorArchitecture)sysInfo.wProcessorArchitecture);
+                    s_osArchPlusOne = osArch + 1;
                 }
 
+                Debug.Assert(osArch >= 0);
                 return (Architecture)osArch;
             }
         }
 
-        public static Architecture ProcessArchitecture
-        {
-            get
-            {
-                Debug.Assert(sizeof(Architecture) == sizeof(int));
-
-                int processArch = s_processArch;
-
-                if (processArch == -1)
-                {
-                    Interop.Kernel32.SYSTEM_INFO sysInfo;
-                    unsafe
-                    {
-                        Interop.Kernel32.GetSystemInfo(&sysInfo);
-                    }
-
-                    processArch = s_processArch = (int)Map((Interop.Kernel32.ProcessorArchitecture)sysInfo.wProcessorArchitecture);
-                }
-
-                return (Architecture)processArch;
-            }
-        }
-
-        private static Architecture Map(Interop.Kernel32.ProcessorArchitecture processorArchitecture)
+        private static Architecture Map(int processorArchitecture)
         {
             switch (processorArchitecture)
             {
-                case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_ARM64:
+                case Interop.Kernel32.PROCESSOR_ARCHITECTURE_ARM64:
                     return Architecture.Arm64;
-                case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_ARM:
+                case Interop.Kernel32.PROCESSOR_ARCHITECTURE_ARM:
                     return Architecture.Arm;
-                case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_AMD64:
+                case Interop.Kernel32.PROCESSOR_ARCHITECTURE_AMD64:
                     return Architecture.X64;
-                case Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_INTEL:
+                case Interop.Kernel32.PROCESSOR_ARCHITECTURE_INTEL:
                 default:
-                    Debug.Assert(processorArchitecture == Interop.Kernel32.ProcessorArchitecture.Processor_Architecture_INTEL, "Unidentified Architecture");
+                    Debug.Assert(processorArchitecture == Interop.Kernel32.PROCESSOR_ARCHITECTURE_INTEL, "Unidentified Architecture");
                     return Architecture.X86;
             }
         }
index 7cff546..6bc4bf0 100644 (file)
@@ -104,7 +104,7 @@ namespace System.Runtime.Versioning
             identifier = identifier.Trim();
             if (identifier.Length == 0)
             {
-                throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(identifier)), nameof(identifier));
+                throw new ArgumentException(SR.Argument_EmptyString, nameof(identifier));
             }
             if (version == null)
             {
@@ -128,7 +128,7 @@ namespace System.Runtime.Versioning
             }
             if (frameworkName.Length == 0)
             {
-                throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(frameworkName)), nameof(frameworkName));
+                throw new ArgumentException(SR.Argument_EmptyString, nameof(frameworkName));
             }
 
             string[] components = frameworkName.Split(ComponentSeparator);
diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.Forwards.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.Forwards.cs
new file mode 100644 (file)
index 0000000..b4661cd
--- /dev/null
@@ -0,0 +1,9 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// ------------------------------------------------------------------------------
+// Changes to this file must follow the https://aka.ms/api-review process.
+// ------------------------------------------------------------------------------
+
+[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.InteropServices.Architecture))]
+[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.InteropServices.OSPlatform))]
+[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.InteropServices.RuntimeInformation))]
diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.cs
deleted file mode 100644 (file)
index 576f7b0..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// ------------------------------------------------------------------------------
-// Changes to this file must follow the https://aka.ms/api-review process.
-// ------------------------------------------------------------------------------
-
-namespace System.Runtime.InteropServices
-{
-    public enum Architecture
-    {
-        X86 = 0,
-        X64 = 1,
-        Arm = 2,
-        Arm64 = 3,
-        Wasm = 4,
-        S390x = 5,
-    }
-    public readonly partial struct OSPlatform : System.IEquatable<System.Runtime.InteropServices.OSPlatform>
-    {
-        private readonly object _dummy;
-        private readonly int _dummyPrimitive;
-        public static System.Runtime.InteropServices.OSPlatform FreeBSD { get { throw null; } }
-        public static System.Runtime.InteropServices.OSPlatform Linux { get { throw null; } }
-        public static System.Runtime.InteropServices.OSPlatform OSX { get { throw null; } }
-        public static System.Runtime.InteropServices.OSPlatform Windows { get { throw null; } }
-        public static System.Runtime.InteropServices.OSPlatform Create(string osPlatform) { throw null; }
-        public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
-        public bool Equals(System.Runtime.InteropServices.OSPlatform other) { throw null; }
-        public override int GetHashCode() { throw null; }
-        public static bool operator ==(System.Runtime.InteropServices.OSPlatform left, System.Runtime.InteropServices.OSPlatform right) { throw null; }
-        public static bool operator !=(System.Runtime.InteropServices.OSPlatform left, System.Runtime.InteropServices.OSPlatform right) { throw null; }
-        public override string ToString() { throw null; }
-    }
-    public static partial class RuntimeInformation
-    {
-        public static string FrameworkDescription { get { throw null; } }
-        public static System.Runtime.InteropServices.Architecture OSArchitecture { get { throw null; } }
-        public static string OSDescription { get { throw null; } }
-        public static System.Runtime.InteropServices.Architecture ProcessArchitecture { get { throw null; } }
-        public static string RuntimeIdentifier { get { throw null; } }
-        public static bool IsOSPlatform(System.Runtime.InteropServices.OSPlatform osPlatform) { throw null; }
-    }
-}
index 57c3f23..f752541 100644 (file)
@@ -4,7 +4,7 @@
     <TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
   </PropertyGroup>
   <ItemGroup>
-    <Compile Include="System.Runtime.InteropServices.RuntimeInformation.cs" />
+    <Compile Include="System.Runtime.InteropServices.RuntimeInformation.Forwards.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/Resources/Strings.resx
deleted file mode 100644 (file)
index e554cfe..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-<root>
-  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
-    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
-    <xsd:element name="root" msdata:IsDataSet="true">
-      <xsd:complexType>
-        <xsd:choice maxOccurs="unbounded">
-          <xsd:element name="metadata">
-            <xsd:complexType>
-              <xsd:sequence>
-                <xsd:element name="value" type="xsd:string" minOccurs="0" />
-              </xsd:sequence>
-              <xsd:attribute name="name" use="required" type="xsd:string" />
-              <xsd:attribute name="type" type="xsd:string" />
-              <xsd:attribute name="mimetype" type="xsd:string" />
-              <xsd:attribute ref="xml:space" />
-            </xsd:complexType>
-          </xsd:element>
-          <xsd:element name="assembly">
-            <xsd:complexType>
-              <xsd:attribute name="alias" type="xsd:string" />
-              <xsd:attribute name="name" type="xsd:string" />
-            </xsd:complexType>
-          </xsd:element>
-          <xsd:element name="data">
-            <xsd:complexType>
-              <xsd:sequence>
-                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
-                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
-              </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
-              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
-              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
-              <xsd:attribute ref="xml:space" />
-            </xsd:complexType>
-          </xsd:element>
-          <xsd:element name="resheader">
-            <xsd:complexType>
-              <xsd:sequence>
-                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
-              </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" use="required" />
-            </xsd:complexType>
-          </xsd:element>
-        </xsd:choice>
-      </xsd:complexType>
-    </xsd:element>
-  </xsd:schema>
-  <resheader name="resmimetype">
-    <value>text/microsoft-resx</value>
-  </resheader>
-  <resheader name="version">
-    <value>2.0</value>
-  </resheader>
-  <resheader name="reader">
-    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
-  </resheader>
-  <resheader name="writer">
-    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
-  </resheader>
-  <data name="Argument_EmptyValue" xml:space="preserve">
-    <value>Value cannot be empty.</value>
-  </data>
-  <data name="PlatformNotSupported_RuntimeInformation" xml:space="preserve">
-    <value>RuntimeInformation is not supported for Portable Class Libraries.</value>
-  </data>
-</root>
\ No newline at end of file
index fc9b3ac..94d0c64 100644 (file)
@@ -1,50 +1,10 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <RootNamespace>System.Runtime.InteropServices</RootNamespace>
-    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
+    <TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
     <Nullable>enable</Nullable>
-    <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
   </PropertyGroup>
   <ItemGroup>
-    <Compile Include="System\Runtime\InteropServices\RuntimeInformation\RuntimeInformation.cs" />
-    <Compile Include="System\Runtime\InteropServices\RuntimeInformation\Architecture.cs" />
-    <Compile Include="System\Runtime\InteropServices\RuntimeInformation\OSPlatform.cs" />
-  </ItemGroup>
-  <ItemGroup Condition="'$(TargetsBrowser)' == 'true'">
-    <Compile Include="System\Runtime\InteropServices\RuntimeInformation\RuntimeInformation.Browser.cs" />
-  </ItemGroup>
-  <ItemGroup Condition="'$(TargetsUnix)' == 'true'">
-    <Compile Include="System\Runtime\InteropServices\RuntimeInformation\RuntimeInformation.Unix.cs" />
-    <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetUnixVersion.cs"
-             Link="Common\Interop\Unix\System.Native\Interop.GetUnixVersion.cs" />
-    <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetOSArchitecture.cs"
-             Link="Common\Interop\Unix\System.Native\Interop.GetOSArchitecture.cs" />
-    <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetProcessArchitecture.cs"
-             Link="Common\Interop\Unix\System.Native\Interop.GetProcessArchitecture.cs" />
-    <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.ProcessorArchitecture.cs"
-             Link="Common\Interop\Unix\System.Native\Interop.ProcessorArchitecture.cs" />
-    <Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
-             Link="Common\Interop\Unix\Interop.Libraries.cs" />
-  </ItemGroup>
-  <ItemGroup Condition="'$(TargetsWindows)' == 'true'">
-    <Compile Include="System\Runtime\InteropServices\RuntimeInformation\RuntimeInformation.Windows.cs" />
-    <Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
-             Link="Common\Interop\Windows\Interop.Libraries.cs" />
-    <Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetNativeSystemInfo.cs"
-             Link="Common\Interop\Windows\Kernel32\Interop.GetNativeSystemInfo.cs" />
-    <Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.SYSTEM_INFO.cs"
-             Link="Common\Interop\Windows\Kernel32\Interop.SYSTEM_INFO.cs" />
-    <Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.GetSystemInfo.cs"
-             Link="Common\Interop\Windows\Kernel32\Interop.GetSystemInfo.cs" />
-  </ItemGroup>
-  <ItemGroup>
-    <Reference Include="System.Memory" />
-    <Reference Include="System.Reflection" />
-    <Reference Include="System.Reflection.Extensions" />
-    <Reference Include="System.Memory" />
     <Reference Include="System.Runtime" />
-    <Reference Include="System.Runtime.CompilerServices.Unsafe" />
-    <Reference Include="System.Runtime.InteropServices" />
-    <Reference Include="System.Threading" />
   </ItemGroup>
 </Project>
diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.Unix.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.Unix.cs
deleted file mode 100644 (file)
index 46b1a85..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Diagnostics;
-
-namespace System.Runtime.InteropServices
-{
-    public static partial class RuntimeInformation
-    {
-        private static string? s_osDescription;
-
-        public static string OSDescription => s_osDescription ??= Interop.Sys.GetUnixVersion();
-
-        public static Architecture OSArchitecture { get; } = Map((Interop.Sys.ProcessorArchitecture)Interop.Sys.GetOSArchitecture());
-
-        public static Architecture ProcessArchitecture { get; } = Map((Interop.Sys.ProcessorArchitecture)Interop.Sys.GetProcessArchitecture());
-
-        private static Architecture Map(Interop.Sys.ProcessorArchitecture arch)
-        {
-            switch (arch)
-            {
-                case Interop.Sys.ProcessorArchitecture.ARM:
-                    return Architecture.Arm;
-                case Interop.Sys.ProcessorArchitecture.x64:
-                    return Architecture.X64;
-                case Interop.Sys.ProcessorArchitecture.ARM64:
-                    return Architecture.Arm64;
-                case Interop.Sys.ProcessorArchitecture.WASM:
-                    return Architecture.Wasm;
-                case Interop.Sys.ProcessorArchitecture.S390x:
-                    return Architecture.S390x;
-                case Interop.Sys.ProcessorArchitecture.x86:
-                default:
-                    Debug.Assert(arch == Interop.Sys.ProcessorArchitecture.x86, "Unidentified Architecture");
-                    return Architecture.X86;
-            }
-        }
-    }
-}
index 435594f..b906bc0 100644 (file)
@@ -13419,6 +13419,15 @@ namespace System.Runtime.ExceptionServices
 }
 namespace System.Runtime.InteropServices
 {
+    public enum Architecture
+    {
+        X86 = 0,
+        X64 = 1,
+        Arm = 2,
+        Arm64 = 3,
+        Wasm = 4,
+        S390x = 5,
+    }
     public enum CharSet
     {
         None = 1,
@@ -13498,11 +13507,36 @@ namespace System.Runtime.InteropServices
         Explicit = 2,
         Auto = 3,
     }
+    public readonly partial struct OSPlatform : System.IEquatable<System.Runtime.InteropServices.OSPlatform>
+    {
+        private readonly object _dummy;
+        private readonly int _dummyPrimitive;
+        public static System.Runtime.InteropServices.OSPlatform FreeBSD { get { throw null; } }
+        public static System.Runtime.InteropServices.OSPlatform Linux { get { throw null; } }
+        public static System.Runtime.InteropServices.OSPlatform OSX { get { throw null; } }
+        public static System.Runtime.InteropServices.OSPlatform Windows { get { throw null; } }
+        public static System.Runtime.InteropServices.OSPlatform Create(string osPlatform) { throw null; }
+        public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
+        public bool Equals(System.Runtime.InteropServices.OSPlatform other) { throw null; }
+        public override int GetHashCode() { throw null; }
+        public static bool operator ==(System.Runtime.InteropServices.OSPlatform left, System.Runtime.InteropServices.OSPlatform right) { throw null; }
+        public static bool operator !=(System.Runtime.InteropServices.OSPlatform left, System.Runtime.InteropServices.OSPlatform right) { throw null; }
+        public override string ToString() { throw null; }
+    }
     [System.AttributeUsageAttribute(System.AttributeTargets.Parameter, Inherited=false)]
     public sealed partial class OutAttribute : System.Attribute
     {
         public OutAttribute() { }
     }
+    public static partial class RuntimeInformation
+    {
+        public static string FrameworkDescription { get { throw null; } }
+        public static System.Runtime.InteropServices.Architecture OSArchitecture { get { throw null; } }
+        public static string OSDescription { get { throw null; } }
+        public static System.Runtime.InteropServices.Architecture ProcessArchitecture { get { throw null; } }
+        public static string RuntimeIdentifier { get { throw null; } }
+        public static bool IsOSPlatform(System.Runtime.InteropServices.OSPlatform osPlatform) { throw null; }
+    }
     public abstract partial class SafeBuffer : Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
     {
         protected SafeBuffer(bool ownsHandle) : base (default(bool)) { }
index 3503004..1a636cc 100644 (file)
   <data name="ArgumentOutOfRange_NeedPosNum" xml:space="preserve">
     <value>Positive number required.</value>
   </data>
-  <data name="Argument_CannotBeNullOrEmpty" xml:space="preserve">
-    <value>Argument cannot be null or empty.</value>
-  </data>
   <data name="Argument_EmptyName" xml:space="preserve">
     <value>Empty name is not legal.</value>
   </data>
index ffad8ee..cb143f5 100644 (file)
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <EnableDefaultItems>false</EnableDefaultItems>
     <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
@@ -54,6 +54,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Platform)' == 'x86'">
     <PlatformTarget>x86</PlatformTarget>
+    <DefineConstants>$(DefineConstants);TARGET_X86</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Platform)' == 'arm'">
     <PlatformTarget>arm</PlatformTarget>
@@ -69,6 +70,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Platform)' == 'wasm'">
     <PlatformTarget>AnyCPU</PlatformTarget>
+    <DefineConstants>$(DefineConstants);TARGET_WASM</DefineConstants>
   </PropertyGroup>
 
   <!-- Configuration specific properties -->
index fe17553..0e54f4b 100644 (file)
@@ -216,7 +216,6 @@ static const Entry s_sysNative[] =
     DllImportEntry(SystemNative_GetUnixRelease)
     DllImportEntry(SystemNative_GetUnixVersion)
     DllImportEntry(SystemNative_GetOSArchitecture)
-    DllImportEntry(SystemNative_GetProcessArchitecture)
     DllImportEntry(SystemNative_SearchPath)
     DllImportEntry(SystemNative_SearchPath_TempDirectory)
     DllImportEntry(SystemNative_RegisterForSigChld)
index c7b7073..107aff8 100644 (file)
@@ -53,52 +53,8 @@ int32_t SystemNative_GetUnixVersion(char* version, int* capacity)
     return 0;
 }
 
-/* Returns an int representing the OS Architecture:
- 0 - x86
- 1 - x64
- 2 - ARM
- 3 - ARM64
- 4 - WASM */
+/* Returns an int representing the OS Architecture. -1 if same as process architecture. */
 int32_t SystemNative_GetOSArchitecture()
 {
-#if defined(TARGET_ARM)
-    return ARCH_ARM;
-#elif defined(TARGET_ARM64)
-    return ARCH_ARM64;
-#elif defined(TARGET_AMD64)
-    return ARCH_X64;
-#elif defined(TARGET_X86)
-    return ARCH_X86;
-#elif defined(TARGET_WASM)
-    return ARCH_WASM;
-#elif defined(TARGET_S390X)
-    return ARCH_S390X;
-#else
-#error Unidentified Architecture
-#endif
-}
-
-/* Returns an int representing the OS Architecture:
-0 - x86
-1 - x64
-2 - ARM
-3 - ARM64
-4 - WASM */
-int32_t SystemNative_GetProcessArchitecture()
-{
-#if defined(TARGET_ARM)
-    return ARCH_ARM;
-#elif defined(TARGET_ARM64)
-    return ARCH_ARM64;
-#elif defined(TARGET_AMD64)
-    return ARCH_X64;
-#elif defined(TARGET_X86)
-    return ARCH_X86;
-#elif defined(TARGET_WASM)
-    return ARCH_WASM;
-#elif defined(TARGET_S390X)
-    return ARCH_S390X;
-#else
-#error Unidentified Architecture
-#endif
+    return -1;
 }
index ff7e91d..6b13077 100644 (file)
@@ -14,8 +14,7 @@ PALEXPORT int32_t SystemNative_GetUnixVersion(char* version, int* capacity);
 
 PALEXPORT int32_t SystemNative_GetOSArchitecture(void);
 
-PALEXPORT int32_t SystemNative_GetProcessArchitecture(void);
-
+// Keep in sync with System.Runtime.InteropServices.Architecture enum
 enum 
 {
     ARCH_X86,