microsoft / microsoft/Detours

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

Open
#271 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
C++
Stars
6.4k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with Detours 4.0.1 using the shown thread_local globals and a function that hooks HeapAlloc. Compare Debug and Release builds, then verify that the Release build no longer throws the reported exception while thread_local remains in use.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.