CreateTimerQueueTimer在DllMain中调用导致的loader lock

开发一个COM组件在Windows 7上注册成功,但是Windows XP SP3版本却导致regsvr32.exe进程挂起。用WinDbg查看发现提示:

Break-in sent, waiting 30 seconds...
WARNING: Break-in timed out, suspending.
         This is usually caused by another thread holding the loader lock

竟然出现了加载锁,kb查看call stack:

0:000> kb
ChildEBP RetAddr  Args to Child              
0007dc00 7c92df3c 7c9546b0 000006e0 00000000 ntdll!KiFastSystemCallRet
0007dc04 7c9546b0 000006e0 00000000 00000000 ntdll!NtWaitForSingleObject+0xc
0007dc30 7c94dbde 7c885854 00000000 0007dc60 ntdll!RtlpInitializeTimerThreadPool+0xe1
0007dc40 7c82cbd2 7c885770 0007dd68 000c9184 ntdll!RtlCreateTimerQueue+0x3b
0007dc60 7c82cbed 0007dc90 0007dd68 00cd7ebd kernel32!BasepCreateDefaultTimerQueue+0x66
0007dc6c 00cd7ebd 000c9184 00000000 00c8b1c1 kernel32!CreateTimerQueueTimer+0x20

组件加载以后会调用Windows API CreateTimerQueueTimer创建一个Timer,regsvr32就是被这段代码给挂住了。

if (m_hTimer != nullptr)
    return;

SetCount(0);
::CreateTimerQueueTimer(&m_hTimer, NULL, OnTimer, this, 0, m_interval, WT_EXECUTEINTIMERTHREAD);
原文地址:https://www.cnblogs.com/junchu25/p/3614619.html