better tb cache handling for hook add and del#2279
Open
PhilippTakacs wants to merge 2 commits intounicorn-engine:devfrom
Open
better tb cache handling for hook add and del#2279PhilippTakacs wants to merge 2 commits intounicorn-engine:devfrom
PhilippTakacs wants to merge 2 commits intounicorn-engine:devfrom
Conversation
Contributor
PhilippTakacs
commented
Jan 5, 2026
- clear tb cache when adding a block or code hook, fixes Unicorn 2: Hooks don't take effect on code which has already been executed. #2200
- only clear tb cache when deleting a block or code hook
wtdcode
reviewed
Jan 16, 2026
uc.c
Outdated
|
|
||
| if (type & UC_HOOK_CODE || type & UC_HOOK_BLOCK) { | ||
| if (end <= begin) { | ||
| uc_ctl_flush_tb(uc); |
Member
There was a problem hiding this comment.
One thing on my mind is that this might be dangerous in a hook context.
Assume we have call stack like uc_emu_start -> hook_code -> tb_flush, then the underlying memory of the current tb is invalidated immediately. I'm a bit forgetting details, what's your idea about this?
Contributor
Author
There was a problem hiding this comment.
I can either use break_translation_loop and do the tb clean in the emulation loop or use some invalidation like uc_hook_del is doing. I need some time to test this.
Code and Block hooks are implemented by adding the callback directly to the translation block. So when a hook is added after the code is already translated the tb cache needs to be cleared. see unicorn-engine#2200
c65e4cb to
82cbf62
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.