Commit graph

198 commits

Author SHA1 Message Date
Serge Gautherie
2d442956b4
[NTOS:IO] IoConnectInterrupt(): Fix default spinlock initialization (#6503)
Addendum to commit d1258e99f (r16229).
2024-05-05 17:03:20 +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
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
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
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
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
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
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
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
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
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
0f3da97456
[NTOS:KE:EX] Fix comment typo. 2023-12-24 22:39:35 +01:00
Ratin Gao
ffb20d3330
[REACTOS] Fix typos (#6198)
- Adress -> Address
- Currupted -> Corrupted

3rd-party files are not modified.
2023-12-23 21:37:08 +01:00
Timo Kreuzer
1831bc6add [NTOS:KE/x64] Implement initial IPI code 2023-12-18 23:16:39 +02:00
Timo Kreuzer
e5c5efe2ad [NTOS:KE/x64] Set the idle thread's IdealProcessor for application processors 2023-12-08 20:16:51 +02:00
Timo Kreuzer
b1a9e72e92 [NTOS:KE/x64] Do not call HalInitSystem from application processors 2023-12-08 20:16:51 +02:00
Timo Kreuzer
d0f6874d92 [NTOS:KE/x64] Factor out KiIntializeProcessorBootStructures 2023-12-08 20:16:51 +02:00
Timo Kreuzer
8c466c3e36 [NTOS:KE/x64] Improve KiInitializePcr 2023-12-08 20:16:51 +02:00
Timo Kreuzer
d2a3b1c791 [NTOS:KE/x64] Factor out KiInitializeP0BootStructures 2023-12-08 20:16:51 +02:00
Timo Kreuzer
e655594609 [NTOS:KE/x64] (Re)move initialization of IRQL and TR 2023-12-08 20:16:51 +02:00
Timo Kreuzer
0a7255e4bf [NTOS:KE/x64] Move Initialization of TSS 2023-12-08 20:16:51 +02:00
Timo Kreuzer
160980aba1 [NTOS:KE/x64] Move initialization of PCR 2023-12-08 20:16:51 +02:00
Timo Kreuzer
ba62dd0aaa [NTOS:KE/x64] Move initialization of KeLoaderBlock 2023-12-08 20:16:51 +02:00
Timo Kreuzer
e1497d43d7 [NTOS:KE/x64] Improve KiInitializeTss 2023-12-08 20:16:51 +02:00
Timo Kreuzer
bbe16859b5 [NTOS:KE/x64] Rename P0 boot stacks 2023-12-08 20:16:51 +02:00
Timo Kreuzer
6c5b3f203d [NTOS:KE/x64] Add back a stubs.c file 2023-12-08 19:38:59 +02:00
Timo Kreuzer
57c7f06004 [NTOS:KE/x64] Rename stubs.c to traphandler.c 2023-12-08 19:38:59 +02:00
Hermès Bélusca-Maïto
2f0a5e546f
[NTOS:KE] Don't hardcode pool tag and TSS flag values (#6051)
Co-authored-by: Serge Gautherie <32623169+SergeGautherie@users.noreply.github.com>
2023-12-03 17:33:10 +01:00
Timo Kreuzer
f92c44b217 [NTOS:KE] Remove KiMask32Array
It's useless and also broken in the way it is used. Replace it with a simple shift and make it correct for 64 bit.
2023-11-30 13:03:52 +02:00
Justin Miller
516ccad340
[NTOS:KE][HALX86] Implement AP startup code (#5879)
Co-authored-by: Victor Perevertkin <victor.perevertkin@reactos.org>

Introduce the initial changes needed to get other processors up and into kernel mode. 
This only supports x86 as of now but is the first real step towards using other system processors.
2023-11-19 15:51:33 -08:00
Timo Kreuzer
410b1030c0 [NTOS:KE/x64] Implement detection of more KF_* feature flags
- Detect KF_SSSE3, KF_SSE4_1, KF_SSE4_2, KF_RDRAND, KF_BRANCH, KF_SLAT, KF_GENUINE_INTEL, KF_AUTHENTICAMD, KF_ACNT2, KF_SMEP, KF_SMAP, KF_RDWRFSGSBASE, KF_XSAVEOPT, KF_XSAVES, KF_HUGEPAGE, KF_RDTSCP
2023-10-03 19:45:44 +03:00
Timo Kreuzer
1a7ab2fe68 [NTOS:KE/x64] Use structures for CPUID 2023-10-03 19:45:44 +03:00