Skip to content

Commit 23c386a

Browse files
authored
Use GeneratedDllImport in System.Data.Odbc, System.IO.Ports, System.ServiceProcess.ServiceController (#61741)
1 parent f6e2377 commit 23c386a

55 files changed

Lines changed: 424 additions & 408 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/libraries/Common/src/Interop/Interop.Odbc.cs

Lines changed: 83 additions & 90 deletions
Large diffs are not rendered by default.

src/libraries/Common/src/Interop/OSX/Interop.libc.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ internal struct AttrList
2323
public const uint ATTR_CMN_CRTIME = 0x00000200;
2424
}
2525

26+
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
27+
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like CULong)
2628
[DllImport(Libraries.libc, EntryPoint = "setattrlist", SetLastError = true)]
27-
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
2829
internal static unsafe extern int setattrlist(string path, AttrList* attrList, void* attrBuf, nint attrBufSize, CULong options);
30+
#pragma warning restore DLLIMPORTGENANALYZER015
2931

3032
internal const uint FSOPT_NOFOLLOW = 0x00000001;
3133
}

src/libraries/Common/src/Interop/Unix/System.IO.Ports.Native/Interop.Serial.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ internal static partial class Interop
1010
{
1111
internal static partial class Serial
1212
{
13-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_SerialPortOpen", SetLastError = true)]
14-
internal static extern SafeSerialDeviceHandle SerialPortOpen(string name);
13+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_SerialPortOpen", CharSet = CharSet.Ansi, SetLastError = true)]
14+
internal static partial SafeSerialDeviceHandle SerialPortOpen(string name);
1515

16-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_SerialPortClose", SetLastError = true)]
17-
internal static extern int SerialPortClose(IntPtr handle);
16+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_SerialPortClose", SetLastError = true)]
17+
internal static partial int SerialPortClose(IntPtr handle);
1818

19-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_Shutdown")]
20-
internal static extern Error Shutdown(IntPtr socket, SocketShutdown how);
19+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_Shutdown")]
20+
internal static partial Error Shutdown(IntPtr socket, SocketShutdown how);
2121

2222
/// <summary>
2323
/// Reads a number of bytes from an open file descriptor into a specified buffer.
@@ -29,8 +29,8 @@ internal static partial class Serial
2929
/// Returns the number of bytes read on success; otherwise, -1 is returned
3030
/// Note - on fail. the position of the stream may change depending on the platform; consult man 2 read for more info
3131
/// </returns>
32-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_Read", SetLastError = true)]
33-
internal static extern unsafe int Read(SafeHandle fd, byte* buffer, int count);
32+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_Read", SetLastError = true)]
33+
internal static unsafe partial int Read(SafeHandle fd, byte* buffer, int count);
3434

3535
/// <summary>
3636
/// Writes the specified buffer to the provided open file descriptor
@@ -41,8 +41,8 @@ internal static partial class Serial
4141
/// <returns>
4242
/// Returns the number of bytes written on success; otherwise, returns -1 and sets errno
4343
/// </returns>
44-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_Write", SetLastError = true)]
45-
internal static extern unsafe int Write(SafeHandle fd, byte* buffer, int bufferSize);
44+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_Write", SetLastError = true)]
45+
internal static unsafe partial int Write(SafeHandle fd, byte* buffer, int bufferSize);
4646

4747
/// <summary>
4848
/// Polls a set of file descriptors for signals and returns what signals have been set
@@ -52,8 +52,8 @@ internal static partial class Serial
5252
/// <param name="timeout">The amount of time to wait; -1 for infinite, 0 for immediate return, and a positive number is the number of milliseconds</param>
5353
/// <param name="triggered">The number of events triggered (i.e. the number of entries in pollEvents with a non-zero TriggeredEvents). May be zero in the event of a timeout.</param>
5454
/// <returns>An error or Error.SUCCESS.</returns>
55-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_Poll")]
56-
private static extern unsafe Error Poll(PollEvent* pollEvents, uint eventCount, int timeout, uint* triggered);
55+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_Poll")]
56+
private static unsafe partial Error Poll(PollEvent* pollEvents, uint eventCount, int timeout, uint* triggered);
5757

5858
/// <summary>
5959
/// Polls a File Descriptor for the passed in flags.

src/libraries/Common/src/Interop/Unix/System.IO.Ports.Native/Interop.Termios.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,34 @@ internal enum Queue
2929
SendQueue = 2,
3030
}
3131

32-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosReset", SetLastError = true)]
33-
internal static extern int TermiosReset(SafeSerialDeviceHandle handle, int speed, int data, StopBits stop, Parity parity, Handshake flow);
32+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosReset", SetLastError = true)]
33+
internal static partial int TermiosReset(SafeSerialDeviceHandle handle, int speed, int data, StopBits stop, Parity parity, Handshake flow);
3434

35-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosGetSignal", SetLastError = true)]
36-
internal static extern int TermiosGetSignal(SafeSerialDeviceHandle handle, Signals signal);
35+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosGetSignal", SetLastError = true)]
36+
internal static partial int TermiosGetSignal(SafeSerialDeviceHandle handle, Signals signal);
3737

38-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosSetSignal", SetLastError = true)]
39-
internal static extern int TermiosGetSignal(SafeSerialDeviceHandle handle, Signals signal, int set);
38+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosSetSignal", SetLastError = true)]
39+
internal static partial int TermiosGetSignal(SafeSerialDeviceHandle handle, Signals signal, int set);
4040

41-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosGetAllSignals")]
42-
internal static extern Signals TermiosGetAllSignals(SafeSerialDeviceHandle handle);
41+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosGetAllSignals")]
42+
internal static partial Signals TermiosGetAllSignals(SafeSerialDeviceHandle handle);
4343

44-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosSetSpeed", SetLastError = true)]
45-
internal static extern int TermiosSetSpeed(SafeSerialDeviceHandle handle, int speed);
44+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosSetSpeed", SetLastError = true)]
45+
internal static partial int TermiosSetSpeed(SafeSerialDeviceHandle handle, int speed);
4646

47-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosGetSpeed", SetLastError = true)]
48-
internal static extern int TermiosGetSpeed(SafeSerialDeviceHandle handle);
47+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosGetSpeed", SetLastError = true)]
48+
internal static partial int TermiosGetSpeed(SafeSerialDeviceHandle handle);
4949

50-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosAvailableBytes", SetLastError = true)]
51-
internal static extern int TermiosGetAvailableBytes(SafeSerialDeviceHandle handle, [MarshalAs(UnmanagedType.Bool)]bool fromReadBuffer);
50+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosAvailableBytes", SetLastError = true)]
51+
internal static partial int TermiosGetAvailableBytes(SafeSerialDeviceHandle handle, [MarshalAs(UnmanagedType.Bool)]bool fromReadBuffer);
5252

53-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosDiscard", SetLastError = true)]
54-
internal static extern int TermiosDiscard(SafeSerialDeviceHandle handle, Queue input);
53+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosDiscard", SetLastError = true)]
54+
internal static partial int TermiosDiscard(SafeSerialDeviceHandle handle, Queue input);
5555

56-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosDrain", SetLastError = true)]
57-
internal static extern int TermiosDrain(SafeSerialDeviceHandle handle);
56+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosDrain", SetLastError = true)]
57+
internal static partial int TermiosDrain(SafeSerialDeviceHandle handle);
5858

59-
[DllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosSendBreak", SetLastError = true)]
60-
internal static extern int TermiosSendBreak(SafeSerialDeviceHandle handle, int duration);
59+
[GeneratedDllImport(Libraries.IOPortsNative, EntryPoint = "SystemIoPortsNative_TermiosSendBreak", SetLastError = true)]
60+
internal static partial int TermiosSendBreak(SafeSerialDeviceHandle handle, int duration);
6161
}
6262
}

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CloseServiceHandle.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal static partial class Interop
88
{
99
internal static partial class Advapi32
1010
{
11-
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
12-
internal static extern bool CloseServiceHandle(IntPtr handle);
11+
[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
12+
internal static partial bool CloseServiceHandle(IntPtr handle);
1313
}
1414
}

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.ControlService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ internal static partial class Interop
99
{
1010
internal static partial class Advapi32
1111
{
12-
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)]
13-
internal static extern unsafe bool ControlService(SafeServiceHandle serviceHandle, int control, SERVICE_STATUS* pStatus);
12+
[GeneratedDllImport(Libraries.Advapi32, SetLastError = true)]
13+
internal static unsafe partial bool ControlService(SafeServiceHandle serviceHandle, int control, SERVICE_STATUS* pStatus);
1414

1515
}
1616
}

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EnumDependentServices.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ internal static partial class Interop
99
{
1010
internal static partial class Advapi32
1111
{
12-
[DllImport(Libraries.Advapi32, EntryPoint = "EnumDependentServicesW", CharSet = CharSet.Unicode, SetLastError = true)]
13-
internal static extern bool EnumDependentServices(
12+
[GeneratedDllImport(Libraries.Advapi32, EntryPoint = "EnumDependentServicesW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
13+
internal static partial bool EnumDependentServices(
1414
SafeServiceHandle serviceHandle,
1515
int serviceState,
1616
IntPtr bufferOfENUM_SERVICE_STATUS,

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EnumServicesStatusEx.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ internal static partial class Interop
99
{
1010
internal static partial class Advapi32
1111
{
12-
[DllImport(Libraries.Advapi32, EntryPoint = "EnumServicesStatusExW", CharSet = CharSet.Unicode, SetLastError = true)]
13-
internal static extern bool EnumServicesStatusEx(
12+
[GeneratedDllImport(Libraries.Advapi32, EntryPoint = "EnumServicesStatusExW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
13+
internal static partial bool EnumServicesStatusEx(
1414
SafeServiceHandle databaseHandle,
1515
int infolevel,
1616
int serviceType,

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ internal static partial class Interop
88
{
99
internal static partial class Advapi32
1010
{
11-
[DllImport(Libraries.Advapi32, ExactSpelling = true)]
11+
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
1212
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
13+
[DllImport(Libraries.Advapi32, ExactSpelling = true)]
1314
internal static extern int EventActivityIdControl(ActivityControl ControlCode, ref Guid ActivityId);
15+
#pragma warning restore DLLIMPORTGENANALYZER015
1416
}
1517
}

src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventRegister.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ internal static partial class Interop
88
{
99
internal static partial class Advapi32
1010
{
11-
[DllImport(Libraries.Advapi32, ExactSpelling = true)]
11+
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
1212
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
13+
[DllImport(Libraries.Advapi32, ExactSpelling = true)]
1314
internal static unsafe extern uint EventRegister(
1415
in Guid providerId,
1516
EtwEnableCallback enableCallback,
1617
void* callbackContext,
1718
ref long registrationHandle);
19+
#pragma warning restore DLLIMPORTGENANALYZER015
1820
}
1921
}

0 commit comments

Comments
 (0)