Skip to content

Chain multiple hooks to the same function in a single transaction #10

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

m417z
Copy link

@m417z m417z commented Apr 4, 2025

Currently, it's assumed that there can only be a single operation per target function in a single transaction. Attaching multiple hooks to the same function doesn't work properly, and removing one hook and setting another doesn't work either.

This change addresses this limitation as following:

  • Hook addition operations are done before hook removal operations during the commit. Hook addition relies on the disassembly of the original function as it was seen before the commit started. Hook removal operations may modify the function and invalidate this assumption.
  • Consecutive hook addition operations for the same target are now chained.

Note that hook removal operations handle the case of the function changing during the commit. In this case, the hook will be put in bypass mode, resulting in a correct removal of the hook but in a memory leak for the allocated trampoline. This case can be optimized in the future.

Currently, it's assumed that there can only be a single operation per
target function in a single transaction. Attaching multiple hooks to the
same function doesn't work properly, and removing one hook and setting
another doesn't work either.

This change addresses this limitation as following:

* Hook addition operations are done before hook removal operations
  during the commit. Hook addition relies on the disassembly of the
  original function as it was seen before the commit started. Hook
  removal operations may modify the function and invalidate this
  assumption.
* Consecutive hook addition operations for the same target are now
  chained.

Note that hook removal operations handle the case of the function
changing during the commit. In this case, the hook will be put in bypass
mode, resulting in a correct removal of the hook but in a memory leak
for the allocated trampoline. This case can be optimized in the future.
@RatinCN RatinCN assigned RatinCN and unassigned RatinCN Apr 16, 2025
@RatinCN RatinCN added the enhancement New feature or request label Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants