Closed vatsan-madhavan closed 4 years ago
FillMemory
and ZeroMemory
are macros that are defined in terms of memset
rather than a native exported function from a Win32 DLL. I will fix MoveMemory
and CopyMemory
though.
Thanks for the report.
While it is technically true that these are macros in the header, kernel32.dll
has long exported RtlZeroMemory
as function forwarder into a function of the same name in ntdll.dll
and also provides an exported RtlFillMemory
function.
As a side-note, Vanara also relies on these four functions existing in kernel32.dll
.
@hugmyndakassi Are RtlZeroMemory
or RtlFillMemory
as exported functions documented? I can't find any documentation for them outside of macros. We don't expose undocumented Windows features in this library.
I'll just leave a quick note here that I got a System.EntryPointNotFoundException: 'Unable to find an entry point named 'RtlCopyMemory' in DLL 'Kernel32'.
in a unit test with a CopyMemory
call. The exception went away after I set Processor Architecture for AnyCPU Projects
to x64
in Visual Studio Test Explorer settings.
.NET Framework 4.7.2, PInvoke 0.7.104
Thanks, @mpolicki. To be clear, it sounds like you're saying that x86 processes don't get a kernel32 export of RtlCopyMemory, but x64 processes do. Does that sound about right? If so, can you open a separate issue to track that?
@AArnott Yes, that's exactly what seems to be the case. The issue is #587.
Thank you.
Please see https://github.com/dotnet/coreclr/issues/24008 for background.
.NET Framework has special case logic to ensure that
MoveMemory
,CopyMemory
,FillMemory
, andZeroMemory
are correctly mapped toRtlMoveMemory
,RtlCopyMemory
,RtlFillMemory
, andRtlZeroMemory
respectively..NET Core does not have this this special case, so the following P/Invoke definition will fail on .NET Core.
At least two definitions in
PInvoke.Kernel32
are likely to fail in .NET Core -MoveMemory
, andCopyMemory
. (I did not inspect to see whetherFillMemory
andZeroMemory
have this bug).