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.
Modified: trunk/reactos/subsys/csrss/api/process.c
Modified: trunk/reactos/subsys/csrss/include/api.h
Modified: trunk/reactos/subsys/csrss/win32csr/conio.c
_____
Modified: trunk/reactos/subsys/csrss/api/process.c
--- trunk/reactos/subsys/csrss/api/process.c 2005-04-03 12:49:25 UTC
(rev 14474)
+++ trunk/reactos/subsys/csrss/api/process.c 2005-04-03 13:04:10 UTC
(rev 14475)
@@ -59,6 +59,9 @@
{
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 @@
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 @@
if (pProcessData)
{
DPRINT("CsrFreeProcessData pid: %d\n", Pid);
+ if (pProcessData->Process)
+ {
+ NtClose(pProcessData->Process);
+ }
if (pProcessData->Console)
{
RtlEnterCriticalSection(&ProcessDataLock);
_____
Modified: trunk/reactos/subsys/csrss/include/api.h
--- trunk/reactos/subsys/csrss/include/api.h 2005-04-03 12:49:25 UTC
(rev 14474)
+++ trunk/reactos/subsys/csrss/include/api.h 2005-04-03 13:04:10 UTC
(rev 14475)
@@ -37,6 +37,7 @@
ULONG HandleTableSize;
Object_t ** HandleTable;
HANDLE ProcessId;
+ HANDLE Process;
ULONG ShutdownLevel;
ULONG ShutdownFlags;
HANDLE ConsoleEvent;
_____
Modified: trunk/reactos/subsys/csrss/win32csr/conio.c
--- trunk/reactos/subsys/csrss/win32csr/conio.c 2005-04-03 12:49:25 UTC
(rev 14474)
+++ trunk/reactos/subsys/csrss/win32csr/conio.c 2005-04-03 13:04:10 UTC
(rev 14475)
@@ -74,49 +74,22 @@
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);
}
}
Show replies by date