Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit46e8714

Browse files
benrr101Ben Russell
and
Ben Russell
authored
Merge | SniNativeWrapper Interface (#3015)
* Introducing ISniNativeMethods and porting X64 implementation to it* Adopting usage of SniNativeMethodsX64 in the netfx SniNativeMethodWrapper* Migrating x86 implementation of native methods* Migrating arm implementation of native methods* Introduce a NotSupported implementation of ISniMethods* Rewrite SniNativeMethodWrapper to select native method provider at static construction* Create a netcore implementation of ISniNativeMethods* Create merge file* Resolve merge conflicts ... I think 😅* Migrating to the merged version* Cleaning up derelict code for unix* Make SniNativeMethod implementations sealed* Fix unix project---------Co-authored-by: Ben Russell <ben@holycrapitsbenrussell>
1 parentfca9c27 commit46e8714

File tree

28 files changed

+2286
-1893
lines changed

28 files changed

+2286
-1893
lines changed

‎src/Microsoft.Data.SqlClient/netcore/src/Interop/SNINativeMethodWrapper.Unix.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎src/Microsoft.Data.SqlClient/netcore/src/Interop/SNINativeMethodWrapper.Windows.cs

Lines changed: 0 additions & 359 deletions
This file was deleted.

‎src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,9 @@
731731
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\IoType.cs">
732732
<Link>Interop\Windows\Sni\IoType.cs</Link>
733733
</Compile>
734+
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\ISniNativeMethods.cs">
735+
<Link>Interop\Windows\Sni\ISniNativeMethods.cs</Link>
736+
</Compile>
734737
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\Prefix.cs">
735738
<Link>Interop\Windows\Sni\Prefix.cs</Link>
736739
</Compile>
@@ -752,6 +755,12 @@
752755
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SniError.cs">
753756
<Link>Interop\Windows\Sni\SniError.cs</Link>
754757
</Compile>
758+
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethods.netcore.cs">
759+
<Link>Interop\Windows\Sni\SniNativeMethods.netcore.cs</Link>
760+
</Compile>
761+
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeWrapper.cs">
762+
<Link>Interop\Windows\Sni\SniNativeWrapper.cs</Link>
763+
</Compile>
755764
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\TransparentNetworkResolutionMode.cs">
756765
<Link>Interop\Windows\Sni\TransparentNetworkResolutionMode.cs</Link>
757766
</Compile>
@@ -788,8 +797,7 @@
788797
<CompileInclude="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlFileStream.Windows.cs">
789798
<Link>Microsoft\Data\SqlTypes\SqlFileStream.Windows.cs</Link>
790799
</Compile>
791-
792-
<CompileInclude="Interop\SNINativeMethodWrapper.Windows.cs" />
800+
793801
<CompileInclude="Microsoft\Data\SqlClient\LocalDBAPI.Common.cs" />
794802
<CompileInclude="Microsoft\Data\SqlClient\LocalDBAPI.Windows.cs" />
795803
<CompileInclude="Microsoft\Data\SqlClient\PacketHandle.Windows.cs" />
@@ -808,8 +816,7 @@
808816
<CompileInclude="$(CommonSourceRoot)Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Unix.cs">
809817
<Link>Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Unix.cs</Link>
810818
</Compile>
811-
812-
<CompileInclude="Interop\SNINativeMethodWrapper.Unix.cs" />
819+
813820
<CompileInclude="Microsoft\Data\Sql\SqlDataSourceEnumerator.Unix.cs" />
814821
<CompileInclude="Microsoft\Data\SqlClient\LocalDBAPI.Unix.cs" />
815822
<CompileInclude="Microsoft\Data\SqlClient\PacketHandle.Unix.cs" />

‎src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/LocalDBAPI.Windows.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
// See the LICENSE file in the project root for more information.
44

55
usingSystem;
6+
usingInterop.Windows.Kernel32;
67
usingMicrosoft.Data.SqlClient;
78
usingInterop.Windows.Sni;
89

910
namespaceMicrosoft.Data
1011
{
1112
internalstaticpartialclassLocalDBAPI
1213
{
13-
privatestaticIntPtrLoadProcAddress()=>SafeNativeMethods.GetProcAddress(UserInstanceDLLHandle,"LocalDBFormatMessage");
14+
privatestaticIntPtrLoadProcAddress()=>
15+
Kernel32.GetProcAddress(UserInstanceDLLHandle,"LocalDBFormatMessage");
1416

1517
privatestaticIntPtrUserInstanceDLLHandle
1618
{
@@ -22,15 +24,15 @@ private static IntPtr UserInstanceDLLHandle
2224
{
2325
if(s_userInstanceDLLHandle==IntPtr.Zero)
2426
{
25-
SNINativeMethodWrapper.SNIQueryInfo(QueryType.SNI_QUERY_LOCALDB_HMODULE,refs_userInstanceDLLHandle);
27+
SniNativeWrapper.SNIQueryInfo(QueryType.SNI_QUERY_LOCALDB_HMODULE,refs_userInstanceDLLHandle);
2628
if(s_userInstanceDLLHandle!=IntPtr.Zero)
2729
{
2830
SqlClientEventSource.Log.TryTraceEvent("LocalDBAPI.UserInstanceDLLHandle | LocalDB - handle obtained");
2931
}
3032
else
3133
{
32-
SNINativeMethodWrapper.SNIGetLastError(outSniErrorsniError);
33-
throwCreateLocalDBException(StringsHelper.GetString("LocalDB_FailedGetDLLHandle"),sniError.sniError);
34+
SniNativeWrapper.SNIGetLastError(outSniErrorsniError);
35+
throwCreateLocalDBException(errorMessage:StringsHelper.GetString("LocalDB_FailedGetDLLHandle"),sniError:sniError.sniError);
3436
}
3537
}
3638
}

‎src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private SNIErrorDetails GetSniErrorDetails()
7575
}
7676
else
7777
{
78-
SNINativeMethodWrapper.SNIGetLastError(outSniErrorsniError);
78+
SniNativeWrapper.SNIGetLastError(outSniErrorsniError);
7979
details.sniErrorNumber=sniError.sniError;
8080
details.errorMessage=sniError.errorMessage;
8181
details.nativeError=sniError.nativeError;

‎src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal override void AssignPendingDNSInfo(string userProtocol, string DNSCache
8484
if(string.IsNullOrEmpty(userProtocol))
8585
{
8686

87-
result=SNINativeMethodWrapper.SniGetProviderNumber(Handle,refproviderNumber);
87+
result=SniNativeWrapper.SniGetProviderNumber(Handle,refproviderNumber);
8888
Debug.Assert(result==TdsEnums.SNI_SUCCESS,"Unexpected failure state upon calling SniGetProviderNumber");
8989
_parser.isTcpProtocol=(providerNumber==Provider.TCP_PROV);
9090
}
@@ -96,10 +96,10 @@ internal override void AssignPendingDNSInfo(string userProtocol, string DNSCache
9696
// serverInfo.UserProtocol could be empty
9797
if(_parser.isTcpProtocol)
9898
{
99-
result=SNINativeMethodWrapper.SniGetConnectionPort(Handle,refportFromSNI);
99+
result=SniNativeWrapper.SniGetConnectionPort(Handle,refportFromSNI);
100100
Debug.Assert(result==TdsEnums.SNI_SUCCESS,"Unexpected failure state upon calling SniGetConnectionPort");
101101

102-
result=SNINativeMethodWrapper.SniGetConnectionIPString(Handle,refIPStringFromSNI);
102+
result=SniNativeWrapper.SniGetConnectionIPString(Handle,refIPStringFromSNI);
103103
Debug.Assert(result==TdsEnums.SNI_SUCCESS,"Unexpected failure state upon calling SniGetConnectionIPString");
104104

105105
pendingDNSInfo=newSQLDNSInfo(DNSCacheKey,null,null,portFromSNI.ToString());
@@ -166,13 +166,13 @@ internal override void CreatePhysicalSNIHandle(
166166
{
167167
// Native SNI requires the Unicode encoding and any other encoding like UTF8 breaks the code.
168168
byte[]srvSPN= Encoding.Unicode.GetBytes(serverSPN);
169-
Trace.Assert(srvSPN.Length<=SNINativeMethodWrapper.SniMaxComposedSpnLength,"Length of the provided SPN exceeded the buffer size.");
169+
Trace.Assert(srvSPN.Length<=SniNativeWrapper.SniMaxComposedSpnLength,"Length of the provided SPN exceeded the buffer size.");
170170
spnBuffer[0]=srvSPN;
171171
SqlClientEventSource.Log.TryTraceEvent("<{0}.{1}|SEC> Server SPN `{2}` from the connection string is used.",nameof(TdsParserStateObjectNative),nameof(CreatePhysicalSNIHandle),serverSPN);
172172
}
173173
else
174174
{
175-
spnBuffer[0]=newbyte[SNINativeMethodWrapper.SniMaxComposedSpnLength];
175+
spnBuffer[0]=newbyte[SniNativeWrapper.SniMaxComposedSpnLength];
176176
}
177177
}
178178

@@ -187,7 +187,7 @@ internal override void CreatePhysicalSNIHandle(
187187
protected overrideuint SNIPacketGetData(PacketHandlepacket,byte[]_inBuff,refuintdataSize)
188188
{
189189
Debug.Assert(packet.Type==PacketHandle.NativePointerType,"unexpected packet type when requiring NativePointer");
190-
returnSNINativeMethodWrapper.SNIPacketGetData(packet.NativePointer,_inBuff,refdataSize);
190+
returnSniNativeWrapper.SNIPacketGetData(packet.NativePointer,_inBuff,refdataSize);
191191
}
192192

193193
protected overridebool CheckPacket(PacketHandlepacket,TaskCompletionSource<object>source)
@@ -267,7 +267,7 @@ internal override PacketHandle ReadSyncOverAsync(int timeoutRemaining, out uint
267267
throwADP.ClosedConnectionError();
268268
}
269269
IntPtrreadPacketPtr=IntPtr.Zero;
270-
error=SNINativeMethodWrapper.SNIReadSyncOverAsync(handle,refreadPacketPtr,GetTimeoutRemaining());
270+
error=SniNativeWrapper.SNIReadSyncOverAsync(handle,refreadPacketPtr,GetTimeoutRemaining());
271271
returnPacketHandle.FromNativePointer(readPacketPtr);
272272
}
273273

@@ -284,20 +284,20 @@ internal override bool IsPacketEmpty(PacketHandle readPacket)
284284
internaloverridevoidReleasePacket(PacketHandlesyncReadPacket)
285285
{
286286
Debug.Assert(syncReadPacket.Type==PacketHandle.NativePointerType,"unexpected packet type when requiring NativePointer");
287-
SNINativeMethodWrapper.SNIPacketRelease(syncReadPacket.NativePointer);
287+
SniNativeWrapper.SNIPacketRelease(syncReadPacket.NativePointer);
288288
}
289289

290290
internaloverrideuintCheckConnection()
291291
{
292292
SNIHandlehandle=Handle;
293-
returnhandle==null?TdsEnums.SNI_SUCCESS:SNINativeMethodWrapper.SNICheckConnection(handle);
293+
returnhandle==null?TdsEnums.SNI_SUCCESS:SniNativeWrapper.SNICheckConnection(handle);
294294
}
295295

296296
internaloverridePacketHandleReadAsync(SessionHandlehandle,outuinterror)
297297
{
298298
Debug.Assert(handle.Type==SessionHandle.NativeHandleType,"unexpected handle type when requiring NativePointer");
299299
IntPtrreadPacketPtr=IntPtr.Zero;
300-
error=SNINativeMethodWrapper.SNIReadAsync(handle.NativeHandle,refreadPacketPtr);
300+
error=SniNativeWrapper.SNIReadAsync(handle.NativeHandle,refreadPacketPtr);
301301
returnPacketHandle.FromNativePointer(readPacketPtr);
302302
}
303303

@@ -313,7 +313,7 @@ internal override PacketHandle CreateAndSetAttentionPacket()
313313
internaloverrideuintWritePacket(PacketHandlepacket,boolsync)
314314
{
315315
Debug.Assert(packet.Type==PacketHandle.NativePacketType,"unexpected packet type when requiring NativePacket");
316-
returnSNINativeMethodWrapper.SNIWritePacket(Handle,packet.NativePacket,sync);
316+
returnSniNativeWrapper.SNIWritePacket(Handle,packet.NativePacket,sync);
317317
}
318318

319319
internaloverridePacketHandleAddPacketToPendingList(PacketHandlepacketToAdd)
@@ -346,7 +346,7 @@ internal override PacketHandle GetResetWritePacket(int dataSize)
346346
{
347347
if(_sniPacket!=null)
348348
{
349-
SNINativeMethodWrapper.SNIPacketReset(Handle,IoType.WRITE,_sniPacket,ConsumerNumber.SNI_Consumer_SNI);
349+
SniNativeWrapper.SNIPacketReset(Handle,IoType.WRITE,_sniPacket,ConsumerNumber.SNI_Consumer_SNI);
350350
}
351351
else
352352
{
@@ -375,17 +375,17 @@ internal override void ClearAllWritePackets()
375375
internaloverridevoidSetPacketData(PacketHandlepacket,byte[]buffer,intbytesUsed)
376376
{
377377
Debug.Assert(packet.Type==PacketHandle.NativePacketType,"unexpected packet type when requiring NativePacket");
378-
SNINativeMethodWrapper.SNIPacketSetData(packet.NativePacket,buffer,bytesUsed);
378+
SniNativeWrapper.SNIPacketSetData(packet.NativePacket,buffer,bytesUsed);
379379
}
380380

381381
internaloverrideuintSniGetConnectionId(refGuidclientConnectionId)
382-
=>SNINativeMethodWrapper.SniGetConnectionId(Handle,refclientConnectionId);
382+
=>SniNativeWrapper.SniGetConnectionId(Handle,refclientConnectionId);
383383

384384
internaloverrideuintDisableSsl()
385-
=>SNINativeMethodWrapper.SNIRemoveProvider(Handle,Provider.SSL_PROV);
385+
=>SniNativeWrapper.SNIRemoveProvider(Handle,Provider.SSL_PROV);
386386

387387
internaloverrideuintEnableMars(refuintinfo)
388-
=>SNINativeMethodWrapper.SNIAddProvider(Handle,Provider.SMUX_PROV,refinfo);
388+
=>SniNativeWrapper.SNIAddProvider(Handle,Provider.SMUX_PROV,refinfo);
389389

390390
internaloverrideuintEnableSsl(refuintinfo,booltlsFirst,stringserverCertificateFilename)
391391
{
@@ -395,15 +395,15 @@ internal override uint EnableSsl(ref uint info, bool tlsFirst, string serverCert
395395
authInfo.serverCertFileName=serverCertificateFilename;
396396

397397
// Add SSL (Encryption) SNI provider.
398-
returnSNINativeMethodWrapper.SNIAddProvider(Handle,Provider.SSL_PROV,refauthInfo);
398+
returnSniNativeWrapper.SNIAddProvider(Handle,Provider.SSL_PROV,refauthInfo);
399399
}
400400

401401
internaloverrideuintSetConnectionBufferSize(refuintunsignedPacketSize)
402-
=>SNINativeMethodWrapper.SNISetInfo(Handle,QueryType.SNI_QUERY_CONN_BUFSIZE,refunsignedPacketSize);
402+
=>SniNativeWrapper.SNISetInfo(Handle,QueryType.SNI_QUERY_CONN_BUFSIZE,refunsignedPacketSize);
403403

404404
internaloverrideuintWaitForSSLHandShakeToComplete(outintprotocolVersion)
405405
{
406-
uintreturnValue=SNINativeMethodWrapper.SNIWaitForSSLHandshakeToComplete(Handle,GetTimeoutRemaining(),outuintnativeProtocolVersion);
406+
uintreturnValue=SniNativeWrapper.SNIWaitForSSLHandshakeToComplete(Handle,GetTimeoutRemaining(),outuintnativeProtocolVersion);
407407
varnativeProtocol=(NativeProtocols)nativeProtocolVersion;
408408

409409
#pragma warning disableCA5398// Avoid hardcoded SslProtocols values
@@ -472,7 +472,7 @@ public SNIPacket Take(SNIHandle sniHandle)
472472
{
473473
// Success - reset the packet
474474
packet=_packets.Pop();
475-
SNINativeMethodWrapper.SNIPacketReset(sniHandle,IoType.WRITE,packet,ConsumerNumber.SNI_Consumer_SNI);
475+
SniNativeWrapper.SNIPacketReset(sniHandle,IoType.WRITE,packet,ConsumerNumber.SNI_Consumer_SNI);
476476
}
477477
else
478478
{

‎src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@
172172
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\IoType.cs">
173173
<Link>Interop\Windows\Sni\IoType.cs</Link>
174174
</Compile>
175+
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\ISniNativeMethods.cs">
176+
<Link>Interop\Windows\Sni\ISniNativeMethods.cs</Link>
177+
</Compile>
175178
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\Prefix.cs">
176179
<Link>Interop\Windows\Sni\Prefix.cs</Link>
177180
</Compile>
@@ -193,6 +196,21 @@
193196
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SniError.cs">
194197
<Link>Interop\Windows\Sni\SniError.cs</Link>
195198
</Compile>
199+
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethodsArm64.netfx.cs">
200+
<Link>Interop\Windows\Sni\SniNativeMethodsArm64.netfx.cs</Link>
201+
</Compile>
202+
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethodsNotSupported.netfx.cs">
203+
<Link>Interop\Windows\Sni\SniNativeMethodsNotSupported.netfx.cs</Link>
204+
</Compile>
205+
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethodsX64.netfx.cs">
206+
<Link>Interop\Windows\Sni\SniNativeMethodsX64.netfx.cs</Link>
207+
</Compile>
208+
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethodsX86.netfx.cs">
209+
<Link>Interop\Windows\Sni\SniNativeMethodsX86.netfx.cs</Link>
210+
</Compile>
211+
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeWrapper.cs">
212+
<Link>Interop\Windows\Sni\SniNativeWrapper.cs</Link>
213+
</Compile>
196214
<CompileInclude="$(CommonSourceRoot)\Interop\Windows\Sni\SqlDependencyProcessDispatcherStorage.netfx.cs">
197215
<Link>Interop\Windows\Sni\SqlDependencyProcessDispatcherStorage.netfx.cs</Link>
198216
</Compile>
@@ -808,10 +826,6 @@
808826
<CompileInclude="Microsoft\Data\Common\DbConnectionOptions.cs" />
809827
<CompileInclude="Microsoft\Data\Common\DbConnectionString.cs" />
810828
<CompileInclude="Microsoft\Data\Common\GreenMethods.cs" />
811-
<CompileInclude="Microsoft\Data\Interop\SNINativeManagedWrapperARM64.cs" />
812-
<CompileInclude="Microsoft\Data\Interop\SNINativeManagedWrapperX64.cs" />
813-
<CompileInclude="Microsoft\Data\Interop\SNINativeManagedWrapperX86.cs" />
814-
<CompileInclude="Microsoft\Data\Interop\SNINativeMethodWrapper.cs" />
815829
<CompileInclude="Microsoft\Data\SqlClient\assemblycache.cs" />
816830
<CompileInclude="Microsoft\Data\SqlClient\LocalDBAPI.cs" />
817831
<CompileInclude="Microsoft\Data\SqlClient\LocalDBConfig.cs" />
@@ -895,12 +909,12 @@
895909
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
896910
</PackageReference>
897911
<PackageReferenceInclude="Azure.Identity"Version="$(AzureIdentityVersion)" />
912+
<PackageReferenceInclude="Microsoft.Bcl.Cryptography"Version="$(MicrosoftBclCryptographyVersion)" />
898913
<PackageReferenceInclude="Microsoft.IdentityModel.Protocols.OpenIdConnect"Version="$(MicrosoftIdentityModelProtocolsOpenIdConnectVersion)" />
899914
<PackageReferenceInclude="Microsoft.IdentityModel.JsonWebTokens"Version="$(MicrosoftIdentityModelJsonWebTokensVersion)" />
900915
<PackageReferenceInclude="System.Buffers"Version="$(SystemBuffersVersion)" />
901-
<PackageReferenceInclude="System.Text.Json"Version="$(SystemTextJsonVersion)" />
902916
<PackageReferenceInclude="System.Security.Cryptography.Pkcs"Version="$(SystemSecurityCryptographyPkcsVersion)" />
903-
<PackageReferenceInclude="Microsoft.Bcl.Cryptography"Version="$(MicrosoftBclCryptographyVersion)" />
917+
<PackageReferenceInclude="System.Text.Json"Version="$(SystemTextJsonVersion)" />
904918
</ItemGroup>
905919
<ImportProject="$(CommonSourceRoot)tools\targets\GenerateResourceStringsSource.targets" />
906920
<ImportProject="$(NetFxSource)tools\targets\GenerateThisAssemblyCs.targets" />

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp