-
Notifications
You must be signed in to change notification settings - Fork 1.5k
add uc_hook_set_user_data #2274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
dca893c
316d92a
dce4d80
b6069af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2060,6 +2060,24 @@ uc_err uc_hook_del(uc_engine *uc, uc_hook hh) | |
| return UC_ERR_OK; | ||
| } | ||
|
|
||
| UNICORN_EXPORT | ||
| uc_err uc_hook_set_user_data(uc_engine *uc, uc_hook hh, void *user_data) | ||
| { | ||
| struct hook *hook = (struct hook *)hh; | ||
| if (hook->type == UC_HOOK_BLOCK || hook->type == UC_HOOK_CODE) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait why do we exclude these two types?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the callbacks are directly called by the tb with the user_data pointer written to the tb. It would require to rebuild the tb to allow change the user_data.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's correct. Can we inline the pointer to the hook struct in the tb instead? In that case, the modification to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No because there is no wrapper function in unicorn for these hooks. The cb function is directly called. I could write a wrapper function which just use the hook_struct. This might affect performance which I would like to avoid in the block case.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh okay, I see. I forgot the inline optimization. A wrapper would hurt performance quite a lot. Spare me some time to think about if we have better ways.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a bit more context, not enabling inlining for more than 1 hooks was due to a bad hack in tcg_optimize leading to segfault at that time. Since I removed the hack recently, we could extend inlining to any number of hooks.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I somehow misinterpreted what this code is doing, thanks for explaining.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I would also recommend not allowing changing data during emulation.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I guess this can be merged now?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, look good now except the small typo and documents above. |
||
| if (uc->nested_level) { | ||
| return UC_ERR_ARG; | ||
| } | ||
| if (hook->end < hook->begin) { | ||
| uc->tb_flush(uc); | ||
| } else { | ||
| uc->uc_invalidate_tb(uc, hook->begin, hook->end - hook->begin); | ||
| } | ||
| } | ||
| hook->user_data = user_data; | ||
| return UC_ERR_OK; | ||
| } | ||
|
|
||
| // TCG helper | ||
| // 2 arguments are enough for most opcodes. Load/Store needs 3 arguments but we | ||
| // have memory hooks already. We may exceed the maximum arguments of a tcg | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documents are not updated here (return error during emulation) and
UC_ERR_ARGSseems a typo.