Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GeneratedDllImport for blittable p/invokes in System.Diagnostics.Process, System.Diagnostics.Process, System.Diagnostics.FileVersionInfo, System.Runtime.InteropServices.RuntimeInformation #61532

Merged
merged 4 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/libraries/Common/src/Interop/Unix/Interop.Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,25 @@ internal static unsafe string StrError(int platformErrno)
}

#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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal static partial class Sys
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI>
<EnableDllImportGenerator>true</EnableDllImportGenerator>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to just do this globally rather than per test project?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We went with only doing source projects globally, since the vast majority of test projects don't need/use it and until we get everything prepped for / through API review, it would result in us adding extra files and types (some which require unsafe) to all the tests unnecessarily.

</PropertyGroup>
<ItemGroup>
<!-- Checked in test binaries for FileVersionInfoTest -->
Expand Down Expand Up @@ -41,4 +42,4 @@
<ItemGroup>
<ProjectReference Include="..\System.Diagnostics.FileVersionInfo.TestAssembly\System.Diagnostics.FileVersionInfo.TestAssembly.csproj" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ System.Text.CodePagesEncodingProvider</PackageDescription>
<Reference Include="System.Memory" />
<Reference Include="System.Resources.ResourceManager" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.CompilerServices.Unsafe" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
Expand Down