windows驱动使用 c++try块 有时会出现问题

GKatHere 2018-10-10 05:48:21

// 各位,这是什么问题?
__try
{
return; // 特殊的地方,如果__try块中return, 卸载时产生APC_INDEX_MISMATCH错误
}__finally
{
}

struct A{A(){}; ~A(){}};
A a; // 特殊的地方,如果有析构类, 卸载时产生APC_INDEX_MISMATCH错误


...全文
185 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
curious_cat 2018-11-06
  • 打赏
  • 举报
回复
WDK的内核驱动范例里面还没有发现使用try..catch的。 MS doc says "Note that structured exception handling is distinct from C++ exceptions. The kernel does not support C++ exceptions." in https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/handling-exceptions
  • 打赏
  • 举报
回复
Error Message:
APC_INDEX_MISMATCH

Explanation:
This is a kernel internal error. This error could be caused by a mismatch between KeEnterCriticalRegion and KeLeaveCriticalRegion in a file system.
只是进出临界共不匹配,其实应当不是try的问题,是否有其它方面的问题而在这里有所表现,比如进入本函数时候调用了KeEnterCriticalRegion, 而你在这里return了,没有可能调用finally下面的KeLeaveCriticalRegion呢

21,597

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