mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 05:55:48 +00:00
- Added constants for all the ETHREAD flags so when we use Interlocked operations to edit them, a nice symbolic name is there isntead of a magic hex value.
- Fixed a bug in PspUserThreadStartup which was causing us to notify the debugger for system threads or hidden threads, instead of vice-versa. - Documented cookie generation for Thomas. - Threads were incorrectly created with KernelMode access instead of PreviousMode. - Initialize the thread's rundown protection and use the process's. - Handle failure when TEB = NULL. - The LPC Semaphore has a limit of 1, not 0x7FFF. svn path=/trunk/; revision=23085
This commit is contained in:
parent
72185bb72b
commit
03d4c9af39
2 changed files with 67 additions and 17 deletions
|
@ -97,9 +97,9 @@ extern NTSYSAPI POBJECT_TYPE PsProcessType;
|
||||||
#define PS_INHERIT_HANDLES 4
|
#define PS_INHERIT_HANDLES 4
|
||||||
#define PS_UNKNOWN_VALUE 8
|
#define PS_UNKNOWN_VALUE 8
|
||||||
#define PS_ALL_FLAGS (PS_REQUEST_BREAKAWAY | \
|
#define PS_ALL_FLAGS (PS_REQUEST_BREAKAWAY | \
|
||||||
PS_NO_DEBUG_INHERIT | \
|
PS_NO_DEBUG_INHERIT | \
|
||||||
PS_INHERIT_HANDLES | \
|
PS_INHERIT_HANDLES | \
|
||||||
PS_UNKNOWN_VALUE)
|
PS_UNKNOWN_VALUE)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Process base priorities
|
// Process base priorities
|
||||||
|
@ -139,7 +139,6 @@ extern NTSYSAPI POBJECT_TYPE PsProcessType;
|
||||||
0xFFF)
|
0xFFF)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Job Access Types
|
// Job Access Types
|
||||||
//
|
//
|
||||||
|
@ -151,6 +150,34 @@ extern NTSYSAPI POBJECT_TYPE PsProcessType;
|
||||||
#define JOB_OBJECT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
|
#define JOB_OBJECT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
|
||||||
SYNCHRONIZE | \
|
SYNCHRONIZE | \
|
||||||
31)
|
31)
|
||||||
|
|
||||||
|
//
|
||||||
|
// Cross Thread Flags
|
||||||
|
//
|
||||||
|
#define CT_TERMINATED_BIT 0x1
|
||||||
|
#define CT_DEAD_THREAD_BIT 0x2
|
||||||
|
#define CT_HIDE_FROM_DEBUGGER_BIT 0x4
|
||||||
|
#define CT_ACTIVE_IMPERSTIONATION_INFO_BIT 0x8
|
||||||
|
#define CT_SYSTEM_THREAD_BIT 0x10
|
||||||
|
#define CT_HARD_ERRORS_ARE_DISABLED_BIT 0x20
|
||||||
|
#define CT_BREAK_ON_TERMINATION_BIT 0x40
|
||||||
|
#define CT_SKIP_CREATION_MSG_BIT 0x80
|
||||||
|
#define CT_SKIP_TERMINATION_MSG_BIT 0x100
|
||||||
|
|
||||||
|
//
|
||||||
|
// Same Thread Passive Flags
|
||||||
|
//
|
||||||
|
#define STP_ACTIVE_EX_WORKER_BIT 0x1
|
||||||
|
#define STP_EX_WORKER_CAN_WAIT_USER_BIT 0x2
|
||||||
|
#define STP_MEMORY_MAKER_BIT 0x4
|
||||||
|
#define STP_KEYED_EVENT_IN_USE_BIT 0x8
|
||||||
|
|
||||||
|
//
|
||||||
|
// Same Thread APC Flags
|
||||||
|
//
|
||||||
|
#define STA_LPC_RECEIVED_MSG_ID_VALID_BIT 0x1
|
||||||
|
#define STA_LPC_EXIT_THREAD_CALLED_BIT 0x2
|
||||||
|
#define STA_ADDRESS_SPACE_OWNER_BIT 0x4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NTOS_MODE_USER
|
#ifdef NTOS_MODE_USER
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* FILE: ntoskrnl/ps/thread.c
|
* FILE: ntoskrnl/ps/thread.c
|
||||||
* PURPOSE: Process Manager: Thread Management
|
* PURPOSE: Process Manager: Thread Management
|
||||||
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
||||||
* Thomas Weidenmueller (w3seek@reactos.org
|
* Thomas Weidenmueller (w3seek@reactos.org)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -66,9 +66,9 @@ PspUserThreadStartup(PKSTART_ROUTINE StartRoutine,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if this is a system thread, or if we're hiding */
|
/* Check if this is a system thread, or if we're hiding */
|
||||||
if ((Thread->SystemThread) || (Thread->HideFromDebugger))
|
if (!(Thread->SystemThread) && !(Thread->HideFromDebugger))
|
||||||
{
|
{
|
||||||
/* Notify the debugger */
|
/* We're not, so notify the debugger */
|
||||||
DbgkCreateThread(StartContext);
|
DbgkCreateThread(StartContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,9 +90,9 @@ PspUserThreadStartup(PKSTART_ROUTINE StartRoutine,
|
||||||
sizeof(KTRAP_FRAME) -
|
sizeof(KTRAP_FRAME) -
|
||||||
sizeof(FX_SAVE_AREA)),
|
sizeof(FX_SAVE_AREA)),
|
||||||
PspSystemDllEntryPoint,
|
PspSystemDllEntryPoint,
|
||||||
NULL,
|
NULL,
|
||||||
PspSystemDllBase,
|
PspSystemDllBase,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* Lower it back to passive */
|
/* Lower it back to passive */
|
||||||
KeLowerIrql(PASSIVE_LEVEL);
|
KeLowerIrql(PASSIVE_LEVEL);
|
||||||
|
@ -100,13 +100,21 @@ PspUserThreadStartup(PKSTART_ROUTINE StartRoutine,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* We're dead, kill us now */
|
/* We're dead, kill us now */
|
||||||
PspTerminateThreadByPointer(Thread, STATUS_THREAD_IS_TERMINATING, TRUE);
|
PspTerminateThreadByPointer(Thread,
|
||||||
|
STATUS_THREAD_IS_TERMINATING,
|
||||||
|
TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do we have a cookie set yet? */
|
/* Do we have a cookie set yet? */
|
||||||
if (!SharedUserData->Cookie)
|
if (!SharedUserData->Cookie)
|
||||||
{
|
{
|
||||||
/* FIXME: Generate cookie */
|
/*
|
||||||
|
* FIXME: Generate cookie
|
||||||
|
* Formula (roughly): Per-CPU Page Fault ^ Per-CPU Interrupt Time ^
|
||||||
|
* Global System Time ^ Stack Address of where
|
||||||
|
* the LARGE_INTEGER containing the Global System
|
||||||
|
* Time is.
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +210,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
Status = ObCreateObject(PreviousMode,
|
Status = ObCreateObject(PreviousMode,
|
||||||
PsThreadType,
|
PsThreadType,
|
||||||
ObjectAttributes,
|
ObjectAttributes,
|
||||||
KernelMode,
|
PreviousMode,
|
||||||
NULL,
|
NULL,
|
||||||
sizeof(ETHREAD),
|
sizeof(ETHREAD),
|
||||||
0,
|
0,
|
||||||
|
@ -218,6 +226,9 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
/* Zero the Object entirely */
|
/* Zero the Object entirely */
|
||||||
RtlZeroMemory(Thread, sizeof(ETHREAD));
|
RtlZeroMemory(Thread, sizeof(ETHREAD));
|
||||||
|
|
||||||
|
/* Initialize rundown protection */
|
||||||
|
ExInitializeRundownProtection(&Thread->RundownProtect);
|
||||||
|
|
||||||
/* Set the Process CID */
|
/* Set the Process CID */
|
||||||
Thread->ThreadsProcess = Process;
|
Thread->ThreadsProcess = Process;
|
||||||
Thread->Cid.UniqueProcess = Process->UniqueProcessId;
|
Thread->Cid.UniqueProcess = Process->UniqueProcessId;
|
||||||
|
@ -228,8 +239,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
Thread->Cid.UniqueThread = ExCreateHandle(PspCidTable, &CidEntry);
|
Thread->Cid.UniqueThread = ExCreateHandle(PspCidTable, &CidEntry);
|
||||||
if (!Thread->Cid.UniqueThread)
|
if (!Thread->Cid.UniqueThread)
|
||||||
{
|
{
|
||||||
/* We couldn't create the CID, dereference everything and fail */
|
/* We couldn't create the CID, dereference the thread and fail */
|
||||||
ObDereferenceObject(Process);
|
|
||||||
ObDereferenceObject(Thread);
|
ObDereferenceObject(Thread);
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +248,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
Thread->ReadClusterSize = MmReadClusterSize;
|
Thread->ReadClusterSize = MmReadClusterSize;
|
||||||
|
|
||||||
/* Initialize the LPC Reply Semaphore */
|
/* Initialize the LPC Reply Semaphore */
|
||||||
KeInitializeSemaphore(&Thread->LpcReplySemaphore, 0, MAXLONG);
|
KeInitializeSemaphore(&Thread->LpcReplySemaphore, 0, 1);
|
||||||
|
|
||||||
/* Initialize the list heads and locks */
|
/* Initialize the list heads and locks */
|
||||||
InitializeListHead(&Thread->LpcReplyChain);
|
InitializeListHead(&Thread->LpcReplyChain);
|
||||||
|
@ -247,6 +257,9 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
InitializeListHead(&Thread->ActiveTimerListHead);
|
InitializeListHead(&Thread->ActiveTimerListHead);
|
||||||
KeInitializeSpinLock(&Thread->ActiveTimerListLock);
|
KeInitializeSpinLock(&Thread->ActiveTimerListLock);
|
||||||
|
|
||||||
|
/* Acquire rundown protection */
|
||||||
|
ExAcquireRundownProtection(&Process->RundownProtect);
|
||||||
|
|
||||||
/* Allocate Stack for non-GUI Thread */
|
/* Allocate Stack for non-GUI Thread */
|
||||||
KernelStack = (ULONG_PTR)MmCreateKernelStack(FALSE) + KERNEL_STACK_SIZE;
|
KernelStack = (ULONG_PTR)MmCreateKernelStack(FALSE) + KERNEL_STACK_SIZE;
|
||||||
|
|
||||||
|
@ -255,6 +268,13 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
{
|
{
|
||||||
/* User-mode Thread, create Teb */
|
/* User-mode Thread, create Teb */
|
||||||
TebBase = MmCreateTeb(Process, &Thread->Cid, InitialTeb);
|
TebBase = MmCreateTeb(Process, &Thread->Cid, InitialTeb);
|
||||||
|
if (!TebBase)
|
||||||
|
{
|
||||||
|
/* Failed to create the TEB. Release rundown and dereference */
|
||||||
|
ExReleaseRundownProtection(&Process->RundownProtect);
|
||||||
|
ObDereferenceObject(Thread);
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the Start Addresses */
|
/* Set the Start Addresses */
|
||||||
Thread->StartAddress = (PVOID)ThreadContext->Eip;
|
Thread->StartAddress = (PVOID)ThreadContext->Eip;
|
||||||
|
@ -274,7 +294,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
{
|
{
|
||||||
/* System Thread */
|
/* System Thread */
|
||||||
Thread->StartAddress = StartRoutine;
|
Thread->StartAddress = StartRoutine;
|
||||||
InterlockedOr((PLONG)&Thread->CrossThreadFlags, 0x10);
|
InterlockedOr((PLONG)&Thread->CrossThreadFlags, CT_SYSTEM_THREAD_BIT);
|
||||||
|
|
||||||
/* Let the kernel intialize the Thread */
|
/* Let the kernel intialize the Thread */
|
||||||
KeInitializeThread(&Process->Pcb,
|
KeInitializeThread(&Process->Pcb,
|
||||||
|
@ -295,6 +315,9 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
|
||||||
InsertTailList(&Process->ThreadListHead, &Thread->ThreadListEntry);
|
InsertTailList(&Process->ThreadListHead, &Thread->ThreadListEntry);
|
||||||
Process->ActiveThreads++;
|
Process->ActiveThreads++;
|
||||||
|
|
||||||
|
/* Release rundown */
|
||||||
|
ExReleaseRundownProtection(&Process->RundownProtect);
|
||||||
|
|
||||||
/* Notify WMI */
|
/* Notify WMI */
|
||||||
//WmiTraceProcess(Process, TRUE);
|
//WmiTraceProcess(Process, TRUE);
|
||||||
//WmiTraceThread(Thread, InitialTeb, TRUE);
|
//WmiTraceThread(Thread, InitialTeb, TRUE);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue