-
Notifications
You must be signed in to change notification settings - Fork 356
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
munmap
need not point to the start of an object
#3407
Comments
munmap supports this, but the LLVM memory model, and thus by extension every language compiled via LLVM, does not. LLVM optimizations assume that allocations can never be partially freed.
Consequently, in Rust, allocations can currently not change their shape or size once they are created.
|
So, closing in favor of rust-lang/unsafe-code-guidelines#430 -- the question really is if and how the Rust memory model can support partial To be clear, I think we should support at least munmap at the "end" of an allocation (allocations with gaps have their own challenges). But we first need to convince LLVM to support that and potentially fix optimizations that rely on allocations never shrinking. |
You're assuming that |
I am assuming that they generate memory that Rust can access. If Rust can't access that memory then they become kind of pointless. :) LLVM assumes that if at moment A, one can access both rust-lang/unsafe-code-guidelines#430 is tracking whether we want Rust to make such assumptions. But currently even if we wanted the answer to be "no", we'd first have to fix LLVM. |
The use case I have is aligned allocation where I overallocate then |
If there is never a memory access nor an in-bounds pointer arithmetic for the part of the allocation that you remove again, then the sketched optimization would still be fine, yeah. (But you better use But the intermediate state before you "pruned" your allocation is a state that doesn't really exist in the LLVM nor Rust memory model, so this is rather shaky ground to stand on. |
Using
munmap
with a partial deallocation results in the following error:error: Undefined Behavior: deallocating 0x2d0000[alloc75617]<212514> which does not point to the beginning of an object
However
munmap
supports such partial deallocation so this is not actually UB.The text was updated successfully, but these errors were encountered: