Re: [Trick] DllMain нотификации без DLL
От: gear nuke  
Дата: 29.03.08 23:05
Оценка:
Здравствуйте, remark, Вы писали:

R> static __declspec(thread) int volatile use_tls;


Мда, жаль, что MS сами не доделали... всего-то нужно убрать ограничение "Only POD classes may be instantiated using __declspec(thread)".


По поводу DLL_PROCESS_ATTACH — может быть просто с логированием проблемы? Хотя если и так используется CRT (всё же решение не чистое WinAPI, где вручную определяется IMAGE_TLS_DIRECTORY) вот фрагмент _cinit:
#ifndef CRTDLL
        /*
         * If we have any dynamically initialized __declspec(thread)
         * variables, then invoke their initialization for the thread on
         * which the DLL is being loaded, by calling __dyn_tls_init through
         * a callback defined in tlsdyn.obj.  We can't rely on the OS
         * calling __dyn_tls_init with DLL_PROCESS_ATTACH because, on
         * Win2K3 and before, that call happens before the CRT is
         * initialized.
         */
        if (__dyn_tls_init_callback != NULL &&
            _IsNonwritableInCurrentImage((PBYTE)&__dyn_tls_init_callback))
        {
            __dyn_tls_init_callback(NULL, DLL_THREAD_ATTACH, NULL);
        }
#endif  /* CRTDLL */

То есть можно посмотреть tlsdyn.c и вместо нового TLS callback зарегистрировать поинтер ".CRT$XDU", который будет вызван из __dyn_tls_init (и кода выше).
People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird (c) D.Knuth
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.