diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs index 9e692c79ee1cf4bfa7554003eed11a9a404a425a..c1d0d991a0e52fb774a12e274d27f005daf31c95 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs @@ -68,23 +68,25 @@ internal static int BioTell(SafeBioHandle bio) [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool PushX509StackField(SafeSharedX509StackHandle stack, SafeX509Handle x509); - internal static string? GetX509RootStorePath(out bool defaultPath) + internal static unsafe string? GetX509RootStorePath(out bool defaultPath) { - IntPtr ptr = GetX509RootStorePath_private(out byte usedDefault); + byte usedDefault; + IntPtr ptr = GetX509RootStorePath_private(&usedDefault); defaultPath = (usedDefault != 0); return Marshal.PtrToStringAnsi(ptr); } - internal static string? GetX509RootStoreFile() + internal static unsafe string? GetX509RootStoreFile() { - return Marshal.PtrToStringAnsi(GetX509RootStoreFile_private(out _)); + byte unused; + return Marshal.PtrToStringAnsi(GetX509RootStoreFile_private(&unused)); } [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509RootStorePath")] - private static extern IntPtr GetX509RootStorePath_private(out byte defaultPath); + private static unsafe extern IntPtr GetX509RootStorePath_private(byte* defaultPath); [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509RootStoreFile")] - private static extern IntPtr GetX509RootStoreFile_private(out byte defaultPath); + private static unsafe extern IntPtr GetX509RootStoreFile_private(byte* defaultPath); [DllImport(Libraries.CryptoNative)] private static extern int CryptoNative_X509StoreSetVerifyTime( diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GlobalMemoryStatusEx.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GlobalMemoryStatusEx.cs index a5029f5ccb6e81e204b70154d117f813cd2fcecc..662cab8383cc760f1cdfd518d9dd2bce44e67e1b 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GlobalMemoryStatusEx.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GlobalMemoryStatusEx.cs @@ -8,6 +8,6 @@ internal static partial class Interop internal static partial class Kernel32 { [DllImport(Libraries.Kernel32)] - internal static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer); + internal static unsafe extern BOOL GlobalMemoryStatusEx(MEMORYSTATUSEX* lpBuffer); } } diff --git a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtCreateFile.cs b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtCreateFile.cs index 1a89d911f83bdf84c08e0c22477be7890836da7d..7d6ab13b6633d3e090e69d69cd47af5dffa0adce 100644 --- a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtCreateFile.cs +++ b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtCreateFile.cs @@ -14,10 +14,10 @@ internal static partial class NtDll // https://msdn.microsoft.com/en-us/library/windows/hardware/ff566424.aspx [DllImport(Libraries.NtDll, CharSet = CharSet.Unicode, ExactSpelling = true)] private static extern unsafe uint NtCreateFile( - out IntPtr FileHandle, + IntPtr* FileHandle, DesiredAccess DesiredAccess, - ref OBJECT_ATTRIBUTES ObjectAttributes, - out IO_STATUS_BLOCK IoStatusBlock, + OBJECT_ATTRIBUTES* ObjectAttributes, + IO_STATUS_BLOCK* IoStatusBlock, long* AllocationSize, FileAttributes FileAttributes, FileShare ShareAccess, @@ -55,11 +55,13 @@ internal static partial class NtDll rootDirectory, securityQualityOfService); + IntPtr handle; + IO_STATUS_BLOCK statusBlock; uint status = NtCreateFile( - out IntPtr handle, + &handle, desiredAccess, - ref attributes, - out IO_STATUS_BLOCK statusBlock, + &attributes, + &statusBlock, AllocationSize: preallocationSize, fileAttributes, shareAccess, diff --git a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtQueryDirectoryFile.cs b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtQueryDirectoryFile.cs index 517fd4195f360d6b592aa483af647aa978c733f2..63b6bf9767c24d052f915d176e474f74daf93df0 100644 --- a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtQueryDirectoryFile.cs +++ b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtQueryDirectoryFile.cs @@ -16,7 +16,7 @@ internal static partial class NtDll IntPtr Event, IntPtr ApcRoutine, IntPtr ApcContext, - out IO_STATUS_BLOCK IoStatusBlock, + IO_STATUS_BLOCK* IoStatusBlock, IntPtr FileInformation, uint Length, FILE_INFORMATION_CLASS FileInformationClass, diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs index 33863ed4259122f25ecf699ee90ee1ed3f48c8f7..3b145fea4cc29ceda259b383a5b3417556332bce 100644 --- a/src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs +++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs @@ -9,7 +9,7 @@ internal static partial class Interop internal static partial class User32 { [DllImport(Libraries.User32, ExactSpelling = true)] - public static extern int GetWindowThreadProcessId(IntPtr handle, out int processId); + public static unsafe extern int GetWindowThreadProcessId(IntPtr handle, int* processId); [DllImport(Libraries.User32, ExactSpelling = true)] public static extern int GetWindowThreadProcessId(HandleRef handle, out int processId); diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.IsWindowVisible.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.IsWindowVisible.cs index 5e819d26db63055ae332bded10d59657be84847e..15a829a9cf55782adedb252a49b5162889fd57be 100644 --- a/src/libraries/Common/src/Interop/Windows/User32/Interop.IsWindowVisible.cs +++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.IsWindowVisible.cs @@ -9,6 +9,6 @@ internal static partial class Interop internal static partial class User32 { [DllImport(Libraries.User32)] - public static extern bool IsWindowVisible(IntPtr hWnd); + public static extern BOOL IsWindowVisible(IntPtr hWnd); } } diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs index 53c9c743de856cfee95bdb5f7bebe68ae54d12dd..e272d5fa4af1f86f54cd401a90c19e11ac7e07f2 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs @@ -42,7 +42,7 @@ public static unsafe IntPtr FindMainWindow(int processId) private static bool IsMainWindow(IntPtr handle) { - return (Interop.User32.GetWindow(handle, GW_OWNER) == IntPtr.Zero) && Interop.User32.IsWindowVisible(handle); + return (Interop.User32.GetWindow(handle, GW_OWNER) == IntPtr.Zero) && Interop.User32.IsWindowVisible(handle) != Interop.BOOL.FALSE; } [UnmanagedCallersOnly] @@ -51,7 +51,7 @@ private static unsafe Interop.BOOL EnumWindowsCallback(IntPtr handle, IntPtr ext MainWindowFinder* instance = (MainWindowFinder*)extraParameter; int processId = 0; // Avoid uninitialized variable if the window got closed in the meantime - Interop.User32.GetWindowThreadProcessId(handle, out processId); + Interop.User32.GetWindowThreadProcessId(handle, &processId); if ((processId == instance->_processId) && IsMainWindow(handle)) { diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/Interop.Windows.cs b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/Interop.Windows.cs index 202c3ead180f2c437fe1e79591f248003fb9cd05..d30e42c558a63a4db4f6cc09acca4e22c6ca1d3f 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/Interop.Windows.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/Interop.Windows.cs @@ -13,7 +13,7 @@ public static unsafe void CheckForAvailableVirtualMemory(ulong nativeSize) { Interop.Kernel32.MEMORYSTATUSEX memoryStatus = default; memoryStatus.dwLength = (uint)sizeof(Interop.Kernel32.MEMORYSTATUSEX); - if (Interop.Kernel32.GlobalMemoryStatusEx(ref memoryStatus)) + if (Interop.Kernel32.GlobalMemoryStatusEx(&memoryStatus) != Interop.BOOL.FALSE) { ulong totalVirtual = memoryStatus.ullTotalVirtual; if (nativeSize >= totalVirtual) diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Win32.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Win32.cs index 22e990194f5d885b39ae3a10bdfbb82a8e1aa397..3b90d71120edaf46b4adb3539ed6d93f75dd6d09 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Win32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Win32.cs @@ -20,12 +20,13 @@ private unsafe bool GetData() { Debug.Assert(_directoryHandle != (IntPtr)(-1) && _directoryHandle != IntPtr.Zero && !_lastEntryFound); + Interop.NtDll.IO_STATUS_BLOCK statusBlock; int status = Interop.NtDll.NtQueryDirectoryFile( FileHandle: _directoryHandle, Event: IntPtr.Zero, ApcRoutine: IntPtr.Zero, ApcContext: IntPtr.Zero, - IoStatusBlock: out Interop.NtDll.IO_STATUS_BLOCK statusBlock, + IoStatusBlock: &statusBlock, FileInformation: _buffer, Length: (uint)_bufferLength, FileInformationClass: Interop.NtDll.FILE_INFORMATION_CLASS.FileFullDirectoryInformation, diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.Windows.cs index 7c4a2da7babb107676511cabd023c61d5c0f3b5a..d5d1952e7a150513af400243a0f17c50d46c209d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.Windows.cs @@ -17,7 +17,7 @@ private static unsafe bool CheckForAvailableMemory(out ulong availPageFile, out { Interop.Kernel32.MEMORYSTATUSEX memoryStatus = default; memoryStatus.dwLength = (uint)sizeof(Interop.Kernel32.MEMORYSTATUSEX); - if (!Interop.Kernel32.GlobalMemoryStatusEx(ref memoryStatus)) + if (Interop.Kernel32.GlobalMemoryStatusEx(&memoryStatus) == Interop.BOOL.FALSE) { availPageFile = default; totalAddressSpaceFree = default; diff --git a/src/libraries/System.Runtime.Caching/src/System.Runtime.Caching.csproj b/src/libraries/System.Runtime.Caching/src/System.Runtime.Caching.csproj index e2a0ebdd803828a5496af738f2c6f89af8dbd498..0c059eae7c103bb2d3c9845d4435f6c5109bee97 100644 --- a/src/libraries/System.Runtime.Caching/src/System.Runtime.Caching.csproj +++ b/src/libraries/System.Runtime.Caching/src/System.Runtime.Caching.csproj @@ -51,6 +51,7 @@ + @@ -85,4 +86,4 @@ - \ No newline at end of file + diff --git a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryMonitor.Windows.cs b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryMonitor.Windows.cs index 189a9460d32c56ecdd89ded3885c63c5404c5f65..acb8bb0f42290b2a846d67da04863f930a0f1532 100644 --- a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryMonitor.Windows.cs +++ b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryMonitor.Windows.cs @@ -16,7 +16,7 @@ static unsafe MemoryMonitor() { Interop.Kernel32.MEMORYSTATUSEX memoryStatus = default; memoryStatus.dwLength = (uint)sizeof(Interop.Kernel32.MEMORYSTATUSEX); - if (Interop.Kernel32.GlobalMemoryStatusEx(ref memoryStatus)) + if (Interop.Kernel32.GlobalMemoryStatusEx(&memoryStatus) != Interop.BOOL.FALSE) { s_totalPhysical = (long)memoryStatus.ullTotalPhys; s_totalVirtual = (long)memoryStatus.ullTotalVirtual; diff --git a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/PhysicalMemoryMonitor.Windows.cs b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/PhysicalMemoryMonitor.Windows.cs index 078bf9ed3794ee623b17b3bae6181518a75ed761..6aff99b66b19d3229ea45b65f72b93a26f8426f3 100644 --- a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/PhysicalMemoryMonitor.Windows.cs +++ b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/PhysicalMemoryMonitor.Windows.cs @@ -14,7 +14,7 @@ protected override unsafe int GetCurrentPressure() { Interop.Kernel32.MEMORYSTATUSEX memoryStatus = default; memoryStatus.dwLength = (uint)sizeof(Interop.Kernel32.MEMORYSTATUSEX); - if (!Interop.Kernel32.GlobalMemoryStatusEx(ref memoryStatus)) + if (Interop.Kernel32.GlobalMemoryStatusEx(&memoryStatus) == Interop.BOOL.FALSE) { return 0; }