IDT检测 多CPU

发布时间:2014-10-22 12:55:56编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"IDT检测 多CPU",主要涉及到IDT检测 多CPU方面的内容,对于IDT检测 多CPU感兴趣的同学可以参考一下。

#define MAKELONG(a, b) ((unsigned long) (((unsigned short) (a)) | ((unsigned long) ((unsigned short) (b))) << 16))             VOID ShowIDTinfo(                      IN struct _KDPC  *Dpc,                      IN ULONG cpuNum,                      IN PVOID  SystemArgument1,                      IN PVOID  SystemArgument2);     typedef struct _IDTENTRY  {      unsigned short LowOffset;      unsigned short selector;      unsigned char unused_lo;      unsigned char segment_type:4;    //0x0E is an interrupt gate      unsigned char system_segment_flag:1;      unsigned char DPL:2;           // descriptor privilege level      unsigned char P:1;              /* present */      unsigned short HiOffset;  } IDTENTRY,*PIDTENTRY; /* sidt returns idt in this format */  typedef struct _IDTINFO  {      unsigned short IDTLimit;      unsigned short LowIDTbase;      unsigned short HiIDTbase;  } IDTINFO,*PIDTINFO;  typedef  ULONG (NTAPI *fnKeQueryActiveProcessorCount)(OUT PKAFFINITY  ActiveProcessors);  ULONG g_dwBuildNumber;  //记录完成dpc的数量  volatile LONG g_FinshedDPC = 0;  //入口函数  extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject,IN PUNICODE_STRING pRegistryPath)  {      NTSTATUS status;     //注册驱动调用函数入口      pDriverObject->DriverUnload = (PDRIVER_UNLOAD)DriverUnload;      pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]= DriverIOCtrl    ;      pDriverObject->MajorFunction[IRP_MJ_CLOSE]= DriverDispatch    ;      pDriverObject->MajorFunction[IRP_MJ_CREATE]= DriverDispatch    ;      pDriverObject->MajorFunction[IRP_MJ_READ]= DriverDispatch    ;      pDriverObject->MajorFunction[IRP_MJ_WRITE]= DriverDispatch    ;     //创建设备      status = CreateDevice(pDriverObject);     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);      }


上一篇:如何在模拟器上安装apk
下一篇:Struts的几个精细之处

相关文章

关键词: IDT检测 多CPU

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款