Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes several issues around the handling of mmaps as well as (some of the)quirks involving mmaps...
mmap(2) will always allocate whole memory pages, even if the
caller only reuqests a partial page. This is considered by calculating the "real" size of the mmap.
munmap(2) also operates on pages, unmapping every page it "touches", so the size parameter is adjusted if needed.
According to munmap(2), the call can fail, e.g if the adress given is not at a page boundary.
mremap can fail, in this case the old mapping is retained.
mremap, when oldsize is 0, a new mapping is created without freeing
the old one.
Fix logic error in process_rb_search_range() The function would not properly check if addr is within the block
due to inversed logic in the comparasion.
munmap(2) will unmap any page "it touches", the parameters
given to it do not necessarily need to match the ones given to mmap(2).
It is legit to specify pages that are not mapped at all, ranges that
span multiple mappings, with or without holes…
A logic error in calculating the size for
process_release_mem() is fixed in the case a munmap would split
a previous allocation in two maps.
Similar fix also for the case where the freed page is at the end
of the allocated area.