From 73c0be13848a85aa41cf51781f7a3b11ca3749bc Mon Sep 17 00:00:00 2001 From: Nick Babcock Date: Sun, 9 May 2021 09:46:11 -0500 Subject: [PATCH] Rename CopyMemory RtlCopyMemory (#438) There is no entry for `CopyMemory` exported from kernel32.dll as it is omitted from the following output: ``` dumpbin /exports C:\Windows\System32\kernel32.dll ``` The name we're looking for is `RtlCopyMemory`. This does not affect traditional .NET framework users as `CopyMemory` was special cased prior to .NET core ([source](https://github.com/dotnet/runtime/issues/12496#issuecomment-483442084)) The incorrect entry point will cause an `EntryPointNotFoundException` for NET core users (ref: https://github.com/nickbabcock/OhmGraphite/issues/214) There were a couple other entries in kernel32 that are missing: - CreateFile - LoadLibrary Both functions appear to have a `CreateFileA` and `LoadLibraryA` variant, but I do not know if those are appropriate. --- LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs | 2 +- LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs | 2 +- LibreHardwareMonitorLib/Interop/Kernel32.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs index 8fbd776..59cce27 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs @@ -56,7 +56,7 @@ namespace LibreHardwareMonitor.Hardware.Storage IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf()); Kernel32.RtlZeroMemory(ptr, finalSize); int len = Math.Min(finalSize, passThrough.DataBuffer.Length); - Kernel32.CopyMemory(ptr, newPtr, (uint)len); + Kernel32.RtlCopyMemory(ptr, newPtr, (uint)len); Marshal.FreeHGlobal(buffer); Kernel32.NVME_IDENTIFY_CONTROLLER_DATA item = Marshal.PtrToStructure(ptr); diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs index 3faaf10..e02cbf1 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs @@ -56,7 +56,7 @@ namespace LibreHardwareMonitor.Hardware.Storage IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf()); Kernel32.RtlZeroMemory(ptr, finalSize); int len = Math.Min(finalSize, passThrough.DataBuffer.Length); - Kernel32.CopyMemory(ptr, newPtr, (uint)len); + Kernel32.RtlCopyMemory(ptr, newPtr, (uint)len); Marshal.FreeHGlobal(buffer); Kernel32.NVME_IDENTIFY_CONTROLLER_DATA item = Marshal.PtrToStructure(ptr); diff --git a/LibreHardwareMonitorLib/Interop/Kernel32.cs b/LibreHardwareMonitorLib/Interop/Kernel32.cs index 5f37e5b..54b1048 100644 --- a/LibreHardwareMonitorLib/Interop/Kernel32.cs +++ b/LibreHardwareMonitorLib/Interop/Kernel32.cs @@ -206,8 +206,8 @@ namespace LibreHardwareMonitor.Interop [DllImport(DllName, SetLastError = true)] internal static extern void RtlZeroMemory(IntPtr Destination, int Length); - [DllImport(DllName, EntryPoint = "CopyMemory", SetLastError = false)] - internal static extern void CopyMemory(IntPtr Destination, IntPtr Source, uint Length); + [DllImport(DllName, SetLastError = false)] + internal static extern void RtlCopyMemory(IntPtr Destination, IntPtr Source, uint Length); [DllImport(DllName, SetLastError = true)] internal static extern IntPtr LoadLibrary(string lpFileName);