加载dll时发生访问冲突
普通 C 应用程序在 MSVC6 上编译良好,但在运行时会引发访问冲突。
在 WinDbg 中运行应用程序时,加载 rasadhlp.dll(Windows 文件)时出现 AV 错误。
问题:加载 Windows dll 时什么可能导致访问冲突?
我习惯于在各种尼克斯而不是窗口上工作,所以可能有一些非常明显的东西我错过了。
[...]
ModLoad: 77920000 77a13000 C:\WINDOWS\system32\SETUPAPI.dll
ModLoad: 76fc0000 76fc6000 C:\WINDOWS\system32\rasadhlp.dll
(f38.a08): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=00000000 ecx=00000000 edx=0049f8f0 esi=0049f8f0 edi=00000000
eip=7c918fea esp=0012fbdc ebp=0012fc50 iopl=0 nv up ei ng nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010286
ntdll!RtlpWaitForCriticalSection+0x5b:
7c918fea ff4010 inc dword ptr [eax+10h] ds:0023:00000010=????????
0:000> g
(f38.a08): Access violation - code c0000005 (!!! second chance !!!)
eax=00000000 ebx=00000000 ecx=00000000 edx=0049f8f0 esi=0049f8f0 edi=00000000
eip=7c918fea esp=0012fbdc ebp=0012fc50 iopl=0 nv up ei ng nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000286
ntdll!RtlpWaitForCriticalSection+0x5b:
7c918fea ff4010 inc dword ptr [eax+10h] ds:0023:00000010=????????
注:该应用程序在win2k上编译,在XP上测试。 (由于各种奇怪的原因,现在无法更改...)
[编辑]:程序跟踪:
ntdll!RtlpWaitForCriticalSection+0x5b
ntdll!RtlEnterCriticalSection+0x46
msvcrt!vprintf+0x18
intl!libintl_vfprintf+0xa8
intl!libintl_fprintf+0x1f
image00400000+0x6239
MSCTF!DllGetClassObject+0x1de9
ntdll!RtlpNtMakeTemporaryKey+0x7ec8
ntdll!RtlInitializeSListHead+0x115c0
ntdll!iswdigit+0x339
ntdll!LdrGetProcedureAddress+0x4b
image00400000+0x626f4
[编辑2]:我知道异常首先被调试器捕获,这是完全正常的。您会在日志中注意到我手动跳过了第一次机会异常,并强制它进入我的程序。我想知道这种错误的根源,而不是处理。
A plain C application compiles fine on MSVC6, but when running, it raises an Access violation.
When running the app in WinDbg, I get the AV error raised when loading rasadhlp.dll (a windows file).
Question: What could possibly cause an access violation when loading a windows dll?
I'm used to working on the various nixes rather than windows, so there might be something really obvious that I'm missing.
[...]
ModLoad: 77920000 77a13000 C:\WINDOWS\system32\SETUPAPI.dll
ModLoad: 76fc0000 76fc6000 C:\WINDOWS\system32\rasadhlp.dll
(f38.a08): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=00000000 ecx=00000000 edx=0049f8f0 esi=0049f8f0 edi=00000000
eip=7c918fea esp=0012fbdc ebp=0012fc50 iopl=0 nv up ei ng nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010286
ntdll!RtlpWaitForCriticalSection+0x5b:
7c918fea ff4010 inc dword ptr [eax+10h] ds:0023:00000010=????????
0:000> g
(f38.a08): Access violation - code c0000005 (!!! second chance !!!)
eax=00000000 ebx=00000000 ecx=00000000 edx=0049f8f0 esi=0049f8f0 edi=00000000
eip=7c918fea esp=0012fbdc ebp=0012fc50 iopl=0 nv up ei ng nz na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000286
ntdll!RtlpWaitForCriticalSection+0x5b:
7c918fea ff4010 inc dword ptr [eax+10h] ds:0023:00000010=????????
Note: The app is compiled on win2k, tested on XP. (which, for various weird reasons, can't be changed right now...)
[edit]: program trace:
ntdll!RtlpWaitForCriticalSection+0x5b
ntdll!RtlEnterCriticalSection+0x46
msvcrt!vprintf+0x18
intl!libintl_vfprintf+0xa8
intl!libintl_fprintf+0x1f
image00400000+0x6239
MSCTF!DllGetClassObject+0x1de9
ntdll!RtlpNtMakeTemporaryKey+0x7ec8
ntdll!RtlInitializeSListHead+0x115c0
ntdll!iswdigit+0x339
ntdll!LdrGetProcedureAddress+0x4b
image00400000+0x626f4
[edit 2]: I know that the exception is first caught by the debugger, and that this is completely normal. You'll notice in the log that I manually skip over the first-chance exception, and force it to rise into my program. I'm wondering about the origin of such an error, rather than the handling.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
加载库时,
RtlpWaitForCriticalSection
中的访问冲突通常是由于库尝试在 DllMain 中使用 LoadLibrary 或 kernel32.dll 之外的代码引起的,因为操作系统在调用该例程时持有“加载程序锁”。Access violations in
RtlpWaitForCriticalSection
when loading a library, is typically caused by the library trying to use LoadLibrary or code outside of kernel32.dll, in DllMain since the OS holds a "loader lock" while calling that routine.请参阅 Microsoft 支持- 第一次和第二次机会异常处理
See Microsoft support - First and second chance exception handling