Use GeneratedDllImport for blittable p/invokes in System.Diagnostics.Process, System...
authorElinor Fung <elfung@microsoft.com>
Mon, 15 Nov 2021 16:41:11 +0000 (08:41 -0800)
committerGitHub <noreply@github.com>
Mon, 15 Nov 2021 16:41:11 +0000 (09:41 -0700)
31 files changed:
eng/generators.targets
src/libraries/Common/src/Interop/Unix/Interop.Errors.cs
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetEGid.cs
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetEUid.cs
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetGroups.cs
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetOSArchitecture.cs
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetProcessArchitecture.cs
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetSid.cs
src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetUid.cs
src/libraries/Common/src/Interop/Unix/System.Native/Interop.RegisterForSigChld.cs
src/libraries/Common/src/Interop/Unix/System.Native/Interop.SetDelayedSigChildConsoleConfigurationHandler.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCPInfoEx.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetConsoleCP.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetConsoleOutputCP.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetNativeSystemInfo.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetStdHandle.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetSystemInfo.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.MultiByteToWideChar.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.VerLanguageName.cs
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WideCharToMultiByte.cs
src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtQuerySystemInformation.cs
src/libraries/Common/src/Interop/Windows/User32/Interop.EnumWindows.cs
src/libraries/Common/src/Interop/Windows/User32/Interop.GetKeyState.cs
src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindow.cs
src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowLong.cs
src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs
src/libraries/Common/src/Interop/Windows/User32/Interop.IsWindowVisible.cs
src/libraries/Common/src/Interop/Windows/User32/Interop.PostMessage.cs
src/libraries/Common/src/Interop/Windows/User32/Interop.SendMessageTimeout.cs
src/libraries/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/System.Diagnostics.FileVersionInfo.Tests.csproj
src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj

index bcedd85..aec6e66 100644 (file)
@@ -22,7 +22,9 @@
                         and (
                           ('@(Reference)' != ''
                             and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.InteropServices'))
-                            and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.CompilerServices.Unsafe'))
+                            and (@(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.CompilerServices.Unsafe'))
+                              or ('@(ProjectReference)' != ''
+                                and @(ProjectReference->AnyHaveMetadataValue('Identity', $([MSBuild]::NormalizePath('$(LibrariesProjectRoot)', 'System.Runtime.CompilerServices.Unsafe', 'src', 'System.Runtime.CompilerServices.Unsafe.ilproj'))))))
                             and @(Reference->AnyHaveMetadataValue('Identity', 'System.Memory')))
                           or ('@(ProjectReference)' != ''
                             and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))))" />
index 4e9b160..88af774 100644 (file)
@@ -183,25 +183,25 @@ internal static partial class Interop
         }
 
 #if SERIAL_PORTS
-        [DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_ConvertErrorPlatformToPal")]
-        internal static extern Error ConvertErrorPlatformToPal(int platformErrno);
+        [GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_ConvertErrorPlatformToPal")]
+        internal static partial Error ConvertErrorPlatformToPal(int platformErrno);
 
-        [DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_ConvertErrorPalToPlatform")]
-        internal static extern int ConvertErrorPalToPlatform(Error error);
+        [GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_ConvertErrorPalToPlatform")]
+        internal static partial int ConvertErrorPalToPlatform(Error error);
 
-        [DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_StrErrorR")]
-        private static extern unsafe byte* StrErrorR(int platformErrno, byte* buffer, int bufferSize);
+        [GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_StrErrorR")]
+        private static unsafe partial byte* StrErrorR(int platformErrno, byte* buffer, int bufferSize);
 #else
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPlatformToPal")]
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPlatformToPal")]
         [SuppressGCTransition]
-        internal static extern Error ConvertErrorPlatformToPal(int platformErrno);
+        internal static partial Error ConvertErrorPlatformToPal(int platformErrno);
 
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPalToPlatform")]
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPalToPlatform")]
         [SuppressGCTransition]
-        internal static extern int ConvertErrorPalToPlatform(Error error);
+        internal static partial int ConvertErrorPalToPlatform(Error error);
 
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_StrErrorR")]
-        private static extern unsafe byte* StrErrorR(int platformErrno, byte* buffer, int bufferSize);
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_StrErrorR")]
+        private static unsafe partial byte* StrErrorR(int platformErrno, byte* buffer, int bufferSize);
 #endif
     }
 }
index 87aede1..6ee390b 100644 (file)
@@ -8,7 +8,7 @@ internal static partial class Interop
 {
     internal static partial class Sys
     {
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEGid")]
-        internal static extern uint GetEGid();
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEGid")]
+        internal static partial uint GetEGid();
     }
 }
index 1b8aa00..f11d4ef 100644 (file)
@@ -7,7 +7,7 @@ internal static partial class Interop
 {
     internal static partial class Sys
     {
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEUid")]
-        internal static extern uint GetEUid();
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEUid")]
+        internal static partial uint GetEUid();
     }
 }
index 2fd3156..0754fab 100644 (file)
@@ -44,7 +44,7 @@ internal static partial class Interop
             while (true);
         }
 
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetGroups", SetLastError = true)]
-        private static extern unsafe int GetGroups(int ngroups, uint* groups);
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetGroups", SetLastError = true)]
+        private static unsafe partial int GetGroups(int ngroups, uint* groups);
     }
 }
index de7b9cd..50bf35c 100644 (file)
@@ -9,7 +9,7 @@ internal static partial class Interop
     internal static partial class Sys
     {
         [SuppressGCTransition]
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetOSArchitecture")]
-        internal static extern int GetOSArchitecture();
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetOSArchitecture")]
+        internal static partial int GetOSArchitecture();
     }
 }
index 2dbb0b1..2086b4a 100644 (file)
@@ -9,7 +9,7 @@ internal static partial class Interop
     internal static partial class Sys
     {
         [SuppressGCTransition]
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetProcessArchitecture")]
-        internal static extern int GetProcessArchitecture();
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetProcessArchitecture")]
+        internal static partial int GetProcessArchitecture();
     }
 }
index 6137740..5b20a86 100644 (file)
@@ -7,7 +7,7 @@ internal static partial class Interop
 {
     internal static partial class Sys
     {
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSid")]
-        internal static extern int GetSid(int pid);
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSid")]
+        internal static partial int GetSid(int pid);
     }
 }
index 0d1bec6..e828974 100644 (file)
@@ -7,7 +7,7 @@ internal static partial class Interop
 {
     internal static partial class Sys
     {
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUid")]
-        internal static extern uint GetUid();
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUid")]
+        internal static partial uint GetUid();
     }
 }
index e11fcfa..2bbac8a 100644 (file)
@@ -7,7 +7,7 @@ internal static partial class Interop
 {
     internal static partial class Sys
     {
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RegisterForSigChld")]
-        internal static extern unsafe void RegisterForSigChld(delegate* unmanaged<int, int, int> handler);
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RegisterForSigChld")]
+        internal static unsafe partial void RegisterForSigChld(delegate* unmanaged<int, int, int> handler);
     }
 }
index bd09aa1..f9c6b2b 100644 (file)
@@ -7,8 +7,8 @@ internal static partial class Interop
 {
     internal static partial class Sys
     {
-        [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetDelayedSigChildConsoleConfigurationHandler")]
+        [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetDelayedSigChildConsoleConfigurationHandler")]
         [SuppressGCTransition]
-        internal static extern unsafe void SetDelayedSigChildConsoleConfigurationHandler(delegate* unmanaged<void> callback);
+        internal static unsafe partial void SetDelayedSigChildConsoleConfigurationHandler(delegate* unmanaged<void> callback);
     }
 }
index b0c64b5..773f7dd 100644 (file)
@@ -7,8 +7,8 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "GetCPInfoExW")]
-        private static extern unsafe Interop.BOOL GetCPInfoExW(uint CodePage, uint dwFlags, CPINFOEXW* lpCPInfoEx);
+        [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "GetCPInfoExW", CharSet = CharSet.Unicode)]
+        private static unsafe partial Interop.BOOL GetCPInfoExW(uint CodePage, uint dwFlags, CPINFOEXW* lpCPInfoEx);
 
         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
         private unsafe struct CPINFOEXW
index e76c069..33e73f8 100644 (file)
@@ -7,7 +7,7 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32)]
-        internal static extern uint GetConsoleCP();
+        [GeneratedDllImport(Libraries.Kernel32)]
+        internal static partial uint GetConsoleCP();
     }
 }
index fd59f4d..3d8c546 100644 (file)
@@ -7,7 +7,7 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32)]
-        internal static extern uint GetConsoleOutputCP();
+        [GeneratedDllImport(Libraries.Kernel32)]
+        internal static partial uint GetConsoleOutputCP();
     }
 }
