Skip to content

ql.mem.unmap_all does not unmap all memory regions #1141

@LukeSerne

Description

@LukeSerne

Describe the bug
Mapping a memory region starting at address 0 and then calling ql.mem.unmap_all does not unmap the region.

Sample Code

import qiling
from qiling.const import QL_ARCH

ql = qiling.Qiling(code=b"\0", archtype=QL_ARCH.ARM, ostype='linux')
ql.mem.map(addr=0, size=0x1000)
ql.mem.unmap_all()
assert ql.mem.map_info == [], ql.mem.map_info 

Actual behavior

$ python main.py
Traceback (most recent call last):
  File "main.py", line 7, in <module>
    assert ql.mem.map_info == [], ql.mem.map_info 
AssertionError: [(0, 4096, 7, '[mapped]', False)]

Expected behavior
No assertion error and the entire memory space is reclaimed (as the docstring says).

Additional context
This region is not unmapped because begin is 0, which causes the begin and end guard in the below code to be False. I am not sure why this check is even there - I think the if should be removed, and self.unmap should always be executed.

qiling/qiling/os/memory.py

Lines 417 to 423 in 59d31c2

def unmap_all(self):
"""Reclaim the entire memory space.
"""
for begin, end, _ in self.ql.uc.mem_regions():
if begin and end:
self.unmap(begin, end - begin + 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions