You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the library consumer side, one solution is to use a lock (perhaps a read/write lock) when accessing the original function pointer and when setting or removing hooks. However, this is not optimal or convenient, and currently isn't documented as a requirement.
On the SlimDetours side, I'm not sure what's the best solution.
If we want to keep the library usage unchanged, we have to make sure that the pointer to call the hook isn't freed. The only way I can think of that's truly guaranteed to be correct is to just never free the trampoline, which is of course suboptimal.
If we want to consider changing the library, perhaps we can introduce a helper function to call the original function, such as:
Then, we can handle the case of a thread being suspended within this function. This approach is also not optimal, both due to the library change and the non-trivial implementation.
Let me know if you come up with a solution I didn't think of.
The text was updated successfully, but these errors were encountered:
one solution is to use a lock (perhaps a read/write lock) when accessing the original function pointer and when setting or removing hooks
It's okay for me to add a function to access the original function pointer if it's optional. The caller could choose use it for more safety, or don't use it for more convenient and keep existing code. We could use lock, ref count, ... to make it safer in different scenarios if needed, what do you think?
The solution I selected for my specific needs with specific constraints is a combination of #19 (pending review/merge) and m417z/thread-call-stack-scanner.
In any case, since there's no easy way to address this in the library without API changes, I think it'd be a good idea to document this limitation (and #15) in the TechWiki.
Consider two threads running in parallel as follows:
If all goes right, the output should be:
And indeed that's what happens most of the time, but there's a problem here.
Consider what happens when these two parts run in parallel:
Thread 1
Thread 2
What can happen is:
pOutputDebugStringWOriginal
, but doesn't yet use it for the actual call.pOutputDebugStringWOriginal
back toOutputDebugStringW
and freezes the trampoline.I noticed this problem only on ARM64. I think that the reason is that while in x86/x64, the call can be a single instruction:
On ARM64, the call is done with multiple instructions which load the address first, something like:
On the library consumer side, one solution is to use a lock (perhaps a read/write lock) when accessing the original function pointer and when setting or removing hooks. However, this is not optimal or convenient, and currently isn't documented as a requirement.
On the SlimDetours side, I'm not sure what's the best solution.
Let me know if you come up with a solution I didn't think of.
The text was updated successfully, but these errors were encountered: