2005-12-01 22:38:03 +00:00
|
|
|
/*
|
2011-07-25 05:54:37 +00:00
|
|
|
* subsystems/win32/csrss/csrsrv/api/process.c
|
1999-06-08 22:50:59 +00:00
|
|
|
*
|
|
|
|
* "\windows\ApiPort" port process management functions
|
|
|
|
*
|
|
|
|
* ReactOS Operating System
|
|
|
|
*/
|
1999-12-22 14:48:30 +00:00
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2010-03-10 04:59:39 +00:00
|
|
|
#include <srv.h>
|
1999-07-17 23:10:31 +00:00
|
|
|
|
2003-03-09 21:41:35 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2012-02-16 03:41:18 +00:00
|
|
|
|
2012-02-17 05:15:13 +00:00
|
|
|
extern NTSTATUS CallProcessCreated(PCSR_PROCESS, PCSR_PROCESS);
|
2010-05-22 23:47:54 +00:00
|
|
|
|
1999-12-30 01:51:42 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
1999-12-22 14:48:30 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2001-08-14 12:57:16 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* CSRSS API
|
|
|
|
*********************************************************************/
|
|
|
|
|
2012-02-19 11:39:07 +00:00
|
|
|
CSR_API(CsrSrvCreateProcess)
|
1999-06-08 22:50:59 +00:00
|
|
|
{
|
2012-02-19 11:39:07 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
HANDLE ProcessHandle, ThreadHandle;
|
|
|
|
PCSR_THREAD CsrThread;
|
|
|
|
PCSR_PROCESS NewProcessData;
|
|
|
|
ULONG Flags, VdmPower = 0, DebugFlags = 0;
|
|
|
|
|
|
|
|
/* Get the current client thread */
|
|
|
|
CsrThread = NtCurrentTeb()->CsrClientThread;
|
|
|
|
ASSERT(CsrThread != NULL);
|
|
|
|
|
|
|
|
/* Extract the flags out of the process handle */
|
|
|
|
Flags = (ULONG_PTR)Request->Data.CreateProcessRequest.ProcessHandle & 3;
|
|
|
|
Request->Data.CreateProcessRequest.ProcessHandle = (HANDLE)((ULONG_PTR)Request->Data.CreateProcessRequest.ProcessHandle & ~3);
|
|
|
|
|
|
|
|
/* Duplicate the process handle */
|
|
|
|
Status = NtDuplicateObject(CsrThread->Process->ProcessHandle,
|
|
|
|
Request->Data.CreateProcessRequest.ProcessHandle,
|
|
|
|
NtCurrentProcess(),
|
|
|
|
&ProcessHandle,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
DUPLICATE_SAME_ACCESS);
|
|
|
|
if (!NT_SUCCESS(Status))
|
1999-12-30 01:51:42 +00:00
|
|
|
{
|
2012-02-19 11:39:07 +00:00
|
|
|
DPRINT1("Failed to duplicate process handle\n");
|
|
|
|
return Status;
|
1999-12-30 01:51:42 +00:00
|
|
|
}
|
2002-10-01 06:41:57 +00:00
|
|
|
|
2012-02-19 11:39:07 +00:00
|
|
|
/* Duplicate the thread handle */
|
|
|
|
Status = NtDuplicateObject(CsrThread->Process->ProcessHandle,
|
|
|
|
Request->Data.CreateProcessRequest.ThreadHandle,
|
|
|
|
NtCurrentProcess(),
|
|
|
|
&ThreadHandle,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
DUPLICATE_SAME_ACCESS);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to duplicate process handle\n");
|
|
|
|
NtClose(ProcessHandle);
|
|
|
|
return Status;
|
|
|
|
}
|
2007-06-14 16:47:24 +00:00
|
|
|
|
2012-02-19 11:39:07 +00:00
|
|
|
/* See if this is a VDM process */
|
|
|
|
if (VdmPower)
|
|
|
|
{
|
|
|
|
/* Request VDM powers */
|
|
|
|
Status = NtSetInformationProcess(ProcessHandle,
|
|
|
|
ProcessWx86Information,
|
|
|
|
&VdmPower,
|
|
|
|
sizeof(VdmPower));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to get VDM powers\n");
|
|
|
|
NtClose(ProcessHandle);
|
|
|
|
NtClose(ThreadHandle);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert some flags. FIXME: More need conversion */
|
|
|
|
if (Request->Data.CreateProcessRequest.CreationFlags & CREATE_NEW_PROCESS_GROUP)
|
|
|
|
{
|
|
|
|
DebugFlags |= CsrProcessCreateNewGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: SxS Stuff */
|
|
|
|
|
|
|
|
/* Call CSRSRV to create the CSR_PROCESS structure and the first CSR_THREAD */
|
|
|
|
Status = CsrCreateProcess(ProcessHandle,
|
|
|
|
ThreadHandle,
|
|
|
|
&Request->Data.CreateProcessRequest.ClientId,
|
|
|
|
CsrThread->Process->NtSession,
|
|
|
|
DebugFlags,
|
|
|
|
NULL);
|
|
|
|
if (Status == STATUS_THREAD_IS_TERMINATING)
|
|
|
|
{
|
|
|
|
DPRINT1("Thread already dead\n");
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for other failures */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to create process/thread structures: %lx\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Should notify user32 */
|
|
|
|
|
|
|
|
/* FIXME: VDM vodoo */
|
|
|
|
|
|
|
|
/* ReactOS Compatibility */
|
|
|
|
Status = CsrLockProcessByClientId(Request->Data.CreateProcessRequest.ClientId.UniqueProcess, &NewProcessData);
|
|
|
|
ASSERT(Status == STATUS_SUCCESS);
|
|
|
|
if (!(Request->Data.CreateProcessRequest.CreationFlags & (CREATE_NEW_CONSOLE | DETACHED_PROCESS)))
|
|
|
|
{
|
|
|
|
NewProcessData->ParentConsole = ProcessData->Console;
|
|
|
|
NewProcessData->bInheritHandles = Request->Data.CreateProcessRequest.bInheritHandles;
|
|
|
|
}
|
|
|
|
RtlInitializeCriticalSection(&NewProcessData->HandleTableLock);
|
|
|
|
CallProcessCreated(ProcessData, NewProcessData);
|
|
|
|
CsrUnlockProcess(NewProcessData);
|
2008-08-02 17:01:22 +00:00
|
|
|
|
2012-02-19 11:39:07 +00:00
|
|
|
/* Return the result of this operation */
|
|
|
|
return Status;
|
1999-06-08 22:50:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-10 06:49:53 +00:00
|
|
|
CSR_API(CsrSrvCreateThread)
|
2010-03-09 20:23:22 +00:00
|
|
|
{
|
|
|
|
PCSR_THREAD CurrentThread;
|
|
|
|
HANDLE ThreadHandle;
|
|
|
|
NTSTATUS Status;
|
2012-02-15 20:29:08 +00:00
|
|
|
PCSR_PROCESS CsrProcess;
|
2010-03-09 20:23:22 +00:00
|
|
|
|
2012-02-19 10:12:14 +00:00
|
|
|
/* Get the current CSR thread */
|
2010-03-09 20:23:22 +00:00
|
|
|
CurrentThread = NtCurrentTeb()->CsrClientThread;
|
2012-02-19 19:40:28 +00:00
|
|
|
if (!CurrentThread)
|
|
|
|
{
|
|
|
|
DPRINT1("Server Thread TID: [%lx.%lx]\n",
|
|
|
|
Request->Data.CreateThreadRequest.ClientId.UniqueProcess,
|
|
|
|
Request->Data.CreateThreadRequest.ClientId.UniqueThread);
|
|
|
|
return STATUS_SUCCESS; // server-to-server
|
|
|
|
}
|
|
|
|
|
2012-02-19 10:12:14 +00:00
|
|
|
/* Get the CSR Process for this request */
|
2010-03-09 20:23:22 +00:00
|
|
|
CsrProcess = CurrentThread->Process;
|
2012-02-19 10:12:14 +00:00
|
|
|
if (CsrProcess->ClientId.UniqueProcess !=
|
|
|
|
Request->Data.CreateThreadRequest.ClientId.UniqueProcess)
|
2010-03-09 20:23:22 +00:00
|
|
|
{
|
2012-02-19 10:12:14 +00:00
|
|
|
/* This is a remote thread request -- is it within the server itself? */
|
2010-03-09 20:23:22 +00:00
|
|
|
if (Request->Data.CreateThreadRequest.ClientId.UniqueProcess == NtCurrentTeb()->ClientId.UniqueProcess)
|
|
|
|
{
|
2012-02-19 10:12:14 +00:00
|
|
|
/* Accept this without any further work */
|
2010-03-09 20:23:22 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2012-02-19 19:40:28 +00:00
|
|
|
|
2012-02-19 10:12:14 +00:00
|
|
|
/* Get the real CSR Process for the remote thread's process */
|
2010-03-09 20:23:22 +00:00
|
|
|
Status = CsrLockProcessByClientId(Request->Data.CreateThreadRequest.ClientId.UniqueProcess,
|
|
|
|
&CsrProcess);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
}
|
2012-02-19 10:12:14 +00:00
|
|
|
|
|
|
|
/* Duplicate the thread handle so we can own it */
|
|
|
|
Status = NtDuplicateObject(CurrentThread->Process->ProcessHandle,
|
2010-03-09 20:23:22 +00:00
|
|
|
Request->Data.CreateThreadRequest.ThreadHandle,
|
|
|
|
NtCurrentProcess(),
|
|
|
|
&ThreadHandle,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
DUPLICATE_SAME_ACCESS);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2012-02-19 10:12:14 +00:00
|
|
|
/* Call CSRSRV to tell it about the new thread */
|
2010-03-10 06:49:53 +00:00
|
|
|
Status = CsrCreateThread(CsrProcess,
|
2012-02-19 10:12:14 +00:00
|
|
|
ThreadHandle,
|
|
|
|
&Request->Data.CreateThreadRequest.ClientId);
|
2010-03-09 20:23:22 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 10:12:14 +00:00
|
|
|
/* Unlock the process and return */
|
|
|
|
if (CsrProcess != CurrentThread->Process) CsrUnlockProcess(CsrProcess);
|
2010-03-09 20:23:22 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2001-08-14 12:57:16 +00:00
|
|
|
CSR_API(CsrTerminateProcess)
|
1999-12-22 14:48:30 +00:00
|
|
|
{
|
2012-02-19 18:46:05 +00:00
|
|
|
PCSR_THREAD CsrThread = NtCurrentTeb()->CsrClientThread;
|
|
|
|
ASSERT(CsrThread != NULL);
|
2012-02-19 19:40:28 +00:00
|
|
|
|
|
|
|
/* Set magic flag so we don't reply this message back */
|
|
|
|
Request->Type = 0xBABE;
|
|
|
|
|
2012-02-19 18:46:05 +00:00
|
|
|
/* Remove the CSR_THREADs and CSR_PROCESS */
|
|
|
|
return CsrDestroyProcess(&CsrThread->ClientId,
|
|
|
|
(NTSTATUS)Request->Data.TerminateProcessRequest.uExitCode);
|
1999-12-22 14:48:30 +00:00
|
|
|
}
|
1999-06-08 22:50:59 +00:00
|
|
|
|
2001-08-14 12:57:16 +00:00
|
|
|
CSR_API(CsrConnectProcess)
|
1999-06-08 22:50:59 +00:00
|
|
|
{
|
2002-10-01 06:41:57 +00:00
|
|
|
|
1999-12-22 14:48:30 +00:00
|
|
|
return(STATUS_SUCCESS);
|
1999-06-08 22:50:59 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 16:40:12 +00:00
|
|
|
CSR_API(CsrGetShutdownParameters)
|
|
|
|
{
|
|
|
|
|
Large change to modify NTDLL'S CSR Functions to be compatible with NT. They are external and we should at least try to match the number of arguments (one vs eight? come on!). Because this is also the direction that Emanuele wants to be taking, the whole external calling interface was modified to be more compatible with NT (although internally it still isn't, and does not have a reason to be). API Names are now generated by a macro from the Server ID, like Emanuele and I noticed from traces, and I've entirely removed the concept of a reply structure. CSRSS uses full-duplex one-way structures, not dual-strutures (this would've been incompatible with the external interface anyways). I don't seem to have introduced any new bugs (console-ROS works great for me, as does the GUI), but there is still a chance some obscure bug might happen, so please bear with me, I had to hand-edit over 250 calls. Also, this now allows full removal of ntdll headers and the next commits will clean this up
svn path=/trunk/; revision=16213
2005-06-22 04:02:32 +00:00
|
|
|
Request->Data.GetShutdownParametersRequest.Level = ProcessData->ShutdownLevel;
|
|
|
|
Request->Data.GetShutdownParametersRequest.Flags = ProcessData->ShutdownFlags;
|
2002-10-20 16:40:12 +00:00
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
CSR_API(CsrSetShutdownParameters)
|
|
|
|
{
|
|
|
|
|
|
|
|
ProcessData->ShutdownLevel = Request->Data.SetShutdownParametersRequest.Level;
|
|
|
|
ProcessData->ShutdownFlags = Request->Data.SetShutdownParametersRequest.Flags;
|
|
|
|
|
|
|
|
return(STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-06-08 22:50:59 +00:00
|
|
|
/* EOF */
|