TLS Callbacks
id:NyaRuRu:20051220#p2 ç¶ç·¨ï¼
Windows Server 2003以éï¼ããã«ã¯Windows XP Professional x64 Editionãå«ã¾ããï¼ã®OSã§ã¯ãFlsAllocã使ç¨ãããã¨ã§ããã¡ã¤ãçµäºæã«OSããã³ã¼ã«ããã¯ãåãããã¨ãã§ããããã«ãªãã¾ããããã¡ã¤ããã¼ã«ã«ã¹ãã¬ã¼ã¸ï¼FLSï¼ã¯ããã¡ã¤ããå ¨ã使ç¨ããªãå ´åã§ãTLSã®ä»£ç¨ã¨ãã¦ä½¿ç¨ã§ãã¾ãããã®ããVisual C++ .NET 2003ã®CRTãVisual C++ 2005ã®CRTã¯ãå¯è½ã§ããã°ãã¡ã¤ããã¼ã«ã«ã¹ãã¬ã¼ã¸ãå©ç¨ãããã¨ã§ã確å®ã«ç®¡çãããã¯ãéæ¾ããããã«ãªã£ã¦ãã¾ãããã®ãããªéè¦ãªã³ã¼ã«ããã¯ã¡ã«ããºã ããå¾æ¥ã®TLSã«ã¯æ¬ å¦ãã¦ããã¨è¨ããã§ãããã
ããããªããï¼Win32 Thread Local Storage (TLS) ã«ã³ã¼ã«ããã¯ã¡ã«ããºã ã¯åå¨ãã¦ï¼google:"TLS Callbacks" ã¨ããã®ãããããã§ã*1ï¼
TLS Callbacks 㯠PE ãããä¸ã«ã³ã¼ã«ããã¯é¢æ°ãç»é²ãã¦ãããã¨ã§ EXE ãã¡ã¤ã«ã§ã DllMain ç¸å½ã®éç¥ãåããããã¨ãããã®ã§ãï¼
http://www.interq.or.jp/chubu/r6/reasm/PE_FORMAT/6_6_2.html
Windows 2000ï¼Windows XP ã§ã¯ä»¥ä¸ã®ã³ã¼ããä»ã足ããã¨ã§ãµã³ãã«ããã°ã©ã ã§ãã¡ã¢ãªãªã¼ã¯ãçºçããªããªããã¨ã確èªãã¾ããï¼
namespace { extern "C" void __cdecl _freeptd (void *); void NTAPI tls_callback( void*, DWORD dwReason, void* ) { if(dwReason == DLL_THREAD_DETACH) { _freeptd(NULL); } } // Add callback to the TLS callback list in TLS directory. #pragma data_seg(push, old_seg) #pragma data_seg(".CRT$XLB") DWORD tls_callback_ptr = (DWORD)tls_callback; #pragma data_seg(pop, old_seg) extern "C" int _tls_used; int dummy() { return _tls_used; } }
ã¾ã Windows 98 SE 㧠TLS Callbacks ãå¼ã³åºãããªããã¨ã確èªãã¾ããï¼
Thread-Local-Storage Callbacks are a seldom used feature of Portable Executables. Many compilers and linkers, including Microsoft's, do not fully support TLS callbacks, or have a buggy implementation. Furthermore, they are not universally supported on all Windows platforms. Win9x does not execute them under all conditions (i.e. program load), while WinNT does.
ã¨ããããã«ï¼Windows 9x ã§ã¯ TLS Callbacks ã¯ãµãã¼ãããã¦ããªãããã§ãï¼
CodeZine ã®è¨äºã¯ææã«ã§ãè¨æ£å
¥ãã¦ããã¾ãï¼
*1:TLS Callbacks ã®åå¨ã«ã¤ãã¦ã¯ boost ML ã®ãWindows MSVC thread exit handler for staticly linked Boost.Threadãã§ã®è°è«ã§ç¥ãã¾ããï¼ãã®ãããã¯æ£ç´ Advanced Windows ã§ã足ãã¦ãªãæãã§ãï¼