Commit graph

1770 commits

Author SHA1 Message Date
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
Timo Kreuzer
78e94a5083 [NTOS:MM] Increase x64 system view and session view size
We have plenty of address space and the desktop heap has grown, so we need some more space.
2024-09-08 10:33:55 +03:00
Serge Gautherie
4b051b914f
[NTOS:PO] Update a comment (#6443)
Addendum to 9e43518 (0.4.15-dev-7560).
2024-09-08 02:29:37 +02:00
Justin Miller
49e07292ed
[NTOS:KE] Clear NpxThread on rundown for SMP as well (#7151)
clear NpxThread on rundown for SMP as well
Fixes the crash whenever a usermode thread is destroyed on x86
2024-08-31 13:18:07 -07:00
Thamatip Chitpong
95c340dfb7
[NTOS:CC] CcRosCreateVacb: Return error code on pool allocation failure (#7275)
Return STATUS_INSUFFICIENT_RESOURCES error code instead of accessing the invalid pointer.
2024-08-30 07:34:48 +07:00
Oleg Dubinskiy
c59e2d20d9 [NTOS:FSRTL] Check for the correct return status when inserting a new Filter Context entry
According to our declaration/definition, IoChangeFileObjectFilerContext returns NTSTATUS, not BOOLEAN. Zero return (which was actually checked before) for BOOLEAN means failure, but for NTSTATUS it's success. So it should (and now actually does) free and fail appropriately only in failure case, but not in success, when it shouldn't.
This fixes most of problems with fltmgr.sys driver from Windows XP/Server 2003 and a lot of 3rd party filter drivers which use it from many apps (Avast Free Antivirus all versions, Avira AntiVir Personal 8.2, Dr. Web Security Space 8.0, Kaspersky Antivirus 2012 etc. etc.).
CORE-14157, CORE-14635, CORE-19318
2024-08-26 11:16:49 +02:00
Oleg Dubinskiy
5d96ba9217
[NTOS:MM] Implement MmProbeAndLockProcessPages (#7221)
Implement undocumented MmProbeAndLockProcessPages routine. Based on mm-implement-mappingaddress.patch by Thomas Faber from CORE-10147, with some improvements from me.
It's badly required by FltMgr.sys driver from Windows XP/Server 2003 and closely used by a lot of apps those are depending on this driver (e. g., Avast Free Antivirus several versions, Avira Antivir Personal 8.2 etc. etc.).
Fixes several asserts from MDL support routines when the 3rd-party minifilter drivers are loading FltMgr.
CORE-14157
2024-08-08 21:02:35 +02:00
Thamatip Chitpong
cf4138fa24 [NTOS:CC] Protect CcFlushCache call with a mutex
Fix crash when the function was called concurrently for the same file by BTRFS driver.
CORE-19664
2024-07-31 18:07:49 +07:00
Thamatip Chitpong
0899f4b2b1 [NTOS:CC] CcFlushCache: Call CcRosReleaseVacb when CcRosFlushVacb fails
CcRosLookupVacb adds a refcount.
2024-07-31 18:07:49 +07:00
Hermès Bélusca-Maïto
3fe12f1a7c
[NTOS:IO] IopCreateArcNamesDisk(): Fix the ArcName link creation condition check.
The bug was introduced in commit 6d0861e9e (r49131).
2024-06-19 17:26:40 +02:00
Hermès Bélusca-Maïto
5e3f3f59df
[NTOS:IO] IopVerifyDiskSignature(): simplify code and SAL2-annotate 2024-06-19 17:25:42 +02:00
Hermès Bélusca-Maïto
85d338ed65
[NTOS:IO] arcname.c: Minor formatting fixes and comments improvements 2024-06-19 17:25:34 +02:00
George Bișoc
fe23a4aaeb
[NTOS:CM] Lock the entire registry down when we unload a hive
The PR #6649 which fixed an issue with orphaned KCBs leaking in memory which also pointed to unloaded registry hives, it also brought a problem.
In CmpEnumerateOpenSubKeys there is a risk of getting hit by a deadlock as we enumerate the cache table to remove empty cache entries.

Fundamentally CmpEnumerateOpenSubKeys locks down a KCB from cache for exclusive use in order to tear down its contents from memory but it doesn't address the fact a KCB might have already been locked in the same calling thread, leading to a recursion.
This leads to random hangs when unloading a hive during system startup (tipically on a clean install).

The solution here is to simply lock the whole registry when we unload a hive so that we don't have to worry the KCBs are getting tampered by anybody else. This also simplifies the code.
Although locking the entire registry while other apps are doing registry related operations to other hives can cause overhead. If this turns out to be bad then we have to rethink the locking mechanism here.

CORE-19539
2024-06-01 16:17:47 +02:00
George Bișoc
5d0117de90
[NTOS:CM] Annotate CmUnloadKey with SAL2 2024-06-01 16:17:47 +02:00
Timo Kreuzer
4fb2fdbac6 [NTOS:CM] Properly unlock registry on failure in NtUnloadKey2 2024-05-23 21:21:35 +02:00
Timo Kreuzer
da64119fe6 [NTOS:CM] Add debug code for analyzing lock issues 2024-05-23 21:21:35 +02:00