index 2322bdd..076079e 100644 (file)
@@ -8,7 +8,7 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32)]
-        internal static unsafe extern void GetNativeSystemInfo(SYSTEM_INFO* lpSystemInfo);
+        [GeneratedDllImport(Libraries.Kernel32)]
+        internal static unsafe partial void GetNativeSystemInfo(SYSTEM_INFO* lpSystemInfo);
     }
 }
index b317b13..501c25f 100644 (file)
@@ -8,10 +8,10 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32)]
+        [GeneratedDllImport(Libraries.Kernel32)]
 #if !NO_SUPPRESS_GC_TRANSITION
         [SuppressGCTransition]
 #endif
-        internal static extern IntPtr GetStdHandle(int nStdHandle);  // param is NOT a handle, but it returns one!
+        internal static partial IntPtr GetStdHandle(int nStdHandle);  // param is NOT a handle, but it returns one!
     }
 }
index f3872f1..383a26f 100644 (file)
@@ -7,7 +7,7 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32)]
-        internal static unsafe extern void GetSystemInfo(SYSTEM_INFO* lpSystemInfo);
+        [GeneratedDllImport(Libraries.Kernel32)]
+        internal static unsafe partial void GetSystemInfo(SYSTEM_INFO* lpSystemInfo);
     }
 }
index 2cd6f2b..dfb7a73 100644 (file)
@@ -7,8 +7,8 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32)]
-        internal static extern unsafe int MultiByteToWideChar(
+        [GeneratedDllImport(Libraries.Kernel32)]
+        internal static unsafe partial int MultiByteToWideChar(
             uint CodePage, uint dwFlags,
             byte* lpMultiByteStr, int cbMultiByte,
             char* lpWideCharStr, int cchWideChar);
index 6c665a4..af062f0 100644 (file)
@@ -7,7 +7,7 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "VerLanguageNameW")]
-        internal static extern unsafe int VerLanguageName(uint wLang, char* szLang, uint cchLang);
+        [GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "VerLanguageNameW")]
+        internal static unsafe partial int VerLanguageName(uint wLang, char* szLang, uint cchLang);
     }
 }
