sidt指令怎样获取多处理器系统IDT表地址

b571013930 2013-10-26 03:49:23
  

ULONG count = 0;
UNICODE_STRING ustr; PKDPC pdpc;
PsGetVersion(0,0,&g_dwBuildNumber,0);
//__asm int 3
//动态获取地址,因为获取cpu数目的方法在vista sp1即以后版本有所改变,
//如果直接使用KeQueryActiveProcessorCount将导致驱动在xp下无法加载
if (g_dwBuildNumber == 2600 || g_dwBuildNumber == 6000)
{
RtlInitUnicodeString(&ustr,L"KeNumberProcessors");
PVOID p = MmGetSystemRoutineAddress(&ustr);
if (p!=0)
{
count = *(ULONG *)p;
}
}
else
{
KAFFINITY procs;
RtlInitUnicodeString(&ustr,L"KeQueryActiveProcessorCount");
fnKeQueryActiveProcessorCount MyQueryActiveProcessorCount = (fnKeQueryActiveProcessorCount)MmGetSystemRoutineAddress(&ustr);
if (MyQueryActiveProcessorCount != 0)
{
count = MyQueryActiveProcessorCount(&procs);
}

}
if (count==1)
{
ShowIDTinfo(0,0,0,0);
}
else
{
ULONG currrent_pro_num = KeGetCurrentProcessorNumber(); ShowIDTinfo(0,currrent_pro_num,0,0);
g_FinshedDPC = 1;
PKDPC temp_dpc;
temp_dpc = (PKDPC)ExAllocatePoolWithTag(NonPagedPool,sizeof(KDPC)*count,'rm');
pdpc = temp_dpc;
if (temp_dpc == NULL)
return status;
for (ULONG i = 0;i<count;i++,*temp_dpc++)
{
if (i!=currrent_pro_num)
{
//传入一个cpu号就好
KeInitializeDpc(temp_dpc,(PKDEFERRED_ROUTINE)ShowIDTinfo,(PVOID)i);
KeSetTargetProcessorDpc(temp_dpc,i);
KeInsertQueueDpc(temp_dpc,NULL,NULL);
}

}
//等待所有的dpc历程完事儿
while(InterlockedCompareExchange(&g_FinshedDPC,count,count) != count)
{
__asm nop
}
ExFreePoolWithTag(pdpc,'rm');
}

return status;
}

VOID ShowIDTinfo(
IN struct _KDPC *Dpc,
IN ULONG cpuNum,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2)
{
IDTINFO idt_info;

__asm sidt idt_info

PIDTENTRY pIDTen =( PIDTENTRY)MAKELONG(idt_info.LowIDTbase,idt_info.HiIDTbase);
PIDTENTRY pIDTtmp;
ULONG addr;

for (ULONG i=0;i<0xFF;i++)
{
pIDTtmp = &pIDTen[i];
addr = MAKELONG(pIDTtmp->LowOffset,pIDTtmp->HiOffset);
DbgPrint("CPU:%d Index:%d Addr:0x%x DPL:%d\n",cpuNum,i,addr,pIDTtmp->DPL);
}

InterlockedIncrement(&g_FinshedDPC);

}

这段代码好象只能获取254个IDT表地址,而真正所有的是CPU数目*254个,哪个明白为什么吗或者怎样获取多处理器系统所有IDT表地址,必须在原有代码做改动?
...全文
369 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuzhiwenk3001 2014-01-08
  • 打赏
  • 举报
回复
多CPU的话,要获得了每个CPU的PKPCR结构,KPRCR里有这个CPU的GDT。 sidt只是取得当前线程的IDT

9,506

社区成员

发帖
与我相关
我的任务
社区描述
Windows专区 安全技术/病毒
社区管理员
  • 安全技术/病毒社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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