Removed some calls to NtOpenProcess. They aren't necessary because the process data structure contains already a process handle.

svn path=/trunk/; revision=14480
This commit is contained in:
Hartmut Birr 2005-04-03 15:47:15 +00:00
parent 4e0cf9abb6
commit f22d019858
2 changed files with 3 additions and 47 deletions

View file

@ -95,7 +95,7 @@ PCSRSS_PROCESS_DATA STDCALL CsrCreateProcessData(HANDLE ProcessId)
/* using OpenProcess is not optimal due to HANDLE vs. DWORD PIDs... */ /* using OpenProcess is not optimal due to HANDLE vs. DWORD PIDs... */
Status = NtOpenProcess(&pProcessData->Process, Status = NtOpenProcess(&pProcessData->Process,
PROCESS_DUP_HANDLE | PROCESS_VM_OPERATION | PROCESS_DUP_HANDLE | PROCESS_VM_OPERATION |
PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, PROCESS_VM_WRITE | PROCESS_CREATE_THREAD | SYNCHRONIZE,
&ObjectAttributes, &ObjectAttributes,
&ClientId); &ClientId);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
@ -195,7 +195,6 @@ CSR_API(CsrCreateProcess)
{ {
PCSRSS_PROCESS_DATA NewProcessData; PCSRSS_PROCESS_DATA NewProcessData;
NTSTATUS Status; NTSTATUS Status;
HANDLE Process;
CSRSS_API_REQUEST ApiRequest; CSRSS_API_REQUEST ApiRequest;
CSRSS_API_REPLY ApiReply; CSRSS_API_REPLY ApiReply;
@ -240,8 +239,6 @@ CSR_API(CsrCreateProcess)
} }
else else
{ {
CLIENT_ID ClientId;
NewProcessData->Console = ProcessData->Console; NewProcessData->Console = ProcessData->Console;
InterlockedIncrement( &(ProcessData->Console->Header.ReferenceCount) ); InterlockedIncrement( &(ProcessData->Console->Header.ReferenceCount) );
CsrInsertObject(NewProcessData, CsrInsertObject(NewProcessData,
@ -253,27 +250,15 @@ CSR_API(CsrCreateProcess)
&(NewProcessData->Console->ActiveBuffer->Header) ); &(NewProcessData->Console->ActiveBuffer->Header) );
RtlLeaveCriticalSection(&ProcessDataLock); RtlLeaveCriticalSection(&ProcessDataLock);
ClientId.UniqueProcess = (HANDLE)NewProcessData->ProcessId; Status = NtDuplicateObject( NtCurrentProcess(), NewProcessData->Console->ActiveEvent, NewProcessData->Process, &NewProcessData->ConsoleEvent, SYNCHRONIZE, FALSE, 0 );
Status = NtOpenProcess( &Process, PROCESS_DUP_HANDLE, 0, &ClientId );
if( !NT_SUCCESS( Status ) )
{
DbgPrint( "CSR: NtOpenProcess() failed for handle duplication\n" );
InterlockedDecrement( &(NewProcessData->Console->Header.ReferenceCount) );
CsrFreeProcessData( NewProcessData->ProcessId );
Reply->Status = Status;
return Status;
}
Status = NtDuplicateObject( NtCurrentProcess(), NewProcessData->Console->ActiveEvent, Process, &NewProcessData->ConsoleEvent, SYNCHRONIZE, FALSE, 0 );
if( !NT_SUCCESS( Status ) ) if( !NT_SUCCESS( Status ) )
{ {
DbgPrint( "CSR: NtDuplicateObject() failed: %x\n", Status ); DbgPrint( "CSR: NtDuplicateObject() failed: %x\n", Status );
NtClose( Process );
InterlockedDecrement( &(NewProcessData->Console->Header.ReferenceCount) ); InterlockedDecrement( &(NewProcessData->Console->Header.ReferenceCount) );
CsrFreeProcessData( NewProcessData->ProcessId ); CsrFreeProcessData( NewProcessData->ProcessId );
Reply->Status = Status; Reply->Status = Status;
return Status; return Status;
} }
NtClose( Process );
NewProcessData->CtrlDispatcher = Request->Data.CreateProcessRequest.CtrlDispatcher; NewProcessData->CtrlDispatcher = Request->Data.CreateProcessRequest.CtrlDispatcher;
RtlEnterCriticalSection(&ProcessDataLock ); RtlEnterCriticalSection(&ProcessDataLock );
InsertHeadList(&NewProcessData->Console->ProcessList, &NewProcessData->ProcessEntry); InsertHeadList(&NewProcessData->Console->ProcessList, &NewProcessData->ProcessEntry);

View file

@ -238,9 +238,6 @@ CsrInitConsole(PCSRSS_CONSOLE Console)
CSR_API(CsrAllocConsole) CSR_API(CsrAllocConsole)
{ {
PCSRSS_CONSOLE Console; PCSRSS_CONSOLE Console;
OBJECT_ATTRIBUTES ObjectAttributes;
CLIENT_ID ClientId;
HANDLE Process;
NTSTATUS Status; NTSTATUS Status;
DPRINT("CsrAllocConsole\n"); DPRINT("CsrAllocConsole\n");
@ -293,35 +290,10 @@ CSR_API(CsrAllocConsole)
return Reply->Status = Status; return Reply->Status = 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,
&ObjectAttributes,
&ClientId);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtOpenProcess() failed for handle duplication, Status: 0x%x\n", Status);
Console->Header.ReferenceCount--;
ProcessData->Console = 0;
Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.OutputHandle);
Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.InputHandle);
Reply->Status = Status;
return Status;
}
if (! DuplicateHandle(GetCurrentProcess(), ProcessData->Console->ActiveEvent, if (! DuplicateHandle(GetCurrentProcess(), ProcessData->Console->ActiveEvent,
Process, &ProcessData->ConsoleEvent, EVENT_ALL_ACCESS, FALSE, 0)) ProcessData->Process, &ProcessData->ConsoleEvent, EVENT_ALL_ACCESS, FALSE, 0))
{ {
DPRINT1("DuplicateHandle() failed: %d\n", GetLastError); DPRINT1("DuplicateHandle() failed: %d\n", GetLastError);
CloseHandle(Process);
Console->Header.ReferenceCount--; Console->Header.ReferenceCount--;
Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.OutputHandle); Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.OutputHandle);
Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.InputHandle); Win32CsrReleaseObject(ProcessData, Reply->Data.AllocConsoleReply.InputHandle);
@ -329,7 +301,6 @@ CSR_API(CsrAllocConsole)
Reply->Status = Status; Reply->Status = Status;
return Status; return Status;
} }
CloseHandle(Process);
ProcessData->CtrlDispatcher = Request->Data.AllocConsoleRequest.CtrlDispatcher; ProcessData->CtrlDispatcher = Request->Data.AllocConsoleRequest.CtrlDispatcher;
DPRINT("CSRSS:CtrlDispatcher address: %x\n", ProcessData->CtrlDispatcher); DPRINT("CSRSS:CtrlDispatcher address: %x\n", ProcessData->CtrlDispatcher);
InsertHeadList(&ProcessData->Console->ProcessList, &ProcessData->ProcessEntry); InsertHeadList(&ProcessData->Console->ProcessList, &ProcessData->ProcessEntry);