- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.

- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.

svn path=/branches/alex-kd-branch/; revision=25833
This commit is contained in:
Alex Ionescu 2007-02-18 07:21:03 +00:00
parent c9a0a6228b
commit 59caa79d63
20 changed files with 690 additions and 89 deletions

View file

@ -635,6 +635,17 @@ typedef IO_ALLOCATION_ACTION
IN PVOID MapRegisterBase,
IN PVOID Context);
typedef struct _EXCEPTION_RECORD64
{
NTSTATUS ExceptionCode;
ULONG ExceptionFlags;
ULONG64 ExceptionRecord;
ULONG64 ExceptionAddress;
ULONG NumberParameters;
ULONG __unusedAlignment;
ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
} EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
typedef EXCEPTION_DISPOSITION
(DDKAPI *PEXCEPTION_ROUTINE)(
IN struct _EXCEPTION_RECORD *ExceptionRecord,
@ -5423,6 +5434,13 @@ KfReleaseSpinLock(
IN PKSPIN_LOCK SpinLock,
IN KIRQL NewIrql);
NTKERNELAPI
BOOLEAN
FASTCALL
KeTryToAcquireSpinLockAtDpcLevel(
IN OUT PKSPIN_LOCK SpinLock
);
#define KeAcquireSpinLockAtDpcLevel(SpinLock) KefAcquireSpinLockAtDpcLevel(SpinLock)
#define KeReleaseSpinLockFromDpcLevel(SpinLock) KefReleaseSpinLockFromDpcLevel(SpinLock)
#define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)

View file

@ -27,29 +27,6 @@ Author:
#ifndef NTOS_MODE_USER
//
// Port Functions
//
UCHAR
NTAPI
KdPollBreakIn(VOID);
NTSTATUS
NTAPI
KdRestore(IN BOOLEAN DisableDbgPorts);
NTSTATUS
NTAPI
KdSave(IN ULONG Unknown);
#ifdef _ARC_
NTSTATUS
NTAPI
KdDebuggerInitialize0(
IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock
);
#endif
//
// Debugger API
//
@ -65,6 +42,12 @@ KdSystemDebugControl(
KPROCESSOR_MODE PreviousMode
);
BOOLEAN
NTAPI
KdPollBreakIn(
VOID
);
#endif
//

View file

@ -52,6 +52,7 @@ Author:
#define BREAKPOINT_PROMPT 2
#define BREAKPOINT_LOAD_SYMBOLS 3
#define BREAKPOINT_UNLOAD_SYMBOLS 4
#define BREAKPOINT_COMMAND_STRING 5
//
// Debug Control Codes for NtSystemDebugcontrol

View file

@ -89,6 +89,21 @@ typedef struct _OBJECT_ATTRIBUTES {
PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
#endif
typedef struct LIST_ENTRY32
{
ULONG Flink;
ULONG Blink;
} LIST_ENTRY32;
typedef LIST_ENTRY32 *PLIST_ENTRY32;
typedef struct LIST_ENTRY64
{
ULONGLONG Flink;
ULONGLONG Blink;
} LIST_ENTRY64;
typedef LIST_ENTRY64 *PLIST_ENTRY64;
#define NOTHING
#define RTL_CONSTANT_STRING(s) { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
#define TYPE_ALIGNMENT( t ) FIELD_OFFSET( struct { char x; t test; }, test )

View file

@ -0,0 +1,185 @@
#ifndef _WDBGEXTS_
#define _WDBGEXTS_
enum
{
DBGKD_SIMULATION_NONE,
DBGKD_SIMULATION_EXDI
};
#define KD_SECONDARY_VERSION_DEFAULT 0
#define KD_SECONDARY_VERSION_AMD64_OBSOLETE_CONTEXT_1 0
#define KD_SECONDARY_VERSION_AMD64_OBSOLETE_CONTEXT_2 1
#define KD_SECONDARY_VERSION_AMD64_CONTEXT 2
#define CURRENT_KD_SECONDARY_VERSION KD_SECONDARY_VERSION_DEFAULT
#define DBGKD_VERS_FLAG_MP 0x0001
#define DBGKD_VERS_FLAG_DATA 0x0002
#define DBGKD_VERS_FLAG_PTR64 0x0004
#define DBGKD_VERS_FLAG_NOMM 0x0008
#define DBGKD_VERS_FLAG_HSS 0x0010
#define DBGKD_VERS_FLAG_PARTITIONS 0x0020
#define KDBG_TAG TAG('G', 'B', 'D', 'K')
typedef struct _DBGKD_GET_VERSION64
{
USHORT MajorVersion;
USHORT MinorVersion;
UCHAR ProtocolVersion;
UCHAR KdSecondaryVersion;
USHORT Flags;
USHORT MachineType;
UCHAR MaxPacketType;
UCHAR MaxStateChange;
UCHAR MaxManipulate;
UCHAR Simulation;
USHORT Unused[1];
ULONG64 KernBase;
ULONG64 PsLoadedModuleList;
ULONG64 DebuggerDataList;
} DBGKD_GET_VERSION64, *PDBGKD_GET_VERSION64;
typedef struct _DBGKD_DEBUG_DATA_HEADER64
{
LIST_ENTRY64 List;
ULONG OwnerTag;
ULONG Size;
} DBGKD_DEBUG_DATA_HEADER64, *PDBGKD_DEBUG_DATA_HEADER64;
typedef struct _KDDEBUGGER_DATA64
{
DBGKD_DEBUG_DATA_HEADER64 Header;
ULONG64 KernBase;
ULONG64 BreakpointWithStatus;
ULONG64 SavedContext;
USHORT ThCallbackStack;
USHORT NextCallback;
USHORT FramePointer;
USHORT PaeEnabled:1;
ULONG64 KiCallUserMode;
ULONG64 KeUserCallbackDispatcher;
ULONG64 PsLoadedModuleList;
ULONG64 PsActiveProcessHead;
ULONG64 PspCidTable;
ULONG64 ExpSystemResourcesList;
ULONG64 ExpPagedPoolDescriptor;
ULONG64 ExpNumberOfPagedPools;
ULONG64 KeTimeIncrement;
ULONG64 KeBugCheckCallbackListHead;
ULONG64 KiBugcheckData;
ULONG64 IopErrorLogListHead;
ULONG64 ObpRootDirectoryObject;
ULONG64 ObpTypeObjectType;
ULONG64 MmSystemCacheStart;
ULONG64 MmSystemCacheEnd;
ULONG64 MmSystemCacheWs;
ULONG64 MmPfnDatabase;
ULONG64 MmSystemPtesStart;
ULONG64 MmSystemPtesEnd;
ULONG64 MmSubsectionBase;
ULONG64 MmNumberOfPagingFiles;
ULONG64 MmLowestPhysicalPage;
ULONG64 MmHighestPhysicalPage;
ULONG64 MmNumberOfPhysicalPages;
ULONG64 MmMaximumNonPagedPoolInBytes;
ULONG64 MmNonPagedSystemStart;
ULONG64 MmNonPagedPoolStart;
ULONG64 MmNonPagedPoolEnd;
ULONG64 MmPagedPoolStart;
ULONG64 MmPagedPoolEnd;
ULONG64 MmPagedPoolInformation;
ULONG64 MmPageSize;
ULONG64 MmSizeOfPagedPoolInBytes;
ULONG64 MmTotalCommitLimit;
ULONG64 MmTotalCommittedPages;
ULONG64 MmSharedCommit;
ULONG64 MmDriverCommit;
ULONG64 MmProcessCommit;
ULONG64 MmPagedPoolCommit;
ULONG64 MmExtendedCommit;
ULONG64 MmZeroedPageListHead;
ULONG64 MmFreePageListHead;
ULONG64 MmStandbyPageListHead;
ULONG64 MmModifiedPageListHead;
ULONG64 MmModifiedNoWritePageListHead;
ULONG64 MmAvailablePages;
ULONG64 MmResidentAvailablePages;
ULONG64 PoolTrackTable;
ULONG64 NonPagedPoolDescriptor;
ULONG64 MmHighestUserAddress;
ULONG64 MmSystemRangeStart;
ULONG64 MmUserProbeAddress;
ULONG64 KdPrintCircularBuffer;
ULONG64 KdPrintCircularBufferEnd;
ULONG64 KdPrintWritePointer;
ULONG64 KdPrintRolloverCount;
ULONG64 MmLoadedUserImageList;
ULONG64 NtBuildLab;
ULONG64 KiNormalSystemCall;
ULONG64 KiProcessorBlock;
ULONG64 MmUnloadedDrivers;
ULONG64 MmLastUnloadedDriver;
ULONG64 MmTriageActionTaken;
ULONG64 MmSpecialPoolTag;
ULONG64 KernelVerifier;
ULONG64 MmVerifierData;
ULONG64 MmAllocatedNonPagedPool;
ULONG64 MmPeakCommitment;
ULONG64 MmTotalCommitLimitMaximum;
ULONG64 CmNtCSDVersion;
ULONG64 MmPhysicalMemoryBlock;
ULONG64 MmSessionBase;
ULONG64 MmSessionSize;
ULONG64 MmSystemParentTablePage;
ULONG64 MmVirtualTranslationBase;
USHORT OffsetKThreadNextProcessor;
USHORT OffsetKThreadTeb;
USHORT OffsetKThreadKernelStack;
USHORT OffsetKThreadInitialStack;
USHORT OffsetKThreadApcProcess;
USHORT OffsetKThreadState;
USHORT OffsetKThreadBStore;
USHORT OffsetKThreadBStoreLimit;
USHORT SizeEProcess;
USHORT OffsetEprocessPeb;
USHORT OffsetEprocessParentCID;
USHORT OffsetEprocessDirectoryTableBase;
USHORT SizePrcb;
USHORT OffsetPrcbDpcRoutine;
USHORT OffsetPrcbCurrentThread;
USHORT OffsetPrcbMhz;
USHORT OffsetPrcbCpuType;
USHORT OffsetPrcbVendorString;
USHORT OffsetPrcbProcStateContext;
USHORT OffsetPrcbNumber;
USHORT SizeEThread;
ULONG64 KdPrintCircularBufferPtr;
ULONG64 KdPrintBufferSize;
ULONG64 KeLoaderBlock;
USHORT SizePcr;
USHORT OffsetPcrSelfPcr;
USHORT OffsetPcrCurrentPrcb;
USHORT OffsetPcrContainedPrcb;
USHORT OffsetPcrInitialBStore;
USHORT OffsetPcrBStoreLimit;
USHORT OffsetPcrInitialStack;
USHORT OffsetPcrStackLimit;
USHORT OffsetPrcbPcrPage;
USHORT OffsetPrcbProcStateSpecialReg;
USHORT GdtR0Code;
USHORT GdtR0Data;
USHORT GdtR0Pcr;
USHORT GdtR3Code;
USHORT GdtR3Data;
USHORT GdtR3Teb;
USHORT GdtLdt;
USHORT GdtTss;
USHORT Gdt64R3CmCode;
USHORT Gdt64R3CmTeb;
ULONG64 IopNumTriageDumpDataBlocks;
ULONG64 IopTriageDumpDataBlocks;
ULONG64 VfCrashDataBlock;
} KDDEBUGGER_DATA64, *PKDDEBUGGER_DATA64;
#endif

View file

@ -0,0 +1,41 @@
#ifndef _KDDLL_
#define _KDDLL_
NTSTATUS
NTAPI
KdDebuggerInitialize0(
IN PLOADER_PARAMETER_BLOCK LoaderBlock
);
ULONG
NTAPI
KdReceivePacket(
IN ULONG PacketType,
OUT PSTRING MessageHeader,
OUT PSTRING MessageData,
OUT PULONG DataLength,
IN OUT PKD_CONTEXT Context
);
NTSTATUS
NTAPI
KdRestore(
IN BOOLEAN SleepTransition
);
NTSTATUS
NTAPI
KdSave(
IN BOOLEAN SleepTransition
);
VOID
NTAPI
KdSendPacket(
IN ULONG PacketType,
IN PSTRING MessageHeader,
IN PSTRING MessageData,
IN OUT PKD_CONTEXT Context
);
#endif

View file

@ -0,0 +1,229 @@
#ifndef _WINDBGKD_
#define _WINDBGKG_
//
// Packet Size and Control Stream Size
//
#define PACKET_MAX_SIZE 4000
#define DBGKD_MAXSTREAM 16
//
// Magic Packet IDs
//
#define INITIAL_PACKET_ID 0x80800000
#define SYNC_PACKET_ID 0x00000800
//
// Magic Packet bytes
//
#define BREAKIN_PACKET 0x62626262
#define BREAKIN_PACKET_BYTE 0x62
#define PACKET_LEADER 0x30303030
#define PACKET_LEADER_BYTE 0x30
#define CONTROL_PACKET_LEADER 0x69696969
#define CONTROL_PACKET_LEADER_BYTE 0x69
#define PACKET_TRAILING_BYTE 0xAA
//
// Packet Types
//
#define PACKET_TYPE_UNUSED 0
#define PACKET_TYPE_KD_STATE_CHANGE32 1
#define PACKET_TYPE_KD_STATE_MANIPULATE 2
#define PACKET_TYPE_KD_DEBUG_IO 3
#define PACKET_TYPE_KD_ACKNOWLEDGE 4
#define PACKET_TYPE_KD_RESEND 5
#define PACKET_TYPE_KD_RESET 6
#define PACKET_TYPE_KD_STATE_CHANGE64 7
#define PACKET_TYPE_KD_POLL_BREAKIN 8
#define PACKET_TYPE_KD_TRACE_IO 9
#define PACKET_TYPE_KD_CONTROL_REQUEST 10
#define PACKET_TYPE_KD_FILE_IO 11
#define PACKET_TYPE_MAX 12
//
// Wait State Change Types
//
#define DbgKdMinimumStateChange 0x00003030
#define DbgKdExceptionStateChange 0x00003030
#define DbgKdLoadSymbolsStateChange 0x00003031
#define DbgKdCommandStringStateChange 0x00003032
#define DbgKdMaximumStateChange 0x00003033
//
// Manipulate Types
//
#define DbgKdMinimumManipulate 0x00003130
#define DbgKdReadVirtualMemoryApi 0x00003130
#define DbgKdWriteVirtualMemoryApi 0x00003131
#define DbgKdGetContextApi 0x00003132
#define DbgKdSetContextApi 0x00003133
#define DbgKdWriteBreakPointApi 0x00003134
#define DbgKdRestoreBreakPointApi 0x00003135
#define DbgKdContinueApi 0x00003136
#define DbgKdReadControlSpaceApi 0x00003137
#define DbgKdWriteControlSpaceApi 0x00003138
#define DbgKdReadIoSpaceApi 0x00003139
#define DbgKdWriteIoSpaceApi 0x0000313A
#define DbgKdRebootApi 0x0000313B
#define DbgKdContinueApi2 0x0000313C
#define DbgKdReadPhysicalMemoryApi 0x0000313D
#define DbgKdWritePhysicalMemoryApi 0x0000313E
#define DbgKdQuerySpecialCallsApi 0x0000313F
#define DbgKdSetSpecialCallApi 0x00003140
#define DbgKdClearSpecialCallsApi 0x00003141
#define DbgKdSetInternalBreakPointApi 0x00003142
#define DbgKdGetInternalBreakPointApi 0x00003143
#define DbgKdReadIoSpaceExtendedApi 0x00003144
#define DbgKdWriteIoSpaceExtendedApi 0x00003145
#define DbgKdGetVersionApi 0x00003146
#define DbgKdWriteBreakPointExApi 0x00003147
#define DbgKdRestoreBreakPointExApi 0x00003148
#define DbgKdCauseBugCheckApi 0x00003149
#define DbgKdSwitchProcessor 0x00003150
#define DbgKdPageInApi 0x00003151
#define DbgKdReadMachineSpecificRegister 0x00003152
#define DbgKdWriteMachineSpecificRegister 0x00003153
#define OldVlm1 0x00003154
#define OldVlm2 0x00003155
#define DbgKdSearchMemoryApi 0x00003156
#define DbgKdGetBusDataApi 0x00003157
#define DbgKdSetBusDataApi 0x00003158
#define DbgKdCheckLowMemoryApi 0x00003159
#define DbgKdClearAllInternalBreakpointsApi 0x0000315A
#define DbgKdFillMemoryApi 0x0000315B
#define DbgKdQueryMemoryApi 0x0000315C
#define DbgKdSwitchPartition 0x0000315D
#define DbgKdMaximumManipulate 0x0000315E
//
// Debug I/O Types
//
#define DbgKdPrintStringApi 0x00003230
#define DbgKdGetStringApi 0x00003231
//
// Control Report Flags
//
#define REPORT_INCLUDES_SEGS 0x0001
#define REPORT_INCLUDES_CS 0x0002
//
// Protocol Versions
//
#define DBGKD_64BIT_PROTOCOL_VERSION1 5
#define DBGKD_64BIT_PROTOCOL_VERSION2 6
//
// KD Packet Structure
//
typedef struct _KD_PACKET
{
ULONG PacketLeader;
USHORT PacketType;
USHORT ByteCount;
ULONG PacketId;
ULONG Checksum;
} KD_PACKET, *PKD_PACKET;
//
// KD Context
//
typedef struct _KD_CONTEXT
{
ULONG KdpDefaultRetries;
BOOLEAN KdpControlCPending;
} KD_CONTEXT, *PKD_CONTEXT;
//
// DBGKM Structure for Exceptions
//
typedef struct _DBGKM_EXCEPTION64
{
EXCEPTION_RECORD64 ExceptionRecord;
ULONG FirstChance;
} DBGKM_EXCEPTION64, *PDBGKM_EXCEPTION64;
//
// DBGKD Structure for State Change
//
typedef struct _DBGKD_CONTROL_REPORT
{
ULONG Dr6;
ULONG Dr7;
USHORT InstructionCount;
USHORT ReportFlags;
UCHAR InstructionStream[DBGKD_MAXSTREAM];
USHORT SegCs;
USHORT SegDs;
USHORT SegEs;
USHORT SegFs;
ULONG EFlags;
} DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
//
// DBGKD Structure for Debug I/O Type Print String
//
typedef struct _DBGKD_PRINT_STRING
{
ULONG LengthOfString;
} DBGKD_PRINT_STRING, *PDBGKD_PRINT_STRING;
//
// DBGKD Structure for Debug I/O Type Get String
//
typedef struct _DBGKD_GET_STRING
{
ULONG LengthOfPromptString;
ULONG LengthOfStringRead;
} DBGKD_GET_STRING, *PDBGKD_GET_STRING;
//
// DBGKD Structure for Debug I/O
//
typedef struct _DBGKD_DEBUG_IO
{
ULONG ApiNumber;
USHORT ProcessorLevel;
USHORT Processor;
union
{
DBGKD_PRINT_STRING PrintString;
DBGKD_GET_STRING GetString;
} u;
} DBGKD_DEBUG_IO, *PDBGKD_DEBUG_IO;
//
// DBGKD Structure for Load Symbols
//
typedef struct _DBGKD_LOAD_SYMBOLS64
{
ULONG PathNameLength;
ULONG64 BaseOfDll;
ULONG64 ProcessId;
ULONG CheckSum;
ULONG SizeOfImage;
BOOLEAN UnloadSymbols;
} DBGKD_LOAD_SYMBOLS64, *PDBGKD_LOAD_SYMBOLS64;
//
// DBGKD Structure for Wait State Change
//
typedef struct _DBGKD_WAIT_STATE_CHANGE64
{
ULONG NewState;
USHORT ProcessorLevel;
USHORT Processor;
ULONG NumberProcessors;
ULONG64 Thread;
ULONG64 ProgramCounter;
union
{
DBGKM_EXCEPTION64 Exception;
DBGKD_LOAD_SYMBOLS64 LoadSymbols;
} u;
DBGKD_CONTROL_REPORT ControlReport;
CONTEXT Context;
} DBGKD_WAIT_STATE_CHANGE64, *PDBGKD_WAIT_STATE_CHANGE64;
#endif

View file

@ -23,9 +23,45 @@ ULONG ExpLastTimeZoneBias = -1;
LARGE_INTEGER ExpTimeZoneBias;
ULONG ExpTimeZoneId;
ULONG ExpTickCountMultiplier;
ERESOURCE ExpTimeRefreshLock;
/* FUNCTIONS ****************************************************************/
BOOLEAN
NTAPI
ExAcquireTimeRefreshLock(BOOLEAN Wait)
{
/* Simply acquire the Resource */
KeEnterCriticalRegion();
if (!(ExAcquireResourceExclusiveLite(&ExpTimeRefreshLock, Wait)))
{
/* We failed! */
KeLeaveCriticalRegion();
return FALSE;
}
/* Success */
return TRUE;
}
VOID
NTAPI
ExReleaseTimeRefreshLock(VOID)
{
/* Simply release the Resource */
ExReleaseResourceLite(&ExpTimeRefreshLock);
KeLeaveCriticalRegion();
}
VOID
NTAPI
ExUpdateSystemTimeFromCmos(IN BOOLEAN UpdateInterruptTime,
IN ULONG MaxSepInSeconds)
{
/* FIXME: TODO */
return;
}
BOOLEAN
NTAPI
ExRefreshTimeZoneInformation(IN PLARGE_INTEGER CurrentBootTime)

View file

@ -17,6 +17,7 @@ extern FAST_MUTEX ExpEnvironmentLock;
extern ERESOURCE ExpFirmwareTableResource;
extern LIST_ENTRY ExpFirmwareTableProviderListHead;
extern BOOLEAN ExpIsWinPEMode;
extern ULONG NtGlobalFlag;
ULONG ExpAnsiCodePageDataOffset, ExpOemCodePageDataOffset;
ULONG ExpUnicodeCaseTableDataOffset;
PVOID ExpNlsSectionPointer;
@ -910,7 +911,7 @@ ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
/* Unlock the pushlock */
OldValue.Value = InterlockedExchangeAddSizeT((PLONG)PushLock,
-EX_PUSH_LOCK_LOCK);
-(LONG)EX_PUSH_LOCK_LOCK);
/* Sanity checks */
ASSERT(OldValue.Locked);
@ -989,6 +990,19 @@ ExfpInterlockedExchange64(
NTSTATUS
ExpSetTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation);
BOOLEAN
NTAPI
ExAcquireTimeRefreshLock(BOOLEAN Wait);
VOID
NTAPI
ExReleaseTimeRefreshLock(VOID);
VOID
NTAPI
ExUpdateSystemTimeFromCmos(IN BOOLEAN UpdateInterruptTime,
IN ULONG MaxSepInSeconds);
NTSTATUS
NTAPI
ExpAllocateLocallyUniqueId(OUT LUID *LocallyUniqueId);

View file

@ -80,18 +80,26 @@ static inline void Ki386Cpuid(ULONG Op, PULONG Eax, PULONG Ebx, PULONG Ecx, PULO
#define Ke386FnInit() __asm__("fninit\n\t");
//
// CR Macros
//
#define Ke386SetCr2(X) __asm__ __volatile__("movl %0,%%cr2" : :"r" (X));
//
// DR Macros
//
#define Ke386GetDr0() _Ke386GetDr(0)
#define Ke386GetDr1() _Ke386GetDr(1)
#define Ke386SetDr0(X) _Ke386SetDr(0,X)
#define Ke386SetDr1(X) _Ke386SetDr(1,X)
#define Ke386GetDr2() _Ke386GetDr(2)
#define Ke386SetDr2(X) _Ke386SetDr(2,X)
#define Ke386GetDr3() _Ke386GetDr(3)
#define Ke386SetDr3(X) _Ke386SetDr(3,X)
#define Ke386GetDr4() _Ke386GetDr(4)
#define Ke386SetDr4(X) _Ke386SetDr(4,X)
#define Ke386GetDr6() _Ke386GetDr(6)
#define Ke386SetDr6(X) _Ke386SetDr(6,X)
#define Ke386GetDr7() _Ke386GetDr(7)
#define Ke386SetDr7(X) _Ke386SetDr(7,X)
@ -192,6 +200,17 @@ Ke386GetTr(IN USHORT Tr)
__asm str Tr;
}
//
// CR Macros
//
VOID
FORCEINLINE
Ke386SetCr2(IN ULONG Value)
{
__asm mov eax, Value;
__asm mov cr2, eax;
}
//
// DR Macros
//
@ -245,6 +264,14 @@ Ke386SetDr0(IN ULONG Value)
__asm mov dr0, eax;
}
VOID
FORCEINLINE
Ke386SetDr1(IN ULONG Value)
{
__asm mov eax, Value;
__asm mov dr1, eax;
}
VOID
FORCEINLINE
Ke386SetDr2(IN ULONG Value)

