- Use safe referencing.
authorAlex Ionescu <aionescu@gmail.com>
Thu, 20 Jul 2006 18:47:35 +0000 (18:47 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Thu, 20 Jul 2006 18:47:35 +0000 (18:47 +0000)
- Fix a bug in PsGetNextProcess(Thread) since we now use safe referencing and the lookup loop can continue.

svn path=/trunk/; revision=23199

reactos/ntoskrnl/KrnlFun.c
reactos/ntoskrnl/include/internal/ob.h
reactos/ntoskrnl/ps/process.c
reactos/ntoskrnl/ps/thread.c

index da04663..948c684 100644 (file)
@@ -27,7 +27,6 @@
 // Ps:\r
 //  - Use Process/Thread Rundown.\r
 //  - Use Process Pushlock Locks.\r
-//  - Use Safe Referencing where needed.\r
 //  - Use Security Locks in security.c\r
 //  - Figure out why processes don't die.\r
 //  - Generate process cookie for user-more thread.\r
index b19d005..3a02158 100644 (file)
@@ -199,6 +199,12 @@ ObReferenceObjectEx(
     IN ULONG Count
 );
 
+BOOLEAN
+FASTCALL
+ObReferenceObjectSafe(
+    IN PVOID Object
+);
+
 VOID
 NTAPI
 ObpReapObject(
index f201c93..735d8c2 100644 (file)
@@ -77,9 +77,12 @@ PsGetNextProcessThread(IN PEPROCESS Process,
         /* Get the Thread */
         FoundThread = CONTAINING_RECORD(Entry, ETHREAD, ThreadListEntry);
 
-        /* Reference the thread. FIXME: Race, use ObSafeReferenceObject */
-        ObReferenceObject(FoundThread);
-        break;
+        /* Safe reference the thread */
+        if (ObReferenceObjectSafe(FoundThread)) break;
+
+        /* Nothing found, keep looping */
+        FoundThread = NULL;
+        Entry = Entry->Flink;
     }
 
     /* Unlock the process */
@@ -123,9 +126,12 @@ PsGetNextProcess(IN PEPROCESS OldProcess)
         /* Get the Thread */
         FoundProcess = CONTAINING_RECORD(Entry, EPROCESS, ActiveProcessLinks);
 
-        /* Reference the thread. FIXME: Race, use ObSafeReferenceObject */
-        ObReferenceObject(FoundProcess);
-        break;
+        /* Reference the process */
+        if (ObReferenceObjectSafe(FoundProcess)) break;
+
+        /* Nothing found, keep trying */
+        FoundProcess = NULL;
+        Entry = Entry->Flink;
     }
 
     /* Release the lock */
@@ -543,10 +549,12 @@ PsLookupProcessByProcessId(IN HANDLE ProcessId,
         /* Make sure it's really a process */
         if (FoundProcess->Pcb.Header.Type == ProcessObject)
         {
-            /* FIXME: Safe Reference and return it */
-            ObReferenceObject(FoundProcess);
-            *Process = FoundProcess;
-            Status = STATUS_SUCCESS;
+            /* Safe Reference and return it */
+            if (ObReferenceObjectSafe(FoundProcess))
+            {
+                *Process = FoundProcess;
+                Status = STATUS_SUCCESS;
+            }
         }
 
         /* Unlock the Entry */
@@ -584,17 +592,19 @@ PsLookupProcessThreadByCid(IN PCLIENT_ID Cid,
         if ((FoundThread->Tcb.DispatcherHeader.Type == ThreadObject) &&
             (FoundThread->Cid.UniqueProcess == Cid->UniqueProcess))
         {
-            /* FIXME: Safe Reference and return it */
-            ObReferenceObject(FoundThread);
-            *Thread = FoundThread;
-            Status = STATUS_SUCCESS;
-
-            /* Check if we should return the Process too */
-            if (Process)
+            /* Safe Reference and return it */
+            if (ObReferenceObjectSafe(FoundThread))
             {
-                /* Return it and reference it */
-                *Process = FoundThread->ThreadsProcess;
-                ObReferenceObject(*Process);
+                *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);
+                }
             }
         }
 
index a663c71..42d3a10 100644 (file)
@@ -436,10 +436,12 @@ PsLookupThreadByThreadId(IN HANDLE ThreadId,
         /* Make sure it's really a process */
         if (FoundThread->Tcb.DispatcherHeader.Type == ThreadObject)
         {
-            /* FIXME: Safe Reference and return it */
-            ObReferenceObject(FoundThread);
-            *Thread = FoundThread;
-            Status = STATUS_SUCCESS;
+            /* Safe Reference and return it */
+            if (ObReferenceObjectSafe(FoundThread))
+            {
+                *Thread = FoundThread;
+                Status = STATUS_SUCCESS;
+            }
         }
 
         /* Unlock the Entry */