On Monday, July 29, 2024, Sebastian Wittmeier wrote:
I think Thiago was referring to storing thread-local variables for reentrant intercepted function calls.
Pick a max recursion depth, let's say:
#define MAX_RECURSION (16u)
and then we have:
thread_local unsigned current_depth = 0u;
thread_local void *addresses[ MAX_RECURSION ];
No linked list and no dynamic allocation.
I'm typing this out on my phone right now and I don't have a compiler, and GodBolt is too big for my phone screen, but when I'm home later I'll show an implementation of an interceptor of a recursive function.
(Although in most cases, once you call the original function in the library, any subsequent recursive calls will directly call the original function, thus bypassing the interceptor -- however this won't necessarily happen in the case of a GUI loop, e.g. how wxWidgets starts a second message loop when you show a modal message box).