microsoft / Detours

Detours is a software package for monitoring and instrumenting API calls on Windows. It is distributed in source code form.
MIT License
5k stars 978 forks source link

hooking HeapAlloc in multi-thread triggers exception if there is thread_local variable used in hooked function #271

Open ElvisJazz opened 1 year ago

ElvisJazz commented 1 year ago

image

thread_local int g_cur_module_index = 0; thread_local MemoryModule g_memory_module[MAX_MEMORY_HOOK_RECURSIVE_DEEP] = {};

When I compile the program with Debug mode, the exception is not thrown. When I compile the program with Release mode, the exception is thown.

When I remove thread_local from g_cur_module_index and g_memory_module, the program runs OK in release mode。

Version 4.0.1 of Detours