mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
Since a process id is only unique if the associated process is not deleted,
we must prevent the deleting of the process. An opened handle does this. svn path=/trunk/; revision=14475
This commit is contained in:
parent
938d6d1baf
commit
7f6485630b
3 changed files with 31 additions and 29 deletions
|
@ -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);
|
||||
|
|
|
@ -37,6 +37,7 @@ typedef struct _CSRSS_PROCESS_DATA
|
|||
ULONG HandleTableSize;
|
||||
Object_t ** HandleTable;
|
||||
HANDLE ProcessId;
|
||||
HANDLE Process;
|
||||
ULONG ShutdownLevel;
|
||||
ULONG ShutdownFlags;
|
||||
HANDLE ConsoleEvent;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue