Skip to content

Commit b1b93a8

Browse files
authored
Cleanup | Preparation for OS-independent builds (dotnet#3844)
* Implement early infrastructure for OS-independent builds. Also clean up the netfx-only s_isWindowsNT variable - this was originally used to distinguish between Windows 9x and Windows NT! * SqlFileStream We only throw a PlatformNotSupportedException in the constructor; if this throws, there's no way execution can reach a property or method. * SqlColumnEncryptionCngProvider * SqlColumnEncryptionCspProvider * Manually inline ThrowOnNonWindowsPlatform This is necessary because when an application using SqlClient is being published, the IL trimmer doesn't see that the throw helper throws an exception, and thus doesn't eliminate the code paths which call Windows-specific APIs. As a result, the Windows-specific API paths aren't removed from executables published for a Linux platform. * Correct preprocessor directive indentation
1 parent f5c41ee commit b1b93a8

25 files changed

Lines changed: 68 additions & 317 deletions

src/Microsoft.Data.SqlClient/src/Interop/Windows/Kernel32/FileTypes.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
namespace Interop.Windows.Kernel32
86
{
97
internal class FileTypes
@@ -14,5 +12,3 @@ internal class FileTypes
1412
internal const int FILE_TYPE_PIPE = 0x0003;
1513
}
1614
}
17-
18-
#endif

src/Microsoft.Data.SqlClient/src/Interop/Windows/Kernel32/IoControlCodeAccess.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
using System;
86

97
namespace Interop.Windows.Kernel32
@@ -33,5 +31,3 @@ internal enum IoControlCodeAccess
3331
FILE_WRITE_DATA = 0x02
3432
}
3533
}
36-
37-
#endif

src/Microsoft.Data.SqlClient/src/Interop/Windows/Kernel32/IoControlTransferType.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
namespace Interop.Windows.Kernel32
86
{
97
/// <summary>
@@ -37,5 +35,3 @@ internal enum IoControlTransferType
3735
METHOD_NEITHER
3836
}
3937
}
40-
41-
#endif

src/Microsoft.Data.SqlClient/src/Interop/Windows/Kernel32/Kernel32.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
using System;
86
using System.Runtime.InteropServices;
97
using System.Text;
108
using Microsoft.Data.Common;
119
using Microsoft.Win32.SafeHandles;
1210

13-
#if !NETFRAMEWORK
11+
#if !NETFRAMEWORK && _WINDOWS
1412
using Interop.Windows.Handles;
1513
#endif
1614

@@ -21,7 +19,7 @@ internal static class Kernel32
2119
internal const ushort FILE_DEVICE_FILE_SYSTEM = 0x0009;
2220
internal const uint SEM_FAILCRITICALERRORS = 1;
2321

24-
#if !NETFRAMEWORK
22+
#if _WINDOWS && !NETFRAMEWORK
2523
internal const int LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
2624
internal const int LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800;
2725
#endif
@@ -56,7 +54,7 @@ internal static extern bool DeviceIoControl(
5654
out uint cbBytesReturned,
5755
IntPtr overlapped);
5856

59-
#if NET
57+
#if NET && _WINDOWS
6058
[DllImport(DllName, ExactSpelling = true, SetLastError = true)]
6159
public static extern bool FreeLibrary([In] IntPtr hModule);
6260
#endif
@@ -73,17 +71,13 @@ internal static extern int GetFullPathName(
7371
IntPtr lpFilePartOrNull);
7472
#endif
7573

76-
#if NET
74+
#if NET && _WINDOWS
7775
[DllImport(DllName, CharSet = CharSet.Ansi, BestFitMapping = false)]
7876
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
79-
#endif
8077

81-
#if NET
8278
[DllImport(DllName, CharSet = CharSet.Ansi, BestFitMapping = false)]
8379
public static extern IntPtr GetProcAddress(SafeLibraryHandle hModule, string lpProcName);
84-
#endif
8580

86-
#if NET
8781
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]
8882
public static extern SafeLibraryHandle LoadLibraryExW([In] string lpwLibFileName, [In] IntPtr hFile, [In] uint dwFlags);
8983
#endif
@@ -92,5 +86,3 @@ internal static extern int GetFullPathName(
9286
internal static extern bool SetThreadErrorMode(uint dwNewMode, out uint lpOldMode);
9387
}
9488
}
95-
96-
#endif

src/Microsoft.Data.SqlClient/src/Interop/Windows/NtDll/CreateDisposition.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
namespace Interop.Windows.NtDll
86
{
97
/// <summary>
@@ -56,5 +54,3 @@ internal enum CreateDisposition : uint
5654
FILE_OVERWRITE_IF = 5
5755
}
5856
}
59-
60-
#endif

src/Microsoft.Data.SqlClient/src/Interop/Windows/NtDll/CreateOptions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
using System;
86

97
namespace Interop.Windows.NtDll
@@ -198,5 +196,3 @@ internal enum CreateOptions : uint
198196
// FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x00800000
199197
}
200198
}
201-
202-
#endif

src/Microsoft.Data.SqlClient/src/Interop/Windows/NtDll/DesiredAccess.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
using System;
86

97
namespace Interop.Windows.NtDll
@@ -190,5 +188,3 @@ internal enum DesiredAccess : uint
190188
FILE_GENERIC_EXECUTE = 0x20000000 // GENERIC_EXECUTE
191189
}
192190
}
193-
194-
#endif

src/Microsoft.Data.SqlClient/src/Interop/Windows/NtDll/FileFullEaInformation.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
using System.Runtime.InteropServices;
86

97
namespace Interop.Windows.NtDll
@@ -37,5 +35,3 @@ internal struct FileFullEaInformation
3735

3836
}
3937
}
40-
41-
#endif

src/Microsoft.Data.SqlClient/src/Interop/Windows/NtDll/ImpersonationLevel.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
namespace Interop.Windows.NtDll
86
{
97
/// <summary>
@@ -41,5 +39,3 @@ internal enum ImpersonationLevel
4139
SecurityDelegation = 3,
4240
}
4341
}
44-
45-
#endif

src/Microsoft.Data.SqlClient/src/Interop/Windows/NtDll/IoStatusBlock.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if _WINDOWS
6-
75
using System;
86
using System.Runtime.InteropServices;
97

@@ -44,5 +42,3 @@ public struct IoStatus
4442
}
4543
}
4644
}
47-
48-
#endif

0 commit comments

Comments
 (0)