Author: ion Date: Thu Jul 20 22:47:35 2006 New Revision: 23199
URL: http://svn.reactos.org/svn/reactos?rev=23199&view=rev Log: - Use safe referencing. - Fix a bug in PsGetNextProcess(Thread) since we now use safe referencing and the lookup loop can continue.
Modified: trunk/reactos/ntoskrnl/KrnlFun.c trunk/reactos/ntoskrnl/include/internal/ob.h trunk/reactos/ntoskrnl/ps/process.c trunk/reactos/ntoskrnl/ps/thread.c
Modified: trunk/reactos/ntoskrnl/KrnlFun.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/KrnlFun.c?rev=2319... ============================================================================== --- trunk/reactos/ntoskrnl/KrnlFun.c (original) +++ trunk/reactos/ntoskrnl/KrnlFun.c Thu Jul 20 22:47:35 2006 @@ -27,7 +27,6 @@ // Ps: // - Use Process/Thread Rundown. // - Use Process Pushlock Locks. -// - Use Safe Referencing where needed. // - Use Security Locks in security.c // - Figure out why processes don't die. // - Generate process cookie for user-more thread.
Modified: trunk/reactos/ntoskrnl/include/internal/ob.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/o... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ob.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ob.h Thu Jul 20 22:47:35 2006 @@ -199,6 +199,12 @@ IN ULONG Count );
+BOOLEAN +FASTCALL +ObReferenceObjectSafe( + IN PVOID Object +); + VOID NTAPI ObpReapObject(
Modified: trunk/reactos/ntoskrnl/ps/process.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/process.c?rev=2... ============================================================================== --- trunk/reactos/ntoskrnl/ps/process.c (original) +++ trunk/reactos/ntoskrnl/ps/process.c Thu Jul 20 22:47:35 2006 @@ -77,9 +77,12 @@ /* 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 @@ /* 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 @@ /* 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 @@ 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); + } } }
Modified: trunk/reactos/ntoskrnl/ps/thread.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/thread.c?rev=23... ============================================================================== --- trunk/reactos/ntoskrnl/ps/thread.c (original) +++ trunk/reactos/ntoskrnl/ps/thread.c Thu Jul 20 22:47:35 2006 @@ -436,10 +436,12 @@ /* 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 */