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

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

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

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

Post by HotKeyIt » 06 Dec 2021, 12:41

Yes in that case the thread will be from exe.

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.

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.

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

Top