-
Notifications
You must be signed in to change notification settings - Fork 360
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
Add support for Windows virtual memory functions (VirtualAlloc, ...) #4187
Comments
Please have a look around for So, if there's a particular pattern that you think should work but currently does not work, please provide a self-contained example demonstrating that pattern. |
Also, we already have #3605 to track "support more uses of |
Yeah, mmap is a beast, but this usecase is pretty limited compared to what it can do.
Sure, I'll do that. Meanwhile, I can give you a short summary of what this is about. I am sorry if you already know all this, but here goes: This is true at least on Windows, but I'd assume it to be true (or at least similar) elsewhere too. VirtualAlloc is the lowest-level memory allocation API you can call. Unlike malloc, which serves allocations of any sizes and alignments, VirtualAlloc only deals with page-granularity allocations. Higher level memory allocators use VirtualAlloc to get the memory from the OS. One huge difference is that unlike malloc/free, the memory can be in multiple states.
The fact that we have a contiguous region of memory that we commit on demand is super useful for writing arenas, which some people prefer using to manage their application's memory (e.g. see RADDebugger's arena https://github.com/EpicGamesExt/raddebugger/blob/master/src/base/base_arena.c). I am also pretty sure arenas or something similar is in most serious garbage collectors. I also think SpiderMoneky uses it to get memory for WASM modules and let the OS page fault handle OOB accesses (https://spidermonkey.dev/blog/2025/01/15/is-memory64-actually-worth-using.html). |
Some basic arena usecases already work with |
I believe this use case with |
Had a look at #3605, and the code example in the first comment (https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d2ea1888ffe60d05399f151af49bbf48) is basically what I had in mind, yes. (Except it does some huge-page specific stuff which I don't have experience with).
Pretty much! FWIW, With On Windows, one has to explicitly EDIT: So, if #3605 already tracks mmap virtual memory, do we repurpose this issue to do the same for Windows? |
Okay, great! I made this issue about It would be very useful to have a little example that can eventually be used as a test case for when someone works on the implementation, also to demonstrate which flags it would be good to support. (I assume there are tons of flags and initially we'll only support a minimal subset, just to get something to work.) |
If you could update the issue description to match, that would be great. :) |
I'll make that example! Might take a couple of days, but will post it back here once I have it. |
No rush, we don't have a timeline for when someone will be interested in implementing this anyway. |
Updated description
Virtual memory is something that high performance applications tend to do. I think it would be great if they had the ability to run their memory allocation test suites under miri.
#3605 already tracks changes to
mmap
such that we can do virtual memory things with it under miri.On Windows, the API to deal with virtual memory is
VirtualAlloc
andVirtualFree
:The minimal set relevant flags is MEM_RESERVE and MEM_COMMIT for VirtualAlloc; and MEM_RELEASE on VirtualFree. There is also MEM_DECOMMIT, which could be useful too.
https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc
https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualfree
TODO @yanchith Provide runnable example.
The text was updated successfully, but these errors were encountered: