mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +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;
|
ULONG hash;
|
||||||
PCSRSS_PROCESS_DATA pProcessData;
|
PCSRSS_PROCESS_DATA pProcessData;
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
CLIENT_ID ClientId;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
hash = (ULONG_PTR)ProcessId % (sizeof(ProcessData) / sizeof(*ProcessData));
|
hash = (ULONG_PTR)ProcessId % (sizeof(ProcessData) / sizeof(*ProcessData));
|
||||||
|
|
||||||
|
@ -80,6 +83,27 @@ PCSRSS_PROCESS_DATA STDCALL CsrCreateProcessData(HANDLE ProcessId)
|
||||||
pProcessData->ProcessId = ProcessId;
|
pProcessData->ProcessId = ProcessId;
|
||||||
pProcessData->next = ProcessData[hash];
|
pProcessData->next = ProcessData[hash];
|
||||||
ProcessData[hash] = pProcessData;
|
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
|
else
|
||||||
|
@ -115,6 +139,10 @@ NTSTATUS STDCALL CsrFreeProcessData(HANDLE Pid)
|
||||||
if (pProcessData)
|
if (pProcessData)
|
||||||
{
|
{
|
||||||
DPRINT("CsrFreeProcessData pid: %d\n", Pid);
|
DPRINT("CsrFreeProcessData pid: %d\n", Pid);
|
||||||
|
if (pProcessData->Process)
|
||||||
|
{
|
||||||
|
NtClose(pProcessData->Process);
|
||||||
|
}
|
||||||
if (pProcessData->Console)
|
if (pProcessData->Console)
|
||||||
{
|
{
|
||||||
RtlEnterCriticalSection(&ProcessDataLock);
|
RtlEnterCriticalSection(&ProcessDataLock);
|
||||||
|
|
|
@ -37,6 +37,7 @@ typedef struct _CSRSS_PROCESS_DATA
|
||||||
ULONG HandleTableSize;
|
ULONG HandleTableSize;
|
||||||
Object_t ** HandleTable;
|
Object_t ** HandleTable;
|
||||||
HANDLE ProcessId;
|
HANDLE ProcessId;
|
||||||
|
HANDLE Process;
|
||||||
ULONG ShutdownLevel;
|
ULONG ShutdownLevel;
|
||||||
ULONG ShutdownFlags;
|
ULONG ShutdownFlags;
|
||||||
HANDLE ConsoleEvent;
|
HANDLE ConsoleEvent;
|
||||||
|
|
|
@ -74,49 +74,22 @@ ConioConsoleFromProcessData(PCSRSS_PROCESS_DATA ProcessData, PCSRSS_CONSOLE *Con
|
||||||
VOID FASTCALL
|
VOID FASTCALL
|
||||||
ConioConsoleCtrlEvent(DWORD Event, PCSRSS_PROCESS_DATA ProcessData)
|
ConioConsoleCtrlEvent(DWORD Event, PCSRSS_PROCESS_DATA ProcessData)
|
||||||
{
|
{
|
||||||
HANDLE Process, Thread;
|
HANDLE Thread;
|
||||||
|
|
||||||
DPRINT("ConioConsoleCtrlEvent Parent ProcessId = %x\n", ProcessData->ProcessId);
|
DPRINT("ConioConsoleCtrlEvent Parent ProcessId = %x\n", ProcessData->ProcessId);
|
||||||
|
|
||||||
if (ProcessData->CtrlDispatcher)
|
if (ProcessData->CtrlDispatcher)
|
||||||
{
|
{
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
||||||
CLIENT_ID ClientId;
|
|
||||||
NTSTATUS Status;
|
|
||||||
|
|
||||||
ClientId.UniqueThread = NULL;
|
Thread = CreateRemoteThread(ProcessData->Process, NULL, 0,
|
||||||
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,
|
|
||||||
(LPTHREAD_START_ROUTINE) ProcessData->CtrlDispatcher,
|
(LPTHREAD_START_ROUTINE) ProcessData->CtrlDispatcher,
|
||||||
(PVOID) Event, 0, NULL);
|
(PVOID) Event, 0, NULL);
|
||||||
if (NULL == Thread)
|
if (NULL == Thread)
|
||||||
{
|
{
|
||||||
DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError());
|
DPRINT1("Failed thread creation (Error: 0x%x)\n", GetLastError());
|
||||||
CloseHandle(Process);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CloseHandle(Thread);
|
CloseHandle(Thread);
|
||||||
CloseHandle(Process);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue