[WIN32CSR] Make CsrFreeConsole close the process's console handles.
authorJeffrey Morlan <mrnobo1024@yahoo.com>
Sat, 22 May 2010 21:40:20 +0000 (21:40 +0000)
committerJeffrey Morlan <mrnobo1024@yahoo.com>
Sat, 22 May 2010 21:40:20 +0000 (21:40 +0000)
svn path=/trunk/; revision=47313

reactos/subsystems/win32/csrss/csrsrv/api/handle.c
reactos/subsystems/win32/csrss/csrsrv/api/process.c
reactos/subsystems/win32/csrss/csrsrv/init.c
reactos/subsystems/win32/csrss/include/api.h
reactos/subsystems/win32/csrss/include/csrplugin.h
reactos/subsystems/win32/csrss/include/win32csr.h
reactos/subsystems/win32/csrss/win32csr/conio.c
reactos/subsystems/win32/csrss/win32csr/dllmain.c

index eb6c12c..6567f89 100644 (file)
@@ -146,6 +146,45 @@ CsrReleaseObject(
     return CsrReleaseObjectByPointer(Object);
 }
 
+NTSTATUS
+WINAPI
+CsrReleaseConsole(
+    PCSRSS_PROCESS_DATA ProcessData)
+{
+    ULONG HandleTableSize;
+    PCSRSS_HANDLE HandleTable;
+    PCSRSS_CONSOLE Console;
+    ULONG i;
+
+    /* Close all console handles and detach process from console */
+    RtlEnterCriticalSection(&ProcessData->HandleTableLock);
+    HandleTableSize = ProcessData->HandleTableSize;
+    HandleTable = ProcessData->HandleTable;
+    Console = ProcessData->Console;
+    ProcessData->HandleTableSize = 0;
+    ProcessData->HandleTable = NULL;
+    ProcessData->Console = NULL;
+    RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
+
+    for (i = 0; i < HandleTableSize; i++)
+    {
+        if (HandleTable[i].Object != NULL)
+            CsrReleaseObjectByPointer(HandleTable[i].Object);
+    }
+    RtlFreeHeap(CsrssApiHeap, 0, HandleTable);
+
+    if (Console != NULL)
+    {
+        RtlEnterCriticalSection((PRTL_CRITICAL_SECTION)&Console->Header.Lock);
+        RemoveEntryList(&ProcessData->ProcessEntry);
+        RtlLeaveCriticalSection((PRTL_CRITICAL_SECTION)&Console->Header.Lock);
+        CsrReleaseObjectByPointer(&Console->Header);
+        return STATUS_SUCCESS;
+    }
+
+    return STATUS_INVALID_PARAMETER;
+}
+
 NTSTATUS
 WINAPI
 CsrInsertObject(
index 5fcac04..580cb21 100644 (file)
@@ -140,7 +140,6 @@ PCSRSS_PROCESS_DATA WINAPI CsrCreateProcessData(HANDLE ProcessId)
 NTSTATUS WINAPI CsrFreeProcessData(HANDLE Pid)
 {
   ULONG hash;
-  UINT c;
   PCSRSS_PROCESS_DATA pProcessData, *pPrevLink;
   HANDLE Process;
 
@@ -158,23 +157,7 @@ NTSTATUS WINAPI CsrFreeProcessData(HANDLE Pid)
     {
       DPRINT("CsrFreeProcessData pid: %d\n", Pid);
       Process = pProcessData->Process;
-      if (pProcessData->HandleTable)
-        {
-          for (c = 0; c < pProcessData->HandleTableSize; c++)
-            {
-              if (pProcessData->HandleTable[c].Object)
-                {
-                  CsrReleaseObjectByPointer(pProcessData->HandleTable[c].Object);
-                }
-            }
-          RtlFreeHeap(CsrssApiHeap, 0, pProcessData->HandleTable);
-        }
-      RtlDeleteCriticalSection(&pProcessData->HandleTableLock);
-      if (pProcessData->Console)
-        {
-          RemoveEntryList(&pProcessData->ProcessEntry);
-          CsrReleaseObjectByPointer((Object_t *) pProcessData->Console);
-        }
+      CsrReleaseConsole(pProcessData);
       if (pProcessData->CsrSectionViewBase)
         {
           NtUnmapViewOfSection(NtCurrentProcess(), pProcessData->CsrSectionViewBase);
index 51adb2c..a507628 100644 (file)
@@ -335,6 +335,7 @@ CsrpInitWin32Csr (int argc, char ** argv, char ** envp)
   Exports.CsrGetObjectProc = CsrGetObject;
   Exports.CsrReleaseObjectByPointerProc = CsrReleaseObjectByPointer;
   Exports.CsrReleaseObjectProc = CsrReleaseObject;
+  Exports.CsrReleaseConsoleProc = CsrReleaseConsole;
   Exports.CsrEnumProcessesProc = CsrEnumProcesses;
   if (! (*InitProc)(&ApiDefinitions, &ObjectDefinitions, &InitCompleteProc,
                     &HardErrorProc, &Exports, CsrssApiHeap))
index 7fbf6db..444cee7 100644 (file)
@@ -193,6 +193,7 @@ NTSTATUS WINAPI CsrGetObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Handle, Ob
 NTSTATUS NTAPI CsrServerInitialization(ULONG ArgumentCount, PCHAR Arguments[]);
 NTSTATUS WINAPI CsrReleaseObjectByPointer(Object_t *Object);
 NTSTATUS WINAPI CsrReleaseObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Object );
+NTSTATUS WINAPI CsrReleaseConsole(PCSRSS_PROCESS_DATA ProcessData);
 NTSTATUS WINAPI CsrVerifyObject( PCSRSS_PROCESS_DATA ProcessData, HANDLE Object );
 
 //hack
index 357b65b..24c0c7d 100644 (file)
@@ -33,6 +33,7 @@ typedef NTSTATUS (WINAPI *CSRSS_GET_OBJECT_PROC)(PCSRSS_PROCESS_DATA ProcessData
 typedef NTSTATUS (WINAPI *CSRSS_RELEASE_OBJECT_BY_POINTER_PROC)(Object_t *Object);
 typedef NTSTATUS (WINAPI *CSRSS_RELEASE_OBJECT_PROC)(PCSRSS_PROCESS_DATA ProcessData,
                                                       HANDLE Object );
+typedef NTSTATUS (WINAPI *CSRSS_RELEASE_CONSOLE_PROC)(PCSRSS_PROCESS_DATA ProcessData);
 typedef NTSTATUS (WINAPI *CSRSS_ENUM_PROCESSES_PROC)(CSRSS_ENUM_PROCESS_PROC EnumProc,
                                                       PVOID Context);
 
@@ -42,6 +43,7 @@ typedef struct tagCSRSS_EXPORTED_FUNCS
   CSRSS_GET_OBJECT_PROC CsrGetObjectProc;
   CSRSS_RELEASE_OBJECT_BY_POINTER_PROC CsrReleaseObjectByPointerProc;
   CSRSS_RELEASE_OBJECT_PROC CsrReleaseObjectProc;
+  CSRSS_RELEASE_CONSOLE_PROC CsrReleaseConsoleProc;
   CSRSS_ENUM_PROCESSES_PROC CsrEnumProcessesProc;
 } CSRSS_EXPORTED_FUNCS, *PCSRSS_EXPORTED_FUNCS;
 
index 6b7791f..4b5ab47 100644 (file)
@@ -33,6 +33,7 @@ NTSTATUS FASTCALL Win32CsrGetObject(PCSRSS_PROCESS_DATA ProcessData,
 NTSTATUS FASTCALL Win32CsrReleaseObjectByPointer(Object_t *Object);
 NTSTATUS FASTCALL Win32CsrReleaseObject(PCSRSS_PROCESS_DATA ProcessData,
                                         HANDLE Object);
+NTSTATUS FASTCALL Win32CsrReleaseConsole(PCSRSS_PROCESS_DATA ProcessData);
 NTSTATUS FASTCALL Win32CsrEnumProcesses(CSRSS_ENUM_PROCESS_PROC EnumProc,
                                         PVOID Context);
 
index 493ac17..5aa5cf8 100644 (file)
@@ -369,25 +369,10 @@ CSR_API(CsrAllocConsole)
 
 CSR_API(CsrFreeConsole)
 {
-  PCSRSS_CONSOLE Console;
-
-
   Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
   Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
 
-  if (ProcessData->Console == NULL)
-    {
-      return STATUS_INVALID_PARAMETER;
-    }
-
-  Console = ProcessData->Console;
-  ProcessData->Console = NULL;
-  RemoveEntryList(&ProcessData->ProcessEntry);
-  if (0 == InterlockedDecrement(&Console->Header.ReferenceCount))
-    {
-      ConioDeleteConsole((Object_t *) Console);
-    }
-  return STATUS_SUCCESS;
+  return Win32CsrReleaseConsole(ProcessData);
 }
 
 static VOID FASTCALL
index f8332a7..5248663 100644 (file)
@@ -166,6 +166,12 @@ Win32CsrReleaseObject(PCSRSS_PROCESS_DATA ProcessData,
   return (CsrExports.CsrReleaseObjectProc)(ProcessData, Object);
 }
 
+NTSTATUS FASTCALL
+Win32CsrReleaseConsole(PCSRSS_PROCESS_DATA ProcessData)
+{
+  return (CsrExports.CsrReleaseConsoleProc)(ProcessData);
+}
+
 NTSTATUS FASTCALL
 Win32CsrEnumProcesses(CSRSS_ENUM_PROCESS_PROC EnumProc,
                       PVOID Context)