找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 4308|回复: 1

给多核CPU投递DPC防止Inline Hook时蓝屏

[复制链接]

280

主题

203

回帖

0

精华

版主

积分
1808
发表于 2011-1-16 00:20:31 | 显示全部楼层 |阅读模式

PKDPC GainExclusivity()
{
NTSTATUS ns;
ULONG u_currentCPU;
CCHAR i;
PKDPC pkdpc, temp_pkdpc;
if (KeGetCurrentIrql() != DISPATCH_LEVEL)
return NULL;
InterlockedAnd(&AllCPURaised, 0);
InterlockedAnd(&NumberOfRaisedCPU, 0);

temp_pkdpc = (PKDPC) ExAllocatePool(NonPagedPool, KeNumberProcessors *
sizeof(KDPC));
if (temp_pkdpc == NULL)
return NULL;
u_currentCPU = KeGetCurrentProcessorNumber();
pkdpc = temp_pkdpc;
for (i = 0; i < KeNumberProcessors; i++, *temp_pkdpc++)
{
if (i != u_currentCPU)
{
KeInitializeDpc(temp_pkdpc,
RaiseCPUIrqlAndWait,
NULL);

KeSetTargetProcessorDpc(temp_pkdpc, i);
KeInsertQueueDpc(temp_pkdpc, NULL, NULL);
}
}
while(InterlockedCompareExchange(&NumberOfRaisedCPU,
KeNumberProcessors-1, KeNumberProcessors-1) !=
KeNumberProcessors-1)
{
__asm nop;
}
return pkdpc;
}

VOID RaiseCPUIrqlAndWait(IN PKDPC Dpc,
IN PVOID DeferredContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2)
{
InterlockedIncrement(&NumberOfRaisedCPU);
while(!InterlockedCompareExchange(&AllCPURaised, 1, 1))
{
__asm nop;
}
InterlockedDecrement(&NumberOfRaisedCPU);
}

NTSTATUS ReleaseExclusivity(PVOID pkdpc)
{
InterlockedIncrement(&AllCPURaised);
while(InterlockedCompareExchange(&NumberOfRaisedCPU, 0, 0))
{
__asm nop;
}
if (pkdpc != NULL)
{
ExFreePool(pkdpc);
pkdpc = NULL;
}
return STATUS_SUCCESS;
}

0

主题

55

回帖

0

精华

铜牌会员

积分
177
发表于 2011-11-22 10:48:28 | 显示全部楼层
要实践一下,看看是否稳定。谢谢楼主分享。
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表