ReactOS 0.4.16-dev-334-g4d9f67c
proc.c File Reference
#include "basesrv.h"
#include "vdm.h"
#include <debug.h>
Include dependency graph for proc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

 CSR_API (BaseSrvDebugProcess)
 
 CSR_API (BaseSrvRegisterThread)
 
 CSR_API (BaseSrvSxsCreateActivationContext)
 
 CSR_API (BaseSrvSetTermsrvAppInstallMode)
 
 CSR_API (BaseSrvSetTermsrvClientTimeZone)
 
 CSR_API (BaseSrvGetTempFile)
 
 CSR_API (BaseSrvCreateProcess)
 
 CSR_API (BaseSrvCreateThread)
 
 CSR_API (BaseSrvExitProcess)
 
 CSR_API (BaseSrvGetProcessShutdownParam)
 
 CSR_API (BaseSrvSetProcessShutdownParam)
 
VOID NTAPI BaseSetProcessCreateNotify (IN BASE_PROCESS_CREATE_NOTIFY_ROUTINE ProcessCreateNotifyProc)
 

Variables

static BASE_PROCESS_CREATE_NOTIFY_ROUTINE UserNotifyProcessCreate = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file proc.c.

Function Documentation

◆ BaseSetProcessCreateNotify()

VOID NTAPI BaseSetProcessCreateNotify ( IN BASE_PROCESS_CREATE_NOTIFY_ROUTINE  ProcessCreateNotifyProc)

Definition at line 321 of file proc.c.

322{
323 /* Set the user notification procedure to be called when a process is created */
324 UserNotifyProcessCreate = ProcessCreateNotifyProc;
325}
static BASE_PROCESS_CREATE_NOTIFY_ROUTINE UserNotifyProcessCreate
Definition: proc.c:20

Referenced by CSR_SERVER_DLL_INIT().

◆ CSR_API() [1/11]

CSR_API ( BaseSrvCreateProcess  )

Definition at line 67 of file proc.c.

