[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: 560
Joined: 16 Apr 2021, 11:18
Contact:

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

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 4971 times
Calling the QueryInterface
2.png
2.png (114.62 KiB) Viewed 4971 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?

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: 560
Joined: 16 Apr 2021, 11:18
Contact:

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

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.

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 7 guests