使用 beginthreadex 创建线程时调试应用程序挂起
我在现场遇到一个奇怪的问题,我们的应用程序在启动时挂起。 我得到了现场自定义生成的故障转储,它显示主线程被 beginthreadex api 卡住了。 这是调用堆栈:
0:006> kv
ChildEBP
0161ebb8 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
0161ebbc ntdll!ZwWaitForSingleObject+0xc (FPO: [3,0,0])
0161ebf8 ntdll!RtlpWaitOnCriticalSection+0x1a3 (FPO: [2,7,4])
0161ec18 ntdll!RtlEnterCriticalSection+0xa8 (FPO: [1,1,0])
0161ec4c ntdll!LdrLockLoaderLock+0x133 (FPO: [SEH])
0161ecc8 ntdll!LdrGetDllHandleEx+0x94 (FPO: [SEH])
0161ece4 ntdll!LdrGetDllHandle+0x18 (FPO: [4,0,0])
0161ed30 kernel32!GetModuleHandleForUnicodeString+0x20 (FPO: [SEH])
0161f1a8 kernel32!BasepGetModuleHandleExW+0x17f (FPO: [SEH])
0161f1c0 kernel32!GetModuleHandleW+0x29 (FPO: [1,0,0])
0161f1cc kernel32!GetModuleHandleA+0x2d (FPO: [1,0,0])
0161f204 msvcr80!initptd+0x17
0161f224 msvcr80!beginthreadex+0x56
0161f248 ZQCommonStlp!ZQ::common::NativeThread::NativeThread+0x59 (FPO: [Non-Fpo]) (CONV: thiscall)
...
我从这个调用堆栈中没有得到任何信息,但只知道主线程在创建新线程时被卡住。 这是系统问题吗?
I encounter a strange problem on site that our application get hung while starting.
I get the crashdump generated by custom on site, and it shows that the main thread was stuck by beginthreadex api.
Here's the callstack:
0:006> kv
ChildEBP
0161ebb8 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
0161ebbc ntdll!ZwWaitForSingleObject+0xc (FPO: [3,0,0])
0161ebf8 ntdll!RtlpWaitOnCriticalSection+0x1a3 (FPO: [2,7,4])
0161ec18 ntdll!RtlEnterCriticalSection+0xa8 (FPO: [1,1,0])
0161ec4c ntdll!LdrLockLoaderLock+0x133 (FPO: [SEH])
0161ecc8 ntdll!LdrGetDllHandleEx+0x94 (FPO: [SEH])
0161ece4 ntdll!LdrGetDllHandle+0x18 (FPO: [4,0,0])
0161ed30 kernel32!GetModuleHandleForUnicodeString+0x20 (FPO: [SEH])
0161f1a8 kernel32!BasepGetModuleHandleExW+0x17f (FPO: [SEH])
0161f1c0 kernel32!GetModuleHandleW+0x29 (FPO: [1,0,0])
0161f1cc kernel32!GetModuleHandleA+0x2d (FPO: [1,0,0])
0161f204 msvcr80!initptd+0x17
0161f224 msvcr80!beginthreadex+0x56
0161f248 ZQCommonStlp!ZQ::common::NativeThread::NativeThread+0x59 (FPO: [Non-Fpo]) (CONV: thiscall)
...
I get nothing from this callstack but just know the main thread was stuck while creating a new thread.
Is this a system problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否在 DllMain(或某些 DLL 初始化)中旋转该线程?臭名昭著的装载机锁似乎陷入了僵局。有关 DllMain 中允许的内容(非常少)的详细信息,请参阅以下文档:
在本例中,运行时函数
_initptd()
正在调用GetModuleHandle(" KERNEL32.DLL”)
。作为参考,这里有一些有关加载程序锁的链接可能会有所帮助,无论您是否有 DllMain:
DllMain 的文档,其中有一些严厉的警告: microsoft.com/en-us/library/ms682583.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms682583.aspx
以及 Raymond 的链接盛会陈的“旧新事物”:
Are you spinning up this thread in DllMain (or some DLL initialization)? It seems to be deadlocked on the infamous loader lock. See the following docs for details of what's allowed (very little) in DllMain:
In this particular case, the runtime function
_initptd()
is callingGetModuleHandle("KERNEL32.DLL")
.For reference, here's a number of links about the loader lock that might be helpful, whether or not you have a DllMain in the mix:
The docs for DllMain, which has some stern warnings: http://msdn.microsoft.com/en-us/library/ms682583.aspx
And a link-fest from Raymond Chen's "Old New Thing":
好吧,它正在等待获取正在运行的(HMODULE)可执行文件的模块。您可能想查看是否打开了这样的句柄,尤其是当它被锁定以供共享读取时。
也许来自 Sysinternals (Microsoft) 的
procexp.exe
可以帮助找到被阻塞的句柄。或者您可以仔细检查任何 HMODULE 句柄、LoadLibrary 调用以找到罪魁祸首Well it is waiting to get the module for the running (HMODULE) executable. You might want to see whether you have opened such a handle, especially when it is locked for shared reading.
Perhaps
procexp.exe
from Sysinternals (Microsoft) could help finding the blocked handle. Or you can scrutinize any HMODULE handles, LoadLibrary calls to find the culprit