68{
70 PBASE_CREATE_PROCESS CreateProcessRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.CreateProcessRequest;
71 HANDLE ProcessHandle, ThreadHandle;
72 PCSR_THREAD CsrThread;
74 ULONG Flags = 0, DebugFlags = 0, VdmPower = 0;
75
76 /* Get the current client thread */
77 CsrThread = CsrGetClientThread();
78 ASSERT(CsrThread != NULL);
79
80 Process = CsrThread->Process;
81
82 /* Extract the flags out of the process handle */
83 Flags = (ULONG_PTR)CreateProcessRequest->ProcessHandle & 3;
84 CreateProcessRequest->ProcessHandle = (HANDLE)((ULONG_PTR)CreateProcessRequest->ProcessHandle & ~3);
85
86 /* Some things should be done if this is a VDM process */
87 if (CreateProcessRequest->VdmBinaryType)
88 {
89 /* We need to set the VDM power later on */
90 VdmPower = 1;
91 }
92
93 /* Duplicate the process handle */
94 Status = NtDuplicateObject(Process->ProcessHandle,
95 CreateProcessRequest->ProcessHandle,
98 0,
99 0,
101 if (!NT_SUCCESS(Status))
102 {
103 DPRINT1("Failed to duplicate process handle: %lx\n", Status);
104 return Status;
105 }
106
107 /* Duplicate the thread handle */
108 Status = NtDuplicateObject(Process->ProcessHandle,
109 CreateProcessRequest->ThreadHandle,
111 &ThreadHandle,
112 0,
113 0,
115 if (!NT_SUCCESS(Status))
116 {
117 DPRINT1("Failed to duplicate thread handle: %lx\n", Status);
119 return Status;
120 }
121
122 /* If this is a VDM process, request VDM power */
123 if (VdmPower)
124 {
127 &VdmPower,
128 sizeof(VdmPower));
129 if (!NT_SUCCESS(Status))
130 {
131 DPRINT1("Failed to get VDM powers\n");
133 NtClose(ThreadHandle);
134 return Status;
135 }
136 }
137
138 /* Flags conversion. FIXME: More need conversion */
139 if (CreateProcessRequest->CreationFlags & CREATE_NEW_PROCESS_GROUP)
140 {
141 DebugFlags |= CsrProcessCreateNewGroup;
142 }
143 if ((Flags & 2) == 0)
144 {
145 /* We are launching a console process */
146 DebugFlags |= CsrProcessIsConsoleApp;
147 }
148
149 /* FIXME: SxS Stuff */
150
151 /* Call CSRSRV to create the CSR_PROCESS structure and the first CSR_THREAD */
153 ThreadHandle,
154 &CreateProcessRequest->ClientId,
155 Process->NtSession,
156 DebugFlags,
157 NULL);
159 {
160 DPRINT1("Thread already dead\n");
161
162 /* Set the special reply value so we don't reply this message back */
163 *ReplyCode = CsrReplyDeadClient;
164
165 return Status;
166 }
167
168 /* Check for other failures */
169 if (!NT_SUCCESS(Status))
170 {
171 DPRINT1("Failed to create process/thread structures: %lx\n", Status);
172 return Status;
173 }
174
175 /* Call the user notification procedure */
177 {
178 UserNotifyProcessCreate(CreateProcessRequest->ClientId.UniqueProcess,
179 Process->ClientId.UniqueThread,
180 0,
181 Flags);
182 }
183
184 /* Check if this is a VDM process */
185 if (CreateProcessRequest->VdmBinaryType)
186 {
187 PVDM_CONSOLE_RECORD ConsoleRecord;
188
189 if (CreateProcessRequest->VdmTask != 0)
190 {
191 /* Get the console record using the task ID */
192 Status = GetConsoleRecordBySessionId(CreateProcessRequest->VdmTask,
193 &ConsoleRecord);
194 }
195 else
196 {
197 /* Get the console record using the console handle */
198 Status = BaseSrvGetConsoleRecord(CreateProcessRequest->hVDM,
199 &ConsoleRecord);
200 }
201
202 /* Check if it failed */
203 if (!NT_SUCCESS(Status)) return Status;
204
205 /* Store the process ID of the VDM in the console record */
206 ConsoleRecord->ProcessId = HandleToUlong(CreateProcessRequest->ClientId.UniqueProcess);
207 }
208
209 /* Return the result of this operation */
210 return Status;
211}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
struct _BASE_API_MESSAGE * PBASE_API_MESSAGE
#define HandleToUlong(h)
Definition: basetsd.h:79
#define CsrGetClientThread()
Definition: csrsrv.h:77
@ CsrProcessCreateNewGroup
Definition: csrsrv.h:91
@ CsrProcessIsConsoleApp
Definition: csrsrv.h:94
@ CsrReplyDeadClient
Definition: csrsrv.h:133
NTSTATUS NTAPI CsrCreateProcess(IN HANDLE hProcess, IN HANDLE hThread, IN PCLIENT_ID ClientId, IN PCSR_NT_SESSION NtSession, IN ULONG Flags, IN PCLIENT_ID DebugCid)
Definition: procsup.c:422
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ULONG_PTR
Definition: config.h:101
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
Status
Definition: gdiplustypes.h:25
@ ProcessWx86Information
Definition: winternl.h:875
#define ASSERT(a)
Definition: mode.c:44
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3410
HANDLE ProcessHandle
Definition: basemsg.h:89
CLIENT_ID ClientId
Definition: basemsg.h:91
HANDLE ThreadHandle
Definition: basemsg.h:90
HANDLE UniqueProcess
Definition: compat.h:825
PCSR_PROCESS Process
Definition: csrsrv.h:69
ULONG ProcessId
Definition: vdm.h:26
NTSTATUS BaseSrvGetConsoleRecord(HANDLE ConsoleHandle, PVDM_CONSOLE_RECORD *Record)
Definition: vdm.c:49
NTSTATUS GetConsoleRecordBySessionId(ULONG TaskId, PVDM_CONSOLE_RECORD *Record)
Definition: vdm.c:94
uint32_t ULONG
Definition: typedefs.h:59
#define CREATE_NEW_PROCESS_GROUP
Definition: winbase.h:188
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define DUPLICATE_SAME_ACCESS

◆ CSR_API() [2/11]

CSR_API ( BaseSrvCreateThread  )

Definition at line 213 of file proc.c.

214{
216 PBASE_CREATE_THREAD CreateThreadRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.CreateThreadRequest;
217 PCSR_THREAD CurrentThread;
218 HANDLE ThreadHandle;
220
221 /* Get the current CSR thread */
222 CurrentThread = CsrGetClientThread();
223 if (!CurrentThread)
224 {
225 DPRINT1("Server Thread TID: [%lx.%lx]\n",
226 CreateThreadRequest->ClientId.UniqueProcess,
227 CreateThreadRequest->ClientId.UniqueThread);
228 return STATUS_SUCCESS; // server-to-server
229 }
230
231 /* Get the CSR Process for this request */
232 CsrProcess = CurrentThread->Process;
233 if (CsrProcess->ClientId.UniqueProcess !=
234 CreateThreadRequest->ClientId.UniqueProcess)
235 {
236 /* This is a remote thread request -- is it within the server itself? */
237 if (CreateThreadRequest->ClientId.UniqueProcess == NtCurrentTeb()->ClientId.UniqueProcess)
238 {
239 /* Accept this without any further work */
240 return STATUS_SUCCESS;
241 }
242
243 /* Get the real CSR Process for the remote thread's process */
245 &CsrProcess);
246 if (!NT_SUCCESS(Status)) return Status;
247 }
248
249 /* Duplicate the thread handle so we can own it */
251 CreateThreadRequest->ThreadHandle,
253 &ThreadHandle,
254 0,
255 0,
257 if (NT_SUCCESS(Status))
258 {
259 /* Call CSRSRV to tell it about the new thread */
261 ThreadHandle,
262 &CreateThreadRequest->ClientId,
263 TRUE);
264 }
265
266 /* Unlock the process and return */
267 if (CsrProcess != CurrentThread->Process) CsrUnlockProcess(CsrProcess);
268 return Status;
269}
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1410
NTSTATUS NTAPI CsrCreateThread(IN PCSR_PROCESS CsrProcess, IN HANDLE hThread, IN PCLIENT_ID ClientId, IN BOOLEAN HaveClient)
Definition: thredsup.c:678
NTSTATUS NTAPI CsrLockProcessByClientId(IN HANDLE Pid, OUT PCSR_PROCESS *CsrProcess OPTIONAL)
#define TRUE
Definition: types.h:120
#define NtCurrentTeb
#define STATUS_SUCCESS
Definition: shellext.h:65
HANDLE ThreadHandle
Definition: basemsg.h:104
CLIENT_ID ClientId
Definition: basemsg.h:105
HANDLE UniqueThread
Definition: compat.h:826
HANDLE ProcessHandle
Definition: csrsrv.h:46
PKPROCESS CsrProcess
Definition: videoprt.c:39
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151

◆ CSR_API() [3/11]

CSR_API ( BaseSrvDebugProcess  )

Definition at line 24 of file proc.c.

25{
26 /* Deprecated */
28}
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

◆ CSR_API() [4/11]

CSR_API ( BaseSrvExitProcess  )

Definition at line 271 of file proc.c.

272{
273 PCSR_THREAD CsrThread = CsrGetClientThread();
274 ASSERT(CsrThread != NULL);
275
276 /* Set the special reply value so we don't reply this message back */
277 *ReplyCode = CsrReplyDeadClient;
278
279 /* Remove the CSR_THREADs and CSR_PROCESS */
280 return CsrDestroyProcess(&CsrThread->ClientId,
281 (NTSTATUS)((PBASE_API_MESSAGE)ApiMessage)->Data.ExitProcessRequest.uExitCode);
282}
NTSTATUS NTAPI CsrDestroyProcess(IN PCLIENT_ID Cid, IN NTSTATUS ExitStatus)
Definition: procsup.c:735
CLIENT_ID ClientId
Definition: csrsrv.h:68

◆ CSR_API() [5/11]

CSR_API ( BaseSrvGetProcessShutdownParam  )

Definition at line 284 of file proc.c.

285{
286 PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.ShutdownParametersRequest;
287 PCSR_THREAD CsrThread = CsrGetClientThread();
288 ASSERT(CsrThread);
289
290 ShutdownParametersRequest->ShutdownLevel = CsrThread->Process->ShutdownLevel;
291 /* Only SHUTDOWN_NORETRY flag is valid for this API. The other private flags are for CSRSRV/WINSRV only. */
292 ShutdownParametersRequest->ShutdownFlags = CsrThread->Process->ShutdownFlags & SHUTDOWN_NORETRY;
293
294 return STATUS_SUCCESS;
295}
ULONG ShutdownFlags
Definition: csrsrv.h:59
ULONG ShutdownLevel
Definition: csrsrv.h:58
#define SHUTDOWN_NORETRY
Definition: winbase.h:474

◆ CSR_API() [6/11]

CSR_API ( BaseSrvGetTempFile  )

Definition at line 54 of file proc.c.

55{
56 static UINT BaseGetTempFileUnique = 0;
57 PBASE_GET_TEMP_FILE GetTempFile = &((PBASE_API_MESSAGE)ApiMessage)->Data.GetTempFileRequest;
58
59 /* Return 16-bits ID */
60 GetTempFile->UniqueID = (++BaseGetTempFileUnique & 0xFFFF);
61
62 DPRINT("Returning: %u\n", GetTempFile->UniqueID);
63
64 return GetTempFile->UniqueID;
65}
unsigned int UINT
Definition: ndis.h:50
#define DPRINT
Definition: sndvol32.h:73

◆ CSR_API() [7/11]

CSR_API ( BaseSrvRegisterThread  )

Definition at line 30 of file proc.c.

31{
32 DPRINT1("%s not yet implemented\n", __FUNCTION__);
34}
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define __FUNCTION__
Definition: types.h:116

◆ CSR_API() [8/11]

CSR_API ( BaseSrvSetProcessShutdownParam  )

Definition at line 297 of file proc.c.

298{
299 PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &((PBASE_API_MESSAGE)ApiMessage)->Data.ShutdownParametersRequest;
300 PCSR_THREAD CsrThread = CsrGetClientThread();
301 ASSERT(CsrThread);
302
303 /* Only SHUTDOWN_NORETRY flag is valid for this API. The other private flags are for CSRSRV/WINSRV only. */
304 if (ShutdownParametersRequest->ShutdownFlags & ~SHUTDOWN_NORETRY)
305 {
306 /* If there were other flags specified, fail the call */
308 }
309
310 CsrThread->Process->ShutdownLevel = ShutdownParametersRequest->ShutdownLevel;
311 /* Notice that all the possible other private flags are reinitialized here */
312 CsrThread->Process->ShutdownFlags = ShutdownParametersRequest->ShutdownFlags;
313
314 return STATUS_SUCCESS;
315}
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

◆ CSR_API() [9/11]

CSR_API ( BaseSrvSetTermsrvAppInstallMode  )

Definition at line 42 of file proc.c.

43{
44 DPRINT1("%s not yet implemented\n", __FUNCTION__);
46}

◆ CSR_API() [10/11]

CSR_API ( BaseSrvSetTermsrvClientTimeZone  )

Definition at line 48 of file proc.c.

49{
50 DPRINT1("%s not yet implemented\n", __FUNCTION__);
52}

◆ CSR_API() [11/11]

CSR_API ( BaseSrvSxsCreateActivationContext  )

Definition at line 36 of file proc.c.

37{
38 DPRINT1("%s not yet implemented\n", __FUNCTION__);
40}

Variable Documentation

◆ UserNotifyProcessCreate

BASE_PROCESS_CREATE_NOTIFY_ROUTINE UserNotifyProcessCreate = NULL
static

Definition at line 20 of file proc.c.

Referenced by BaseSetProcessCreateNotify(), and CSR_API().