-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement NativeMemory #54006
Implement NativeMemory #54006
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.cs
Outdated
Show resolved
Hide resolved
CC. @GrabYourPitchforks, @jkotas I've put this up to validate it builds/passes on all architectures, but it should be generally in the "right" shape (barring any feedback). |
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.cs
Outdated
Show resolved
Hide resolved
1da201c
to
bd5e64e
Compare
src/libraries/Common/src/Interop/Unix/System.Native/Interop.MemAlloc.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/Interop/Windows/Ucrtbase/Interop.MemAlloc.cs
Outdated
Show resolved
Hide resolved
af899a1
to
73af10a
Compare
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.Unix.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Unix.cs
Show resolved
Hide resolved
b76cc68
to
f3ebd46
Compare
...ies/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/NativeMemoryTests.cs
Show resolved
Hide resolved
f3ebd46
to
d2ae1a1
Compare
...ies/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/NativeMemoryTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.Unix.cs
Outdated
Show resolved
Hide resolved
@jkotas, any other feedback here. If not, I think this is "good" and ready for taking the open questions (like renaming |
CI job is here: https://dev.azure.com/dnceng/public/_build/results?buildId=1191094&view=results (it is running now, the push notifications are backed up however) |
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeMemory.Unix.cs
Outdated
Show resolved
Hide resolved
…pServices/NativeMemory.Unix.cs Co-authored-by: Jan Kotas <jkotas@microsoft.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
|
||
if (ptr != null) | ||
{ | ||
Buffer.Memmove(ref *(byte*)newPtr, ref *(byte*)ptr, byteCount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this works. byteCount
is the new size, but we can only copy old size (the rest should be left uninitialized).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right. I'll need to either expose malloc_usable_size
/malloc_size
or make this a P/Invoke to a wrapper SystemNative.AlignedRealloc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to be a P/Invoke to a SystemNative_AlignedRealloc
to avoid needing 3-4 P/Invoke transitions.
It now correctly does:
- Allocate new space
- If allocation was successful:
- Get usable size of previous allocation
- Copy min of old/new size from old to new
- Free old allocation
- Return result
I've also added a test that explicitly tests going from a small to large allocation and that the bytes are as expected.
…of the last allocation
Turns out I've fixed it to track the |
0e413a0
to
805882b
Compare
@jkotas, @stephentoub This required a couple additional fixes since your sign-off to ensure it compiled on FreeBSD and so tests were passing everywhere. Would appreciate if you could take a look. I believe it is otherwise good now and is just waiting on the last couple legs to complete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This resolves #33244