Commit Graph

1718 Commits

Author SHA1 Message Date
Doug Lyons 69ebfd671d
[NTOS:EX] Various fixes for Daylight Saving Time transitions (#5868)
* [NTOS:EX] Various fixes for Daylight Saving Time transitions

* Fix automatic time changes when DST starts and ends.
* Currently it takes two cycles of the update provided by w32time to make the actual change.
* Convert Eric Kohl's TimeZoneID code contained in ExRefreshTimeZoneInformation to a new function.
* Use this new function in ExpSetTimeZoneInformation and ExRefreshTimeZoneInformation functions.

CORE-19290
2024-05-05 21:32:04 -05:00
Serge Gautherie cb6fc76b8b
[NTOS:IO] IoDisconnectInterrupt(): Switch to ExFreePoolWithTag() (#6503)
Follow-up to commit 24a14abf2 (r57412).

HBelusca's comment:
> If this ExFreePoolWithTag() call was left commented, it's probably
> because, back in the day where I introduced it, there was a pool
> corruption that was detected, the source of which was unknown at
> that time. In retrospect, it is most probably the interrupt disconnect
> bug in IoDisconnectInterrupt() that was causing it. Now that this
> bug has been fixed just previously, it should be safe to re-enable
> pool freeing with tag.
2024-05-05 17:03:42 +02:00
Serge Gautherie 347ca5f859
[NTOS:IO] IoConnectInterrupt(): Move InterruptObject assignment where it belongs (#6503)
Addendum to commit d1258e99f (r16229), supersedes commit adf534b28.

CORE-17256
2024-05-05 17:03:28 +02:00
Serge Gautherie 2d442956b4
[NTOS:IO] IoConnectInterrupt(): Fix default spinlock initialization (#6503)
Addendum to commit d1258e99f (r16229).
2024-05-05 17:03:20 +02:00
Serge Gautherie cbc78e0629
[NTOS:IO] IoDisconnectInterrupt(): Fix disconnecting other interrupts (#6503)
Addendum to commit d1258e99f (r16229).
2024-05-05 17:03:13 +02:00
Hermès Bélusca-Maïto 603fd832d0
[NTOS:IO] IoConnectInterrupt(): Zero-out the allocated structure at the correct place (#6503)
Addendum to commit d1258e99f (r16229).
2024-05-05 17:02:34 +02:00
Serge Gautherie 35d46b23f1
[FORMATTING][NTOS:IO] iomgr/irq.c
- Add a few blank lines.
- Use 2 'continue'.
2024-05-05 16:35:22 +02:00
Timo Kreuzer 5c3b1c78a7 [NTOS:KE] Improve NtRaiseException and NtContinue
- Fix annotations
- Don't use KiServiceExit to return to the caller with an error code, instead just return from the function, that is the same thing.
- Refactor failure path
- Add DPRINTs on failure
2024-05-01 11:30:29 +02:00
Timo Kreuzer 4bc591c6f0 [NTOS:KE] Fix NtRaiseException and NtContinue on x64
- Implement KiExceptionExit, which works like KiServiceExit2, but takes an exception frame as 2nd parameter
- Add a local exception frame to NtRaiseException and NtContinue, which is needed to exit with a full context on x64 and arm
- Use KeContextToTrapFrame again instead of KiSetTrapContext, since we have a proper exception frame now.
2024-05-01 11:30:29 +02:00
Doug Lyons 0f9bf6abb4
[NTOS:CC] Restore unlock/reacquire locks around MmPageOutPhysicalAddress (#5735)
* [NTOS:CC] Restore unlock and reacquire locks around MmPageOutPhysicalAddress which was mistakenly lost in commit 2b14056

* Add bypass for problematic code path for now
2024-04-30 13:59:50 -05:00
Timo Kreuzer c9864da823 [NTOS:IO] Fix broken pool allocations
ExAllocatePoolWithTag doesn't raise an exception on failure, only ExAllocatePoolWithQuotaTag does. Use that when quotas are relevant instead of silently continuing with a NULL pointer.
2024-04-28 14:06:07 +02:00
Timo Kreuzer b8e50f787d [NTOS:KE/x64] On syscalls clear nested task flag
When this flag is not cleared and the system returns with an IRET, this causes a #GP. Randomly hit by the umkm:SystemCall test.
2024-04-27 15:12:40 +02:00
Timo Kreuzer 6ac260dcec [NTOS:KE/x64] Handle NMI vs swapgs race condition 2024-04-23 15:50:06 +02:00
Timo Kreuzer 72fd54a7f4 [NTOS:KE/x64] Implement Kd processor switching 2024-04-23 15:50:06 +02:00
Timo Kreuzer 9229709312 [NTOS:KE/x64] Implement processor freeze code 2024-04-23 15:50:06 +02:00
Timo Kreuzer af2ce4d08f [NTOS:KE/x64] Implement KiSaveProcessorState / KiRestoreProcessorState 2024-04-23 15:50:06 +02:00
Timo Kreuzer 1d289fec77 [NTOS:KE] Improve freeze code in KeBugCheckWithTf
- Don't wait 1 second for each processor
- Use AFFINITY_MASK
- Use Prcb->Number, which is more future proof than KeGetCurrentProcessorNumber
- Improve for loop
2024-04-23 15:50:06 +02:00
Timo Kreuzer d96f01b5dc [NTOS:KE/x64] Add KiNmiInterruptHandler
So far it only calls KiHandleNmi. It will also handle processor freeze later.

TODO: Pass TF_WITH_EF to directly generate a KEXCEPTION_FRAME
2024-04-23 15:50:06 +02:00
Timo Kreuzer 05456808e8 [NTOS:KE/x64] Fix handling of non-volatiles in trap vs exception frame
The registers that are saved/restored in the trap / exception frame need to be consistent between all entry/exit points as well as the functions that convert between trap/exception frame and context. The trap frame contains only the non-volatile registers and rbp, the rest is saved in the exception frame.
The previous code didn't save rbp in the syscall handler, which led to it being clobbered when exiting though KiServiceExit2 rather than returning back to the syscall exit path. Also KeContextToTrapFrame would use rbx, rsi and rdi from the trap frame, which wouldn't be saved there by the syscall handler.
2024-04-14 16:09:20 +02:00
Timo Kreuzer c69371cced [NTOS:KE/x64] Improve KeGetTrapFrame 2024-04-10 23:27:53 +02:00
Timo Kreuzer 713a360c74 [NTOS:KE/x64] Remove pointless loop in KiInitiateUserApc
Only one user APC can be delivered here. The next one can only be delivered, when KiUserApcDispatcher returns to the previous context with NtContinue.
2024-04-07 09:14:26 +02:00
Timo Kreuzer 7589238b68 [NTOS:KE/x64] Fix user APC delivery on syscall exit
We need to save the missing registers in the trap frame before calling KiInitiateUserApc, because they will be used to create the CONTEXT that is saved on the user mode stack, where KiUserApcDispatcher returns back to using NtContinue. This fixes remaining failures in kernel32_apitest QueueUserAPC.
2024-04-07 09:14:26 +02:00
Timo Kreuzer 43b181309e [NTOS:KE] Fix calculation of timer expiration
Both due-times and interrupt time are unsigned, but were treated as signed in KiInsertTimerTable, which led to very long (e.g. INFINITE) waits being interpreted as having a negative due-time and being completed instantly.
Mostly fixes kernel32_apitest QueueUserAPC
2024-04-07 09:14:26 +02:00
Timo Kreuzer 34576c7015 [NTOS:KE/x64] Implement KiUserCallbackExit
This is used in KiUserModeCallout instead of KiServiceExit2. The latter is broken, leaks non-volatile registers and will need to be modified to handle an exception frame, which we don't need/have here. It will also use sysret instead of iret and is generally simpler/faster.
Eventually it would be desirable to skip the entire trap frame setup and do everything in KiCallUserMode. This requires some cleanup and special handling for user APC delivery.
2024-04-07 09:13:58 +02:00
Timo Kreuzer 5b82ada2ed [NTOS:Ke/x64] Improve KiDispatchExceptionToUser
Return back to the caller instead of exiting through KiServiceExit2, which is broken and needs to be changed to allow restoring of an exception frame.
2024-04-04 18:41:39 +02:00
Timo Kreuzer 24b4026ce8 [NTOS:KE/x64][SDK] Add HANDLE_USER_APCS asm macro
This also fixes delivering APCs from the system call handler, which previously would have clobbered rax. Also don't use the thread's TrapFrame member, which is not always set, when returning.
2024-04-01 20:15:49 +02:00
Timo Kreuzer 88e24bc463 [NTOS:KE/x64][SDK] Add some trap handling support asm macros 2024-04-01 20:15:49 +02:00
Thamatip Chitpong 5329e475db [NTOS:MM] MiDeleteVirtualAddresses: Update PrototypePte before exiting loop, when deleting PDE
Fix BSoD 0x1A introduced by commit c7e09061ca
CORE-18190
CORE-18818
CORE-19253
2024-04-02 00:14:57 +07:00
Thamatip Chitpong 588449c364 [NTOS:MM] Revert commit 0c612980ac
This revert commit 0c612980ac
2024-04-02 00:14:57 +07:00
Timo Kreuzer 1538712c0b [NTOS:KE/x64] Move setting the thread's trap frame to KiSystemCallEntry64
This is needed, because KiSystemCallHandler can be called multiple times for the same syscall entry, which would mess up the linkage. This replaces a previous hack and makes things cleaner.
2024-03-31 12:12:48 +02:00
Gleb Surikov fc6bf61e4c
[NTOS:CM] Avoid unnecessary ObDereferenceObject when handling an ObInsertObject failure (#6673)
In case of failure, ObInsertObject itself dereferences the object, so calling ObDereferenceObject one more time in the failure handler is redundant.

- Remove ObDereferenceObject call from CmpCreateRegistryRoot in case ObInsertObject fails.
- Add missing RootKey dereference if CmpCreateRegistryRoot failed to get the key cell (KeyCell).

CORE-17904
2024-03-30 22:10:17 +03:00
Timo Kreuzer 5442f87080 [NTOS:KE/x64] Improve KiSystemCallHandler code a bit
- Use an index for the table instead of ugly pointer offset
- Invert the check for GUI calls
- Fail with proper status code on invalid win32k syscall ids
2024-03-28 22:26:42 +01:00
Timo Kreuzer 2ed8541dc8 [NTOS:KE/x64] Remove duplicated REX prefix from sysretq 2024-03-28 21:37:25 +01:00
Doug Lyons 0c612980ac
[NTOS:MM] Fix ntoskrnl/mm/ARM3/virtual.c causing BSOD 0x1a introduced by commit https://github.com/reactos/reactos/commit/c7e09061ca (#6633) 2024-03-27 23:50:45 +02:00
Adam Słaboń fec827eeef
[FREELDR][NTOS:MM] Add security cookie generation to FreeLoader (#6270)
* [NTOS:MM] Misc improvements for cookie generation code

- Improve support for 64 bit images
- Improve LdrpFetchAddressOfSecurityCookie code

* [FREELDR] Add security cookie generation to FreeLoader

CORE-17808
2024-03-27 23:33:06 +02:00
Timo Kreuzer 36fa628605 [NTOS:KE/x64] Loop in KiInitiateUserApc
This is required since while interrupts are enabled, another user APC could get queued and we want to guarantee that those are all delivered before returning to user mode.
2024-03-27 22:11:07 +01:00
George Bișoc 7dd8a30cf9
[NTOS:CM] Remove orphaned KCBs of keys during normal hive unload
A hive whose KCBs have a reference count of 0, meaning nobody is using these keys anymore, will not get removed from the cache table.
As a result during a normal hive unloading operation you will get orphaned KCBs which results in an unload failure.

This is wrong, because this is what a normal hive unloading is supposed to do. What it cannot do of course is that it cannot
scramble the references of opened keys by the users who use the Registry, as it is the job of force unloading mechanism to do that.

Also remove a misleading debug print. Force unloading works as intended by scrambling the references of keys and marking the KCB for deletion,
which is what how a force unload works. Namely Windows does exactly that.

CORE-10705
2024-03-24 19:03:47 +01:00
George Bișoc f1d2a44859
[NTOS:CM] Lock the cached KCB before removing it from cache entries
- Annotate the CmpEnumerateOpenSubKeys function with SAL2
- When removing an orphaned cached KCB, ensure that it is locked before clearing it from cache table entries
2024-03-24 19:03:43 +01:00
Timo Kreuzer 7fff216bed [NTOS:EX] Fix a loop bug 2024-03-19 07:43:20 +01:00
Timo Kreuzer bbbcd8ed68 [NTOS:EX] Remove an ASSERT in ExpInsertPoolTracker 2024-03-03 07:19:35 +01:00
Timo Kreuzer 2ce5d43a33 [NTOS/x64] Gracefully handle invalid Vector in KeConnectInterrupt
Fail instead of asserting. This is needed because a kmtest triggers it.
2024-03-02 07:30:06 +01:00
Dmitry Borisov adf534b284 [NTOS:IO] Initialize InterruptObject to NULL on failure
Fixes a pool corruption when trying to handle IRP_MN_REMOVE_DEVICE in the driver

CORE-17256
2024-02-11 20:24:15 +03:00
Hermès Bélusca-Maïto 475098c8b1
[NTOS:IO] Don't uppercase the ServiceName in IopDisplayLoadingMessage().
Problematic behaviour was added in commit a97f262ed (r26067), and
commit c39812d1b (r46193) converted to RtlUpcaseUnicodeString() call.

This was modifying the caller's given string. This is not really
a good practice to do so just to make display fancier.

For example, IopInitializeBuiltinDriver(), that calls the display
function, also uses the passed ServiceName later after.

Because IopDisplayLoadingMessage() executes only in SOS mode,
uppercasing the ServiceName in one case but not the other would
implicitly modify the observable OS behaviour.

IopSuffixUnicodeString() is adapted to be similar to RtlPrefixUnicodeString().
2024-02-09 17:16:20 +01:00
Hermès Bélusca-Maïto 3b60f4fa13
[NTOS:IO] Fix a count in characters vs. bytes mismatch. 2024-02-09 17:14:19 +01:00
Hermès Bélusca-Maïto d1b3115afa
[NTOS:IO] IopDisplayLoadingMessage(): Display the loading messages only in SOS mode.
- Make the boolean SosEnabled from ex/init.c visible globally so that
  it can be checked against by IopDisplayLoadingMessage().

- Also use RtlString* function to construct the string.
2024-02-09 17:13:30 +01:00
Hermès Bélusca-Maïto 17c59456cd
[NTOS:IO] Minor formatting for IopSuffixUnicodeString and IopDisplayLoadingMessage.
- Doxygen comments;
- SAL annotations;
- These two functions are local to driver.c file only -> static'ify them.
- 2 -> sizeof(WCHAR);
- Rename Length to NumChars;
- static const'ify the L".SYS" string.
2024-02-09 17:00:25 +01:00
Hermès Bélusca-Maïto 08afb1f4b4
[NTOS:INBV] Don't include the fancy splashscreen logo as well
CORE-19449
2024-02-09 12:00:01 +01:00
Hermès Bélusca-Maïto ee2e256ebf
[NTOS:INBV] Disable fancy boot splashscreen features
CORE-19449
2024-02-09 11:52:23 +01:00
Adam Słaboń 1f28f715ba
[NTOS:FSTUB] Pack the MASTER_BOOT_RECORD structure (#6416)
Otherwise the USHORT members are aligned to 4-byte boundary space
which overflows the disk sector buffer and ultimately results in crash.
This can be reproduced by trying to format the USB drive with Rufus.

Also put some additional C_ASSERT checks for extra safety.
2024-02-08 01:02:19 +03:00
Hervé Poussineau 9e43518da5 [NTOS:PO] Set SystemBatteriesPresent when having a battery device in the system
This is (at least) used by powercfg.cpl to know if it needs to display some additional pages.
2024-02-05 18:04:02 +01:00