Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess

svn path=/trunk/; revision=11284
This commit is contained in:
Alex Ionescu 2004-10-13 01:42:14 +00:00
parent 83a232d3a2
commit c30ca53066
9 changed files with 171 additions and 33 deletions

View file

@ -597,7 +597,7 @@ KeTerminateThread(
IN KPRIORITY Increment IN KPRIORITY Increment
); );
VOID BOOLEAN
STDCALL STDCALL
KeIsExecutingDpc( KeIsExecutingDpc(
VOID VOID
@ -632,7 +632,8 @@ KeFindConfigurationNextEntry(
VOID VOID
STDCALL STDCALL
KeFlushEntireTb( KeFlushEntireTb(
IN ULONGLONG Flag IN BOOLEAN Unknown,
IN BOOLEAN CurrentCpuOnly
); );
VOID VOID

View file

@ -30,6 +30,7 @@ OBJECTS_KE_I386 := \
ke/i386/brkpoint.o \ ke/i386/brkpoint.o \
ke/i386/kernel.o \ ke/i386/kernel.o \
ke/i386/fpu.o \ ke/i386/fpu.o \
ke/i386/tlbflush.o \
ke/i386/tss.o \ ke/i386/tss.o \
ke/i386/usertrap.o \ ke/i386/usertrap.o \
ke/i386/stkswitch.o ke/i386/stkswitch.o

View file

@ -169,6 +169,10 @@ KeUpdateRunTime(
IN PKTRAP_FRAME TrapFrame IN PKTRAP_FRAME TrapFrame
); );
VOID
STDCALL
KeFlushCurrentTb(VOID);
#endif /* not __ASM__ */ #endif /* not __ASM__ */
#define MAXIMUM_PROCESSORS 32 #define MAXIMUM_PROCESSORS 32

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: ps.h,v 1.70 2004/10/01 20:26:04 gvg Exp $ /* $Id: ps.h,v 1.71 2004/10/13 01:42:14 ion Exp $
* *
* FILE: ntoskrnl/ke/kthread.c * FILE: ntoskrnl/ke/kthread.c
* PURPOSE: Process manager definitions * PURPOSE: Process manager definitions
@ -445,6 +445,7 @@ VOID PsInitProcessManagment(VOID);
VOID PsInitIdleThread(VOID); VOID PsInitIdleThread(VOID);
VOID PsDispatchThreadNoLock(ULONG NewThreadStatus); VOID PsDispatchThreadNoLock(ULONG NewThreadStatus);
VOID PiTerminateProcessThreads(PEPROCESS Process, NTSTATUS ExitStatus); VOID PiTerminateProcessThreads(PEPROCESS Process, NTSTATUS ExitStatus);
VOID PsTerminateCurrentThread(NTSTATUS ExitStatus);
VOID PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus); VOID PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus);
VOID PsReleaseThread(PETHREAD Thread); VOID PsReleaseThread(PETHREAD Thread);
VOID PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext); VOID PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext);

View file

@ -44,7 +44,7 @@ VOID PsTerminateCurrentThread(NTSTATUS ExitStatus);
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
/* /*
* @unimplemented * @implemented
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
@ -52,7 +52,7 @@ KeAreApcsDisabled(
VOID VOID
) )
{ {
UNIMPLEMENTED; return KeGetCurrentThread()->KernelApcDisable ? FALSE : TRUE;
} }
VOID KiRundownThread(VOID) VOID KiRundownThread(VOID)

View file

@ -1,4 +1,4 @@
/* $Id: device.c,v 1.2 2004/08/15 16:39:05 chorns Exp $ /* $Id: device.c,v 1.3 2004/10/13 01:42:14 ion Exp $
* *
* FILE: ntoskrnl/ke/profile.c * FILE: ntoskrnl/ke/profile.c
* PURPOSE: Kernel Device/Settings Functions * PURPOSE: Kernel Device/Settings Functions
@ -45,15 +45,51 @@ KeFindConfigurationNextEntry(
} }
/* /*
* @unimplemented * @implemented
*/ */
STDCALL STDCALL
VOID VOID
KeFlushEntireTb( KeFlushEntireTb(
IN ULONGLONG Flag IN BOOLEAN Unknown,
IN BOOLEAN CurrentCpuOnly
) )
{ {
UNIMPLEMENTED; KIRQL OldIrql;
PKPROCESS Process;
PKPCR Pcr;
/* Raise the IRQL for the TB Flush */
OldIrql = KeRaiseIrqlToSynchLevel();
/* All CPUs need to have the TB flushed. */
if (CurrentCpuOnly == FALSE) {
Pcr = KeGetCurrentKPCR();
/* How many CPUs is our caller using? */
Process = Pcr->PrcbData.CurrentThread->ApcState.Process;
/* More then one, so send an IPI */
if (Process->ActiveProcessors > 1) {
/* Send IPI Packet */
}
}
/* Flush the TB for the Current CPU */
KeFlushCurrentTb();
/* Clean up */
if (CurrentCpuOnly == FALSE) {
/* Did we send an IPI? If so, wait for completion */
if (Process->ActiveProcessors > 1) {
do {
} while (Pcr->PrcbData.TargetSet != 0);
}
}
/* FIXME: According to MSKB, we should increment a counter? */
/* Return to Original IRQL */
KeLowerIrql(OldIrql);
} }

View file

@ -18,7 +18,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: dpc.c,v 1.36 2004/10/01 20:09:57 hbirr Exp $ /* $Id: dpc.c,v 1.37 2004/10/13 01:42:14 ion Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -144,15 +144,15 @@ KeFlushQueuedDpcs(
} }
/* /*
* @unimplemented * @implemented
*/ */
VOID BOOLEAN
STDCALL STDCALL
KeIsExecutingDpc( KeIsExecutingDpc(
VOID VOID
) )
{ {
UNIMPLEMENTED; return KeGetCurrentKPCR()->PrcbData.DpcRoutineActive;
} }
/* /*

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: kthread.c,v 1.53 2004/09/28 15:02:29 weiden Exp $ /* $Id: kthread.c,v 1.54 2004/10/13 01:42:14 ion Exp $
* *
* FILE: ntoskrnl/ke/kthread.c * FILE: ntoskrnl/ke/kthread.c
* PURPOSE: Microkernel thread support * PURPOSE: Microkernel thread support
@ -63,7 +63,7 @@ KeFreeStackPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
} }
/* /*
* @unimplemented * @implemented
*/ */
KPRIORITY KPRIORITY
STDCALL STDCALL
@ -71,8 +71,7 @@ KeQueryPriorityThread (
IN PKTHREAD Thread IN PKTHREAD Thread
) )
{ {
UNIMPLEMENTED; return Thread->Priority;
return 0;
} }
NTSTATUS NTSTATUS
@ -106,7 +105,7 @@ KeReleaseThread(PKTHREAD Thread)
} }
/* /*
* @unimplemented * @implemented
*/ */
BOOLEAN BOOLEAN
STDCALL STDCALL
@ -114,8 +113,19 @@ KeSetKernelStackSwapEnable(
IN BOOLEAN Enable IN BOOLEAN Enable
) )
{ {
UNIMPLEMENTED; PKTHREAD Thread;
return FALSE; BOOLEAN PreviousState;
Thread = KeGetCurrentThread();
/* Save Old State */
PreviousState = Thread->EnableStackSwap;
/* Set New State */
Thread->EnableStackSwap = Enable;
/* Return Old State */
return PreviousState;
} }
VOID VOID
@ -324,7 +334,7 @@ KeRescheduleThread()
} }
/* /*
* @unimplemented * @implemented
*/ */
VOID VOID
STDCALL STDCALL
@ -332,11 +342,18 @@ KeRevertToUserAffinityThread(
VOID VOID
) )
{ {
UNIMPLEMENTED; PKTHREAD CurrentThread;
CurrentThread = KeGetCurrentThread();
/* Return to User Affinity */
CurrentThread->Affinity = CurrentThread->UserAffinity;
/* Disable System Affinity */
CurrentThread->SystemAffinityActive = FALSE;
} }
/* /*
* @unimplemented * @implemented
*/ */
CCHAR CCHAR
STDCALL STDCALL
@ -345,12 +362,20 @@ KeSetIdealProcessorThread (
IN CCHAR Processor IN CCHAR Processor
) )
{ {
UNIMPLEMENTED; CCHAR PreviousIdealProcessor;
return 0;
/* Save Old Ideal Processor */
PreviousIdealProcessor = Thread->IdealProcessor;
/* Set New Ideal Processor */
Thread->IdealProcessor = Processor;
/* Return Old Ideal Processor */
return PreviousIdealProcessor;
} }
/* /*
* @unimplemented * @implemented
*/ */
VOID VOID
STDCALL STDCALL
@ -358,11 +383,18 @@ KeSetSystemAffinityThread(
IN KAFFINITY Affinity IN KAFFINITY Affinity
) )
{ {
UNIMPLEMENTED; PKTHREAD CurrentThread;
CurrentThread = KeGetCurrentThread();
/* Set the System Affinity Specified */
CurrentThread->Affinity = Affinity;
/* Enable System Affinity */
CurrentThread->SystemAffinityActive = TRUE;
} }
/* /*
* @unimplemented * @implemented
*/ */
VOID VOID
STDCALL STDCALL
@ -370,5 +402,8 @@ KeTerminateThread(
IN KPRIORITY Increment IN KPRIORITY Increment
) )
{ {
UNIMPLEMENTED; /* The Increment Argument seems to be ignored by NT and always 0 when called */
/* Call our own internal routine */
PsTerminateCurrentThread(0);
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: process.c,v 1.27 2004/08/31 20:17:18 hbirr Exp $ /* $Id: process.c,v 1.28 2004/10/13 01:42:14 ion Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/process.c * FILE: ntoskrnl/ke/process.c
@ -123,11 +123,37 @@ KeStackAttachProcess (
OUT PRKAPC_STATE ApcState OUT PRKAPC_STATE ApcState
) )
{ {
UNIMPLEMENTED; KIRQL OldIrql;
PKTHREAD Thread;
Thread = KeGetCurrentThread();
OldIrql = KeAcquireDispatcherDatabaseLock();
/* Crash system if DPC is being executed! */
if (KeIsExecutingDpc()) {
DPRINT1("Invalid attach (Thread is executing a DPC!)\n");
KEBUGCHECK(INVALID_PROCESS_ATTACH_ATTEMPT);
}
/* Check if the Target Process is already attached */
if (Thread->ApcState.Process == Process) {
ApcState->Process = (PKPROCESS)1; /* Meaning already attached to the same Process */
} else {
/* Check if the Current Thread is already attached */
if (Thread->ApcStateIndex != 0) {
KeAttachProcess((PEPROCESS)Process); /* FIXME: Re-write function to support stackability and fix it not to use EPROCESS */
} else {
KeAttachProcess((PEPROCESS)Process);
ApcState->Process = NULL; /* FIXME: Re-write function to support stackability and fix it not to use EPROCESS */
}
}
/* Return to old IRQL*/
KeReleaseDispatcherDatabaseLock(OldIrql);
} }
/* /*
* @unimplemented * @implemented
*/ */
VOID VOID
STDCALL STDCALL
@ -135,7 +161,41 @@ KeUnstackDetachProcess (
IN PRKAPC_STATE ApcState IN PRKAPC_STATE ApcState
) )
{ {
UNIMPLEMENTED; KIRQL OldIrql;
PKTHREAD Thread;
ULONG PageDir;
/* If the special "We tried to attach to the process already being attached to" flag is there, don't do anything */
if (ApcState->Process == (PKPROCESS)1) return;
Thread = KeGetCurrentThread();
OldIrql = KeAcquireDispatcherDatabaseLock();
/* Sorry Buddy, can't help you if you've got APCs or just aren't attached */
if ((Thread->ApcStateIndex == 0) || (Thread->ApcState.KernelApcInProgress)) {
DPRINT1("Invalid detach (Thread not Attached, or Kernel APC in Progress!)\n");
KEBUGCHECK(INVALID_PROCESS_DETACH_ATTEMPT);
}
/* Restore the Old APC State if a Process was present */
if (ApcState->Process) {
RtlMoveMemory(ApcState, &Thread->ApcState, sizeof(KAPC_STATE));
} else {
/* The ApcState parameter is useless, so use the saved data and reset it */
RtlMoveMemory(&Thread->SavedApcState, &Thread->ApcState, sizeof(KAPC_STATE));
Thread->SavedApcState.Process = NULL;
Thread->ApcStateIndex = 0;
Thread->ApcStatePointer[0] = &Thread->ApcState;
Thread->ApcStatePointer[1] = &Thread->SavedApcState;
}
/* Do the Actual Swap */
KiSwapApcEnvironment(Thread, Thread->SavedApcState.Process);
PageDir = Thread->ApcState.Process->DirectoryTableBase.u.LowPart;
Ke386SetPageTableDirectory(PageDir);
/* Return to old IRQL*/
KeReleaseDispatcherDatabaseLock(OldIrql);
} }
/* EOF */ /* EOF */