From 83bcad15b20ac812b9a5be930efb28b419853fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Mon, 4 Jul 2016 22:27:35 +0000 Subject: [PATCH] [NTOS] - Document ObKillProcess. - Implement and document ObClearProcessHandleTable (based on ObKillProcess). svn path=/trunk/; revision=71816 --- reactos/ntoskrnl/ob/obhandle.c | 66 ++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/reactos/ntoskrnl/ob/obhandle.c b/reactos/ntoskrnl/ob/obhandle.c index 60b717dd2a6..f53ba783dc7 100644 --- a/reactos/ntoskrnl/ob/obhandle.c +++ b/reactos/ntoskrnl/ob/obhandle.c @@ -2004,17 +2004,69 @@ ObpDuplicateHandleCallback(IN PEPROCESS Process, return Ret; } +/*++ +* @name ObClearProcessHandleTable +* +* The ObClearProcessHandleTable routine clears the handle table +* of the given process. +* +* @param Process +* The process of which the handle table should be cleared. +* +* @return None. +* +* @remarks None. +* +*--*/ VOID NTAPI ObClearProcessHandleTable(IN PEPROCESS Process) { - /* FIXME */ + PHANDLE_TABLE HandleTable; + OBP_CLOSE_HANDLE_CONTEXT Context; + KAPC_STATE ApcState; + BOOLEAN AttachedToProcess = FALSE; + + ASSERT(Process); + + /* Ensure the handle table doesn't go away while we use it */ + HandleTable = ObReferenceProcessHandleTable(Process); + if (!HandleTable) return; + + /* Attach to the current process if needed */ + if (PsGetCurrentProcess() != Process) + { + KeStackAttachProcess(&Process->Pcb, &ApcState); + AttachedToProcess = TRUE; + } + + /* Enter a critical region */ + KeEnterCriticalRegion(); + + /* Fill out the context */ + Context.AccessMode = UserMode; + Context.HandleTable = HandleTable; + + /* Sweep the handle table to close all handles */ + ExSweepHandleTable(HandleTable, + ObpCloseHandleCallback, + &Context); + + /* Leave the critical region */ + KeLeaveCriticalRegion(); + + /* Detach if needed */ + if (AttachedToProcess) + KeUnstackDetachProcess(&ApcState); + + /* Let the handle table go */ + ObDereferenceProcessHandleTable(Process); } /*++ -* @name ObpCreateHandleTable +* @name ObInitProcess * -* The ObpCreateHandleTable routine +* The ObInitProcess routine * * @param Parent * . @@ -2085,14 +2137,16 @@ ObInitProcess(IN PEPROCESS Parent OPTIONAL, /*++ * @name ObKillProcess * -* The ObKillProcess routine +* The ObKillProcess routine performs rundown operations on the process, +* then clears and destroys its handle table. * * @param Process -* . +* The process to be killed. * * @return None. * -* @remarks None. +* @remarks Called by the Object Manager cleanup code (kernel) +* when a process is to be destroyed. * *--*/ VOID