mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-19 03:33:56 +00:00
Optimize module_manager::get_module
This commit is contained in:
@@ -46,7 +46,7 @@ struct mapped_module
|
||||
|
||||
bool contains(const uint64_t address) const
|
||||
{
|
||||
return address >= this->image_base && address < (this->image_base + this->size_of_image);
|
||||
return (address - this->image_base) < this->size_of_image;
|
||||
}
|
||||
|
||||
uint64_t find_export(const std::string_view export_name) const
|
||||
|
||||
@@ -156,6 +156,7 @@ mapped_module* module_manager::map_memory_module(uint64_t base_address, uint64_t
|
||||
|
||||
const auto image_base = mod.image_base;
|
||||
const auto entry = this->modules_.try_emplace(image_base, std::move(mod));
|
||||
this->last_module_cache_ = this->modules_.end();
|
||||
this->callbacks_->on_module_load(entry.first->second);
|
||||
return &entry.first->second;
|
||||
}
|
||||
@@ -183,6 +184,7 @@ void module_manager::serialize(utils::buffer_serializer& buffer) const
|
||||
void module_manager::deserialize(utils::buffer_deserializer& buffer)
|
||||
{
|
||||
buffer.read_map(this->modules_);
|
||||
this->last_module_cache_ = this->modules_.end();
|
||||
|
||||
const auto executable_base = buffer.read<uint64_t>();
|
||||
const auto ntdll_base = buffer.read<uint64_t>();
|
||||
@@ -209,6 +211,7 @@ bool module_manager::unmap(const uint64_t address)
|
||||
this->callbacks_->on_module_unload(mod->second);
|
||||
unmap_module(*this->memory_, mod->second);
|
||||
this->modules_.erase(mod);
|
||||
this->last_module_cache_ = this->modules_.end();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -83,9 +83,15 @@ class module_manager
|
||||
callbacks* callbacks_{};
|
||||
|
||||
module_map modules_{};
|
||||
mutable module_map::iterator last_module_cache_{modules_.end()};
|
||||
|
||||
module_map::iterator get_module(const uint64_t address)
|
||||
{
|
||||
if (last_module_cache_ != this->modules_.end() && last_module_cache_->second.contains(address))
|
||||
{
|
||||
return last_module_cache_;
|
||||
}
|
||||
|
||||
if (this->modules_.empty())
|
||||
{
|
||||
return this->modules_.end();
|
||||
@@ -101,6 +107,7 @@ class module_manager
|
||||
|
||||
if (upper_bound->second.contains(address))
|
||||
{
|
||||
last_module_cache_ = upper_bound;
|
||||
return upper_bound;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user