index ce255b4..ad2d77e 100644 (file)
@@ -8,8 +8,8 @@ internal static partial class Interop
 {
     internal static partial class Kernel32
     {
-        [DllImport(Libraries.Kernel32)]
-        internal static extern unsafe int WideCharToMultiByte(
+        [GeneratedDllImport(Libraries.Kernel32)]
+        internal static unsafe partial int WideCharToMultiByte(
             uint CodePage, uint dwFlags,
             char* lpWideCharStr, int cchWideChar,
             byte* lpMultiByteStr, int cbMultiByte,
index 3c55603..6e6ef56 100644 (file)
@@ -7,8 +7,8 @@ internal static partial class Interop
 {
     internal static partial class NtDll
     {
-        [DllImport(Libraries.NtDll, ExactSpelling = true)]
-        internal static extern unsafe uint NtQuerySystemInformation(int SystemInformationClass, void* SystemInformation, uint SystemInformationLength, uint* ReturnLength);
+        [GeneratedDllImport(Libraries.NtDll, ExactSpelling = true)]
+        internal static unsafe partial uint NtQuerySystemInformation(int SystemInformationClass, void* SystemInformation, uint SystemInformationLength, uint* ReturnLength);
 
         internal const uint STATUS_INFO_LENGTH_MISMATCH = 0xC0000004;
     }
index eff18b1..c500842 100644 (file)
@@ -8,7 +8,7 @@ internal static partial class Interop
 {
     internal static partial class User32
     {
-        [DllImport(Libraries.User32)]
-        public static extern unsafe Interop.BOOL EnumWindows(delegate* unmanaged<IntPtr, IntPtr, Interop.BOOL> callback, IntPtr extraData);
+        [GeneratedDllImport(Libraries.User32)]
+        public static unsafe partial Interop.BOOL EnumWindows(delegate* unmanaged<IntPtr, IntPtr, Interop.BOOL> callback, IntPtr extraData);
     }
 }
index bff237b..9ee51a0 100644 (file)
@@ -7,7 +7,7 @@ internal static partial class Interop
 {
     internal static partial class User32
     {
-        [DllImport(Libraries.User32)]
-        internal static extern short GetKeyState(int virtualKeyCode);
+        [GeneratedDllImport(Libraries.User32)]
+        internal static partial short GetKeyState(int virtualKeyCode);
     }
 }
index 1ece26d..3091b5c 100644 (file)
@@ -8,7 +8,7 @@ internal static partial class Interop
 {
     internal static partial class User32
     {
-        [DllImport(Libraries.User32)]
-        public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
+        [GeneratedDllImport(Libraries.User32)]
+        public static partial IntPtr GetWindow(IntPtr hWnd, int uCmd);
     }
 }
index 1a03109..9cc34ee 100644 (file)
@@ -8,7 +8,7 @@ internal static partial class Interop
 {
     internal static partial class User32
     {
-        [DllImport(Libraries.User32, EntryPoint = "GetWindowLongW")]
-        public static extern int GetWindowLong(IntPtr hWnd, int uCmd);
+        [GeneratedDllImport(Libraries.User32, EntryPoint = "GetWindowLongW")]
+        public static partial int GetWindowLong(IntPtr hWnd, int uCmd);
     }
 }
index 3b145fe..daee2bf 100644 (file)
@@ -8,8 +8,8 @@ internal static partial class Interop
 {
     internal static partial class User32
     {
-        [DllImport(Libraries.User32, ExactSpelling = true)]
-        public static unsafe extern int GetWindowThreadProcessId(IntPtr handle, int* processId);
+        [GeneratedDllImport(Libraries.User32, ExactSpelling = true)]
+        public static unsafe partial int GetWindowThreadProcessId(IntPtr handle, int* processId);
 
         [DllImport(Libraries.User32, ExactSpelling = true)]
         public static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);
index 15a829a..c09bfb7 100644 (file)
@@ -8,7 +8,7 @@ internal static partial class Interop
 {
     internal static partial class User32
     {
-        [DllImport(Libraries.User32)]
-        public static extern BOOL IsWindowVisible(IntPtr hWnd);
+        [GeneratedDllImport(Libraries.User32)]
+        public static partial BOOL IsWindowVisible(IntPtr hWnd);
     }
 }
index eeec1ba..962ccd2 100644 (file)
@@ -8,8 +8,8 @@ internal static partial class Interop
 {
     internal static partial class User32
     {
-        [DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
-        public static extern int PostMessageW(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
+        [GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
+        public static partial int PostMessageW(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
 
         [DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
         public static extern int PostMessageW(HandleRef hwnd, int msg, IntPtr wparam, IntPtr lparam);
index c84dfda..d3ebb4a 100644 (file)
@@ -8,7 +8,7 @@ internal static partial class Interop
 {
     internal static partial class User32
     {
-        [DllImport(Libraries.User32, EntryPoint = "SendMessageTimeoutW")]
-        public static unsafe extern IntPtr SendMessageTimeout(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, int flags, int timeout, IntPtr* pdwResult);
+        [GeneratedDllImport(Libraries.User32, EntryPoint = "SendMessageTimeoutW")]
+        public static unsafe partial IntPtr SendMessageTimeout(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, int flags, int timeout, IntPtr* pdwResult);
     }
 }
index ad027e8..9b99ef0 100644 (file)
@@ -3,6 +3,7 @@
     <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI>
+    <EnableDllImportGenerator>true</EnableDllImportGenerator>
   </PropertyGroup>
   <ItemGroup>
     <!-- Checked in test binaries for FileVersionInfoTest -->
@@ -41,4 +42,4 @@
   <ItemGroup>
     <ProjectReference Include="..\System.Diagnostics.FileVersionInfo.TestAssembly\System.Diagnostics.FileVersionInfo.TestAssembly.csproj" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
index 077938e..4e77239 100644 (file)
@@ -4,9 +4,10 @@
     <NoWarn>169,649</NoWarn>
     <StringResourcesPath>../../src/Resources/Strings.resx</StringResourcesPath>
     <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
+    <EnableDllImportGenerator>true</EnableDllImportGenerator>
   </PropertyGroup>
   <PropertyGroup>
-    <!-- SYSTEM_NET_PRIMITIVES_DLL is required to allow source-level code sharing for types defined within the 
+    <!-- SYSTEM_NET_PRIMITIVES_DLL is required to allow source-level code sharing for types defined within the
          System.Net.Internals namespace. -->
     <DefineConstants>$(DefineConstants);SYSTEM_NET_PRIMITIVES_DLL</DefineConstants>
   </PropertyGroup>
     <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.InterfaceNameToIndex.cs"
              Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.InterfaceNameToIndex.cs" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>