mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-21 04:33:56 +00:00
Small callback optimization and unification
This commit is contained in:
@@ -54,9 +54,10 @@ namespace utils
|
||||
}
|
||||
}
|
||||
|
||||
module_manager::module_manager(memory_manager& memory, file_system& file_sys)
|
||||
module_manager::module_manager(memory_manager& memory, file_system& file_sys, callbacks& cb)
|
||||
: memory_(&memory),
|
||||
file_sys_(&file_sys)
|
||||
file_sys_(&file_sys),
|
||||
callbacks_(&cb)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ mapped_module* module_manager::map_local_module(const std::filesystem::path& fil
|
||||
|
||||
const auto image_base = mod.image_base;
|
||||
const auto entry = this->modules_.try_emplace(image_base, std::move(mod));
|
||||
this->on_module_load(entry.first->second);
|
||||
this->callbacks_->on_module_load(entry.first->second);
|
||||
return &entry.first->second;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@@ -147,7 +148,7 @@ bool module_manager::unmap(const uint64_t address, const logger& logger)
|
||||
|
||||
logger.log("Unmapping %s (0x%" PRIx64 ")\n", mod->second.path.generic_string().c_str(), mod->second.image_base);
|
||||
|
||||
this->on_module_unload(mod->second);
|
||||
this->callbacks_->on_module_unload(mod->second);
|
||||
unmap_module(*this->memory_, mod->second);
|
||||
this->modules_.erase(mod);
|
||||
|
||||
|
||||
@@ -10,11 +10,15 @@ class logger;
|
||||
class module_manager
|
||||
{
|
||||
public:
|
||||
using module_map = std::map<uint64_t, mapped_module>;
|
||||
utils::optional_function<void(mapped_module& mod)> on_module_load{};
|
||||
utils::optional_function<void(mapped_module& mod)> on_module_unload{};
|
||||
struct callbacks
|
||||
{
|
||||
utils::optional_function<void(mapped_module& mod)> on_module_load{};
|
||||
utils::optional_function<void(mapped_module& mod)> on_module_unload{};
|
||||
};
|
||||
|
||||
module_manager(memory_manager& memory, file_system& file_sys);
|
||||
using module_map = std::map<uint64_t, mapped_module>;
|
||||
|
||||
module_manager(memory_manager& memory, file_system& file_sys, callbacks& cb);
|
||||
|
||||
void map_main_modules(const windows_path& executable_path, const windows_path& ntdll_path,
|
||||
const windows_path& win32u_path, const logger& logger);
|
||||
@@ -61,6 +65,7 @@ class module_manager
|
||||
private:
|
||||
memory_manager* memory_{};
|
||||
file_system* file_sys_{};
|
||||
callbacks* callbacks_{};
|
||||
|
||||
module_map modules_{};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user