https://git.reactos.org/?p=reactos.git;a=commitdiff;h=da59d797d15a957e14d97…
commit da59d797d15a957e14d97d179f0859b89f4447ca
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat Dec 7 16:31:15 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Dec 14 23:31:51 2024 +0100
[NTOS:EX] Minor enhancements to ExpDebuggerWorker()
- Add some DbgPrints.
- Use SAL2 annotations.
---
ntoskrnl/ex/dbgctrl.c | 24 +++++++++++++++---------
ntoskrnl/include/internal/ex.h | 5 ++++-
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/ntoskrnl/ex/dbgctrl.c b/ntoskrnl/ex/dbgctrl.c
index 70280703a31..f3fc6c0b43b 100644
--- a/ntoskrnl/ex/dbgctrl.c
+++ b/ntoskrnl/ex/dbgctrl.c
@@ -49,7 +49,8 @@ ULONG_PTR ExpDebuggerPageIn;
*/
VOID
NTAPI
-ExpDebuggerWorker(IN PVOID Context)
+ExpDebuggerWorker(
+ _In_ PVOID Context)
{
PEPROCESS ProcessToAttach, ProcessToKill;
ULONG_PTR PageInAddress;
@@ -83,11 +84,10 @@ ExpDebuggerWorker(IN PVOID Context)
Process = NULL;
/* Check if we need to attach or kill some process */
- if (ProcessToAttach != NULL || ProcessToKill != NULL)
+ if (ProcessToAttach || ProcessToKill)
{
/* Find the process in the list */
- Process = PsGetNextProcess(Process);
- while (Process)
+ while ((Process = PsGetNextProcess(Process)))
{
/* Is this the process we want to attach to? */
if (Process == ProcessToAttach)
@@ -104,12 +104,16 @@ ExpDebuggerWorker(IN PVOID Context)
ObDereferenceObject(Process);
return;
}
+ }
- /* Get the next process */
- Process = PsGetNextProcess(Process);
+ if (!Process)
+ {
+ DbgPrintEx(DPFLTR_SYSTEM_ID, DPFLTR_ERROR_LEVEL,
+ "EX debug work: Unable to find process %p\n",
+ ProcessToAttach ? ProcessToAttach : ProcessToKill);
}
- /* We either have found a process, or we default to the current process */
+ /* We either have found a process, or we default to the current one */
}
/* If we have an address to page in... */
@@ -122,7 +126,9 @@ ExpDebuggerWorker(IN PVOID Context)
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- DPRINT1("Failed to page in address 0x%p, Status 0x%08lx\n", PageInAddress, _SEH2_GetExceptionCode());
+ DbgPrintEx(DPFLTR_SYSTEM_ID, DPFLTR_ERROR_LEVEL,
+ "EX page in: Failed to page-in address 0x%p, Status 0x%08lx\n",
+ PageInAddress, _SEH2_GetExceptionCode());
}
_SEH2_END;
}
@@ -135,7 +141,7 @@ ExpDebuggerWorker(IN PVOID Context)
{
/* ... we can detach from the process */
KeUnstackDetachProcess(&ApcState);
- /* Dereference the process which was referenced for us by PsGetNextProcess */
+ /* Dereference the process referenced by PsGetNextProcess() */
ObDereferenceObject(Process);
}
}
diff --git a/ntoskrnl/include/internal/ex.h b/ntoskrnl/include/internal/ex.h
index 50dde0cbfc8..4c212972fcb 100644
--- a/ntoskrnl/include/internal/ex.h
+++ b/ntoskrnl/include/internal/ex.h
@@ -70,7 +70,10 @@ extern PEPROCESS ExpDebuggerProcessAttach;
extern PEPROCESS ExpDebuggerProcessKill;
extern ULONG_PTR ExpDebuggerPageIn;
-VOID NTAPI ExpDebuggerWorker(IN PVOID Context);
+VOID
+NTAPI
+ExpDebuggerWorker(
+ _In_ PVOID Context);
#ifdef _WIN64
#define HANDLE_LOW_BITS (PAGE_SHIFT - 4)
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f395f87bb35fbc66c920a…
commit f395f87bb35fbc66c920abf2ea6acb9be9dd49fa
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Nov 28 21:11:24 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Dec 14 23:31:48 2024 +0100
[NTOS:MM] MiScanMemoryDescriptors(): Use the MiIsMemoryTypeInvisible() and MiIsMemoryTypeFree() helpers.
---
ntoskrnl/mm/ARM3/mminit.c | 21 ++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)
diff --git a/ntoskrnl/mm/ARM3/mminit.c b/ntoskrnl/mm/ARM3/mminit.c
index bd5ab3caa88..30e17c6edff 100644
--- a/ntoskrnl/mm/ARM3/mminit.c
+++ b/ntoskrnl/mm/ARM3/mminit.c
@@ -421,20 +421,14 @@ MiScanMemoryDescriptors(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
/* Count this descriptor */
MiNumberDescriptors++;
- /* Check if this is invisible memory */
- if ((Descriptor->MemoryType == LoaderFirmwarePermanent) ||
- (Descriptor->MemoryType == LoaderSpecialMemory) ||
- (Descriptor->MemoryType == LoaderHALCachedMemory) ||
- (Descriptor->MemoryType == LoaderBBTMemory))
- {
- /* Skip this descriptor */
+ /* If this is invisible memory, skip this descriptor */
+ if (MiIsMemoryTypeInvisible(Descriptor->MemoryType))
continue;
- }
- /* Check if this is bad memory */
+ /* Check if this isn't bad memory */
if (Descriptor->MemoryType != LoaderBad)
{
- /* Count this in the total of pages */
+ /* Count it in the physical pages */
MmNumberOfPhysicalPages += (PFN_COUNT)Descriptor->PageCount;
}
@@ -454,12 +448,9 @@ MiScanMemoryDescriptors(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
}
/* Check if this is free memory */
- if ((Descriptor->MemoryType == LoaderFree) ||
- (Descriptor->MemoryType == LoaderLoadedProgram) ||
- (Descriptor->MemoryType == LoaderFirmwareTemporary) ||
- (Descriptor->MemoryType == LoaderOsloaderStack))
+ if (MiIsMemoryTypeFree(Descriptor->MemoryType))
{
- /* Count it too free pages */
+ /* Count it in the free pages */
MiNumberOfFreePages += Descriptor->PageCount;
/* Check if this is the largest memory descriptor */
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cb0c9a4570b2c563c866d…
commit cb0c9a4570b2c563c866d07d98be1b7729cbbc26
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Nov 28 20:07:25 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Dec 14 23:31:46 2024 +0100
[NTOS:KD64] KdInitSystem(): Minor code enhancements.
- Move local variables to the code blocks where they are used.
- if-s one-line bodies on their own lines.
- Massage the boot-images symbols loading, using a for-loop.
---
ntoskrnl/kd64/kdinit.c | 71 +++++++++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 39 deletions(-)
diff --git a/ntoskrnl/kd64/kdinit.c b/ntoskrnl/kd64/kdinit.c
index 93f2bd7dfca..99ff187b962 100644
--- a/ntoskrnl/kd64/kdinit.c
+++ b/ntoskrnl/kd64/kdinit.c
@@ -162,21 +162,10 @@ KdInitSystem(
_In_ ULONG BootPhase,
_In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock)
{
- BOOLEAN EnableKd, DisableKdAfterInit = FALSE, BlockEnable;
- PSTR CommandLine, DebugLine, DebugOptionStart, DebugOptionEnd;
- STRING ImageName;
+ BOOLEAN EnableKd, DisableKdAfterInit = FALSE, BlockEnable = FALSE;
PLDR_DATA_TABLE_ENTRY LdrEntry;
- PLIST_ENTRY NextEntry;
- ULONG i, j, Length;
- SIZE_T DebugOptionLength;
+ ULONG i;
SIZE_T MemSizeMBs;
- CHAR NameBuffer[256];
- PWCHAR Name;
-
-#if defined(__GNUC__)
- /* Make gcc happy */
- BlockEnable = FALSE;
-#endif
/* Check if this is Phase 1 */
if (BootPhase)
@@ -187,7 +176,8 @@ KdInitSystem(
}
/* Check if we already initialized once */
- if (KdDebuggerEnabled) return TRUE;
+ if (KdDebuggerEnabled)
+ return TRUE;
/* Set the Debug Routine as the Stub for now */
KiDebugRoutine = KdpStub;
@@ -233,6 +223,8 @@ KdInitSystem(
/* Check if we have a loader block */
if (LoaderBlock)
{
+ PSTR CommandLine, DebugLine;
+
/* Get the image entry */
LdrEntry = CONTAINING_RECORD(LoaderBlock->LoadOrderListHead.Flink,
LDR_DATA_TABLE_ENTRY,
@@ -263,7 +255,7 @@ KdInitSystem(
/* Don't enable KD and don't let it be enabled later */
KdPitchDebugger = TRUE;
}
- else if ((DebugLine = strstr(CommandLine, "DEBUG")) != NULL)
+ else if ((DebugLine = strstr(CommandLine, "DEBUG")))
{
/* Enable KD */
EnableKd = TRUE;
@@ -272,11 +264,14 @@ KdInitSystem(
if (DebugLine[5] == '=')
{
/* Save pointers */
+ PSTR DebugOptionStart, DebugOptionEnd;
DebugOptionStart = DebugOptionEnd = &DebugLine[6];
/* Scan the string for debug options */
for (;;)
{
+ SIZE_T DebugOptionLength;
+
/* Loop until we reach the end of the string */
while (*DebugOptionEnd != ANSI_NULL)
{
@@ -287,7 +282,7 @@ KdInitSystem(
{
/*
* We reached the end of the option or
- * the end of the string, break out
+ * the end of the string, break out.
*/
break;
}
@@ -301,20 +296,19 @@ KdInitSystem(
/* Calculate the length of the current option */
DebugOptionLength = (DebugOptionEnd - DebugOptionStart);
- /*
- * Break out if we reached the last option
- * or if there were no options at all
- */
- if (!DebugOptionLength) break;
+ /*
+ * Break out if we reached the last option
+ * or if there were no options at all.
+ */
+ if (!DebugOptionLength)
+ break;
/* Now check which option this is */
if ((DebugOptionLength == 10) &&
!(strncmp(DebugOptionStart, "AUTOENABLE", 10)))
{
- /*
- * Disable the debugger, but
- * allow it to be reenabled
- */
+ /* Disable the debugger, but
+ * allow to re-enable it later */
DisableKdAfterInit = TRUE;
BlockEnable = FALSE;
KdAutoEnableOnEvent = TRUE;
@@ -335,14 +329,11 @@ KdInitSystem(
}
/*
- * If there are more options then
- * the next character should be a comma
+ * If there are more options then the next character
+ * should be a comma. Break out if it isn't.
*/
if (*DebugOptionEnd != ',')
- {
- /* It isn't, break out */
break;
- }
/* Move on to the next option */
DebugOptionEnd++;
@@ -431,10 +422,16 @@ KdInitSystem(
/* Check if we have a loader block */
if (LoaderBlock)
{
- /* Loop boot images */
- NextEntry = LoaderBlock->LoadOrderListHead.Flink;
- i = 0;
- while ((NextEntry != &LoaderBlock->LoadOrderListHead) && (i < 2))
+ PLIST_ENTRY NextEntry;
+ ULONG j, Length;
+ PWCHAR Name;
+ STRING ImageName;
+ CHAR NameBuffer[256];
+
+ /* Loop over the first two boot images: HAL and kernel */
+ for (NextEntry = LoaderBlock->LoadOrderListHead.Flink, i = 0;
+ NextEntry != &LoaderBlock->LoadOrderListHead && (i < 2);
+ NextEntry = NextEntry->Flink, ++i)
{
/* Get the image entry */
LdrEntry = CONTAINING_RECORD(NextEntry,
@@ -454,15 +451,11 @@ KdInitSystem(
/* Null-terminate */
NameBuffer[j] = ANSI_NULL;
- /* Load symbols for image */
+ /* Load the symbols */
RtlInitString(&ImageName, NameBuffer);
DbgLoadImageSymbols(&ImageName,
LdrEntry->DllBase,
(ULONG_PTR)PsGetCurrentProcessId());
-
- /* Go to the next entry */
- NextEntry = NextEntry->Flink;
- i++;
}
/* Check for incoming break-in and break on symbol load