最近在学windows2000的驱动编程,在很多代码中都看见有PAGED_CODE,实在debug模式下使用的一个分页代码的级别诊断,查了下windows2000的源码,PAGED_CODE是这样定义的。
#define PAGED_CODE() /
if (KeGetCurrentIrql() > APC_LEVEL) { /
KdPrint(( "EX: Pageable code called at IRQL %d/n", KeGetCurrentIrql() )); /
ASSERT(FALSE); /
}
其中 APC_LEVEL等于1,
还有KeGetCurrentIrql是这样定义的#define KeGetCurrentIrql() PCR->CurrentIrql
#define PCR ((volatile KPCR * const)KIPCR)
#define KIPCR 0xfffff000 // kernel address of first PCR
typedef struct _KPCR {
//
// Start of the architecturally defined section of the PCR. This section
// may be directly addressed by vendor/platform specific HAL code and will
// not change from version to version of NT.
//
NT_TIB NtTib;
struct _KPCR *SelfPcr; // flat address of this PCR
struct _KPRCB *Prcb; // pointer to Prcb
KIRQL Irql;
ULONG IRR;
ULONG IrrActive;
ULONG IDR;
ULONG Reserved2;
struct _KIDTENTRY *IDT;
struct _KGDTENTRY *GDT;
struct _KTSS *TSS;
USHORT MajorVersion;
USHORT MinorVersion;
KAFFINITY SetMember;
ULONG StallScaleFactor;
UCHAR DebugActive;
UCHAR Number;
// end_ntddk
UCHAR VdmAlert;
UCHAR Reserved[1]; // dword align
ULONG KernelReserved[15]; // For use by the kernel
ULONG SecondLevelCacheSize;
ULONG HalReserved[16]; // For use by Hal
// End of the architecturally defined section of the PCR.
// end_nthal
ULONG InterruptMode;
UCHAR Spare1;
ULONG KernelReserved2[17];
struct _KPRCB PrcbData;
// begin_nthal begin_ntddk
} KPCR;
typedef KPCR *PKPCR;