- Directly call KdpGetMemorySizeInMBs() within KdpPrintBanner(),
instead of having the caller doing it.
- Use the miarm.h MiIsMemoryTypeInvisible() helper.
- Add Doxygen comments.
- 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.
PeLdrCheckForLoadedDll():
- Use a for-loop to iterate over the linked list.
- Adjust few comments.
- Use SAL2 annotations.
PeLdrpCompareDllName():
- Make its input paramters const.
- Use SAL2 annotations.
See https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlqueryregistryvalues
The RTL_REGISTRY_OPTIONAL applies to the first parameter of the
RtlQueryRegistryValues() function, not to the Flags member of the
table entries. However, a RTL_QUERY_REGISTRY_REQUIRED flag exists
to mark values whose existence is NOT optional.
Problematic usage was introduced in the following modules:
drivers/input/i8042prt: Commit e7e959fb0 (r30000)
drivers/input/kbdclass: Commit 5a77f871d (r18911)
drivers/input/mouclass: Commit aeeab7d1f (r18906)
drivers/input/sermouse: Commit 3f348259c (r19100)
rosapps/drivers/green : Commit c8a90f769 (r21165)
Override DbgPrint(), used by the debugger banner DPRINTs,
because KdInitSystem() can be called under the debugger lock
by KdEnableDebugger(WithLock)().
In this case, when DbgPrint() (re-)enters the debugger via an
interrupt and acquires the debugger lock, a deadlock occurs.
- The debugging banner helpers *CANNOT* be in the INIT section, because
it is possible for KdInitSystem() to enable the debugger **MUCH LATER**
after boot time. (Reverts part of commit f239ca0f0 (r72922).)
This can happen in two situations:
* When the debugger is in CRASHDEBUG mode, i.e. initialized at boot
time but not immediately enabled, and a BSOD happens later that
enables the debugger with a `KdInitSystem(0, NULL)` call.
* When the debugger was possibly manually disabled with a
KdDisableDebugger() call, then later re-enabled with a
KdEnableDebugger() call.
- In the same cases as described above, the KeLoaderBlock is freed after
boot time. Thus, KdpGetMemorySizeInMBs() cannot use it and enumerate
the MemoryDescriptors to evaluate the number of physical memory pages
available on the system. Instead, we can use what the memory manager
has already computed, since the latter is already initialized by now.
These two fixes avoid (invisible) crashes when (re-)enabling
the debugger at non-boot run time.
I.e. when LoaderBlock != NULL and we have loaded the initial hal and
ntoskrnl symbols. KdBreakAfterSymbolLoad is then checked for when the
other boot symbols have been loaded by ex/init.c!ExpLoadBootSymbols(),
invoked by ExpInitializeExecutive().
Use the PE import table's OriginalFirstThunk array when scanning and
resolving imports during DLL binding.
It points to an array of pointer-sized IMAGE_THUNK_DATA structures
which describe the functions being imported. On the other hand, the
FirstThunk points to an array of pointers, whose initial values are
a copy of those pointed to by OriginalFirstThunk, but are replaced
by the actual function pointers determined at runtime, when a DLL
is loaded (see PeLdrpBindImportName() function).
If we were to use the FirstThunk array to find again later the imports
by name or ordinal, we would fail because these are replaced by the
addresses of the corresponding functions.
This fixes loading kdcom.dll from Windows XP x64 with FreeLDR when
testing on ReactOS x64.
```diff
(freeldr\freeldr\lib\peloader.c:498) trace: PeLdrpScanImportAddressTable() ---- Calling PeLdrpBindImportName() in a loop
(freeldr\freeldr\lib\peloader.c:501) trace: *** ThunkName->u1.AddressOfData = 00000000000070F0
(freeldr\freeldr\lib\peloader.c:502) trace: *** ThunkData->u1.AddressOfData = 0000000000573780
(freeldr\freeldr\lib\peloader.c:209) trace: !!! ExportDirectory->NumberOfNames 1504
-(freeldr\freeldr\lib\peloader.c:210) trace: !!! ImportHint 0 - ExportName 'CcCanIWrite' - ImportDataName ''
+(freeldr\freeldr\lib\peloader.c:210) trace: !!! ImportHint 282 - ExportName 'HalPrivateDispatchTable' - ImportDataName 'HalPrivateDispatchTable'
....
-(freeldr\freeldr\lib\peloader.c:268) err: Did not find export ''!
-(freeldr\freeldr\lib\peloader.c:709) err: PeLdrpScanImportAddressTable() failed: ImportName = 'ntoskrnl.exe', DirectoryPath = 'multi(0)disk(0)rdisk(0)partition(2)\ReactOS\system32\'
```
('-': lines before the fix; '+': lines after the fix)
Code has been adapted based from the following functions:
ntdll/ldr/ldrpe.c!LdrpSnapThunk() and LdrpSnapIAT()
ntoskrnl/mm/ARM3/sysldr.c!MiSnapThunk() and MiResolveImageReferences()
References:
https://devblogs.microsoft.com/oldnewthing/20231129-00/?p=109077https://devblogs.microsoft.com/oldnewthing/20231130-00/?p=109084https://stackoverflow.com/questions/42413937/why-pe-need-original-first-thunkoft
CORE-13525
Notes:
- Most of the exported functions have been turned from default cdecl to explicit stdcall / "NTAPI".
- The two InitializeSetup() phases have been collapsed to make the initialization simpler.
Average reductions (percentages; see PR #7523 for actual numbers):
x86 Debug builds:
reactos.exe: 35.1%
smss.exe : 39.8%
Total (including setuplib.dll): 17.9%
x86 Release builds:
reactos.exe: 22.3%
smss.exe : 25.0%
Total (including setuplib.dll): 10.6%
x64 Debug builds:
reactos.exe: 40.6%
smss.exe : 41.6%
Total (including setuplib.dll): 20.0%
x64 Release builds:
reactos.exe: 22.8%
smss.exe : 22.3%
Total (including setuplib.dll): 10.1%
Use name from public Windows SDK for 'Network Connections' CLSID, available since Windows SDK 6.0A (Visual Studio 2008 or higher).
Replace all such instances in netshell, shell32, apitests/com.
- Partially reverts/refactors commit bea0b47
- Follow-up to PR #7266
Improves detection of Explorer being the default shell.
- Check the "Software\Microsoft\Windows NT\CurrentVersion\Winlogon" key to see if Explorer is the default shell.
- Use this check to determine whether to start the desktop and taskbar or only open a file browser window.
JIRA issue CORE-19887