mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-08 03:27:04 +09:00
Move DllImportGenerator to use DisableRuntimeMarshalling for its blittable classification (#64279)
This commit is contained in:
parent
b0e16a1802
commit
ccd67b0c44
214 changed files with 6599 additions and 2957 deletions
|
@ -26,6 +26,10 @@
|
|||
<InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(VersionSuffix)' != ''">$(ProductVersion)-$(VersionSuffix)</InformationalVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<SupportedNETCoreAppTargetFramework Include=".NETCoreApp,Version=v$(NETCoreAppMaximumVersion)" DisplayName=".NET $(NETCoreAppMaximumVersion)" Alias="net$(NETCoreAppMaximumVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- The Default behavior in VS is to show files for the first target framework in TargetFrameworks property.
|
||||
This is required to show all the files corresponding to all target frameworks in VS. -->
|
||||
<ItemGroup Condition="'$(DefaultLanguageSourceExtension)' != '' and
|
||||
|
|
|
@ -40,11 +40,8 @@ namespace System.Diagnostics.Tracing
|
|||
[GeneratedDllImport(RuntimeHelpers.QCall, EntryPoint = "EventPipeInternal_DeleteProvider")]
|
||||
internal static partial void DeleteProvider(IntPtr provHandle);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(RuntimeHelpers.QCall, EntryPoint = "EventPipeInternal_EventActivityIdControl")]
|
||||
internal static extern int EventActivityIdControl(uint controlCode, ref Guid activityId);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
[GeneratedDllImport(RuntimeHelpers.QCall, EntryPoint = "EventPipeInternal_EventActivityIdControl")]
|
||||
internal static partial int EventActivityIdControl(uint controlCode, ref Guid activityId);
|
||||
|
||||
[GeneratedDllImport(RuntimeHelpers.QCall, EntryPoint = "EventPipeInternal_WriteEventData")]
|
||||
internal static unsafe partial void WriteEventData(IntPtr eventHandle, EventProvider.EventData* pEventData, uint dataCount, Guid* activityId, Guid* relatedActivityId);
|
||||
|
|
|
@ -283,11 +283,9 @@ namespace System.Runtime.InteropServices
|
|||
GetTypeFromCLSID(clsid, server, ObjectHandleOnStack.Create(ref type));
|
||||
return type;
|
||||
}
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(RuntimeHelpers.QCall, EntryPoint = "MarshalNative_GetTypeFromCLSID", CharSet = CharSet.Unicode)]
|
||||
private static extern void GetTypeFromCLSID(in Guid clsid, string? server, ObjectHandleOnStack retType);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
|
||||
[GeneratedDllImport(RuntimeHelpers.QCall, EntryPoint = "MarshalNative_GetTypeFromCLSID", CharSet = CharSet.Unicode)]
|
||||
private static partial void GetTypeFromCLSID(in Guid clsid, string? server, ObjectHandleOnStack retType);
|
||||
|
||||
/// <summary>
|
||||
/// Return the IUnknown* for an Object if the current context is the one
|
||||
|
@ -698,32 +696,48 @@ namespace System.Runtime.InteropServices
|
|||
throw new NotSupportedException(SR.NotSupported_COM);
|
||||
}
|
||||
|
||||
CreateBindCtx(0, out IBindCtx bindctx);
|
||||
ThrowExceptionForHR(CreateBindCtx(0, out IntPtr bindctx));
|
||||
|
||||
MkParseDisplayName(bindctx, monikerName, out _, out IMoniker pmoniker);
|
||||
BindMoniker(pmoniker, 0, ref IID_IUnknown, out object obj);
|
||||
|
||||
return obj;
|
||||
try
|
||||
{
|
||||
ThrowExceptionForHR(MkParseDisplayName(bindctx, monikerName, out _, out IntPtr pmoniker));
|
||||
try
|
||||
{
|
||||
ThrowExceptionForHR(BindMoniker(pmoniker, 0, ref IID_IUnknown, out IntPtr ptr));
|
||||
try
|
||||
{
|
||||
return GetObjectForIUnknown(ptr);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Release(ptr);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Release(pmoniker);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Release(bindctx);
|
||||
}
|
||||
}
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// These methods use built-in COM interop, which is not supported by the source generator.
|
||||
|
||||
// Revist after https://github.com/mono/linker/issues/1989 is fixed
|
||||
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern",
|
||||
Justification = "The calling method is annotated with RequiresUnreferencedCode")]
|
||||
[DllImport(Interop.Libraries.Ole32, PreserveSig = false)]
|
||||
private static extern void CreateBindCtx(uint reserved, out IBindCtx ppbc);
|
||||
[GeneratedDllImport(Interop.Libraries.Ole32)]
|
||||
private static partial int CreateBindCtx(uint reserved, out IntPtr ppbc);
|
||||
|
||||
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern",
|
||||
Justification = "The calling method is annotated with RequiresUnreferencedCode")]
|
||||
[DllImport(Interop.Libraries.Ole32, PreserveSig = false)]
|
||||
private static extern void MkParseDisplayName(IBindCtx pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IMoniker ppmk);
|
||||
[GeneratedDllImport(Interop.Libraries.Ole32, PreserveSig = false)]
|
||||
private static partial int MkParseDisplayName(IntPtr pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IntPtr ppmk);
|
||||
|
||||
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern",
|
||||
Justification = "The calling method is annotated with RequiresUnreferencedCode")]
|
||||
[DllImport(Interop.Libraries.Ole32, PreserveSig = false)]
|
||||
private static extern void BindMoniker(IMoniker pmk, uint grfOpt, ref Guid iidResult, [MarshalAs(UnmanagedType.Interface)] out object ppvResult);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
[GeneratedDllImport(Interop.Libraries.Ole32, PreserveSig = false)]
|
||||
private static partial int BindMoniker(IntPtr pmk, uint grfOpt, ref Guid iidResult, out IntPtr ppvResult);
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace System.Runtime
|
|||
IDynamicCastableGetInterfaceImplementation = 9,
|
||||
}
|
||||
|
||||
internal static class InternalCalls
|
||||
internal static partial class InternalCalls
|
||||
{
|
||||
//
|
||||
// internalcalls for System.GC.
|
||||
|
@ -59,8 +59,9 @@ namespace System.Runtime
|
|||
RhpCollect(generation, mode);
|
||||
}
|
||||
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern void RhpCollect(int generation, InternalGCCollectionMode mode);
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
private static partial void RhpCollect(int generation, InternalGCCollectionMode mode);
|
||||
|
||||
[RuntimeExport("RhGetGcTotalMemory")]
|
||||
internal static long RhGetGcTotalMemory()
|
||||
|
@ -68,8 +69,9 @@ namespace System.Runtime
|
|||
return RhpGetGcTotalMemory();
|
||||
}
|
||||
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern long RhpGetGcTotalMemory();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
private static partial long RhpGetGcTotalMemory();
|
||||
|
||||
[RuntimeExport("RhStartNoGCRegion")]
|
||||
internal static int RhStartNoGCRegion(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC)
|
||||
|
@ -284,39 +286,49 @@ namespace System.Runtime
|
|||
|
||||
// Block the current thread until at least one object needs to be finalized (returns true) or
|
||||
// memory is low (returns false and the finalizer thread should initiate a garbage collection).
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern uint RhpWaitForFinalizerRequest();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial uint RhpWaitForFinalizerRequest();
|
||||
|
||||
// Indicate that the current round of finalizations is complete.
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void RhpSignalFinalizationComplete();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial void RhpSignalFinalizationComplete();
|
||||
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void RhpAcquireCastCacheLock();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial void RhpAcquireCastCacheLock();
|
||||
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void RhpReleaseCastCacheLock();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial void RhpReleaseCastCacheLock();
|
||||
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern ulong RhpGetTickCount64();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial ulong RhpGetTickCount64();
|
||||
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void RhpAcquireThunkPoolLock();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial void RhpAcquireThunkPoolLock();
|
||||
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void RhpReleaseThunkPoolLock();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial void RhpReleaseThunkPoolLock();
|
||||
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr RhAllocateThunksMapping();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial IntPtr RhAllocateThunksMapping();
|
||||
|
||||
// Enters a no GC region, possibly doing a blocking GC if there is not enough
|
||||
// memory available to satisfy the caller's request.
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern int RhpStartNoGCRegion(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC);
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial int RhpStartNoGCRegion(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC);
|
||||
|
||||
// Exits a no GC region, possibly doing a GC to clean up the garbage that
|
||||
// the caller allocated.
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern int RhpEndNoGCRegion();
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial int RhpEndNoGCRegion();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an equivalent to <see cref="UnmanagedCallersOnlyAttribute"/> for native
|
||||
/// functions declared in .NET.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
public sealed class UnmanagedCallConvAttribute : Attribute
|
||||
{
|
||||
public UnmanagedCallConvAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Types indicating calling conventions for the unmanaged target.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If <c>null</c>, the semantics are identical to <c>CallingConvention.Winapi</c>.
|
||||
/// </remarks>
|
||||
public Type[]? CallConvs;
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ using Internal.Runtime.CompilerServices;
|
|||
|
||||
namespace System.Runtime
|
||||
{
|
||||
internal static class RuntimeExports
|
||||
internal static partial class RuntimeExports
|
||||
{
|
||||
//
|
||||
// internal calls for allocation
|
||||
|
@ -301,8 +301,9 @@ namespace System.Runtime
|
|||
return RhpGetCurrentThreadStackTrace(pOutputBuffer, (uint)((outputBuffer != null) ? outputBuffer.Length : 0), new UIntPtr(&pOutputBuffer));
|
||||
}
|
||||
|
||||
[DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe int RhpGetCurrentThreadStackTrace(IntPtr* pOutputBuffer, uint outputBufferLength, UIntPtr addressInCurrentFrame);
|
||||
[GeneratedDllImport(Redhawk.BaseName)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
private static unsafe partial int RhpGetCurrentThreadStackTrace(IntPtr* pOutputBuffer, uint outputBufferLength, UIntPtr addressInCurrentFrame);
|
||||
|
||||
// Worker for RhGetCurrentThreadStackTrace. RhGetCurrentThreadStackTrace just allocates a transition
|
||||
// frame that will be used to seed the stack trace and this method does all the real work.
|
||||
|
|
|
@ -22,16 +22,18 @@ namespace System.Runtime
|
|||
// but if a class library wants to factor differently (such as putting the GCHandle methods in an
|
||||
// optional library, those methods can be moved to a different file/namespace/dll
|
||||
[ReflectionBlocked]
|
||||
public static class RuntimeImports
|
||||
public static partial class RuntimeImports
|
||||
{
|
||||
private const string RuntimeLibrary = "*";
|
||||
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
[SuppressGCTransition]
|
||||
internal static extern ulong RhpGetTickCount64();
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial ulong RhpGetTickCount64();
|
||||
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr RhpGetCurrentThread();
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial IntPtr RhpGetCurrentThread();
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
[RuntimeImport(RuntimeLibrary, "RhpInitiateThreadAbort")]
|
||||
|
@ -67,8 +69,8 @@ namespace System.Runtime
|
|||
private static extern bool _RhReRegisterForFinalize(object obj);
|
||||
|
||||
// Wait for all pending finalizers. This must be a p/invoke to avoid starving the GC.
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
private static extern void RhWaitForPendingFinalizers(int allowReentrantWait);
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
private static partial void RhWaitForPendingFinalizers(int allowReentrantWait);
|
||||
|
||||
// Temporary workaround to unblock shareable assembly bring-up - without shared interop,
|
||||
// we must prevent RhWaitForPendingFinalizers from using marshaling because it would
|
||||
|
@ -80,8 +82,8 @@ namespace System.Runtime
|
|||
RhWaitForPendingFinalizers(allowReentrantWait ? 1 : 0);
|
||||
}
|
||||
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static extern void RhInitializeFinalizerThread();
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static partial void RhInitializeFinalizerThread();
|
||||
|
||||
// Get maximum GC generation number.
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
|
@ -185,18 +187,19 @@ namespace System.Runtime
|
|||
[RuntimeImport(RuntimeLibrary, "RhGetTotalAllocatedBytes")]
|
||||
internal static extern long RhGetTotalAllocatedBytes();
|
||||
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern long RhGetTotalAllocatedBytesPrecise();
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial long RhGetTotalAllocatedBytesPrecise();
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
[RuntimeImport(RuntimeLibrary, "RhGetMemoryInfo")]
|
||||
internal static extern void RhGetMemoryInfo(ref byte info, GCKind kind);
|
||||
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static unsafe extern void RhAllocateNewArray(IntPtr pArrayEEType, uint numElements, uint flags, void* pResult);
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static unsafe partial void RhAllocateNewArray(IntPtr pArrayEEType, uint numElements, uint flags, void* pResult);
|
||||
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static unsafe extern void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static unsafe partial void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
[RuntimeImport(RuntimeLibrary, "RhCompareObjectContentsAndPadding")]
|
||||
|
@ -365,23 +368,26 @@ namespace System.Runtime
|
|||
internal static extern object RhMemberwiseClone(object obj);
|
||||
|
||||
// Busy spin for the given number of iterations.
|
||||
[DllImport(RuntimeLibrary, EntryPoint = "RhSpinWait", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhSpinWait", ExactSpelling = true)]
|
||||
[SuppressGCTransition]
|
||||
internal static extern void RhSpinWait(int iterations);
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial void RhSpinWait(int iterations);
|
||||
|
||||
// Yield the cpu to another thread ready to process, if one is available.
|
||||
[DllImport(RuntimeLibrary, EntryPoint = "RhYield", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
private static extern int _RhYield();
|
||||
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhYield", ExactSpelling = true)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
private static partial int _RhYield();
|
||||
internal static bool RhYield() { return (_RhYield() != 0); }
|
||||
|
||||
[DllImport(RuntimeLibrary, EntryPoint = "RhFlushProcessWriteBuffers", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||
internal static extern void RhFlushProcessWriteBuffers();
|
||||
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhFlushProcessWriteBuffers", ExactSpelling = true)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static partial void RhFlushProcessWriteBuffers();
|
||||
|
||||
#if !TARGET_UNIX
|
||||
// Wait for any object to be signalled, in a way that's compatible with the CLR's behavior in an STA.
|
||||
// ExactSpelling = 'true' to force MCG to resolve it to default
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
private static extern unsafe int RhCompatibleReentrantWaitAny(int alertable, int timeout, int count, IntPtr* handles);
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
private static unsafe partial int RhCompatibleReentrantWaitAny(int alertable, int timeout, int count, IntPtr* handles);
|
||||
|
||||
// Temporary workaround to unblock shareable assembly bring-up - without shared interop,
|
||||
// we must prevent RhCompatibleReentrantWaitAny from using marshaling because it would
|
||||
|
@ -611,8 +617,8 @@ namespace System.Runtime
|
|||
internal static extern void RhCallDescrWorker(IntPtr callDescr);
|
||||
|
||||
// For Managed to Native calls
|
||||
[DllImport(RuntimeLibrary, EntryPoint = "RhCallDescrWorker", ExactSpelling = true)]
|
||||
internal static extern void RhCallDescrWorkerNative(IntPtr callDescr);
|
||||
[GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhCallDescrWorker", ExactSpelling = true)]
|
||||
internal static partial void RhCallDescrWorkerNative(IntPtr callDescr);
|
||||
|
||||
// Moves memory from smem to dmem. Size must be a positive value.
|
||||
// This copy uses an intrinsic to be safe for copying arbitrary bits of
|
||||
|
@ -929,15 +935,16 @@ namespace System.Runtime
|
|||
[RuntimeImport(RuntimeLibrary, "modff")]
|
||||
internal static extern unsafe float modff(float x, float* intptr);
|
||||
|
||||
[DllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static extern unsafe void* memmove(byte* dmem, byte* smem, nuint size);
|
||||
[GeneratedDllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static unsafe partial void* memmove(byte* dmem, byte* smem, nuint size);
|
||||
|
||||
[DllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static extern unsafe void* memset(byte* mem, int value, nuint size);
|
||||
[GeneratedDllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static unsafe partial void* memset(byte* mem, int value, nuint size);
|
||||
|
||||
#if TARGET_X86 || TARGET_AMD64
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void RhCpuIdEx(int* cpuInfo, int functionId, int subFunctionId);
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
|
||||
internal static unsafe partial void RhCpuIdEx(int* cpuInfo, int functionId, int subFunctionId);
|
||||
#endif
|
||||
|
||||
internal static RhCorElementTypeInfo GetRhCorElementTypeInfo(CorElementType elementType)
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace System.Runtime
|
|||
// but if a class library wants to factor differently (such as putting the GCHandle methods in an
|
||||
// optional library, those methods can be moved to a different file/namespace/dll
|
||||
|
||||
public static class RuntimeImports
|
||||
public static partial class RuntimeImports
|
||||
{
|
||||
private const string RuntimeLibrary = "*";
|
||||
|
||||
|
@ -85,8 +85,8 @@ namespace System.Runtime
|
|||
internal static unsafe Array RhNewArray(EETypePtr pEEType, int length)
|
||||
=> RhNewArray(pEEType.ToPointer(), length);
|
||||
|
||||
[DllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static unsafe extern void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
|
||||
[GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
|
||||
internal static unsafe partial void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
[RuntimeImport(RuntimeLibrary, "RhpFallbackFailFast")]
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<EnableDllImportGenerator>true</EnableDllImportGenerator>
|
||||
<!--
|
||||
DLLIMPORTGEN003: DllImportGenerator Target Framework Not Supported.
|
||||
-->
|
||||
<NoWarn>$(NoWarn);DLLIMPORTGEN003</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
|
||||
<DefineConstants>FEATURE_GC_STRESS;$(DefineConstants)</DefineConstants>
|
||||
|
@ -184,6 +189,9 @@
|
|||
<Compile Include="..\..\Runtime.Base\src\System\Runtime\InteropServices\LayoutKind.cs">
|
||||
<Link>System\Runtime\InteropServices\LayoutKind.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\Runtime.Base\src\System\Runtime\InteropServices\UnmanagedCallConvAttribute.cs">
|
||||
<Link>System\Runtime\InteropServices\UnmanagedCallConvAttribute.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\Runtime.Base\src\System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs">
|
||||
<Link>System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -872,26 +872,28 @@ namespace Internal.TypeSystem.Interop
|
|||
internal static MarshallerKind GetDisabledMarshallerKind(
|
||||
TypeDesc type)
|
||||
{
|
||||
if (type.Category == TypeFlags.Void)
|
||||
// Get the underlying type for enum types.
|
||||
TypeDesc underlyingType = type.UnderlyingType;
|
||||
if (underlyingType.Category == TypeFlags.Void)
|
||||
{
|
||||
return MarshallerKind.VoidReturn;
|
||||
}
|
||||
else if (type.IsByRef)
|
||||
else if (underlyingType.IsByRef)
|
||||
{
|
||||
// Managed refs are not supported when runtime marshalling is disabled.
|
||||
return MarshallerKind.Invalid;
|
||||
}
|
||||
else if (type.IsPrimitive)
|
||||
else if (underlyingType.IsPrimitive)
|
||||
{
|
||||
return MarshallerKind.BlittableValue;
|
||||
}
|
||||
else if (type.IsPointer || type.IsFunctionPointer)
|
||||
else if (underlyingType.IsPointer || underlyingType.IsFunctionPointer)
|
||||
{
|
||||
return MarshallerKind.BlittableValue;
|
||||
}
|
||||
else if (type.IsValueType)
|
||||
else if (underlyingType.IsValueType)
|
||||
{
|
||||
var defType = (DefType)type;
|
||||
var defType = (DefType)underlyingType;
|
||||
if (!defType.ContainsGCPointers && !defType.IsAutoLayoutOrHasAutoLayoutFields)
|
||||
{
|
||||
return MarshallerKind.BlittableValue;
|
||||
|
|
|
@ -3349,6 +3349,7 @@ BOOL NDirect::MarshalingRequired(
|
|||
// any types that contain gc pointers, but all "unmanaged" types are treated as blittable
|
||||
// as long as they aren't auto-layout and don't have any auto-layout fields.
|
||||
if (!runtimeMarshallingEnabled &&
|
||||
!hndArgType.IsEnum() &&
|
||||
(hndArgType.GetMethodTable()->ContainsPointers()
|
||||
|| hndArgType.GetMethodTable()->IsAutoLayoutOrHasAutoLayoutField()))
|
||||
{
|
||||
|
|
|
@ -1065,65 +1065,79 @@ namespace
|
|||
MethodTable** pMTOut,
|
||||
UINT* errorResIDOut)
|
||||
{
|
||||
switch (sig.PeekElemTypeNormalized(pModule, pTypeContext))
|
||||
while (true)
|
||||
{
|
||||
case ELEMENT_TYPE_BOOLEAN:
|
||||
case ELEMENT_TYPE_U1:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_U1;
|
||||
case ELEMENT_TYPE_I1:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_1;
|
||||
case ELEMENT_TYPE_CHAR:
|
||||
case ELEMENT_TYPE_U2:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_U2;
|
||||
case ELEMENT_TYPE_I2:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_2;
|
||||
case ELEMENT_TYPE_U4:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_U4;
|
||||
case ELEMENT_TYPE_I4:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_4;
|
||||
case ELEMENT_TYPE_U8:
|
||||
case ELEMENT_TYPE_I8:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_8;
|
||||
#ifdef TARGET_64BIT
|
||||
case ELEMENT_TYPE_U:
|
||||
case ELEMENT_TYPE_PTR:
|
||||
case ELEMENT_TYPE_FNPTR:
|
||||
case ELEMENT_TYPE_I:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_8;
|
||||
#else
|
||||
case ELEMENT_TYPE_U:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_U4;
|
||||
case ELEMENT_TYPE_PTR:
|
||||
case ELEMENT_TYPE_FNPTR:
|
||||
case ELEMENT_TYPE_I:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_4;
|
||||
#endif
|
||||
case ELEMENT_TYPE_R4:
|
||||
return MarshalInfo::MARSHAL_TYPE_FLOAT;
|
||||
case ELEMENT_TYPE_R8:
|
||||
return MarshalInfo::MARSHAL_TYPE_DOUBLE;
|
||||
case ELEMENT_TYPE_VAR:
|
||||
case ELEMENT_TYPE_VALUETYPE:
|
||||
{
|
||||
TypeHandle sigTH = sig.GetTypeHandleThrowing(pModule, pTypeContext);
|
||||
MethodTable* pMT = sigTH.GetMethodTable();
|
||||
|
||||
if (!pMT->IsValueType() || pMT->ContainsPointers())
|
||||
switch (sig.PeekElemTypeNormalized(pModule, pTypeContext))
|
||||
{
|
||||
// Skip modreqs and modopts in the signature.
|
||||
case ELEMENT_TYPE_CMOD_OPT:
|
||||
case ELEMENT_TYPE_CMOD_REQD:
|
||||
{
|
||||
if(FAILED(sig.GetElemType(NULL)))
|
||||
{
|
||||
*errorResIDOut = IDS_EE_BADMARSHAL_MARSHAL_DISABLED;
|
||||
return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ELEMENT_TYPE_BOOLEAN:
|
||||
case ELEMENT_TYPE_U1:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_U1;
|
||||
case ELEMENT_TYPE_I1:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_1;
|
||||
case ELEMENT_TYPE_CHAR:
|
||||
case ELEMENT_TYPE_U2:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_U2;
|
||||
case ELEMENT_TYPE_I2:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_2;
|
||||
case ELEMENT_TYPE_U4:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_U4;
|
||||
case ELEMENT_TYPE_I4:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_4;
|
||||
case ELEMENT_TYPE_U8:
|
||||
case ELEMENT_TYPE_I8:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_8;
|
||||
#ifdef TARGET_64BIT
|
||||
case ELEMENT_TYPE_U:
|
||||
case ELEMENT_TYPE_PTR:
|
||||
case ELEMENT_TYPE_FNPTR:
|
||||
case ELEMENT_TYPE_I:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_8;
|
||||
#else
|
||||
case ELEMENT_TYPE_U:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_U4;
|
||||
case ELEMENT_TYPE_PTR:
|
||||
case ELEMENT_TYPE_FNPTR:
|
||||
case ELEMENT_TYPE_I:
|
||||
return MarshalInfo::MARSHAL_TYPE_GENERIC_4;
|
||||
#endif
|
||||
case ELEMENT_TYPE_R4:
|
||||
return MarshalInfo::MARSHAL_TYPE_FLOAT;
|
||||
case ELEMENT_TYPE_R8:
|
||||
return MarshalInfo::MARSHAL_TYPE_DOUBLE;
|
||||
case ELEMENT_TYPE_VAR:
|
||||
case ELEMENT_TYPE_VALUETYPE:
|
||||
{
|
||||
TypeHandle sigTH = sig.GetTypeHandleThrowing(pModule, pTypeContext);
|
||||
MethodTable* pMT = sigTH.GetMethodTable();
|
||||
|
||||
if (!pMT->IsValueType() || pMT->ContainsPointers())
|
||||
{
|
||||
*errorResIDOut = IDS_EE_BADMARSHAL_MARSHAL_DISABLED;
|
||||
return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
|
||||
}
|
||||
if (pMT->IsAutoLayoutOrHasAutoLayoutField())
|
||||
{
|
||||
*errorResIDOut = IDS_EE_BADMARSHAL_AUTOLAYOUT;
|
||||
return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
|
||||
}
|
||||
*pMTOut = pMT;
|
||||
return MarshalInfo::MARSHAL_TYPE_BLITTABLEVALUECLASS;
|
||||
}
|
||||
default:
|
||||
*errorResIDOut = IDS_EE_BADMARSHAL_MARSHAL_DISABLED;
|
||||
return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
|
||||
}
|
||||
if (pMT->IsAutoLayoutOrHasAutoLayoutField())
|
||||
{
|
||||
*errorResIDOut = IDS_EE_BADMARSHAL_AUTOLAYOUT;
|
||||
return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
|
||||
}
|
||||
*pMTOut = pMT;
|
||||
return MarshalInfo::MARSHAL_TYPE_BLITTABLEVALUECLASS;
|
||||
}
|
||||
default:
|
||||
*errorResIDOut = IDS_EE_BADMARSHAL_MARSHAL_DISABLED;
|
||||
return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
5
src/libraries/Common/src/DisableRuntimeMarshalling.cs
Normal file
5
src/libraries/Common/src/DisableRuntimeMarshalling.cs
Normal file
|
@ -0,0 +1,5 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
// Used to indicate that runtime marshalling should be disabled.
|
||||
[assembly: System.Runtime.CompilerServices.DisableRuntimeMarshalling]
|
|
@ -8,12 +8,12 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class HostPolicy
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)]
|
||||
internal delegate void corehost_resolve_component_dependencies_result_fn(string assemblyPaths,
|
||||
string nativeSearchPaths, string resourceSearchPaths);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal delegate void corehost_resolve_component_dependencies_result_fn(IntPtr assemblyPaths,
|
||||
IntPtr nativeSearchPaths, IntPtr resourceSearchPaths);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)]
|
||||
internal delegate void corehost_error_writer_fn(string message);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal delegate void corehost_error_writer_fn(IntPtr message);
|
||||
|
||||
#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant
|
||||
[GeneratedDllImport(Libraries.HostPolicy, CharSet = CharSet.Auto)]
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Authentication;
|
||||
|
||||
internal static partial class Interop
|
||||
{
|
||||
|
@ -15,7 +17,7 @@ internal static partial class Interop
|
|||
namespace System.DirectoryServices.Protocols
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal sealed class Luid
|
||||
internal readonly struct Luid
|
||||
{
|
||||
private readonly int _lowPart;
|
||||
private readonly int _highPart;
|
||||
|
@ -24,8 +26,11 @@ namespace System.DirectoryServices.Protocols
|
|||
public int HighPart => _highPart;
|
||||
}
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
[NativeMarshalling(typeof(Native))]
|
||||
#endif
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal sealed class SEC_WINNT_AUTH_IDENTITY_EX
|
||||
internal struct SEC_WINNT_AUTH_IDENTITY_EX
|
||||
{
|
||||
public int version;
|
||||
public int length;
|
||||
|
@ -38,6 +43,45 @@ namespace System.DirectoryServices.Protocols
|
|||
public int flags;
|
||||
public string packageList;
|
||||
public int packageListLength;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct Native
|
||||
{
|
||||
public int version;
|
||||
public int length;
|
||||
public IntPtr user;
|
||||
public int userLength;
|
||||
public IntPtr domain;
|
||||
public int domainLength;
|
||||
public IntPtr password;
|
||||
public int passwordLength;
|
||||
public int flags;
|
||||
public IntPtr packageList;
|
||||
public int packageListLength;
|
||||
|
||||
public Native(SEC_WINNT_AUTH_IDENTITY_EX managed)
|
||||
{
|
||||
version = managed.version;
|
||||
length = managed.length;
|
||||
user = Marshal.StringToCoTaskMemUni(managed.user);
|
||||
userLength = managed.userLength;
|
||||
domain = Marshal.StringToCoTaskMemUni(managed.domain);
|
||||
domainLength = managed.domainLength;
|
||||
password = Marshal.StringToCoTaskMemUni(managed.password);
|
||||
passwordLength = managed.passwordLength;
|
||||
flags = managed.flags;
|
||||
packageList = Marshal.StringToCoTaskMemUni(managed.packageList);
|
||||
packageListLength = managed.packageListLength;
|
||||
}
|
||||
|
||||
public void FreeNative()
|
||||
{
|
||||
Marshal.FreeCoTaskMem(user);
|
||||
Marshal.FreeCoTaskMem(domain);
|
||||
Marshal.FreeCoTaskMem(password);
|
||||
Marshal.FreeCoTaskMem(packageList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal enum BindMethod : uint // Not Supported in Linux
|
||||
|
@ -113,19 +157,35 @@ namespace System.DirectoryServices.Protocols
|
|||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal sealed class LDAP_TIMEVAL
|
||||
internal struct LDAP_TIMEVAL
|
||||
{
|
||||
public int tv_sec;
|
||||
public int tv_usec;
|
||||
}
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
[NativeMarshalling(typeof(PinningMarshaller))]
|
||||
#endif
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal sealed class BerVal
|
||||
{
|
||||
public int bv_len;
|
||||
public IntPtr bv_val = IntPtr.Zero;
|
||||
|
||||
public BerVal() { }
|
||||
#if NET7_0_OR_GREATER
|
||||
internal unsafe struct PinningMarshaller
|
||||
{
|
||||
private readonly BerVal _managed;
|
||||
public PinningMarshaller(BerVal managed)
|
||||
{
|
||||
_managed = managed;
|
||||
}
|
||||
|
||||
public ref int GetPinnableReference() => ref (_managed is null ? ref Unsafe.NullRef<int>() : ref _managed.bv_len);
|
||||
|
||||
public void* Value => Unsafe.AsPointer(ref GetPinnableReference());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
|
@ -138,13 +198,64 @@ namespace System.DirectoryServices.Protocols
|
|||
public LdapControl() { }
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
#if NET7_0_OR_GREATER
|
||||
[NativeMarshalling(typeof(Marshaller))]
|
||||
#endif
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct LdapReferralCallback
|
||||
{
|
||||
public int sizeofcallback;
|
||||
public QUERYFORCONNECTIONInternal query;
|
||||
public NOTIFYOFNEWCONNECTIONInternal notify;
|
||||
public DEREFERENCECONNECTIONInternal dereference;
|
||||
#if NET7_0_OR_GREATER
|
||||
public static readonly unsafe int Size = sizeof(Marshaller.Native);
|
||||
|
||||
public unsafe struct Marshaller
|
||||
{
|
||||
public unsafe struct Native
|
||||
{
|
||||
public int sizeofcallback;
|
||||
public IntPtr query;
|
||||
public IntPtr notify;
|
||||
public IntPtr dereference;
|
||||
}
|
||||
|
||||
private LdapReferralCallback _managed;
|
||||
private Native _native;
|
||||
|
||||
public Marshaller(LdapReferralCallback managed)
|
||||
: this()
|
||||
{
|
||||
_managed = managed;
|
||||
_native.sizeofcallback = sizeof(Native);
|
||||
_native.query = managed.query is not null ? Marshal.GetFunctionPointerForDelegate(managed.query) : IntPtr.Zero;
|
||||
_native.notify = managed.notify is not null ? Marshal.GetFunctionPointerForDelegate(managed.notify) : IntPtr.Zero;
|
||||
_native.dereference = managed.dereference is not null ? Marshal.GetFunctionPointerForDelegate(managed.dereference) : IntPtr.Zero;
|
||||
}
|
||||
|
||||
public Native Value
|
||||
{
|
||||
get => _native;
|
||||
set => _native = value;
|
||||
}
|
||||
|
||||
public LdapReferralCallback ToManaged()
|
||||
{
|
||||
return new LdapReferralCallback()
|
||||
{
|
||||
sizeofcallback = _native.sizeofcallback,
|
||||
query = _native.query != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer<QUERYFORCONNECTIONInternal>(_native.query) : null,
|
||||
notify = _native.notify != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer<NOTIFYOFNEWCONNECTIONInternal>(_native.notify) : null,
|
||||
dereference = _native.dereference != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer<DEREFERENCECONNECTIONInternal>(_native.dereference) : null
|
||||
};
|
||||
}
|
||||
|
||||
public void FreeNative() => GC.KeepAlive(_managed);
|
||||
}
|
||||
#else
|
||||
public static readonly unsafe int Size = Marshal.SizeOf<LdapReferralCallback>();
|
||||
#endif
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
|
|
|
@ -5,6 +5,9 @@ using System;
|
|||
using System.Data.Odbc;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
#if NET7_0_OR_GREATER
|
||||
using System.Runtime.InteropServices.GeneratedMarshalling;
|
||||
#endif
|
||||
using System.Runtime.Versioning;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
@ -29,12 +32,16 @@ internal static partial class Interop
|
|||
/*SQLHANDLE*/OdbcHandle InputHandle,
|
||||
/*SQLHANDLE* */out IntPtr OutputHandle);
|
||||
|
||||
[DllImport(Interop.Libraries.Odbc32)]
|
||||
internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLBindCol(
|
||||
[GeneratedDllImport(Interop.Libraries.Odbc32)]
|
||||
internal static partial /*SQLRETURN*/ODBC32.SQLRETURN SQLBindCol(
|
||||
/*SQLHSTMT*/OdbcStatementHandle StatementHandle,
|
||||
/*SQLUSMALLINT*/ushort ColumnNumber,
|
||||
/*SQLSMALLINT*/ODBC32.SQL_C TargetType,
|
||||
/*SQLPOINTER*/HandleRef TargetValue,
|
||||
/*SQLPOINTER*/
|
||||
#if NET7_0_OR_GREATER
|
||||
[MarshalUsing(typeof(HandleRefMarshaller))]
|
||||
#endif
|
||||
HandleRef TargetValue,
|
||||
/*SQLLEN*/IntPtr BufferLength,
|
||||
/*SQLLEN* */IntPtr StrLen_or_Ind);
|
||||
|
||||
|
@ -47,8 +54,8 @@ internal static partial class Interop
|
|||
/*SQLLEN*/IntPtr BufferLength,
|
||||
/*SQLLEN* */IntPtr StrLen_or_Ind);
|
||||
|
||||
[DllImport(Interop.Libraries.Odbc32)]
|
||||
internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLBindParameter(
|
||||
[GeneratedDllImport(Interop.Libraries.Odbc32)]
|
||||
internal static partial /*SQLRETURN*/ODBC32.SQLRETURN SQLBindParameter(
|
||||
/*SQLHSTMT*/OdbcStatementHandle StatementHandle,
|
||||
/*SQLUSMALLINT*/ushort ParameterNumber,
|
||||
/*SQLSMALLINT*/short ParamDirection,
|
||||
|
@ -56,9 +63,17 @@ internal static partial class Interop
|
|||
/*SQLSMALLINT*/short SQLType,
|
||||
/*SQLULEN*/IntPtr cbColDef,
|
||||
/*SQLSMALLINT*/IntPtr ibScale,
|
||||
/*SQLPOINTER*/HandleRef rgbValue,
|
||||
/*SQLPOINTER*/
|
||||
#if NET7_0_OR_GREATER
|
||||
[MarshalUsing(typeof(HandleRefMarshaller))]
|
||||
#endif
|
||||
HandleRef rgbValue,
|
||||
/*SQLLEN*/IntPtr BufferLength,
|
||||
/*SQLLEN* */HandleRef StrLen_or_Ind);
|
||||
/*SQLLEN* */
|
||||
#if NET7_0_OR_GREATER
|
||||
[MarshalUsing(typeof(HandleRefMarshaller))]
|
||||
#endif
|
||||
HandleRef StrLen_or_Ind);
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.Odbc32)]
|
||||
internal static partial ODBC32.SQLRETURN SQLCancel(
|
||||
|
@ -176,24 +191,24 @@ internal static partial class Interop
|
|||
/*SQLINTEGER*/int BufferLength,
|
||||
/*SQLINTEGER* */out int StringLength);
|
||||
|
||||
[DllImport(Interop.Libraries.Odbc32, CharSet = CharSet.Unicode)]
|
||||
internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLGetDiagRecW(
|
||||
[GeneratedDllImport(Interop.Libraries.Odbc32, CharSet = CharSet.Unicode)]
|
||||
internal static partial ODBC32.SQLRETURN SQLGetDiagRecW(
|
||||
/*SQLSMALLINT*/ODBC32.SQL_HANDLE HandleType,
|
||||
/*SQLHANDLE*/OdbcHandle Handle,
|
||||
/*SQLSMALLINT*/short RecNumber,
|
||||
/*SQLCHAR* */ [Out] StringBuilder rchState,
|
||||
/*SQLCHAR* */ char[] rchState,
|
||||
/*SQLINTEGER* */out int NativeError,
|
||||
/*SQLCHAR* */ [Out] StringBuilder MessageText,
|
||||
/*SQLCHAR* */ char[] MessageText,
|
||||
/*SQLSMALLINT*/short BufferLength,
|
||||
/*SQLSMALLINT* */out short TextLength);
|
||||
|
||||
[DllImport(Interop.Libraries.Odbc32, CharSet = CharSet.Unicode)]
|
||||
internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLGetDiagFieldW(
|
||||
[GeneratedDllImport(Interop.Libraries.Odbc32, CharSet = CharSet.Unicode)]
|
||||
internal static partial ODBC32.SQLRETURN SQLGetDiagFieldW(
|
||||
/*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType,
|
||||
/*SQLHANDLE*/ OdbcHandle Handle,
|
||||
/*SQLSMALLINT*/ short RecNumber,
|
||||
/*SQLSMALLINT*/ short DiagIdentifier,
|
||||
/*SQLPOINTER*/ [Out] StringBuilder rchState,
|
||||
/*SQLPOINTER*/ char[] rchState,
|
||||
/*SQLSMALLINT*/ short BufferLength,
|
||||
/*SQLSMALLINT* */ out short StringLength);
|
||||
|
||||
|
@ -305,12 +320,16 @@ internal static partial class Interop
|
|||
/*SQLPOINTER*/IntPtr Value,
|
||||
/*SQLINTEGER*/int StringLength);
|
||||
|
||||
[DllImport(Interop.Libraries.Odbc32)]
|
||||
internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLSetDescFieldW(
|
||||
[GeneratedDllImport(Interop.Libraries.Odbc32)]
|
||||
internal static partial /*SQLRETURN*/ODBC32.SQLRETURN SQLSetDescFieldW(
|
||||
/*SQLHSTMT*/OdbcDescriptorHandle StatementHandle,
|
||||
/*SQLSMALLINT*/short ColumnNumber,
|
||||
/*SQLSMALLINT*/ODBC32.SQL_DESC FieldIdentifier,
|
||||
/*SQLPOINTER*/HandleRef CharacterAttribute,
|
||||
/*SQLPOINTER*/
|
||||
#if NET7_0_OR_GREATER
|
||||
[MarshalUsing(typeof(HandleRefMarshaller))]
|
||||
#endif
|
||||
HandleRef CharacterAttribute,
|
||||
/*SQLINTEGER*/int BufferLength);
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.Odbc32)]
|
||||
|
|
|
@ -15,11 +15,8 @@ internal static partial class Interop
|
|||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ber_alloc_t", CharSet = CharSet.Ansi)]
|
||||
public static partial IntPtr ber_alloc(int option);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.OpenLdap, EntryPoint = "ber_init", CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr ber_init(BerVal value);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ber_init", CharSet = CharSet.Ansi)]
|
||||
public static partial IntPtr ber_init(BerVal value);
|
||||
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ber_free", CharSet = CharSet.Ansi)]
|
||||
public static partial IntPtr ber_free(IntPtr berelement, int option);
|
||||
|
|
|
@ -88,11 +88,8 @@ internal static partial class Interop
|
|||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_option", CharSet = CharSet.Ansi)]
|
||||
public static partial int ldap_get_option_bool(ConnectionHandle ldapHandle, LdapOption option, ref bool outValue);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] We need to manually convert SecurityPackageContextConnectionInformation to marshal differently as layout classes are not supported in generated interop.
|
||||
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_option", CharSet = CharSet.Ansi)]
|
||||
public static extern int ldap_get_option_secInfo(ConnectionHandle ldapHandle, LdapOption option, [In, Out] SecurityPackageContextConnectionInformation outValue);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_option", CharSet = CharSet.Ansi)]
|
||||
public static unsafe partial int ldap_get_option_secInfo(ConnectionHandle ldapHandle, LdapOption option, void* outValue);
|
||||
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_option", CharSet = CharSet.Ansi)]
|
||||
public static partial int ldap_get_option_sechandle(ConnectionHandle ldapHandle, LdapOption option, ref SecurityHandle outValue);
|
||||
|
@ -109,11 +106,8 @@ internal static partial class Interop
|
|||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_values_len", CharSet = CharSet.Ansi)]
|
||||
public static partial IntPtr ldap_get_values_len(ConnectionHandle ldapHandle, IntPtr result, string name);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_result", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
public static extern int ldap_result(ConnectionHandle ldapHandle, int messageId, int all, LDAP_TIMEVAL timeout, ref IntPtr Mesage);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_result", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
public static partial int ldap_result(ConnectionHandle ldapHandle, int messageId, int all, in LDAP_TIMEVAL timeout, ref IntPtr Mesage);
|
||||
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_result2error", CharSet = CharSet.Ansi)]
|
||||
public static partial int ldap_result2error(ConnectionHandle ldapHandle, IntPtr result, int freeIt);
|
||||
|
@ -139,11 +133,8 @@ internal static partial class Interop
|
|||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option", CharSet = CharSet.Ansi)]
|
||||
public static partial int ldap_set_option_string(ConnectionHandle ldapHandle, LdapOption option, string inValue);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option", CharSet = CharSet.Ansi)]
|
||||
public static extern int ldap_set_option_referral(ConnectionHandle ldapHandle, LdapOption option, ref LdapReferralCallback outValue);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option", CharSet = CharSet.Ansi)]
|
||||
public static partial int ldap_set_option_referral(ConnectionHandle ldapHandle, LdapOption option, ref LdapReferralCallback outValue);
|
||||
|
||||
// Note that ldap_start_tls_s has a different signature across Windows LDAP and OpenLDAP
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_start_tls_s", CharSet = CharSet.Ansi)]
|
||||
|
@ -161,11 +152,8 @@ internal static partial class Interop
|
|||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_parse_reference", CharSet = CharSet.Ansi)]
|
||||
public static partial int ldap_parse_reference(ConnectionHandle ldapHandle, IntPtr result, ref IntPtr referrals, IntPtr ServerControls, byte freeIt);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_sasl_bind_s", CharSet = CharSet.Ansi)]
|
||||
internal static extern int ldap_sasl_bind(ConnectionHandle ld, string dn, string mechanism, BerVal cred, IntPtr serverctrls, IntPtr clientctrls, IntPtr servercredp);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_sasl_bind_s", CharSet = CharSet.Ansi)]
|
||||
internal static partial int ldap_sasl_bind(ConnectionHandle ld, string dn, string mechanism, in BerVal cred, IntPtr serverctrls, IntPtr clientctrls, IntPtr servercredp);
|
||||
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_sasl_interactive_bind_s", CharSet = CharSet.Ansi)]
|
||||
internal static partial int ldap_sasl_interactive_bind(ConnectionHandle ld, string dn, string mechanism, IntPtr serverctrls, IntPtr clientctrls, uint flags, LDAP_SASL_INTERACT_PROC proc, IntPtr defaults);
|
||||
|
@ -173,11 +161,8 @@ internal static partial class Interop
|
|||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_err2string", CharSet = CharSet.Ansi)]
|
||||
public static partial IntPtr ldap_err2string(int err);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_extended_operation", CharSet = CharSet.Ansi)]
|
||||
public static extern int ldap_extended_operation(ConnectionHandle ldapHandle, string oid, BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_extended_operation", CharSet = CharSet.Ansi)]
|
||||
public static partial int ldap_extended_operation(ConnectionHandle ldapHandle, string oid, in BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_first_attribute", CharSet = CharSet.Ansi)]
|
||||
public static partial IntPtr ldap_first_attribute(ConnectionHandle ldapHandle, IntPtr result, ref IntPtr address);
|
||||
|
@ -233,10 +218,7 @@ internal static partial class Interop
|
|||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_rename", CharSet = CharSet.Ansi)]
|
||||
public static partial int ldap_rename(ConnectionHandle ldapHandle, string dn, string newRdn, string newParentDn, int deleteOldRdn, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.OpenLdap, EntryPoint = "ldap_compare_ext", CharSet = CharSet.Ansi)]
|
||||
public static extern int ldap_compare(ConnectionHandle ldapHandle, string dn, string attributeName, BerVal binaryValue, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_compare_ext", CharSet = CharSet.Ansi)]
|
||||
public static partial int ldap_compare(ConnectionHandle ldapHandle, string dn, string attributeName, in BerVal binaryValue, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,8 @@ internal static partial class Interop
|
|||
public const uint ATTR_CMN_CRTIME = 0x00000200;
|
||||
}
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like CULong)
|
||||
[DllImport(Libraries.libc, EntryPoint = "setattrlist", SetLastError = true)]
|
||||
internal static unsafe extern int setattrlist(string path, AttrList* attrList, void* attrBuf, nint attrBufSize, CULong options);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
[GeneratedDllImport(Libraries.libc, EntryPoint = "setattrlist", CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
internal static unsafe partial int setattrlist(string path, AttrList* attrList, void* attrBuf, nint attrBufSize, CULong options);
|
||||
|
||||
internal const uint FSOPT_NOFOLLOW = 0x00000001;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Sys
|
||||
{
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SearchPath_TempDirectory")]
|
||||
internal static extern string SearchPathTempDirectory();
|
||||
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SearchPath_TempDirectory", CharSet = CharSet.Ansi)]
|
||||
internal static partial string SearchPathTempDirectory();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ internal static partial class Interop
|
|||
internal unsafe partial class Sys
|
||||
{
|
||||
[DoesNotReturn]
|
||||
[DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_Abort")]
|
||||
internal static extern void Abort();
|
||||
[GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_Abort")]
|
||||
internal static partial void Abort();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,16 +8,16 @@ internal static partial class Interop
|
|||
{
|
||||
internal unsafe partial class Sys
|
||||
{
|
||||
[DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_LoadLibrary")]
|
||||
internal static extern IntPtr LoadLibrary(string filename);
|
||||
[GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_LoadLibrary", CharSet = CharSet.Ansi)]
|
||||
internal static partial IntPtr LoadLibrary(string filename);
|
||||
|
||||
[DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetProcAddress")]
|
||||
internal static extern IntPtr GetProcAddress(IntPtr handle, byte* symbol);
|
||||
[GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetProcAddress")]
|
||||
internal static partial IntPtr GetProcAddress(IntPtr handle, byte* symbol);
|
||||
|
||||
[DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetProcAddress")]
|
||||
internal static extern IntPtr GetProcAddress(IntPtr handle, string symbol);
|
||||
[GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetProcAddress", CharSet = CharSet.Ansi)]
|
||||
internal static partial IntPtr GetProcAddress(IntPtr handle, string symbol);
|
||||
|
||||
[DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_FreeLibrary")]
|
||||
internal static extern void FreeLibrary(IntPtr handle);
|
||||
[GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_FreeLibrary")]
|
||||
internal static partial void FreeLibrary(IntPtr handle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ internal static partial class Interop
|
|||
internal unsafe partial class Sys
|
||||
{
|
||||
[DoesNotReturn]
|
||||
[DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_Exit")]
|
||||
internal static extern void Exit(int exitCode);
|
||||
[GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_Exit")]
|
||||
internal static partial void Exit(int exitCode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal unsafe partial class Sys
|
||||
{
|
||||
[DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_SchedGetCpu")]
|
||||
internal static extern int SchedGetCpu();
|
||||
[GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_SchedGetCpu")]
|
||||
internal static partial int SchedGetCpu();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal unsafe partial class Sys
|
||||
{
|
||||
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateThread")]
|
||||
internal static extern unsafe bool CreateThread(IntPtr stackSize, delegate* unmanaged<IntPtr, IntPtr> startAddress, IntPtr parameter);
|
||||
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateThread")]
|
||||
internal static unsafe partial bool CreateThread(IntPtr stackSize, delegate* unmanaged<IntPtr, IntPtr> startAddress, IntPtr parameter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ internal static partial class Interop
|
|||
throw new NetSecurityNative.GssApiException(SR.Format(SR.net_context_buffer_too_small, sourceLength, destinationAvailable));
|
||||
}
|
||||
|
||||
Marshal.Copy(_data, destination, offset, sourceLength);
|
||||
Span.CopyTo(destination.AsSpan(offset, sourceLength));
|
||||
return sourceLength;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ internal static partial class Interop
|
|||
|
||||
int destinationLength = Convert.ToInt32(_length);
|
||||
byte[] destination = new byte[destinationLength];
|
||||
Marshal.Copy(_data, destination, 0, destinationLength);
|
||||
Span.CopyTo(destination);
|
||||
return destination;
|
||||
}
|
||||
|
||||
|
@ -67,11 +67,11 @@ internal static partial class Interop
|
|||
}
|
||||
|
||||
#if DEBUG
|
||||
static GssBuffer()
|
||||
static unsafe GssBuffer()
|
||||
{
|
||||
// Verify managed size on both 32-bit and 64-bit matches the PAL_GssBuffer
|
||||
// native struct size, which is also padded on 32-bit.
|
||||
Debug.Assert(Marshal.SizeOf<GssBuffer>() == 16);
|
||||
Debug.Assert(sizeof(GssBuffer) == 16);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -218,8 +218,8 @@ internal static partial class Interop
|
|||
}
|
||||
}
|
||||
|
||||
[DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslAddExtraChainCert")]
|
||||
internal static extern bool SslAddExtraChainCert(SafeSslHandle ssl, SafeX509Handle x509);
|
||||
[GeneratedDllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslAddExtraChainCert")]
|
||||
internal static partial bool SslAddExtraChainCert(SafeSslHandle ssl, SafeX509Handle x509);
|
||||
|
||||
internal static bool AddExtraChainCertificates(SafeSslHandle ssl, X509Certificate2[] chain)
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Activeds
|
||||
{
|
||||
[DllImport(Interop.Libraries.Activeds, CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
internal static extern int ADsOpenObject(string path, string? userName, string? password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject);
|
||||
[GeneratedDllImport(Interop.Libraries.Activeds, CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
internal static partial int ADsOpenObject(string path, string? userName, string? password, int flags, ref Guid iid, out IntPtr ppObject);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,14 +15,12 @@ internal static partial class Interop
|
|||
CRYPT_USER_DEFAULT = 0x00000002
|
||||
}
|
||||
|
||||
[DllImport(Libraries.Advapi32, SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CryptGetDefaultProviderW")]
|
||||
public static extern bool CryptGetDefaultProvider(
|
||||
[GeneratedDllImport(Libraries.Advapi32, EntryPoint = "CryptGetDefaultProviderW", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static partial bool CryptGetDefaultProvider(
|
||||
int dwProvType,
|
||||
IntPtr pdwReserved,
|
||||
GetDefaultProviderFlags dwFlags,
|
||||
#pragma warning disable CA1838 // not on a hot path
|
||||
[Out] StringBuilder? pszProvName,
|
||||
#pragma warning restore CA1838
|
||||
[Out] char[]? pszProvName,
|
||||
ref int pcbProvName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ internal static partial class Interop
|
|||
}
|
||||
|
||||
internal unsafe delegate void EtwEnableCallback(
|
||||
in Guid sourceId,
|
||||
Guid* sourceId,
|
||||
int isEnabled,
|
||||
byte level,
|
||||
long matchAnyKeywords,
|
||||
|
|
|
@ -8,10 +8,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Advapi32
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(Libraries.Advapi32, ExactSpelling = true)]
|
||||
internal static extern int EventActivityIdControl(ActivityControl ControlCode, ref Guid ActivityId);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
[GeneratedDllImport(Libraries.Advapi32, ExactSpelling = true)]
|
||||
internal static partial int EventActivityIdControl(ActivityControl ControlCode, ref Guid ActivityId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,11 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Advapi32
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(Libraries.Advapi32, ExactSpelling = true)]
|
||||
internal static unsafe extern uint EventRegister(
|
||||
[GeneratedDllImport(Libraries.Advapi32, ExactSpelling = true)]
|
||||
internal static unsafe partial uint EventRegister(
|
||||
in Guid providerId,
|
||||
EtwEnableCallback enableCallback,
|
||||
void* callbackContext,
|
||||
ref long registrationHandle);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,8 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Advapi32
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupNames2", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
internal static extern uint LsaLookupNames2(
|
||||
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupNames2", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static partial uint LsaLookupNames2(
|
||||
SafeLsaPolicyHandle handle,
|
||||
int flags,
|
||||
int count,
|
||||
|
@ -20,15 +18,29 @@ internal static partial class Interop
|
|||
out SafeLsaMemoryHandle referencedDomains,
|
||||
out SafeLsaMemoryHandle sids
|
||||
);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
[NativeMarshalling(typeof(Native))]
|
||||
internal struct MARSHALLED_UNICODE_STRING
|
||||
{
|
||||
internal ushort Length;
|
||||
internal ushort MaximumLength;
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
internal string Buffer;
|
||||
|
||||
public struct Native
|
||||
{
|
||||
internal ushort Length;
|
||||
internal ushort MaximumLength;
|
||||
internal IntPtr Buffer;
|
||||
|
||||
public Native(MARSHALLED_UNICODE_STRING managed)
|
||||
{
|
||||
Length = managed.Length;
|
||||
MaximumLength = managed.MaximumLength;
|
||||
Buffer = Marshal.StringToCoTaskMemUni(managed.Buffer);
|
||||
}
|
||||
|
||||
public void FreeNative() => Marshal.FreeCoTaskMem(Buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// 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;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
|
@ -12,7 +13,7 @@ internal static partial class Interop
|
|||
internal struct CMSG_CTRL_DECRYPT_PARA
|
||||
{
|
||||
internal int cbSize;
|
||||
internal SafeProvOrNCryptKeyHandle hKey;
|
||||
internal IntPtr hKey;
|
||||
internal CryptKeySpec dwKeySpec;
|
||||
internal int dwRecipientIndex;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// 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;
|
||||
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
@ -13,7 +14,7 @@ internal static partial class Interop
|
|||
internal unsafe struct CMSG_CTRL_KEY_AGREE_DECRYPT_PARA
|
||||
{
|
||||
internal int cbSize;
|
||||
internal SafeProvOrNCryptKeyHandle hProv;
|
||||
internal IntPtr hProv;
|
||||
internal CryptKeySpec dwKeySpec;
|
||||
internal CMSG_KEY_AGREE_RECIPIENT_INFO* pKeyAgree;
|
||||
internal int dwRecipientIndex;
|
||||
|
|
|
@ -8,22 +8,18 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Crypt32
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we add support for non-blittable struct marshalling.
|
||||
[DllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool CryptMsgControl(
|
||||
[GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static partial bool CryptMsgControl(
|
||||
SafeCryptMsgHandle hCryptMsg,
|
||||
int dwFlags,
|
||||
MsgControlType dwCtrlType,
|
||||
ref CMSG_CTRL_DECRYPT_PARA pvCtrlPara);
|
||||
|
||||
[DllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool CryptMsgControl(
|
||||
[GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static partial bool CryptMsgControl(
|
||||
SafeCryptMsgHandle hCryptMsg,
|
||||
int dwFlags,
|
||||
MsgControlType dwCtrlType,
|
||||
ref CMSG_CTRL_KEY_AGREE_DECRYPT_PARA pvCtrlPara);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
|
@ -9,8 +10,12 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class CryptUI
|
||||
{
|
||||
#if NET7_0_OR_GREATER
|
||||
[NativeMarshalling(typeof(Native))]
|
||||
#else
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal sealed class CRYPTUI_VIEWCERTIFICATE_STRUCTW
|
||||
#endif
|
||||
internal struct CRYPTUI_VIEWCERTIFICATE_STRUCTW
|
||||
{
|
||||
internal uint dwSize;
|
||||
internal IntPtr hwndParent;
|
||||
|
@ -30,10 +35,91 @@ internal static partial class Interop
|
|||
internal uint cPropSheetPages;
|
||||
internal IntPtr rgPropSheetPages;
|
||||
internal uint nStartPage;
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
internal unsafe struct Native
|
||||
{
|
||||
private uint dwSize;
|
||||
private IntPtr hwndParent;
|
||||
private uint dwFlags;
|
||||
private IntPtr szTitle;
|
||||
private IntPtr pCertContext;
|
||||
private IntPtr rgszPurposes;
|
||||
private uint cPurposes;
|
||||
private IntPtr pCryptProviderData;
|
||||
private bool fpCryptProviderDataTrustedUsage;
|
||||
private uint idxSigner;
|
||||
private uint idxCert;
|
||||
private bool fCounterSigner;
|
||||
private uint idxCounterSigner;
|
||||
private uint cStores;
|
||||
private IntPtr rghStores;
|
||||
private uint cPropSheetPages;
|
||||
private IntPtr rgPropSheetPages;
|
||||
private uint nStartPage;
|
||||
|
||||
public Native(CRYPTUI_VIEWCERTIFICATE_STRUCTW managed)
|
||||
{
|
||||
dwSize = managed.dwSize;
|
||||
hwndParent = managed.hwndParent;
|
||||
dwFlags = managed.dwFlags;
|
||||
szTitle = Marshal.StringToCoTaskMemUni(managed.szTitle);
|
||||
pCertContext = managed.pCertContext;
|
||||
rgszPurposes = managed.rgszPurposes;
|
||||
cPurposes = managed.cPurposes;
|
||||
pCryptProviderData = managed.pCryptProviderData;
|
||||
fpCryptProviderDataTrustedUsage = managed.fpCryptProviderDataTrustedUsage;
|
||||
idxSigner = managed.idxSigner;
|
||||
idxCert = managed.idxCert;
|
||||
fCounterSigner = managed.fCounterSigner;
|
||||
idxCounterSigner = managed.idxCounterSigner;
|
||||
cStores = managed.cStores;
|
||||
rghStores = managed.rghStores;
|
||||
cPropSheetPages = managed.cPropSheetPages;
|
||||
rgPropSheetPages = managed.rgPropSheetPages;
|
||||
nStartPage = managed.nStartPage;
|
||||
|
||||
}
|
||||
|
||||
public void FreeNative()
|
||||
{
|
||||
Marshal.FreeCoTaskMem(szTitle);
|
||||
}
|
||||
|
||||
public CRYPTUI_VIEWCERTIFICATE_STRUCTW ToManaged()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
dwSize = dwSize,
|
||||
hwndParent = hwndParent,
|
||||
dwFlags = dwFlags,
|
||||
szTitle = Marshal.PtrToStringUni(szTitle),
|
||||
pCertContext = pCertContext,
|
||||
rgszPurposes = rgszPurposes,
|
||||
cPurposes = cPurposes,
|
||||
pCryptProviderData = pCryptProviderData,
|
||||
fpCryptProviderDataTrustedUsage = fpCryptProviderDataTrustedUsage,
|
||||
idxSigner = idxSigner,
|
||||
idxCert = idxCert,
|
||||
fCounterSigner = fCounterSigner,
|
||||
idxCounterSigner = idxCounterSigner,
|
||||
cStores = cStores,
|
||||
rghStores = rghStores,
|
||||
cPropSheetPages = cPropSheetPages,
|
||||
rgPropSheetPages = rgPropSheetPages,
|
||||
nStartPage = nStartPage
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
[NativeMarshalling(typeof(Native))]
|
||||
#else
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal sealed class CRYPTUI_SELECTCERTIFICATE_STRUCTW
|
||||
#endif
|
||||
internal struct CRYPTUI_SELECTCERTIFICATE_STRUCTW
|
||||
{
|
||||
internal uint dwSize;
|
||||
internal IntPtr hwndParent;
|
||||
|
@ -51,15 +137,84 @@ internal static partial class Interop
|
|||
internal uint cPropSheetPages;
|
||||
internal IntPtr rgPropSheetPages;
|
||||
internal IntPtr hSelectedCertStore;
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
internal unsafe struct Native
|
||||
{
|
||||
private uint dwSize;
|
||||
private IntPtr hwndParent;
|
||||
private uint dwFlags;
|
||||
private IntPtr szTitle;
|
||||
private uint dwDontUseColumn;
|
||||
private IntPtr szDisplayString;
|
||||
private IntPtr pFilterCallback;
|
||||
private IntPtr pDisplayCallback;
|
||||
private IntPtr pvCallbackData;
|
||||
private uint cDisplayStores;
|
||||
private IntPtr rghDisplayStores;
|
||||
private uint cStores;
|
||||
private IntPtr rghStores;
|
||||
private uint cPropSheetPages;
|
||||
private IntPtr rgPropSheetPages;
|
||||
internal IntPtr hSelectedCertStore;
|
||||
|
||||
public Native(CRYPTUI_SELECTCERTIFICATE_STRUCTW managed)
|
||||
{
|
||||
dwSize = managed.dwSize;
|
||||
hwndParent = managed.hwndParent;
|
||||
dwFlags = managed.dwFlags;
|
||||
szTitle = Marshal.StringToCoTaskMemUni(managed.szTitle);
|
||||
dwDontUseColumn = managed.dwDontUseColumn;
|
||||
szDisplayString = Marshal.StringToCoTaskMemUni(managed.szDisplayString);
|
||||
pFilterCallback = managed.pFilterCallback;
|
||||
pDisplayCallback = managed.pDisplayCallback;
|
||||
pvCallbackData = managed.pvCallbackData;
|
||||
cDisplayStores = managed.cDisplayStores;
|
||||
rghDisplayStores = managed.rghDisplayStores;
|
||||
cStores = managed.cStores;
|
||||
rghStores = managed.rghStores;
|
||||
cPropSheetPages = managed.cPropSheetPages;
|
||||
rgPropSheetPages = managed.rgPropSheetPages;
|
||||
hSelectedCertStore = managed.hSelectedCertStore;
|
||||
}
|
||||
|
||||
public void FreeNative()
|
||||
{
|
||||
Marshal.FreeCoTaskMem(szTitle);
|
||||
Marshal.FreeCoTaskMem(szDisplayString);
|
||||
}
|
||||
|
||||
public CRYPTUI_SELECTCERTIFICATE_STRUCTW ToManaged()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
dwSize = dwSize,
|
||||
hwndParent = hwndParent,
|
||||
dwFlags = dwFlags,
|
||||
szTitle = Marshal.PtrToStringUni(szTitle),
|
||||
dwDontUseColumn = dwDontUseColumn,
|
||||
szDisplayString = Marshal.PtrToStringUni(szDisplayString),
|
||||
pFilterCallback = pFilterCallback,
|
||||
pDisplayCallback = pDisplayCallback,
|
||||
pvCallbackData = pvCallbackData,
|
||||
cDisplayStores = cDisplayStores,
|
||||
rghDisplayStores = rghDisplayStores,
|
||||
cStores = cStores,
|
||||
rghStores = rghStores,
|
||||
cPropSheetPages = cPropSheetPages,
|
||||
rgPropSheetPages = rgPropSheetPages,
|
||||
hSelectedCertStore = hSelectedCertStore
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
|
||||
[DllImport(Interop.Libraries.CryptUI, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
|
||||
internal static extern bool CryptUIDlgViewCertificateW([MarshalAs(UnmanagedType.LPStruct)] CRYPTUI_VIEWCERTIFICATE_STRUCTW ViewInfo, IntPtr pfPropertiesChanged);
|
||||
[GeneratedDllImport(Interop.Libraries.CryptUI, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
|
||||
internal static partial bool CryptUIDlgViewCertificateW(
|
||||
in CRYPTUI_VIEWCERTIFICATE_STRUCTW ViewInfo, IntPtr pfPropertiesChanged);
|
||||
|
||||
[DllImport(Interop.Libraries.CryptUI, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
|
||||
internal static extern SafeCertContextHandle CryptUIDlgSelectCertificateW([In, Out, MarshalAs(UnmanagedType.LPStruct)] CRYPTUI_SELECTCERTIFICATE_STRUCTW csc);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
[GeneratedDllImport(Interop.Libraries.CryptUI, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
|
||||
internal static partial SafeCertContextHandle CryptUIDlgSelectCertificateW(ref CRYPTUI_SELECTCERTIFICATE_STRUCTW csc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,8 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Gdi32
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
|
||||
[DllImport(Libraries.Gdi32)]
|
||||
public static extern bool OffsetViewportOrgEx(IntPtr hdc, int x, int y, ref Point lppt);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.Gdi32)]
|
||||
public static partial bool OffsetViewportOrgEx(IntPtr hdc, int x, int y, ref Point lppt);
|
||||
|
||||
public static bool OffsetViewportOrgEx(HandleRef hdc, int x, int y, ref Point lppt)
|
||||
{
|
||||
|
|
|
@ -236,7 +236,7 @@ internal static partial class Interop
|
|||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct MibIfRow2 // MIB_IF_ROW2
|
||||
internal unsafe struct MibIfRow2 // MIB_IF_ROW2
|
||||
{
|
||||
private const int GuidLength = 16;
|
||||
private const int IfMaxStringSize = 256;
|
||||
|
@ -244,17 +244,12 @@ internal static partial class Interop
|
|||
|
||||
internal ulong interfaceLuid;
|
||||
internal uint interfaceIndex;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = GuidLength)]
|
||||
internal byte[] interfaceGuid;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = IfMaxStringSize + 1)]
|
||||
internal char[] alias; // Null terminated string.
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = IfMaxStringSize + 1)]
|
||||
internal char[] description; // Null terminated string.
|
||||
internal Guid interfaceGuid;
|
||||
internal fixed char alias[IfMaxStringSize + 1]; // Null terminated string.
|
||||
internal fixed char description[IfMaxStringSize + 1]; // Null terminated string.
|
||||
internal uint physicalAddressLength;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = IfMaxPhysAddressLength)]
|
||||
internal byte[] physicalAddress; // ANSI
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = IfMaxPhysAddressLength)]
|
||||
internal byte[] permanentPhysicalAddress; // ANSI
|
||||
internal fixed byte physicalAddress[IfMaxPhysAddressLength]; // ANSI
|
||||
internal fixed byte permanentPhysicalAddress[IfMaxPhysAddressLength]; // ANSI
|
||||
internal uint mtu;
|
||||
internal NetworkInterfaceType type;
|
||||
internal InterfaceTunnelType tunnelType;
|
||||
|
@ -266,8 +261,7 @@ internal static partial class Interop
|
|||
internal OperationalStatus operStatus;
|
||||
internal uint adminStatus; // Enum
|
||||
internal uint mediaConnectState; // Enum
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = GuidLength)]
|
||||
internal byte[] networkGuid;
|
||||
internal Guid networkGuid;
|
||||
internal InterfaceConnectionType connectionType;
|
||||
internal ulong transmitLinkSpeed;
|
||||
internal ulong receiveLinkSpeed;
|
||||
|
@ -382,12 +376,11 @@ internal static partial class Interop
|
|||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct MibIcmpStatsEx
|
||||
internal unsafe struct MibIcmpStatsEx
|
||||
{
|
||||
internal uint dwMsgs;
|
||||
internal uint dwErrors;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
||||
internal uint[] rgdwTypeCount;
|
||||
internal fixed uint rgdwTypeCount[256];
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
@ -519,11 +512,8 @@ internal static partial class Interop
|
|||
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
|
||||
internal static unsafe partial uint GetBestInterfaceEx(byte* ipAddress, int* index);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Interop.Libraries.IpHlpApi)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
|
||||
internal static extern uint GetIfEntry2(ref MibIfRow2 pIfRow);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
|
||||
internal static partial uint GetIfEntry2(ref MibIfRow2 pIfRow);
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
|
||||
internal static unsafe partial uint GetIpStatisticsEx(MibIpStats* statistics, AddressFamily family);
|
||||
|
@ -537,11 +527,8 @@ internal static partial class Interop
|
|||
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
|
||||
internal static unsafe partial uint GetIcmpStatistics(MibIcmpInfo* statistics);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Interop.Libraries.IpHlpApi)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
|
||||
internal static extern uint GetIcmpStatisticsEx(out MibIcmpInfoEx statistics, AddressFamily family);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
|
||||
internal static partial uint GetIcmpStatisticsEx(out MibIcmpInfoEx statistics, AddressFamily family);
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
|
||||
internal static unsafe partial uint GetTcpTable(IntPtr pTcpTable, uint* dwOutBufLen, bool order);
|
||||
|
|
|
@ -10,7 +10,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal static unsafe partial class Kernel32
|
||||
{
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern IntPtr GetProcAddress(IntPtr hModule, byte* lpProcName);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static partial IntPtr GetProcAddress(IntPtr hModule, byte* lpProcName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ internal static partial class Interop
|
|||
internal static unsafe partial class Kernel32
|
||||
{
|
||||
[DoesNotReturn]
|
||||
[DllImport(Libraries.Kernel32, EntryPoint = "ExitProcess")]
|
||||
internal static extern void ExitProcess(int exitCode);
|
||||
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "ExitProcess")]
|
||||
internal static partial void ExitProcess(int exitCode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Kernel32
|
||||
{
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern uint GetCurrentProcessorNumber();
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static partial uint GetCurrentProcessorNumber();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Kernel32
|
||||
{
|
||||
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "QueryFullProcessImageNameW", ExactSpelling = true, SetLastError = true)]
|
||||
private static unsafe extern bool QueryFullProcessImageName(
|
||||
[GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "QueryFullProcessImageNameW", ExactSpelling = true, SetLastError = true)]
|
||||
private static unsafe partial bool QueryFullProcessImageName(
|
||||
SafeHandle hProcess,
|
||||
uint dwFlags,
|
||||
char* lpBuffer,
|
||||
|
|
|
@ -9,8 +9,8 @@ internal static partial class Interop
|
|||
{
|
||||
internal static unsafe partial class Kernel32
|
||||
{
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
[SuppressGCTransition]
|
||||
internal static extern ulong GetTickCount64();
|
||||
internal static partial ulong GetTickCount64();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Kernel32
|
||||
{
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern bool IsDebuggerPresent();
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static partial bool IsDebuggerPresent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,9 +49,9 @@ internal partial class Interop
|
|||
pExAddress == IntPtr.Zero ? FAIL_FAST_GENERATE_EXCEPTION_ADDRESS : 0);
|
||||
}
|
||||
|
||||
[DllImport(Libraries.Kernel32, EntryPoint = "RaiseFailFastException")]
|
||||
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "RaiseFailFastException")]
|
||||
[DoesNotReturn]
|
||||
private static extern unsafe void RaiseFailFastException(
|
||||
private static unsafe partial void RaiseFailFastException(
|
||||
EXCEPTION_RECORD* pExceptionRecord,
|
||||
IntPtr pContextRecord,
|
||||
uint dwFlags);
|
||||
|
|
|
@ -8,25 +8,25 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Kernel32
|
||||
{
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern unsafe IntPtr CreateThreadpoolWork(delegate* unmanaged<IntPtr, IntPtr, IntPtr, void> pfnwk, IntPtr pv, IntPtr pcbe);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static unsafe partial IntPtr CreateThreadpoolWork(delegate* unmanaged<IntPtr, IntPtr, IntPtr, void> pfnwk, IntPtr pv, IntPtr pcbe);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern void SubmitThreadpoolWork(IntPtr pwk);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static partial void SubmitThreadpoolWork(IntPtr pwk);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern void CloseThreadpoolWork(IntPtr pwk);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static partial void CloseThreadpoolWork(IntPtr pwk);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern unsafe IntPtr CreateThreadpoolWait(delegate* unmanaged<IntPtr, IntPtr, IntPtr, uint, void> pfnwa, IntPtr pv, IntPtr pcbe);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static unsafe partial IntPtr CreateThreadpoolWait(delegate* unmanaged<IntPtr, IntPtr, IntPtr, uint, void> pfnwa, IntPtr pv, IntPtr pcbe);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern void SetThreadpoolWait(IntPtr pwa, IntPtr h, IntPtr pftTimeout);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static partial void SetThreadpoolWait(IntPtr pwa, IntPtr h, IntPtr pftTimeout);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern void WaitForThreadpoolWaitCallbacks(IntPtr pwa, bool fCancelPendingCallbacks);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static partial void WaitForThreadpoolWaitCallbacks(IntPtr pwa, bool fCancelPendingCallbacks);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern void CloseThreadpoolWait(IntPtr pwa);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static partial void CloseThreadpoolWait(IntPtr pwa);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,16 +9,16 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Kernel32
|
||||
{
|
||||
[DllImport(Libraries.Kernel32, SetLastError = true)]
|
||||
internal static unsafe extern SafeThreadPoolIOHandle CreateThreadpoolIo(SafeHandle fl, delegate* unmanaged<IntPtr, IntPtr, IntPtr, uint, UIntPtr, IntPtr, void> pfnio, IntPtr context, IntPtr pcbe);
|
||||
[GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
|
||||
internal static unsafe partial SafeThreadPoolIOHandle CreateThreadpoolIo(SafeHandle fl, delegate* unmanaged<IntPtr, IntPtr, IntPtr, uint, UIntPtr, IntPtr, void> pfnio, IntPtr context, IntPtr pcbe);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static unsafe extern void CloseThreadpoolIo(IntPtr pio);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static unsafe partial void CloseThreadpoolIo(IntPtr pio);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static unsafe extern void StartThreadpoolIo(SafeThreadPoolIOHandle pio);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static unsafe partial void StartThreadpoolIo(SafeThreadPoolIOHandle pio);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static unsafe extern void CancelThreadpoolIo(SafeThreadPoolIOHandle pio);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static unsafe partial void CancelThreadpoolIo(SafeThreadPoolIOHandle pio);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Kernel32
|
||||
{
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern unsafe IntPtr CreateThreadpoolTimer(delegate* unmanaged<IntPtr, IntPtr, IntPtr, void> pfnti, IntPtr pv, IntPtr pcbe);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static unsafe partial IntPtr CreateThreadpoolTimer(delegate* unmanaged<IntPtr, IntPtr, IntPtr, void> pfnti, IntPtr pv, IntPtr pcbe);
|
||||
|
||||
[DllImport(Libraries.Kernel32)]
|
||||
internal static extern unsafe IntPtr SetThreadpoolTimer(IntPtr pti, long* pftDueTime, uint msPeriod, uint msWindowLength);
|
||||
[GeneratedDllImport(Libraries.Kernel32)]
|
||||
internal static unsafe partial IntPtr SetThreadpoolTimer(IntPtr pti, long* pftDueTime, uint msPeriod, uint msWindowLength);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Ole32
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(Interop.Libraries.Ole32, CharSet = CharSet.Unicode)]
|
||||
internal static extern int CLSIDFromProgID(string lpszProgID, out Guid lpclsid);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
[GeneratedDllImport(Interop.Libraries.Ole32, CharSet = CharSet.Unicode)]
|
||||
internal static partial int CLSIDFromProgID(string lpszProgID, out Guid lpclsid);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Ole32
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(Interop.Libraries.Ole32)]
|
||||
internal static extern int CoCreateGuid(out Guid guid);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
[GeneratedDllImport(Interop.Libraries.Ole32)]
|
||||
internal static partial int CoCreateGuid(out Guid guid);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ internal static partial class Interop
|
|||
|
||||
internal static partial class Ole32
|
||||
{
|
||||
[DllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
|
||||
internal static extern int CoGetApartmentType(out APTTYPE pAptType, out APTTYPEQUALIFIER pAptQualifier);
|
||||
[GeneratedDllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
|
||||
internal static partial int CoGetApartmentType(out APTTYPE pAptType, out APTTYPEQUALIFIER pAptQualifier);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,16 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Ole32
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(Libraries.Ole32)]
|
||||
internal static extern int CoGetObjectContext([MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IntPtr ppv);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
internal static unsafe int CoGetObjectContext(in Guid riid, out IntPtr ppv)
|
||||
{
|
||||
fixed (Guid* riidPtr = &riid)
|
||||
fixed (IntPtr* ppvPtr = &ppv)
|
||||
{
|
||||
return CoGetObjectContext(riidPtr, ppvPtr);
|
||||
}
|
||||
}
|
||||
|
||||
[GeneratedDllImport(Libraries.Ole32)]
|
||||
internal static unsafe partial int CoGetObjectContext(Guid* riid, IntPtr* ppv);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ internal static partial class Interop
|
|||
internal const uint COINIT_APARTMENTTHREADED = 2;
|
||||
internal const uint COINIT_MULTITHREADED = 0;
|
||||
|
||||
[DllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
|
||||
internal static extern int CoInitializeEx(IntPtr reserved, uint dwCoInit);
|
||||
[GeneratedDllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
|
||||
internal static partial int CoInitializeEx(IntPtr reserved, uint dwCoInit);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Ole32
|
||||
{
|
||||
[DllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
|
||||
internal static extern int CoUninitialize();
|
||||
[GeneratedDllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
|
||||
internal static partial int CoUninitialize();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,24 +53,20 @@ internal static partial class Interop
|
|||
internal uint InstanceNameSize;
|
||||
}
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(Libraries.Advapi32, ExactSpelling = true)]
|
||||
internal static extern uint PerfStartProvider(
|
||||
[GeneratedDllImport(Libraries.Advapi32, ExactSpelling = true)]
|
||||
internal static partial uint PerfStartProvider(
|
||||
ref Guid ProviderGuid,
|
||||
PERFLIBREQUEST ControlCallback,
|
||||
out SafePerfProviderHandle phProvider
|
||||
);
|
||||
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(Libraries.Advapi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
|
||||
internal static extern unsafe PerfCounterSetInstanceStruct* PerfCreateInstance(
|
||||
[GeneratedDllImport(Libraries.Advapi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
|
||||
internal static unsafe partial PerfCounterSetInstanceStruct* PerfCreateInstance(
|
||||
SafePerfProviderHandle hProvider,
|
||||
ref Guid CounterSetGuid,
|
||||
string szInstanceName,
|
||||
uint dwInstance
|
||||
);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
|
||||
[GeneratedDllImport(Libraries.Advapi32, ExactSpelling = true)]
|
||||
internal static unsafe partial uint PerfSetCounterSetInfo(
|
||||
|
|
|
@ -10,16 +10,13 @@ internal static partial class Interop
|
|||
{
|
||||
internal const int COR_E_PLATFORMNOTSUPPORTED = unchecked((int)0x80131539);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb762188.aspx
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
[DllImport(Libraries.Shell32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = false)]
|
||||
internal static extern int SHGetKnownFolderPath(
|
||||
[MarshalAs(UnmanagedType.LPStruct)] Guid rfid,
|
||||
[GeneratedDllImport(Libraries.Shell32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = false)]
|
||||
internal static partial int SHGetKnownFolderPath(
|
||||
in Guid rfid,
|
||||
uint dwFlags,
|
||||
IntPtr hToken,
|
||||
out string ppszPath);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx
|
||||
internal static class KnownFolders
|
||||
|
|
|
@ -10,25 +10,22 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class SspiCli
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Libraries.SspiCli)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
internal static extern int LsaLogonUser(
|
||||
[In] SafeLsaHandle LsaHandle,
|
||||
[In] ref Advapi32.LSA_STRING OriginName,
|
||||
[In] SECURITY_LOGON_TYPE LogonType,
|
||||
[In] int AuthenticationPackage,
|
||||
[In] IntPtr AuthenticationInformation,
|
||||
[In] int AuthenticationInformationLength,
|
||||
[In] IntPtr LocalGroups,
|
||||
[In] ref TOKEN_SOURCE SourceContext,
|
||||
[Out] out SafeLsaReturnBufferHandle ProfileBuffer,
|
||||
[Out] out int ProfileBufferLength,
|
||||
[Out] out LUID LogonId,
|
||||
[Out] out SafeAccessTokenHandle Token,
|
||||
[Out] out QUOTA_LIMITS Quotas,
|
||||
[Out] out int SubStatus
|
||||
[GeneratedDllImport(Libraries.SspiCli)]
|
||||
internal static partial int LsaLogonUser(
|
||||
SafeLsaHandle LsaHandle,
|
||||
in Advapi32.LSA_STRING OriginName,
|
||||
SECURITY_LOGON_TYPE LogonType,
|
||||
int AuthenticationPackage,
|
||||
IntPtr AuthenticationInformation,
|
||||
int AuthenticationInformationLength,
|
||||
IntPtr LocalGroups,
|
||||
in TOKEN_SOURCE SourceContext,
|
||||
out SafeLsaReturnBufferHandle ProfileBuffer,
|
||||
out int ProfileBufferLength,
|
||||
out LUID LogonId,
|
||||
out SafeAccessTokenHandle Token,
|
||||
out QUOTA_LIMITS Quotas,
|
||||
out int SubStatus
|
||||
);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
}
|
||||
}
|
||||
|
|
|
@ -344,13 +344,10 @@ internal static partial class Interop
|
|||
uint sequenceNumber,
|
||||
uint* qualityOfProtection);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
internal static extern int QuerySecurityContextToken(
|
||||
[GeneratedDllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)]
|
||||
internal static partial int QuerySecurityContextToken(
|
||||
ref CredHandle phContext,
|
||||
out SecurityContextTokenHandle handle);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)]
|
||||
internal static partial int FreeContextBuffer(
|
||||
|
@ -478,14 +475,11 @@ internal static partial class Interop
|
|||
string password,
|
||||
out SafeSspiAuthDataHandle authData);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Interop.Libraries.SspiCli, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
internal static extern SECURITY_STATUS SetCredentialsAttributesW(
|
||||
[GeneratedDllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)]
|
||||
internal static partial SECURITY_STATUS SetCredentialsAttributesW(
|
||||
in CredHandle handlePtr,
|
||||
long ulAttribute,
|
||||
in SecPkgCred_ClientCertPolicy pBuffer,
|
||||
long cbBuffer);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,9 @@ internal static partial class Interop
|
|||
internal static partial class SspiCli
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct TOKEN_SOURCE
|
||||
internal unsafe struct TOKEN_SOURCE
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = TOKEN_SOURCE_LENGTH)]
|
||||
internal byte[] SourceName;
|
||||
internal fixed byte SourceName[TOKEN_SOURCE_LENGTH];
|
||||
internal LUID SourceIdentifier;
|
||||
|
||||
internal const int TOKEN_SOURCE_LENGTH = 8;
|
||||
|
|
|
@ -10,8 +10,5 @@ internal static partial class Interop
|
|||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,5 @@ internal static partial class Interop
|
|||
{
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,5 @@ internal static partial class Interop
|
|||
{
|
||||
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
public static partial IntPtr SendMessageW(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
public static extern IntPtr SendMessageW(HandleRef hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,15 +41,35 @@ internal static partial class Interop
|
|||
internal ushort CloseStatus;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[NativeMarshalling(typeof(Native))]
|
||||
internal struct HttpHeader
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
internal string Name;
|
||||
internal uint NameLength;
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
internal string Value;
|
||||
internal uint ValueLength;
|
||||
|
||||
internal struct Native
|
||||
{
|
||||
private IntPtr Name;
|
||||
private uint NameLength;
|
||||
private IntPtr Value;
|
||||
private uint ValueLength;
|
||||
|
||||
public Native(HttpHeader managed)
|
||||
{
|
||||
Name = Marshal.StringToCoTaskMemAnsi(managed.Name);
|
||||
NameLength = managed.NameLength;
|
||||
Value = Marshal.StringToCoTaskMemAnsi(managed.Value);
|
||||
ValueLength = managed.ValueLength;
|
||||
}
|
||||
|
||||
public void FreeNative()
|
||||
{
|
||||
Marshal.FreeCoTaskMem(Name);
|
||||
Marshal.FreeCoTaskMem(Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,19 +8,16 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class WebSocket
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Libraries.WebSocket)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
internal static extern int WebSocketBeginClientHandshake(
|
||||
[In] SafeHandle webSocketHandle,
|
||||
[In] IntPtr subProtocols,
|
||||
[In] uint subProtocolCount,
|
||||
[In] IntPtr extensions,
|
||||
[In] uint extensionCount,
|
||||
[In] HttpHeader[] initialHeaders,
|
||||
[In] uint initialHeaderCount,
|
||||
[Out] out IntPtr additionalHeadersPtr,
|
||||
[Out] out uint additionalHeaderCount);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.WebSocket)]
|
||||
internal static partial int WebSocketBeginClientHandshake(
|
||||
SafeHandle webSocketHandle,
|
||||
IntPtr subProtocols,
|
||||
uint subProtocolCount,
|
||||
IntPtr extensions,
|
||||
uint extensionCount,
|
||||
HttpHeader[] initialHeaders,
|
||||
uint initialHeaderCount,
|
||||
out IntPtr additionalHeadersPtr,
|
||||
out uint additionalHeaderCount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,18 +8,15 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class WebSocket
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Libraries.WebSocket)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
internal static extern int WebSocketBeginServerHandshake(
|
||||
[In] SafeHandle webSocketHandle,
|
||||
[In] IntPtr subProtocol,
|
||||
[In] IntPtr extensions,
|
||||
[In] uint extensionCount,
|
||||
[In] HttpHeader[] requestHeaders,
|
||||
[In] uint requestHeaderCount,
|
||||
[Out] out IntPtr responseHeadersPtr,
|
||||
[Out] out uint responseHeaderCount);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.WebSocket)]
|
||||
internal static partial int WebSocketBeginServerHandshake(
|
||||
SafeHandle webSocketHandle,
|
||||
IntPtr subProtocol,
|
||||
IntPtr extensions,
|
||||
uint extensionCount,
|
||||
HttpHeader[] requestHeaders,
|
||||
uint requestHeaderCount,
|
||||
out IntPtr responseHeadersPtr,
|
||||
out uint responseHeaderCount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,16 +38,41 @@ internal static partial class Interop
|
|||
string acceptTypes,
|
||||
uint flags);
|
||||
|
||||
[DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[GeneratedDllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool WinHttpAddRequestHeaders(
|
||||
public static partial bool WinHttpAddRequestHeaders(
|
||||
SafeWinHttpHandle requestHandle,
|
||||
#if NET7_0_OR_GREATER
|
||||
[MarshalUsing(typeof(SimpleStringBufferMarshaller))] StringBuilder headers,
|
||||
#else
|
||||
#pragma warning disable CA1838 // Uses pooled StringBuilder
|
||||
[In] StringBuilder headers,
|
||||
#pragma warning restore CA1838
|
||||
#pragma warning restore CA1838 // Uses pooled StringBuilder
|
||||
#endif
|
||||
uint headersLength,
|
||||
uint modifiers);
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
private unsafe struct SimpleStringBufferMarshaller
|
||||
{
|
||||
public SimpleStringBufferMarshaller(StringBuilder builder)
|
||||
{
|
||||
int length = builder.Length + 1;
|
||||
Value = NativeMemory.Alloc(sizeof(char) * (nuint)length);
|
||||
Span<char> buffer = new(Value, length);
|
||||
buffer.Clear();
|
||||
builder.CopyTo(0, buffer, length - 1);
|
||||
}
|
||||
|
||||
public void* Value { get; }
|
||||
|
||||
public void FreeNative()
|
||||
{
|
||||
NativeMemory.Free(Value);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static partial bool WinHttpAddRequestHeaders(
|
||||
|
@ -187,15 +212,12 @@ internal static partial class Interop
|
|||
public static partial bool WinHttpGetIEProxyConfigForCurrentUser(
|
||||
out WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[return: MarshalAs(UnmanagedType.Bool)]public static extern bool WinHttpGetProxyForUrl(
|
||||
[GeneratedDllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]public static partial bool WinHttpGetProxyForUrl(
|
||||
SafeWinHttpHandle? sessionHandle,
|
||||
string url,
|
||||
ref WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions,
|
||||
out WINHTTP_PROXY_INFO proxyInfo);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static partial IntPtr WinHttpSetStatusCallback(
|
||||
|
|
|
@ -244,6 +244,9 @@ internal static partial class Interop
|
|||
IntPtr statusInformation,
|
||||
uint statusInformationLength);
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
[NativeMarshalling(typeof(Native))]
|
||||
#endif
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct WINHTTP_AUTOPROXY_OPTIONS
|
||||
{
|
||||
|
@ -255,6 +258,45 @@ internal static partial class Interop
|
|||
public uint Reserved2;
|
||||
[MarshalAs(UnmanagedType.Bool)]
|
||||
public bool AutoLoginIfChallenged;
|
||||
#if NET7_0_OR_GREATER
|
||||
public struct Native
|
||||
{
|
||||
private uint Flags;
|
||||
private uint AutoDetectFlags;
|
||||
private IntPtr AutoConfigUrl;
|
||||
private IntPtr Reserved1;
|
||||
private uint Reserved2;
|
||||
private int AutoLoginIfChallenged;
|
||||
|
||||
public Native(WINHTTP_AUTOPROXY_OPTIONS managed)
|
||||
{
|
||||
Flags = managed.Flags;
|
||||
AutoDetectFlags = managed.AutoDetectFlags;
|
||||
AutoConfigUrl = managed.AutoConfigUrl is not null ? Marshal.StringToCoTaskMemUni(managed.AutoConfigUrl) : IntPtr.Zero;
|
||||
Reserved1 = managed.Reserved1;
|
||||
Reserved2 = managed.Reserved2;
|
||||
AutoLoginIfChallenged = managed.AutoLoginIfChallenged ? 1 : 0;
|
||||
}
|
||||
|
||||
public WINHTTP_AUTOPROXY_OPTIONS ToManaged()
|
||||
{
|
||||
return new WINHTTP_AUTOPROXY_OPTIONS
|
||||
{
|
||||
Flags = Flags,
|
||||
AutoDetectFlags = AutoDetectFlags,
|
||||
AutoConfigUrl = AutoConfigUrl != IntPtr.Zero ? Marshal.PtrToStringUni(AutoConfigUrl) : null,
|
||||
Reserved1 = Reserved1,
|
||||
Reserved2 = Reserved2,
|
||||
AutoLoginIfChallenged = AutoLoginIfChallenged != 0
|
||||
};
|
||||
}
|
||||
|
||||
public void FreeNative()
|
||||
{
|
||||
Marshal.FreeCoTaskMem(AutoConfigUrl);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
|
|
|
@ -9,21 +9,18 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Winsock
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// Used with SIOGETEXTENSIONFUNCTIONPOINTER - we're assuming that will never block.
|
||||
[DllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
|
||||
internal static extern SocketError WSAIoctl(
|
||||
[GeneratedDllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
|
||||
internal static partial SocketError WSAIoctl(
|
||||
SafeSocketHandle socketHandle,
|
||||
[In] int ioControlCode,
|
||||
[In, Out] ref Guid guid,
|
||||
[In] int guidSize,
|
||||
[Out] out IntPtr funcPtr,
|
||||
[In] int funcPtrSize,
|
||||
[Out] out int bytesTransferred,
|
||||
[In] IntPtr shouldBeNull,
|
||||
[In] IntPtr shouldBeNull2);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
int ioControlCode,
|
||||
ref Guid guid,
|
||||
int guidSize,
|
||||
out IntPtr funcPtr,
|
||||
int funcPtrSize,
|
||||
out int bytesTransferred,
|
||||
IntPtr shouldBeNull,
|
||||
IntPtr shouldBeNull2);
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.Ws2_32, EntryPoint = "WSAIoctl", SetLastError = true)]
|
||||
internal static partial SocketError WSAIoctl_Blocking(
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
// 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.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
internal static partial class Interop
|
||||
|
@ -57,23 +59,53 @@ internal static partial class Interop
|
|||
|
||||
// Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct IPMulticastRequest
|
||||
internal unsafe struct IPMulticastRequest
|
||||
{
|
||||
internal int MulticastAddress; // IP multicast address of group
|
||||
internal int InterfaceAddress; // local IP address of interface
|
||||
|
||||
internal static readonly int Size = Marshal.SizeOf<IPMulticastRequest>();
|
||||
internal static readonly int Size = sizeof(IPMulticastRequest);
|
||||
}
|
||||
|
||||
// Argument structure for IPV6_ADD_MEMBERSHIP and IPV6_DROP_MEMBERSHIP.
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[NativeMarshalling(typeof(Native))]
|
||||
internal struct IPv6MulticastRequest
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
||||
internal byte[] MulticastAddress; // IP address of group.
|
||||
internal int InterfaceIndex; // Local interface index.
|
||||
|
||||
internal static readonly int Size = Marshal.SizeOf<IPv6MulticastRequest>();
|
||||
public unsafe struct Native
|
||||
{
|
||||
private const int MulticastAddressLength = 16;
|
||||
private fixed byte _multicastAddress[MulticastAddressLength];
|
||||
private int _interfaceIndex;
|
||||
|
||||
public Native(IPv6MulticastRequest managed)
|
||||
{
|
||||
Debug.Assert(managed.MulticastAddress.Length == MulticastAddressLength);
|
||||
fixed (void* dest = _multicastAddress)
|
||||
{
|
||||
managed.MulticastAddress.CopyTo(new Span<byte>(dest, MulticastAddressLength));
|
||||
}
|
||||
_interfaceIndex = managed.InterfaceIndex;
|
||||
}
|
||||
|
||||
public IPv6MulticastRequest ToManaged()
|
||||
{
|
||||
IPv6MulticastRequest managed = new()
|
||||
{
|
||||
MulticastAddress = new byte[MulticastAddressLength],
|
||||
InterfaceIndex = _interfaceIndex
|
||||
};
|
||||
fixed (void* src = _multicastAddress)
|
||||
{
|
||||
new Span<byte>(src, 16).CopyTo(managed.MulticastAddress);
|
||||
}
|
||||
return managed;
|
||||
}
|
||||
}
|
||||
|
||||
internal static readonly unsafe int Size = sizeof(Native);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
|
|
@ -32,15 +32,12 @@ internal static partial class Interop
|
|||
out IPMulticastRequest optionValue,
|
||||
ref int optionLength);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittale structs.
|
||||
internal static extern SocketError getsockopt(
|
||||
[In] SafeSocketHandle socketHandle,
|
||||
[In] SocketOptionLevel optionLevel,
|
||||
[In] SocketOptionName optionName,
|
||||
[Out] out IPv6MulticastRequest optionValue,
|
||||
[In, Out] ref int optionLength);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
|
||||
internal static partial SocketError getsockopt(
|
||||
SafeSocketHandle socketHandle,
|
||||
SocketOptionLevel optionLevel,
|
||||
SocketOptionName optionName,
|
||||
out IPv6MulticastRequest optionValue,
|
||||
ref int optionLength);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,15 +57,12 @@ internal static partial class Interop
|
|||
ref IPMulticastRequest mreq,
|
||||
int optionLength);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[DllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittale structs.
|
||||
internal static extern SocketError setsockopt(
|
||||
[In] SafeSocketHandle socketHandle,
|
||||
[In] SocketOptionLevel optionLevel,
|
||||
[In] SocketOptionName optionName,
|
||||
[In] ref IPv6MulticastRequest mreq,
|
||||
[In] int optionLength);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
|
||||
internal static partial SocketError setsockopt(
|
||||
SafeSocketHandle socketHandle,
|
||||
SocketOptionLevel optionLevel,
|
||||
SocketOptionName optionName,
|
||||
in IPv6MulticastRequest mreq,
|
||||
int optionLength);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,28 +17,49 @@ internal static partial class Interop
|
|||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial IntPtr ber_alloc(int option);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Requires some varargs support mechanism in generated interop
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int ber_printf(SafeBerHandle berElement, string format, __arglist);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_printf(SafeBerHandle berElement, string format, IntPtr value);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_printf(SafeBerHandle berElement, string format, HGlobalMemHandle value, uint length);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_printf(SafeBerHandle berElement, string format);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_printf(SafeBerHandle berElement, string format, int value);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_printf(SafeBerHandle berElement, string format, uint tag);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_flatten", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_flatten(SafeBerHandle berElement, ref IntPtr value);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ber_init", CharSet = CharSet.Unicode)]
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_init", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static extern IntPtr ber_init(BerVal value);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
public static partial IntPtr ber_init(BerVal value);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Requires some varargs support mechanism in generated interop
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int ber_scanf(SafeBerHandle berElement, string format, __arglist);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_scanf(SafeBerHandle berElement, string format);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_scanf(SafeBerHandle berElement, string format, ref IntPtr ptrResult, ref uint bitLength);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_scanf(SafeBerHandle berElement, string format, ref int result);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ber_scanf(SafeBerHandle berElement, string format, ref IntPtr value);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_bvfree", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
|
|
|
@ -9,23 +9,17 @@ internal static partial class Interop
|
|||
{
|
||||
internal static partial class Ldap
|
||||
{
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ldap_bind_sW", CharSet = CharSet.Unicode)]
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_bind_sW", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static extern int ldap_bind_s(ConnectionHandle ldapHandle, string dn, SEC_WINNT_AUTH_IDENTITY_EX credentials, BindMethod method);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
public static partial int ldap_bind_s(ConnectionHandle ldapHandle, string dn, in SEC_WINNT_AUTH_IDENTITY_EX credentials, BindMethod method);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_initW", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial IntPtr ldap_init(string hostName, int portNumber);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ldap_connect", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_connect", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static extern int ldap_connect(ConnectionHandle ldapHandle, LDAP_TIMEVAL timeout);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
public static partial int ldap_connect(ConnectionHandle ldapHandle, in LDAP_TIMEVAL timeout);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_unbind", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
|
@ -51,16 +45,13 @@ internal static partial class Interop
|
|||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ldap_get_option_sechandle(ConnectionHandle ldapHandle, LdapOption option, ref SecurityHandle outValue);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ldap_get_optionW", CharSet = CharSet.Unicode)]
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_get_optionW", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static extern int ldap_get_option_secInfo(ConnectionHandle ldapHandle, LdapOption option, [In, Out] SecurityPackageContextConnectionInformation outValue);
|
||||
public static unsafe partial int ldap_get_option_secInfo(ConnectionHandle ldapHandle, LdapOption option, void* outValue);
|
||||
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ldap_set_optionW", CharSet = CharSet.Unicode)]
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_set_optionW", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static extern int ldap_set_option_referral(ConnectionHandle ldapHandle, LdapOption option, ref LdapReferralCallback outValue);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
public static partial int ldap_set_option_referral(ConnectionHandle ldapHandle, LdapOption option, ref LdapReferralCallback outValue);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_set_optionW", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
|
@ -86,12 +77,9 @@ internal static partial class Interop
|
|||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ldap_delete_ext(ConnectionHandle ldapHandle, string dn, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ldap_result", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_result", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static extern int ldap_result(ConnectionHandle ldapHandle, int messageId, int all, LDAP_TIMEVAL timeout, ref IntPtr Mesage);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
public static partial int ldap_result(ConnectionHandle ldapHandle, int messageId, int all, in LDAP_TIMEVAL timeout, ref IntPtr Mesage);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_parse_resultW", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
|
@ -129,12 +117,9 @@ internal static partial class Interop
|
|||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ldap_rename(ConnectionHandle ldapHandle, string dn, string newRdn, string newParentDn, int deleteOldRdn, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ldap_compare_extW", CharSet = CharSet.Unicode)]
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_compare_extW", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static extern int ldap_compare(ConnectionHandle ldapHandle, string dn, string attributeName, string strValue, BerVal binaryValue, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
public static partial int ldap_compare(ConnectionHandle ldapHandle, string dn, string attributeName, string strValue, BerVal binaryValue, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_add_extW", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
|
@ -144,12 +129,9 @@ internal static partial class Interop
|
|||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static partial int ldap_modify(ConnectionHandle ldapHandle, string dn, IntPtr attrs, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
|
||||
[DllImport(Libraries.Wldap32, EntryPoint = "ldap_extended_operationW", CharSet = CharSet.Unicode)]
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_extended_operationW", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
public static extern int ldap_extended_operation(ConnectionHandle ldapHandle, string oid, BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
public static partial int ldap_extended_operation(ConnectionHandle ldapHandle, string oid, BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
|
||||
|
||||
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_parse_extended_resultW", CharSet = CharSet.Unicode)]
|
||||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
// 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 Wtsapi32
|
||||
{
|
||||
[DllImport(Libraries.Wtsapi32, ExactSpelling = true)]
|
||||
public static extern bool WTSRegisterSessionNotification(HandleRef hWnd, int dwFlags);
|
||||
[GeneratedDllImport(Libraries.Wtsapi32, ExactSpelling = true)]
|
||||
public static partial bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
// 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 Wtsapi32
|
||||
{
|
||||
[DllImport(Libraries.Wtsapi32, ExactSpelling = true)]
|
||||
public static extern bool WTSUnRegisterSessionNotification(HandleRef hWnd);
|
||||
[GeneratedDllImport(Libraries.Wtsapi32, ExactSpelling = true)]
|
||||
public static partial bool WTSUnRegisterSessionNotification(IntPtr hWnd);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +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 Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace System.Net
|
||||
{
|
||||
#if DEBUG
|
||||
//
|
||||
// This is a helper class for debugging GC-ed handles that we define.
|
||||
// As a general rule normal code path should always destroy handles explicitly
|
||||
//
|
||||
internal abstract class DebugCriticalHandleZeroOrMinusOneIsInvalid : CriticalHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
private string _trace;
|
||||
|
||||
protected DebugCriticalHandleZeroOrMinusOneIsInvalid() : base()
|
||||
{
|
||||
_trace = "WARNING! GC-ed >>" + this.GetType().FullName + "<< (should be explicitly closed) \r\n";
|
||||
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, "Creating SafeHandle");
|
||||
}
|
||||
|
||||
~DebugCriticalHandleZeroOrMinusOneIsInvalid()
|
||||
{
|
||||
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, _trace);
|
||||
}
|
||||
}
|
||||
#endif // DEBUG
|
||||
}
|
|
@ -10,17 +10,17 @@ namespace System.Net
|
|||
// This is a helper class for debugging GC-ed handles that we define.
|
||||
// As a general rule normal code path should always destroy handles explicitly
|
||||
//
|
||||
internal abstract class DebugCriticalHandleMinusOneIsInvalid : CriticalHandleMinusOneIsInvalid
|
||||
internal abstract class DebugSafeHandleZeroOrMinusOneIsInvalid : SafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
private string _trace;
|
||||
|
||||
protected DebugCriticalHandleMinusOneIsInvalid() : base()
|
||||
protected DebugSafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(ownsHandle)
|
||||
{
|
||||
_trace = "WARNING! GC-ed >>" + this.GetType().FullName + "<< (should be explicitly closed) \r\n";
|
||||
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, "Creating SafeHandle");
|
||||
}
|
||||
|
||||
~DebugCriticalHandleMinusOneIsInvalid()
|
||||
~DebugSafeHandleZeroOrMinusOneIsInvalid()
|
||||
{
|
||||
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, _trace);
|
||||
}
|
|
@ -8,23 +8,18 @@ using System.Threading;
|
|||
namespace System.Net.Security
|
||||
{
|
||||
#if DEBUG
|
||||
internal sealed class SecurityContextTokenHandle : DebugCriticalHandleZeroOrMinusOneIsInvalid
|
||||
internal sealed class SecurityContextTokenHandle : DebugSafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
#else
|
||||
internal sealed class SecurityContextTokenHandle : CriticalHandleZeroOrMinusOneIsInvalid
|
||||
internal sealed class SecurityContextTokenHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
#endif
|
||||
private int _disposed;
|
||||
|
||||
public SecurityContextTokenHandle() : base()
|
||||
public SecurityContextTokenHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
internal IntPtr DangerousGetHandle()
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
if (!IsInvalid)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
//
|
||||
// Types in this file are used for generated p/invokes (docs/design/features/source-generator-pinvokes.md).
|
||||
// See the DllImportGenerator experiment in https://github.com/dotnet/runtimelab.
|
||||
//
|
||||
#if DLLIMPORTGENERATOR_INTERNALUNSAFE
|
||||
using Internal.Runtime.CompilerServices;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
//
|
||||
// Types in this file are used for generated p/invokes (docs/design/features/source-generator-pinvokes.md).
|
||||
// See the DllImportGenerator experiment in https://github.com/dotnet/runtimelab.
|
||||
//
|
||||
namespace System.Runtime.InteropServices
|
||||
{
|
||||
|
@ -19,16 +18,6 @@ namespace System.Runtime.InteropServices
|
|||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Struct)]
|
||||
#if DLLIMPORT_GENERATOR_TEST
|
||||
public
|
||||
#else
|
||||
internal
|
||||
#endif
|
||||
sealed class BlittableTypeAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class)]
|
||||
#if DLLIMPORT_GENERATOR_TEST
|
||||
public
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
#nullable enable
|
||||
|
||||
|
||||
namespace System.Runtime.InteropServices.GeneratedMarshalling
|
||||
{
|
||||
internal struct HandleRefMarshaller
|
||||
{
|
||||
private HandleRef _handle;
|
||||
|
||||
public HandleRefMarshaller(HandleRef handle)
|
||||
{
|
||||
_handle = handle;
|
||||
}
|
||||
|
||||
public IntPtr Value => _handle.Handle;
|
||||
|
||||
public void FreeNative() => GC.KeepAlive(_handle.Wrapper);
|
||||
}
|
||||
}
|
|
@ -11,6 +11,8 @@
|
|||
<NoWarn Condition="'$(TargetsWindows)' != 'true'">$(NoWarn);CA1823</NoWarn> <!-- Avoid unused fields warnings in Unix build -->
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
|
||||
Link="Common\DisableRuntimeMarshalling.cs" />
|
||||
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.RegistryConstants.cs"
|
||||
Link="Common\Interop\Windows\Advapi32\Interop.RegistryConstants.cs" />
|
||||
<Compile Include="$(CoreLibSharedDir)Microsoft\Win32\SafeHandles\SafeRegistryHandle.cs"
|
||||
|
|
|
@ -7,10 +7,10 @@ using Microsoft.Win32.SafeHandles;
|
|||
|
||||
namespace Microsoft.Win32.RegistryTests
|
||||
{
|
||||
internal static class Helpers
|
||||
internal static partial class Helpers
|
||||
{
|
||||
[DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueW", SetLastError = true)]
|
||||
private static extern int RegSetValue(SafeRegistryHandle handle, string value, int regType, string sb, int sizeIgnored);
|
||||
[GeneratedDllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueW", SetLastError = true)]
|
||||
private static partial int RegSetValue(SafeRegistryHandle handle, string value, int regType, string sb, int sizeIgnored);
|
||||
|
||||
internal static bool SetDefaultValue(this RegistryKey key, string value)
|
||||
{
|
||||
|
@ -18,8 +18,8 @@ namespace Microsoft.Win32.RegistryTests
|
|||
return RegSetValue(key.Handle, null, REG_SZ, value, 0) == 0;
|
||||
}
|
||||
|
||||
[DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", SetLastError = true)]
|
||||
private static extern int RegQueryValueEx(SafeRegistryHandle handle, string valueName, int[] reserved, IntPtr regType, [Out] byte[] value, ref int size);
|
||||
[GeneratedDllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", SetLastError = true)]
|
||||
private static partial int RegQueryValueEx(SafeRegistryHandle handle, string valueName, int[] reserved, IntPtr regType, byte[] value, ref int size);
|
||||
|
||||
internal static bool IsDefaultValueSet(this RegistryKey key)
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ namespace Microsoft.Win32.RegistryTests
|
|||
return RegQueryValueEx(key.Handle, null, null, IntPtr.Zero, b, ref size) != ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
[DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool SetEnvironmentVariable(string lpName, string lpValue);
|
||||
[GeneratedDllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static partial bool SetEnvironmentVariable(string lpName, string lpValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
|
||||
Link="Common\DisableRuntimeMarshalling.cs" />
|
||||
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
|
||||
Link="Common\Interop\Windows\Interop.Libraries.cs" />
|
||||
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.RegSetValueEx.cs"
|
||||
|
@ -58,4 +60,4 @@
|
|||
<Compile Include="TestData.cs" />
|
||||
<Compile Include="XunitAssemblyAttributes.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -120,6 +120,9 @@ Microsoft.Win32.SystemEvents</PackageDescription>
|
|||
<Compile Include="Microsoft\Win32\UserPreferenceChangedEventHandler.cs" />
|
||||
<Compile Include="Microsoft\Win32\UserPreferenceChangingEventArgs.cs" />
|
||||
<Compile Include="Microsoft\Win32\UserPreferenceChangingEventHandler.cs" />
|
||||
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
|
||||
Link="Common\DisableRuntimeMarshalling.cs"
|
||||
Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))" />
|
||||
<Compile Include="$(CoreLibSharedDir)System\Runtime\InteropServices\SuppressGCTransitionAttribute.cs"
|
||||
Link="System\Runtime\InteropServices\SuppressGCTransitionAttribute.cs"
|
||||
Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
|
||||
|
|
|
@ -393,8 +393,9 @@ namespace Microsoft.Win32
|
|||
}
|
||||
|
||||
EnsureSystemEvents(requireHandle: true);
|
||||
IntPtr timerId = Interop.User32.SendMessageW(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle),
|
||||
IntPtr timerId = Interop.User32.SendMessageW(s_systemEvents!._windowHandle,
|
||||
Interop.User32.WM_CREATETIMER, (IntPtr)interval, IntPtr.Zero);
|
||||
GC.KeepAlive(s_systemEvents);
|
||||
|
||||
if (timerId == IntPtr.Zero)
|
||||
{
|
||||
|
@ -409,7 +410,8 @@ namespace Microsoft.Win32
|
|||
{
|
||||
if (s_registeredSessionNotification)
|
||||
{
|
||||
Interop.Wtsapi32.WTSUnRegisterSessionNotification(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle));
|
||||
Interop.Wtsapi32.WTSUnRegisterSessionNotification(s_systemEvents!._windowHandle);
|
||||
GC.KeepAlive(s_systemEvents);
|
||||
}
|
||||
|
||||
IntPtr handle = _windowHandle;
|
||||
|
@ -507,7 +509,8 @@ namespace Microsoft.Win32
|
|||
|
||||
if (retval != IntPtr.Zero)
|
||||
{
|
||||
Interop.Wtsapi32.WTSRegisterSessionNotification(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle), Interop.Wtsapi32.NOTIFY_FOR_THIS_SESSION);
|
||||
Interop.Wtsapi32.WTSRegisterSessionNotification(s_systemEvents!._windowHandle, Interop.Wtsapi32.NOTIFY_FOR_THIS_SESSION);
|
||||
GC.KeepAlive(s_systemEvents);
|
||||
s_registeredSessionNotification = true;
|
||||
Interop.Kernel32.FreeLibrary(retval);
|
||||
}
|
||||
|
@ -752,9 +755,13 @@ namespace Microsoft.Win32
|
|||
EnsureSystemEvents(requireHandle: true);
|
||||
|
||||
#if DEBUG
|
||||
int pid;
|
||||
int thread = Interop.User32.GetWindowThreadProcessId(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle), out pid);
|
||||
Debug.Assert(s_windowThread == null || thread != Interop.Kernel32.GetCurrentThreadId(), "Don't call MarshaledInvoke on the system events thread");
|
||||
unsafe
|
||||
{
|
||||
int pid;
|
||||
int thread = Interop.User32.GetWindowThreadProcessId(s_systemEvents!._windowHandle, &pid);
|
||||
GC.KeepAlive(s_systemEvents);
|
||||
Debug.Assert(s_windowThread == null || thread != Interop.Kernel32.GetCurrentThreadId(), "Don't call MarshaledInvoke on the system events thread");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (s_threadCallbackList == null)
|
||||
|
@ -776,7 +783,8 @@ namespace Microsoft.Win32
|
|||
s_threadCallbackList.Enqueue(method);
|
||||
}
|
||||
|
||||
Interop.User32.PostMessageW(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle), s_threadCallbackMessage, IntPtr.Zero, IntPtr.Zero);
|
||||
Interop.User32.PostMessageW(s_systemEvents!._windowHandle, s_threadCallbackMessage, IntPtr.Zero, IntPtr.Zero);
|
||||
GC.KeepAlive(s_systemEvents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -787,8 +795,9 @@ namespace Microsoft.Win32
|
|||
EnsureSystemEvents(requireHandle: true);
|
||||
if (s_systemEvents!._windowHandle != IntPtr.Zero)
|
||||
{
|
||||
int res = (int)Interop.User32.SendMessageW(new HandleRef(s_systemEvents, s_systemEvents._windowHandle),
|
||||
int res = (int)Interop.User32.SendMessageW(s_systemEvents._windowHandle,
|
||||
Interop.User32.WM_KILLTIMER, timerId, IntPtr.Zero);
|
||||
GC.KeepAlive(s_systemEvents);
|
||||
|
||||
if (res == 0)
|
||||
throw new ExternalException(SR.ErrorKillTimer);
|
||||
|
@ -1080,18 +1089,22 @@ namespace Microsoft.Win32
|
|||
if (s_windowThread != null)
|
||||
{
|
||||
#if DEBUG
|
||||
int pid;
|
||||
int thread = Interop.User32.GetWindowThreadProcessId(new HandleRef(s_systemEvents, s_systemEvents._windowHandle), out pid);
|
||||
Debug.Assert(thread != Interop.Kernel32.GetCurrentThreadId(), "Don't call Shutdown on the system events thread");
|
||||
#endif
|
||||
unsafe
|
||||
{
|
||||
int pid;
|
||||
int thread = Interop.User32.GetWindowThreadProcessId(s_systemEvents._windowHandle, &pid);
|
||||
Debug.Assert(thread != Interop.Kernel32.GetCurrentThreadId(), "Don't call Shutdown on the system events thread");
|
||||
|
||||
}
|
||||
#endif
|
||||
// The handle could be valid, Zero or invalid depending on the state of the thread
|
||||
// that is processing the messages. We optimistically expect it to be valid to
|
||||
// notify the thread to shutdown. The Zero or invalid values should be present
|
||||
// only when the thread is already shutting down due to external factors.
|
||||
if (s_systemEvents._windowHandle != IntPtr.Zero)
|
||||
{
|
||||
Interop.User32.PostMessageW(new HandleRef(s_systemEvents, s_systemEvents._windowHandle), Interop.User32.WM_QUIT, IntPtr.Zero, IntPtr.Zero);
|
||||
Interop.User32.PostMessageW(s_systemEvents._windowHandle, Interop.User32.WM_QUIT, IntPtr.Zero, IntPtr.Zero);
|
||||
GC.KeepAlive(s_systemEvents);
|
||||
}
|
||||
|
||||
s_windowThread.Join();
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
<Compile Include="System\IO\CachedConsoleStream.cs" />
|
||||
<Compile Include="System\IO\SyncTextReader.cs" />
|
||||
<Compile Include="System\IO\Error.cs" />
|
||||
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
|
||||
Link="Common\DisableRuntimeMarshalling.cs" />
|
||||
<Compile Include="$(CommonPath)System\Text\ConsoleEncoding.cs"
|
||||
Link="Common\System\Text\ConsoleEncoding.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -134,11 +134,11 @@ public partial class CancelKeyPressTests
|
|||
}
|
||||
}
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
private static extern int kill(int pid, int sig);
|
||||
[GeneratedDllImport("libc", SetLastError = true)]
|
||||
private static partial int kill(int pid, int sig);
|
||||
|
||||
[DllImport("libc", SetLastError = true)]
|
||||
private static unsafe extern int sigaction(int signum, struct_sigaction* act, struct_sigaction* oldact);
|
||||
[GeneratedDllImport("libc", SetLastError = true)]
|
||||
private static unsafe partial int sigaction(int signum, struct_sigaction* act, struct_sigaction* oldact);
|
||||
|
||||
private const int SIGINT = 2;
|
||||
private const int SIGQUIT = 3;
|
||||
|
|
|
@ -67,9 +67,9 @@ public partial class ConsoleEncoding
|
|||
}).Dispose();
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern uint GetConsoleCP();
|
||||
[GeneratedDllImport("kernel32.dll")]
|
||||
public static partial uint GetConsoleCP();
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern uint GetConsoleOutputCP();
|
||||
[GeneratedDllImport("kernel32.dll")]
|
||||
public static partial uint GetConsoleOutputCP();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
<Compile Include="TermInfo.cs" />
|
||||
<Compile Include="RedirectedStream.cs" />
|
||||
<Compile Include="ReadKey.cs" />
|
||||
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
|
||||
Link="Common\DisableRuntimeMarshalling.cs" />
|
||||
<Compile Include="$(CommonTestPath)System\IO\InterceptStreamWriter.cs"
|
||||
Link="Common\System\IO\InterceptStreamWriter.cs" />
|
||||
<Compile Include="$(CommonTestPath)System\ShouldNotBeInvokedException.cs"
|
||||
|
|
|
@ -126,6 +126,12 @@ System.Data.Odbc.OdbcTransaction</PackageDescription>
|
|||
<Compile Include="$(CommonPath)Interop\Interop.Odbc.cs"
|
||||
Link="Common\Interop\Interop.Odbc.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
|
||||
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
|
||||
Link="Common\DisableRuntimeMarshalling.cs" />
|
||||
<Compile Include="$(CommonPath)System\Runtime\InteropServices\HandleRefMarshaller.cs"
|
||||
Link="Common\System\Runtime\InteropServices\HandleRefMarshaller.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetsLinux)' == 'true' or '$(TargetsFreeBSD)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'">
|
||||
<Compile Include="$(CommonPath)Interop\Linux\Interop.Libraries.cs"
|
||||
Link="Common\Interop\Linux\Interop.Libraries.cs" />
|
||||
|
|
|
@ -178,19 +178,19 @@ namespace System.Data.Odbc
|
|||
internal ODBC32.SQLRETURN GetDiagnosticField(out string sqlState)
|
||||
{
|
||||
// ODBC (MSDN) documents it expects a buffer large enough to hold 5(+L'\0') unicode characters
|
||||
StringBuilder sb = new StringBuilder(6);
|
||||
char[] buffer = new char[6];
|
||||
ODBC32.SQLRETURN retcode = Interop.Odbc.SQLGetDiagFieldW(
|
||||
HandleType,
|
||||
this,
|
||||
(short)1,
|
||||
ODBC32.SQL_DIAG_SQLSTATE,
|
||||
sb,
|
||||
checked((short)(2 * sb.Capacity)), // expects number of bytes, see \\kbinternal\kb\articles\294\1\69.HTM
|
||||
buffer,
|
||||
checked((short)(2 * buffer.Length)), // expects number of bytes, see \\kbinternal\kb\articles\294\1\69.HTM
|
||||
out _);
|
||||
ODBC.TraceODBC(3, "SQLGetDiagFieldW", retcode);
|
||||
if ((retcode == ODBC32.SQLRETURN.SUCCESS) || (retcode == ODBC32.SQLRETURN.SUCCESS_WITH_INFO))
|
||||
{
|
||||
sqlState = sb.ToString();
|
||||
sqlState = new string(buffer.AsSpan().Slice(0, buffer.AsSpan().IndexOf('\0')));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -199,21 +199,23 @@ namespace System.Data.Odbc
|
|||
return retcode;
|
||||
}
|
||||
|
||||
internal ODBC32.SQLRETURN GetDiagnosticRecord(short record, out string sqlState, StringBuilder message, out int nativeError, out short cchActual)
|
||||
internal ODBC32.SQLRETURN GetDiagnosticRecord(short record, out string sqlState, StringBuilder messageBuilder, out int nativeError, out short cchActual)
|
||||
{
|
||||
// ODBC (MSDN) documents it expects a buffer large enough to hold 4(+L'\0') unicode characters
|
||||
StringBuilder sb = new StringBuilder(5);
|
||||
ODBC32.SQLRETURN retcode = Interop.Odbc.SQLGetDiagRecW(HandleType, this, record, sb, out nativeError, message, checked((short)message.Capacity), out cchActual);
|
||||
char[] buffer = new char[5];
|
||||
char[] message = new char[1024];
|
||||
ODBC32.SQLRETURN retcode = Interop.Odbc.SQLGetDiagRecW(HandleType, this, record, buffer, out nativeError, message, checked((short)message.Length), out cchActual);
|
||||
ODBC.TraceODBC(3, "SQLGetDiagRecW", retcode);
|
||||
|
||||
if ((retcode == ODBC32.SQLRETURN.SUCCESS) || (retcode == ODBC32.SQLRETURN.SUCCESS_WITH_INFO))
|
||||
{
|
||||
sqlState = sb.ToString();
|
||||
sqlState = new string(buffer.AsSpan().Slice(0, buffer.AsSpan().IndexOf('\0')));
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlState = string.Empty;
|
||||
}
|
||||
messageBuilder.Append(new string(message.AsSpan().Slice(0, message.AsSpan().IndexOf('\0'))));
|
||||
return retcode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,6 +133,9 @@ System.Data.OleDb.OleDbTransaction</PackageDescription>
|
|||
<Compile Include="UnsafeNativeMethods.COMWrappers.cs" />
|
||||
<Compile Include="OleDbComWrappers.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true' and !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))">
|
||||
<Compile Include="UnsafeNativeMethods.NoCOMWrappers.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\System.Data.OleDb.OleDbMetaData.xml"
|
||||
|
|
|
@ -19,7 +19,6 @@ namespace System.Data.ProviderBase
|
|||
{
|
||||
private const int E_NotImpersonationToken = unchecked((int)0x8007051D);
|
||||
private const int Win32_CheckTokenMembership = 1;
|
||||
private const int Win32_CreateWellKnownSid = 5;
|
||||
|
||||
public static readonly DbConnectionPoolIdentity NoIdentity = new DbConnectionPoolIdentity(string.Empty, false, true);
|
||||
|
||||
|
@ -41,22 +40,6 @@ namespace System.Data.ProviderBase
|
|||
get { return _isRestricted; }
|
||||
}
|
||||
|
||||
private static byte[] CreateWellKnownSid(WellKnownSidType sidType)
|
||||
{
|
||||
// Passing an array as big as it can ever be is a small price to pay for
|
||||
// not having to P/Invoke twice (once to get the buffer, once to get the data)
|
||||
|
||||
uint length = (uint)SecurityIdentifier.MaxBinaryLength;
|
||||
|
||||
// NOTE - We copied this code from System.Security.Principal.Win32.CreateWellKnownSid...
|
||||
|
||||
if (0 == UnsafeNativeMethods.CreateWellKnownSid((int)sidType, null, out byte[] resultSid, ref length))
|
||||
{
|
||||
IntegratedSecurityError(Win32_CreateWellKnownSid);
|
||||
}
|
||||
return resultSid;
|
||||
}
|
||||
|
||||
public override bool Equals(object? value)
|
||||
{
|
||||
bool result = ((this == NoIdentity) || (this == value));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// 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;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
|
@ -831,12 +832,5 @@ namespace System.Data.Common
|
|||
_name = name;
|
||||
}
|
||||
}
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "CreateWellKnownSid", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
internal static partial int CreateWellKnownSid(
|
||||
int sidType,
|
||||
byte[]? domainSid,
|
||||
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] out byte[] resultSid,
|
||||
ref uint resultSidLength);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,10 @@ System.Diagnostics.EventLog</PackageDescription>
|
|||
<Compile Include="$(CommonPath)System\Diagnostics\NetFrameworkUtils.cs"
|
||||
Link="Common\System\Diagnostics\NetFrameworkUtils.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
|
||||
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
|
||||
Link="Common\DisableRuntimeMarshalling.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
|
||||
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" />
|
||||
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" />
|
||||
|
|
|
@ -338,7 +338,10 @@ namespace Microsoft.Win32
|
|||
EvtRpcLogin = 1
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
#if NET7_0_OR_GREATER
|
||||
[NativeMarshalling(typeof(Marshaller))]
|
||||
#endif
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct EvtRpcLogin
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
|
@ -349,6 +352,72 @@ namespace Microsoft.Win32
|
|||
public string Domain;
|
||||
public CoTaskMemUnicodeSafeHandle Password;
|
||||
public int Flags;
|
||||
#if NET7_0_OR_GREATER
|
||||
public struct Marshaller
|
||||
{
|
||||
public struct Native
|
||||
{
|
||||
public IntPtr Server;
|
||||
public IntPtr User;
|
||||
public IntPtr Domain;
|
||||
public IntPtr Password;
|
||||
public int Flags;
|
||||
}
|
||||
|
||||
private CoTaskMemUnicodeSafeHandle _passwordHandle;
|
||||
private Native _value;
|
||||
private bool _passwordHandleAddRefd;
|
||||
|
||||
public Marshaller(EvtRpcLogin managed)
|
||||
{
|
||||
_passwordHandleAddRefd = false;
|
||||
_value.Server = Marshal.StringToCoTaskMemUni(managed.Server);
|
||||
_value.User = Marshal.StringToCoTaskMemUni(managed.User);
|
||||
_value.Domain = Marshal.StringToCoTaskMemUni(managed.Domain);
|
||||
_passwordHandle = managed.Password;
|
||||
_passwordHandle.DangerousAddRef(ref _passwordHandleAddRefd);
|
||||
_value.Password = _passwordHandle.DangerousGetHandle();
|
||||
_value.Flags = managed.Flags;
|
||||
}
|
||||
|
||||
public Native Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
// SafeHandle fields cannot change the underlying handle value during marshalling.
|
||||
if (_value.Password != value.Password)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public EvtRpcLogin ToManaged()
|
||||
{
|
||||
return new EvtRpcLogin
|
||||
{
|
||||
Server = Marshal.PtrToStringUni(_value.Server),
|
||||
User = Marshal.PtrToStringUni(_value.User),
|
||||
Domain = Marshal.PtrToStringUni(_value.Domain),
|
||||
Password = _passwordHandle,
|
||||
Flags = _value.Flags
|
||||
};
|
||||
}
|
||||
|
||||
public void FreeNative()
|
||||
{
|
||||
Marshal.FreeCoTaskMem(_value.Server);
|
||||
Marshal.FreeCoTaskMem(_value.User);
|
||||
Marshal.FreeCoTaskMem(_value.Domain);
|
||||
if (_passwordHandleAddRefd)
|
||||
{
|
||||
_passwordHandle.DangerousRelease();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// SEEK
|
||||
|
@ -597,7 +666,10 @@ namespace Microsoft.Win32
|
|||
out int buffUsed,
|
||||
out int propCount);
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Auto)]
|
||||
#if NET7_0_OR_GREATER
|
||||
[NativeMarshalling(typeof(Native))]
|
||||
#endif
|
||||
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
|
||||
internal struct EvtStringVariant
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPWStr), FieldOffset(0)]
|
||||
|
@ -606,12 +678,45 @@ namespace Microsoft.Win32
|
|||
public uint Count;
|
||||
[FieldOffset(12)]
|
||||
public uint Type;
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Native
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
private IntPtr StringVal;
|
||||
[FieldOffset(8)]
|
||||
private uint Count;
|
||||
[FieldOffset(12)]
|
||||
private uint Type;
|
||||
|
||||
public Native(EvtStringVariant managed)
|
||||
{
|
||||
StringVal = Marshal.StringToCoTaskMemUni(managed.StringVal);
|
||||
Count = managed.Count;
|
||||
Type = managed.Type;
|
||||
}
|
||||
|
||||
public EvtStringVariant ToManaged()
|
||||
{
|
||||
return new EvtStringVariant
|
||||
{
|
||||
StringVal = Marshal.PtrToStringUni(StringVal),
|
||||
Count = Count,
|
||||
Type = Type
|
||||
};
|
||||
}
|
||||
|
||||
public void FreeNative()
|
||||
{
|
||||
Marshal.FreeCoTaskMem(StringVal);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
|
||||
[DllImport(Interop.Libraries.Wevtapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
|
||||
internal static extern bool EvtFormatMessage(
|
||||
[GeneratedDllImport(Interop.Libraries.Wevtapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
|
||||
internal static partial bool EvtFormatMessage(
|
||||
EventLogHandle publisherMetadataHandle,
|
||||
EventLogHandle eventHandle,
|
||||
uint messageId,
|
||||
|
@ -621,7 +726,6 @@ namespace Microsoft.Win32
|
|||
int bufferSize,
|
||||
[Out] char[]? buffer,
|
||||
out int bufferUsed);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
|
||||
[GeneratedDllImport(Interop.Libraries.Wevtapi, EntryPoint = "EvtFormatMessage", SetLastError = true)]
|
||||
internal static partial bool EvtFormatMessageBuffer(
|
||||
|
@ -636,15 +740,12 @@ namespace Microsoft.Win32
|
|||
out int bufferUsed);
|
||||
|
||||
// SESSION
|
||||
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
|
||||
// TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
|
||||
[DllImport(Interop.Libraries.Wevtapi, SetLastError = true)]
|
||||
internal static extern EventLogHandle EvtOpenSession(
|
||||
[GeneratedDllImport(Interop.Libraries.Wevtapi, SetLastError = true)]
|
||||
internal static partial EventLogHandle EvtOpenSession(
|
||||
EvtLoginClass loginClass,
|
||||
ref EvtRpcLogin login,
|
||||
int timeout,
|
||||
int flags);
|
||||
#pragma warning restore DLLIMPORTGENANALYZER015
|
||||
|
||||
// BOOKMARK
|
||||
[GeneratedDllImport(Interop.Libraries.Wevtapi, EntryPoint = "EvtCreateBookmark", SetLastError = true)]
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
|
||||
<Compile Include="EventLogMessagesTests.cs" />
|
||||
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
|
||||
Link="Common\DisableRuntimeMarshalling.cs" />
|
||||
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.CloseHandle.cs"
|
||||
Link="Common\Interop\Windows\Kernel32\Interop.CloseHandle.cs" />
|
||||
<Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeLibraryHandle.cs"
|
||||
|
@ -43,4 +45,4 @@
|
|||
<ProjectReference Include="..\src\System.Diagnostics.EventLog.csproj" />
|
||||
<ProjectReference Include="..\src\Messages\System.Diagnostics.EventLog.Messages.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
</PropertyGroup>
|
||||
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
|
||||
<PropertyGroup>
|
||||
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsAnyOS)' == 'true'">SR.DiagnosticsFileVersionInfo_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
|
||||
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsAnyOS)' == 'true'">SR.DiagnosticsFileVersionInfo_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
|
||||
<Compile Include="System\Diagnostics\FileVersionInfo.cs" />
|
||||
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
|
||||
Link="Common\DisableRuntimeMarshalling.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
|
||||
<Compile Include="System\Diagnostics\FileVersionInfo.Windows.cs" />
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue