Skip to content

Commit

Permalink
Merge pull request #1489 from elicn/dev-periodic
Browse files Browse the repository at this point in the history
Refine munmap logic to better align with POSIX specification
  • Loading branch information
xwings authored Oct 8, 2024
2 parents ea1a17b + 8c3a5dc commit 3d71cf9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions qiling/os/posix/syscall/mman.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
def ql_syscall_munmap(ql: Qiling, addr: int, length: int):
try:
# find addr's enclosing memory range
label = next(label for lbound, ubound, _, label, _ in ql.mem.get_mapinfo() if (lbound <= addr < ubound) and label.startswith(('[mmap]', '[mmap anonymous]')))
ubound, label = next((ubound, label) for lbound, ubound, _, label, _ in ql.mem.get_mapinfo() if (lbound <= addr < ubound) and label.startswith(('[mmap]', '[mmap anonymous]')))
except StopIteration:
# nothing to do; cannot munmap what was not originally mmapped
ql.log.debug(f'munmap: enclosing area for {addr:#x} was not mmapped')
Expand All @@ -43,9 +43,10 @@ def ql_syscall_munmap(ql: Qiling, addr: int, length: int):
fd.lseek(fd._mapped_offset)
fd.write(content)

# unmap the enclosing memory region
# unmap the enclosing memory pages.
# munmap allows the length to exceed the mapped range. in such case, unmap by original ubound
lbound = ql.mem.align(addr)
ubound = ql.mem.align_up(addr + length)
ubound = min(ql.mem.align_up(addr + length), ubound)

ql.mem.unmap(lbound, ubound - lbound)

Expand Down

0 comments on commit 3d71cf9

Please sign in to comment.