English 中文(简体)
这个 Windows API 调用 等待 SingleObject 有什么问题?
原标题:What s wrong with this Windows API call WaitForSingleObject?

在 Windows 7. 我使用 !analyze - v 命令在 winDbg 中进行例外分析, 无法将进程崩溃。 它显示以下信息。 例外实际上被 WaitForSingleObject 函数抛出, 该函数被称为 IrsSim! IrsNet_BlockOutput 。 WinDbg s 例外分析告诉我, 错误是 INvalID_POINTER_READ 错误 。

对于调用代码, pChannel- gt;hMutex 不是 NULLL 。 我已经丢弃它并检查了它的价值 。

IRSNETRET IrsNet_BlockOutput( IRSNET    *pChannel)
{

// Check channel
    IRSNET_CHECK_CHANNEL(pChannel);

// Wait for synchronization mutex
    switch(WaitForSingleObject(pChannel->hMutex, INFINITE))
    {
...
}

& lt;<< << <<

FAULTING_IP: IrsSim!Channel::SendIrsMessage+285 [s:som5icsscsvisv est.uirssimirsiftransport.cpp @ 539] 00520ed5 8b06 mov eax,dword ptr [esi]

EXCEPTION_RECORD: ffffffff -- (.exr 0xffffffffffffffff) ExceptionAddress: 77db4639 (ntdll!RtlDeactivateActivationContextUnsafeFast+0x00000058)
ExceptionCode: c0150010 ExceptionFlags: 00000001 NumberParameters: 3 Parameter[0]: 00000000 Parameter[1]: 07befc58 Parameter[2]: 00000000

灾难发生日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:日期:地点:地点:地点:地点:地点:地点,地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点,地点:地点:地点:地点:地点:地点,地点:地点:地点:地点:地点:地点:地点:地点,地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点,地点:地点:地点:地点:地点,地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点,地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点:地点

IrsSim.exe (IrsSim.exe) NAME: IrsSim.exe (IrsSim.exe)

ERROR_CODE: (NTSTATUS) 0xc0150010 - The activation context being deactivated is not active for the current thread of execution.

EXCEPTION_CODE: (NTSTATUS) 0xc0150010 - The activation context being deactivated is not active for the current thread of execution.

例外: 1: 000000

7bec58(7bec58)

3:000000

STACK_TEXT: 07d2fce0 00520ed5 irssim!Channel::SendIrsMessage+0x285 07d2fd1c 00521072 irssim!CChannelArray::SendIrsMessage+0x132 07d2fd50 0052208a irssim!CNetLibInterface::SendIrsMessage+0xba 07d2fd78 005c01b6 irssim!CSendActivity::Execute+0x76 07d2fdac 005e0b3f irssim!SimulationThreadState::ExecuteOneActivity+0x11f 07d2fdf8 005cc937 irssim!CSimulationSubThreadState::ExecuteState+0x267 07d2fe8c 005ccf02 irssim!ThreadFctSubSimulation+0xf2 07d2fec4 73b1e3ee mfc90u!_AfxThreadEntry+0xf2 07d2ff4c 739f3433 msvcr90!_endthreadex+0x44 07d2ff84 739f34c7 msvcr90!_endthreadex+0xd8 07d2ff90 767d339a kernel32!BaseThreadInitThunk+0xe 07d2ff9c 77d69ed2 ntdll!__RtlUserThreadStart+0x70 07d2ffdc 77d69ea5 ntdll!_RtlUserThreadStart+0x1b

_____________________________________________________________________________________________________________________________________________________________________________________________

在那之后,我使用 ieteb 命令 尝试获得更多的堆叠信息 。

0:011> k L=07beec2c 100 ChildEBP RetAddr 07bef54c 76be0bdd ntdll!NtWaitForMultipleObjects+0x15 07bef5e8 767d1a2c KERNELBASE!WaitForMultipleObjectsEx+0x100 07bef630 767d4208 kernel32!WaitForMultipleObjectsExImplementation+0xe0 07bef64c 767f80a4 kernel32!WaitForMultipleObjects+0x18 07bef6b8 767f7f63 kernel32!WerpReportFaultInternal+0x186 07bef6cc 767f7858 kernel32!WerpReportFault+0x70 07bef6dc 767f77d7 kernel32!BasepReportFault+0x20 07bef768 77da21d7 kernel32!UnhandledExceptionFilter+0x1af 07bef770 77da20b4 ntdll!__RtlUserThreadStart+0x62 07bef784 77da1f59 ntdll!_EH4_CallFilterFunc+0x12 07bef7ac 77d76ab9 ntdll!_except_handler4+0x8e 07bef7d0 77d76a8b ntdll!ExecuteHandler2+0x26 07bef7f4 77d76a2d ntdll!ExecuteHandler+0x24 07bef880 77d40143 ntdll!RtlDispatchException+0x127 07bef880 77db4639 ntdll!KiUserExceptionDispatcher+0xf 07befc34 76be0ad7 ntdll!RtlDeactivateActivationContextUnsafeFast+0x58 07befc38 76be0abc KERNELBASE!WaitForSingleObjectEx+0xde 07befc98 767d1194 KERNELBASE!WaitForSingleObjectEx+0xc3 07befcb0 767d1148 kernel32!WaitForSingleObjectExImplementation+0x75

07fcc4 005e3b6e 内核32! 等待单排对象+0x12

07fcd4 00520d3b IrsSim! IrsNet_ Block 输出+0x1e

07befd14 00521072 IrsSim!Channel::SendIrsMessage+0xeb 07befd48 0052208a IrsSim!CChannelArray::SendIrsMessage+0x132 07befd70 005c01b6 IrsSim!CNetLibInterface::SendIrsMessage+0xba 07befda4 005e0b3f IrsSim!CSendActivity::Execute+0x76 07befdf0 005cc937 IrsSim!SimulationThreadState::ExecuteOneActivity+0x11f 07befe84 005ccf02 IrsSim!CSimulationSubThreadState::ExecuteState+0x267 07befebc 73b1e3ee IrsSim!ThreadFctSubSimulation+0xf2 07beff44 739f3433 mfc90u!_AfxThreadEntry+0xf2 07beff7c 739f34c7 msvcr90!_endthreadex+0x44 07beff88 767d339a msvcr90!_endthreadex+0xd8 07beff94 77d69ed2 kernel32!BaseThreadInitThunk+0xe 07beffd4 77d69ea5 ntdll!__RtlUserThreadStart+0x70 07beffec 00000000 ntdll!_RtlUserThreadStart+0x1b

_____________________________________________________________________________________________________________________________________________________________________________________________====>>>>>>

问题回答

这看起来与 MFC 应用程序中遇到的 0xC015000f 例外非常相似 (“被禁用的激活环境不是最近激活的环境 ” ) 。

在我遇到这一例外的所有情况中,例外并不是主要问题。 它是一个早期例外的副作用, 通常是违反访问权, 堆叠没有正确损坏。 在例外处理中, 缺少一个使用 AFX_ MANAGE_ StATE 宏等宏的呼叫框架。 结果, 下一次激活环境被操纵, 比如, 另一个例行程序导致呼叫 AFX_ MAINSTEN_STATE2: ~ AFX_ MAINESEN_STATE2, 系统检测到一个曲奇的错配, 并抛出例外 。

在您的情况中, 您可能会在其中的一条代码中造成例外( 很可能是 AV ), 然后通过上下文例外来显示 。 要捕捉根源, 请先运行调试器, 并启用首机例外处理 。 这样, 被某个可能使用试捕(...) 的人困在别处呼叫框上的 AV 将会暴露出来 。 由于您似乎正在串线, 您可能只是拥有导致主要例外的记忆存取的种族条件( 如果这确实正在发生的话 ) 。

I see in a previous post: "In fact, this problem comes from porting the program from 64-bit Win XP to 64-bit Win7. The compiler is switched therefore from VC6 to VC9. "

这不是MFC中的错误。 MFC 6 不包括在2005 视觉工作室中添加的激活背景切换代码( 基于 cookie ) 。 我认为, 因此您不会遇到这一例外。 我们太认为更新的 MFC 存在问题, 但在我们遇到的每一个案例中,都是我们的代码造成了问题。 最初的问题被代码流掩盖了, 代码流是从试捕( 通常... ) 开始的。 最初的代码流( 通常... ) 最终被称为代码, 使用一个 MFC 管理状态宏, 然后在最终会发生 AV 的地方调用更多的代码。 由于捕获是堆叠的, 并且取决于腐败, 不是所有框架都无法正确调整。 因此, MFC 宏的背面被忽略了( 某些破坏者没有弹出它的上下文 ) 。 更糟糕的是, 最终的环境崩溃可能发生在您的代码中任何地方( 我们在CWnd s base mess 信件处理路径方法中经历了很多次 ) 。 我们最终为一个用户创建了另一个工具, 将自己作为解发目标的驱动器。, 。

以这种方式失败的唯一办法是,如果:

pChannel->hMutex

无效。 要么 pChannel 本身被插入, 要么 hMutex 。 很可能是前者 。

您应该检查控点是否无效, 不仅仅是 NULLL , 诸如 :

if (myHandle != INVALID_HANDLE_VALUE)
{
    // do something
}

通常情况下, 如果出现错误, 创建控件函数会返回此值 。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签