Page 1 of 1
[C++] The address of a thread-local variable may change when a COM function is called?
Posted: 04 Dec 2021, 09:58
by thqby
The address of a thread-local variable may change when a COM virtual function is called???
Before calling the
QueryInterface
- 1.png (91.44 KiB) Viewed 3165 times
Calling the
QueryInterface
- 2.png (114.62 KiB) Viewed 3165 times
Re: [C++] The address of a thread-local variable may change when a COM function is called?
Posted: 05 Dec 2021, 04:59
by HotKeyIt
Do you mean &g? ThreadLocalStoragePointer does not change.
AFAIK g changes because it is called in new pseudo thread.
Can you provide example code.
Re: [C++] The address of a thread-local variable may change when a COM function is called?
Posted: 06 Dec 2021, 00:22
by thqby
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.
Re: [C++] The address of a thread-local variable may change when a COM function is called?
Posted: 06 Dec 2021, 12:41
by HotKeyIt
Yes in that case the thread will be from exe.