Commit graph

1700 commits

Author SHA1 Message Date
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
Hervé Poussineau dff8b93ee2 [NTOS:PO] Give the power device type to PopAddRemoveSysCapsCallback function 2024-02-05 18:04:02 +01:00
Oleg Dubinskiy 5abf0c76b7
[NTOS:KE/x86/arm] Use a better boot process affinity value (#6399)
Use a value that is independent of the CPU bitness.
Addendum to commit 96d5b6281
2024-01-24 17:52:56 +01:00
Justin Miller 748a2e1655
[NTOS] Fix boot on UP build - PrcbLocks are not used on UP (#6391)
On the uniprocessor kernel KiAcquirePrcbLock is a stub that doesn't modify the current Prcb's PrcbLock value.
Quickly protect this assert around CONFIG_SMP
2024-01-20 08:59:13 -08:00
Oleg Dubinskiy ab528ac6ae
[NTOS:KE] Acquire PRCB lock before marking thread ready for execution in dispatch interrupt routine (#6387)
Fixed in x86 and ARM (this was already done in x64).

This is needed because thread preparation routine KxQueueReadyThread()
releases PRCB lock, but does not acquire it, so that the locking must
always be done outside the function, same as in all its other usage cases.
This fixes an assert from release PRCB routine, when booting x86 ReactOS
in SMP mode, because it attempts to release the lock when it is not
actually acquired.

Addendum to commit a011d19ed.

+ Add an assert in KxQueueReadyThread() to ensure the PRCB lock is actually acquired.
2024-01-20 15:58:39 +01:00
Oleg Dubinskiy f72d6dd4c5
[NTOS:KE] Set IRQL to SYNCH_LEVEL when exiting from idle after the thread is ready for execution (#6386)
CORE-1697

Raise IRQL to SYNCH_LEVEL when exiting from the idle thread in the
idle loop, in case it is scheduled for execution. Then restore it
back to DISPATCH_LEVEL, after this is done.
This behaviour is a bit similar to the way it's done on x64.

This IRQL raise is necessary only in SMP builds.
Calls are placed in CONFIG_SMP ifdef: this avoids unnecessary IRQL
changes on UP, since SYNCH_LEVEL and DISPATCH_LEVEL are identical
there, unlike in MP, where SYNCH_LEVEL is IPI_LEVEL - 2 actually.

This prevents bugcheck DRIVER_IRQL_NOT_LESS_OR_EQUAL when booting
SMP x86 ReactOS, in KiTimerExpiration when calling it 2nd time.
The BSOD happened due to IRQL levels mismatch.
2024-01-20 15:55:20 +01:00
Timo Kreuzer 9c1cfe0587 [NTOS:KE] Fix initialization of node block for application processors
- Initialize KeNodeBlock[0] statically
- Update Prcb->ParentNode->ProcessorMask for all processors
2024-01-18 22:41:46 +01:00
Hermès Bélusca-Maïto feb67576dd
[NTOS:CM][CMLIB] In PE mode, allow registry hives (except system ones) to use read/write access.
+ Improve related comments.

Registry hives are opened in shared read access when NT is loaded in PE
mode (MININT) or from network (the hives residing on a network share).
This is true in particular for the main system hives (SYSTEM, SOFTWARE,
DEFAULT, ...).

However, in PE mode, we can allow other hives, e.g. those loaded by the
user (with NtLoadKey) to be loaded with full read/write access, since we
boot from a local computer.
2024-01-17 22:13:03 +01:00
Hermès Bélusca-Maïto 793ee786cd
[NTOS:CM] Initially start the registry in read-only mode.
Disable registry hive writes, until the IO subsystem is initialized
and disk access is enabled (when the SM signals so after AUTOCHK).
2024-01-17 22:09:45 +01:00
Hermès Bélusca-Maïto 76f1da5631
[NTOS:CM][CMLIB] Minor code styling
In particular remove some extra-parentheses around single code tokens,
and replace few "DPRINT1 + while (TRUE);" by UNIMPLEMENTED_DBGBREAK.

+ Improve some comments.
2024-01-17 22:09:37 +01:00
Timo Kreuzer 96d5b6281d [NTOS:KE/x64] Fix boot process affinity 2024-01-16 08:15:53 +01:00
Timo Kreuzer 1ee23d33ac [NTOS:KE] Fix some KAFFINITYs 2024-01-16 08:15:53 +01:00
Hermès Bélusca-Maïto a70ce994f0
🎊 🍾 🥳 Happy New Year 2024 to the ReactOS Community! 🎆 ⚛️ ☢️
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.██████╗  ██████╗ ██████╗ ██╗  ██╗
 __,  ,__)            __,  ,__)       __, ,__)         ╚════██╗██╔═████╗╚════██╗██║  ██║
(--|__| _ ,_ ,_      (--|\ | _       (--\ | _  _ ,_     █████╔╝██║██╔██║ █████╔╝███████║
  _|  |(_||_)|_)(_|    _| \|(/_(_|_)     \|(/_(_||     ██╔═══╝ ████╔╝██║██╔═══╝ ╚════██║
 (        |  |  ,_|   (                (__|            ███████╗╚██████╔╝███████╗     ██║
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.╚══════╝ ╚═════╝ ╚══════╝     ╚═╝
2024-01-01 00:00:00 +01:00
Hermès Bélusca-Maïto 434ac241df
[NTOS:INBV:PO] Consolidate shutdown logo routines where all the boot theming is implemented.
And it's late now, but... Merry Christmas 2023 as well! 🎄
Logo design by contributor 'TheCustomFHD'

"From ReactOS with Love" ;^)
2023-12-25 21:43:20 +01:00
Hermès Bélusca-Maïto 6d265d1fd8
[NTOS:INBV] Isolate the bitmap resources pertaining to the boot theme/animation into their resource sub-file. 2023-12-24 22:39:36 +01:00
Hermès Bélusca-Maïto 0f3da97456
[NTOS:KE:EX] Fix comment typo. 2023-12-24 22:39:35 +01:00
Hermès Bélusca-Maïto 7b410fb8ca
[NTOS:INBV] Don't hardcode the off-screen rot-bar-bits buffer size. 2023-12-24 21:54:24 +01:00
Hermès Bélusca-Maïto 81dc30a434
[NTOS:INBV] Improve comment & define name. 2023-12-24 21:54:23 +01:00
Hermès Bélusca-Maïto 7aec73a76c
[NTOS:INBV] Minor code style. 2023-12-24 21:54:16 +01:00