https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ec4c169e3ebe128892141…
commit ec4c169e3ebe128892141d2d39b7ac80dec18bdf
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Nov 28 20:18:32 2024 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Dec 14 23:31:49 2024 +0100
[NTOS:EX] Revamp ExpLoadBootSymbols() a bit.
- Use a for-loop.
- Make some comments more accurate.
- Reduce indentation level in the loop.
---
ntoskrnl/ex/init.c | 120 ++++++++++++++++++++++++++---------------------------
1 file changed, 58 insertions(+), 62 deletions(-)
diff --git a/ntoskrnl/ex/init.c b/ntoskrnl/ex/init.c
index 433a635d7d2..6393a1083f9 100644
--- a/ntoskrnl/ex/init.c
+++ b/ntoskrnl/ex/init.c
@@ -790,84 +790,79 @@ ExpIsLoaderValid(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
return TRUE;
}
-CODE_SEG("INIT")
+static CODE_SEG("INIT")
VOID
-NTAPI
-ExpLoadBootSymbols(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
+ExpLoadBootSymbols(
+ _In_ PLOADER_PARAMETER_BLOCK LoaderBlock)
{
- ULONG i = 0;
PLIST_ENTRY NextEntry;
+ PLDR_DATA_TABLE_ENTRY LdrEntry;
+ NTSTATUS Status;
+ ULONG i;
ULONG Count, Length;
PWCHAR Name;
- PLDR_DATA_TABLE_ENTRY LdrEntry;
+ STRING ImageName;
CHAR NameBuffer[256];
- STRING SymbolString;
- NTSTATUS Status;
- /* Loop the driver list */
- NextEntry = LoaderBlock->LoadOrderListHead.Flink;
- while (NextEntry != &LoaderBlock->LoadOrderListHead)
+ /* Loop over the boot modules list */
+ for (NextEntry = LoaderBlock->LoadOrderListHead.Flink, i = 0;
+ NextEntry != &LoaderBlock->LoadOrderListHead;
+ NextEntry = NextEntry->Flink, ++i)
{
- /* Skip the first two images */
- if (i >= 2)
+ /* Skip the first two images: HAL and kernel */
+ if (i < 2)
+ continue;
+
+ /* Get the entry */
+ LdrEntry = CONTAINING_RECORD(NextEntry,
+ LDR_DATA_TABLE_ENTRY,
+ InLoadOrderLinks);
+ if (LdrEntry->FullDllName.Buffer[0] == L'\\')
{
- /* Get the entry */
- LdrEntry = CONTAINING_RECORD(NextEntry,
- LDR_DATA_TABLE_ENTRY,
- InLoadOrderLinks);
- if (LdrEntry->FullDllName.Buffer[0] == L'\\')
- {
- /* We have a name, read its data */
- Name = LdrEntry->FullDllName.Buffer;
- Length = LdrEntry->FullDllName.Length / sizeof(WCHAR);
+ /* We have a name, read its data */
+ Name = LdrEntry->FullDllName.Buffer;
+ Length = LdrEntry->FullDllName.Length / sizeof(WCHAR);
- /* Check if our buffer can hold it */
- if (sizeof(NameBuffer) < Length + sizeof(ANSI_NULL))
- {
- /* It's too long */
- Status = STATUS_BUFFER_OVERFLOW;
- }
- else
- {
- /* Copy the name */
- Count = 0;
- do
- {
- /* Copy the character */
- NameBuffer[Count++] = (CHAR)*Name++;
- } while (Count < Length);
-
- /* Null-terminate */
- NameBuffer[Count] = ANSI_NULL;
- Status = STATUS_SUCCESS;
- }
- }
- else
+ /* Check if our buffer can hold it */
+ if (sizeof(NameBuffer) < Length + sizeof(ANSI_NULL))
{
- /* Safely print the string into our buffer */
- Status = RtlStringCbPrintfA(NameBuffer,
- sizeof(NameBuffer),
- "%S\\System32\\Drivers\\%wZ",
- &SharedUserData->NtSystemRoot[2],
- &LdrEntry->BaseDllName);
+ /* It's too long */
+ Status = STATUS_BUFFER_OVERFLOW;
}
-
- /* Check if the buffer was ok */
- if (NT_SUCCESS(Status))
+ else
{
- /* Initialize the STRING for the debugger */
- RtlInitString(&SymbolString, NameBuffer);
+ /* Copy the name */
+ Count = 0;
+ do
+ {
+ /* Do cheap Unicode to ANSI conversion */
+ NameBuffer[Count++] = (CHAR)*Name++;
+ } while (Count < Length);
- /* Load the symbols */
- DbgLoadImageSymbols(&SymbolString,
- LdrEntry->DllBase,
- (ULONG_PTR)PsGetCurrentProcessId());
+ /* Null-terminate */
+ NameBuffer[Count] = ANSI_NULL;
+ Status = STATUS_SUCCESS;
}
}
+ else
+ {
+ /* Safely print the string into our buffer */
+ Status = RtlStringCbPrintfA(NameBuffer,
+ sizeof(NameBuffer),
+ "%S\\System32\\Drivers\\%wZ",
+ &SharedUserData->NtSystemRoot[2],
+ &LdrEntry->BaseDllName);
+ }
- /* Go to the next entry */
- i++;
- NextEntry = NextEntry->Flink;
+ /* Check if the buffer is OK */
+ if (NT_SUCCESS(Status))
+ {
+ /* Load the symbols */
+ RtlInitString(&ImageName, NameBuffer);
+ DbgLoadImageSymbols(&ImageName,
+ LdrEntry->DllBase,
+ (ULONG_PTR)PsGetCurrentProcessId());
+ }
}
}
@@ -1108,7 +1103,8 @@ ExpInitializeExecutive(IN ULONG Cpu,
ExpLoadBootSymbols(LoaderBlock);
/* Check if we should break after symbol load */
- if (KdBreakAfterSymbolLoad) DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
+ if (KdBreakAfterSymbolLoad)
+ DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
/* Check if this loader is compatible with NT 5.2 */
if (LoaderBlock->Extension->Size >= sizeof(LOADER_PARAMETER_EXTENSION))