diff --git a/reactos/ntoskrnl/ke/i386/ctxswitch.S b/reactos/ntoskrnl/ke/i386/ctxswitch.S index 6cfa4f9b5f0..04a16d18ca8 100644 --- a/reactos/ntoskrnl/ke/i386/ctxswitch.S +++ b/reactos/ntoskrnl/ke/i386/ctxswitch.S @@ -544,10 +544,19 @@ MainLoop: #endif jz CheckSchedule + /* Raise to DISPATCH_LEVEL */ + mov ecx, DISPATCH_LEVEL + call @KfRaiseIrql@4 + mov edi, eax + /* Handle the above */ lea ecx, [ebx+KPCR_PRCB_DATA] call @KiRetireDpcList@4 + /* Lower IRQL */ + mov ecx, edi + call @KfLowerIrql@4 + CheckSchedule: /* Check if a next thread is queued */ cmp dword ptr [ebx+KPCR_PRCB_NEXT_THREAD], 0 diff --git a/reactos/ntoskrnl/ntoskrnl.rbuild b/reactos/ntoskrnl/ntoskrnl.rbuild index 30f4e239246..ce341471dfd 100644 --- a/reactos/ntoskrnl/ntoskrnl.rbuild +++ b/reactos/ntoskrnl/ntoskrnl.rbuild @@ -292,7 +292,6 @@ debug.c - idle.c job.c kill.c notify.c diff --git a/reactos/ntoskrnl/ps/idle.c b/reactos/ntoskrnl/ps/idle.c deleted file mode 100644 index e46a744435c..00000000000 --- a/reactos/ntoskrnl/ps/idle.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/ps/idle.c - * PURPOSE: Using idle time - * - * PROGRAMMERS: Alex Ionescu (alex@relsoft.net) - * David Welch (welch@cwcom.net) - */ - -/* INCLUDES *****************************************************************/ - -#include -#define NDEBUG -#include - -#if defined (ALLOC_PRAGMA) -#pragma alloc_text(INIT, PsInitIdleThread) -#endif - -/* FUNCTIONS *****************************************************************/ - -/** System idle thread procedure - * - */ -VOID STDCALL -PsIdleThreadMain(PVOID Context) -{ - KIRQL oldlvl; - - PKPRCB Prcb = KeGetCurrentPrcb(); - - for(;;) - { - if (Prcb->DpcData[0].DpcQueueDepth > 0) - { - KeRaiseIrql(DISPATCH_LEVEL,&oldlvl); - KiDispatchInterrupt(); - KeLowerIrql(oldlvl); - } - - NtYieldExecution(); - - Ke386HaltProcessor(); - } -} - -/* - * HACK-O-RAMA - * Antique vestigial code left alive for the sole purpose of First/Idle Thread - * creation until I can merge my fix for properly creating them. - */ -NTSTATUS -NTAPI -PsInitializeIdleOrFirstThread(PEPROCESS Process, - PETHREAD* ThreadPtr, - PKSTART_ROUTINE StartRoutine, - KPROCESSOR_MODE AccessMode, - BOOLEAN First) -{ - PETHREAD Thread; - PVOID KernelStack; - - Thread = ExAllocatePool(NonPagedPool, sizeof(ETHREAD)); - RtlZeroMemory(Thread, sizeof(ETHREAD)); - Thread->ThreadsProcess = Process; - if (First) - { - KernelStack = P0BootStack; - } - else - { - KernelStack = (PVOID)((ULONG_PTR)MmCreateKernelStack(FALSE) + - KERNEL_STACK_SIZE); - } - KeInitializeThread(&Process->Pcb, - &Thread->Tcb, - PspSystemThreadStartup, - StartRoutine, - NULL, - NULL, - NULL, - KernelStack); - InitializeListHead(&Thread->IrpList); - *ThreadPtr = Thread; - return STATUS_SUCCESS; -} - -/* - * HACK-O-RAMA - * Antique vestigial code left alive for the sole purpose of First/Idle Thread - * creation until I can merge my fix for properly creating them. - */ -VOID -INIT_FUNCTION -NTAPI -PsInitIdleThread(VOID) -{ - PETHREAD IdleThread; - KIRQL oldIrql; - - PsInitializeIdleOrFirstThread(PsIdleProcess, - &IdleThread, - PsIdleThreadMain, - KernelMode, - FALSE); - - oldIrql = KiAcquireDispatcherLock (); - KiReadyThread(&IdleThread->Tcb); - KiReleaseDispatcherLock(oldIrql); - - KeGetCurrentPrcb()->IdleThread = &IdleThread->Tcb; - KeSetPriorityThread(&IdleThread->Tcb, LOW_PRIORITY); - KeSetAffinityThread(&IdleThread->Tcb, 1 << 0); -} diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index df6d3c287ff..1346d98f11b 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -64,6 +64,75 @@ NTSTATUS STDCALL INIT_FUNCTION PspLookupKernelUserEntryPoints(VOID); /* FUNCTIONS ***************************************************************/ +VOID +FASTCALL +KiIdleLoop(VOID); + +/* FUNCTIONS *****************************************************************/ + +/* + * HACK-O-RAMA + * Antique vestigial code left alive for the sole purpose of First/Idle Thread + * creation until I can merge my fix for properly creating them. + */ +VOID +INIT_FUNCTION +NTAPI +PsInitHackThread(VOID) +{ + PETHREAD IdleThread; + KIRQL oldIrql; + + IdleThread = ExAllocatePool(NonPagedPool, sizeof(ETHREAD)); + RtlZeroMemory(IdleThread, sizeof(ETHREAD)); + IdleThread->ThreadsProcess = PsIdleProcess; + KeInitializeThread(&PsIdleProcess->Pcb, + &IdleThread->Tcb, + PspSystemThreadStartup, + (PVOID)KiIdleLoop, + NULL, + NULL, + NULL, + (PVOID)((ULONG_PTR)MmCreateKernelStack(FALSE) + + KERNEL_STACK_SIZE)); + InitializeListHead(&IdleThread->IrpList); + + oldIrql = KiAcquireDispatcherLock (); + KiReadyThread(&IdleThread->Tcb); + KiReleaseDispatcherLock(oldIrql); + + KeGetCurrentPrcb()->IdleThread = &IdleThread->Tcb; + KeSetPriorityThread(&IdleThread->Tcb, LOW_PRIORITY); + KeSetAffinityThread(&IdleThread->Tcb, 1 << 0); +} + +/* + * HACK-O-RAMA + * Antique vestigial code left alive for the sole purpose of First/Idle Thread + * creation until I can merge my fix for properly creating them. + */ +VOID +INIT_FUNCTION +NTAPI +PsInitHackThread2(IN PETHREAD *Hack) +{ + PETHREAD IdleThread; + + IdleThread = ExAllocatePool(NonPagedPool, sizeof(ETHREAD)); + RtlZeroMemory(IdleThread, sizeof(ETHREAD)); + IdleThread->ThreadsProcess = PsInitialSystemProcess; + KeInitializeThread(&PsInitialSystemProcess->Pcb, + &IdleThread->Tcb, + PspSystemThreadStartup, + NULL, + NULL, + NULL, + NULL, + P0BootStack); + InitializeListHead(&IdleThread->IrpList); + *Hack = IdleThread; +} + VOID INIT_FUNCTION NTAPI @@ -72,7 +141,7 @@ PiInitProcessManager(VOID) PsInitJobManagment(); PsInitProcessManagment(); PsInitThreadManagment(); - PsInitIdleThread(); + PsInitHackThread(); } VOID @@ -115,7 +184,7 @@ PsInitThreadManagment(VOID) ObjectTypeInitializer.DeleteProcedure = PspDeleteThread; ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &PsThreadType); - PsInitializeIdleOrFirstThread(PsInitialSystemProcess, &FirstThread, NULL, KernelMode, TRUE); + PsInitHackThread2(&FirstThread); FirstThread->Tcb.State = Running; FirstThread->Tcb.FreezeCount = 0; FirstThread->Tcb.UserAffinity = (1 << 0); /* Set the affinity of the first thread to the boot processor */