2033 Commits
Author SHA1 Message Date
Timo Kreuzer e3e58ac1aa [NTOS:KE/x64] Fix KiInitializeContextThread
Copy values manually instead of calling KeContextToTrapFrame.
2026-08-01 11:05:47 +00:00
Timo Kreuzer 6bc61687e6 [NTOS:KE/x64] Fix KiInitializeUserApc
Set EFlags instead of "fixing" it.
Prevents crashes in the thread initialization APC, when the thread has set the direction flag or trap flag.
2026-08-01 11:05:47 +00:00
Timo Kreuzer 652403caf2 [RTL/x64][NTOS:KE/x64] Fix RtlInitializeContext
- In RtlInitializeContext only set the registers required, don't offset RSP
- In KiInitializeContextThread force control segments, which are not set by RtlInitializeContext
- Allocate the stack home space in KiInitializeContextThread
- Fix BaseInitializeContext to work with the changed stack adjustments
2026-08-01 11:05:47 +00:00
Timo Kreuzer 39ea28d4c6 [NTOS:KE/x64] Fix KeContextToTrapFrame 2026-08-01 11:05:47 +00:00
Alex Mendoza c9780d9095 [NTOS:OB] Validate ACCESS_SYSTEM_SECURITY in ObpIncrementHandleCount
Validate ACCESS_SYSTEM_SECURITY access requests when creating a new
handle in ObpIncrementHandleCount.

- Check for SeSecurityPrivilege (with SeSinglePrivilegeCheck) when a
  caller requests ACCESS_SYSTEM_SECURITY on handle creation.
- Take away ACCESS_SYSTEM_SECURITY from RemainingDesiredAccess /
  PreviouslyGrantedAccess if the privilege isn't held.
2026-07-30 20:22:58 +02:00
Alex Mendoza 8dc41c663d [NTOS:OB] Correct a typo 2026-07-30 20:22:03 +02:00
Ahmed Arif c606fd79b1 [NTOS:FSRTL] Respect byte-range lock ownership (#9342)
FsRtlCheckLockForReadAccess() accepts access through an exclusive
byte-range lock when the IRP key matches, even if another process
owns the lock. FsRtlFastUnlockAll() likewise removes exclusive locks
without checking the Process argument.

Require both the key and requestor process for exclusive-read access,
and skip exclusive locks owned by other processes in FsRtlFastUnlockAll().
This matches the ownership checks already used by
FsRtlFastCheckLockForRead() and FsRtlFastUnlockAllByKey().

Reference:
- https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-_fsrtl_advanced_fcb_header-fsrtlfastchecklockforread
2026-07-29 21:54:44 +03:00
Timo Kreuzer 07217d3245 [NDK][NTOS] Change Object callback types to NT6 style
This is required to support the NT6 access flags THREAD_QUERY_LIMITED_INFORMATION and THREAD_SET_LIMITED_INFORMATION.
2026-07-28 12:16:32 +00:00
Timo Kreuzer 9675f756ce [NDK] Fix definition of OB_CLOSE_METHOD 2026-07-28 12:16:32 +00:00
Ahmed Arif 98256a4f5d [NTOS:MM] Allow contiguous-memory frees at DISPATCH_LEVEL (#9349)
MmFreeContiguousMemory() is callable at up to DISPATCH_LEVEL,
but MiFreeContiguousMemory() used PAGED_CODE(), which incorrectly asserted
above APC_LEVEL in checked builds.

Replace it with an assertion that enforces the exported IRQL contract.
2026-07-27 17:44:40 +03:00
Ahmed Arif 28373a9f84 [NTOS:IO] Do not free the active VPB (#9343)
IopDereferenceVpbAndFree frees a zero-reference VPB only while it is still
installed in RealDevice->Vpb. This can leave the device with a dangling
VPB pointer while detached VPBs are retained.

Reverse the identity test so only a detached, nonpersistent VPB is released
after its reference count reaches zero.

Reference:
- https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_vpb
2026-07-27 15:48:33 +03:00
Ahmed Arif 6c515f5aa6 [NTOS:MM] Release system image PTEs on unload (#9078)
MmUnloadSystemImage() had an explicit leak placeholder for driver images.

Implement the MmUnloadSystemImage() that performs matching teardown
for the image mappings, releasing the reserved system PTE range.

Also fix similar leak in MiLoadImageSection() by releasing image mappings
after load failures.

CORE-8294

Note that the driver images loaded at boot, which were not reloaded by
MiReloadBootLoadedDrivers(), remain at their loader-assigned addresses
and do not own system PTEs.
2026-07-27 15:20:39 +03:00
Ahmed ARIF 174b9d64fe [NTOS] Export the UTF-8 conversion routines
RtlUTF8ToUnicodeN and RtlUnicodeToUTF8N are documented kernel APIs since Windows 7, but they are missing from the ntoskrnl export table.
2026-07-24 14:49:13 +02:00
Carl J. Bialorucki c3d141b675 [NTOS][NTOS:FSRTL] Use RtlIsNameInExpression for FsRtlIsNameInExpression
Also link rtl_vista to ntoskrnl
2026-07-22 19:53:20 -05:00
copilot-swe-agent[bot] 7877f5bc0b [NTOS:CC] Fix CcRosDeleteFileCache race with concurrent CcFlushCache causing ASSERT(Refs > 0)
Root cause: CcRosDeleteFileCache's first loop ran under the spinlock and removed VACBs from the LRU and dirty lists, but left them in CacheMapVacbListHead. It also set Vacb->Dirty = TRUE as a flush hint (after CcRosUnmarkDirtyVacb cleared it), creating an inconsistent VACB state: Dirty=TRUE but not in the dirty list, with only the cache-map-list refcount (1). After releasing the lock, the second loop removed VACBs from CacheMapVacbListHead without holding any lock.

This created a race with CcFlushCache: a caller that already held a SharedCacheMap pointer could call CcRosLookupVacb between the two loops, find the VACB (refcount → 2), see Dirty=TRUE (the hack), and call CcRosFlushVacb. Meanwhile the second loop could set Dirty=FALSE, drop the cmap ref (→1, print "Leaking VACB"), and then the early-return in CcRosUnmarkDirtyVacb would skip the decrement. CcRosReleaseVacb then drops 1→0 → ASSERT(Refs > 0) fires.

Before the previous fix, the same race caused ASSERT(Vacb->Dirty) in the old CcRosUnmarkDirtyVacb — the previous fix just changed which assert fired.

The fix:
- CcRosDeleteFileCache: VACBs are now removed from CacheMapVacbListHead in the first loop, under the spinlock, and moved to a private LocalVacbList. After the lock is released, CcRosLookupVacb can no longer find these VACBs, preventing new lookup references from being created.
- CcRosReleaseVacb: Removed the overly strict ASSERT(Refs > 0). When CcRosDeleteFileCache drops the cmap ref while a lookup is outstanding, CcRosReleaseVacb legitimately releases the last reference and CcRosVacbDecRefCount correctly frees the VACB. Callers (e.g., CcFlushCache) don't access the VACB pointer afterward.

Signed-off-by: Timo Kreuzer <[email protected]>
2026-07-21 21:59:09 +00:00
copilot-swe-agent[bot] 55c4c525b4 [NTOS:CC] Fix a race condition for dirty VACBs
- CcRosUnmarkDirtyVacb: return BOOLEAN, guard against double-unmark
- CcRosMarkDirtyVacb: guard against double-insertion
- CcRosFlushVacb: only re-mark dirty on failure if we were the one who unmarked
- Add comments to lockless Dirty reads in CcFlushCache and CcRosReleaseVacb

Signed-off-by: Timo Kreuzer <[email protected]>
2026-07-21 21:59:09 +00:00
Justin Miller 9ffc373bf6 [NTOS:IO][SDK:DRIVERS][FORMATTING] Start SDK:Arbiter from scratch (#9270)
Same idea as
094b7d9
and
Final step that doesn't require rtlrange improvements
2026-07-19 10:29:04 -07:00
Justin Miller 1b460291e2 [NTOS:IO] Fix a small bug in PiUpdateDeviceState (#9290)
technically an adjustment to commit cf0bc1c.

CORE-17519
2026-07-14 22:07:42 -07:00
Timo Kreuzer 7955690ad7 [NTOS:EX] Create a stub for SystemModuleInformationEx sysinfo class
The stub returns STATUS_INVALID_INFO_CLASS rather than STATUS_NOT_IMPLEMENTED.
This is a temporary measure to indicate to ntdll_winetest that this system information class is not implemented and prevent the test from crashing.
2026-07-03 17:04:11 +00:00
Timo Kreuzer c6410fb0c2 [NTOS:EX] Fix query of SystemTimeAdjustmentInformation 2026-07-03 17:04:11 +00:00
Timo Kreuzer feb0f56da7 [NTOS:EX] Fix query of SystemInterruptInformation 2026-07-03 17:04:11 +00:00
Timo Kreuzer eb3d5a4f9d [NTOS:EX] Implement query of SystemRecommendedSharedDataAlignment 2026-07-03 17:04:11 +00:00
Timo Kreuzer 05017d7160 [NTOS:EX] Implement query of SystemExtendedProcessInformation 2026-07-03 17:04:11 +00:00
Timo Kreuzer ef7d4d2043 [NTOS:EX] Implement query of SystemProcessorBrandString 2026-07-03 17:04:11 +00:00
Timo Kreuzer 5ab5b8e5f3 [NTOS:EX] Implement query of SystemEmulationProcessorInformation 2026-07-03 17:04:11 +00:00
Timo Kreuzer 252a552dc6 [NTOS:EX] Implement query of SystemEmulationBasicInformation 2026-07-03 17:04:11 +00:00
Timo Kreuzer dbb4d36927 [NTOS:KE][NTDLL][NTDLL_VISTA] Implement NtGetCurrentProcessorNumberEx 2026-07-01 21:45:34 +00:00
Alex Mendoza 8e865cb39d [NTOS:OB] Return handle attributes by ObReferenceFileObjectForWrite (#9213)
Resolve a FIXME in ObReferenceFileObjectForWrite by getting the handle attributes,
the same way it's done in other parts of the Ob code.
2026-06-26 19:22:55 +02:00
Hermès Bélusca-Maïto 620222ad28 [NTOS:OB][NDK] Enhancements to ObSetHandleAttributes() and ObpSetHandleAttributes() (#9170)
- Use SAL2 annotations; write Doxygen documentation (based on GPT-5.4 feedback).
- Simplify some of the code.
- Add the `ObSetHandleAttributes()` prototype to `ndk/obfuncs.h`,
  since it is exported by ntoskrnl.exe
2026-06-23 19:52:22 +02:00
Hermès Bélusca-Maïto 37fe06f1c7 [NTOS:OB] Enhancements to NtSetInformationObject() (#9170)
- Simplify the `ObjectHandleFlagInformation` class implementation,
  by directly invoking the `ObSetHandleAttributes()` routine.
  Addendum to commit 02d0bb9dbd (r22228) that implemented the class,
  and to commit 91105c7915 (r61037) that implemented `ObSetHandleAttributes()`.

- Use SAL2 annotations; write Doxygen documentation (based on GPT-5.4
  feedback and https://ntdoc.m417z.com/ntsetinformationobject).
2026-06-23 19:52:21 +02:00
Hermès Bélusca-Maïto cf4dce77c2 [NDK][NTOS:INCLUDE] Minor reshuffling of some functions (#9170) 2026-06-23 19:52:16 +02:00
Dmitry Borisov 57a7c56d51 [NTOS:PNP] Compile PC-98 PnP IDs only on x86 (#9195)
Addendum to 7d5e159131

CORE-17977
2026-06-23 01:20:19 +03:00
Stanislav Motylkov 13364f7be6 [NTOS:CM] Detect NEC PC-98 alternative system architecture dynamically (#9193)
Perform detection by matching system identifier passed from the loader block,
similarly to how FreeLoader detects the boot video driver:
https://github.com/reactos/reactos/blob/332331ce1b7a71b0227b9ec3d4449272b28a84f6/boot/freeldr/freeldr/ntldr/winldr.c#L653

Windows checks if the identifier starts with a known string and then sets
additional flags for the drivers.

See also https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/arc/i386_loader_block.htm

Follow up of 8df1b53508. CORE-17977
2026-06-22 14:04:34 +03:00
Adam Słaboń 8aac5c4c87 [NTOS:KE][AMD64] Move KD initialization after HalInitializeProcessor call (#9177)
This is needed for PCI debugging devices whose KD modules depend
on the functions registered in HalpRegisterKdSupportFunctions().

Also it's consistent with what x86 does, and also what Win7 x64 does
(the KdInitSystem is invoked after the HalInitializeProcessor call).

Necessary for PR #9156 on AMD64. CORE-20385
2026-06-19 00:44:48 +03:00
Ahmed Arif 69474b3190 [NTOS:OB] Replace the joke debug print in NtWaitForMultipleObjects with a proper diagnostic (#9163)
Addendum to commit f543c860f7 (r69399).
2026-06-16 18:06:18 +03:00
Serge Gautherie 5df7d05049 [NTOS:MM] MiMapViewOfDataSection(): ASSERT InheritDisposition value 2026-06-15 12:34:56 +00:00
Timo Kreuzer d1c281c95e [NTOS:EX] Fix wait mode in keyed event implementation
Use previous mode instead of KernelMode, to allow user mode threads to be terminated.
2026-06-08 14:10:10 +00:00
Ahmed Arif b1f04786e1 [NTOS:FSTUB] Clear the whole partition table in FstubCreateDiskRaw (#9124)
FstubCreateDiskRaw is supposed to wipe the MBR when it makes a RAW disk.
Before this fix, that function only cleared the first of the 4 partition entries, so one entry (16 bytes) instead of the whole table (64).
As a consequence, the wiped MBR written back to disk still had entries 2, 3 and 4 sitting there with old data, and those came back as ghost/garbage partitions.
2026-06-08 00:14:11 +02:00
Timo Kreuzer a7f658e322 [NTOS:IO] Fix IopGetBusTypeGuidIndex
- Use a global structure instead of pointer
- Allocate only the GUID buffer
- Keep track of allocated size and number of GUIDs
- Grow in steps of 8 GUIDs
- Use ExAllocatePoolWithTag instead of ExAllocatePool
- Use IsEqualGUID

See CORE-12791
2026-05-16 21:07:55 +00:00
Serge Gautherie f00e1cd6aa [NTOS:PNP] IopGetBusTypeGuidIndex(): Remove 1 unwanted ExFreePool()
in a failure case.

CORE-12791
2026-05-10 14:07:51 +00:00
Serge Gautherie 25a6fdf867 [NTOS:MM] Convert some annotations to SAL2 and fix them
And add a specific ASSERT(SectionOffset) in MmMapViewOfSection().
2026-05-10 11:05:30 +00:00
Timo Kreuzer da64ad34ef [CRT] Stop implementing non-conforming swprintf / vswprintf
- Don't compile the non-conformng swprintf (it is identical to _swprinf)
- Rename swprintf to _swprintf
- Forward non-conforming exports to the underscored versions in CRT dlls
2026-05-07 06:27:58 +00:00
Timo Kreuzer 1cf31524d5 [REACTOS] Stop using non-conforming swprintf / vswprintf
Use the underscored versions instead.
2026-05-07 06:27:58 +00:00
Timo Kreuzer 081a6366df [KSECDD][NTOS][RTL] Change license of some of my code to MIT 2026-04-23 12:39:01 +00:00
Timo Kreuzer 77b88c48a4 [NDK][NTOS][NTDLL][KRNEL32] Fix read/write of KSYSTEM_TIME
Fix KiWriteSystemTime and move it to NDK. The previous implementation of KiWriteSystemTime was broken and updated the fields in the wrong order. Before that it was right for SystemTime and wrong for InterruptTime. ExpSetTimeZoneInformation had it wrong for the TimeZoneBias.
Add KiReadSystemTime to read KSYSTEM_TIME values correctly, instead of doing it manually (and partly wrongly) all over the place.
2026-04-23 11:58:15 +00:00
Dmitry Borisov e2aa54321a [BOOTVID] Rename some function parameters
Delta       -> Stride
TopDelta -> Height
2026-04-21 15:08:17 -05:00
Hermès Bélusca-Maïto 13ac291830 [NTOS:FSTUB] IoGetBootDiskInformation(): Fix the disks matching condition check.
This is the same fix for the same condition check, as the one already
applied to `IopCreateArcNamesDisk()` in commit 3fe12f1a7c.

This bug was introduced in commit 538b9e4fbf (r49212) and is identical
to the one introduced in commit 6d0861e9ed (r49131).

The idea behind the condition check, is that we consider the enumerated
disk to be a match with the currently-considered one from the ARC disk
signatures, *IF*:

- there is only one single disk listed in the ARC disk signatures,
  *AND* only one single disk detected at runtime by the kernel,
  *AND* this disk is MBR-partitioned;

- *OR*, there is one or more disks present and the enumerated disk's
  signature match the currently-considered ARC disk signature. (This
  is the more general case for when there are one or multiple disks
  on the system, and/or one disk at least is GPT).
2026-04-12 17:26:54 +02:00
Hermès Bélusca-Maïto 278234259d [NTOS:FSTUB] Fix bugs in the drive-letters assignment algorithm
Addendum to commit 5ab1cfc553.

- Fix the drive letters assignment ordering for hard disks.

  * Fix the loop that assigns letters to MBR boot and primary partitions;
  * Fix the condition that finds the boot partition (or defaults to the
    first primary partition) to be skipped when assigning letters to all
    remaining hard-disk partitions -- after letters have been assigned
    to the specific boot, primary, logical, etc. partitions.

  NOTE: The drive-letter assignment algorithm is as follows:

  1. For each hard disk, assign a letter to the first encountered boot
     (MBR "active") partition; or if GPT disk, to all data partitions.
     If no boot partition has been found on this disk, assign a letter
     to all of its primary partitions.

  2. Assign a letter to all (MBR) logical partitions for each hard disk.

  3. Assign a letter to all remaining partitions with recognized IDs on
     all disks.

  ****
  We observe that the algorithm 1-3 is tailored for MBR-partitioned disks,
  as it is inherited from the way MS-DOS did it. In addition, partitions
  on GPT disks acquire their drive letters early one, during step 1.
  ****

  4. Assign letters to floppy disks (see below), then to CD-ROMs.

  5. Finally, verify that the OS boot volume has got a drive letter; if
     not, get a free one (or delete the 'Z' drive letter and reassign it
     to the boot volume).

  (See also "Inside Storage Management, Part 1", Mark Russinovich,
   https://www.digiater.nl/openvms/decus/vmslt00b/nt/storage-mgt-nt_2.htm
   about the `IoAssignDriveLetters` function.)

- When assigning drive letters to floppy drives, first assign letters to
  legacy (non-MountMgr-aware) devices, and then to MountMgr-aware devices.
2026-04-11 18:16:27 +02:00
Hermès Bélusca-Maïto 750e463fb1 [NTOS:FSTUB] disksup.c: More simplifications
Addendum to commit 5ab1cfc553.

- Static const-ify the `FloppyString` and `CdString` constants, that are
  common to both `HalpNextDriveLetter()` and `xHalIoAssignDriveLetters()`.

- Improve code comments and variable names.

- In `xHalIoAssignDriveLetters()`:
  * One of the two "generic string buffers" can be thrown away, since
    we can already use the on-stack `Buffer`.

  * No need to `sprintf` + `RtlInitAnsiString` + `RtlAnsiStringToUnicodeString`
    with the risk of failing the conversion (that also allocates memory).
    Instead, just invoke `swprintf` + `RtlInitUnicodeString` as already
    done elsewhere in this function.

  * Replace some '0' to 'FALSE' where applicable.
  * Reduce indentation level of two for-loops.
2026-04-11 18:16:25 +02:00
Hermès Bélusca-Maïto f2e0e63ee5 [NTOS:FSTUB] Simplify GUID comparisons and partition info saving 2026-04-11 18:16:24 +02:00