????????_beginthreadex?????????????

????1?? ?????????????????_tiddata???飬???????C/C++???п????heap?????????

????2??????_beginthreadex??????????????????_tiddata?????С?

????3??_beginthreadex?????????????CreateThread??????????????????????????????????????

????4??CreateThread?????????????????????????????_threadstartex??????pfnStartAddr?????????????????_tiddata????????????pvParam??

????5???????????????????????????CreateThread???????κβ???????????0??

??????????????_tiddata??????????????????????????????????


 static   unsigned  long   WINAPI _threadstartex (void* ptd) {

                // Note: ptd is the address of this thread's tiddata block.
                // Associate the tiddata block with this thread so

                // _getptd() will be able to find it in _callthreadstartex.

              TlsSetValue(__tlsindex?? ptd);
               // Save this thread ID in the _tiddata block.
               ((_ptiddata) ptd)->_tid = GetCurrentThreadId();

             // Initialize floating-point support (code not shown).

            // call helper function.
          _callthreadstartex ();
            // We never get here; the thread dies in _callthreadstartex.
           return(0L);
        }

    static void _callthreadstartex(void) {
              _ptiddata ptd; /* pointer to thread's _tiddata struct */

             // get the pointer to thread data from TLS
           ptd = _getptd();

         // Wrap desired thread function in SEH frame to
       // handle run-time errors and signal support.
    __try {
              // Call desired thread function?? passing it the desired parameter.
             // Pass thread's exit code value to _endthreadex.
    _endthreadex (
              ((unsigned (WINAPI *)(void *))(((_ptiddata)ptd)->_initaddr))
               (((_ptiddata)ptd)->_initarg)) ;
    }
    __except(_XcptFilter(GetExceptionCode()?? GetExceptionInformation())){

     // The C run-time's exception handler deals with run-time errors

    // and signal support; we should never get it here.

        _exit(GetExceptionCode());
      }
 }
 


????????_threadstartex???????????????????

????1???μ???????????RtlUserThreadStart????NTDLL.dll????У?????????????_threadstartex??

????2??_threadstartex?????????????_tiddata?????????

????3??TlsSetValue???????????????????????????????????????????????????ν????????洢??Thread Local Storage??TLS????_threadstartex??????_tiddata?????????????????????

????4??????????????????_callthreadstartex?У??????SEH?????????????е?????????Χ?????????????????????п??й?????????—?????????????

????5????????е????????????????????????????????????????????????????TLS??_tiddata??????У???????_callthreadstartex?д?TLS?л????

????6????????????????????????????????