From 5846d2c0b9174766f127ae1abf47b8b08c076168 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 1 Apr 2025 20:09:43 +0200 Subject: [PATCH] Generalize hook store --- src/icicle-emulator/icicle_x64_emulator.cpp | 22 +++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/icicle-emulator/icicle_x64_emulator.cpp b/src/icicle-emulator/icicle_x64_emulator.cpp index 42e84d93..3947e9bd 100644 --- a/src/icicle-emulator/icicle_x64_emulator.cpp +++ b/src/icicle-emulator/icicle_x64_emulator.cpp @@ -41,6 +41,13 @@ namespace icicle throw std::runtime_error(std::string(error)); } } + + template + struct function_object : std::function, utils::object + { + using std::function::function; + ~function_object() override = default; + }; } class icicle_x64_emulator : public x64_emulator @@ -212,16 +219,16 @@ namespace icicle return nullptr; } - auto callback_store = std::make_unique>([c = std::move(callback)] { + auto callback_store = std::make_unique>([c = std::move(callback)] { (void)c(); // }); const auto invoker = +[](void* cb) { - (*static_cast*>(cb))(); // + (*static_cast*>(cb))(); // }; const auto id = icicle_add_syscall_hook(this->emu_, invoker, callback_store.get()); - this->syscall_hooks_[id] = std::move(callback_store); + this->hooks_[id] = std::move(callback_store); return reinterpret_cast(static_cast(id)); } @@ -273,14 +280,14 @@ namespace icicle void delete_hook(emulator_hook* hook) override { const auto id = static_cast(reinterpret_cast(hook)); - const auto entry = this->syscall_hooks_.find(id); - if (entry == this->syscall_hooks_.end()) + const auto entry = this->hooks_.find(id); + if (entry == this->hooks_.end()) { return; } icicle_remove_syscall_hook(this->emu_, id); - this->syscall_hooks_.erase(entry); + this->hooks_.erase(entry); } void serialize_state(utils::buffer_serializer& buffer, const bool is_snapshot) const override @@ -330,8 +337,7 @@ namespace icicle private: std::list> storage_{}; - using syscall_hook_storage = std::unique_ptr>; - std::unordered_map syscall_hooks_{}; + std::unordered_map> hooks_{}; icicle_emulator* emu_{}; };