From ef21516cc45e0d7152cfeaec7ae5799dc3c840c4 Mon Sep 17 00:00:00 2001 From: Stefan Ginsberg Date: Sun, 8 Nov 2009 01:13:49 +0000 Subject: [PATCH] - Disable the MiCacheImageSymbols call in MmLoadSystemImage for KD too as this hack is required for rossym rather than KDBG. Fixes detection of non-boot driver images by WinDbg. - Add another hack to freeldr.c to make sure that HAL is the second entry in the Load Order list -- detect if it isn't and insert it as the second entry manually if it isn't. - KdbInitialize can now assume that the 2nd entry in the Load Order list is HAL, just like ExpLoadBootSymbols and KD does, so get the Loader Entry directly instead of searching for it. - Move KiBootTss and KiBootGdt to freeldr.c as this is where they belong -- they are not required for NTLDR/WINLDR boot style and are only used directly in freeldr.c. - Get rid of the AcpiTableDetected variable from freeldr.c. Instead, set the AcpiTable entry to something and make PoInitSystem check for that instead to preserve the old behavior. - Implement KdpGetFirstParameter and KdpGetSecondParameter for ARM too -- just retrieve R3/R4 here. Also rename those macros to clarify what parameters we are retrieving. - Add MmIsSessionAddress stub and use it from KD handle session space properly in the Memory Query API, and ASSERT that we are not trying to do a copy to/from session space in MmDbgCopyMemory as we don't handle it properly. Put this in mmdbg.c for now as we don't implement session space, and it is only called from KD right now. - Rename the 3 kdsup.c files to kdx86.c, kdx64.c and kdarm.c to differ them from each other. - Implement KdpAllowDisable -- just check if any processor breakpoints are set on any processor in the system and disallow the disable if so. The routine is now architecture dependant, so move it to the appropriate files. - Get rid of the MmFreeLdr* variables too. These have been deprecated for some time now. - The ModuleObject and ImageBaseAddress parameters of MmLoadSystemImage are not optional so don't treat them as such, and don't zero initialize them as callers shouldn't rely on this. - Set LDRP_ENTRY_NATIVE instead of LDRP_COMPAT_DATABASE_PROCESSED to mark the image as a native image. Also fix the value of LDRP_ENTRY_NATIVE. - Fix definition of LDR_DATA_TABLE_ENTRY -- the Checksum member should be in the union too. - Remove some unnecessary externs for stuff we now define globally in the kernel headers. - Rename some variables in KD to better match the logic. - Move some x86 only stuff from global ke.h and ke_x.h to the x86 dependent ke.h. Remove DR_ACTIVE_MASK as it has been deprecated/unused for a while now. svn path=/trunk/; revision=44023 --- reactos/include/ndk/ldrtypes.h | 9 +- reactos/include/reactos/rosldr.h | 3 - reactos/ntoskrnl/ex/init.c | 4 +- reactos/ntoskrnl/include/internal/i386/ke.h | 183 +++++++++++++++++- reactos/ntoskrnl/include/internal/kd64.h | 13 +- reactos/ntoskrnl/include/internal/ke.h | 94 --------- reactos/ntoskrnl/include/internal/ke_x.h | 82 -------- reactos/ntoskrnl/include/internal/mm.h | 9 + reactos/ntoskrnl/include/internal/po.h | 3 +- .../ntoskrnl/kd64/amd64/{kdsup.c => kdx64.c} | 11 +- .../ntoskrnl/kd64/arm/{kdsup.c => kdarm.c} | 11 +- .../ntoskrnl/kd64/i386/{kdsup.c => kdx86.c} | 27 ++- reactos/ntoskrnl/kd64/kdapi.c | 47 ++--- reactos/ntoskrnl/kd64/kdprint.c | 34 ++-- reactos/ntoskrnl/kd64/kdtrap.c | 65 ++++--- reactos/ntoskrnl/kdbg/kdb_symbols.c | 7 +- reactos/ntoskrnl/ke/freeldr.c | 91 +++++++-- reactos/ntoskrnl/ke/i386/cpu.c | 23 --- reactos/ntoskrnl/ke/i386/exp.c | 1 - reactos/ntoskrnl/mm/mmdbg.c | 15 ++ reactos/ntoskrnl/mm/sysldr.c | 31 ++- reactos/ntoskrnl/po/power.c | 9 +- 22 files changed, 437 insertions(+), 335 deletions(-) rename reactos/ntoskrnl/kd64/amd64/{kdsup.c => kdx64.c} (95%) rename reactos/ntoskrnl/kd64/arm/{kdsup.c => kdarm.c} (95%) rename reactos/ntoskrnl/kd64/i386/{kdsup.c => kdx86.c} (95%) diff --git a/reactos/include/ndk/ldrtypes.h b/reactos/include/ndk/ldrtypes.h index 62edb6c57aa..d706fec93e3 100644 --- a/reactos/include/ndk/ldrtypes.h +++ b/reactos/include/ndk/ldrtypes.h @@ -52,7 +52,7 @@ Author: #define LDRP_SYSTEM_MAPPED 0x01000000 #define LDRP_IMAGE_VERIFYING 0x02000000 #define LDRP_DRIVER_DEPENDENT_DLL 0x04000000 -#define LDRP_ENTRY_NATIVE 0x08800000 +#define LDRP_ENTRY_NATIVE 0x08000000 #define LDRP_REDIRECTED 0x10000000 #define LDRP_NON_PAGED_DEBUG_INFO 0x20000000 #define LDRP_MM_LOADED 0x40000000 @@ -112,9 +112,12 @@ typedef struct _LDR_DATA_TABLE_ENTRY union { LIST_ENTRY HashLinks; - PVOID SectionPointer; + struct + { + PVOID SectionPointer; + ULONG CheckSum; + }; }; - ULONG CheckSum; union { ULONG TimeDateStamp; diff --git a/reactos/include/reactos/rosldr.h b/reactos/include/reactos/rosldr.h index 7360c31bda1..029152e98f1 100644 --- a/reactos/include/reactos/rosldr.h +++ b/reactos/include/reactos/rosldr.h @@ -48,7 +48,4 @@ typedef struct _ROS_LOADER_PARAMETER_BLOCK ULONG (*FrLdrDbgPrint)(const char *Format, ...); } ROS_LOADER_PARAMETER_BLOCK, *PROS_LOADER_PARAMETER_BLOCK; -extern BOOLEAN AcpiTableDetected; -extern ULONG MmFreeLdrPageDirectoryStart, MmFreeLdrPageDirectoryEnd; - #endif diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 012f9fa81a6..bc4a37c7847 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -1395,7 +1395,7 @@ Phase1InitializationDiscard(IN PVOID Context) InbvDisplayString(EndBuffer); /* Initialize Power Subsystem in Phase 0 */ - if (!PoInitSystem(0, AcpiTableDetected)) KeBugCheck(INTERNAL_POWER_ERROR); + if (!PoInitSystem(0)) KeBugCheck(INTERNAL_POWER_ERROR); /* Check for Y2K hack */ Y2KHackRequired = strstr(CommandLine, "YEAR"); @@ -1833,7 +1833,7 @@ Phase1InitializationDiscard(IN PVOID Context) #endif /* Initialize Power Subsystem in Phase 1*/ - if (!PoInitSystem(1, AcpiTableDetected)) KeBugCheck(INTERNAL_POWER_ERROR); + if (!PoInitSystem(1)) KeBugCheck(INTERNAL_POWER_ERROR); /* Initialize the Process Manager at Phase 1 */ if (!PsInitSystem(LoaderBlock)) KeBugCheck(PROCESS1_INITIALIZATION_FAILED); diff --git a/reactos/ntoskrnl/include/internal/i386/ke.h b/reactos/ntoskrnl/include/internal/i386/ke.h index f62add28422..ea2f8bc286f 100644 --- a/reactos/ntoskrnl/include/internal/i386/ke.h +++ b/reactos/ntoskrnl/include/internal/i386/ke.h @@ -8,6 +8,12 @@ extern ULONG Ke386CacheAlignment; +// +// Thread Dispatcher Header DebugActive Mask +// +#define DR_MASK(x) (1 << (x)) +#define DR_REG_MASK 0x4F + #define IMAGE_FILE_MACHINE_ARCHITECTURE IMAGE_FILE_MACHINE_I386 // @@ -107,7 +113,180 @@ Ke386GetGdtEntryThread( IN PKGDTENTRY Descriptor ); +VOID +NTAPI +KiFlushNPXState( + IN FLOATING_SAVE_AREA *SaveArea +); + +VOID +NTAPI +Ki386AdjustEsp0( + IN PKTRAP_FRAME TrapFrame +); + +VOID +NTAPI +Ki386SetupAndExitToV86Mode( + OUT PTEB VdmTeb +); + +VOID +NTAPI +KeI386VdmInitialize( + VOID +); + +ULONG_PTR +NTAPI +Ki386EnableGlobalPage( + IN volatile ULONG_PTR Context +); + +VOID +NTAPI +KiI386PentiumLockErrataFixup( + VOID +); + +VOID +NTAPI +KiInitializePAT( + VOID +); + +VOID +NTAPI +KiInitializeMTRR( + IN BOOLEAN FinalCpu +); + +VOID +NTAPI +KiAmdK6InitializeMTRR( + VOID +); + +VOID +NTAPI +KiRestoreFastSyscallReturnState( + VOID +); + +ULONG_PTR +NTAPI +Ki386EnableDE( + IN ULONG_PTR Context +); + +ULONG_PTR +NTAPI +Ki386EnableFxsr( + IN ULONG_PTR Context +); + +ULONG_PTR +NTAPI +Ki386EnableXMMIExceptions( + IN ULONG_PTR Context +); + +// +// Global x86 only Kernel data +// +extern PVOID Ki386IopmSaveArea; +extern ULONG KeI386EFlagsAndMaskV86; +extern ULONG KeI386EFlagsOrMaskV86; +extern BOOLEAN KeI386VirtualIntExtensions; +extern KIDTENTRY KiIdt[MAXIMUM_IDTVECTOR]; +extern KDESCRIPTOR KiIdtDescriptor; +extern ULONG Ke386GlobalPagesEnabled; +extern BOOLEAN KiI386PentiumLockErrataPresent; +extern ULONG KeI386NpxPresent; +extern ULONG KeI386XMMIPresent; +extern ULONG KeI386FxsrPresent; +extern ULONG KiMXCsrMask; +extern ULONG KeI386CpuType; +extern ULONG KeI386CpuStep; +extern UCHAR KiDebugRegisterTrapOffsets[9]; +extern UCHAR KiDebugRegisterContextOffsets[9]; +extern VOID __cdecl KiTrap2(VOID); +extern VOID __cdecl KiTrap8(VOID); +extern VOID __cdecl KiTrap19(VOID); +extern VOID __cdecl KiFastCallEntry(VOID); + +// +// Sanitizes a selector +// +FORCEINLINE +ULONG +Ke386SanitizeSeg(IN ULONG Cs, + IN KPROCESSOR_MODE Mode) +{ + // + // Check if we're in kernel-mode, and force CPL 0 if so. + // Otherwise, force CPL 3. + // + return ((Mode == KernelMode) ? + (Cs & (0xFFFF & ~RPL_MASK)) : + (RPL_MASK | (Cs & 0xFFFF))); +} + +// +// Sanitizes EFLAGS +// +FORCEINLINE +ULONG +Ke386SanitizeFlags(IN ULONG Eflags, + IN KPROCESSOR_MODE Mode) +{ + // + // Check if we're in kernel-mode, and sanitize EFLAGS if so. + // Otherwise, also force interrupt mask on. + // + return ((Mode == KernelMode) ? + (Eflags & (EFLAGS_USER_SANITIZE | EFLAGS_INTERRUPT_MASK)) : + (EFLAGS_INTERRUPT_MASK | (Eflags & EFLAGS_USER_SANITIZE))); +} + +// +// Gets a DR register from a CONTEXT structure +// +FORCEINLINE +PVOID +KiDrFromContext(IN ULONG Dr, + IN PCONTEXT Context) +{ + return *(PVOID*)((ULONG_PTR)Context + KiDebugRegisterContextOffsets[Dr]); +} + +// +// Gets a DR register from a KTRAP_FRAME structure +// +FORCEINLINE +PVOID* +KiDrFromTrapFrame(IN ULONG Dr, + IN PKTRAP_FRAME TrapFrame) +{ + return (PVOID*)((ULONG_PTR)TrapFrame + KiDebugRegisterTrapOffsets[Dr]); +} + +// +// Sanitizes a Debug Register +// +FORCEINLINE +PVOID +Ke386SanitizeDr(IN PVOID DrAddress, + IN KPROCESSOR_MODE Mode) +{ + // + // Check if we're in kernel-mode, and return the address directly if so. + // Otherwise, make sure it's not inside the kernel-mode address space. + // If it is, then clear the address. + // + return ((Mode == KernelMode) ? DrAddress : + (DrAddress <= MM_HIGHEST_USER_ADDRESS) ? DrAddress : 0); +} + #endif #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H */ - -/* EOF */ diff --git a/reactos/ntoskrnl/include/internal/kd64.h b/reactos/ntoskrnl/include/internal/kd64.h index 3d7fc16cb7e..405aed1560b 100644 --- a/reactos/ntoskrnl/include/internal/kd64.h +++ b/reactos/ntoskrnl/include/internal/kd64.h @@ -179,7 +179,7 @@ KdEnterDebugger( VOID NTAPI KdExitDebugger( - IN BOOLEAN Entered + IN BOOLEAN Enable ); NTSTATUS @@ -207,7 +207,7 @@ KdpPrint( IN KPROCESSOR_MODE PreviousMode, IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, - OUT PBOOLEAN Status + OUT PBOOLEAN Handled ); USHORT @@ -313,6 +313,15 @@ KdpSuspendAllBreakPoints( VOID ); +// +// Routine to determine if it is safe to disable the debugger +// +NTSTATUS +NTAPI +KdpAllowDisable( + VOID +); + // // Safe memory read & write Support // diff --git a/reactos/ntoskrnl/include/internal/ke.h b/reactos/ntoskrnl/include/internal/ke.h index f512e2f1f30..34e1ae0cbc2 100644 --- a/reactos/ntoskrnl/include/internal/ke.h +++ b/reactos/ntoskrnl/include/internal/ke.h @@ -71,10 +71,6 @@ typedef PCHAR IN ULONG Length ); -extern ULONG_PTR MmFreeLdrFirstKrnlPhysAddr; -extern ULONG_PTR MmFreeLdrLastKrnlPhysAddr; -extern ULONG_PTR MmFreeLdrLastKernelAddress; - extern PVOID KeUserApcDispatcher; extern PVOID KeUserCallbackDispatcher; extern PVOID KeUserExceptionDispatcher; @@ -82,18 +78,10 @@ extern PVOID KeRaiseUserExceptionDispatcher; extern LARGE_INTEGER KeBootTime; extern ULONGLONG KeBootTimeBias; extern BOOLEAN ExCmosClockIsSane; -extern ULONG KeI386NpxPresent; -extern ULONG KeI386XMMIPresent; -extern ULONG KeI386FxsrPresent; -extern ULONG KiMXCsrMask; -extern ULONG KeI386CpuType; -extern ULONG KeI386CpuStep; extern ULONG KeProcessorArchitecture; extern ULONG KeProcessorLevel; extern ULONG KeProcessorRevision; extern ULONG KeFeatureBits; -extern ULONG Ke386GlobalPagesEnabled; -extern BOOLEAN KiI386PentiumLockErrataPresent; extern KNODE KiNode0; extern PKNODE KeNodeBlock[1]; extern UCHAR KeNumberNodes; @@ -105,17 +93,6 @@ extern PULONG KiInterruptTemplateObject; extern PULONG KiInterruptTemplateDispatch; extern PULONG KiInterruptTemplate2ndDispatch; extern ULONG KiUnexpectedEntrySize; -#ifdef _M_IX86 -extern PVOID Ki386IopmSaveArea; -extern ULONG KeI386EFlagsAndMaskV86; -extern ULONG KeI386EFlagsOrMaskV86; -extern BOOLEAN KeI386VirtualIntExtensions; -extern KIDTENTRY KiIdt[]; -extern KGDTENTRY KiBootGdt[]; -extern KDESCRIPTOR KiGdtDescriptor; -extern KDESCRIPTOR KiIdtDescriptor; -extern KTSS KiBootTss; -#endif extern UCHAR P0BootStack[]; extern UCHAR KiDoubleFaultStack[]; extern EX_PUSH_LOCK KernelAddressSpaceLock; @@ -142,16 +119,10 @@ extern KEVENT KiSwapEvent; extern PKPRCB KiProcessorBlock[]; extern ULONG KiMask32Array[MAXIMUM_PRIORITY]; extern ULONG KiIdleSummary; -extern VOID __cdecl KiTrap19(VOID); -extern VOID __cdecl KiTrap8(VOID); -extern VOID __cdecl KiTrap2(VOID); -extern VOID __cdecl KiFastCallEntry(VOID); extern PVOID KeUserApcDispatcher; extern PVOID KeUserCallbackDispatcher; extern PVOID KeUserExceptionDispatcher; extern PVOID KeRaiseUserExceptionDispatcher; -extern UCHAR KiDebugRegisterTrapOffsets[9]; -extern UCHAR KiDebugRegisterContextOffsets[9]; extern ULONG KeTimeIncrement; extern ULONG KeTimeAdjustment; extern ULONG_PTR KiBugCheckData[5]; @@ -883,41 +854,12 @@ KiChainedDispatch( VOID ); -VOID -NTAPI -Ki386AdjustEsp0( - IN PKTRAP_FRAME TrapFrame -); - -VOID -NTAPI -Ki386SetupAndExitToV86Mode( - OUT PTEB VdmTeb -); - -VOID -NTAPI -KeI386VdmInitialize( - VOID -); - VOID NTAPI KiInitializeMachineType( VOID ); -// -// We need to do major portability work -// -#ifdef _M_IX86 -VOID -NTAPI -KiFlushNPXState( - IN FLOATING_SAVE_AREA *SaveArea -); -#endif - VOID NTAPI KiSetupStackAndInitializeKernel( @@ -969,46 +911,10 @@ KiGetUserModeStackAddress( VOID ); -ULONG_PTR -NTAPI -Ki386EnableGlobalPage(IN volatile ULONG_PTR Context); - -VOID -NTAPI -KiInitializePAT(VOID); - -VOID -NTAPI -KiInitializeMTRR(IN BOOLEAN FinalCpu); - -VOID -NTAPI -KiAmdK6InitializeMTRR(VOID); - -VOID -NTAPI -KiRestoreFastSyscallReturnState(VOID); - -ULONG_PTR -NTAPI -Ki386EnableDE(IN ULONG_PTR Context); - -ULONG_PTR -NTAPI -Ki386EnableFxsr(IN ULONG_PTR Context); - -ULONG_PTR -NTAPI -Ki386EnableXMMIExceptions(IN ULONG_PTR Context); - VOID NTAPI KiInitMachineDependent(VOID); -VOID -NTAPI -KiI386PentiumLockErrataFixup(VOID); - BOOLEAN NTAPI KeFreezeExecution(IN PKTRAP_FRAME TrapFrame, diff --git a/reactos/ntoskrnl/include/internal/ke_x.h b/reactos/ntoskrnl/include/internal/ke_x.h index 85da12618db..b6f37e15548 100644 --- a/reactos/ntoskrnl/include/internal/ke_x.h +++ b/reactos/ntoskrnl/include/internal/ke_x.h @@ -6,88 +6,6 @@ * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) */ -// -// Thread Dispatcher Header DebugActive Mask -// -#define DR_MASK(x) 1 << x -#define DR_ACTIVE_MASK 0x10 -#define DR_REG_MASK 0x4F - -#ifdef _M_IX86 -// -// Sanitizes a selector -// -FORCEINLINE -ULONG -Ke386SanitizeSeg(IN ULONG Cs, - IN KPROCESSOR_MODE Mode) -{ - // - // Check if we're in kernel-mode, and force CPL 0 if so. - // Otherwise, force CPL 3. - // - return ((Mode == KernelMode) ? - (Cs & (0xFFFF & ~RPL_MASK)) : - (RPL_MASK | (Cs & 0xFFFF))); -} - -// -// Sanitizes EFLAGS -// -FORCEINLINE -ULONG -Ke386SanitizeFlags(IN ULONG Eflags, - IN KPROCESSOR_MODE Mode) -{ - // - // Check if we're in kernel-mode, and sanitize EFLAGS if so. - // Otherwise, also force interrupt mask on. - // - return ((Mode == KernelMode) ? - (Eflags & (EFLAGS_USER_SANITIZE | EFLAGS_INTERRUPT_MASK)) : - (EFLAGS_INTERRUPT_MASK | (Eflags & EFLAGS_USER_SANITIZE))); -} - -// -// Gets a DR register from a CONTEXT structure -// -FORCEINLINE -PVOID -KiDrFromContext(IN ULONG Dr, - IN PCONTEXT Context) -{ - return *(PVOID*)((ULONG_PTR)Context + KiDebugRegisterContextOffsets[Dr]); -} - -// -// Gets a DR register from a KTRAP_FRAME structure -// -FORCEINLINE -PVOID* -KiDrFromTrapFrame(IN ULONG Dr, - IN PKTRAP_FRAME TrapFrame) -{ - return (PVOID*)((ULONG_PTR)TrapFrame + KiDebugRegisterTrapOffsets[Dr]); -} - -// -// -// -FORCEINLINE -PVOID -Ke386SanitizeDr(IN PVOID DrAddress, - IN KPROCESSOR_MODE Mode) -{ - // - // Check if we're in kernel-mode, and return the address directly if so. - // Otherwise, make sure it's not inside the kernel-mode address space. - // If it is, then clear the address. - // - return ((Mode == KernelMode) ? DrAddress : - (DrAddress <= MM_HIGHEST_USER_ADDRESS) ? DrAddress : 0); -} -#endif /* _M_IX86 */ - #ifndef _M_ARM FORCEINLINE PRKTHREAD diff --git a/reactos/ntoskrnl/include/internal/mm.h b/reactos/ntoskrnl/include/internal/mm.h index 8a8f6b7260a..d7dc087d826 100644 --- a/reactos/ntoskrnl/include/internal/mm.h +++ b/reactos/ntoskrnl/include/internal/mm.h @@ -511,6 +511,15 @@ MmDbgCopyMemory( IN ULONG Flags ); +// +// Determines if a given address is a session address +// +BOOLEAN +NTAPI +MmIsSessionAddress( + IN PVOID Address +); + /* marea.c *******************************************************************/ NTSTATUS diff --git a/reactos/ntoskrnl/include/internal/po.h b/reactos/ntoskrnl/include/internal/po.h index f1cbc2192c0..e45a0d95957 100644 --- a/reactos/ntoskrnl/include/internal/po.h +++ b/reactos/ntoskrnl/include/internal/po.h @@ -38,8 +38,7 @@ BOOLEAN NTAPI PoInitSystem( - IN ULONG BootPhase, - IN BOOLEAN HaveAcpiTable + IN ULONG BootPhase ); VOID diff --git a/reactos/ntoskrnl/kd64/amd64/kdsup.c b/reactos/ntoskrnl/kd64/amd64/kdx64.c similarity index 95% rename from reactos/ntoskrnl/kd64/amd64/kdsup.c rename to reactos/ntoskrnl/kd64/amd64/kdx64.c index e335f7ae27b..32193c12061 100644 --- a/reactos/ntoskrnl/kd64/amd64/kdsup.c +++ b/reactos/ntoskrnl/kd64/amd64/kdx64.c @@ -1,7 +1,7 @@ /* * PROJECT: ReactOS Kernel * LICENSE: GPL - See COPYING in the top level directory - * FILE: ntoskrnl/kd64/amd64/kdsup.c + * FILE: ntoskrnl/kd64/amd64/kdx64.c * PURPOSE: KD support routines for AMD64 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org) */ @@ -149,3 +149,12 @@ KdpSysCheckLowMemory(IN ULONG Flags) while (TRUE); return STATUS_UNSUCCESSFUL; } + +NTSTATUS +NTAPI +KdpAllowDisable(VOID) +{ + UNIMPLEMENTED; + while (TRUE); + return STATUS_ACCESS_DENIED; +} diff --git a/reactos/ntoskrnl/kd64/arm/kdsup.c b/reactos/ntoskrnl/kd64/arm/kdarm.c similarity index 95% rename from reactos/ntoskrnl/kd64/arm/kdsup.c rename to reactos/ntoskrnl/kd64/arm/kdarm.c index e24ff16fef8..32a82ebb9d0 100644 --- a/reactos/ntoskrnl/kd64/arm/kdsup.c +++ b/reactos/ntoskrnl/kd64/arm/kdarm.c @@ -1,7 +1,7 @@ /* * PROJECT: ReactOS Kernel * LICENSE: BSD - See COPYING.ARM in the top level directory - * FILE: ntoskrnl/kd64/arm/kdsup.c + * FILE: ntoskrnl/kd64/arm/kdarm.c * PURPOSE: KD support routines for ARM * PROGRAMMERS: ReactOS Portable Systems Group */ @@ -149,3 +149,12 @@ KdpSysCheckLowMemory(IN ULONG Flags) while (TRUE); return STATUS_UNSUCCESSFUL; } + +NTSTATUS +NTAPI +KdpAllowDisable(VOID) +{ + UNIMPLEMENTED; + while (TRUE); + return STATUS_ACCESS_DENIED; +} diff --git a/reactos/ntoskrnl/kd64/i386/kdsup.c b/reactos/ntoskrnl/kd64/i386/kdx86.c similarity index 95% rename from reactos/ntoskrnl/kd64/i386/kdsup.c rename to reactos/ntoskrnl/kd64/i386/kdx86.c index dece8d99169..7b7eafbf744 100644 --- a/reactos/ntoskrnl/kd64/i386/kdsup.c +++ b/reactos/ntoskrnl/kd64/i386/kdx86.c @@ -1,7 +1,7 @@ /* * PROJECT: ReactOS Kernel * LICENSE: GPL - See COPYING in the top level directory - * FILE: ntoskrnl/kd64/i386/kdsup.c + * FILE: ntoskrnl/kd64/i386/kdx86.c * PURPOSE: KD support routines for x86 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) * Stefan Ginsberg (stefan.ginsberg@reactos.org) @@ -421,3 +421,28 @@ KdpSysCheckLowMemory(IN ULONG Flags) /* Stubbed as we don't support PAE */ return STATUS_UNSUCCESSFUL; } + +NTSTATUS +NTAPI +KdpAllowDisable(VOID) +{ + LONG i; + ULONG Dr7; + + /* Loop every processor */ + for (i = 0; i < KeNumberProcessors; i++) + { + /* Get its DR7 */ + Dr7 = KiProcessorBlock[i]->ProcessorState.SpecialRegisters.KernelDr7; + + /* Check if any processor breakpoints are active */ + if (Dr7 != 0) + { + /* We can't allow running without a debugger then */ + return STATUS_ACCESS_DENIED; + } + } + + /* No processor breakpoints; allow disabling the debugger */ + return STATUS_SUCCESS; +} diff --git a/reactos/ntoskrnl/kd64/kdapi.c b/reactos/ntoskrnl/kd64/kdapi.c index 43a8e375788..a3ce60da88a 100644 --- a/reactos/ntoskrnl/kd64/kdapi.c +++ b/reactos/ntoskrnl/kd64/kdapi.c @@ -112,8 +112,17 @@ KdpQueryMemory(IN PDBGKD_MANIPULATE_STATE64 State, } else { - /* FIXME: Check if it's session space */ - Memory->AddressSpace = DBGKD_QUERY_MEMORY_KERNEL; + /* Check if it's session space */ + if (MmIsSessionAddress((PVOID)(ULONG_PTR)Memory->Address)) + { + /* It is */ + Memory->AddressSpace = DBGKD_QUERY_MEMORY_SESSION; + } + else + { + /* Not session space but some other kernel memory */ + Memory->AddressSpace = DBGKD_QUERY_MEMORY_KERNEL; + } } /* Set flags */ @@ -1642,28 +1651,12 @@ KdpQueryPerformanceCounter(IN PKTRAP_FRAME TrapFrame) return KeQueryPerformanceCounter(NULL); } -NTSTATUS -NTAPI -KdpAllowDisable(VOID) -{ - /* Check if we are on MP */ - if (KeNumberProcessors > 1) - { - /* TODO */ - KdpDprintf("KdpAllowDisable: SMP UNHANDLED\n"); - while (TRUE); - } - - /* Allow disable */ - return STATUS_SUCCESS; -} - BOOLEAN NTAPI KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame) { - BOOLEAN Entered; + BOOLEAN Enable; /* Check if we have a trap frame */ if (TrapFrame) @@ -1683,7 +1676,7 @@ KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, KeGetCurrentPrcb()->DebuggerSavedIRQL = KeGetCurrentIrql(); /* Freeze all CPUs */ - Entered = KeFreezeExecution(TrapFrame, ExceptionFrame); + Enable = KeFreezeExecution(TrapFrame, ExceptionFrame); /* Lock the port, save the state and set debugger entered */ KdpPortLocked = KeTryToAcquireSpinLockAtDpcLevel(&KdpDebuggerLock); @@ -1707,13 +1700,13 @@ KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, /* Make sure we acquired the port */ if (!KdpPortLocked) KdpDprintf("Port lock was not acquired!\n"); - /* Return enter state */ - return Entered; + /* Return if interrupts needs to be re-enabled */ + return Enable; } VOID NTAPI -KdExitDebugger(IN BOOLEAN Entered) +KdExitDebugger(IN BOOLEAN Enable) { ULONG TimeSlip; @@ -1722,7 +1715,7 @@ KdExitDebugger(IN BOOLEAN Entered) if (KdpPortLocked) KdpPortUnlock(); /* Unfreeze the CPUs */ - KeThawExecution(Entered); + KeThawExecution(Enable); /* Compare time with the one from KdEnterDebugger */ if (!KdTimerStop.QuadPart) @@ -2048,7 +2041,7 @@ BOOLEAN NTAPI KdRefreshDebuggerNotPresent(VOID) { - BOOLEAN Entered, DebuggerNotPresent; + BOOLEAN Enable, DebuggerNotPresent; /* Check if the debugger is completely disabled */ if (KdPitchDebugger) @@ -2058,7 +2051,7 @@ KdRefreshDebuggerNotPresent(VOID) } /* Enter the debugger */ - Entered = KdEnterDebugger(NULL, NULL); + Enable = KdEnterDebugger(NULL, NULL); /* * Attempt to send a string to the debugger to refresh the @@ -2070,7 +2063,7 @@ KdRefreshDebuggerNotPresent(VOID) DebuggerNotPresent = KdDebuggerNotPresent; /* Exit the debugger and return the state */ - KdExitDebugger(Entered); + KdExitDebugger(Enable); return DebuggerNotPresent; } diff --git a/reactos/ntoskrnl/kd64/kdprint.c b/reactos/ntoskrnl/kd64/kdprint.c index 71f384c0602..0e3a62762b0 100644 --- a/reactos/ntoskrnl/kd64/kdprint.c +++ b/reactos/ntoskrnl/kd64/kdprint.c @@ -130,14 +130,14 @@ KdpCommandString(IN PSTRING NameString, IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame) { - BOOLEAN Entered; + BOOLEAN Enable; PKPRCB Prcb = KeGetCurrentPrcb(); /* Check if we need to do anything */ if ((PreviousMode != KernelMode) || (KdDebuggerNotPresent)) return; /* Enter the debugger */ - Entered = KdEnterDebugger(TrapFrame, ExceptionFrame); + Enable = KdEnterDebugger(TrapFrame, ExceptionFrame); /* Save the CPU Control State and save the context */ KiSaveProcessorControlState(&Prcb->ProcessorState); @@ -157,7 +157,7 @@ KdpCommandString(IN PSTRING NameString, KiRestoreProcessorControlState(&Prcb->ProcessorState); /* Exit the debugger and return */ - KdExitDebugger(Entered); + KdExitDebugger(Enable); } VOID @@ -170,14 +170,14 @@ KdpSymbol(IN PSTRING DllPath, IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame) { - BOOLEAN Entered; + BOOLEAN Enable; PKPRCB Prcb = KeGetCurrentPrcb(); /* Check if we need to do anything */ if ((PreviousMode != KernelMode) || (KdDebuggerNotPresent)) return; /* Enter the debugger */ - Entered = KdEnterDebugger(TrapFrame, ExceptionFrame); + Enable = KdEnterDebugger(TrapFrame, ExceptionFrame); /* Save the CPU Control State and save the context */ KiSaveProcessorControlState(&Prcb->ProcessorState); @@ -198,7 +198,7 @@ KdpSymbol(IN PSTRING DllPath, KiRestoreProcessorControlState(&Prcb->ProcessorState); /* Exit the debugger and return */ - KdExitDebugger(Entered); + KdExitDebugger(Enable); } USHORT @@ -212,7 +212,7 @@ KdpPrompt(IN LPSTR PromptString, IN PKEXCEPTION_FRAME ExceptionFrame) { STRING PromptBuffer, ResponseBuffer; - BOOLEAN Entered, Resend; + BOOLEAN Enable, Resend; /* Normalize the lengths */ PromptLength = min(PromptLength, 512); @@ -235,7 +235,7 @@ KdpPrompt(IN LPSTR PromptString, //KdLogDbgPrint(&PromptBuffer); /* Enter the debugger */ - Entered = KdEnterDebugger(TrapFrame, ExceptionFrame); + Enable = KdEnterDebugger(TrapFrame, ExceptionFrame); /* Enter prompt loop */ do @@ -247,7 +247,7 @@ KdpPrompt(IN LPSTR PromptString, } while (Resend); /* Exit the debugger */ - KdExitDebugger(Entered); + KdExitDebugger(Enable); /* Return the number of characters received */ return ResponseBuffer.Length; @@ -262,14 +262,14 @@ KdpPrint(IN ULONG ComponentId, IN KPROCESSOR_MODE PreviousMode, IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, - OUT PBOOLEAN Status) + OUT PBOOLEAN Handled) { NTSTATUS ReturnStatus; - BOOLEAN Entered; + BOOLEAN Enable; STRING OutputString; /* Assume failure */ - *Status = FALSE; + *Handled = FALSE; /* Validate the mask */ if (Level < 32) Level = 1 << Level; @@ -278,7 +278,7 @@ KdpPrint(IN ULONG ComponentId, !(*KdComponentTable[ComponentId] & Level))) { /* Mask validation failed */ - *Status = TRUE; + *Handled = TRUE; return STATUS_SUCCESS; } @@ -302,12 +302,12 @@ KdpPrint(IN ULONG ComponentId, if (KdDebuggerNotPresent) { /* Fail */ - *Status = TRUE; + *Handled = TRUE; return STATUS_DEVICE_NOT_CONNECTED; } /* Enter the debugger */ - Entered = KdEnterDebugger(TrapFrame, ExceptionFrame); + Enable = KdEnterDebugger(TrapFrame, ExceptionFrame); /* Print the string */ if (KdpPrintString(&OutputString)) @@ -322,8 +322,8 @@ KdpPrint(IN ULONG ComponentId, } /* Exit the debugger and return */ - KdExitDebugger(Entered); - *Status = TRUE; + KdExitDebugger(Enable); + *Handled = TRUE; return ReturnStatus; } diff --git a/reactos/ntoskrnl/kd64/kdtrap.c b/reactos/ntoskrnl/kd64/kdtrap.c index 4ad2069f07e..5de193bd17e 100644 --- a/reactos/ntoskrnl/kd64/kdtrap.c +++ b/reactos/ntoskrnl/kd64/kdtrap.c @@ -22,20 +22,24 @@ // // EBX/EDI on x86 // -#define KdpGetFirstParameter(Context) ((Context)->Ebx) -#define KdpGetSecondParameter(Context) ((Context)->Edi) +#define KdpGetParameterThree(Context) ((Context)->Ebx) +#define KdpGetParameterFour(Context) ((Context)->Edi) #elif defined(_AMD64_) // // R8/R9 on AMD64 // -#define KdpGetFirstParameter(Context) ((Context)->R8) -#define KdpGetSecondParameter(Context) ((Context)->R9) +#define KdpGetParameterThree(Context) ((Context)->R8) +#define KdpGetParameterFour(Context) ((Context)->R9) #elif defined(_ARM_) -#error Yo Ninjas! +// +// R3/R4 on ARM +// +#define KdpGetParameterThree(Context) ((Context)->R3) +#define KdpGetParameterFour(Context) ((Context)->R4) #else #error Unsupported Architecture @@ -52,7 +56,7 @@ KdpReport(IN PKTRAP_FRAME TrapFrame, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN SecondChanceException) { - BOOLEAN Entered, Status; + BOOLEAN Enable, Handled; PKPRCB Prcb; NTSTATUS ExceptionCode = ExceptionRecord->ExceptionCode; @@ -95,7 +99,7 @@ KdpReport(IN PKTRAP_FRAME TrapFrame, } /* Enter the debugger */ - Entered = KdEnterDebugger(TrapFrame, ExceptionFrame); + Enable = KdEnterDebugger(TrapFrame, ExceptionFrame); /* * Get the KPRCB and save the CPU Control State manually instead of @@ -108,10 +112,10 @@ KdpReport(IN PKTRAP_FRAME TrapFrame, sizeof(CONTEXT)); /* Report the new state */ - Status = KdpReportExceptionStateChange(ExceptionRecord, - &Prcb->ProcessorState. - ContextFrame, - SecondChanceException); + Handled = KdpReportExceptionStateChange(ExceptionRecord, + &Prcb->ProcessorState. + ContextFrame, + SecondChanceException); /* Now restore the processor state, manually again. */ RtlCopyMemory(ContextRecord, @@ -120,9 +124,9 @@ KdpReport(IN PKTRAP_FRAME TrapFrame, KiRestoreProcessorControlState(&Prcb->ProcessorState); /* Exit the debugger and clear the CTRL-C state */ - KdExitDebugger(Entered); + KdExitDebugger(Enable); KdpControlCPressed = FALSE; - return Status; + return Handled; } BOOLEAN @@ -136,7 +140,7 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame, { BOOLEAN Unload = FALSE; ULONG_PTR ProgramCounter; - BOOLEAN Status = FALSE; + BOOLEAN Handled; NTSTATUS ReturnStatus; USHORT ReturnLength; @@ -158,8 +162,8 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame, case BREAKPOINT_PRINT: /* Call the worker routine */ - ReturnStatus = KdpPrint((ULONG)KdpGetFirstParameter(ContextRecord), - (ULONG)KdpGetSecondParameter(ContextRecord), + ReturnStatus = KdpPrint((ULONG)KdpGetParameterThree(ContextRecord), + (ULONG)KdpGetParameterFour(ContextRecord), (LPSTR)ExceptionRecord-> ExceptionInformation[1], (USHORT)ExceptionRecord-> @@ -167,7 +171,7 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame, PreviousMode, TrapFrame, ExceptionFrame, - &Status); + &Handled); /* Update the return value for the caller */ KeSetContextReturnRegister(ContextRecord, ReturnStatus); @@ -181,12 +185,12 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame, ExceptionInformation[1], (USHORT)ExceptionRecord-> ExceptionInformation[2], - (LPSTR)KdpGetFirstParameter(ContextRecord), - (USHORT)KdpGetSecondParameter(ContextRecord), + (LPSTR)KdpGetParameterThree(ContextRecord), + (USHORT)KdpGetParameterFour(ContextRecord), PreviousMode, TrapFrame, ExceptionFrame); - Status = TRUE; + Handled = TRUE; /* Update the return value for the caller */ KeSetContextReturnRegister(ContextRecord, ReturnLength); @@ -211,7 +215,7 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame, ContextRecord, TrapFrame, ExceptionFrame); - Status = TRUE; + Handled = TRUE; break; /* DbgCommandString */ @@ -226,12 +230,13 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame, ContextRecord, TrapFrame, ExceptionFrame); - Status = TRUE; + Handled = TRUE; /* Anything else, do nothing */ default: - /* Get out */ + /* Invalid debug service! Don't handle this! */ + Handled = FALSE; break; } @@ -249,16 +254,16 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame, else { /* Call the worker routine */ - Status = KdpReport(TrapFrame, - ExceptionFrame, - ExceptionRecord, - ContextRecord, - PreviousMode, - SecondChanceException); + Handled = KdpReport(TrapFrame, + ExceptionFrame, + ExceptionRecord, + ContextRecord, + PreviousMode, + SecondChanceException); } /* Return TRUE or FALSE to caller */ - return Status; + return Handled; } BOOLEAN diff --git a/reactos/ntoskrnl/kdbg/kdb_symbols.c b/reactos/ntoskrnl/kdbg/kdb_symbols.c index b40447266c9..03ea286cbe7 100644 --- a/reactos/ntoskrnl/kdbg/kdb_symbols.c +++ b/reactos/ntoskrnl/kdbg/kdb_symbols.c @@ -529,10 +529,9 @@ KdbInitialize( LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); KdbSymProcessSymbols(LdrEntry); - /* Also load them for HAL.DLL. - This module has no fixed position, so search for it. */ - if(KdbpSymFindModule(NULL, L"HAL.DLL", -1, &LdrEntry)) - KdbSymProcessSymbols(LdrEntry); + /* Also load them for HAL.DLL. */ + LdrEntry = CONTAINING_RECORD(PsLoadedModuleList.Flink->Flink, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); + KdbSymProcessSymbols(LdrEntry); KdbpSymbolsInitialized = TRUE; } diff --git a/reactos/ntoskrnl/ke/freeldr.c b/reactos/ntoskrnl/ke/freeldr.c index 6099c58a3cc..65fd00dce75 100644 --- a/reactos/ntoskrnl/ke/freeldr.c +++ b/reactos/ntoskrnl/ke/freeldr.c @@ -9,10 +9,10 @@ /* INCLUDES *****************************************************************/ #include -//#define NDEBUG +#define NDEBUG #include -#ifdef _M_PPC +#if defined(_PPC_) #include #define KERNEL_RVA(x) RVA(x,0x80800000) #define KERNEL_DESCRIPTOR_PAGE(x) (((ULONG_PTR)x + KernelBase) >> PAGE_SHIFT) @@ -31,7 +31,6 @@ typedef struct _BIOS_MEMORY_DESCRIPTOR /* FreeLDR Loader Data */ PROS_LOADER_PARAMETER_BLOCK KeRosLoaderBlock; -BOOLEAN AcpiTableDetected = FALSE; ADDRESS_RANGE KeMemoryMap[64]; ULONG KeMemoryMapRangeCount; @@ -66,8 +65,35 @@ PBIOS_MEMORY_DESCRIPTOR BiosMemoryDescriptorList = BiosMemoryDescriptors; ULONG NumberDescriptors = 0; MEMORY_DESCRIPTOR MDArray[60] = { { 0, 0, 0 }, }; +#if defined(_X86_) + +/* The Boot TSS */ +KTSS KiBootTss; + /* Old boot style IDT */ -KIDTENTRY KiHackIdt[256]; +KIDTENTRY KiBootIdt[256]; + +/* The Boot GDT */ +KGDTENTRY KiBootGdt[256] = +{ + {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_NULL */ + {0xffff, 0x0000, {{0x00, 0x9b, 0xcf, 0x00}}}, /* KGDT_R0_CODE */ + {0xffff, 0x0000, {{0x00, 0x93, 0xcf, 0x00}}}, /* KGDT_R0_DATA */ + {0xffff, 0x0000, {{0x00, 0xfb, 0xcf, 0x00}}}, /* KGDT_R3_CODE */ + {0xffff, 0x0000, {{0x00, 0xf3, 0xcf, 0x00}}}, /* KGDT_R3_DATA*/ + {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_TSS */ + {0x0001, 0xf000, {{0xdf, 0x93, 0xc0, 0xff}}}, /* KGDT_R0_PCR */ + {0x0fff, 0x0000, {{0x00, 0xf3, 0x40, 0x00}}}, /* KGDT_R3_TEB */ + {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_UNUSED */ + {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_LDT */ + {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_DF_TSS */ + {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}} /* KGDT_NMI_TSS */ +}; + +/* GDT Descriptor */ +KDESCRIPTOR KiGdtDescriptor = {0, sizeof(KiBootGdt) - 1, (ULONG)KiBootGdt}; + +#endif /* FUNCTIONS *****************************************************************/ @@ -465,7 +491,7 @@ KiRosBuildOsMemoryMap(VOID) /* If anything failed until now, return error code */ if (Status != STATUS_SUCCESS) return Status; -#ifdef _M_IX86 +#if defined(_X86_) /* Set the top 16MB region as reserved */ Status = KiRosConfigureArcDescriptor(0xFC0, 0x1000, MemorySpecialMemory); if (Status != STATUS_SUCCESS) return Status; @@ -492,6 +518,7 @@ KiRosBuildOsMemoryMap(VOID) return Status; } +#if defined(_X86_) VOID NTAPI KiRosBuildReservedMemoryMap(VOID) @@ -560,6 +587,7 @@ KiRosBuildReservedMemoryMap(VOID) } } } +#endif VOID NTAPI @@ -917,13 +945,10 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock, WCHAR PathSetup[] = L"\\SystemRoot\\"; CHAR DriverNameLow[256]; ULONG Base; -#ifdef _M_PPC +#if defined(_PPC_) ULONG KernelBase = RosLoaderBlock->ModsAddr[0].ModStart; #endif - /* First get some kernel-loader globals */ - AcpiTableDetected = (RosLoaderBlock->Flags & MB_FLAGS_ACPI_TABLE) ? TRUE : FALSE; - /* Set the NT Loader block and initialize it */ *NtLoaderBlock = KeLoaderBlock = LoaderBlock = &BldrLoaderBlock; RtlZeroMemory(LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK)); @@ -949,7 +974,7 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock, /* Build entries for ReactOS memory ranges, which uses ARC Descriptors */ KiRosBuildOsMemoryMap(); -#ifdef _M_IX86 +#if defined(_X86_) /* Build entries for the reserved map, which uses ARC Descriptors */ KiRosBuildReservedMemoryMap(); #endif @@ -966,7 +991,7 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock, ModStart = (PVOID)RosEntry->ModStart; ModSize = RosEntry->ModEnd - (ULONG_PTR)ModStart; -#ifdef _M_PPC +#if defined(_PPC_) ModStart -= KernelBase; #endif @@ -1073,7 +1098,7 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock, &Base); } -#ifdef _M_PPC +#if defined(_PPC_) ModStart += 0x80800000; #endif @@ -1139,6 +1164,33 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock, LDRP_ENTRY_PROCESSED; if (RosEntry->Reserved) LdrEntry->Flags |= LDRP_ENTRY_INSERTED; + /* Check if this is HAL */ + if (!(_stricmp(DriverName, "hal.dll"))) + { + /* Check if there is a second entry already */ + if (LoaderBlock->LoadOrderListHead.Flink->Flink != + &LoaderBlock->LoadOrderListHead) + { + PLIST_ENTRY OldSecondEntry; + + /* Get the second entry */ + OldSecondEntry = + LoaderBlock->LoadOrderListHead.Flink->Flink; + + /* Set up our entry correctly */ + LdrEntry->InLoadOrderLinks.Flink = OldSecondEntry; + LdrEntry->InLoadOrderLinks.Blink = OldSecondEntry->Blink; + + /* Make the first entry (always the kernel) point to us */ + LoaderBlock->LoadOrderListHead.Flink->Flink = + &LdrEntry->InLoadOrderLinks; + + /* Make the old entry point back to us and continue looping */ + OldSecondEntry->Blink = &LdrEntry->InLoadOrderLinks; + continue; + } + } + /* Insert it into the loader block */ InsertTailList(&LoaderBlock->LoadOrderListHead, &LdrEntry->InLoadOrderLinks); @@ -1186,6 +1238,13 @@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PARAMETER_BLOCK RosLoaderBlock, /* Now convert to pages */ LoaderBlock->Extension->LoaderPagesSpanned /= PAGE_SIZE; + /* Check if FreeLdr detected a ACPI table */ + if (RosLoaderBlock->Flags & MB_FLAGS_ACPI_TABLE) + { + /* Set the pointer to something for compatibility */ + LoaderBlock->Extension->AcpiTable = (PVOID)1; + } + /* Now setup the setup block if we have one */ if (LoaderBlock->SetupLdrBlock) { @@ -1266,15 +1325,15 @@ KiRosPrepareForSystemStartup(IN ULONG Dummy, { PLOADER_PARAMETER_BLOCK NtLoaderBlock; ULONG size, i = 0, *ent; -#if defined(_M_IX86) +#if defined(_X86_) PKTSS Tss; PKGDTENTRY TssEntry; KDESCRIPTOR IdtDescriptor; __sidt(&IdtDescriptor.Limit); - RtlCopyMemory(KiHackIdt, (PVOID)IdtDescriptor.Base, IdtDescriptor.Limit + 1); - IdtDescriptor.Base = (ULONG)&KiHackIdt; - IdtDescriptor.Limit = sizeof(KiHackIdt) - 1; + RtlCopyMemory(KiBootIdt, (PVOID)IdtDescriptor.Base, IdtDescriptor.Limit + 1); + IdtDescriptor.Base = (ULONG)&KiBootIdt; + IdtDescriptor.Limit = sizeof(KiBootIdt) - 1; /* Load the GDT and IDT */ Ke386SetGlobalDescriptorTable(&KiGdtDescriptor.Limit); diff --git a/reactos/ntoskrnl/ke/i386/cpu.c b/reactos/ntoskrnl/ke/i386/cpu.c index 2e958d74cb8..111e2a89abb 100644 --- a/reactos/ntoskrnl/ke/i386/cpu.c +++ b/reactos/ntoskrnl/ke/i386/cpu.c @@ -14,35 +14,12 @@ /* GLOBALS *******************************************************************/ -/* The Boot TSS */ -KTSS KiBootTss; - /* The TSS to use for Double Fault Traps (INT 0x9) */ UCHAR KiDoubleFaultTSS[KTSS_IO_MAPS]; /* The TSS to use for NMI Fault Traps (INT 0x2) */ UCHAR KiNMITSS[KTSS_IO_MAPS]; -/* The Boot GDT */ -KGDTENTRY KiBootGdt[256] = -{ - {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_NULL */ - {0xffff, 0x0000, {{0x00, 0x9b, 0xcf, 0x00}}}, /* KGDT_R0_CODE */ - {0xffff, 0x0000, {{0x00, 0x93, 0xcf, 0x00}}}, /* KGDT_R0_DATA */ - {0xffff, 0x0000, {{0x00, 0xfb, 0xcf, 0x00}}}, /* KGDT_R3_CODE */ - {0xffff, 0x0000, {{0x00, 0xf3, 0xcf, 0x00}}}, /* KGDT_R3_DATA*/ - {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_TSS */ - {0x0001, 0xf000, {{0xdf, 0x93, 0xc0, 0xff}}}, /* KGDT_R0_PCR */ - {0x0fff, 0x0000, {{0x00, 0xf3, 0x40, 0x00}}}, /* KGDT_R3_TEB */ - {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_UNUSED */ - {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_LDT */ - {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_DF_TSS */ - {0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}} /* KGDT_NMI_TSS */ -}; - -/* GDT Descriptor */ -KDESCRIPTOR KiGdtDescriptor = {0, sizeof(KiBootGdt) - 1, (ULONG)KiBootGdt}; - /* CPU Features and Flags */ ULONG KeI386CpuType; ULONG KeI386CpuStep; diff --git a/reactos/ntoskrnl/ke/i386/exp.c b/reactos/ntoskrnl/ke/i386/exp.c index 28fdeb8fea1..c80ee0364fa 100644 --- a/reactos/ntoskrnl/ke/i386/exp.c +++ b/reactos/ntoskrnl/ke/i386/exp.c @@ -53,7 +53,6 @@ KeInitExceptions(VOID) { ULONG i; USHORT FlippedSelector; - extern KIDTENTRY KiIdt[MAXIMUM_IDTVECTOR]; /* Loop the IDT */ for (i = 0; i <= MAXIMUM_IDTVECTOR; i++) diff --git a/reactos/ntoskrnl/mm/mmdbg.c b/reactos/ntoskrnl/mm/mmdbg.c index 8224b5b739b..65f9ebc7f47 100644 --- a/reactos/ntoskrnl/mm/mmdbg.c +++ b/reactos/ntoskrnl/mm/mmdbg.c @@ -20,6 +20,16 @@ BOOLEAN MiDbgReadyForPhysical = FALSE; /* FUNCTIONS ******************************************************************/ +BOOLEAN +NTAPI +MmIsSessionAddress(IN PVOID Address) +{ + // + // No session space support yet + // + return FALSE; +} + PVOID NTAPI MiDbgTranslatePhysicalAddress(IN ULONG64 PhysicalAddress, @@ -217,6 +227,11 @@ MmDbgCopyMemory(IN ULONG64 Address, TargetAddress); return STATUS_UNSUCCESSFUL; } + + // + // No session space support yet + // + ASSERT(MmIsSessionAddress(TargetAddress) == FALSE); } // diff --git a/reactos/ntoskrnl/mm/sysldr.c b/reactos/ntoskrnl/mm/sysldr.c index cbabd8deaf1..f6177e4479f 100644 --- a/reactos/ntoskrnl/mm/sysldr.c +++ b/reactos/ntoskrnl/mm/sysldr.c @@ -32,7 +32,6 @@ LIST_ENTRY MmLoadedUserImageList; KSPIN_LOCK PsLoadedModuleSpinLock; ULONG_PTR PsNtosImageBase; KMUTANT MmSystemLoadLock; -extern ULONG NtGlobalFlag; PVOID MmUnloadedDrivers; PVOID MmLastUnloadedDrivers; @@ -997,7 +996,7 @@ CheckDllState: /* Now add the import name and null-terminate it */ RtlAppendStringToString((PSTRING)&DllName, (PSTRING)&NameString); - DllName.Buffer[(DllName.MaximumLength - 1) / 2] = UNICODE_NULL; + DllName.Buffer[(DllName.MaximumLength - 1) / sizeof(WCHAR)] = UNICODE_NULL; /* Load the image */ Status = MmLoadSystemImage(&DllName, @@ -1220,7 +1219,7 @@ MiReloadBootLoadedDrivers(IN PLOADER_PARAMETER_BLOCK LoaderBlock) /* Debug info */ DPRINT("[Mm0]: Driver at: %p ending at: %p for module: %wZ\n", LdrEntry->DllBase, - (ULONG_PTR)LdrEntry->DllBase+ LdrEntry->SizeOfImage, + (ULONG_PTR)LdrEntry->DllBase + LdrEntry->SizeOfImage, &LdrEntry->FullDllName); /* Skip kernel and HAL */ @@ -1315,7 +1314,7 @@ MiReloadBootLoadedDrivers(IN PLOADER_PARAMETER_BLOCK LoaderBlock) LdrEntry->SizeOfImage); /* Update the loader entry */ - LdrEntry->Flags |= 0x01000000; + LdrEntry->Flags |= LDRP_SYSTEM_MAPPED; LdrEntry->EntryPoint = (PVOID)((ULONG_PTR)NewImageAddress + NtHeader->OptionalHeader.AddressOfEntryPoint); LdrEntry->SizeOfImage = LdrEntry->SizeOfImage; @@ -1551,9 +1550,6 @@ MmLoadSystemImage(IN PUNICODE_STRING FileName, if (!PsGetCurrentProcess()->ProcessInSession) return STATUS_NO_MEMORY; } - if (ModuleObject) *ModuleObject = NULL; - if (ImageBaseAddress) *ImageBaseAddress = NULL; - /* Allocate a buffer we'll use for names */ Buffer = ExAllocatePoolWithTag(NonPagedPool, MAX_PATH, TAG_LDR_WSTR); if (!Buffer) return STATUS_INSUFFICIENT_RESOURCES; @@ -1644,8 +1640,8 @@ LoaderScan: if (!Flags) { /* It wasn't, so just return the data */ - if (ModuleObject) *ModuleObject = LdrEntry; - if (ImageBaseAddress) *ImageBaseAddress = LdrEntry->DllBase; + *ModuleObject = LdrEntry; + *ImageBaseAddress = LdrEntry->DllBase; Status = STATUS_IMAGE_ALREADY_LOADED; } else @@ -1818,7 +1814,7 @@ LoaderScan: (NtHeader->OptionalHeader.MajorImageVersion >= 5)) { /* Mark this image as a native image */ - LdrEntry->Flags |= 0x80000000; + LdrEntry->Flags |= LDRP_ENTRY_NATIVE; } /* Setup the rest of the entry */ @@ -1838,7 +1834,7 @@ LoaderScan: RtlCopyMemory(LdrEntry->BaseDllName.Buffer, BaseName.Buffer, BaseName.Length); - LdrEntry->BaseDllName.Buffer[BaseName.Length / 2] = UNICODE_NULL; + LdrEntry->BaseDllName.Buffer[BaseName.Length / sizeof(WCHAR)] = UNICODE_NULL; /* Now allocate the full name */ LdrEntry->FullDllName.Buffer = ExAllocatePoolWithTag(PagedPool, @@ -1861,7 +1857,7 @@ LoaderScan: RtlCopyMemory(LdrEntry->FullDllName.Buffer, PrefixName.Buffer, PrefixName.Length); - LdrEntry->FullDllName.Buffer[PrefixName.Length / 2] = UNICODE_NULL; + LdrEntry->FullDllName.Buffer[PrefixName.Length / sizeof(WCHAR)] = UNICODE_NULL; } /* Add the entry */ @@ -1919,11 +1915,11 @@ LoaderScan: PspRunLoadImageNotifyRoutines(FileName, NULL, &ImageInfo); } - /* Check if there's symbols */ -#ifdef KDBG - /* If KDBG is defined, then we always have symbols */ +#if defined(KDBG) || defined(_WINKD_) + /* MiCacheImageSymbols doesn't detect rossym */ if (TRUE) #else + /* Check if there's symbols */ if (MiCacheImageSymbols(LdrEntry->DllBase)) #endif { @@ -1960,8 +1956,8 @@ LoaderScan: ASSERT(Section == NULL); /* Return pointers */ - if (ModuleObject) *ModuleObject = LdrEntry; - if (ImageBaseAddress) *ImageBaseAddress = LdrEntry->DllBase; + *ModuleObject = LdrEntry; + *ImageBaseAddress = LdrEntry->DllBase; Quickie: /* If we have a file handle, close it */ @@ -1995,7 +1991,6 @@ MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName) ANSI_STRING AnsiRoutineName; NTSTATUS Status; PLIST_ENTRY NextEntry; - extern LIST_ENTRY PsLoadedModuleList; PLDR_DATA_TABLE_ENTRY LdrEntry; BOOLEAN Found = FALSE; UNICODE_STRING KernelName = RTL_CONSTANT_STRING(L"ntoskrnl.exe"); diff --git a/reactos/ntoskrnl/po/power.c b/reactos/ntoskrnl/po/power.c index 486b0fe0fe4..f103898d2f5 100644 --- a/reactos/ntoskrnl/po/power.c +++ b/reactos/ntoskrnl/po/power.c @@ -15,8 +15,6 @@ /* GLOBALS *******************************************************************/ -extern ULONG ExpInitialiationPhase; - typedef struct _REQUEST_POWER_ITEM { PREQUEST_POWER_COMPLETE CompletionRoutine; @@ -126,8 +124,7 @@ PopSetSystemPowerState(SYSTEM_POWER_STATE PowerState) BOOLEAN NTAPI -PoInitSystem(IN ULONG BootPhase, - IN BOOLEAN HaveAcpiTable) +PoInitSystem(IN ULONG BootPhase) { PVOID NotificationEntry; PCHAR CommandLine; @@ -164,8 +161,8 @@ PoInitSystem(IN ULONG BootPhase, } else { - /* Otherwise check the LoaderBlock's Flag */ - PopAcpiPresent = HaveAcpiTable; + /* Otherwise check if the LoaderBlock has a ACPI Table */ + PopAcpiPresent = KeLoaderBlock->Extension->AcpiTable != NULL ? TRUE : FALSE; } return TRUE;