summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2019-02-13 13:43:13 -0500
committerGitHub <noreply@github.com>2019-02-13 13:43:13 -0500
commit78cbd968cabc2bd6c84bfe6a0a240658e564a6d5 (patch)
tree17cc1c5224af1cf06b65069a34ea7b175bb2d625 /src/System.Private.CoreLib
parentb8d7a8de00bd13c958d501ada0695af52f6761af (diff)
downloadcoreclr-78cbd968cabc2bd6c84bfe6a0a240658e564a6d5.tar.gz
coreclr-78cbd968cabc2bd6c84bfe6a0a240658e564a6d5.tar.bz2
coreclr-78cbd968cabc2bd6c84bfe6a0a240658e564a6d5.zip
Replace Win32Native.cs with Interop files (#22540)
* Replace Win32Native.cs with Interop files - Replace Win32Native usage with existing Interop.* calls where they already existed - Moved Win32Native.* to their own files otherwise, and changed call sites - Left a stub Win32Native in place to handle some emitted IL from the runtime. The current infrastructure doesn't support targeting nested types, like Interop.Kernel32, and fixing that would be more involved. * Remove Win32Native.cs Replace emitted calls with ones to Marshal. * Fix incorrectly changed field * Fix Kernel32 -> Ole32
Diffstat (limited to 'src/System.Private.CoreLib')
-rw-r--r--src/System.Private.CoreLib/System.Private.CoreLib.csproj10
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs14
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs15
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs19
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetVersionExW.cs16
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LocalAlloc.cs24
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OSVERSIONINFOEX.cs27
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryUnbiasedInterruptTime.cs14
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerSetConditionMask.cs14
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerifyVersionExW.cs20
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoTaskMemAlloc.cs21
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringByteLen.cs15
-rw-r--r--src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems15
-rw-r--r--src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs2
-rw-r--r--src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs4
-rw-r--r--src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/StubEnvironment.cs4
-rw-r--r--src/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs1
-rw-r--r--src/System.Private.CoreLib/src/Internal/Console.cs16
-rw-r--r--src/System.Private.CoreLib/src/Interop/Unix/Interop.Libraries.cs1
-rw-r--r--src/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs14
-rw-r--r--src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs186
-rw-r--r--src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs4
-rw-r--r--src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs16
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs23
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs5
-rw-r--r--src/System.Private.CoreLib/src/System/StubHelpers.cs28
-rw-r--r--src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs3
-rw-r--r--src/System.Private.CoreLib/src/System/Threading/Timer.CoreCLR.cs2
-rw-r--r--src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs22
29 files changed, 260 insertions, 295 deletions
diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj
index e785601d35..df251e5a71 100644
--- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj
+++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj
@@ -118,7 +118,6 @@
<Compile Include="$(BclSourcesRoot)\Internal\Console.cs" />
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\Augments\RuntimeThread.cs" />
<Compile Include="$(BclSourcesRoot)\Microsoft\Win32\UnsafeNativeMethods.cs" />
- <Compile Include="$(BclSourcesRoot)\Microsoft\Win32\Win32Native.cs" />
<Compile Include="$(BclSourcesRoot)\System\__Canon.cs" />
<Compile Include="$(BclSourcesRoot)\System\Activator.cs" />
<Compile Include="$(BclSourcesRoot)\System\AppContext.CoreCLR.cs" />
@@ -276,6 +275,15 @@
<Compile Include="$(BclSourcesRoot)\System\ValueType.cs" />
<Compile Include="$(BclSourcesRoot)\System\WeakReference.cs" />
<Compile Include="$(BclSourcesRoot)\System\WeakReferenceOfT.cs" />
+ <Compile Include="shared\Interop\Windows\Kernel32\Interop.GetCurrentProcessId.cs" />
+ <Compile Include="shared\Interop\Windows\Kernel32\Interop.GetCurrentThreadId.cs" />
+ <Compile Include="shared\Interop\Windows\Kernel32\Interop.GetStdHandle.cs" />
+ <Compile Include="shared\Interop\Windows\Kernel32\Interop.LocalAlloc.cs" />
+ <Compile Include="shared\Interop\Windows\Kernel32\Interop.QueryUnbiasedInterruptTime.cs" />
+ <Compile Include="shared\Interop\Windows\Kernel32\Interop.VerifyVersionExW.cs" />
+ <Compile Include="shared\Interop\Windows\Kernel32\Interop.VerSetConditionMask.cs" />
+ <Compile Include="shared\Interop\Windows\Ole32\Interop.CoTaskMemAlloc.cs" />
+ <Compile Include="shared\Interop\Windows\OleAut32\Interop.SysAllocStringByteLen.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\XplatEventLogger.cs" Condition="'$(FeatureXplatEventSource)' == 'true'" />
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs
new file mode 100644
index 0000000000..a042bfeccf
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class Kernel32
+ {
+ [DllImport(Libraries.Kernel32)]
+ internal extern static uint GetCurrentProcessId();
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs
new file mode 100644
index 0000000000..d456db7522
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Kernel32
+ {
+ [DllImport(Libraries.Kernel32, ExactSpelling = true)]
+ public static extern int GetCurrentThreadId();
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs
new file mode 100644
index 0000000000..9637ca9716
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs
@@ -0,0 +1,19 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class Kernel32
+ {
+ internal const int STD_INPUT_HANDLE = -10;
+ internal const int STD_OUTPUT_HANDLE = -11;
+ internal const int STD_ERROR_HANDLE = -12;
+
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
+ internal static extern IntPtr GetStdHandle(int nStdHandle);
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetVersionExW.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetVersionExW.cs
index 11c9143542..13a997a344 100644
--- a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetVersionExW.cs
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetVersionExW.cs
@@ -10,21 +10,5 @@ internal partial class Interop
{
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool GetVersionExW(ref OSVERSIONINFOEX osvi);
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal unsafe struct OSVERSIONINFOEX
- {
- public int dwOSVersionInfoSize;
- public int dwMajorVersion;
- public int dwMinorVersion;
- public int dwBuildNumber;
- public int dwPlatformId;
- public fixed char szCSDVersion[128];
- public ushort wServicePackMajor;
- public ushort wServicePackMinor;
- public ushort wSuiteMask;
- public byte wProductType;
- public byte wReserved;
- }
}
}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LocalAlloc.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LocalAlloc.cs
new file mode 100644
index 0000000000..9c74adbe01
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.LocalAlloc.cs
@@ -0,0 +1,24 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class Kernel32
+ {
+ internal const uint LMEM_FIXED = 0x0000;
+ internal const uint LMEM_MOVEABLE = 0x0002;
+
+ [DllImport(Libraries.Kernel32)]
+ internal static extern IntPtr LocalAlloc(uint uFlags, UIntPtr uBytes);
+
+ [DllImport(Libraries.Kernel32)]
+ internal static extern IntPtr LocalReAlloc(IntPtr hMem, IntPtr uBytes, uint uFlags);
+
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
+ internal static extern IntPtr LocalFree(IntPtr hMem);
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OSVERSIONINFOEX.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OSVERSIONINFOEX.cs
new file mode 100644
index 0000000000..1bfe00c574
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.OSVERSIONINFOEX.cs
@@ -0,0 +1,27 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class Kernel32
+ {
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+ internal unsafe struct OSVERSIONINFOEX
+ {
+ public int dwOSVersionInfoSize;
+ public int dwMajorVersion;
+ public int dwMinorVersion;
+ public int dwBuildNumber;
+ public int dwPlatformId;
+ public fixed char szCSDVersion[128];
+ public ushort wServicePackMajor;
+ public ushort wServicePackMinor;
+ public ushort wSuiteMask;
+ public byte wProductType;
+ public byte wReserved;
+ }
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryUnbiasedInterruptTime.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryUnbiasedInterruptTime.cs
new file mode 100644
index 0000000000..87ca7fd1d4
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.QueryUnbiasedInterruptTime.cs
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class Kernel32
+ {
+ [DllImport(Libraries.Kernel32, SetLastError = true)]
+ internal static extern bool QueryUnbiasedInterruptTime(out ulong UnbiasedTime);
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerSetConditionMask.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerSetConditionMask.cs
new file mode 100644
index 0000000000..385e48a439
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerSetConditionMask.cs
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class Kernel32
+ {
+ [DllImport(Libraries.Kernel32)]
+ internal static extern ulong VerSetConditionMask(ulong ConditionMask, uint TypeMask, byte Condition);
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerifyVersionExW.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerifyVersionExW.cs
new file mode 100644
index 0000000000..5c2471cf49
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.VerifyVersionExW.cs
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class Kernel32
+ {
+ internal const byte VER_GREATER_EQUAL = 0x3;
+ internal const uint VER_MAJORVERSION = 0x0000002;
+ internal const uint VER_MINORVERSION = 0x0000001;
+ internal const uint VER_SERVICEPACKMAJOR = 0x0000020;
+ internal const uint VER_SERVICEPACKMINOR = 0x0000010;
+
+ [DllImport(Libraries.Kernel32)]
+ internal static extern bool VerifyVersionInfoW(ref OSVERSIONINFOEX lpVersionInfo, uint dwTypeMask, ulong dwlConditionMask);
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoTaskMemAlloc.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoTaskMemAlloc.cs
new file mode 100644
index 0000000000..9119ee774e
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Ole32/Interop.CoTaskMemAlloc.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class Ole32
+ {
+ [DllImport(Libraries.Ole32)]
+ internal static extern IntPtr CoTaskMemAlloc(UIntPtr cb);
+
+ [DllImport(Libraries.Ole32)]
+ internal static extern IntPtr CoTaskMemRealloc(IntPtr pv, UIntPtr cb);
+
+ [DllImport(Libraries.Ole32)]
+ internal static extern void CoTaskMemFree(IntPtr ptr);
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringByteLen.cs b/src/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringByteLen.cs
new file mode 100644
index 0000000000..52496893a0
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/OleAut32/Interop.SysAllocStringByteLen.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class OleAut32
+ {
+ [DllImport(Libraries.OleAut32)]
+ internal static extern IntPtr SysAllocStringByteLen(byte[] str, uint len);
+ }
+}
diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
index 21dc2f92e4..79be842e60 100644
--- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
+++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
@@ -991,15 +991,11 @@
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.VirtualFree.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.VirtualQuery.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WideCharToMultiByte.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_NativeOverlapped.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Normaliz\Interop.Idna.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Normaliz\Interop.Normalization.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\NtDll\Interop.NtQuerySystemInformation.cs" Condition="'$(EnableWinRT)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Ole32\Interop.CoCreateGuid.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysAllocStringLen.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysFreeString.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysStringLen.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Secur32\Interop.GetUserNameExW.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Shell32\Interop.SHGetKnownFolderPath.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Internal\IO\File.Windows.cs" />
@@ -1029,7 +1025,6 @@
<Compile Include="$(MSBuildThisFileDirectory)System\PasteArguments.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\MemoryFailPoint.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\Marshal.Windows.cs" Condition="'$(TargetsCoreRT)' != 'true'" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Security\SafeBSTRHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Security\SecureString.Windows.cs" />
</ItemGroup>
<ItemGroup Condition="'$(FeatureAsyncCausalityTracer)' != 'true'">
@@ -1076,19 +1071,25 @@
</ItemGroup>
<ItemGroup Condition="$(TargetsWindows) or '$(FeaturePal)'=='true'">
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeWaitHandle.Windows.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Interop.Errors.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysAllocStringLen.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysFreeString.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysStringLen.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CloseHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.Constants.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Interop.Errors.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.EventWaitHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetEnvironmentVariable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.GetEnvironmentStrings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FreeEnvironmentStrings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FormatMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.Mutex.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.OSVERSIONINFOEX.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.Semaphore.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.SetEnvironmentVariable.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.EventWaitHandle.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Variables.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\Win32Marshal.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Security\SafeBSTRHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Mutex.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\Semaphore.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\EventWaitHandle.Windows.cs" />
diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs
index 1b82e6f6b3..c886758b2b 100644
--- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs
+++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventProvider.cs
@@ -494,7 +494,7 @@ namespace System.Diagnostics.Tracing
var providerInfos = (UnsafeNativeMethods.ManifestEtw.TRACE_GUID_INFO*)buffer;
var providerInstance = (UnsafeNativeMethods.ManifestEtw.TRACE_PROVIDER_INSTANCE_INFO*)&providerInfos[1];
- int processId = unchecked((int)Win32Native.GetCurrentProcessId());
+ int processId = unchecked((int)Interop.Kernel32.GetCurrentProcessId());
// iterate over the instances of the EventProvider in all processes
for (int i = 0; i < providerInfos->InstanceCount; i++)
{
diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
index d653e95995..e4247fef5b 100644
--- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
+++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
@@ -455,7 +455,7 @@ namespace System.Diagnostics.Tracing
{
get
{
- int threadID = Win32Native.GetCurrentThreadId();
+ int threadID = Interop.Kernel32.GetCurrentThreadId();
// Managed thread IDs are more aggressively re-used than native thread IDs,
// so we'll use the latter...
@@ -2742,7 +2742,7 @@ namespace System.Diagnostics.Tracing
// for non-BCL EventSource we must assert SecurityPermission
new SecurityPermission(PermissionState.Unrestricted).Assert();
#endif
- s_currentPid = Win32Native.GetCurrentProcessId();
+ s_currentPid = Interop.Kernel32.GetCurrentProcessId();
}
}
diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/StubEnvironment.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/StubEnvironment.cs
index 9773491b5d..981a100e2f 100644
--- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/StubEnvironment.cs
+++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/StubEnvironment.cs
@@ -325,13 +325,13 @@ namespace Microsoft.Reflection
}
#if ES_BUILD_STANDALONE
-namespace Microsoft.Win32
+internal static partial class Interop
{
using System.Runtime.InteropServices;
using System.Security;
[SuppressUnmanagedCodeSecurityAttribute()]
- internal static class Win32Native
+ internal static partial class Kernel32
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetCurrentThreadId();
diff --git a/src/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs b/src/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs
index 212eb9dc31..c40ab94dc3 100644
--- a/src/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs
+++ b/src/System.Private.CoreLib/shared/System/Threading/Mutex.Windows.cs
@@ -78,7 +78,6 @@ namespace System.Threading
if (Interop.Errors.ERROR_INVALID_HANDLE == errorCode)
return OpenExistingResult.NameInvalid;
- // this is for passed through Win32Native Errors
throw Win32Marshal.GetExceptionForWin32Error(errorCode, name);
}
diff --git a/src/System.Private.CoreLib/src/Internal/Console.cs b/src/System.Private.CoreLib/src/Internal/Console.cs
index a2a323fa13..ecb751f8b3 100644
--- a/src/System.Private.CoreLib/src/Internal/Console.cs
+++ b/src/System.Private.CoreLib/src/Internal/Console.cs
@@ -4,8 +4,6 @@
using System;
using System.Text;
-using System.Security;
-using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
namespace Internal
@@ -18,27 +16,21 @@ namespace Internal
public static class Console
{
private static readonly SafeFileHandle _outputHandle =
- new SafeFileHandle(Win32Native.GetStdHandle(Win32Native.STD_OUTPUT_HANDLE), false);
+ new SafeFileHandle(Interop.Kernel32.GetStdHandle(Interop.Kernel32.STD_OUTPUT_HANDLE), ownsHandle: false);
public static unsafe void Write(string s)
{
byte[] bytes = Encoding.UTF8.GetBytes(s);
-
fixed (byte* pBytes = bytes)
{
- int bytesWritten;
- Win32Native.WriteFile(_outputHandle, pBytes, bytes.Length, out bytesWritten, IntPtr.Zero);
+ Interop.Kernel32.WriteFile(_outputHandle, pBytes, bytes.Length, out _, IntPtr.Zero);
}
}
- public static void WriteLine(string s)
- {
+ public static void WriteLine(string s) =>
Write(s + Environment.NewLine);
- }
- public static void WriteLine()
- {
+ public static void WriteLine() =>
Write(Environment.NewLine);
- }
}
}
diff --git a/src/System.Private.CoreLib/src/Interop/Unix/Interop.Libraries.cs b/src/System.Private.CoreLib/src/Interop/Unix/Interop.Libraries.cs
index 31df8c75de..da7cbf29d2 100644
--- a/src/System.Private.CoreLib/src/Interop/Unix/Interop.Libraries.cs
+++ b/src/System.Private.CoreLib/src/Interop/Unix/Interop.Libraries.cs
@@ -10,5 +10,6 @@ internal static partial class Interop
internal const string User32 = "libcoreclr";
internal const string Ole32 = "libcoreclr";
internal const string OleAut32 = "libcoreclr";
+ internal const string Advapi32 = "libcoreclr";
}
}
diff --git a/src/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs b/src/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs
index 4ddf56663e..8e0a68248b 100644
--- a/src/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs
+++ b/src/System.Private.CoreLib/src/Microsoft/Win32/UnsafeNativeMethods.cs
@@ -56,7 +56,7 @@ namespace Microsoft.Win32
//
// Registration APIs
//
- [DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventRegister", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+ [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, EntryPoint = "EventRegister", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern unsafe uint EventRegister(
[In] ref Guid providerId,
[In]EtwEnableCallback enableCallback,
@@ -65,10 +65,10 @@ namespace Microsoft.Win32
);
//
- [DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventUnregister", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+ [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, EntryPoint = "EventUnregister", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern uint EventUnregister([In] long registrationHandle);
- [DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventWriteString", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+ [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, EntryPoint = "EventWriteString", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern int EventWriteString(
[In] long registrationHandle,
[In] byte level,
@@ -106,7 +106,7 @@ namespace Microsoft.Win32
return HResult;
}
- [DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventWriteTransfer", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+ [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, EntryPoint = "EventWriteTransfer", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
private static extern int EventWriteTransfer(
[In] long registrationHandle,
[In] ref EventDescriptor eventDescriptor,
@@ -125,7 +125,7 @@ namespace Microsoft.Win32
EVENT_ACTIVITY_CTRL_CREATE_SET_ID = 5
};
- [DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventActivityIdControl", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+ [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, EntryPoint = "EventActivityIdControl", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern int EventActivityIdControl([In] ActivityControl ControlCode, [In][Out] ref Guid ActivityId);
internal enum EVENT_INFO_CLASS
@@ -135,7 +135,7 @@ namespace Microsoft.Win32
SetTraits,
}
- [DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventSetInformation", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+ [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, EntryPoint = "EventSetInformation", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern int EventSetInformation(
[In] long registrationHandle,
[In] EVENT_INFO_CLASS informationClass,
@@ -178,7 +178,7 @@ namespace Microsoft.Win32
public long MatchAllKeyword;
};
- [DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EnumerateTraceGuidsEx", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
+ [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, EntryPoint = "EnumerateTraceGuidsEx", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern int EnumerateTraceGuidsEx(
TRACE_QUERY_INFO_CLASS TraceQueryInfoClass,
void* InBuffer,
diff --git a/src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs b/src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs
deleted file mode 100644
index 9d2cc9a4e6..0000000000
--- a/src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs
+++ /dev/null
@@ -1,186 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** Purpose: CoreCLR wrapper for Win32, either the native
-** operations or the Unix PAL implementation of them.
-**
-**
-===========================================================*/
-/*
- * Notes to PInvoke users: Getting the syntax exactly correct is crucial, and
- * more than a little confusing. Here's some guidelines.
- *
- * For handles, you should use a SafeHandle subclass specific to your handle
- * type. For files, we have the following set of interesting definitions:
- *
- * [DllImport(Interop.Libraries.Kernel32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- * private static extern SafeFileHandle CreateFile(...);
- *
- * [DllImport(Interop.Libraries.Kernel32, SetLastError=true)]
- * internal static extern unsafe int ReadFile(SafeFileHandle handle, ...);
- *
- * [DllImport(Interop.Libraries.Kernel32, SetLastError=true)]
- * internal static extern bool CloseHandle(IntPtr handle);
- *
- * P/Invoke will create the SafeFileHandle instance for you and assign the
- * return value from CreateFile into the handle atomically. When we call
- * ReadFile, P/Invoke will increment a ref count, make the call, then decrement
- * it (preventing handle recycling vulnerabilities). Then SafeFileHandle's
- * ReleaseHandle method will call CloseHandle, passing in the handle field
- * as an IntPtr.
- *
- * If for some reason you cannot use a SafeHandle subclass for your handles,
- * then use IntPtr as the handle type (or possibly HandleRef - understand when
- * to use GC.KeepAlive). If your code will run in SQL Server (or any other
- * long-running process that can't be recycled easily), use a constrained
- * execution region to prevent thread aborts while allocating your
- * handle, and consider making your handle wrapper subclass
- * CriticalFinalizerObject to ensure you can free the handle. As you can
- * probably guess, SafeHandle will save you a lot of headaches if your code
- * needs to be robust to thread aborts and OOM.
- *
- *
- * If you have a method that takes a native struct, you have two options for
- * declaring that struct. You can make it a value type ('struct' in CSharp),
- * or a reference type ('class'). This choice doesn't seem very interesting,
- * but your function prototype must use different syntax depending on your
- * choice. For example, if your native method is prototyped as such:
- *
- * bool GetVersionEx(OSVERSIONINFO &amp; lposvi);
- *
- *
- * you must use EITHER THIS OR THE NEXT syntax:
- *
- * [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
- * internal struct OSVERSIONINFO { ... }
- *
- * [DllImport(Interop.Libraries.Kernel32, CharSet=CharSet.Auto)]
- * internal static extern bool GetVersionEx(ref OSVERSIONINFO lposvi);
- *
- * OR:
- *
- * [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
- * internal class OSVERSIONINFO { ... }
- *
- * [DllImport(Interop.Libraries.Kernel32, CharSet=CharSet.Auto)]
- * internal static extern bool GetVersionEx([In, Out] OSVERSIONINFO lposvi);
- *
- * Note that classes require being marked as [In, Out] while value types must
- * be passed as ref parameters.
- *
- * Also note the CharSet.Auto on GetVersionEx - while it does not take a String
- * as a parameter, the OSVERSIONINFO contains an embedded array of TCHARs, so
- * the size of the struct varies on different platforms, and there's a
- * GetVersionExA &amp; a GetVersionExW. Also, the OSVERSIONINFO struct has a sizeof
- * field so the OS can ensure you've passed in the correctly-sized copy of an
- * OSVERSIONINFO. You must explicitly set this using Marshal.SizeOf(Object);
- *
- * For security reasons, if you're making a P/Invoke method to a Win32 method
- * that takes an ANSI String and that String is the name of some resource you've
- * done a security check on (such as a file name), you want to disable best fit
- * mapping in WideCharToMultiByte. Do this by setting BestFitMapping=false
- * in your DllImportAttribute.
- */
-
-namespace Microsoft.Win32
-{
- using System;
- using System.Runtime.InteropServices;
- using Microsoft.Win32.SafeHandles;
-
- /**
- * Win32 encapsulation for System.Private.CoreLib.
- */
- internal static class Win32Native
- {
- internal const int LMEM_FIXED = 0x0000;
- internal const int LMEM_ZEROINIT = 0x0040;
- internal const int LPTR = (LMEM_FIXED | LMEM_ZEROINIT);
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal unsafe struct OSVERSIONINFOEX
- {
- internal int dwOSVersionInfoSize;
- internal int dwMajorVersion;
- internal int dwMinorVersion;
- internal int dwBuildNumber;
- internal int dwPlatformId;
- internal fixed char szCSDVersion[128];
- internal ushort wServicePackMajor;
- internal ushort wServicePackMinor;
- internal short wSuiteMask;
- internal byte wProductType;
- internal byte wReserved;
- }
-
- internal const string ADVAPI32 = "advapi32.dll";
-
- [DllImport(Interop.Libraries.Kernel32, EntryPoint = "LocalAlloc")]
- internal static extern IntPtr LocalAlloc_NoSafeHandle(int uFlags, UIntPtr sizetdwBytes);
-
- [DllImport(Interop.Libraries.Kernel32, SetLastError = true)]
- internal static extern IntPtr LocalFree(IntPtr handle);
-
- [DllImport(Interop.Libraries.Kernel32)]
- internal static extern IntPtr LocalReAlloc(IntPtr handle, IntPtr sizetcbBytes, int uFlags);
-
- [DllImport(Interop.Libraries.OleAut32, CharSet = CharSet.Unicode)]
- internal static extern IntPtr SysAllocStringLen(string src, int len); // BSTR
-
- [DllImport(Interop.Libraries.OleAut32)]
- internal static extern uint SysStringLen(IntPtr bstr);
-
- [DllImport(Interop.Libraries.OleAut32)]
- internal static extern void SysFreeString(IntPtr bstr);
-
- [DllImport(Interop.Libraries.OleAut32)]
- internal static extern IntPtr SysAllocStringByteLen(byte[] str, uint len); // BSTR
-
- [DllImport(Interop.Libraries.Kernel32, SetLastError = true)]
- internal static extern unsafe int WriteFile(SafeFileHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero);
-
- internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1); // WinBase.h
-
- // Note, these are #defines used to extract handles, and are NOT handles.
- internal const int STD_INPUT_HANDLE = -10;
- internal const int STD_OUTPUT_HANDLE = -11;
- internal const int STD_ERROR_HANDLE = -12;
-
- [DllImport(Interop.Libraries.Kernel32, SetLastError = true)]
- internal static extern IntPtr GetStdHandle(int nStdHandle); // param is NOT a handle, but it returns one!
-
- [DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Auto)]
- internal static extern int GetCurrentThreadId();
-
- [DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Auto)]
- internal static extern uint GetCurrentProcessId();
-
- [DllImport(Interop.Libraries.Ole32)]
- internal static extern IntPtr CoTaskMemAlloc(UIntPtr cb);
-
- [DllImport(Interop.Libraries.Ole32)]
- internal static extern void CoTaskMemFree(IntPtr ptr);
-
- [DllImport(Interop.Libraries.Ole32)]
- internal static extern IntPtr CoTaskMemRealloc(IntPtr pv, UIntPtr cb);
-
- [DllImport(Interop.Libraries.Kernel32, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool QueryUnbiasedInterruptTime(out ulong UnbiasedTime);
-
- internal const byte VER_GREATER_EQUAL = 0x3;
- internal const uint VER_MAJORVERSION = 0x0000002;
- internal const uint VER_MINORVERSION = 0x0000001;
- internal const uint VER_SERVICEPACKMAJOR = 0x0000020;
- internal const uint VER_SERVICEPACKMINOR = 0x0000010;
- [DllImport("kernel32.dll")]
- internal static extern bool VerifyVersionInfoW(ref OSVERSIONINFOEX lpVersionInfo, uint dwTypeMask, ulong dwlConditionMask);
- [DllImport("kernel32.dll")]
- internal static extern ulong VerSetConditionMask(ulong dwlConditionMask, uint dwTypeBitMask, byte dwConditionMask);
- }
-}
diff --git a/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs b/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs
index ba469f1872..21a9b925a6 100644
--- a/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs
+++ b/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs
@@ -211,7 +211,7 @@ namespace System.Diagnostics.Tracing
{
// If set, bail out early if the specified process does not match the current process.
int processID = Convert.ToInt32(strProcessID);
- if (processID != Win32Native.GetCurrentProcessId())
+ if (processID != Interop.Kernel32.GetCurrentProcessId())
{
return null;
}
@@ -293,7 +293,7 @@ namespace System.Diagnostics.Tracing
private static string BuildTraceFileName()
{
- return GetAppName() + "." + Win32Native.GetCurrentProcessId().ToString() + NetPerfFileExtension;
+ return GetAppName() + "." + Interop.Kernel32.GetCurrentProcessId().ToString() + NetPerfFileExtension;
}
private static string GetAppName()
diff --git a/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
index 8d92a7e4a8..d5fea8a751 100644
--- a/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
@@ -116,24 +116,24 @@ namespace System
private static bool GetIsWindows8OrAbove()
{
- ulong conditionMask = Win32Native.VerSetConditionMask(0, Win32Native.VER_MAJORVERSION, Win32Native.VER_GREATER_EQUAL);
- conditionMask = Win32Native.VerSetConditionMask(conditionMask, Win32Native.VER_MINORVERSION, Win32Native.VER_GREATER_EQUAL);
- conditionMask = Win32Native.VerSetConditionMask(conditionMask, Win32Native.VER_SERVICEPACKMAJOR, Win32Native.VER_GREATER_EQUAL);
- conditionMask = Win32Native.VerSetConditionMask(conditionMask, Win32Native.VER_SERVICEPACKMINOR, Win32Native.VER_GREATER_EQUAL);
+ ulong conditionMask = Interop.Kernel32.VerSetConditionMask(0, Interop.Kernel32.VER_MAJORVERSION, Interop.Kernel32.VER_GREATER_EQUAL);
+ conditionMask = Interop.Kernel32.VerSetConditionMask(conditionMask, Interop.Kernel32.VER_MINORVERSION, Interop.Kernel32.VER_GREATER_EQUAL);
+ conditionMask = Interop.Kernel32.VerSetConditionMask(conditionMask, Interop.Kernel32.VER_SERVICEPACKMAJOR, Interop.Kernel32.VER_GREATER_EQUAL);
+ conditionMask = Interop.Kernel32.VerSetConditionMask(conditionMask, Interop.Kernel32.VER_SERVICEPACKMINOR, Interop.Kernel32.VER_GREATER_EQUAL);
// Windows 8 version is 6.2
- var version = new Win32Native.OSVERSIONINFOEX();
+ Interop.Kernel32.OSVERSIONINFOEX version = default;
unsafe
{
- version.dwOSVersionInfoSize = sizeof(Win32Native.OSVERSIONINFOEX);
+ version.dwOSVersionInfoSize = sizeof(Interop.Kernel32.OSVERSIONINFOEX);
}
version.dwMajorVersion = 6;
version.dwMinorVersion = 2;
version.wServicePackMajor = 0;
version.wServicePackMinor = 0;
- return Win32Native.VerifyVersionInfoW(ref version,
- Win32Native.VER_MAJORVERSION | Win32Native.VER_MINORVERSION | Win32Native.VER_SERVICEPACKMAJOR | Win32Native.VER_SERVICEPACKMINOR,
+ return Interop.Kernel32.VerifyVersionInfoW(ref version,
+ Interop.Kernel32.VER_MAJORVERSION | Interop.Kernel32.VER_MINORVERSION | Interop.Kernel32.VER_SERVICEPACKMAJOR | Interop.Kernel32.VER_SERVICEPACKMINOR,
conditionMask);
}
}
diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
index a3c62f95e6..28c4ec223a 100644
--- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
@@ -30,9 +30,6 @@ namespace System.Runtime.InteropServices
internal static Guid IID_IUnknown = new Guid(0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
#endif //FEATURE_COMINTEROP
- private const int LMEM_FIXED = 0;
- private const int LMEM_MOVEABLE = 2;
-
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int SizeOfHelper(Type t, bool throwIfNotMarshalable);
@@ -272,7 +269,7 @@ namespace System.Runtime.InteropServices
numBytes = new UIntPtr(unchecked((uint)cb.ToInt32()));
#endif
- IntPtr pNewMem = Win32Native.LocalAlloc_NoSafeHandle(LMEM_FIXED, unchecked(numBytes));
+ IntPtr pNewMem = Interop.Kernel32.LocalAlloc(Interop.Kernel32.LMEM_FIXED, unchecked(numBytes));
if (pNewMem == IntPtr.Zero)
{
throw new OutOfMemoryException();
@@ -285,7 +282,7 @@ namespace System.Runtime.InteropServices
{
if (!IsWin32Atom(hglobal))
{
- if (IntPtr.Zero != Win32Native.LocalFree(hglobal))
+ if (IntPtr.Zero != Interop.Kernel32.LocalFree(hglobal))
{
ThrowExceptionForHR(GetHRForLastWin32Error());
}
@@ -294,7 +291,7 @@ namespace System.Runtime.InteropServices
public static IntPtr ReAllocHGlobal(IntPtr pv, IntPtr cb)
{
- IntPtr pNewMem = Win32Native.LocalReAlloc(pv, cb, LMEM_MOVEABLE);
+ IntPtr pNewMem = Interop.Kernel32.LocalReAlloc(pv, cb, Interop.Kernel32.LMEM_MOVEABLE);
if (pNewMem == IntPtr.Zero)
{
throw new OutOfMemoryException();
@@ -425,7 +422,7 @@ namespace System.Runtime.InteropServices
public static IntPtr AllocCoTaskMem(int cb)
{
- IntPtr pNewMem = Win32Native.CoTaskMemAlloc(new UIntPtr((uint)cb));
+ IntPtr pNewMem = Interop.Ole32.CoTaskMemAlloc(new UIntPtr((uint)cb));
if (pNewMem == IntPtr.Zero)
{
throw new OutOfMemoryException();
@@ -438,13 +435,13 @@ namespace System.Runtime.InteropServices
{
if (!IsWin32Atom(ptr))
{
- Win32Native.CoTaskMemFree(ptr);
+ Interop.Ole32.CoTaskMemFree(ptr);
}
}
public static IntPtr ReAllocCoTaskMem(IntPtr pv, int cb)
{
- IntPtr pNewMem = Win32Native.CoTaskMemRealloc(pv, new UIntPtr((uint)cb));
+ IntPtr pNewMem = Interop.Ole32.CoTaskMemRealloc(pv, new UIntPtr((uint)cb));
if (pNewMem == IntPtr.Zero && cb != 0)
{
throw new OutOfMemoryException();
@@ -455,7 +452,7 @@ namespace System.Runtime.InteropServices
internal static IntPtr AllocBSTR(int length)
{
- IntPtr bstr = Win32Native.SysAllocStringLen(null, length);
+ IntPtr bstr = Interop.OleAut32.SysAllocStringLen(null, length);
if (bstr == IntPtr.Zero)
{
throw new OutOfMemoryException();
@@ -467,7 +464,7 @@ namespace System.Runtime.InteropServices
{
if (!IsWin32Atom(ptr))
{
- Win32Native.SysFreeString(ptr);
+ Interop.OleAut32.SysFreeString(ptr);
}
}
@@ -484,7 +481,7 @@ namespace System.Runtime.InteropServices
throw new ArgumentOutOfRangeException(nameof(s));
}
- IntPtr bstr = Win32Native.SysAllocStringLen(s, s.Length);
+ IntPtr bstr = Interop.OleAut32.SysAllocStringLen(s, s.Length);
if (bstr == IntPtr.Zero)
{
throw new OutOfMemoryException();
@@ -495,7 +492,7 @@ namespace System.Runtime.InteropServices
public static string PtrToStringBSTR(IntPtr ptr)
{
- return PtrToStringUni(ptr, (int)Win32Native.SysStringLen(ptr));
+ return PtrToStringUni(ptr, (int)Interop.OleAut32.SysStringLen(ptr));
}
#if FEATURE_COMINTEROP
diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs
index 00b78d5c2c..ca70d5d873 100644
--- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs
+++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs
@@ -2,13 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Collections.Generic;
using System.Reflection;
-using System.Reflection.Emit;
using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
-using Win32Native = Microsoft.Win32.Win32Native;
-using System.Diagnostics;
using System.Threading;
namespace System.Runtime.InteropServices
diff --git a/src/System.Private.CoreLib/src/System/StubHelpers.cs b/src/System.Private.CoreLib/src/System/StubHelpers.cs
index 972a30c32b..90767fa6a7 100644
--- a/src/System.Private.CoreLib/src/System/StubHelpers.cs
+++ b/src/System.Private.CoreLib/src/System/StubHelpers.cs
@@ -113,7 +113,7 @@ namespace System.StubHelpers
internal static void ClearNative(IntPtr pNative)
{
- Win32Native.CoTaskMemFree(pNative);
+ Interop.Ole32.CoTaskMemFree(pNative);
}
} // class CSTRMarshaler
@@ -169,7 +169,7 @@ namespace System.StubHelpers
{
if (pNative != IntPtr.Zero)
{
- Win32Native.CoTaskMemFree(pNative);
+ Interop.Ole32.CoTaskMemFree(pNative);
}
}
}
@@ -236,20 +236,20 @@ namespace System.StubHelpers
// If caller provided a buffer, construct the BSTR manually. The size
// of the buffer must be at least (lengthInBytes + 6) bytes.
#if DEBUG
- uint length = *((uint*)pNativeBuffer.ToPointer());
+ uint length = *((uint*)pNativeBuffer);
Debug.Assert(length >= lengthInBytes + 6, "BSTR localloc'ed buffer is too small");
#endif
// set length
- *((uint*)pNativeBuffer.ToPointer()) = lengthInBytes;
+ *((uint*)pNativeBuffer) = lengthInBytes;
- ptrToFirstChar = (byte*)pNativeBuffer.ToPointer() + 4;
+ ptrToFirstChar = (byte*)pNativeBuffer + 4;
}
else
{
// If not provided, allocate the buffer using SysAllocStringByteLen so
// that odd-sized strings will be handled as well.
- ptrToFirstChar = (byte*)Win32Native.SysAllocStringByteLen(null, lengthInBytes).ToPointer();
+ ptrToFirstChar = (byte*)Interop.OleAut32.SysAllocStringByteLen(null, lengthInBytes);
if (ptrToFirstChar == null)
{
@@ -314,7 +314,7 @@ namespace System.StubHelpers
if ((length & 1) == 1)
{
// odd-sized strings need to have the trailing byte saved in their sync block
- ret.SetTrailByte(((byte*)bstr.ToPointer())[length - 1]);
+ ret.SetTrailByte(((byte*)bstr)[length - 1]);
}
return ret;
@@ -325,7 +325,7 @@ namespace System.StubHelpers
{
if (IntPtr.Zero != pNative)
{
- Win32Native.SysFreeString(pNative);
+ Interop.OleAut32.SysFreeString(pNative);
}
}
} // class BSTRMarshaler
@@ -385,7 +385,7 @@ namespace System.StubHelpers
{
if (IntPtr.Zero != pNative)
{
- Win32Native.CoTaskMemFree((IntPtr)(((long)pNative) - sizeof(uint)));
+ Interop.Ole32.CoTaskMemFree((IntPtr)(((long)pNative) - sizeof(uint)));
}
}
} // class VBByValStrMarshaler
@@ -407,7 +407,7 @@ namespace System.StubHelpers
bytes = AnsiCharMarshaler.DoAnsiConversion(strManaged, 0 != (flags & 0xFF), 0 != (flags >> 8), out nb);
}
- return Win32Native.SysAllocStringByteLen(bytes, (uint)nb);
+ return Interop.OleAut32.SysAllocStringByteLen(bytes, (uint)nb);
}
internal static unsafe string ConvertToManaged(IntPtr bstr)
@@ -429,7 +429,7 @@ namespace System.StubHelpers
{
if (IntPtr.Zero != pNative)
{
- Win32Native.SysFreeString(pNative);
+ Interop.OleAut32.SysFreeString(pNative);
}
}
} // class AnsiBSTRMarshaler
@@ -1099,7 +1099,7 @@ namespace System.StubHelpers
// marshal the object as class with layout (UnmanagedType.LPStruct)
if (IsIn(dwFlags))
{
- StubHelpers.FmtClassUpdateNativeInternal(pManagedHome, (byte*)pNativeHome.ToPointer(), ref cleanupWorkList);
+ StubHelpers.FmtClassUpdateNativeInternal(pManagedHome, (byte*)pNativeHome, ref cleanupWorkList);
}
if (IsOut(dwFlags))
{
@@ -1172,7 +1172,7 @@ namespace System.StubHelpers
case BackPropAction.Layout:
{
- StubHelpers.FmtClassUpdateCLRInternal(pManagedHome, (byte*)pNativeHome.ToPointer());
+ StubHelpers.FmtClassUpdateCLRInternal(pManagedHome, (byte*)pNativeHome);
break;
}
@@ -1221,7 +1221,7 @@ namespace System.StubHelpers
// this must happen regardless of BackPropAction
Marshal.DestroyStructure(pNativeHome, layoutType);
}
- Win32Native.CoTaskMemFree(pNativeHome);
+ Interop.Ole32.CoTaskMemFree(pNativeHome);
}
StubHelpers.DestroyCleanupList(ref cleanupWorkList);
}
diff --git a/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
index 592f2f6b70..02dedbf6e1 100644
--- a/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
@@ -14,7 +14,6 @@
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
-using Microsoft.Win32;
namespace System.Threading
{
@@ -31,7 +30,7 @@ namespace System.Threading
internal sealed class RegisteredWaitHandleSafe : CriticalFinalizerObject
{
- private static IntPtr InvalidHandle => Win32Native.INVALID_HANDLE_VALUE;
+ private static IntPtr InvalidHandle => new IntPtr(-1);
private IntPtr registeredWaitHandle = InvalidHandle;
private WaitHandle m_internalWaitObject;
private bool bReleaseNeeded = false;
diff --git a/src/System.Private.CoreLib/src/System/Threading/Timer.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Threading/Timer.CoreCLR.cs
index bc783417be..83b13b408d 100644
--- a/src/System.Private.CoreLib/src/System/Threading/Timer.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Threading/Timer.CoreCLR.cs
@@ -30,7 +30,7 @@ namespace System.Threading
{
ulong time100ns;
- bool result = Win32Native.QueryUnbiasedInterruptTime(out time100ns);
+ bool result = Interop.Kernel32.QueryUnbiasedInterruptTime(out time100ns);
if (!result)
throw Marshal.GetExceptionForHR(Marshal.GetLastWin32Error());
diff --git a/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs b/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs
index 83c5269cbb..c591e1d53e 100644
--- a/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs
+++ b/src/System.Private.CoreLib/src/System/Threading/WaitHandle.cs
@@ -12,18 +12,14 @@
**
=============================================================================*/
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+using System.Diagnostics.CodeAnalysis;
+
namespace System.Threading
{
- using System.Threading;
- using System;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using Microsoft.Win32.SafeHandles;
- using System.Runtime.Versioning;
- using System.Runtime.ConstrainedExecution;
- using System.Diagnostics.CodeAnalysis;
- using Win32Native = Microsoft.Win32.Win32Native;
-
public abstract class WaitHandle : MarshalByRefObject, IDisposable
{
public const int WaitTimeout = 0x102;
@@ -38,11 +34,7 @@ namespace System.Threading
internal bool hasThreadAffinity;
- private static IntPtr GetInvalidHandle()
- {
- return Win32Native.INVALID_HANDLE_VALUE;
- }
- protected static readonly IntPtr InvalidHandle = GetInvalidHandle();
+ protected static readonly IntPtr InvalidHandle = new IntPtr(-1);
private const int WAIT_OBJECT_0 = 0;
private const int WAIT_ABANDONED = 0x80;
private const int WAIT_FAILED = 0x7FFFFFFF;