2000-10-07 13:41:58 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
2001-03-16 18:11:24 +00:00
|
|
|
* Copyright (C) 2000 ReactOS Team
|
2000-10-07 13:41:58 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
2005-01-01 11:47:33 +00:00
|
|
|
/* $Id$
|
2002-05-07 22:34:17 +00:00
|
|
|
*
|
2000-10-07 13:41:58 +00:00
|
|
|
* FILE: ntoskrnl/ke/kthread.c
|
|
|
|
* PURPOSE: Microkernel thread support
|
|
|
|
* PROGRAMMER: David Welch (welch@cwcom.net)
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* Created 22/05/98
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2000-10-07 13:41:58 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <internal/debug.h>
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2004-06-23 22:32:24 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
VOID
|
2004-08-21 21:09:39 +00:00
|
|
|
STDCALL
|
2004-06-23 22:32:24 +00:00
|
|
|
KeCapturePersistentThreadState(
|
|
|
|
IN PVOID CurrentThread,
|
|
|
|
IN ULONG Setting1,
|
|
|
|
IN ULONG Setting2,
|
|
|
|
IN ULONG Setting3,
|
|
|
|
IN ULONG Setting4,
|
|
|
|
IN ULONG Setting5,
|
|
|
|
IN PVOID ThreadState
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2001-03-29 01:14:00 +00:00
|
|
|
VOID
|
2002-06-04 David Welch <welch@whitehall1-5.seh.ox.ac.uk>
* ntoskrnl/ke/i386/exp.c (KiDoubleFaultHandler): Print CR3
correctly.
2002-06-04 David Welch <welch@whitehall1-5.seh.ox.ac.uk>
* ntoskrnl/include/internal/ps.h: Added KTHREAD_STACK_LIMIT definition.
* ntoskrnl/ke/i386/tskswitch.S (Ki386ContextSwitch): Force all the
pages of the kernel stack to be accessible from this process.
2002-06-04 David Welch <welch@cwcom.net>
* ntoskrnl/cc/view.c (ReadCacheSegmentChain): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/cc/copy.c (CcRosCreateCacheSegment): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/cc/copy.c (CcFreeCachePage): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/include/internal/mm.h: Changed prototypes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/include/internal/ps.h (KPROCESS): Changed type of
page directory base to PHYSICAL_ADDRESS.
* ntoskrnl/include/internal/i386/mm.h: Changed prototypes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/ke/kthread.c (KeFreeStackPage): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/ke/kthread.c (KeInitializeThread): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/ke/process.c (KeAttachProcess, KeDetachProcess): Changes
to use PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/ke/kernel.c (PcrPages, KeApplicationProcessorInit): Changes
to use PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/balance.c (MM_ALLOCATION_REQUEST): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/balance.c (MmReleasePageMemoryConsumer): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/balance.c (MmRequestPageMemoryConsumer): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/cont.c (MmFreeContinuousPage): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/cont.c (MmAllocateContinuousAlignedMemory): Changes to
use PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/freelist.c (MmTransferOwnershipPage,
MmGetLRUFirstUserPage, MmGetLRUNextUserPage, MmGetContinuousPages,
MmInitializePageList, MmSetFlagsPage, MmSetRmapListHeadPage,
MmGetRmapListHeadPage, MmMarkPageMapped, MmMarkPageUnmapped,
MmGetFlagsPage, MmSetSavedSwapEntryPage, MmGetSavedSwapEntryPage,
MmReferencePage, MmGetReferenceCountPage, MmIsUsablePage,
MmDereferencePage, MmGetLockCountPage, MmLockPage, MmUnlockPage,
MmAllocPage): Changes to use PHYSICAL_ADDRESS type for physical
addresses.
* ntoskrnl/mm/iospace.c (MmMapIoSpace): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/kmap.c (ExAllocatePage, MiZeroPage, MiCopyFromUserPage,
ExAllocatePageWithPhysPage): Changes to use PHYSICAL_ADDRESS type for
physical addresses.
* ntoskrnl/mm/marea.c (MmFreeMemoryArea): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/mdl.c (MmUnlockPages, MmMapLockedPages,
MmProbeAndLockPages): Changes to use PHYSICAL_ADDRESS type for
physical addresses.
* ntoskrnl/mm/mm.c (MmSharedDataPagePhysicalAddress,
MmCommitPagedPoolAddress, MmNotPresentFault): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/mminit.c (MmInitVirtualMemory): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/ncache.c (MmAllocateNonCachedMemory,
MmFreeNonCachedPage): Changes to use PHYSICAL_ADDRESS type for
physical addresses.
* ntoskrnl/mm/npool.c (grow_kernel_pool): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/rmap.c (MmPageOutPhysicalAddress, MmInsertRmap,
MmDeleteAllRmaps, MmDeleteRmap): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/section.c (MiReadPage, MmNotPresentFaultSectionView,
MmAccessFaultSectionView, MmPageOutDeleteMapping,
MmPageOutSectionView, MmFreeSectionPage): Changes to use
PHYSICAL_ADDRESS type for physical addresses.
* ntoskrnl/mm/slab.c (ExGrowSlabCache): Changes to use
PHYSICAL_ADDRESS type for physical address.
* ntoskrnl/mm/virtual.c (MmPageOutVirtualMemory,
MmNotPresentFaultVirtualMemory, MmFreeVirtualMemoryPage): Changes to
use PHYSICAL_ADDRESS type for physical address.
* ntoskrnl/mm/wset.c (MmTrimUserMemory): Changes to use
PHYSICAL_ADDRESS type for physical address.
* ntoskrnl/mm/page.c (Mmi386ReleaseMmInfo, MmCopyMmInfo,
MmGetPhysicalAddressForProcess, MmCreateVirtualMapping,
MmCreateVirtualMappingUnsafe, MmCreateVirtualMappingForProcess,
MmDeleteVirtualMapping): Changes to use PHYSICAL_ADDRESS type for
physical address.
* ntoskrnl/ps/process (PsInitProcessManagment): Changes to use
PHYSICAL_ADDRESS type for physical address.
* ntoskrnl/ps/thread.c (PsAllocateCallbackStack): Changes to use
PHYSICAL_ADDRESS type for physical address.
2002-06-04 David Welch <welch@cwcom.net>
* Lots of change since the ChangeLog was last updated.
svn path=/trunk/; revision=3000
2002-06-04 15:26:58 +00:00
|
|
|
KeFreeStackPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
|
2004-08-01 07:24:59 +00:00
|
|
|
PFN_TYPE Page, SWAPENTRY SwapEntry, BOOLEAN Dirty)
|
2001-03-29 01:14:00 +00:00
|
|
|
{
|
2004-10-22 20:43:58 +00:00
|
|
|
ASSERT(SwapEntry == 0);
|
2004-08-01 07:24:59 +00:00
|
|
|
if (Page != 0)
|
2001-03-29 01:14:00 +00:00
|
|
|
{
|
2004-08-01 07:24:59 +00:00
|
|
|
MmReleasePageMemoryConsumer(MC_NPPOOL, Page);
|
2001-03-29 01:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-23 22:32:24 +00:00
|
|
|
/*
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
KPRIORITY
|
2004-08-21 21:09:39 +00:00
|
|
|
STDCALL
|
2004-06-23 22:32:24 +00:00
|
|
|
KeQueryPriorityThread (
|
|
|
|
IN PKTHREAD Thread
|
|
|
|
)
|
|
|
|
{
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
return Thread->Priority;
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
2001-03-08 22:06:02 +00:00
|
|
|
NTSTATUS
|
2004-09-28 15:02:31 +00:00
|
|
|
KeReleaseThread(PKTHREAD Thread)
|
2001-03-08 22:06:02 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Releases the resource allocated for a thread by
|
2002-02-15 14:47:55 +00:00
|
|
|
* KeInitializeThread
|
2001-03-08 22:06:02 +00:00
|
|
|
* NOTE: The thread had better not be running when this is called
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
extern unsigned int init_stack;
|
2001-03-29 01:14:00 +00:00
|
|
|
|
2004-09-28 15:02:31 +00:00
|
|
|
/* FIXME - lock the process */
|
|
|
|
RemoveEntryList(&Thread->ThreadListEntry);
|
|
|
|
|
2004-10-30 23:48:57 +00:00
|
|
|
if (Thread->StackLimit != (ULONG_PTR)&init_stack)
|
2001-03-08 22:06:02 +00:00
|
|
|
{
|
2002-05-07 22:34:17 +00:00
|
|
|
MmLockAddressSpace(MmGetKernelAddressSpace());
|
2001-03-29 01:14:00 +00:00
|
|
|
MmFreeMemoryArea(MmGetKernelAddressSpace(),
|
2004-09-28 15:02:31 +00:00
|
|
|
(PVOID)Thread->StackLimit,
|
2001-03-29 01:14:00 +00:00
|
|
|
MM_STACK_SIZE,
|
|
|
|
KeFreeStackPage,
|
|
|
|
NULL);
|
2002-05-07 22:34:17 +00:00
|
|
|
MmUnlockAddressSpace(MmGetKernelAddressSpace());
|
2001-03-08 22:06:02 +00:00
|
|
|
}
|
2004-09-28 15:02:31 +00:00
|
|
|
Thread->StackLimit = 0;
|
|
|
|
Thread->InitialStack = NULL;
|
|
|
|
Thread->StackBase = NULL;
|
|
|
|
Thread->KernelStack = NULL;
|
2001-03-08 22:06:02 +00:00
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2004-06-23 22:32:24 +00:00
|
|
|
/*
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
BOOLEAN
|
2004-08-21 21:09:39 +00:00
|
|
|
STDCALL
|
2004-06-23 22:32:24 +00:00
|
|
|
KeSetKernelStackSwapEnable(
|
|
|
|
IN BOOLEAN Enable
|
|
|
|
)
|
|
|
|
{
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
PKTHREAD Thread;
|
|
|
|
BOOLEAN PreviousState;
|
|
|
|
|
|
|
|
Thread = KeGetCurrentThread();
|
|
|
|
|
|
|
|
/* Save Old State */
|
|
|
|
PreviousState = Thread->EnableStackSwap;
|
|
|
|
|
|
|
|
/* Set New State */
|
|
|
|
Thread->EnableStackSwap = Enable;
|
|
|
|
|
|
|
|
/* Return Old State */
|
|
|
|
return PreviousState;
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
2003-06-16 16:45:52 +00:00
|
|
|
VOID
|
2000-12-23 02:37:41 +00:00
|
|
|
KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
|
2000-10-07 13:41:58 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION: Initialize the microkernel state of the thread
|
|
|
|
*/
|
|
|
|
{
|
2001-11-25 15:21:11 +00:00
|
|
|
PVOID KernelStack;
|
|
|
|
NTSTATUS Status;
|
|
|
|
extern unsigned int init_stack_top;
|
|
|
|
extern unsigned int init_stack;
|
|
|
|
PMEMORY_AREA StackArea;
|
|
|
|
ULONG i;
|
2003-12-31 05:33:04 +00:00
|
|
|
PHYSICAL_ADDRESS BoundaryAddressMultiple;
|
|
|
|
|
|
|
|
BoundaryAddressMultiple.QuadPart = 0;
|
2001-11-25 15:21:11 +00:00
|
|
|
|
|
|
|
KeInitializeDispatcherHeader(&Thread->DispatcherHeader,
|
|
|
|
InternalThreadType,
|
|
|
|
sizeof(ETHREAD),
|
|
|
|
FALSE);
|
|
|
|
InitializeListHead(&Thread->MutantListHead);
|
|
|
|
if (!First)
|
|
|
|
{
|
2004-08-01 07:24:59 +00:00
|
|
|
PFN_TYPE Page[MM_STACK_SIZE / PAGE_SIZE];
|
2001-11-25 15:21:11 +00:00
|
|
|
KernelStack = NULL;
|
|
|
|
|
|
|
|
MmLockAddressSpace(MmGetKernelAddressSpace());
|
|
|
|
Status = MmCreateMemoryArea(NULL,
|
|
|
|
MmGetKernelAddressSpace(),
|
|
|
|
MEMORY_AREA_KERNEL_STACK,
|
|
|
|
&KernelStack,
|
|
|
|
MM_STACK_SIZE,
|
2002-05-14 21:19:21 +00:00
|
|
|
0,
|
2001-11-25 15:21:11 +00:00
|
|
|
&StackArea,
|
2003-05-17 15:29:50 +00:00
|
|
|
FALSE,
|
2003-12-31 05:33:04 +00:00
|
|
|
FALSE,
|
|
|
|
BoundaryAddressMultiple);
|
2001-11-25 15:21:11 +00:00
|
|
|
MmUnlockAddressSpace(MmGetKernelAddressSpace());
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to create thread stack\n");
|
2003-07-21 21:53:53 +00:00
|
|
|
KEBUGCHECK(0);
|
2001-11-25 15:21:11 +00:00
|
|
|
}
|
2002-10-01 19:27:25 +00:00
|
|
|
for (i = 0; i < (MM_STACK_SIZE / PAGE_SIZE); i++)
|
2001-11-25 15:21:11 +00:00
|
|
|
{
|
2004-08-01 07:24:59 +00:00
|
|
|
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &Page[i]);
|
2001-12-31 01:53:46 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2003-07-21 21:53:53 +00:00
|
|
|
KEBUGCHECK(0);
|
2001-12-31 01:53:46 +00:00
|
|
|
}
|
2004-08-01 07:24:59 +00:00
|
|
|
}
|
|
|
|
Status = MmCreateVirtualMapping(NULL,
|
|
|
|
KernelStack,
|
|
|
|
PAGE_READWRITE,
|
|
|
|
Page,
|
|
|
|
MM_STACK_SIZE / PAGE_SIZE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
KEBUGCHECK(0);
|
2001-11-25 15:21:11 +00:00
|
|
|
}
|
2004-10-30 23:48:57 +00:00
|
|
|
Thread->InitialStack = (PCHAR)KernelStack + MM_STACK_SIZE;
|
|
|
|
Thread->StackBase = (PCHAR)KernelStack + MM_STACK_SIZE;
|
|
|
|
Thread->StackLimit = (ULONG_PTR)KernelStack;
|
|
|
|
Thread->KernelStack = (PCHAR)KernelStack + MM_STACK_SIZE;
|
2001-11-25 15:21:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-10-30 23:48:57 +00:00
|
|
|
Thread->InitialStack = (PCHAR)&init_stack_top;
|
|
|
|
Thread->StackBase = (PCHAR)&init_stack_top;
|
|
|
|
Thread->StackLimit = (ULONG_PTR)&init_stack;
|
|
|
|
Thread->KernelStack = (PCHAR)&init_stack_top;
|
2001-11-25 15:21:11 +00:00
|
|
|
}
|
2004-08-27 10:24:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Establish the pde's for the new stack and the thread structure within the
|
|
|
|
* address space of the new process. They are accessed while taskswitching or
|
|
|
|
* while handling page faults. At this point it isn't possible to call the
|
|
|
|
* page fault handler for the missing pde's.
|
|
|
|
*/
|
2001-11-25 15:21:11 +00:00
|
|
|
|
2004-08-19 21:51:06 +00:00
|
|
|
MmUpdatePageDir((PEPROCESS)Process, (PVOID)Thread->StackLimit, MM_STACK_SIZE);
|
2004-08-27 10:24:04 +00:00
|
|
|
MmUpdatePageDir((PEPROCESS)Process, (PVOID)Thread, sizeof(ETHREAD));
|
2004-08-19 21:51:06 +00:00
|
|
|
|
2001-11-25 15:21:11 +00:00
|
|
|
/*
|
|
|
|
* The Native API function will initialize the TEB field later
|
|
|
|
*/
|
|
|
|
Thread->Teb = NULL;
|
|
|
|
Thread->TlsArray = NULL;
|
|
|
|
Thread->DebugActive = 0;
|
2002-07-10 15:15:00 +00:00
|
|
|
Thread->State = THREAD_STATE_INITIALIZED;
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->Alerted[0] = 0;
|
|
|
|
Thread->Alerted[1] = 0;
|
|
|
|
Thread->Iopl = 0;
|
|
|
|
/*
|
|
|
|
* FIXME: Think how this might work
|
|
|
|
*/
|
|
|
|
Thread->NpxState = 0;
|
|
|
|
|
|
|
|
Thread->Saturation = 0;
|
2004-10-30 23:48:57 +00:00
|
|
|
Thread->Priority = Process->BasePriority;
|
2001-11-25 15:21:11 +00:00
|
|
|
InitializeListHead(&Thread->ApcState.ApcListHead[0]);
|
|
|
|
InitializeListHead(&Thread->ApcState.ApcListHead[1]);
|
|
|
|
Thread->ApcState.Process = Process;
|
|
|
|
Thread->ApcState.KernelApcInProgress = 0;
|
|
|
|
Thread->ApcState.KernelApcPending = 0;
|
|
|
|
Thread->ApcState.UserApcPending = 0;
|
|
|
|
Thread->ContextSwitches = 0;
|
|
|
|
Thread->WaitStatus = STATUS_SUCCESS;
|
2005-01-01 11:47:33 +00:00
|
|
|
Thread->WaitIrql = PASSIVE_LEVEL;
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->WaitMode = 0;
|
2005-01-01 11:47:33 +00:00
|
|
|
Thread->WaitNext = FALSE;
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->WaitBlockList = NULL;
|
|
|
|
Thread->WaitListEntry.Flink = NULL;
|
|
|
|
Thread->WaitListEntry.Blink = NULL;
|
|
|
|
Thread->WaitTime = 0;
|
2004-10-30 23:48:57 +00:00
|
|
|
Thread->BasePriority = Process->BasePriority;
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->DecrementCount = 0;
|
|
|
|
Thread->PriorityDecrement = 0;
|
2004-10-30 23:48:57 +00:00
|
|
|
Thread->Quantum = Process->ThreadQuantum;
|
2001-11-25 15:21:11 +00:00
|
|
|
memset(Thread->WaitBlock, 0, sizeof(KWAIT_BLOCK)*4);
|
2004-11-10 02:51:00 +00:00
|
|
|
Thread->LegoData = 0;
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->UserAffinity = Process->Affinity;
|
|
|
|
Thread->SystemAffinityActive = 0;
|
2003-06-16 16:45:52 +00:00
|
|
|
Thread->PowerState = 0;
|
|
|
|
Thread->NpxIrql = 0;
|
|
|
|
Thread->ServiceTable = KeServiceDescriptorTable;
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->Queue = NULL;
|
|
|
|
KeInitializeSpinLock(&Thread->ApcQueueLock);
|
|
|
|
memset(&Thread->Timer, 0, sizeof(KTIMER));
|
2003-12-30 18:52:06 +00:00
|
|
|
KeInitializeTimer(&Thread->Timer);
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->QueueListEntry.Flink = NULL;
|
|
|
|
Thread->QueueListEntry.Blink = NULL;
|
|
|
|
Thread->Affinity = Process->Affinity;
|
|
|
|
Thread->Preempted = 0;
|
|
|
|
Thread->ProcessReadyQueue = 0;
|
|
|
|
Thread->KernelStackResident = 1;
|
|
|
|
Thread->NextProcessor = 0;
|
|
|
|
Thread->CallbackStack = NULL;
|
2004-09-28 15:02:31 +00:00
|
|
|
Thread->Win32Thread = NULL;
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->TrapFrame = NULL;
|
2003-11-27 01:13:05 +00:00
|
|
|
Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
|
|
|
|
Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->EnableStackSwap = 0;
|
|
|
|
Thread->LargeStack = 0;
|
|
|
|
Thread->ResourceIndex = 0;
|
|
|
|
Thread->PreviousMode = KernelMode;
|
|
|
|
Thread->KernelTime = 0;
|
|
|
|
Thread->UserTime = 0;
|
|
|
|
memset(&Thread->SavedApcState, 0, sizeof(KAPC_STATE));
|
2004-11-10 02:51:00 +00:00
|
|
|
|
2003-11-27 01:13:05 +00:00
|
|
|
Thread->ApcStateIndex = OriginalApcEnvironment;
|
|
|
|
Thread->ApcQueueable = TRUE;
|
2004-10-30 23:48:57 +00:00
|
|
|
Thread->AutoAlignment = Process->AutoAlignment;
|
2004-11-10 02:51:00 +00:00
|
|
|
|
2001-11-25 15:21:11 +00:00
|
|
|
KeInitializeApc(&Thread->SuspendApc,
|
|
|
|
Thread,
|
2003-06-16 16:45:52 +00:00
|
|
|
OriginalApcEnvironment,
|
2001-11-25 15:21:11 +00:00
|
|
|
PiSuspendThreadKernelRoutine,
|
|
|
|
PiSuspendThreadRundownRoutine,
|
|
|
|
PiSuspendThreadNormalRoutine,
|
|
|
|
KernelMode,
|
|
|
|
NULL);
|
2002-08-09 17:23:57 +00:00
|
|
|
KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 128);
|
2004-11-10 02:51:00 +00:00
|
|
|
|
2004-09-28 15:02:31 +00:00
|
|
|
InsertTailList(&Process->ThreadListHead,
|
|
|
|
&Thread->ThreadListEntry);
|
2001-11-25 15:21:11 +00:00
|
|
|
Thread->FreezeCount = 0;
|
|
|
|
Thread->SuspendCount = 0;
|
2000-12-10 23:42:01 +00:00
|
|
|
|
2000-10-07 13:41:58 +00:00
|
|
|
/*
|
|
|
|
* Do x86 specific part
|
|
|
|
*/
|
|
|
|
}
|
2000-12-23 02:37:41 +00:00
|
|
|
|
2004-06-23 22:32:24 +00:00
|
|
|
/*
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
VOID
|
2004-08-21 21:09:39 +00:00
|
|
|
STDCALL
|
2004-10-22 20:43:58 +00:00
|
|
|
KeRevertToUserAffinityThread(VOID)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2005-01-01 11:47:33 +00:00
|
|
|
#ifdef MP
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
PKTHREAD CurrentThread;
|
2004-12-12 17:36:00 +00:00
|
|
|
KIRQL oldIrql;
|
|
|
|
|
2004-12-12 23:18:55 +00:00
|
|
|
oldIrql = KeAcquireDispatcherDatabaseLock();
|
|
|
|
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
CurrentThread = KeGetCurrentThread();
|
2004-12-12 17:25:53 +00:00
|
|
|
|
|
|
|
ASSERT(CurrentThread->SystemAffinityActive != FALSE);
|
|
|
|
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
/* Return to User Affinity */
|
|
|
|
CurrentThread->Affinity = CurrentThread->UserAffinity;
|
|
|
|
|
|
|
|
/* Disable System Affinity */
|
|
|
|
CurrentThread->SystemAffinityActive = FALSE;
|
2004-12-12 17:25:53 +00:00
|
|
|
|
|
|
|
if (CurrentThread->Affinity & (1 << KeGetCurrentProcessorNumber()))
|
|
|
|
{
|
|
|
|
KeReleaseDispatcherDatabaseLock(oldIrql);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentThread->WaitIrql = oldIrql;
|
|
|
|
PsDispatchThreadNoLock(THREAD_STATE_READY);
|
|
|
|
KeLowerIrql(oldIrql);
|
|
|
|
}
|
2005-01-01 11:47:33 +00:00
|
|
|
#endif
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
CCHAR
|
2004-08-21 21:09:39 +00:00
|
|
|
STDCALL
|
2004-06-23 22:32:24 +00:00
|
|
|
KeSetIdealProcessorThread (
|
|
|
|
IN PKTHREAD Thread,
|
2004-10-22 20:43:58 +00:00
|
|
|
IN CCHAR Processor)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
CCHAR PreviousIdealProcessor;
|
|
|
|
|
|
|
|
/* Save Old Ideal Processor */
|
|
|
|
PreviousIdealProcessor = Thread->IdealProcessor;
|
|
|
|
|
|
|
|
/* Set New Ideal Processor */
|
|
|
|
Thread->IdealProcessor = Processor;
|
|
|
|
|
|
|
|
/* Return Old Ideal Processor */
|
|
|
|
return PreviousIdealProcessor;
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
VOID
|
2004-08-21 21:09:39 +00:00
|
|
|
STDCALL
|
2004-10-22 20:43:58 +00:00
|
|
|
KeSetSystemAffinityThread(IN KAFFINITY Affinity)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2005-01-01 11:47:33 +00:00
|
|
|
#ifdef MP
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
PKTHREAD CurrentThread;
|
2004-12-12 17:25:53 +00:00
|
|
|
KIRQL oldIrql;
|
|
|
|
|
|
|
|
oldIrql = KeAcquireDispatcherDatabaseLock();
|
|
|
|
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
CurrentThread = KeGetCurrentThread();
|
2004-12-12 17:25:53 +00:00
|
|
|
|
|
|
|
ASSERT(Affinity & ((1 << KeNumberProcessors) - 1));
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
|
2004-12-12 17:25:53 +00:00
|
|
|
/* Set the System Affinity Specified */
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
CurrentThread->Affinity = Affinity;
|
|
|
|
|
|
|
|
/* Enable System Affinity */
|
|
|
|
CurrentThread->SystemAffinityActive = TRUE;
|
2004-12-12 17:25:53 +00:00
|
|
|
|
|
|
|
if (Affinity & (1 << KeGetCurrentProcessorNumber()))
|
|
|
|
{
|
|
|
|
KeReleaseDispatcherDatabaseLock(oldIrql);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentThread->WaitIrql = oldIrql;
|
|
|
|
PsDispatchThreadNoLock(THREAD_STATE_READY);
|
|
|
|
KeLowerIrql(oldIrql);
|
|
|
|
}
|
2005-01-01 11:47:33 +00:00
|
|
|
#endif
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
2004-10-22 20:43:58 +00:00
|
|
|
VOID
|
2004-08-21 21:09:39 +00:00
|
|
|
STDCALL
|
2004-10-22 20:43:58 +00:00
|
|
|
KeTerminateThread(IN KPRIORITY Increment)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
/* The Increment Argument seems to be ignored by NT and always 0 when called */
|
|
|
|
|
|
|
|
/* Call our own internal routine */
|
|
|
|
PsTerminateCurrentThread(0);
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|