Commit graph

1785 commits

Author SHA1 Message Date
Hermès Bélusca-Maïto
a18424267b
[NTOS:CM] Add some more configuration options.
Add support for configuring the CM lazy-flush and delay-close variables:

  `CmpLazyFlushIntervalInSeconds`, `CmpLazyFlushHiveCount`,
  and `CmpDelayedCloseSize`,

using REG_DWORD values named respectively:

  `RegistryLazyFlushInterval`, `RegistryLazyFlushHiveCount`,
  and `DelayCloseSize`,

in the registry key
`HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Configuration Manager` .

Extra observations:
- While delay-close support exists in Windows 2003, configuring
  the delay-close size is possible only in Windows Vista and later.
- The possibility of configuring the lazy-flush hive count has been
  removed in Windows 8+.

See the comparison tables at:
https://redplait.blogspot.com/2011/07/cmcontrolvector.html
https://redplait.blogspot.com/2012/06/cmcontrolvector-for-w8.html
https://redplait.blogspot.com/2016/03/cmcontrolvector-from-windows-10-build.html

In addition:
Remove `CmpDelayedCloseIndex` from cm.h as it is not used anymore in our code.
2024-12-19 11:52:13 +01:00
Thamatip Chitpong
1e06829961 [NTOS:PS] Add query support for QUOTA_LIMITS_EX 2024-12-18 09:53:21 +07:00
Thamatip Chitpong
bf0dbdbd19 [NTOS:PS] NtQueryInformationProcess: Move process information-specific variables to their own scope 2024-12-18 09:53:21 +07:00
Timo Kreuzer
5ebd478325 [NTOS][HAL:APIC] Call HalBegin/EndSystemInterrupt from clock handler 2024-12-16 16:21:44 +02:00
Timo Kreuzer
67231bd69a [NTOS:KE/X64] Fix KiInterruptDispatch
- Enable interrupts
- Acquire the spinlock on SMP builds
2024-12-16 16:21:44 +02:00
Timo Kreuzer
29721ac552 [NTOS:KE/x64] Fix unwinding in KiUserApcDispatcher
This adds a MACHINE_FRAME to the user mode APC dispatcher stack frame.
2024-12-16 16:19:32 +02:00
Timo Kreuzer
91948dea80 [NTOS:KE/x64] Fix handling of PCR::UserRsp
This is a temporary helper for the system call entry point to store the user mode stack, before switching to the kernel mode stack. Initially it was copied to the trap frame inside KiSystemCallHandler. This has been moved to the system call entry point, but some remnants remained. The problem is that KiSystemCallHandler can be called twice in a system call (when the call is the first GUI call and the stack needs to be extended). In that scenario, when the thread was preempted, a new value could be saved in the PCR before running KiSystemCallHandler again, and then overwriting the proper value with a bogus one from a different thread. This rarely seemed to happen on UP, but happens a lot with SMP.
2024-12-16 16:18:45 +02:00
Hermès Bélusca-Maïto
3c1e022d0e
[NTOS:KE] Synchronize KiPcToFileHeader/KiRosPcToUserFileHeader 1st parameter name 2024-12-15 22:21:10 +01:00
Hermès Bélusca-Maïto
cc40a5870a
[NTOS:CM] Implement Win7+ VolatileBoot support.
Its support is controlled with a REG_DWORD value named
`VolatileBoot` inside the registry key
`HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Configuration Manager` .

Its implementation is very trivial: when enabled, CmpShareSystemHives
is set to TRUE and doesn't change state during runtime.
In a sense this is similar to what happens in WinPE-boot, except that
ALL hives without exception (system hives and others) will be loaded
in shared mode.
2024-12-15 22:15:13 +01:00
Hermès Bélusca-Maïto
f42c81e4ed
[NTOS:CM] Allow CmSelfHeal to be configured via registry.
This is controlled with a REG_DWORD value named
`SelfHealingEnabled` inside the registry key
`HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Configuration Manager` .

The `CmSelfHeal` variable is used to retrieve the data,
hence it needs to be a ULONG.
2024-12-15 22:12:51 +01:00
Hermès Bélusca-Maïto
a43bfe2916
[NTOS:CM/IO/KE] Implement minimal support for CrashControl:AutoReboot
The REG_DWORD value `AutoReboot` stored in the registry key
`HKLM\SYSTEM\CurrentControlSet\Control\CrashControl`
(used as a boolean value), controls whether to automatically reboot
the operating system at the end of the crash dump, after a bugcheck.

ReactOS doesn't currently implement crash dumps, so only the auto-reboot
is done. (The reason of the apparent redundant `Reboot` variable in
KeBugCheckWithTf() is because that variable would be updated on return
by the not-yet-existing crash-dump helper routines called from there.)
2024-12-15 22:12:22 +01:00
Hermès Bélusca-Maïto
3abb21080d
[NTOS:KE/EX] Add minimal EMS (headless) support for bugcheck.
In particular, the HeadlessGlobals->InBugCheck flag MUST be set prior
to displaying the blue-screen, because the HDL global lock function
would trigger a (nested) BSoD otherwise.

Regarding the unimplemented HeadlessCmdSendBlueScreenData:
it sends to the management console an XML description of the bugcheck.
An example can be seen in this issue report:
https://github.com/cloud-hypervisor/cloud-hypervisor/issues/3168

For more information, please consult:
https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/windowsserver2003emssacxml.doc
2024-12-14 23:38:43 +01:00
Hermès Bélusca-Maïto
b15dcb5cf6
[NTOS:KD64] The DbgKdPageInApi, introduced in NT4, has been obsoleted in NT5.
It has been replaced by ExpDebuggerPageIn support in ExpDebuggerWorker().
2024-12-14 23:33:53 +01:00
Hermès Bélusca-Maïto
08ed0988ff
[NTOS:KE] KeRemoveQueueDpc(): Use KeRestoreInterrupts() 2024-12-14 23:33:49 +01:00
Hermès Bélusca-Maïto
da59d797d1
[NTOS:EX] Minor enhancements to ExpDebuggerWorker()
- Add some DbgPrints.
- Use SAL2 annotations.
2024-12-14 23:31:51 +01:00
Hermès Bélusca-Maïto
ec4c169e3e
[NTOS:EX] Revamp ExpLoadBootSymbols() a bit.
- Use a for-loop.
- Make some comments more accurate.
- Reduce indentation level in the loop.
2024-12-14 23:31:49 +01:00
Hermès Bélusca-Maïto
f395f87bb3
[NTOS:MM] MiScanMemoryDescriptors(): Use the MiIsMemoryTypeInvisible() and MiIsMemoryTypeFree() helpers. 2024-12-14 23:31:48 +01:00
Hermès Bélusca-Maïto
c53eb190c7
[NTOS:KD64] Revamp the debugger banner helpers a little.
- Directly call KdpGetMemorySizeInMBs() within KdpPrintBanner(),
  instead of having the caller doing it.
- Use the miarm.h MiIsMemoryTypeInvisible() helper.
- Add Doxygen comments.
2024-12-14 23:31:47 +01:00
Hermès Bélusca-Maïto
cb0c9a4570
[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.
2024-12-14 23:31:46 +01:00
Ratin Gao
d936dba7ff [REACTOS] Fix 'seperate' typos 2024-12-11 08:56:06 +02:00
Hermès Bélusca-Maïto
6cf426345b
[NTOS:KD64] Use KdpDprintf() instead of DbgPrint() for the debugger banner DPRINTs (#7540)
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.
2024-12-03 22:14:02 +01:00
Hermès Bélusca-Maïto
1a02d3306b
[NTOS:KD64] Fix usage of the debugging banner code, based on when KdInitSystem() is called (#7540)
- 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.
2024-12-03 22:13:57 +01:00
Hermès Bélusca-Maïto
76d35dde1d
[NTOS:KD64] KdInitSystem(): Poll for break-in on symbol load *ONLY* at boot-time (#7539)
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().
2024-12-03 19:29:12 +01:00
Hermès Bélusca-Maïto
2995806a44
[NTOS:KD64] kdx64.c: Implement KdpAllowDisable() the same as in x86 (#7538)
AMD64 has the same DR7 register as x86 with the same bits meanings,
thus the same implementation can be used.

References:

- https://en.wikipedia.org/wiki/X86_debug_register#DR7_-_Debug_control

- AMD64 Architecture Programmer’s Manual, Volume 2: System Programming
  https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/24593.pdf
  Section "13.1.1.4 Debug-Control Register (DR7)"
  pgs. 393-396 (pgs. 455-458 of the PDF)

- Intel® 64 and IA-32 Architectures Software Developer’s Manual,
  Volume 3 (3A, 3B, 3C, & 3D): System Programming Guide
  https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html
  Section "19.2.4 Debug Control Register (DR7)" (pgs. 644-646)
  Section "19.2.6 Debug Registers and Intel® 64 Processors" (pg. 647)
2024-12-03 19:02:28 +01:00
Hermès Bélusca-Maïto
61feb649d1
[NTOS:KD64] kdx86.c: Fix Dr7 check to verify whether debugger disabling is allowed (#7538)
Don't check the whole Dr7 value, but only the first 8 bits that
correspond to the local/global enable breakpoints.

We cannot check the whole value because some of the Dr7 bits are
reserved always set to 1 (bit 10), or describe other debug state.

References:

- https://en.wikipedia.org/wiki/X86_debug_register#DR7_-_Debug_control

- Intel® 64 and IA-32 Architectures Software Developer’s Manual,
  Volume 3 (3A, 3B, 3C, & 3D): System Programming Guide
  https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html
  Section "19.2.4 Debug Control Register (DR7)" (pgs. 644-646)
2024-12-03 19:02:21 +01:00
Thamatip Chitpong
af4e39385c
[NTOS:CC] CcRosInitializeFileCache: Fix a missing spinlock release 2024-11-25 23:35:48 +07:00
Thamatip Chitpong
69bf140506
[NTOS:MM][NTOS:CC] Rewrite some cache memory management functions (#7510)
Use section object pointer with byte offset instead of using base address. This simplifies the Mm functions themselves and also the code in Cc that calls them.
Also add minor fixes for MmFlushSegment and MmPurgeSegment.
2024-11-24 21:37:27 +07:00
Hermès Bélusca-Maïto
edb6d19aa8
[NTOS:KD64] Only use the UNIMPLEMENTED macro in the debugger's KdpSys* helpers.
This basically avoids re-entering the debugger (via the embedded breakpoint)
while we are already running within its context.

In addition, this allows the tests for Kd/NtSystemDebugControl
(see PRs #7424 and #7426) to run without having ReactOS to crash.
2024-11-21 22:34:37 +01:00
Oleg Dubinskiy
8ed8682256
[NTOS:FSRTL] FsRtlAcquireFileExclusiveCommon: don't return before acquiring a file resource, except special cases (#7273)
Don't return before file object's resource is acquired in FsRtlAcquireFileExclusiveCommon, except some special return cases, when return is required. Based on hpoussin_filter_extra.patch by Herve Poussineau (@hpoussin) with improved comment, which matches the actual behaviour now.
This is required by fltmgr.sys driver from Windows XP/Server 2003 to work correctly, so this change fixes asserts/exceptions when releasing the file via FsRtlReleaseFile after acquiring, when using 3rd party filter drivers from several antivirus programs (e. g., Avast Free Antivirus all versions, AVG Antivirus Free 18.8, Avira AntiVir Personal 8.2, Dr. Web Security Space 8.0, Kaspersky Antivirus 2012 etc. etc.).
CORE-14157, CORE-14635, CORE-19318
2024-11-20 16:47:32 +01:00
Thamatip Chitpong
d52031a4f1
[NTOS:MM] MmPurgeSegment: Fix missing MmDereferenceSegment cleanup (#7509)
MiGrabDataSection adds a refcount. There is a missing MmDereferenceSegment cleanup in case of range check error.
Fix that by moving MiGrabDataSection calling code to after range check.
2024-11-19 11:17:41 +07:00
Doug Lyons
e0759a5e35
[NTOS:MM] Finish MmAllocateMappingAddress and MmFreeMappingAddress and fix test failures. (#7491)
* [NTOS:MM] Fix MmAllocateMappingAddress and MmFreeMappingAddress and their regression test failures.
Follow up of #7260.
This fixes kmtest:MmReservedMapping failures and hang.
Based on mm-implement-mappingaddress.patch by Thomas Faber and some changes by Oleg Dubinskiy.
kmtest:MmReservedMapping revisions and updates to Vista+ method by Timo Kreuzer.

Signed-off-by: Oleg Dubinskiy <oleg.dubinskij30@gmail.com>
Signed-off-by: Timo Kreuzer <timo.kreuzer@reactos.org>

CORE-10147, CORE-14635, CORE-17409, CORE-19318
2024-11-18 02:44:51 -06:00
Oleg Dubinskiy
83d74e7433
[NTOS:MM] Implement MmAllocate/FreeMappingAddress (#7260)
Implement MmAllocateMappingAddress and MmFreeMappingAddress routines.
Based on mm-implement-mappingaddress.patch by Thomas Faber with some changes from me.
Required by Microsoft NTFS driver (from Windows Server 2003 SP2 only, the one from Windows XP SP3 does not need them) and by NDIS & TDI drivers (both from Windows XP SP3 and Windows Server 2003 SP2). Also they are called when using Dr. Web Security Space 8 filter drivers together with MS FltMgr & TDI.
Fortunately, this part (these two routines) are enough to get the drivers working in both cases, and others (partially incomplete) routines are not badly required, so they can be finished and committed later.
CORE-10147, CORE-14635, CORE-17409, CORE-19318
2024-11-02 15:10:51 +01:00
Ratin Gao
1f4ef448de
[NTOS:EX] Fix SAL notations, Timeout parameter should be optional (#7482)
Fix warnings:

E:\3rdRepo\ReactOS_Fork4\ntoskrnl\ex\keyedevt.c(458): warning C6387: 'Timeout' could be '0': this does not adhere to the specification for the function 'ExpWaitForKeyedEvent'.
E:\3rdRepo\ReactOS_Fork4\ntoskrnl\ex\keyedevt.c(527): warning C6387: 'Timeout' could be '0': this does not adhere to the specification for the function 'ExpReleaseKeyedEvent'.

JIRA issue: None.

Proposed changes
Timeout parameter of those two functions should be optional.
2024-11-01 11:53:28 +01:00
Timo Kreuzer
1d3bce1a59 [NTOS:KE] Make KeFlushQueuedDpcs SMP ready
KeFlushQueuedDpcs is used by some drivers, when unloading or removing a device, to be sure no DPC is still running their code. On a UP system this can be done "inline", on an SMP system, it requires to send an IPI to each processor that has DPCs queued and also synchronize it with the calling thread, which is what KeSetSystemAffinityThread does implicitly: When a queued DPC was detected on a remote processor (implying that processor is currently running at DISPATCH_LEVEL or above), KeSetSystemAffinityThread will schedule the current thread on that processor and send a DPC interrupt. The remote processor will handle that DPC interrupt once it is back below DISPATCH_LEVEL. It will only run the current thread, after all queued DPCs (including threaded DPCs) have finished running.
2024-10-20 16:28:11 +03:00
Serge Gautherie
4c84e191fd
[NTOS:KE/i386] KeStartAllProcessors(): ProcessorCount is a ULONG (#7455)
Let's be explicit.

Addendum to 516ccad (0.4.15-dev-7016).
2024-10-16 22:38:01 +02:00
Hermès Bélusca-Maïto
52192f19d6
[NTOS:KDBG] For SYSREG2: HACK emission of a 'bt' command when entering the debugger
CORE-19807
2024-10-14 23:37:22 +02:00
Hermès Bélusca-Maïto
b15963abb8
[NTOS:KDBG] Reintroduce the capability of KdbpCliInit() to interpret the KDBinit file (#4917)
Addendum to commit baa47fa5e.

Similarly to what was originally done, have KdbpCliInterpretInitFile()
parse the KDBinit file by breaking back into the debugger.
But contrary to before, replace the deprecated call to KdbEnter() by
a standard DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C) . This allows
KdbEnterDebuggerException() to do the KdbpCliInterpretInitFile() call.

Additional fixes and improvements:

- Run KdbpCliInterpretInitFile() in full KDBG environment (interrupts
  disabled, modified IRQL, own stack), like the usual interactive loop.

- The KDBinit data buffer must be in non-paged pool.

- Demote the "Could not open KDBinit" error to a DPRINT, so that it
  doesn't pollute the debug log when the KDBG init function is called
  early (before the storage stack is initialized), or if the file
  doesn't exist -- since this is an optional feature.
2024-10-14 22:51:54 +02:00
Hermès Bélusca-Maïto
b86c4bd522
[NTOS:KDBG] Small improvements for KdbpCliMainLoop() and KdbpDoCommand() (#4917)
- Move the printing pager state reset code (setting the number of
  printed rows and columns to zero, and the output aborted flag)
  to KdbpDoCommand(). This allows to keep the original behaviour,
  while also inheriting it whenever KdbpDoCommand() is invoked
  elsewhere (for example, from KdbpCliInterpretInitFile()).

- Use KdbPuts/Printf() instead of KdbpPrint() for the entry banners,
  so that they aren't subject to the current printing pager state.
  Do the same for the "command unknown" error in KdbpDoCommand().

- Add a "Type 'help' for a list of commands" banner, for the users.

- Replace the do-while-loop with a simple while-loop.
2024-10-14 22:51:52 +02:00
Hermès Bélusca-Maïto
842e40d7cd
[NTOS:KDBG] Minor code style for the following commits 2024-10-14 22:51:51 +02:00
Timo Kreuzer
176de8bd25 [NTOS:PNP] Don't use a pointer to a stack structure in a work-item
Previously FsRtlNotifyVolumeEvent would pass a pointer to a TARGET_DEVICE_CUSTOM_NOTIFICATION structure on the stack to IoReportTargetDeviceChangeAsynchronous, which would store a pointer to it in a work-item and process that after the stack object was already out of scope. This broke x64 boot. Started happening after recent fixes to IoReportTargetDeviceChangeAsynchronous.
2024-10-10 20:28:59 +03:00
Timo Kreuzer
c0590f5de0 [NTOS:MM] Fix PTE protection for executable CoW pages
Fixes Blender x64.
See https://jira.reactos.org/browse/CORE-19761
2024-10-10 17:37:56 +03:00
Adam Słaboń
1d18b12ff7 [NTOS:PNP] PiNotifyTargetDeviceChange: Don't free incorrect buffer 2024-10-07 11:16:03 +02:00
Adam Słaboń
77af265315 [NTOS:PNP] IoReportTargetDeviceChange: Correct the check for system PnP notifications
Now IoReportTargetDeviceChange will process the custom notifications (rather than processing only those that it shouldn't).
2024-10-07 11:16:03 +02:00
Serge Gautherie
8de4d4d2ea
[NTOS:KDBG] Add missing \n to DPRINT() calls (#6018)
And demote/promote some DPRINT()/DPRINT1().
2024-10-07 11:07:47 +02:00
Thamatip Chitpong
259180a568
[NTOS:MM] MmFlushSegment: Simplify return (#7422) 2024-10-07 15:56:29 +07:00
Timo Kreuzer
0c2cdcae83 [REACTOS] Add missing line breaks at end of file 2024-10-06 10:47:11 +03:00
Timo Kreuzer
96c65e94e1 [NTOS:MM] Properly handle execution in NX section
This prevents processes from looping forever, thinking the fault was already resolbed, because the page is writable.
2024-09-16 16:04:43 +03:00
Thomas Faber
bf6af0f52e [NTOS:SE] Mark output parameters as such. 2024-09-12 17:44:13 +03:00
Thomas Faber
156053cafd [NDK] Match AUX_ACCESS_DATA definition with publicly available version.
Looks like public symbols contain this structure starting with Win7,
so we can deduce what it looked like in Win2003.
Note that our previous definition was missing a second ULONG at the
end, which can be seen in the SeQueryInfoToken kmtest -- if you
allocated only sizeof(AUX_ACCESS_DATA), the test would crash with
a 4 byte buffer overflow.
2024-09-12 17:44:13 +03:00
Timo Kreuzer
2913ef5c93 [NTOS:KE/x64] Fix exception information on page faults
Pass a proper write/execute flag in the ExceptionInformation[0] field of the exception record instead of the raw fault code. This fixes comdlg:filedlg wine test, which writes to a write protected resource section, which needs to be handled by kernel32 UnhandledExceptionFilter, which relies on this parameter to be correct.
2024-09-12 17:07:59 +03:00