Unicorn upgrade (#491)

This commit is contained in:
Maurice Heumann
2025-08-24 12:29:11 +02:00
committed by GitHub
4 changed files with 23 additions and 10 deletions

2
.gitmodules vendored
View File

@@ -2,7 +2,7 @@
path = deps/unicorn
url = https://github.com/momo5502/unicorn.git
shallow = true
branch = wasm
branch = dev
[submodule "deps/reflect"]
path = deps/reflect
url = https://github.com/qlibs/reflect.git

2
deps/unicorn vendored

View File

@@ -2,12 +2,13 @@
#include "unicorn_x86_64_emulator.hpp"
#include <array>
#include <ranges>
#include <optional>
#include "unicorn_memory_regions.hpp"
#include "unicorn_hook.hpp"
#include "function_wrapper.hpp"
#include <ranges>
namespace unicorn
{
@@ -214,8 +215,9 @@ namespace unicorn
void start(const size_t count) override
{
this->has_violation_ = false;
const auto start = this->read_instruction_pointer();
const auto start = this->violation_ip_.value_or(this->read_instruction_pointer());
this->violation_ip_ = std::nullopt;
constexpr auto end = std::numeric_limits<uint64_t>::max();
const auto res = uc_emu_start(*this, start, end, 0, count);
if (res == UC_ERR_OK)
@@ -231,7 +233,7 @@ namespace unicorn
res == UC_ERR_WRITE_PROT || //
res == UC_ERR_FETCH_PROT;
if (!is_violation || !this->has_violation_)
if (!is_violation || !this->has_violation())
{
uce(res);
}
@@ -487,14 +489,22 @@ namespace unicorn
const auto resume =
c(address, static_cast<uint64_t>(size), operation, violation) == memory_violation_continuation::resume;
const auto has_ip_changed = ip != this->read_instruction_pointer();
const auto new_ip = this->read_instruction_pointer();
const auto has_ip_changed = ip != new_ip;
if (!resume)
{
return false;
}
this->has_violation_ = resume && has_ip_changed;
if (resume && has_ip_changed)
{
this->violation_ip_ = new_ip;
}
else
{
this->violation_ip_ = std::nullopt;
}
if (has_ip_changed)
{
@@ -659,7 +669,7 @@ namespace unicorn
bool has_violation() const override
{
return this->has_violation_;
return this->violation_ip_.has_value();
}
std::string get_name() const override
@@ -670,7 +680,7 @@ namespace unicorn
private:
mutable bool has_snapshots_{false};
uc_engine* uc_{};
bool has_violation_{false};
std::optional<uint64_t> violation_ip_{};
std::vector<std::unique_ptr<hook_object>> hooks_{};
std::unordered_map<uint64_t, mmio_callbacks> mmio_{};
};

View File

@@ -459,11 +459,14 @@ void windows_emulator::setup_hooks()
const auto ticks = this->clock_->timestamp_counter();
this->emu().reg(x86_register::rax, ticks & 0xFFFFFFFF);
this->emu().reg(x86_register::rdx, (ticks >> 32) & 0xFFFFFFFF);
return instruction_hook_continuation::skip_instruction;
});
// TODO: Unicorn needs this - This should be handled in the backend
this->emu().hook_instruction(x86_hookable_instructions::invalid, [&] {
// TODO: Unify icicle & unicorn handling
dispatch_illegal_instruction_violation(this->emu(), this->process);
return instruction_hook_continuation::skip_instruction; //
});