Skip to content
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

Bugfixes mmap #11

Merged
merged 6 commits into from
Jun 24, 2022
Merged

Bugfixes mmap #11

merged 6 commits into from
Jun 24, 2022

Conversation

coldtobi
Copy link

@coldtobi coldtobi commented Jun 24, 2022

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.

Tobias Frost added 6 commits June 22, 2022 15:13
mmaps are full of quirks ;-)

- 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.

See mremap(2) for details.
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…

Beside that, 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.
@sstefani sstefani merged commit 237bf3a into sstefani:master Jun 24, 2022
@coldtobi coldtobi deleted the bugfixes_mmap branch June 24, 2022 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants