reactos/sdk/include/xdk/x86/ke.h
Hermès Bélusca-Maïto bf9cac8a67
[SDK:NDK/XDK] Remove x86 KeGetPcr() definition from the DDK (#6526)
The official MS DDK/WDK does not expose KeGetPcr() for x86, so do
not expose it there as well. Use instead the private NDK definition.

If it were exposed in the DDK/WDK, it would have to be a
multiprocessor-compatible definition.

Note that the broken definition was working only in single-processor
mode, using the PCR static memory pointer value.
The official MS DDK/WDK exposes KeGetPcr() as an alias to such a
PCR value only for IA64, MIPS and PPC, which is of course not great.
2024-03-10 16:55:44 +01:00

370 lines
8.8 KiB
C

$if (_WDMDDK_)
/** Kernel definitions for x86 **/
/* Interrupt request levels */
#define PASSIVE_LEVEL 0
#define LOW_LEVEL 0
#define APC_LEVEL 1
#define DISPATCH_LEVEL 2
#define CMCI_LEVEL 5
#define PROFILE_LEVEL 27
#define CLOCK1_LEVEL 28
#define CLOCK2_LEVEL 28
#define IPI_LEVEL 29
#define POWER_LEVEL 30
#define HIGH_LEVEL 31
#define CLOCK_LEVEL CLOCK2_LEVEL
#define KIP0PCRADDRESS 0xffdff000
#define KI_USER_SHARED_DATA 0xffdf0000
#define SharedUserData ((KUSER_SHARED_DATA * CONST)KI_USER_SHARED_DATA)
#define PAGE_SIZE 0x1000
#define PAGE_SHIFT 12L
#define KeGetDcacheFillSize() 1L
#define EFLAG_SIGN 0x8000
#define EFLAG_ZERO 0x4000
#define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
#define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
#define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
#define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
typedef struct _KFLOATING_SAVE {
ULONG ControlWord;
ULONG StatusWord;
ULONG ErrorOffset;
ULONG ErrorSelector;
ULONG DataOffset;
ULONG DataSelector;
ULONG Cr0NpxState;
ULONG Spare1;
} KFLOATING_SAVE, *PKFLOATING_SAVE;
extern NTKERNELAPI volatile KSYSTEM_TIME KeTickCount;
#define YieldProcessor _mm_pause
FORCEINLINE
VOID
KeMemoryBarrier(VOID)
{
LONG Barrier, *Dummy = &Barrier;
(VOID)Dummy;
#if defined(__GNUC__)
__asm__ __volatile__ ("xchg %%eax, %0" : : "m" (Barrier) : "%eax");
#elif defined(_MSC_VER)
__asm xchg [Barrier], eax
#endif
}
#define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
_IRQL_requires_max_(HIGH_LEVEL)
_IRQL_saves_
NTHALAPI
KIRQL
NTAPI
KeGetCurrentIrql(VOID);
_IRQL_requires_max_(HIGH_LEVEL)
NTHALAPI
VOID
FASTCALL
KfLowerIrql(
_In_ _IRQL_restores_ _Notliteral_ KIRQL NewIrql);
#define KeLowerIrql(a) KfLowerIrql(a)
_IRQL_requires_max_(HIGH_LEVEL)
_IRQL_raises_(NewIrql)
_IRQL_saves_
NTHALAPI
KIRQL
FASTCALL
KfRaiseIrql(
_In_ KIRQL NewIrql);
#define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
_IRQL_requires_max_(DISPATCH_LEVEL)
_IRQL_saves_
_IRQL_raises_(DISPATCH_LEVEL)
NTHALAPI
KIRQL
NTAPI
KeRaiseIrqlToDpcLevel(VOID);
NTHALAPI
KIRQL
NTAPI
KeRaiseIrqlToSynchLevel(VOID);
_Requires_lock_not_held_(*SpinLock)
_Acquires_lock_(*SpinLock)
_IRQL_requires_max_(DISPATCH_LEVEL)
_IRQL_saves_
_IRQL_raises_(DISPATCH_LEVEL)
NTHALAPI
KIRQL
FASTCALL
KfAcquireSpinLock(
_Inout_ PKSPIN_LOCK SpinLock);
#define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
_Requires_lock_held_(*SpinLock)
_Releases_lock_(*SpinLock)
_IRQL_requires_(DISPATCH_LEVEL)
NTHALAPI
VOID
FASTCALL
KfReleaseSpinLock(
_Inout_ PKSPIN_LOCK SpinLock,
_In_ _IRQL_restores_ KIRQL NewIrql);
#define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
_Requires_lock_not_held_(*SpinLock)
_Acquires_lock_(*SpinLock)
_IRQL_requires_min_(DISPATCH_LEVEL)
NTKERNELAPI
VOID
FASTCALL
KefAcquireSpinLockAtDpcLevel(
_Inout_ PKSPIN_LOCK SpinLock);
#define KeAcquireSpinLockAtDpcLevel(SpinLock) KefAcquireSpinLockAtDpcLevel(SpinLock)
_Requires_lock_held_(*SpinLock)
_Releases_lock_(*SpinLock)
_IRQL_requires_min_(DISPATCH_LEVEL)
NTKERNELAPI
VOID
FASTCALL
KefReleaseSpinLockFromDpcLevel(
_Inout_ PKSPIN_LOCK SpinLock);
#define KeReleaseSpinLockFromDpcLevel(SpinLock) KefReleaseSpinLockFromDpcLevel(SpinLock)
NTSYSAPI
PKTHREAD
NTAPI
KeGetCurrentThread(VOID);
_Always_(_Post_satisfies_(return<=0))
_Must_inspect_result_
_IRQL_requires_max_(DISPATCH_LEVEL)
_Kernel_float_saved_
_At_(*FloatSave, _Kernel_requires_resource_not_held_(FloatState) _Kernel_acquires_resource_(FloatState))
NTKERNELAPI
NTSTATUS
NTAPI
KeSaveFloatingPointState(
_Out_ PKFLOATING_SAVE FloatSave);
_Success_(1)
_Kernel_float_restored_
_At_(*FloatSave, _Kernel_requires_resource_held_(FloatState) _Kernel_releases_resource_(FloatState))
NTKERNELAPI
NTSTATUS
NTAPI
KeRestoreFloatingPointState(
_In_ PKFLOATING_SAVE FloatSave);
#if (NTDDI_VERSION >= NTDDI_WIN7)
FORCEINLINE
ULONG
NTAPI
KeGetCurrentProcessorIndex(VOID)
{
return __readfsbyte(0x51);
}
#endif
/* VOID
* KeFlushIoBuffers(
* IN PMDL Mdl,
* IN BOOLEAN ReadOperation,
* IN BOOLEAN DmaOperation)
*/
#define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
/* x86 and x64 performs a 0x2C interrupt */
#define DbgRaiseAssertionFailure __int2c
FORCEINLINE
VOID
_KeQueryTickCount(
OUT PLARGE_INTEGER CurrentCount)
{
for (;;) {
#ifdef NONAMELESSUNION
CurrentCount->s.HighPart = KeTickCount.High1Time;
CurrentCount->s.LowPart = KeTickCount.LowPart;
if (CurrentCount->s.HighPart == KeTickCount.High2Time) break;
#else
CurrentCount->HighPart = KeTickCount.High1Time;
CurrentCount->LowPart = KeTickCount.LowPart;
if (CurrentCount->HighPart == KeTickCount.High2Time) break;
#endif
YieldProcessor();
}
}
#define KeQueryTickCount(CurrentCount) _KeQueryTickCount(CurrentCount)
$endif (_WDMDDK_)
$if (_NTDDK_)
#define PAUSE_PROCESSOR YieldProcessor();
#define KERNEL_STACK_SIZE 12288
#define KERNEL_LARGE_STACK_SIZE 61440
#define KERNEL_LARGE_STACK_COMMIT 12288
#define SIZE_OF_80387_REGISTERS 80
#if !defined(RC_INVOKED)
#define CONTEXT_i386 0x10000
#define CONTEXT_i486 0x10000
#define CONTEXT_CONTROL (CONTEXT_i386|0x00000001L)
#define CONTEXT_INTEGER (CONTEXT_i386|0x00000002L)
#define CONTEXT_SEGMENTS (CONTEXT_i386|0x00000004L)
#define CONTEXT_FLOATING_POINT (CONTEXT_i386|0x00000008L)
#define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386|0x00000010L)
#define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L)
#define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS)
#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | \
CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | \
CONTEXT_EXTENDED_REGISTERS)
#define CONTEXT_XSTATE (CONTEXT_i386 | 0x00000040L)
#endif /* !defined(RC_INVOKED) */
typedef struct _FLOATING_SAVE_AREA {
ULONG ControlWord;
ULONG StatusWord;
ULONG TagWord;
ULONG ErrorOffset;
ULONG ErrorSelector;
ULONG DataOffset;
ULONG DataSelector;
UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
ULONG Cr0NpxState;
} FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
#include "pshpack4.h"
typedef struct _CONTEXT {
ULONG ContextFlags;
ULONG Dr0;
ULONG Dr1;
ULONG Dr2;
ULONG Dr3;
ULONG Dr6;
ULONG Dr7;
FLOATING_SAVE_AREA FloatSave;
ULONG SegGs;
ULONG SegFs;
ULONG SegEs;
ULONG SegDs;
ULONG Edi;
ULONG Esi;
ULONG Ebx;
ULONG Edx;
ULONG Ecx;
ULONG Eax;
ULONG Ebp;
ULONG Eip;
ULONG SegCs;
ULONG EFlags;
ULONG Esp;
ULONG SegSs;
UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
} CONTEXT;
#include "poppack.h"
#define PCR_MINOR_VERSION 1
#define PCR_MAJOR_VERSION 1
typedef struct _KPCR {
union {
NT_TIB NtTib;
struct {
struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
PVOID Used_StackBase;
PVOID Spare2;
PVOID TssCopy;
ULONG ContextSwitches;
KAFFINITY SetMemberCopy;
PVOID Used_Self;
};
};
struct _KPCR *SelfPcr;
struct _KPRCB *Prcb;
KIRQL Irql;
ULONG IRR;
ULONG IrrActive;
ULONG IDR;
PVOID KdVersionBlock;
struct _KIDTENTRY *IDT;
struct _KGDTENTRY *GDT;
struct _KTSS *TSS;
USHORT MajorVersion;
USHORT MinorVersion;
KAFFINITY SetMember;
ULONG StallScaleFactor;
UCHAR SpareUnused;
UCHAR Number;
UCHAR Spare0;
UCHAR SecondLevelCacheAssociativity;
ULONG VdmAlert;
ULONG KernelReserved[14];
ULONG SecondLevelCacheSize;
ULONG HalReserved[16];
} KPCR, *PKPCR;
/* NOTE: This macro is not exposed in the DDK/WDK for _M_IX86.
* If it were, this would be its definition. */
#if 0
// #define KeGetPcr() ((PKPCR)__readfsdword(FIELD_OFFSET(KPCR, SelfPcr)))
FORCEINLINE
PKPCR
KeGetPcr(VOID)
{
return (PKPCR)__readfsdword(FIELD_OFFSET(KPCR, SelfPcr));
}
#endif
#if (NTDDI_VERSION >= NTDDI_WIN7)
_CRT_DEPRECATE_TEXT("KeGetCurrentProcessorNumber is deprecated. Use KeGetCurrentProcessorNumberEx or KeGetCurrentProcessorIndex instead.")
#endif
FORCEINLINE
ULONG
KeGetCurrentProcessorNumber(VOID)
{
return (ULONG)__readfsbyte(FIELD_OFFSET(KPCR, Number));
}
/* Macros for kernel-mode run-time checks of X86 system architecture */
#ifdef IsNEC_98
#undef IsNEC_98
#endif
#define IsNEC_98 (SharedUserData->AlternativeArchitecture == NEC98x86)
#ifdef IsNotNEC_98
#undef IsNotNEC_98
#endif
#define IsNotNEC_98 (SharedUserData->AlternativeArchitecture != NEC98x86)
#ifdef SetNEC_98
#undef SetNEC_98
#endif
#define SetNEC_98 (SharedUserData->AlternativeArchitecture = NEC98x86)
#ifdef SetNotNEC_98
#undef SetNotNEC_98
#endif
#define SetNotNEC_98 (SharedUserData->AlternativeArchitecture = StandardDesign)
$endif (_NTDDK_)