Skip to content

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

Open
m417z wants to merge 1 commit intoKNSoft:mainfrom
m417z:attach-hook-chain
Open

Chain multiple hooks to the same function in a single transaction#10
m417z wants to merge 1 commit intoKNSoft:mainfrom
m417z:attach-hook-chain

Conversation

@m417z
Copy link
Copy Markdown

@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.

@RatinCN RatinCN assigned RatinCN and unassigned RatinCN Apr 16, 2025
@RatinCN RatinCN added the enhancement New feature or request label Apr 16, 2025
@RatinCN RatinCN force-pushed the main branch 2 times, most recently from 8937581 to 30ff0bc Compare September 4, 2025 08:45
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.
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