Skip to content

Commit

Permalink
Use MemMapManager to detect free space in memory instead of page perm…
Browse files Browse the repository at this point in the history
…issions (#149)
  • Loading branch information
Boyan-MILANOV authored Sep 21, 2022
1 parent 4140818 commit 9b49a4b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/include/maat/memory_page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class MemMapManager: public serial::Serializable
public:
void map(MemMap map);
void unmap(addr_t start, addr_t end);
bool is_free(addr_t start, addr_t end) const;
public:
const std::list<MemMap>& get_maps() const;
void set_maps(std::list<MemMap>&&);
Expand Down
3 changes: 1 addition & 2 deletions src/loader/loader_lief.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ addr_t LoaderLIEF::alloc_segment(
addr_t size,
mem_flag_t flags,
const std::string& name
)
{
){
try
{
return engine->mem->allocate(prefered_base, size, 0x1000, flags, name);
Expand Down
4 changes: 2 additions & 2 deletions src/memory/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ addr_t MemEngine::allocate(

while (base <= max_addr-size+1)
{
if (page_manager.is_unmapped(base, base+size-1))
if (mappings.is_free(base, base+size-1))
{
map(base, base+size-1, flags, name);
return base;
Expand Down Expand Up @@ -1710,7 +1710,7 @@ std::shared_ptr<MemSegment> MemEngine::get_segment_containing(addr_t addr)

bool MemEngine::is_free(addr_t start, addr_t end)
{
return page_manager.is_unmapped(start, end);
return mappings.is_free(start, end);
}

addr_t MemEngine::allocate_segment(
Expand Down
8 changes: 8 additions & 0 deletions src/memory/memory_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ const MemMap& MemMapManager::get_map_by_name(const std::string& name) const
);
}

bool MemMapManager::is_free(addr_t start, addr_t end) const
{
for (const MemMap& map : _maps)
if (map.intersects_with_range(start, end))
return false;
return true;
}

std::ostream& operator<<(std::ostream& os, const MemMapManager& mem)
{
static unsigned int addr_w = 20;
Expand Down

0 comments on commit 9b49a4b

Please sign in to comment.