View file

@ -63,10 +63,16 @@ Ki386InitializeTss(
VOID
NTAPI
KiSaveProcessorControlState(
KiRestoreProcessorControlState(
IN PKPROCESSOR_STATE ProcessorState
);
VOID
NTAPI
KiSaveProcessorControlState(
OUT PKPROCESSOR_STATE ProcessorState
);
VOID
FASTCALL
KiIdleLoop(VOID);

View file

@ -71,11 +71,6 @@ typedef PCHAR
IN ULONG Length
);
struct _KIRQ_TRAPFRAME;
struct _KPCR;
struct _KPRCB;
struct _KEXCEPTION_FRAME;
extern ULONG_PTR MmFreeLdrFirstKrnlPhysAddr;
extern ULONG_PTR MmFreeLdrLastKrnlPhysAddr;
extern ULONG_PTR MmFreeLdrLastKernelAddress;
@ -154,6 +149,7 @@ extern PVOID KeUserExceptionDispatcher;
extern PVOID KeRaiseUserExceptionDispatcher;
extern UCHAR KiDebugRegisterTrapOffsets[9];
extern UCHAR KiDebugRegisterContextOffsets[9];
extern ULONG KiFreezeFlag;
/* MACROS *************************************************************************/
@ -193,16 +189,6 @@ extern UCHAR KiDebugRegisterContextOffsets[9];
/* INTERNAL KERNEL FUNCTIONS ************************************************/
/* Readies a Thread for Execution. */
BOOLEAN
NTAPI
KiDispatchThreadNoLock(ULONG NewThreadStatus);
/* Readies a Thread for Execution. */
VOID
NTAPI
KiDispatchThread(ULONG NewThreadStatus);
/* Finds a new thread to run */
NTSTATUS
FASTCALL
@ -393,10 +379,6 @@ KeProfileInterruptWithSource(
IN KPROFILE_SOURCE Source
);
BOOLEAN
NTAPI
KiRosPrintAddress(PVOID Address);
VOID
NTAPI
KeUpdateRunTime(
@ -520,13 +502,6 @@ KiSetPriorityThread(
IN KPRIORITY Priority
);
BOOLEAN
NTAPI
KiDispatcherObjectWake(
DISPATCHER_HEADER* hdr,
KPRIORITY increment
);
VOID
FASTCALL
KiUnlinkThread(
@ -534,15 +509,6 @@ KiUnlinkThread(
IN NTSTATUS WaitStatus
);
VOID
NTAPI
KeExpireTimers(
PKDPC Apc,
PVOID Arg1,
PVOID Arg2,
PVOID Arg3
);
VOID
NTAPI
KeDumpStackFrames(PULONG Frame);
@ -724,10 +690,6 @@ VOID
NTAPI
KiInitializeBugCheck(VOID);
VOID
NTAPI
KiInitializeSystemClock(VOID);
VOID
NTAPI
KiSystemStartup(
@ -949,6 +911,15 @@ WRMSR(
IN LONGLONG Value
);
BOOLEAN
NTAPI
KeFreezeExecution(IN PKTRAP_FRAME TrapFrame,
IN PKEXCEPTION_FRAME ExceptionFrame);
VOID
NTAPI
KeThawExecution(IN BOOLEAN Enable);
#include "ke_x.h"
#endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */

View file

@ -384,7 +384,8 @@ extern GENERIC_MAPPING PspJobMapping;
extern POBJECT_TYPE PsJobType;
extern LARGE_INTEGER ShortPsLockDelay;
extern UNICODE_STRING PsNtDllPathName;
extern LIST_ENTRY PriorityListHead[MAXIMUM_PRIORITY];
extern LIST_ENTRY PsLoadedModuleList;
extern ULONG PsNtosImageBase;
//
// Inlined Functions

View file

@ -12,6 +12,7 @@
#define _WIN32_WINNT _WIN32_WINNT_WS03
#define NTDDI_VERSION NTDDI_WS03SP1
#define NTKERNELAPI
#define NOEXTAPI
/* DDK/IFS/NDK Headers */
#include <ntifs.h>
@ -51,6 +52,11 @@
/* SetupLDR Support */
#include <arc/setupblk.h>
/* KD Support */
#include <windbgkd.h>
#include <wdbgexts.h>
#include <kddll.h>
/* PNP GUIDs */
#include <umpnpmgr/sysguid.h>

View file

@ -37,15 +37,15 @@ KiRosPrintAddress(PVOID address)
{
PLIST_ENTRY current_entry;
PLDR_DATA_TABLE_ENTRY current;
extern LIST_ENTRY ModuleListHead;
extern LIST_ENTRY PsLoadedModuleList;
ULONG_PTR RelativeAddress;
ULONG i = 0;
do
{
current_entry = ModuleListHead.Flink;
current_entry = PsLoadedModuleList.Flink;
while (current_entry != &ModuleListHead)
while (current_entry != &PsLoadedModuleList)
{
current = CONTAINING_RECORD(current_entry,
LDR_DATA_TABLE_ENTRY,
@ -267,13 +267,13 @@ KiPcToFileHeader(IN PVOID Eip,
PVOID ImageBase, EipBase = NULL;
PLDR_DATA_TABLE_ENTRY Entry;
PLIST_ENTRY ListHead, NextEntry;
extern LIST_ENTRY ModuleListHead;
extern LIST_ENTRY PsLoadedModuleList;
/* Assume no */
*InKernel = FALSE;
/* Set list pointers and make sure it's valid */
ListHead = &ModuleListHead;
ListHead = &PsLoadedModuleList;
NextEntry = ListHead->Flink;
if (NextEntry)
{

View file

@ -74,6 +74,10 @@ KAFFINITY KeActiveProcessors = 1;
BOOLEAN KiI386PentiumLockErrataPresent;
BOOLEAN KiSMTProcessorsPresent;
/* Freeze data */
KIRQL KiOldIrql;
ULONG KiFreezeFlag;
/* CPU Signatures */
static const CHAR CmpIntelID[] = "GenuineIntel";
static const CHAR CmpAmdID[] = "AuthenticAMD";
@ -672,7 +676,36 @@ KeFlushCurrentTb(VOID)
VOID
NTAPI
KiSaveProcessorControlState(IN PKPROCESSOR_STATE ProcessorState)
KiRestoreProcessorControlState(PKPROCESSOR_STATE ProcessorState)
{
/* Restore the CR registers */
__writecr0(ProcessorState->SpecialRegisters.Cr0);
Ke386SetCr2(ProcessorState->SpecialRegisters.Cr2);
__writecr3(ProcessorState->SpecialRegisters.Cr3);
__writecr4(ProcessorState->SpecialRegisters.Cr4);
//
// Restore the DR registers
//
Ke386SetDr0(ProcessorState->SpecialRegisters.KernelDr0);
Ke386SetDr1(ProcessorState->SpecialRegisters.KernelDr1);
Ke386SetDr2(ProcessorState->SpecialRegisters.KernelDr2);
Ke386SetDr3(ProcessorState->SpecialRegisters.KernelDr3);
Ke386SetDr6(ProcessorState->SpecialRegisters.KernelDr6);
Ke386SetDr7(ProcessorState->SpecialRegisters.KernelDr7);
//
// Restore GDT, IDT, LDT and TSS
//
Ke386SetGlobalDescriptorTable(ProcessorState->SpecialRegisters.Gdtr);
Ke386SetInterruptDescriptorTable(ProcessorState->SpecialRegisters.Idtr);
Ke386SetTr(ProcessorState->SpecialRegisters.Tr);
Ke386SetLocalDescriptorTable(ProcessorState->SpecialRegisters.Ldtr);
}
VOID
NTAPI
KiSaveProcessorControlState(OUT PKPROCESSOR_STATE ProcessorState)
{
/* Save the CR registers */
ProcessorState->SpecialRegisters.Cr0 = __readcr0();
@ -807,6 +840,39 @@ KiI386PentiumLockErrataFixup(VOID)
MmSetPageProtect(NULL, NewIdt, PAGE_READONLY);
}
BOOLEAN
NTAPI
KeFreezeExecution(IN PKTRAP_FRAME TrapFrame,
IN PKEXCEPTION_FRAME ExceptionFrame)
{
ULONG Flags;
/* Disable interrupts and get previous state */
Ke386SaveFlags(Flags);
//Flags = __getcallerseflags();
_disable();
/* Save freeze flag */
KiFreezeFlag = 4;
/* Save the old IRQL */
KiOldIrql = KeGetCurrentIrql();
/* Return whether interrupts were enabled */
return (Flags & EFLAGS_INTERRUPT_MASK) ? TRUE: FALSE;
}
VOID
NTAPI
KeThawExecution(IN BOOLEAN Enable)
{
/* Cleanup CPU caches */
KeFlushCurrentTb();
/* Re-enable interrupts */
if (Enable) _enable();
}
/* PUBLIC FUNCTIONS **********************************************************/
/*

View file

@ -42,7 +42,8 @@
/* GLOBALS *******************************************************************/
LIST_ENTRY ModuleListHead;
LIST_ENTRY PsLoadedModuleList;
ULONG PsNtosImageBase = 0x80100000;
KSPIN_LOCK ModuleListLock;
LDR_DATA_TABLE_ENTRY NtoskrnlModuleObject;
LDR_DATA_TABLE_ENTRY HalModuleObject;
@ -101,7 +102,7 @@ LdrInit1(VOID)
PLDR_DATA_TABLE_ENTRY HalModuleObject, NtoskrnlModuleObject, LdrEntry;
/* Initialize the module list and spinlock */
InitializeListHead(&ModuleListHead);
InitializeListHead(&PsLoadedModuleList);
KeInitializeSpinLock(&ModuleListLock);
/* Get the NTOSKRNL Entry from the loader */
@ -112,13 +113,14 @@ LdrInit1(VOID)
sizeof(LDR_DATA_TABLE_ENTRY),
TAG('M', 'm', 'L', 'd'));
NtoskrnlModuleObject->DllBase = LdrEntry->DllBase;
PsNtosImageBase = PtrToUlong(LdrEntry->DllBase);
RtlInitUnicodeString(&NtoskrnlModuleObject->FullDllName, KERNEL_MODULE_NAME);
LdrpBuildModuleBaseName(&NtoskrnlModuleObject->BaseDllName, &NtoskrnlModuleObject->FullDllName);
NtoskrnlModuleObject->EntryPoint = LdrEntry->EntryPoint;
NtoskrnlModuleObject->SizeOfImage = LdrEntry->SizeOfImage;
/* Insert it into the list */
InsertTailList(&ModuleListHead, &NtoskrnlModuleObject->InLoadOrderLinks);
InsertTailList(&PsLoadedModuleList, &NtoskrnlModuleObject->InLoadOrderLinks);
/* Get the HAL Entry from the loader */
LdrEntry = CONTAINING_RECORD(KeLoaderBlock->LoadOrderListHead.Flink->Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
@ -134,7 +136,7 @@ LdrInit1(VOID)
HalModuleObject->SizeOfImage = LdrEntry->SizeOfImage;
/* Insert it into the list */
InsertTailList(&ModuleListHead, &HalModuleObject->InLoadOrderLinks);
InsertTailList(&PsLoadedModuleList, &HalModuleObject->InLoadOrderLinks);
}
NTSTATUS
@ -384,8 +386,8 @@ LdrpQueryModuleInformation (
KeAcquireSpinLock(&ModuleListLock,&Irql);
/* calculate required size */
current_entry = ModuleListHead.Flink;
while (current_entry != (&ModuleListHead))
current_entry = PsLoadedModuleList.Flink;
while (current_entry != (&PsLoadedModuleList))
{
ModuleCount++;
current = CONTAINING_RECORD(current_entry,LDR_DATA_TABLE_ENTRY,InLoadOrderLinks);
@ -418,8 +420,8 @@ LdrpQueryModuleInformation (
Smi->NumberOfModules = ModuleCount;
ModuleCount = 0;
current_entry = ModuleListHead.Flink;
while (current_entry != (&ModuleListHead))
current_entry = PsLoadedModuleList.Flink;
while (current_entry != (&PsLoadedModuleList))
{
current = CONTAINING_RECORD(current_entry,LDR_DATA_TABLE_ENTRY,InLoadOrderLinks);
@ -576,8 +578,8 @@ LdrGetModuleObject ( PUNICODE_STRING ModuleName )
KeAcquireSpinLock(&ModuleListLock,&Irql);
Entry = ModuleListHead.Flink;
while (Entry != &ModuleListHead)
Entry = PsLoadedModuleList.Flink;
while (Entry != &PsLoadedModuleList)
{
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
@ -871,7 +873,7 @@ LdrPEProcessModule(
/* Insert module */
KeAcquireSpinLock(&ModuleListLock, &Irql);
InsertTailList(&ModuleListHead,
InsertTailList(&PsLoadedModuleList,
&CreatedModuleObject->InLoadOrderLinks);
KeReleaseSpinLock(&ModuleListLock, Irql);

View file

@ -409,7 +409,7 @@ MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
ANSI_STRING AnsiRoutineName;
NTSTATUS Status;
PLIST_ENTRY NextEntry;
extern LIST_ENTRY ModuleListHead;
extern LIST_ENTRY PsLoadedModuleList;
PLDR_DATA_TABLE_ENTRY LdrEntry;
BOOLEAN Found = FALSE;
UNICODE_STRING KernelName = RTL_CONSTANT_STRING(L"ntoskrnl.exe");
@ -422,8 +422,8 @@ MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
if (!NT_SUCCESS(Status)) return NULL;
/* Loop the loaded module list */
NextEntry = ModuleListHead.Flink;
while (NextEntry != &ModuleListHead)
NextEntry = PsLoadedModuleList.Flink;
while (NextEntry != &PsLoadedModuleList)
{
/* Get the entry */
LdrEntry = CONTAINING_RECORD(NextEntry,

View file

@ -143,7 +143,7 @@ RiPrintLastOwner ( PR_USED Block )
if ( Block->LastOwnerStack[i] != 0xDEADBEEF )
{
R_DEBUG(" ");
if (!R_PRINT_ADDRESS ((PVOID)Block->LastOwnerStack[i]) )
//if (!R_PRINT_ADDRESS ((PVOID)Block->LastOwnerStack[i]) )
{
R_DEBUG("<%X>", Block->LastOwnerStack[i] );
}

View file

@ -19,7 +19,7 @@ LIST_ENTRY MiVerifierDriverAddedThunkListHead;
KMUTANT MmSystemLoadLock;
ULONG MiActiveVerifierThunks;
extern LIST_ENTRY ModuleListHead;
extern LIST_ENTRY PsLoadedModuleList;
/* PRIVATE FUNCTIONS *********************************************************/
@ -32,7 +32,7 @@ MiLookupDataTableEntry(IN PVOID Address)
PAGED_CODE();
/* Loop entries */
NextEntry = ModuleListHead.Flink;
NextEntry = PsLoadedModuleList.Flink;
do
{
/* Get the loader entry */
@ -51,7 +51,7 @@ MiLookupDataTableEntry(IN PVOID Address)
/* Move on */
NextEntry = NextEntry->Flink;
} while(NextEntry != &ModuleListHead);
} while(NextEntry != &PsLoadedModuleList);
/* Return the entry */
return FoundEntry;