能力值:
( LV7,RANK:110 )
|
-
-
2 楼
投递DPC 啊 简单啊
我只给出关键部分的代码
ULONG allProcessorDone =0;
DWORD cpuNum[16] = {0};
void MyDpcCallBack(PKDPC pKDpc,PVOID Data1,PVOID Data2,PVOID Data3);
void MyDpcCallBack(PKDPC pKDpc,PVOID Data1,PVOID Data2,PVOID Data3)
{//这个函数被调用的时候已经椒DPC级别
DpcCallBack( Data1,Data2,Data3,KeGetCurrentProcessorNumber());
InterlockedIncrement(&allProcessorDone);
}
NTSTATUS UpCpuToDpc()
{
CCHAR i;
long currentProcessor =0;
PKDPC pkDpc =NULL;
KIRQL oldIrql, currentIrql;
currentIrql = KeGetCurrentIrql();
allProcessorDone =0;
if (currentIrql < DISPATCH_LEVEL)
KeRaiseIrql(DISPATCH_LEVEL, &oldIrql);
InterlockedAnd(&allProcessorDone, 0);
pkDpc = (PKDPC)ExAllocatePoolWithTag(NonPagedPool, KeNumberProcessors * sizeof(KDPC), (ULONG)' pni');
//DpcCallBack
if (!pkDpc)
{
DbgPrint("Insufficient Resource error\n");
return 0xc000005;
}
//循环向CPU插入DPC
for (i = 0; i < KeNumberProcessors; i++)
{
KeInitializeDpc(&pkDpc[i],
MyDpcCallBack,
&cpuNum[i]);
KeSetTargetProcessorDpc(&pkDpc[i], i);
KeInsertQueueDpc(&pkDpc[i], NULL, NULL);
}
//等待DPC函数调用完成
while(InterlockedCompareExchange(&allProcessorDone, KeNumberProcessors - 1, KeNumberProcessors - 1) != KeNumberProcessors - 1)
{
_asm pause;
}
if (currentIrql < DISPATCH_LEVEL)
KeLowerIrql(oldIrql);
if (pkDpc)
{
ExFreePool(pkDpc);
pkDpc = NULL;
}
return 0;
}
|
能力值:
( LV3,RANK:30 )
|
-
-
3 楼
// MAXIMUM_PROCESSORS 在32位系统中是32, 64位是64
pDpc->Number = MAXIMUM_PROCESSORS + CpuNumber;
KeInsertQueueDpc(pDpc, NULL, NULL);
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
谢谢大家.......但楼上的朋友,你这样投递DPC好象不大对吧?
|
能力值:
( LV3,RANK:30 )
|
-
-
5 楼
很对, 不信就试试
|
|
|