diff --git a/reactos/ntoskrnl/include/internal/ps.h b/reactos/ntoskrnl/include/internal/ps.h
index 12f4f13f398..ccee3e26390 100644
--- a/reactos/ntoskrnl/include/internal/ps.h
+++ b/reactos/ntoskrnl/include/internal/ps.h
@@ -216,10 +216,6 @@ PspGetSystemDllEntryPoints(VOID);
/* CLIENT ID */
-NTSTATUS PsCreateCidHandle(PVOID Object, POBJECT_TYPE ObjectType, PHANDLE Handle);
-NTSTATUS PsDeleteCidHandle(HANDLE CidHandle, POBJECT_TYPE ObjectType);
-PHANDLE_TABLE_ENTRY PsLookupCidHandle(HANDLE CidHandle, POBJECT_TYPE ObjectType, PVOID *Object);
-VOID PsUnlockCidHandle(PHANDLE_TABLE_ENTRY CidEntry);
NTSTATUS PsLockProcess(PEPROCESS Process, BOOLEAN Timeout);
VOID PsUnlockProcess(PEPROCESS Process);
diff --git a/reactos/ntoskrnl/ntoskrnl.xml b/reactos/ntoskrnl/ntoskrnl.xml
index a3416ec5383..4b347b884c6 100644
--- a/reactos/ntoskrnl/ntoskrnl.xml
+++ b/reactos/ntoskrnl/ntoskrnl.xml
@@ -290,7 +290,6 @@
continue.c
- cid.c
debug.c
idle.c
job.c
diff --git a/reactos/ntoskrnl/ps/cid.c b/reactos/ntoskrnl/ps/cid.c
index 935ca8ff495..dfd3b1df0dc 100644
--- a/reactos/ntoskrnl/ps/cid.c
+++ b/reactos/ntoskrnl/ps/cid.c
@@ -18,117 +18,16 @@
PHANDLE_TABLE PspCidTable = NULL;
-#define CID_FLAG_PROCESS 0x1
-#define CID_FLAG_THREAD 0x2
-#define CID_FLAGS_MASK (CID_FLAG_PROCESS | CID_FLAG_THREAD)
-
/* FUNCTIONS *****************************************************************/
-VOID INIT_FUNCTION
+VOID
+INIT_FUNCTION
PsInitClientIDManagment(VOID)
{
PspCidTable = ExCreateHandleTable(NULL);
ASSERT(PspCidTable);
}
-NTSTATUS
-PsCreateCidHandle(PVOID Object, POBJECT_TYPE ObjectType, PHANDLE Handle)
-{
- HANDLE_TABLE_ENTRY NewEntry;
- LONG ExHandle;
-
- PAGED_CODE();
-
- NewEntry.u1.Object = Object;
- if(ObjectType == PsThreadType)
- NewEntry.u2.GrantedAccess = CID_FLAG_THREAD;
- else if(ObjectType == PsProcessType)
- NewEntry.u2.GrantedAccess = CID_FLAG_PROCESS;
- else
- {
- DPRINT1("Can't create CID handles for %wZ objects\n", &ObjectType->Name);
- KEBUGCHECK(0);
- }
-
- ExHandle = ExCreateHandle(PspCidTable,
- &NewEntry);
- if(ExHandle != EX_INVALID_HANDLE)
- {
- *Handle = EX_HANDLE_TO_HANDLE(ExHandle);
- return STATUS_SUCCESS;
- }
-
- return STATUS_UNSUCCESSFUL;
-}
-
-NTSTATUS
-PsDeleteCidHandle(HANDLE CidHandle, POBJECT_TYPE ObjectType)
-{
- PHANDLE_TABLE_ENTRY Entry;
- LONG ExHandle = HANDLE_TO_EX_HANDLE(CidHandle);
-
- PAGED_CODE();
-
- KeEnterCriticalRegion();
-
- Entry = ExMapHandleToPointer(PspCidTable,
- ExHandle);
- if(Entry != NULL)
- {
- if((ObjectType == PsThreadType && ((Entry->u2.GrantedAccess & CID_FLAGS_MASK) == CID_FLAG_THREAD)) ||
- (ObjectType == PsProcessType && ((Entry->u2.GrantedAccess & CID_FLAGS_MASK) == CID_FLAG_PROCESS)))
- {
- ExDestroyHandleByEntry(PspCidTable,
- Entry,
- ExHandle);
- KeLeaveCriticalRegion();
- return STATUS_SUCCESS;
- }
- else
- {
- ExUnlockHandleTableEntry(PspCidTable,
- Entry);
- KeLeaveCriticalRegion();
- return STATUS_OBJECT_TYPE_MISMATCH;
- }
- }
- KeLeaveCriticalRegion();
- return STATUS_INVALID_HANDLE;
-}
-
-PHANDLE_TABLE_ENTRY
-PsLookupCidHandle(HANDLE CidHandle, POBJECT_TYPE ObjectType, PVOID *Object)
-{
- PHANDLE_TABLE_ENTRY Entry;
-
- PAGED_CODE();
-
- KeEnterCriticalRegion();
-
- Entry = ExMapHandleToPointer(PspCidTable,
- HANDLE_TO_EX_HANDLE(CidHandle));
- if(Entry != NULL)
- {
- if((ObjectType == PsProcessType && ((Entry->u2.GrantedAccess & CID_FLAGS_MASK) == CID_FLAG_PROCESS)) ||
- (ObjectType == PsThreadType && ((Entry->u2.GrantedAccess & CID_FLAGS_MASK) == CID_FLAG_THREAD)))
- {
- *Object = Entry->u1.Object;
- return Entry;
- }
- else
- {
- DPRINT1("CID Obj type mismatch handle 0x%x %wZ vs 0x%x\n", CidHandle,
- &ObjectType->Name, Entry->u2.GrantedAccess);
- ExUnlockHandleTableEntry(PspCidTable,
- Entry);
- }
- }
-
- KeLeaveCriticalRegion();
-
- return NULL;
-}
-
/*
* @implemented
*/
diff --git a/reactos/ntoskrnl/ps/kill.c b/reactos/ntoskrnl/ps/kill.c
index ca28ec73e4f..a4f2e7be68f 100644
--- a/reactos/ntoskrnl/ps/kill.c
+++ b/reactos/ntoskrnl/ps/kill.c
@@ -21,6 +21,7 @@ WORK_QUEUE_ITEM PspReaperWorkItem;
BOOLEAN PspReaping = FALSE;
extern LIST_ENTRY PsActiveProcessHead;
extern FAST_MUTEX PspActiveProcessMutex;
+extern PHANDLE_TABLE PspCidTable;
/* FUNCTIONS *****************************************************************/
@@ -153,9 +154,9 @@ PspDeleteProcess(PVOID ObjectBody)
ExReleaseFastMutex(&PspActiveProcessMutex);
/* Delete the CID Handle */
- if(Process->UniqueProcessId != NULL) {
-
- PsDeleteCidHandle(Process->UniqueProcessId, PsProcessType);
+ if(Process->UniqueProcessId)
+ {
+ ExDestroyHandle(PspCidTable, Process->UniqueProcessId);
}
/* KDB hook */
@@ -184,9 +185,9 @@ PspDeleteThread(PVOID ObjectBody)
Thread->ThreadsProcess = NULL;
/* Delete the CID Handle */
- if(Thread->Cid.UniqueThread != NULL) {
-
- PsDeleteCidHandle(Thread->Cid.UniqueThread, PsThreadType);
+ if(Thread->Cid.UniqueThread)
+ {
+ ExDestroyHandle(PspCidTable, Thread->Cid.UniqueThread);
}
/* Free the W32THREAD structure if present */
diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c
index 06de86f6f65..f71343c07d4 100644
--- a/reactos/ntoskrnl/ps/process.c
+++ b/reactos/ntoskrnl/ps/process.c
@@ -19,6 +19,7 @@
PEPROCESS EXPORTED PsInitialSystemProcess = NULL;
PEPROCESS PsIdleProcess = NULL;
POBJECT_TYPE EXPORTED PsProcessType = NULL;
+extern PHANDLE_TABLE PspCidTable;
EPROCESS_QUOTA_BLOCK PspDefaultQuotaBlock;
@@ -189,6 +190,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
PHYSICAL_ADDRESS DirectoryTableBase;
KAFFINITY Affinity;
+ HANDLE_TABLE_ENTRY CidEntry;
DirectoryTableBase.QuadPart = (ULONGLONG)0;
DPRINT("PspCreateProcess(ObjectAttributes %x)\n", ObjectAttributes);
@@ -362,13 +364,13 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
/* Create a handle for the Process */
DPRINT("Initialzing Process CID Handle\n");
- Status = PsCreateCidHandle(Process,
- PsProcessType,
- &Process->UniqueProcessId);
+ CidEntry.u1.Object = Process;
+ CidEntry.u2.GrantedAccess = 0;
+ Process->UniqueProcessId = (ExCreateHandle(PspCidTable, &CidEntry));
DPRINT("Created CID: %d\n", Process->UniqueProcessId);
- if(!NT_SUCCESS(Status))
+ if(!Process->UniqueProcessId)
{
- DPRINT1("Failed to create CID handle (unique process ID)! Status: 0x%x\n", Status);
+ DPRINT1("Failed to create CID handle\n");
ObDereferenceObject(Process);
goto exitdereferenceobjects;
}
@@ -471,25 +473,80 @@ STDCALL
PsLookupProcessByProcessId(IN HANDLE ProcessId,
OUT PEPROCESS *Process)
{
- PHANDLE_TABLE_ENTRY CidEntry;
- PEPROCESS FoundProcess;
+ PHANDLE_TABLE_ENTRY CidEntry;
+ PEPROCESS FoundProcess;
+ NTSTATUS Status = STATUS_INVALID_PARAMETER;
+ PAGED_CODE();
- PAGED_CODE();
+ /* Get the CID Handle Entry */
+ if (!(CidEntry = ExMapHandleToPointer(PspCidTable,
+ HANDLE_TO_EX_HANDLE(ProcessId))))
+ {
+ /* Get the Process */
+ FoundProcess = CidEntry->u1.Object;
- ASSERT(Process);
+ /* Make sure it's really a process */
+ if (FoundProcess->Pcb.Header.Type == ProcessObject)
+ {
+ /* Reference and return it */
+ ObReferenceObject(FoundProcess);
+ *Process = FoundProcess;
+ Status = STATUS_SUCCESS;
+ }
- CidEntry = PsLookupCidHandle(ProcessId, PsProcessType, (PVOID*)&FoundProcess);
- if(CidEntry != NULL)
- {
- ObReferenceObject(FoundProcess);
-
- PsUnlockCidHandle(CidEntry);
-
- *Process = FoundProcess;
- return STATUS_SUCCESS;
+ /* Unlock the Entry */
+ ExUnlockHandleTableEntry(PspCidTable, CidEntry);
}
- return STATUS_INVALID_PARAMETER;
+ /* Return to caller */
+ return Status;
+}
+
+/*
+ * @implemented
+ */
+NTSTATUS
+STDCALL
+PsLookupProcessThreadByCid(IN PCLIENT_ID Cid,
+ OUT PEPROCESS *Process OPTIONAL,
+ OUT PETHREAD *Thread)
+{
+ PHANDLE_TABLE_ENTRY CidEntry;
+ PETHREAD FoundThread;
+ NTSTATUS Status = STATUS_INVALID_PARAMETER;
+ PAGED_CODE();
+
+ /* Get the CID Handle Entry */
+ if (!(CidEntry = ExMapHandleToPointer(PspCidTable,
+ HANDLE_TO_EX_HANDLE(Cid->UniqueThread))))
+ {
+ /* Get the Process */
+ FoundThread = CidEntry->u1.Object;
+
+ /* Make sure it's really a thread and this process' */
+ if ((FoundThread->Tcb.DispatcherHeader.Type == ThreadObject) &&
+ (FoundThread->Cid.UniqueProcess == Cid->UniqueProcess))
+ {
+ /* Reference and return it */
+ ObReferenceObject(FoundThread);
+ *Thread = FoundThread;
+ Status = STATUS_SUCCESS;
+
+ /* Check if we should return the Process too */
+ if (Process)
+ {
+ /* Return it and reference it */
+ *Process = FoundThread->ThreadsProcess;
+ ObReferenceObject(*Process);
+ }
+ }
+
+ /* Unlock the Entry */
+ ExUnlockHandleTableEntry(PspCidTable, CidEntry);
+ }
+
+ /* Return to caller */
+ return Status;
}
/*
diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c
index f234c20ef4e..a384db69d49 100644
--- a/reactos/ntoskrnl/ps/psmgr.c
+++ b/reactos/ntoskrnl/ps/psmgr.c
@@ -44,11 +44,7 @@ extern PVOID KeRaiseUserExceptionDispatcher;
PVOID PspSystemDllBase = NULL;
PVOID PspSystemDllSection = NULL;
PVOID PspSystemDllEntryPoint = NULL;
-
-VOID
-INIT_FUNCTION
-PsInitClientIDManagment(VOID);
-
+PHANDLE_TABLE PspCidTable = NULL;
VOID STDCALL PspKillMostProcesses();
/* FUNCTIONS ***************************************************************/
@@ -70,6 +66,14 @@ PiInitProcessManager(VOID)
PsInitialiseW32Call();
}
+VOID
+INIT_FUNCTION
+PsInitClientIDManagment(VOID)
+{
+ PspCidTable = ExCreateHandleTable(NULL);
+ ASSERT(PspCidTable);
+}
+
VOID
INIT_FUNCTION
PsInitThreadManagment(VOID)
@@ -261,7 +265,7 @@ PsInitProcessManagment(VOID)
VOID
PspPostInitSystemProcess(VOID)
{
- NTSTATUS Status;
+ HANDLE_TABLE_ENTRY CidEntry;
/* this routine is called directly after the exectuive handle tables were
initialized. We'll set up the Client ID handle table and assign the system
@@ -271,10 +275,11 @@ PspPostInitSystemProcess(VOID)
ObCreateHandleTable(NULL, FALSE, PsInitialSystemProcess);
ObpKernelHandleTable = PsInitialSystemProcess->ObjectTable;
- Status = PsCreateCidHandle(PsInitialSystemProcess,
- PsProcessType,
- &PsInitialSystemProcess->UniqueProcessId);
- if(!NT_SUCCESS(Status))
+ CidEntry.u1.Object = PsInitialSystemProcess;
+ CidEntry.u2.GrantedAccess = 0;
+ PsInitialSystemProcess->UniqueProcessId = ExCreateHandle(PspCidTable, &CidEntry);
+
+ if(!PsInitialSystemProcess->UniqueProcessId)
{
DPRINT1("Failed to create CID handle (unique process id) for the system process!\n");
KEBUGCHECK(0);
diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c
index 3838dfd1bd3..04f2fd8777a 100644
--- a/reactos/ntoskrnl/ps/thread.c
+++ b/reactos/ntoskrnl/ps/thread.c
@@ -19,6 +19,7 @@
extern LIST_ENTRY PsActiveProcessHead;
extern PEPROCESS PsIdleProcess;
extern PVOID PspSystemDllEntryPoint;
+extern PHANDLE_TABLE PspCidTable;
POBJECT_TYPE EXPORTED PsThreadType = NULL;
@@ -114,6 +115,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
KIRQL OldIrql;
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
NTSTATUS Status;
+ HANDLE_TABLE_ENTRY CidEntry;
PVOID KernelStack;
/* Reference the Process by handle or pointer, depending on what we got */
@@ -180,12 +182,15 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
/* Create Cid Handle */
DPRINT("Creating Thread Handle (CID)\n");
- if (!(NT_SUCCESS(PsCreateCidHandle(Thread, PsThreadType, &Thread->Cid.UniqueThread)))) {
+ CidEntry.u1.Object = Thread;
+ CidEntry.u2.GrantedAccess = 0;
+ Thread->Cid.UniqueThread = ExCreateHandle(PspCidTable, &CidEntry);
+ if (!Thread->Cid.UniqueThread) {
DPRINT1("Failed to create Thread Handle (CID)\n");
ObDereferenceObject(Process);
ObDereferenceObject(Thread);
- return Status;
+ return STATUS_INSUFFICIENT_RESOURCES;
}
/* Initialize Lists */
@@ -357,6 +362,43 @@ PsCreateSystemThread(PHANDLE ThreadHandle,
StartContext);
}
+/*
+ * @implemented
+ */
+NTSTATUS
+STDCALL
+PsLookupThreadByThreadId(IN HANDLE ThreadId,
+ OUT PETHREAD *Thread)
+{
+ PHANDLE_TABLE_ENTRY CidEntry;
+ PETHREAD FoundThread;
+ NTSTATUS Status = STATUS_INVALID_PARAMETER;
+ PAGED_CODE();
+
+ /* Get the CID Handle Entry */
+ if (!(CidEntry = ExMapHandleToPointer(PspCidTable,
+ HANDLE_TO_EX_HANDLE(ThreadId))))
+ {
+ /* Get the Process */
+ FoundThread = CidEntry->u1.Object;
+
+ /* Make sure it's really a process */
+ if (FoundThread->Tcb.DispatcherHeader.Type == ThreadObject)
+ {
+ /* Reference and return it */
+ ObReferenceObject(FoundThread);
+ *Thread = FoundThread;
+ Status = STATUS_SUCCESS;
+ }
+
+ /* Unlock the Entry */
+ ExUnlockHandleTableEntry(PspCidTable, CidEntry);
+ }
+
+ /* Return to caller */
+ return Status;
+}
+
/*
* @implemented
*/