2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Base API Server DLL
4 * FILE: subsystems/win/basesrv/proc.c
5 * PURPOSE: Process and Thread Management
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES *******************************************************************/
16 /* PUBLIC SERVER APIS *********************************************************/
18 CSR_API(BaseSrvDebugProcess
)
20 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
21 return STATUS_NOT_IMPLEMENTED
;
24 CSR_API(BaseSrvRegisterThread
)
26 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
27 return STATUS_NOT_IMPLEMENTED
;
29 CSR_API(BaseSrvSxsCreateActivationContext
)
31 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
32 return STATUS_NOT_IMPLEMENTED
;
35 CSR_API(BaseSrvSetTermsrvAppInstallMode
)
37 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
38 return STATUS_NOT_IMPLEMENTED
;
41 CSR_API(BaseSrvSetTermsrvClientTimeZone
)
43 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
44 return STATUS_NOT_IMPLEMENTED
;
47 CSR_API(BaseSrvUnknown
)
49 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
50 return STATUS_NOT_IMPLEMENTED
;
53 CSR_API(BaseSrvGetTempFile
)
55 static UINT BaseGetTempFileUnique
= 0;
56 PBASE_GET_TEMP_FILE GetTempFile
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.GetTempFileRequest
;
58 /* Return 16-bits ID */
59 GetTempFile
->UniqueID
= (++BaseGetTempFileUnique
& 0xFFFF);
61 DPRINT("Returning: %u\n", GetTempFile
->UniqueID
);
63 return STATUS_SUCCESS
;
66 CSR_API(BaseSrvCreateProcess
)
69 PBASE_CREATE_PROCESS CreateProcessRequest
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.CreateProcessRequest
;
70 HANDLE ProcessHandle
, ThreadHandle
;
71 PCSR_THREAD CsrThread
;
73 ULONG Flags
= 0, VdmPower
= 0, DebugFlags
= 0;
75 /* Get the current client thread */
76 CsrThread
= CsrGetClientThread();
77 ASSERT(CsrThread
!= NULL
);
79 Process
= CsrThread
->Process
;
81 /* Extract the flags out of the process handle */
82 Flags
= (ULONG_PTR
)CreateProcessRequest
->ProcessHandle
& 3;
83 CreateProcessRequest
->ProcessHandle
= (HANDLE
)((ULONG_PTR
)CreateProcessRequest
->ProcessHandle
& ~3);
85 /* Duplicate the process handle */
86 Status
= NtDuplicateObject(Process
->ProcessHandle
,
87 CreateProcessRequest
->ProcessHandle
,
92 DUPLICATE_SAME_ACCESS
);
93 if (!NT_SUCCESS(Status
))
95 DPRINT1("Failed to duplicate process handle: %lx\n", Status
);
99 /* Duplicate the thread handle */
100 Status
= NtDuplicateObject(Process
->ProcessHandle
,
101 CreateProcessRequest
->ThreadHandle
,
106 DUPLICATE_SAME_ACCESS
);
107 if (!NT_SUCCESS(Status
))
109 DPRINT1("Failed to duplicate thread handle: %lx\n", Status
);
110 NtClose(ProcessHandle
);
114 /* See if this is a VDM process */
117 /* Request VDM powers */
118 Status
= NtSetInformationProcess(ProcessHandle
,
119 ProcessWx86Information
,
122 if (!NT_SUCCESS(Status
))
124 DPRINT1("Failed to get VDM powers\n");
125 NtClose(ProcessHandle
);
126 NtClose(ThreadHandle
);
131 /* Flags conversion. FIXME: More need conversion */
132 if (CreateProcessRequest
->CreationFlags
& CREATE_NEW_PROCESS_GROUP
)
134 DebugFlags
|= CsrProcessCreateNewGroup
;
136 if ((Flags
& 2) == 0)
138 /* We are launching a console process */
139 DebugFlags
|= CsrProcessIsConsoleApp
;
142 /* FIXME: SxS Stuff */
144 /* Call CSRSRV to create the CSR_PROCESS structure and the first CSR_THREAD */
145 Status
= CsrCreateProcess(ProcessHandle
,
147 &CreateProcessRequest
->ClientId
,
151 if (Status
== STATUS_THREAD_IS_TERMINATING
)
153 DPRINT1("Thread already dead\n");
155 /* Set the special reply value so we don't reply this message back */
156 *ReplyCode
= CsrReplyDeadClient
;
161 /* Check for other failures */
162 if (!NT_SUCCESS(Status
))
164 DPRINT1("Failed to create process/thread structures: %lx\n", Status
);
168 /* FIXME: Should notify user32 */
170 /* FIXME: VDM vodoo */
172 /* Return the result of this operation */
176 CSR_API(BaseSrvCreateThread
)
179 PBASE_CREATE_THREAD CreateThreadRequest
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.CreateThreadRequest
;
180 PCSR_THREAD CurrentThread
;
182 PCSR_PROCESS CsrProcess
;
184 /* Get the current CSR thread */
185 CurrentThread
= CsrGetClientThread();
188 DPRINT1("Server Thread TID: [%lx.%lx]\n",
189 CreateThreadRequest
->ClientId
.UniqueProcess
,
190 CreateThreadRequest
->ClientId
.UniqueThread
);
191 return STATUS_SUCCESS
; // server-to-server
194 /* Get the CSR Process for this request */
195 CsrProcess
= CurrentThread
->Process
;
196 if (CsrProcess
->ClientId
.UniqueProcess
!=
197 CreateThreadRequest
->ClientId
.UniqueProcess
)
199 /* This is a remote thread request -- is it within the server itself? */
200 if (CreateThreadRequest
->ClientId
.UniqueProcess
== NtCurrentTeb()->ClientId
.UniqueProcess
)
202 /* Accept this without any further work */
203 return STATUS_SUCCESS
;
206 /* Get the real CSR Process for the remote thread's process */
207 Status
= CsrLockProcessByClientId(CreateThreadRequest
->ClientId
.UniqueProcess
,
209 if (!NT_SUCCESS(Status
)) return Status
;
212 /* Duplicate the thread handle so we can own it */
213 Status
= NtDuplicateObject(CurrentThread
->Process
->ProcessHandle
,
214 CreateThreadRequest
->ThreadHandle
,
219 DUPLICATE_SAME_ACCESS
);
220 if (NT_SUCCESS(Status
))
222 /* Call CSRSRV to tell it about the new thread */
223 Status
= CsrCreateThread(CsrProcess
,
225 &CreateThreadRequest
->ClientId
,
229 /* Unlock the process and return */
230 if (CsrProcess
!= CurrentThread
->Process
) CsrUnlockProcess(CsrProcess
);
234 CSR_API(BaseSrvExitProcess
)
236 PCSR_THREAD CsrThread
= CsrGetClientThread();
237 ASSERT(CsrThread
!= NULL
);
239 /* Set the special reply value so we don't reply this message back */
240 *ReplyCode
= CsrReplyDeadClient
;
242 /* Remove the CSR_THREADs and CSR_PROCESS */
243 return CsrDestroyProcess(&CsrThread
->ClientId
,
244 (NTSTATUS
)((PBASE_API_MESSAGE
)ApiMessage
)->Data
.ExitProcessRequest
.uExitCode
);
247 CSR_API(BaseSrvGetProcessShutdownParam
)
249 PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.ShutdownParametersRequest
;
250 PCSR_THREAD CsrThread
= CsrGetClientThread();
253 ShutdownParametersRequest
->ShutdownLevel
= CsrThread
->Process
->ShutdownLevel
;
254 ShutdownParametersRequest
->ShutdownFlags
= CsrThread
->Process
->ShutdownFlags
;
256 return STATUS_SUCCESS
;
259 CSR_API(BaseSrvSetProcessShutdownParam
)
261 PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.ShutdownParametersRequest
;
262 PCSR_THREAD CsrThread
= CsrGetClientThread();
265 CsrThread
->Process
->ShutdownLevel
= ShutdownParametersRequest
->ShutdownLevel
;
266 CsrThread
->Process
->ShutdownFlags
= ShutdownParametersRequest
->ShutdownFlags
;
268 return STATUS_SUCCESS
;
271 /* PUBLIC API *****************************************************************/
275 BaseSetProcessCreateNotify(IN BASE_PROCESS_CREATE_NOTIFY_ROUTINE ProcessCreateNotifyProc
)
277 DPRINT("BASESRV: %s(%08lx) called\n", __FUNCTION__
, ProcessCreateNotifyProc
);
278 return STATUS_NOT_IMPLEMENTED
;