Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenprocess.c
Go to the documentation of this file.
00001 /* 00002 * subsystems/win32/csrss/csrsrv/api/process.c 00003 * 00004 * "\windows\ApiPort" port process management functions 00005 * 00006 * ReactOS Operating System 00007 */ 00008 00009 /* INCLUDES ******************************************************************/ 00010 00011 #include <srv.h> 00012 00013 #define NDEBUG 00014 #include <debug.h> 00015 00016 extern NTSTATUS CallProcessCreated(PCSR_PROCESS, PCSR_PROCESS); 00017 00018 /* GLOBALS *******************************************************************/ 00019 00020 /* FUNCTIONS *****************************************************************/ 00021 00022 /********************************************************************** 00023 * CSRSS API 00024 *********************************************************************/ 00025 00026 CSR_API(CsrSrvCreateProcess) 00027 { 00028 NTSTATUS Status; 00029 HANDLE ProcessHandle, ThreadHandle; 00030 PCSR_THREAD CsrThread; 00031 PCSR_PROCESS NewProcessData; 00032 ULONG Flags, VdmPower = 0, DebugFlags = 0; 00033 00034 /* Get the current client thread */ 00035 CsrThread = NtCurrentTeb()->CsrClientThread; 00036 ASSERT(CsrThread != NULL); 00037 00038 /* Extract the flags out of the process handle */ 00039 Flags = (ULONG_PTR)Request->Data.CreateProcessRequest.ProcessHandle & 3; 00040 Request->Data.CreateProcessRequest.ProcessHandle = (HANDLE)((ULONG_PTR)Request->Data.CreateProcessRequest.ProcessHandle & ~3); 00041 00042 /* Duplicate the process handle */ 00043 Status = NtDuplicateObject(CsrThread->Process->ProcessHandle, 00044 Request->Data.CreateProcessRequest.ProcessHandle, 00045 NtCurrentProcess(), 00046 &ProcessHandle, 00047 0, 00048 0, 00049 DUPLICATE_SAME_ACCESS); 00050 if (!NT_SUCCESS(Status)) 00051 { 00052 DPRINT1("Failed to duplicate process handle\n"); 00053 return Status; 00054 } 00055 00056 /* Duplicate the thread handle */ 00057 Status = NtDuplicateObject(CsrThread->Process->ProcessHandle, 00058 Request->Data.CreateProcessRequest.ThreadHandle, 00059 NtCurrentProcess(), 00060 &ThreadHandle, 00061 0, 00062 0, 00063 DUPLICATE_SAME_ACCESS); 00064 if (!NT_SUCCESS(Status)) 00065 { 00066 DPRINT1("Failed to duplicate process handle\n"); 00067 NtClose(ProcessHandle); 00068 return Status; 00069 } 00070 00071 /* See if this is a VDM process */ 00072 if (VdmPower) 00073 { 00074 /* Request VDM powers */ 00075 Status = NtSetInformationProcess(ProcessHandle, 00076 ProcessWx86Information, 00077 &VdmPower, 00078 sizeof(VdmPower)); 00079 if (!NT_SUCCESS(Status)) 00080 { 00081 DPRINT1("Failed to get VDM powers\n"); 00082 NtClose(ProcessHandle); 00083 NtClose(ThreadHandle); 00084 return Status; 00085 } 00086 } 00087 00088 /* Convert some flags. FIXME: More need conversion */ 00089 if (Request->Data.CreateProcessRequest.CreationFlags & CREATE_NEW_PROCESS_GROUP) 00090 { 00091 DebugFlags |= CsrProcessCreateNewGroup; 00092 } 00093 00094 /* FIXME: SxS Stuff */ 00095 00096 /* Call CSRSRV to create the CSR_PROCESS structure and the first CSR_THREAD */ 00097 Status = CsrCreateProcess(ProcessHandle, 00098 ThreadHandle, 00099 &Request->Data.CreateProcessRequest.ClientId, 00100 CsrThread->Process->NtSession, 00101 DebugFlags, 00102 NULL); 00103 if (Status == STATUS_THREAD_IS_TERMINATING) 00104 { 00105 DPRINT1("Thread already dead\n"); 00106 return Status; 00107 } 00108 00109 /* Check for other failures */ 00110 if (!NT_SUCCESS(Status)) 00111 { 00112 DPRINT1("Failed to create process/thread structures: %lx\n", Status); 00113 return Status; 00114 } 00115 00116 /* FIXME: Should notify user32 */ 00117 00118 /* FIXME: VDM vodoo */ 00119 00120 /* ReactOS Compatibility */ 00121 Status = CsrLockProcessByClientId(Request->Data.CreateProcessRequest.ClientId.UniqueProcess, &NewProcessData); 00122 ASSERT(Status == STATUS_SUCCESS); 00123 if (!(Request->Data.CreateProcessRequest.CreationFlags & (CREATE_NEW_CONSOLE | DETACHED_PROCESS))) 00124 { 00125 NewProcessData->ParentConsole = ProcessData->Console; 00126 NewProcessData->bInheritHandles = Request->Data.CreateProcessRequest.bInheritHandles; 00127 } 00128 RtlInitializeCriticalSection(&NewProcessData->HandleTableLock); 00129 CallProcessCreated(ProcessData, NewProcessData); 00130 CsrUnlockProcess(NewProcessData); 00131 00132 /* Return the result of this operation */ 00133 return Status; 00134 } 00135 00136 CSR_API(CsrSrvCreateThread) 00137 { 00138 PCSR_THREAD CurrentThread; 00139 HANDLE ThreadHandle; 00140 NTSTATUS Status; 00141 PCSR_PROCESS CsrProcess; 00142 00143 /* Get the current CSR thread */ 00144 CurrentThread = NtCurrentTeb()->CsrClientThread; 00145 if (!CurrentThread) 00146 { 00147 DPRINT1("Server Thread TID: [%lx.%lx]\n", 00148 Request->Data.CreateThreadRequest.ClientId.UniqueProcess, 00149 Request->Data.CreateThreadRequest.ClientId.UniqueThread); 00150 return STATUS_SUCCESS; // server-to-server 00151 } 00152 00153 /* Get the CSR Process for this request */ 00154 CsrProcess = CurrentThread->Process; 00155 if (CsrProcess->ClientId.UniqueProcess != 00156 Request->Data.CreateThreadRequest.ClientId.UniqueProcess) 00157 { 00158 /* This is a remote thread request -- is it within the server itself? */ 00159 if (Request->Data.CreateThreadRequest.ClientId.UniqueProcess == NtCurrentTeb()->ClientId.UniqueProcess) 00160 { 00161 /* Accept this without any further work */ 00162 return STATUS_SUCCESS; 00163 } 00164 00165 /* Get the real CSR Process for the remote thread's process */ 00166 Status = CsrLockProcessByClientId(Request->Data.CreateThreadRequest.ClientId.UniqueProcess, 00167 &CsrProcess); 00168 if (!NT_SUCCESS(Status)) return Status; 00169 } 00170 00171 /* Duplicate the thread handle so we can own it */ 00172 Status = NtDuplicateObject(CurrentThread->Process->ProcessHandle, 00173 Request->Data.CreateThreadRequest.ThreadHandle, 00174 NtCurrentProcess(), 00175 &ThreadHandle, 00176 0, 00177 0, 00178 DUPLICATE_SAME_ACCESS); 00179 if (NT_SUCCESS(Status)) 00180 { 00181 /* Call CSRSRV to tell it about the new thread */ 00182 Status = CsrCreateThread(CsrProcess, 00183 ThreadHandle, 00184 &Request->Data.CreateThreadRequest.ClientId); 00185 } 00186 00187 /* Unlock the process and return */ 00188 if (CsrProcess != CurrentThread->Process) CsrUnlockProcess(CsrProcess); 00189 return Status; 00190 } 00191 00192 CSR_API(CsrTerminateProcess) 00193 { 00194 PCSR_THREAD CsrThread = NtCurrentTeb()->CsrClientThread; 00195 ASSERT(CsrThread != NULL); 00196 00197 /* Set magic flag so we don't reply this message back */ 00198 Request->Type = 0xBABE; 00199 00200 /* Remove the CSR_THREADs and CSR_PROCESS */ 00201 return CsrDestroyProcess(&CsrThread->ClientId, 00202 (NTSTATUS)Request->Data.TerminateProcessRequest.uExitCode); 00203 } 00204 00205 CSR_API(CsrConnectProcess) 00206 { 00207 00208 return(STATUS_SUCCESS); 00209 } 00210 00211 CSR_API(CsrGetShutdownParameters) 00212 { 00213 00214 Request->Data.GetShutdownParametersRequest.Level = ProcessData->ShutdownLevel; 00215 Request->Data.GetShutdownParametersRequest.Flags = ProcessData->ShutdownFlags; 00216 00217 return(STATUS_SUCCESS); 00218 } 00219 00220 CSR_API(CsrSetShutdownParameters) 00221 { 00222 00223 ProcessData->ShutdownLevel = Request->Data.SetShutdownParametersRequest.Level; 00224 ProcessData->ShutdownFlags = Request->Data.SetShutdownParametersRequest.Flags; 00225 00226 return(STATUS_SUCCESS); 00227 } 00228 00229 /* EOF */ Generated on Sun May 27 2012 04:17:15 for ReactOS by
1.7.6.1
|