diff --git a/reactos/subsys/csrss/api/process.c b/reactos/subsys/csrss/api/process.c index 7a5bd60d846..9ccd15c5508 100644 --- a/reactos/subsys/csrss/api/process.c +++ b/reactos/subsys/csrss/api/process.c @@ -59,6 +59,9 @@ PCSRSS_PROCESS_DATA STDCALL CsrCreateProcessData(HANDLE ProcessId) { ULONG hash; PCSRSS_PROCESS_DATA pProcessData; + OBJECT_ATTRIBUTES ObjectAttributes; + CLIENT_ID ClientId; + NTSTATUS Status; hash = (ULONG_PTR)ProcessId % (sizeof(ProcessData) / sizeof(*ProcessData)); @@ -80,6 +83,27 @@ PCSRSS_PROCESS_DATA STDCALL CsrCreateProcessData(HANDLE ProcessId) pProcessData->ProcessId = ProcessId; pProcessData->next = ProcessData[hash]; ProcessData[hash] = pProcessData; + + ClientId.UniqueThread = NULL; + ClientId.UniqueProcess = pProcessData->ProcessId; + InitializeObjectAttributes(&ObjectAttributes, + NULL, + 0, + NULL, + NULL); + + /* using OpenProcess is not optimal due to HANDLE vs. DWORD PIDs... */ + Status = NtOpenProcess(&pProcessData->Process, + PROCESS_DUP_HANDLE | PROCESS_VM_OPERATION | + PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, + &ObjectAttributes, + &ClientId); + if (!NT_SUCCESS(Status)) + { + ProcessData[hash] = pProcessData->next; + RtlFreeHeap(CsrssApiHeap, 0, pProcessData); + pProcessData = NULL; + } } } else @@ -115,6 +139,10 @@ NTSTATUS STDCALL CsrFreeProcessData(HANDLE Pid) if (pProcessData) { DPRINT("CsrFreeProcessData pid: %d\n", Pid); + if (pProcessData->Process) + { + NtClose(pProcessData->Process); + } if (pProcessData->Console) { RtlEnterCriticalSection(&ProcessDataLock); diff --git a/reactos/subsys/csrss/include/api.h b/reactos/subsys/csrss/include/api.h index eddf4d99198..06b358f5092 100644 --- a/reactos/subsys/csrss/include/api.h +++ b/reactos/subsys/csrss/include/api.h @@ -37,6 +37,7 @@ typedef struct _CSRSS_PROCESS_DATA ULONG HandleTableSize; Object_t ** HandleTable; HANDLE ProcessId; + HANDLE Process; ULONG ShutdownLevel; ULONG ShutdownFlags; HANDLE ConsoleEvent; diff --git a/reactos/subsys/csrss/win32csr/conio.c b/reactos/subsys/csrss/win32csr/conio.c index cffb26cb106..4dfac19dc95 100644 --- a/reactos/subsys/csrss/win32csr/conio.c +++ b/reactos/subsys/csrss/win32csr/conio.c @@ -74,49 +74,22 @@ ConioConsoleFromProcessData(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_CONSOLE *Con VOID FASTCALL ConioConsoleCtrlEvent(DWORD Event, PCSRSS_PROCESS_DATA ProcessData) { - HANDLE Process, Thread; + HANDLE Thread; DPRINT("ConioConsoleCtrlEvent Parent ProcessId = %x\n", ProcessData->ProcessId); if (ProcessData->CtrlDispatcher) { - OBJECT_ATTRIBUTES ObjectAttributes; - CLIENT_ID ClientId; - NTSTATUS Status; - - ClientId.UniqueThread = NULL; - ClientId.UniqueProcess = ProcessData->ProcessId; - InitializeObjectAttributes(&ObjectAttributes, - NULL, - 0, - NULL, - NULL); - /* using OpenProcess is not optimal due to HANDLE vs. DWORD PIDs... */ - Status = NtOpenProcess(&Process, - PROCESS_DUP_HANDLE | PROCESS_VM_OPERATION | - PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, - &ObjectAttributes, - &ClientId); - if (!NT_SUCCESS(Status)) - { - DPRINT1("Failed for handle duplication, Status: 0x%x\n", Status); - return; - } - - DPRINT("ConioConsoleCtrlEvent Process Handle = %x\n", Process); - - Thread = CreateRemoteThread(Process, NULL, 0, + Thread = CreateRemoteThread(ProcessData->Process, NULL, 0, (LPTHREAD_START_ROUTINE) ProcessData->CtrlDispatcher, (PVOID) Event, 0, NULL); if (NULL == Thread) { DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError()); - CloseHandle(Process); return; } CloseHandle(Thread); - CloseHandle(Process); } }