Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Convert to OleDb assembly and last Cryptography DllImport to GeneratedDllImport #61184

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/generators.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<EnabledGenerators Include="DllImportGenerator"
Condition="'$(EnableDllImportGenerator)' == ''
and '$(IsFrameworkSupportFacade)' != 'true'
and '$(IsNetCoreAppSrc)' == 'true'
and '$(IsSourceProject)' == 'true'
and '$(MSBuildProjectExtension)' == '.csproj'
and (
('@(Reference)' != ''
Expand Down
46 changes: 23 additions & 23 deletions src/libraries/System.Data.OleDb/src/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace System.Data.Common
{
internal static class NativeMethods
internal static partial class NativeMethods
{
[Guid("0c733a1e-2a1c-11ce-ade5-00aa0044773d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport]
internal interface ISourcesRowset
Expand Down Expand Up @@ -33,17 +33,17 @@ void JoinTransaction(
[In] IntPtr pOtherOptions);
}

[DllImport(Interop.Libraries.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
internal static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, IntPtr dwNumberOfBytesToMap);
[GeneratedDllImport(Interop.Libraries.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
internal static partial IntPtr MapViewOfFile(IntPtr hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, IntPtr dwNumberOfBytesToMap);

[DllImport(Interop.Libraries.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
internal static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
[GeneratedDllImport(Interop.Libraries.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
internal static partial bool UnmapViewOfFile(IntPtr lpBaseAddress);

[DllImport(Interop.Libraries.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static extern bool CloseHandle(IntPtr handle);
[GeneratedDllImport(Interop.Libraries.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static partial bool CloseHandle(IntPtr handle);

[DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static extern bool AllocateAndInitializeSid(
[GeneratedDllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static partial bool AllocateAndInitializeSid(
IntPtr pIdentifierAuthority, // authority
byte nSubAuthorityCount, // count of subauthorities
int dwSubAuthority0, // subauthority 0
Expand All @@ -56,43 +56,43 @@ internal static extern bool AllocateAndInitializeSid(
int dwSubAuthority7, // subauthority 7
ref IntPtr pSid); // SID

[DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static extern int GetLengthSid(
[GeneratedDllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static partial int GetLengthSid(
IntPtr pSid); // SID to query

[DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static extern bool InitializeAcl(
[GeneratedDllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static partial bool InitializeAcl(
IntPtr pAcl, // ACL
int nAclLength, // size of ACL
int dwAclRevision); // revision level of ACL

[DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static extern bool AddAccessDeniedAce(
[GeneratedDllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static partial bool AddAccessDeniedAce(
IntPtr pAcl, // access control list
int dwAceRevision, // ACL revision level
int AccessMask, // access mask
IntPtr pSid); // security identifier

[DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static extern bool AddAccessAllowedAce(
[GeneratedDllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static partial bool AddAccessAllowedAce(
IntPtr pAcl, // access control list
int dwAceRevision, // ACL revision level
uint AccessMask, // access mask
IntPtr pSid); // security identifier

[DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static extern bool InitializeSecurityDescriptor(
[GeneratedDllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static partial bool InitializeSecurityDescriptor(
IntPtr pSecurityDescriptor, // SD
int dwRevision); // revision level
[DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static extern bool SetSecurityDescriptorDacl(
[GeneratedDllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static partial bool SetSecurityDescriptorDacl(
IntPtr pSecurityDescriptor, // SD
bool bDaclPresent, // DACL presence
IntPtr pDacl, // DACL
bool bDaclDefaulted); // default DACL

[DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static extern IntPtr FreeSid(
[GeneratedDllImport(Interop.Libraries.Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
internal static partial IntPtr FreeSid(
IntPtr pSid); // SID to free
}
}
58 changes: 29 additions & 29 deletions src/libraries/System.Data.OleDb/src/SafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
namespace System.Data.Common
{
[SuppressUnmanagedCodeSecurity]
internal static class SafeNativeMethods
internal static partial class SafeNativeMethods
{
[DllImport(Interop.Libraries.Ole32, SetLastError = false)]
internal static extern IntPtr CoTaskMemAlloc(IntPtr cb);
[GeneratedDllImport(Interop.Libraries.Ole32, SetLastError = false)]
internal static partial IntPtr CoTaskMemAlloc(IntPtr cb);

[DllImport(Interop.Libraries.Ole32, SetLastError = false)]
internal static extern void CoTaskMemFree(IntPtr handle);
[GeneratedDllImport(Interop.Libraries.Ole32, SetLastError = false)]
internal static partial void CoTaskMemFree(IntPtr handle);

[DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode, PreserveSig = true)]
internal static extern int GetUserDefaultLCID();
[GeneratedDllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode, PreserveSig = true)]
internal static partial int GetUserDefaultLCID();

internal static void ZeroMemory(IntPtr ptr, int length)
{
Expand All @@ -44,40 +44,40 @@ internal static unsafe IntPtr InterlockedExchangePointer(
return actualPtr;
}

[DllImport(Interop.Libraries.Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
internal static extern int GetCurrentProcessId();
[GeneratedDllImport(Interop.Libraries.Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
internal static partial int GetCurrentProcessId();

[DllImport(Interop.Libraries.Kernel32, SetLastError = true)]
internal static extern IntPtr LocalAlloc(int flags, IntPtr countOfBytes);
[GeneratedDllImport(Interop.Libraries.Kernel32, SetLastError = true)]
internal static partial IntPtr LocalAlloc(int flags, IntPtr countOfBytes);

[DllImport(Interop.Libraries.Kernel32, SetLastError = true)]
internal static extern IntPtr LocalFree(IntPtr handle);
[GeneratedDllImport(Interop.Libraries.Kernel32, SetLastError = true)]
internal static partial IntPtr LocalFree(IntPtr handle);

[DllImport(Interop.Libraries.OleAut32, CharSet = CharSet.Unicode)]
internal static extern IntPtr SysAllocStringLen(string src, int len); // BSTR
[GeneratedDllImport(Interop.Libraries.OleAut32, CharSet = CharSet.Unicode)]
internal static partial IntPtr SysAllocStringLen(string src, int len); // BSTR

[DllImport(Interop.Libraries.OleAut32)]
internal static extern void SysFreeString(IntPtr bstr);
[GeneratedDllImport(Interop.Libraries.OleAut32)]
internal static partial void SysFreeString(IntPtr bstr);

// only using this to clear existing error info with null
[DllImport(Interop.Libraries.OleAut32, CharSet = CharSet.Unicode, PreserveSig = false)]
[GeneratedDllImport(Interop.Libraries.OleAut32, CharSet = CharSet.Unicode, PreserveSig = false)]
// TLS values are preserved between threads, need to check that we use this API to clear the error state only.
private static extern void SetErrorInfo(int dwReserved, IntPtr pIErrorInfo);
private static partial void SetErrorInfo(int dwReserved, IntPtr pIErrorInfo);

[DllImport(Interop.Libraries.Kernel32, SetLastError = true)]
internal static extern int ReleaseSemaphore(IntPtr handle, int releaseCount, IntPtr previousCount);
[GeneratedDllImport(Interop.Libraries.Kernel32, SetLastError = true)]
internal static partial int ReleaseSemaphore(IntPtr handle, int releaseCount, IntPtr previousCount);

[DllImport(Interop.Libraries.Kernel32, SetLastError = true)]
internal static extern int WaitForMultipleObjectsEx(uint nCount, IntPtr lpHandles, bool bWaitAll, uint dwMilliseconds, bool bAlertable);
[GeneratedDllImport(Interop.Libraries.Kernel32, SetLastError = true)]
internal static partial int WaitForMultipleObjectsEx(uint nCount, IntPtr lpHandles, bool bWaitAll, uint dwMilliseconds, bool bAlertable);

[DllImport(Interop.Libraries.Kernel32/*, SetLastError=true*/)]
internal static extern int WaitForSingleObjectEx(IntPtr lpHandles, uint dwMilliseconds, bool bAlertable);
[GeneratedDllImport(Interop.Libraries.Kernel32/*, SetLastError=true*/)]
internal static partial int WaitForSingleObjectEx(IntPtr lpHandles, uint dwMilliseconds, bool bAlertable);

[DllImport(Interop.Libraries.Ole32, PreserveSig = false)]
internal static extern void PropVariantClear(IntPtr pObject);
[GeneratedDllImport(Interop.Libraries.Ole32, PreserveSig = false)]
internal static partial void PropVariantClear(IntPtr pObject);

[DllImport(Interop.Libraries.OleAut32, PreserveSig = false)]
internal static extern void VariantClear(IntPtr pObject);
[GeneratedDllImport(Interop.Libraries.OleAut32, PreserveSig = false)]
internal static partial void VariantClear(IntPtr pObject);

internal sealed class Wrapper
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ System.Data.OleDb.OleDbTransaction</PackageDescription>
<Reference Include="System.Memory" />
<Reference Include="System.ObjectModel" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.CompilerServices.Unsafe" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Security.Principal.Windows" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static byte[] CreateWellKnownSid(WellKnownSidType sidType)

// NOTE - We copied this code from System.Security.Principal.Win32.CreateWellKnownSid...

if (0 == UnsafeNativeMethods.CreateWellKnownSid((int)sidType, null, resultSid, ref length))
if (0 == UnsafeNativeMethods.CreateWellKnownSid((int)sidType, null, out resultSid, ref length))
{
IntegratedSecurityError(Win32_CreateWellKnownSid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ internal static partial class UnsafeNativeMethods
// Oleaut32
//

[DllImport(Interop.Libraries.OleAut32)]
internal static unsafe extern OleDbHResult GetErrorInfo(
[GeneratedDllImport(Interop.Libraries.OleAut32)]
internal static unsafe partial OleDbHResult GetErrorInfo(
int dwReserved,
System.IntPtr* ppIErrorInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ internal static partial class UnsafeNativeMethods
// Oleaut32
//

[DllImport(Interop.Libraries.OleAut32, CharSet = CharSet.Unicode, PreserveSig = true)]
internal static extern System.Data.OleDb.OleDbHResult GetErrorInfo(
[GeneratedDllImport(Interop.Libraries.OleAut32, CharSet = CharSet.Unicode, PreserveSig = true)]
internal static partial System.Data.OleDb.OleDbHResult GetErrorInfo(
int dwReserved,
[MarshalAs(UnmanagedType.Interface)] out UnsafeNativeMethods.IErrorInfo? ppIErrorInfo);

Expand Down
6 changes: 3 additions & 3 deletions src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,11 @@ internal Trustee(string name)
}
}

[DllImport(Interop.Libraries.Advapi32, EntryPoint = "CreateWellKnownSid", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern int CreateWellKnownSid(
[GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "CreateWellKnownSid", SetLastError = true, CharSet = CharSet.Unicode)]
internal static partial int CreateWellKnownSid(
int sidType,
byte[]? domainSid,
[Out] byte[] resultSid,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] out byte[] resultSid,
ref uint resultSidLength);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ internal static SafeChainEngineHandle CertCreateCertificateChainEngine(ref CERT_
[GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
private static partial bool CertCreateCertificateChainEngine(ref CERT_CHAIN_ENGINE_CONFIG pConfig, out SafeChainEngineHandle hChainEngineHandle);

[DllImport(Libraries.Crypt32)]
public static extern void CertFreeCertificateChainEngine(IntPtr hChainEngine);
[GeneratedDllImport(Libraries.Crypt32)]
public static partial void CertFreeCertificateChainEngine(IntPtr hChainEngine);

[GeneratedDllImport(Libraries.Crypt32, SetLastError = true)]
public static unsafe partial bool CertGetCertificateChain(IntPtr hChainEngine, SafeCertContextHandle pCertContext, FILETIME* pTime, SafeCertStoreHandle hStore, ref CERT_CHAIN_PARA pChainPara, CertChainFlags dwFlags, IntPtr pvReserved, out SafeX509ChainHandle ppChainContext);
Expand Down