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.
This commit is contained in:
Nick Babcock
2021-05-09 16:46:11 +02:00
committed by GitHub
parent 5a47cda6ed
commit 73c0be1384
3 changed files with 4 additions and 4 deletions
@@ -56,7 +56,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<Kernel32.NVME_IDENTIFY_CONTROLLER_DATA>());
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<Kernel32.NVME_IDENTIFY_CONTROLLER_DATA>(ptr);
@@ -56,7 +56,7 @@ namespace LibreHardwareMonitor.Hardware.Storage
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<Kernel32.NVME_IDENTIFY_CONTROLLER_DATA>());
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<Kernel32.NVME_IDENTIFY_CONTROLLER_DATA>(ptr);
+2 -2
View File
@@ -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);