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.IO.Compression, System.IO.Compression.Brotli, System.Net.Http, System.Net.NameResolution #61638

Merged
merged 5 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions src/libraries/Common/src/Interop/Interop.Brotli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ internal static unsafe partial int BrotliDecoderDecompressStream(
SafeBrotliDecoderHandle state, ref nuint availableIn, byte** nextIn,
ref nuint availableOut, byte** nextOut, out nuint totalOut);

[DllImport(Libraries.CompressionNative)]
internal static extern unsafe BOOL BrotliDecoderDecompress(nuint availableInput, byte* inBytes, nuint* availableOutput, byte* outBytes);
[GeneratedDllImport(Libraries.CompressionNative)]
internal static unsafe partial BOOL BrotliDecoderDecompress(nuint availableInput, byte* inBytes, nuint* availableOutput, byte* outBytes);

[DllImport(Libraries.CompressionNative)]
internal static extern void BrotliDecoderDestroyInstance(IntPtr state);
[GeneratedDllImport(Libraries.CompressionNative)]
internal static partial void BrotliDecoderDestroyInstance(IntPtr state);

[GeneratedDllImport(Libraries.CompressionNative)]
internal static partial BOOL BrotliDecoderIsFinished(SafeBrotliDecoderHandle state);
Expand All @@ -41,10 +41,10 @@ internal static unsafe partial BOOL BrotliEncoderCompressStream(
[GeneratedDllImport(Libraries.CompressionNative)]
internal static partial BOOL BrotliEncoderHasMoreOutput(SafeBrotliEncoderHandle state);

[DllImport(Libraries.CompressionNative)]
internal static extern void BrotliEncoderDestroyInstance(IntPtr state);
[GeneratedDllImport(Libraries.CompressionNative)]
internal static partial void BrotliEncoderDestroyInstance(IntPtr state);

[DllImport(Libraries.CompressionNative)]
internal static extern unsafe BOOL BrotliEncoderCompress(int quality, int window, int v, nuint availableInput, byte* inBytes, nuint* availableOutput, byte* outBytes);
[GeneratedDllImport(Libraries.CompressionNative)]
internal static unsafe partial BOOL BrotliEncoderCompress(int quality, int window, int v, nuint availableInput, byte* inBytes, nuint* availableOutput, byte* outBytes);
}
}
36 changes: 18 additions & 18 deletions src/libraries/Common/src/Interop/Interop.zlib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ internal static partial class Interop
{
internal static partial class zlib
{
[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_DeflateInit2_")]
internal static extern unsafe ZLibNative.ErrorCode DeflateInit2_(
[GeneratedDllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_DeflateInit2_")]
internal static unsafe partial ZLibNative.ErrorCode DeflateInit2_(
ZLibNative.ZStream* stream,
ZLibNative.CompressionLevel level,
ZLibNative.CompressionMethod method,
int windowBits,
int memLevel,
ZLibNative.CompressionStrategy strategy);

[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_Deflate")]
internal static extern unsafe ZLibNative.ErrorCode Deflate(ZLibNative.ZStream* stream, ZLibNative.FlushCode flush);
[GeneratedDllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_Deflate")]
internal static unsafe partial ZLibNative.ErrorCode Deflate(ZLibNative.ZStream* stream, ZLibNative.FlushCode flush);

[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_DeflateReset")]
internal static extern unsafe ZLibNative.ErrorCode DeflateReset(ZLibNative.ZStream* stream);
[GeneratedDllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_DeflateReset")]
internal static unsafe partial ZLibNative.ErrorCode DeflateReset(ZLibNative.ZStream* stream);

[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_DeflateEnd")]
internal static extern unsafe ZLibNative.ErrorCode DeflateEnd(ZLibNative.ZStream* stream);
[GeneratedDllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_DeflateEnd")]
internal static unsafe partial ZLibNative.ErrorCode DeflateEnd(ZLibNative.ZStream* stream);

[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_InflateInit2_")]
internal static extern unsafe ZLibNative.ErrorCode InflateInit2_(ZLibNative.ZStream* stream, int windowBits);
[GeneratedDllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_InflateInit2_")]
internal static unsafe partial ZLibNative.ErrorCode InflateInit2_(ZLibNative.ZStream* stream, int windowBits);

[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_Inflate")]
internal static extern unsafe ZLibNative.ErrorCode Inflate(ZLibNative.ZStream* stream, ZLibNative.FlushCode flush);
[GeneratedDllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_Inflate")]
internal static unsafe partial ZLibNative.ErrorCode Inflate(ZLibNative.ZStream* stream, ZLibNative.FlushCode flush);

[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_InflateReset")]
internal static extern unsafe ZLibNative.ErrorCode InflateReset(ZLibNative.ZStream* stream);
[GeneratedDllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_InflateReset")]
internal static unsafe partial ZLibNative.ErrorCode InflateReset(ZLibNative.ZStream* stream);

[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_InflateEnd")]
internal static extern unsafe ZLibNative.ErrorCode InflateEnd(ZLibNative.ZStream* stream);
[GeneratedDllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_InflateEnd")]
internal static unsafe partial ZLibNative.ErrorCode InflateEnd(ZLibNative.ZStream* stream);

[DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_Crc32")]
internal static extern unsafe uint crc32(uint crc, byte* buffer, int len);
[GeneratedDllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_Crc32")]
internal static unsafe partial uint crc32(uint crc, byte* buffer, int len);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal enum CFNumberType
kCFNumberIntType = 9,
}

[DllImport(Libraries.CoreFoundationLibrary)]
private static unsafe extern int CFNumberGetValue(IntPtr handle, CFNumberType type, int* value);
[GeneratedDllImport(Libraries.CoreFoundationLibrary)]
private static unsafe partial int CFNumberGetValue(IntPtr handle, CFNumberType type, int* value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ internal static SafeCreateHandle CFArrayCreate(IntPtr[] values, UIntPtr numValue
/// </summary>
/// <param name="ptr">The CFType object to retain. This value must not be NULL</param>
/// <returns>The input value</returns>
[DllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static extern IntPtr CFRetain(IntPtr ptr);
[GeneratedDllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static partial IntPtr CFRetain(IntPtr ptr);

/// <summary>
/// Decrements the reference count on the specified object and, if the ref count hits 0, cleans up the object.
/// </summary>
/// <param name="ptr">The pointer on which to decrement the reference count.</param>
[DllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static extern void CFRelease(IntPtr ptr);
[GeneratedDllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static partial void CFRelease(IntPtr ptr);
}
}
29 changes: 15 additions & 14 deletions src/libraries/Common/src/Interop/OSX/Interop.RunLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,57 @@ internal static partial class RunLoop
/// </summary>
#if MONO
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void CFRunLoopRun();
#else
[DllImport(Interop.Libraries.CoreFoundationLibrary)]
[GeneratedDllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static partial void CFRunLoopRun();
#endif
internal static extern void CFRunLoopRun();

/// <summary>
/// Runs the current thread's CFRunLoop object in a particular mode.
/// </summary>
[DllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static extern int CFRunLoopRunInMode(CFStringRef mode, double seconds, int returnAfterSourceHandled);
[GeneratedDllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static partial int CFRunLoopRunInMode(CFStringRef mode, double seconds, int returnAfterSourceHandled);

/// <summary>
/// Notifies a RunLoop to stop and return control to the execution context that called CFRunLoopRun
/// </summary>
/// <param name="rl">The RunLoop to notify to stop</param>
[DllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static extern void CFRunLoopStop(CFRunLoopRef rl);
[GeneratedDllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static partial void CFRunLoopStop(CFRunLoopRef rl);

/// <summary>
/// Retrieves the RunLoop associated with the current thread; all threads automatically have a RunLoop.
/// Follows the "Get Rule" where you do not own the object unless you CFRetain it; in which case, you must also CFRelease it as well.
/// </summary>
/// <returns>Returns a pointer to a CFRunLoop on success; otherwise, returns IntPtr.Zero</returns>
[DllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static extern CFRunLoopRef CFRunLoopGetCurrent();
[GeneratedDllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static partial CFRunLoopRef CFRunLoopGetCurrent();

/// <summary>
/// Adds a CFRunLoopSource object to a run loop mode.
/// </summary>
/// <param name="rl">The run loop to modify.</param>
/// <param name="source">The run loop source to add. The source is retained by the run loop.</param>
/// <param name="mode">The run loop mode to which to add source.</param>
[DllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static extern void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFStringRef mode);
[GeneratedDllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static partial void CFRunLoopAddSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFStringRef mode);

/// <summary>
/// Removes a CFRunLoopSource object from a run loop mode.
/// </summary>
/// <param name="rl">The run loop to modify.</param>
/// <param name="source">The run loop source to remove.</param>
/// <param name="mode">The run loop mode of rl from which to remove source.</param>
[DllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static extern void CFRunLoopRemoveSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFStringRef mode);
[GeneratedDllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static partial void CFRunLoopRemoveSource(CFRunLoopRef rl, CFRunLoopSourceRef source, CFStringRef mode);

/// <summary>
/// Invalidates a CFRunLoopSource object, stopping it from ever firing again.
/// </summary>
/// <param name="source">The run loop source to invalidate.</param>
[DllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static extern void CFRunLoopSourceInvalidate(CFRunLoopSourceRef source);
[GeneratedDllImport(Interop.Libraries.CoreFoundationLibrary)]
internal static partial void CFRunLoopSourceInvalidate(CFRunLoopSourceRef source);

/// <summary>
/// Returns a bool that indicates whether the run loop is waiting for an event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ internal enum GetNameInfoFlags : int
NI_NUMERICHOST = 0x2,
}

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNameInfo")]
internal static extern unsafe int GetNameInfo(
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNameInfo")]
internal static unsafe partial int GetNameInfo(
byte* address,
uint addressLength,
byte isIpv6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal unsafe struct HostEntry
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetHostEntryForName", CharSet = CharSet.Ansi)]
internal static unsafe partial int GetHostEntryForName(string address, AddressFamily family, HostEntry* entry);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FreeHostEntry")]
internal static extern unsafe void FreeHostEntry(HostEntry* entry);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FreeHostEntry")]
internal static unsafe partial void FreeHostEntry(HostEntry* entry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ internal static partial class Sys
/// <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>
/// <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>
/// <returns>An error or Error.SUCCESS.</returns>
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Poll")]
internal static extern unsafe Error Poll(PollEvent* pollEvents, uint eventCount, int timeout, uint* triggered);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Poll")]
internal static unsafe partial Error Poll(PollEvent* pollEvents, uint eventCount, int timeout, uint* triggered);

/// <summary>
/// Polls a File Descriptor for the passed in flags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Socket")]
internal static extern unsafe Error Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, IntPtr* socket);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Socket")]
internal static unsafe partial Error Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, IntPtr* socket);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,38 @@ internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPSocketAddressSizes")]
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPSocketAddressSizes")]
[SuppressGCTransition]
internal static extern unsafe Error GetIPSocketAddressSizes(int* ipv4SocketAddressSize, int* ipv6SocketAddressSize);
internal static unsafe partial Error GetIPSocketAddressSizes(int* ipv4SocketAddressSize, int* ipv6SocketAddressSize);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetAddressFamily")]
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetAddressFamily")]
[SuppressGCTransition]
internal static extern unsafe Error GetAddressFamily(byte* socketAddress, int socketAddressLen, int* addressFamily);
internal static unsafe partial Error GetAddressFamily(byte* socketAddress, int socketAddressLen, int* addressFamily);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetAddressFamily")]
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetAddressFamily")]
[SuppressGCTransition]
internal static extern unsafe Error SetAddressFamily(byte* socketAddress, int socketAddressLen, int addressFamily);
internal static unsafe partial Error SetAddressFamily(byte* socketAddress, int socketAddressLen, int addressFamily);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPort")]
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPort")]
[SuppressGCTransition]
internal static extern unsafe Error GetPort(byte* socketAddress, int socketAddressLen, ushort* port);
internal static unsafe partial Error GetPort(byte* socketAddress, int socketAddressLen, ushort* port);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetPort")]
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetPort")]
[SuppressGCTransition]
internal static extern unsafe Error SetPort(byte* socketAddress, int socketAddressLen, ushort port);
internal static unsafe partial Error SetPort(byte* socketAddress, int socketAddressLen, ushort port);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv4Address")]
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv4Address")]
[SuppressGCTransition]
internal static extern unsafe Error GetIPv4Address(byte* socketAddress, int socketAddressLen, uint* address);
internal static unsafe partial Error GetIPv4Address(byte* socketAddress, int socketAddressLen, uint* address);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetIPv4Address")]
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetIPv4Address")]
[SuppressGCTransition]
internal static extern unsafe Error SetIPv4Address(byte* socketAddress, int socketAddressLen, uint address);
internal static unsafe partial Error SetIPv4Address(byte* socketAddress, int socketAddressLen, uint address);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv6Address")]
internal static extern unsafe Error GetIPv6Address(byte* socketAddress, int socketAddressLen, byte* address, int addressLen, uint* scopeId);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv6Address")]
internal static unsafe partial Error GetIPv6Address(byte* socketAddress, int socketAddressLen, byte* address, int addressLen, uint* scopeId);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetIPv6Address")]
internal static extern unsafe Error SetIPv6Address(byte* socketAddress, int socketAddressLen, byte* address, int addressLen, uint scopeId);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetIPv6Address")]
internal static unsafe partial Error SetIPv6Address(byte* socketAddress, int socketAddressLen, byte* address, int addressLen, uint scopeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ internal static partial class NetSecurityNative
[GeneratedDllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_IsNtlmInstalled")]
internal static partial bool IsNtlmInstalled();

[DllImport(Interop.Libraries.NetSecurityNative, EntryPoint = "NetSecurityNative_EnsureGssInitialized")]
private static extern int EnsureGssInitialized();
[GeneratedDllImport(Interop.Libraries.NetSecurityNative, EntryPoint = "NetSecurityNative_EnsureGssInitialized")]
private static partial int EnsureGssInitialized();

static NetSecurityNative()
{
Expand Down
Loading