[C++] The address of a thread-local variable may change when a COM function is called?

Talk about things C/C++, some related to AutoHotkey
User avatar
thqby
Posts: 406
Joined: 16 Apr 2021, 11:18
Contact:

[C++] The address of a thread-local variable may change when a COM function is called?

Post by thqby » 04 Dec 2021, 09:58

The address of a thread-local variable may change when a COM virtual function is called???

Before calling the QueryInterface
1.png
1.png (91.44 KiB) Viewed 2874 times
Calling the QueryInterface
2.png
2.png (114.62 KiB) Viewed 2874 times

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [C++] The address of a thread-local variable may change when a COM function is called?

Post by HotKeyIt » 05 Dec 2021, 04:59

Do you mean &g? ThreadLocalStoragePointer does not change.
AFAIK g changes because it is called in new pseudo thread.
Can you provide example code.

User avatar
thqby
Posts: 406
Joined: 16 Apr 2021, 11:18
Contact:

Re: [C++] The address of a thread-local variable may change when a COM function is called?

Post by thqby » 06 Dec 2021, 00:22

Code: Select all

ahk := ComObject("AutoHotkey2.Script")
threadid := ahk.NewThread("Persistent`na := 0 ")

Sleep 100
ahk.ahkAssign(threadid, 'a', [55])
c++source https://github.com/thqby/AutoHotkey_H/blob/v2.0-beta.3-COM/source/COMServer.cpp#L197

An object outside a dll module enters the dll module of the same thread through the com interface, and then ThreadLocalStoragePointer of the DLL module has been replaced with another thread, and then calls QueryInterface, and the thread local variables are overwritten. But unable to find the source of this rewritten thread local variable from the known threads.

Perhaps the new thread local variable from the exe module in the thread corresponding to the current ThreadLocalStoragePointer.


Post Reply

Return to “C/C++”