ReactOS 0.4.15-dev-7918-g2a2556c
api.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CsrAcquireProcessLock()    RtlEnterCriticalSection(&CsrProcessLock);
 
#define CsrReleaseProcessLock()    RtlLeaveCriticalSection(&CsrProcessLock);
 
#define ProcessStructureListLocked()    (CsrProcessLock.OwningThread == NtCurrentTeb()->ClientId.UniqueThread)
 
#define CsrAcquireWaitLock()    RtlEnterCriticalSection(&CsrWaitListsLock);
 
#define CsrReleaseWaitLock()    RtlLeaveCriticalSection(&CsrWaitListsLock);
 
#define CsrAcquireNtSessionLock()    RtlEnterCriticalSection(&CsrNtSessionLock);
 
#define CsrReleaseNtSessionLock()    RtlLeaveCriticalSection(&CsrNtSessionLock);
 
#define CSR_SERVER_DLL_MAX   4
 
#define NUMBER_THREAD_HASH_BUCKETS   257
 

Functions

 CSR_API (CsrSrvClientConnect)
 
 CSR_API (CsrSrvUnusedFunction)
 
NTSTATUS NTAPI CsrServerDllInitialization (IN PCSR_SERVER_DLL LoadedServerDll)
 
BOOLEAN NTAPI CsrCaptureArguments (IN PCSR_THREAD CsrThread, IN PCSR_API_MESSAGE ApiMessage)
 
VOID NTAPI CsrReleaseCapturedArguments (IN PCSR_API_MESSAGE ApiMessage)
 
NTSTATUS NTAPI CsrLoadServerDll (IN PCHAR DllString, IN PCHAR EntryPoint OPTIONAL, IN ULONG ServerId)
 
PCSR_THREAD NTAPI CsrAllocateThread (IN PCSR_PROCESS CsrProcess)
 
PCSR_PROCESS NTAPI CsrAllocateProcess (VOID)
 
VOID NTAPI CsrDeallocateProcess (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrInsertProcess (IN PCSR_PROCESS ParentProcess OPTIONAL, IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrRemoveProcess (IN PCSR_PROCESS CsrProcess)
 
NTSTATUS NTAPI CsrApiRequestThread (IN PVOID Parameter)
 
VOID NTAPI CsrSbApiRequestThread (IN PVOID Parameter)
 
NTSTATUS NTAPI CsrApiPortInitialize (VOID)
 
BOOLEAN NTAPI ProtectHandle (IN HANDLE ObjectHandle)
 
BOOLEAN NTAPI UnProtectHandle (IN HANDLE ObjectHandle)
 
NTSTATUS NTAPI CsrInsertThread (IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
 
VOID NTAPI CsrDeallocateThread (IN PCSR_THREAD CsrThread)
 
VOID NTAPI CsrLockedReferenceProcess (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrLockedReferenceThread (IN PCSR_THREAD CsrThread)
 
NTSTATUS NTAPI CsrInitializeProcessStructure (VOID)
 
PCSR_THREAD NTAPI CsrLocateThreadInProcess (IN PCSR_PROCESS CsrProcess OPTIONAL, IN PCLIENT_ID Cid)
 
PCSR_THREAD NTAPI CsrLocateThreadByClientId (OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
 
NTSTATUS NTAPI CsrInitializeNtSessionList (VOID)
 
NTSTATUS NTAPI CsrSrvAttachSharedSection (IN PCSR_PROCESS CsrProcess OPTIONAL, OUT PCSR_API_CONNECTINFO ConnectInfo)
 
NTSTATUS NTAPI CsrSrvCreateSharedSection (IN PCHAR ParameterValue)
 
VOID NTAPI CsrLockedDereferenceProcess (PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrLockedDereferenceThread (IN PCSR_THREAD CsrThread)
 
BOOLEAN NTAPI CsrNotifyWaitBlock (IN PCSR_WAIT_BLOCK WaitBlock, IN PLIST_ENTRY WaitList, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags, IN BOOLEAN DereferenceThread)
 
VOID NTAPI CsrReferenceNtSession (IN PCSR_NT_SESSION Session)
 
VOID NTAPI CsrDereferenceNtSession (IN PCSR_NT_SESSION Session, IN NTSTATUS ExitStatus)
 
NTSTATUS NTAPI CsrCreateSessionObjectDirectory (IN ULONG SessionId)
 
NTSTATUS NTAPI CsrCreateObjectDirectory (IN PCHAR ObjectDirectory)
 
NTSTATUS NTAPI CsrSbApiPortInitialize (VOID)
 
BOOLEAN NTAPI CsrSbCreateSession (IN PSB_API_MSG ApiMessage)
 
BOOLEAN NTAPI CsrSbTerminateSession (IN PSB_API_MSG ApiMessage)
 
BOOLEAN NTAPI CsrSbForeignSessionComplete (IN PSB_API_MSG ApiMessage)
 
BOOLEAN NTAPI CsrSbCreateProcess (IN PSB_API_MSG ApiMessage)
 
NTSTATUS NTAPI CsrSbApiHandleConnectionRequest (IN PSB_API_MSG Message)
 
NTSTATUS NTAPI CsrApiHandleConnectionRequest (IN PCSR_API_MESSAGE ApiMessage)
 
NTSTATUS NTAPI CsrCreateLocalSystemSD (OUT PSECURITY_DESCRIPTOR *LocalSystemSd)
 
NTSTATUS NTAPI CsrSetDirectorySecurity (IN HANDLE ObjectDirectory)
 

Variables

RTL_CRITICAL_SECTION CsrProcessLock
 
RTL_CRITICAL_SECTION CsrWaitListsLock
 
ULONG CsrDebug
 
HANDLE hBootstrapOk
 
HANDLE CsrApiPort
 
HANDLE CsrSmApiPort
 
HANDLE CsrSbApiPort
 
LIST_ENTRY CsrThreadHashTable [NUMBER_THREAD_HASH_BUCKETS]
 
PCSR_PROCESS CsrRootProcess
 
UNICODE_STRING CsrDirectoryName
 
ULONG CsrTotalPerProcessDataLength
 
SYSTEM_BASIC_INFORMATION CsrNtSysInfo
 
HANDLE CsrHeap
 
PVOID CsrSrvSharedSectionHeap
 
PVOIDCsrSrvSharedStaticServerData
 
HANDLE CsrInitializationEvent
 
PCSR_SERVER_DLL CsrLoadedServerDll [CSR_SERVER_DLL_MAX]
 
ULONG CsrMaxApiRequestThreads
 
UNICODE_STRING CsrSbApiPortName
 
UNICODE_STRING CsrApiPortName
 
HANDLE CsrObjectDirectory
 

Macro Definition Documentation

◆ CSR_SERVER_DLL_MAX

#define CSR_SERVER_DLL_MAX   4

Definition at line 34 of file api.h.

◆ CsrAcquireNtSessionLock

#define CsrAcquireNtSessionLock ( )     RtlEnterCriticalSection(&CsrNtSessionLock);

Definition at line 27 of file api.h.

◆ CsrAcquireProcessLock

#define CsrAcquireProcessLock ( )     RtlEnterCriticalSection(&CsrProcessLock);

Definition at line 12 of file api.h.

◆ CsrAcquireWaitLock

#define CsrAcquireWaitLock ( )     RtlEnterCriticalSection(&CsrWaitListsLock);

Definition at line 21 of file api.h.

◆ CsrReleaseNtSessionLock

#define CsrReleaseNtSessionLock ( )     RtlLeaveCriticalSection(&CsrNtSessionLock);

Definition at line 30 of file api.h.

◆ CsrReleaseProcessLock

#define CsrReleaseProcessLock ( )     RtlLeaveCriticalSection(&CsrProcessLock);

Definition at line 15 of file api.h.

◆ CsrReleaseWaitLock

#define CsrReleaseWaitLock ( )     RtlLeaveCriticalSection(&CsrWaitListsLock);

Definition at line 24 of file api.h.

◆ NUMBER_THREAD_HASH_BUCKETS

#define NUMBER_THREAD_HASH_BUCKETS   257

Definition at line 44 of file api.h.

◆ ProcessStructureListLocked

#define ProcessStructureListLocked ( )     (CsrProcessLock.OwningThread == NtCurrentTeb()->ClientId.UniqueThread)

Definition at line 18 of file api.h.

Function Documentation

◆ CSR_API() [1/2]

CSR_API ( CsrSrvClientConnect  )

Definition at line 293 of file server.c.

294{
296 PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage->Data.CsrClientConnect;
297 PCSR_SERVER_DLL ServerDll;
298 PCSR_PROCESS CurrentProcess = CsrGetClientThread()->Process;
299
300 /* Set default reply */
301 *ReplyCode = CsrReplyImmediately;
302
303 /* Validate the ServerID */
304 if (ClientConnect->ServerId >= CSR_SERVER_DLL_MAX)
305 {
307 }
308 else if (!CsrLoadedServerDll[ClientConnect->ServerId])
309 {
311 }
312
313 /* Validate the Message Buffer */
314 if (!(CsrValidateMessageBuffer(ApiMessage,
315 &ClientConnect->ConnectionInfo,
316 ClientConnect->ConnectionInfoSize,
317 sizeof(BYTE))))
318 {
319 /* Fail due to buffer overflow or other invalid buffer */
321 }
322
323 /* Load the Server DLL */
324 ServerDll = CsrLoadedServerDll[ClientConnect->ServerId];
325
326 /* Check if it has a Connect Callback */
327 if (ServerDll->ConnectCallback)
328 {
329 /* Call the callback */
330 Status = ServerDll->ConnectCallback(CurrentProcess,
331 ClientConnect->ConnectionInfo,
332 &ClientConnect->ConnectionInfoSize);
333 }
334 else
335 {
336 /* Assume success */
338 }
339
340 /* Return status */
341 return Status;
342}
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage, IN PVOID *Buffer, IN ULONG ElementCount, IN ULONG ElementSize)
Definition: api.c:1430
#define CsrGetClientThread()
Definition: csrsrv.h:77
@ CsrReplyImmediately
Definition: csrsrv.h:131
Status
Definition: gdiplustypes.h:25
#define STATUS_TOO_MANY_NAMES
Definition: ntstatus.h:441
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG ConnectionInfoSize
Definition: csrmsg.h:87
PVOID ConnectionInfo
Definition: csrmsg.h:86
PCSR_CONNECT_CALLBACK ConnectCallback
Definition: csrsrv.h:235
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char BYTE
Definition: xxhash.c:193

◆ CSR_API() [2/2]

CSR_API ( CsrSrvUnusedFunction  )

Definition at line 593 of file server.c.

594{
595 UNREFERENCED_PARAMETER(ApiMessage);
596 UNREFERENCED_PARAMETER(ReplyCode);
597
598 /* Deprecated */
600}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

◆ CsrAllocateProcess()

PCSR_PROCESS NTAPI CsrAllocateProcess ( VOID  )

Definition at line 189 of file procsup.c.

190{
192 ULONG TotalSize;
193
194 /* Calculate the amount of memory this should take */
195 TotalSize = sizeof(CSR_PROCESS) +
196 (CSR_SERVER_DLL_MAX * sizeof(PVOID)) +
198
199 /* Allocate a Process */
201 if (!CsrProcess) return NULL;
202
203 /* Handle the Sequence Number and protect against overflow */
204 CsrProcess->SequenceNumber = CsrProcessSequenceCount++;
206
207 /* Increase the reference count */
209
210 /* Initialize the Thread List */
211 InitializeListHead(&CsrProcess->ThreadList);
212
213 /* Return the Process */
214 return CsrProcess;
215}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
struct _CSR_PROCESS CSR_PROCESS
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
HANDLE CsrHeap
Definition: init.c:25
ULONG CsrTotalPerProcessDataLength
Definition: init.c:39
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:233
ULONG CsrProcessSequenceCount
Definition: procsup.c:30
uint32_t ULONG
Definition: typedefs.h:59
PKPROCESS CsrProcess
Definition: videoprt.c:39

Referenced by CsrCreateProcess(), CsrInitializeProcessStructure(), and CsrSbCreateSession().

◆ CsrAllocateThread()

PCSR_THREAD NTAPI CsrAllocateThread ( IN PCSR_PROCESS  CsrProcess)

Definition at line 119 of file thredsup.c.

120{
121 PCSR_THREAD CsrThread;
122
123 /* Allocate the structure */
124 CsrThread = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, sizeof(CSR_THREAD));
125 if (!CsrThread) return NULL;
126
127 /* Reference the Thread and Process */
128 CsrLockedReferenceThread(CsrThread);
130
131 /* Set the Parent Process */
132 CsrThread->Process = CsrProcess;
133
134 /* Return Thread */
135 return CsrThread;
136}
PCSR_PROCESS Process
Definition: csrsrv.h:69
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:233
VOID NTAPI CsrLockedReferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:154

Referenced by CsrAddStaticServerThread(), CsrCreateProcess(), CsrCreateRemoteThread(), CsrCreateThread(), CsrExecServerThread(), and CsrSbCreateSession().

◆ CsrApiHandleConnectionRequest()

NTSTATUS NTAPI CsrApiHandleConnectionRequest ( IN PCSR_API_MESSAGE  ApiMessage)

Definition at line 144 of file api.c.

145{
146 PCSR_THREAD CsrThread = NULL;
149 PCSR_API_CONNECTINFO ConnectInfo = &ApiMessage->ConnectionInfo;
150 BOOLEAN AllowConnection = FALSE;
151 REMOTE_PORT_VIEW RemotePortView;
153
154 /* Acquire the Process Lock */
156
157 /* Lookup the CSR Thread */
158 CsrThread = CsrLocateThreadByClientId(NULL, &ApiMessage->Header.ClientId);
159
160 /* Check if we have a thread */
161 if (CsrThread)
162 {
163 /* Get the Process and make sure we have it as well */
164 CsrProcess = CsrThread->Process;
165 if (CsrProcess)
166 {
167 /* Reference the Process */
169
170 /* Attach the Shared Section */
172 if (NT_SUCCESS(Status))
173 {
174 /* Allow the connection and return debugging flag */
175 ConnectInfo->DebugFlags = CsrDebug;
176 AllowConnection = TRUE;
177 }
178
179 /* Dereference the Process */
181 }
182 }
183
184 /* Release the Process Lock */
186
187 /* Setup the Port View Structure */
188 RemotePortView.Length = sizeof(REMOTE_PORT_VIEW);
189 RemotePortView.ViewSize = 0;
190 RemotePortView.ViewBase = NULL;
191
192 /* Save the Process ID */
193 ConnectInfo->ServerProcessId = NtCurrentTeb()->ClientId.UniqueProcess;
194
195 /* Accept the Connection */
196 ASSERT(!AllowConnection || CsrProcess);
198 AllowConnection ? UlongToPtr(CsrProcess->SequenceNumber) : 0,
199 &ApiMessage->Header,
200 AllowConnection,
201 NULL,
202 &RemotePortView);
203 if (!NT_SUCCESS(Status))
204 {
205 DPRINT1("CSRSS: NtAcceptConnectPort - failed. Status == %X\n", Status);
206 }
207 else if (AllowConnection)
208 {
209 if (CsrDebug & 2)
210 {
211 DPRINT1("CSRSS: ClientId: %lx.%lx has ClientView: Base=%p, Size=%lx\n",
212 ApiMessage->Header.ClientId.UniqueProcess,
213 ApiMessage->Header.ClientId.UniqueThread,
214 RemotePortView.ViewBase,
215 RemotePortView.ViewSize);
216 }
217
218 /* Set some Port Data in the Process */
219 CsrProcess->ClientPort = ServerPort;
220 CsrProcess->ClientViewBase = (ULONG_PTR)RemotePortView.ViewBase;
221 CsrProcess->ClientViewBounds = (ULONG_PTR)((ULONG_PTR)RemotePortView.ViewBase +
222 (ULONG_PTR)RemotePortView.ViewSize);
223
224 /* Complete the connection */
226 if (!NT_SUCCESS(Status))
227 {
228 DPRINT1("CSRSS: NtCompleteConnectPort - failed. Status == %X\n", Status);
229 }
230 }
231 else
232 {
233 DPRINT1("CSRSS: Rejecting Connection Request from ClientId: %lx.%lx\n",
234 ApiMessage->Header.ClientId.UniqueProcess,
235 ApiMessage->Header.ClientId.UniqueThread);
236 }
237
238 /* Return status to caller */
239 return Status;
240}
static const INTERNET_PORT ServerPort
Definition: CWebService.cpp:11
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI NtAcceptConnectPort(OUT PHANDLE PortHandle, IN PVOID PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage, IN BOOLEAN AcceptConnection, IN OUT PPORT_VIEW ServerView OPTIONAL, OUT PREMOTE_PORT_VIEW ClientView OPTIONAL)
Definition: complete.c:40
NTSTATUS NTAPI NtCompleteConnectPort(IN HANDLE PortHandle)
Definition: complete.c:423
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define UlongToPtr(u)
Definition: config.h:106
#define ULONG_PTR
Definition: config.h:101
#define NtCurrentTeb
#define ASSERT(a)
Definition: mode.c:44
struct _REMOTE_PORT_VIEW REMOTE_PORT_VIEW
HANDLE ServerProcessId
Definition: csrmsg.h:57
NTSTATUS NTAPI CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL, OUT PCSR_API_CONNECTINFO ConnectInfo)
Definition: server.c:482
ULONG CsrDebug
Definition: init.c:23
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
#define CsrAcquireProcessLock()
Definition: api.h:12
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
Definition: procsup.c:159
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by CsrApiRequestThread().

◆ CsrApiPortInitialize()

NTSTATUS NTAPI CsrApiPortInitialize ( VOID  )

Definition at line 900 of file api.c.

901{
902 ULONG Size;
905 HANDLE hRequestEvent, hThread;
907 PLIST_ENTRY ListHead, NextEntry;
909
910 /* Calculate how much space we'll need for the Port Name */
911 Size = CsrDirectoryName.Length + sizeof(CSR_PORT_NAME) + sizeof(WCHAR);
912
913 /* Create the buffer for it */
916
917 /* Setup the rest of the empty string */
923 if (CsrDebug & 1)
924 {
925 DPRINT1("CSRSS: Creating %wZ port and associated threads\n", &CsrApiPortName);
926 DPRINT1("CSRSS: sizeof( CONNECTINFO ) == %ld sizeof( API_MSG ) == %ld\n",
927 sizeof(CSR_API_CONNECTINFO), sizeof(CSR_API_MESSAGE));
928 }
929
930 /* FIXME: Create a Security Descriptor */
931
932 /* Initialize the Attributes */
935 0,
936 NULL,
937 NULL /* FIXME: Use the Security Descriptor */);
938
939 /* Create the Port Object */
942 sizeof(CSR_API_CONNECTINFO),
943 sizeof(CSR_API_MESSAGE),
944 16 * PAGE_SIZE);
945 if (NT_SUCCESS(Status))
946 {
947 /* Create the event the Port Thread will use */
948 Status = NtCreateEvent(&hRequestEvent,
950 NULL,
952 FALSE);
953 if (NT_SUCCESS(Status))
954 {
955 /* Create the Request Thread */
957 NULL,
958 TRUE,
959 0,
960 0,
961 0,
963 (PVOID)hRequestEvent,
964 &hThread,
965 &ClientId);
966 if (NT_SUCCESS(Status))
967 {
968 /* Add this as a static thread to CSRSRV */
970
971 /* Get the Thread List Pointers */
972 ListHead = &CsrRootProcess->ThreadList;
973 NextEntry = ListHead->Flink;
974
975 /* Start looping the list */
976 while (NextEntry != ListHead)
977 {
978 /* Get the Thread */
980
981 /* Start it up */
982 Status = NtResumeThread(ServerThread->ThreadHandle, NULL);
983
984 /* Is this a Server Thread? */
986 {
987 /* If so, then wait for it to initialize */
988 Status = NtWaitForSingleObject(hRequestEvent, FALSE, NULL);
990 }
991
992 /* Next thread */
993 NextEntry = NextEntry->Flink;
994 }
995
996 /* We don't need this anymore */
997 NtClose(hRequestEvent);
998 }
999 }
1000 }
1001
1002 /* Return */
1003 return Status;
1004}
UINT CALLBACK ServerThread(_Inout_ PVOID Parameter)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define CSR_PORT_NAME
Definition: csrmsg.h:17
PCSR_THREAD NTAPI CsrAddStaticServerThread(IN HANDLE hThread, IN PCLIENT_ID ClientId, IN ULONG ThreadFlags)
Definition: thredsup.c:512
@ CsrThreadIsServerThread
Definition: csrsrv.h:107
#define PAGE_SIZE
Definition: env_spec_w32.h:49
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI RtlCreateUserThread(_In_ PVOID ThreadContext, _Out_ HANDLE *OutThreadHandle, _Reserved_ PVOID Reserved1, _Reserved_ PVOID Reserved2, _Reserved_ PVOID Reserved3, _Reserved_ PVOID Reserved4, _Reserved_ PVOID Reserved5, _Reserved_ PVOID Reserved6, _Reserved_ PVOID Reserved7, _Reserved_ PVOID Reserved8)
HANDLE hThread
Definition: wizard.c:28
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
@ SynchronizationEvent
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:96
NTSTATUS NTAPI NtCreatePort(OUT PHANDLE PortHandle, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG MaxConnectInfoLength, IN ULONG MaxDataLength, IN ULONG MaxPoolUsage)
Definition: create.c:222
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
unsigned short USHORT
Definition: pedump.c:61
#define UNICODE_PATH_SEP
Definition: srv.h:49
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
USHORT MaximumLength
Definition: env_spec_w32.h:370
HANDLE CsrApiPort
Definition: connect.c:27
UNICODE_STRING CsrApiPortName
Definition: api.c:22
NTSTATUS NTAPI CsrApiRequestThread(IN PVOID Parameter)
Definition: api.c:336
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
UNICODE_STRING CsrDirectoryName
Definition: init.c:27
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static int Link(const char **args)
Definition: vfdcmd.c:2414
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CsrServerInitialization().

◆ CsrApiRequestThread()

NTSTATUS NTAPI CsrApiRequestThread ( IN PVOID  Parameter)

Definition at line 336 of file api.c.

337{
338 PTEB Teb = NtCurrentTeb();
339 LARGE_INTEGER TimeOut;
340 PCSR_THREAD CurrentThread, CsrThread;
342 CSR_REPLY_CODE ReplyCode;
343 PCSR_API_MESSAGE ReplyMsg;
344 CSR_API_MESSAGE ReceiveMsg;
346 PHARDERROR_MSG HardErrorMsg;
347 PVOID PortContext;
348 PCSR_SERVER_DLL ServerDll;
349 PCLIENT_DIED_MSG ClientDiedMsg;
350 PDBGKM_MSG DebugMessage;
351 ULONG ServerId, ApiId, MessageType, i;
352 HANDLE ReplyPort;
353
354 /* Setup LPC loop port and message */
355 ReplyMsg = NULL;
356 ReplyPort = CsrApiPort;
357
358 /* Connect to user32 */
359 while (!CsrConnectToUser())
360 {
361 /* Set up the timeout for the connect (30 seconds) */
362 TimeOut.QuadPart = -30 * 1000 * 1000 * 10;
363
364 /* Keep trying until we get a response */
365 Teb->Win32ClientInfo[0] = 0;
366 NtDelayExecution(FALSE, &TimeOut);
367 }
368
369 /* Get our thread */
370 CurrentThread = Teb->CsrClientThread;
371
372 /* If we got an event... */
373 if (Parameter)
374 {
375 /* Set it, to let stuff waiting on us load */
378
379 /* Increase the Thread Counts */
382 }
383
384 /* Now start the loop */
385 while (TRUE)
386 {
387 /* Make sure the real CID is set */
388 Teb->RealClientId = Teb->ClientId;
389
390#ifdef CSR_DBG
391 /* Debug check */
393 {
394 DPRINT1("CSRSRV: FATAL ERROR. CsrThread is Idle while holding %lu critical sections\n",
396 DPRINT1("CSRSRV: Last Receive Message %lx ReplyMessage %lx\n",
397 &ReceiveMsg, ReplyMsg);
399 }
400#endif
401
402 /* Wait for a message to come through */
403 Status = NtReplyWaitReceivePort(ReplyPort,
404 &PortContext,
405 &ReplyMsg->Header,
406 &ReceiveMsg.Header);
407
408 /* Check if we didn't get success */
409 if (Status != STATUS_SUCCESS)
410 {
411 /* Was it a failure or another success code? */
412 if (!NT_SUCCESS(Status))
413 {
414#ifdef CSR_DBG
415 /* Check for specific status cases */
416 if ((Status != STATUS_INVALID_CID) &&
418 ((Status != STATUS_INVALID_HANDLE) || (ReplyPort == CsrApiPort)))
419 {
420 /* Notify the debugger */
421 DPRINT1("CSRSS: ReceivePort failed - Status == %X\n", Status);
422 DPRINT1("CSRSS: ReplyPortHandle %lx CsrApiPort %lx\n", ReplyPort, CsrApiPort);
423 }
424#endif
425
426 /* We failed big time, so start out fresh */
427 ReplyMsg = NULL;
428 ReplyPort = CsrApiPort;
429 continue;
430 }
431 else
432 {
433 /* A strange "success" code, just try again */
434 DPRINT1("NtReplyWaitReceivePort returned \"success\" status 0x%x\n", Status);
435 continue;
436 }
437 }
438
439 // ASSERT(ReceiveMsg.Header.u1.s1.TotalLength >= sizeof(PORT_MESSAGE));
440 // ASSERT(ReceiveMsg.Header.u1.s1.TotalLength < sizeof(ReceiveMsg));
441
442 /* Use whatever Client ID we got */
443 Teb->RealClientId = ReceiveMsg.Header.ClientId;
444
445 /* Get the Message Type */
446 MessageType = ReceiveMsg.Header.u2.s2.Type;
447
448 /* Handle connection requests */
449 if (MessageType == LPC_CONNECTION_REQUEST)
450 {
451 /* Handle the Connection Request */
453
454 ReplyMsg = NULL;
455 ReplyPort = CsrApiPort;
456 continue;
457 }
458
459 /* It's some other kind of request. Get the lock for the lookup */
461
462 /* Now do the lookup to get the CSR_THREAD */
464 &ReceiveMsg.Header.ClientId);
465
466 /* Did we find a thread? */
467 if (!CsrThread)
468 {
469 /* This wasn't a CSR Thread, release lock */
471
472 /* If this was an exception, handle it */
473 if (MessageType == LPC_EXCEPTION)
474 {
475 ReplyMsg = &ReceiveMsg;
476 ReplyPort = CsrApiPort;
477 ReplyMsg->Status = DBG_CONTINUE;
478 }
479 else if (MessageType == LPC_PORT_CLOSED ||
480 MessageType == LPC_CLIENT_DIED)
481 {
482 /* The Client or Port are gone, loop again */
483 ReplyMsg = NULL;
484 ReplyPort = CsrApiPort;
485 }
486 else if (MessageType == LPC_ERROR_EVENT)
487 {
488 /* If it's a hard error, handle this too */
489 HardErrorMsg = (PHARDERROR_MSG)&ReceiveMsg;
490
491 /* Default it to unhandled */
492 HardErrorMsg->Response = ResponseNotHandled;
493
494 /* Check if there are free api threads */
497 {
498 /* Loop every Server DLL */
499 for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
500 {
501 /* Get the Server DLL */
502 ServerDll = CsrLoadedServerDll[i];
503
504 /* Check if it's valid and if it has a Hard Error Callback */
505 if ((ServerDll) && (ServerDll->HardErrorCallback))
506 {
507 /* Call it */
508 ServerDll->HardErrorCallback(NULL /* == CsrThread */, HardErrorMsg);
509
510 /* If it's handled, get out of here */
511 if (HardErrorMsg->Response != ResponseNotHandled) break;
512 }
513 }
514 }
515
516 /* Increase the thread count */
518
519 /* If the response was 0xFFFFFFFF, we'll ignore it */
520 if (HardErrorMsg->Response == 0xFFFFFFFF)
521 {
522 ReplyMsg = NULL;
523 ReplyPort = CsrApiPort;
524 }
525 else
526 {
527 ReplyMsg = &ReceiveMsg;
528 ReplyPort = CsrApiPort;
529 }
530 }
531 else if (MessageType == LPC_REQUEST)
532 {
533 /* This is an API Message coming from a non-CSR Thread */
534 ReplyMsg = &ReceiveMsg;
535 ReplyPort = CsrApiPort;
537 }
538 else if (MessageType == LPC_DATAGRAM)
539 {
540 /* This is an API call, get the Server ID */
541 ServerId = CSR_API_NUMBER_TO_SERVER_ID(ReceiveMsg.ApiNumber);
542
543 /* Make sure that the ID is within limits, and the Server DLL loaded */
544 ServerDll = NULL;
545 if ((ServerId >= CSR_SERVER_DLL_MAX) ||
546 (!(ServerDll = CsrLoadedServerDll[ServerId])))
547 {
548 /* We are beyond the Maximum Server ID */
549#ifdef CSR_DBG
550 DPRINT1("CSRSS: %lx is invalid ServerDllIndex (%08x)\n",
551 ServerId, ServerDll);
552 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
553#endif
554 ReplyMsg = NULL;
555 ReplyPort = CsrApiPort;
556 continue;
557 }
558
559 /* Get the API ID, normalized with our Base ID */
560 ApiId = CSR_API_NUMBER_TO_API_ID(ReceiveMsg.ApiNumber) - ServerDll->ApiBase;
561
562 /* Make sure that the ID is within limits, and the entry exists */
563 if (ApiId >= ServerDll->HighestApiSupported)
564 {
565 /* We are beyond the Maximum API ID, or it doesn't exist */
566#ifdef CSR_DBG
567 DPRINT1("CSRSS: %lx is invalid ApiTableIndex for %Z\n",
569 &ServerDll->Name);
570#endif
571 ReplyPort = CsrApiPort;
572 ReplyMsg = NULL;
573 continue;
574 }
575
576#ifdef CSR_DBG
577 if (CsrDebug & 2)
578 {
579 DPRINT1("[%02x] CSRSS: [%02x,%02x] - %s Api called from %08x\n",
581 ReceiveMsg.Header.ClientId.UniqueProcess,
582 ReceiveMsg.Header.ClientId.UniqueThread,
583 ServerDll->NameTable[ApiId],
584 NULL);
585 }
586#endif
587
588 /* Assume success */
589 ReceiveMsg.Status = STATUS_SUCCESS;
590
591 /* Validation complete, start SEH */
593 {
594 /* Make sure we have enough threads */
596
597 /* Call the API and get the reply code */
598 ReplyMsg = NULL;
599 ReplyPort = CsrApiPort;
600 ServerDll->DispatchTable[ApiId](&ReceiveMsg, &ReplyCode);
601
602 /* Increase the static thread count */
604 }
606 {
607 ReplyMsg = NULL;
608 ReplyPort = CsrApiPort;
609 }
610 _SEH2_END;
611 }
612 else
613 {
614 /* Some other ignored message type */
615 ReplyMsg = NULL;
616 ReplyPort = CsrApiPort;
617 }
618
619 /* Keep going */
620 continue;
621 }
622
623 /* We have a valid thread, was this an LPC Request? */
624 if (MessageType != LPC_REQUEST)
625 {
626 /* It's not an API, check if the client died */
627 if (MessageType == LPC_CLIENT_DIED)
628 {
629 /* Get the information and check if it matches our thread */
630 ClientDiedMsg = (PCLIENT_DIED_MSG)&ReceiveMsg;
631 if (ClientDiedMsg->CreateTime.QuadPart == CsrThread->CreateTime.QuadPart)
632 {
633 /* Now we reply to the dying client */
634 ReplyPort = CsrThread->Process->ClientPort;
635
636 /* Reference the thread */
637 CsrLockedReferenceThread(CsrThread);
638
639 /* Destroy the thread in the API Message */
640 CsrDestroyThread(&ReceiveMsg.Header.ClientId);
641
642 /* Check if the thread was actually ourselves */
643 if (CsrProcess->ThreadCount == 1)
644 {
645 /* Kill the process manually here */
646 CsrDestroyProcess(&CsrThread->ClientId, 0);
647 }
648
649 /* Remove our extra reference */
651 }
652
653 /* Release the lock and keep looping */
655
656 ReplyMsg = NULL;
657 ReplyPort = CsrApiPort;
658 continue;
659 }
660
661 /* Reference the thread and release the lock */
662 CsrLockedReferenceThread(CsrThread);
664
665 /* Check if this was an exception */
666 if (MessageType == LPC_EXCEPTION)
667 {
668 /* Kill the process */
670
671 /* Destroy it from CSR */
673
674 /* Return a Debug Message */
675 DebugMessage = (PDBGKM_MSG)&ReceiveMsg;
676 DebugMessage->ReturnedStatus = DBG_CONTINUE;
677 ReplyMsg = &ReceiveMsg;
678 ReplyPort = CsrApiPort;
679
680 /* Remove our extra reference */
681 CsrDereferenceThread(CsrThread);
682 }
683 else if (MessageType == LPC_ERROR_EVENT)
684 {
685 /* If it's a hard error, handle this too */
686 HardErrorMsg = (PHARDERROR_MSG)&ReceiveMsg;
687
688 /* Default it to unhandled */
689 HardErrorMsg->Response = ResponseNotHandled;
690
691 /* Check if there are free api threads */
694 {
695 /* Loop every Server DLL */
696 for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
697 {
698 /* Get the Server DLL */
699 ServerDll = CsrLoadedServerDll[i];
700
701 /* Check if it's valid and if it has a Hard Error Callback */
702 if ((ServerDll) && (ServerDll->HardErrorCallback))
703 {
704 /* Call it */
705 ServerDll->HardErrorCallback(CsrThread, HardErrorMsg);
706
707 /* If it's handled, get out of here */
708 if (HardErrorMsg->Response != ResponseNotHandled) break;
709 }
710 }
711 }
712
713 /* Increase the thread count */
715
716 /* If the response was 0xFFFFFFFF, we'll ignore it */
717 if (HardErrorMsg->Response == 0xFFFFFFFF)
718 {
719 ReplyMsg = NULL;
720 ReplyPort = CsrApiPort;
721 }
722 else
723 {
724 CsrDereferenceThread(CsrThread);
725 ReplyMsg = &ReceiveMsg;
726 ReplyPort = CsrApiPort;
727 }
728 }
729 else
730 {
731 /* Something else */
732 CsrDereferenceThread(CsrThread);
733 ReplyMsg = NULL;
734 }
735
736 /* Keep looping */
737 continue;
738 }
739
740 /* We got an API Request */
741 CsrLockedReferenceThread(CsrThread);
743
744 /* This is an API call, get the Server ID */
745 ServerId = CSR_API_NUMBER_TO_SERVER_ID(ReceiveMsg.ApiNumber);
746
747 /* Make sure that the ID is within limits, and the Server DLL loaded */
748 ServerDll = NULL;
749 if ((ServerId >= CSR_SERVER_DLL_MAX) ||
750 (!(ServerDll = CsrLoadedServerDll[ServerId])))
751 {
752 /* We are beyond the Maximum Server ID */
753#ifdef CSR_DBG
754 DPRINT1("CSRSS: %lx is invalid ServerDllIndex (%08x)\n",
755 ServerId, ServerDll);
756 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
757#endif
758 ReplyPort = CsrApiPort;
759 ReplyMsg = &ReceiveMsg;
761 CsrDereferenceThread(CsrThread);
762 continue;
763 }
764
765 /* Get the API ID, normalized with our Base ID */
766 ApiId = CSR_API_NUMBER_TO_API_ID(ReceiveMsg.ApiNumber) - ServerDll->ApiBase;
767
768 /* Make sure that the ID is within limits, and the entry exists */
769 if (ApiId >= ServerDll->HighestApiSupported)
770 {
771#ifdef CSR_DBG
772 /* We are beyond the Maximum API ID, or it doesn't exist */
773 DPRINT1("CSRSS: %lx is invalid ApiTableIndex for %Z\n",
775 &ServerDll->Name);
776#endif
777 ReplyPort = CsrApiPort;
778 ReplyMsg = &ReceiveMsg;
780 CsrDereferenceThread(CsrThread);
781 continue;
782 }
783
784#ifdef CSR_DBG
785 if (CsrDebug & 2)
786 {
787 DPRINT1("[%02x] CSRSS: [%02x,%02x] - %s Api called from %08x, Process %08x - %08x\n",
789 ReceiveMsg.Header.ClientId.UniqueProcess,
790 ReceiveMsg.Header.ClientId.UniqueThread,
791 ServerDll->NameTable[ApiId],
792 CsrThread,
793 CsrThread->Process,
794 CsrProcess);
795 }
796#endif
797
798 /* Assume success */
799 ReplyMsg = &ReceiveMsg;
800 ReceiveMsg.Status = STATUS_SUCCESS;
801
802 /* Now we reply to a particular client */
803 ReplyPort = CsrThread->Process->ClientPort;
804
805 /* Check if there's a capture buffer */
806 if (ReceiveMsg.CsrCaptureData)
807 {
808 /* Capture the arguments */
809 if (!CsrCaptureArguments(CsrThread, &ReceiveMsg))
810 {
811 /* Ignore this message if we failed to get the arguments */
812 CsrDereferenceThread(CsrThread);
813 continue;
814 }
815 }
816
817 /* Validation complete, start SEH */
819 {
820 /* Make sure we have enough threads */
822
823 Teb->CsrClientThread = CsrThread;
824
825 /* Call the API, get the reply code and return the result */
826 ReplyCode = CsrReplyImmediately;
827 ReplyMsg->Status = ServerDll->DispatchTable[ApiId](&ReceiveMsg, &ReplyCode);
828
829 /* Increase the static thread count */
831
832 Teb->CsrClientThread = CurrentThread;
833
834 if (ReplyCode == CsrReplyAlreadySent)
835 {
836 if (ReceiveMsg.CsrCaptureData)
837 {
838 CsrReleaseCapturedArguments(&ReceiveMsg);
839 }
840 ReplyMsg = NULL;
841 ReplyPort = CsrApiPort;
842 CsrDereferenceThread(CsrThread);
843 }
844 else if (ReplyCode == CsrReplyDeadClient)
845 {
846 /* Reply to the death message */
847 NTSTATUS Status2;
848 Status2 = NtReplyPort(ReplyPort, &ReplyMsg->Header);
849 if (!NT_SUCCESS(Status2))
850 DPRINT1("CSRSS: Error while replying to the death message, Status 0x%lx\n", Status2);
851
852 /* Reply back to the API port now */
853 ReplyMsg = NULL;
854 ReplyPort = CsrApiPort;
855 CsrDereferenceThread(CsrThread);
856 }
857 else if (ReplyCode == CsrReplyPending)
858 {
859 ReplyMsg = NULL;
860 ReplyPort = CsrApiPort;
861 }
862 else
863 {
864 if (ReceiveMsg.CsrCaptureData)
865 {
866 CsrReleaseCapturedArguments(&ReceiveMsg);
867 }
868 CsrDereferenceThread(CsrThread);
869 }
870 }
872 {
873 ReplyMsg = NULL;
874 ReplyPort = CsrApiPort;
875 }
876 _SEH2_END;
877 }
878
879 /* We're out of the loop for some reason, terminate! */
881 return Status;
882}
#define NtCurrentPeb()
Definition: FLS.c:22
#define CSR_API_NUMBER_TO_API_ID(ApiNumber)
Definition: csrmsg.h:43
#define CSR_API_NUMBER_TO_SERVER_ID(ApiNumber)
Definition: csrmsg.h:40
EXCEPTION_DISPOSITION NTAPI CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: server.c:643
NTSTATUS NTAPI CsrDestroyProcess(IN PCLIENT_ID Cid, IN NTSTATUS ExitStatus)
Definition: procsup.c:735
enum _CSR_REPLY_CODE CSR_REPLY_CODE
NTSTATUS NTAPI CsrDestroyThread(IN PCLIENT_ID Cid)
Definition: thredsup.c:814
VOID NTAPI CsrDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:776
@ CsrReplyAlreadySent
Definition: csrsrv.h:134
@ CsrReplyDeadClient
Definition: csrsrv.h:133
@ CsrReplyPending
Definition: csrsrv.h:132
struct _DBGKM_MSG * PDBGKM_MSG
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1527
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSYSAPI void WINAPI DbgBreakPoint(void)
struct _CLIENT_DIED_MSG * PCLIENT_DIED_MSG
#define LPC_ERROR_EVENT
Definition: port.c:101
#define LPC_EXCEPTION
Definition: port.c:99
#define LPC_CLIENT_DIED
Definition: port.c:98
#define LPC_REQUEST
Definition: port.c:93
#define LPC_DATAGRAM
Definition: port.c:95
#define LPC_CONNECTION_REQUEST
Definition: port.c:102
#define LPC_PORT_CLOSED
Definition: port.c:97
struct _HARDERROR_MSG * PHARDERROR_MSG
@ ResponseNotHandled
Definition: extypes.h:200
NTSTATUS NtTerminateThread(IN HANDLE ThreadHandle OPTIONAL, IN NTSTATUS ExitStatus)
Definition: kill.c:1279
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
NTSTATUS NTAPI NtDelayExecution(IN BOOLEAN Alertable, IN PLARGE_INTEGER DelayInterval)
Definition: wait.c:876
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
NTSTATUS NTAPI NtReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE ReplyMessage)
Definition: reply.c:190
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
#define STATUS_INVALID_CID
Definition: ntstatus.h:248
#define DBG_CONTINUE
Definition: ntstatus.h:47
#define STATUS_ABANDONED
Definition: ntstatus.h:75
#define STATUS_ILLEGAL_FUNCTION
Definition: ntstatus.h:411
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:158
LARGE_INTEGER CreateTime
Definition: lpctypes.h:270
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
NTSTATUS Status
Definition: csrmsg.h:110
PCSR_CAPTURE_BUFFER CsrCaptureData
Definition: csrmsg.h:108
PORT_MESSAGE Header
Definition: csrmsg.h:102
CSR_API_NUMBER ApiNumber
Definition: csrmsg.h:109
HANDLE ClientPort
Definition: csrsrv.h:43
PCSR_HARDERROR_CALLBACK HardErrorCallback
Definition: csrsrv.h:237
ULONG HighestApiSupported
Definition: csrsrv.h:223
ANSI_STRING Name
Definition: csrsrv.h:218
PCSR_API_ROUTINE * DispatchTable
Definition: csrsrv.h:224
ULONG ApiBase
Definition: csrsrv.h:222
LARGE_INTEGER CreateTime
Definition: csrsrv.h:65
CLIENT_ID ClientId
Definition: csrsrv.h:68
NTSTATUS ReturnedStatus
Definition: dbgktypes.h:210
ULONG Response
Definition: extypes.h:670
CLIENT_ID ClientId
Definition: winternl.h:1751
Definition: compat.h:836
ULONG Win32ClientInfo[31]
Definition: compat.h:847
ULONG CountOfOwnedCriticalSections
Definition: compat.h:844
CLIENT_ID ClientId
Definition: compat.h:839
CLIENT_ID RealClientId
Definition: compat.h:861
PVOID CsrClientThread
Definition: compat.h:845
VOID NTAPI CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage)
Definition: api.c:1337
volatile ULONG CsrpStaticThreadCount
Definition: api.c:23
NTSTATUS NTAPI CsrApiHandleConnectionRequest(IN PCSR_API_MESSAGE ApiMessage)
Definition: api.c:144
volatile ULONG CsrpDynamicThreadTotal
Definition: api.c:24
PCSR_THREAD NTAPI CsrConnectToUser(VOID)
Definition: api.c:1021
NTSTATUS NTAPI CsrpCheckRequestThreads(VOID)
Definition: api.c:259
BOOLEAN NTAPI CsrCaptureArguments(IN PCSR_THREAD CsrThread, IN PCSR_API_MESSAGE ApiMessage)
Definition: api.c:1123
VOID NTAPI CsrLockedReferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:154
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
LONGLONG QuadPart
Definition: typedefs.h:114
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:323
#define NtCurrentThread()

Referenced by CsrApiPortInitialize(), and CsrpCheckRequestThreads().

◆ CsrCaptureArguments()

BOOLEAN NTAPI CsrCaptureArguments ( IN PCSR_THREAD  CsrThread,
IN PCSR_API_MESSAGE  ApiMessage 
)

Definition at line 1123 of file api.c.

1125{
1126 PCSR_PROCESS CsrProcess = CsrThread->Process;
1127 PCSR_CAPTURE_BUFFER ClientCaptureBuffer, ServerCaptureBuffer = NULL;
1128 ULONG_PTR EndOfClientBuffer;
1129 SIZE_T SizeOfBufferThroughOffsetsArray;
1130 SIZE_T BufferDistance;
1131 ULONG Length;
1132 ULONG PointerCount;
1133 PULONG_PTR OffsetPointer;
1134 ULONG_PTR CurrentOffset;
1135
1136 /* Get the buffer we got from whoever called NTDLL */
1137 ClientCaptureBuffer = ApiMessage->CsrCaptureData;
1138
1139 /* Use SEH to validate and capture the client buffer */
1140 _SEH2_TRY
1141 {
1142 /* Check whether at least the buffer's header is inside our mapped section */
1143 if ( ((ULONG_PTR)ClientCaptureBuffer < CsrProcess->ClientViewBase) ||
1144 (((ULONG_PTR)ClientCaptureBuffer + FIELD_OFFSET(CSR_CAPTURE_BUFFER, PointerOffsetsArray))
1145 >= CsrProcess->ClientViewBounds) )
1146 {
1147#ifdef CSR_DBG
1148 DPRINT1("*** CSRSS: CaptureBuffer outside of ClientView 1\n");
1149 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
1150#endif
1151 /* Return failure */
1152 ApiMessage->Status = STATUS_INVALID_PARAMETER;
1153 _SEH2_YIELD(return FALSE);
1154 }
1155
1156 /* Capture the buffer length */
1157 Length = ((volatile CSR_CAPTURE_BUFFER*)ClientCaptureBuffer)->Size;
1158
1159 /*
1160 * Now check if the remaining of the buffer is inside our mapped section.
1161 * Take also care for any possible wrap-around of the buffer end-address.
1162 */
1163 EndOfClientBuffer = (ULONG_PTR)ClientCaptureBuffer + Length;
1164 if ( (EndOfClientBuffer < (ULONG_PTR)ClientCaptureBuffer) ||
1165 (EndOfClientBuffer >= CsrProcess->ClientViewBounds) )
1166 {
1167#ifdef CSR_DBG
1168 DPRINT1("*** CSRSS: CaptureBuffer outside of ClientView 2\n");
1169 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
1170#endif
1171 /* Return failure */
1172 ApiMessage->Status = STATUS_INVALID_PARAMETER;
1173 _SEH2_YIELD(return FALSE);
1174 }
1175
1176 /* Capture the pointer count */
1177 PointerCount = ((volatile CSR_CAPTURE_BUFFER*)ClientCaptureBuffer)->PointerCount;
1178
1179 /*
1180 * Check whether the total buffer size and the pointer count are consistent
1181 * -- the array of offsets must be contained inside the buffer.
1182 */
1183 SizeOfBufferThroughOffsetsArray =
1184 FIELD_OFFSET(CSR_CAPTURE_BUFFER, PointerOffsetsArray) +
1185 (PointerCount * sizeof(PVOID));
1186 if ( (PointerCount > MAXUSHORT) ||
1187 (SizeOfBufferThroughOffsetsArray > Length) )
1188 {
1189#ifdef CSR_DBG
1190 DPRINT1("*** CSRSS: CaptureBuffer %p has bad length\n", ClientCaptureBuffer);
1191 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
1192#endif
1193 /* Return failure */
1194 ApiMessage->Status = STATUS_INVALID_PARAMETER;
1195 _SEH2_YIELD(return FALSE);
1196 }
1197 }
1199 {
1200#ifdef CSR_DBG
1201 DPRINT1("*** CSRSS: Took exception during capture %x\n", _SEH2_GetExceptionCode());
1202 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
1203#endif
1204 /* Return failure */
1205 ApiMessage->Status = STATUS_INVALID_PARAMETER;
1206 _SEH2_YIELD(return FALSE);
1207 }
1208 _SEH2_END;
1209
1210 /* We validated the client buffer, now allocate the server buffer */
1211 ServerCaptureBuffer = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, Length);
1212 if (!ServerCaptureBuffer)
1213 {
1214 /* We're out of memory */
1215 ApiMessage->Status = STATUS_NO_MEMORY;
1216 return FALSE;
1217 }
1218
1219 /*
1220 * Copy the client's buffer and ensure we use the correct buffer length
1221 * and pointer count we captured and used for validation earlier on.
1222 */
1223 _SEH2_TRY
1224 {
1225 RtlMoveMemory(ServerCaptureBuffer, ClientCaptureBuffer, Length);
1226 }
1228 {
1229#ifdef CSR_DBG
1230 DPRINT1("*** CSRSS: Took exception during capture %x\n", _SEH2_GetExceptionCode());
1231 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
1232#endif
1233 /* Failure, free the buffer and return */
1234 RtlFreeHeap(CsrHeap, 0, ServerCaptureBuffer);
1235 ApiMessage->Status = STATUS_INVALID_PARAMETER;
1236 _SEH2_YIELD(return FALSE);
1237 }
1238 _SEH2_END;
1239
1240 ServerCaptureBuffer->Size = Length;
1241 ServerCaptureBuffer->PointerCount = PointerCount;
1242
1243 /* Calculate the difference between our buffer and the client's */
1244 BufferDistance = (ULONG_PTR)ServerCaptureBuffer - (ULONG_PTR)ClientCaptureBuffer;
1245
1246 /*
1247 * All the pointer offsets correspond to pointers that point
1248 * to the server data buffer instead of the client one.
1249 */
1250 // PointerCount = ServerCaptureBuffer->PointerCount;
1251 OffsetPointer = ServerCaptureBuffer->PointerOffsetsArray;
1252 while (PointerCount--)
1253 {
1254 CurrentOffset = *OffsetPointer;
1255
1256 if (CurrentOffset != 0)
1257 {
1258 /*
1259 * Check whether the offset is pointer-aligned and whether
1260 * it points inside CSR_API_MESSAGE::Data.ApiMessageData.
1261 */
1262 if ( ((CurrentOffset & (sizeof(PVOID)-1)) != 0) ||
1263 (CurrentOffset < FIELD_OFFSET(CSR_API_MESSAGE, Data.ApiMessageData)) ||
1264 (CurrentOffset >= sizeof(CSR_API_MESSAGE)) )
1265 {
1266#ifdef CSR_DBG
1267 DPRINT1("*** CSRSS: CaptureBuffer MessagePointer outside of message\n");
1268 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
1269#endif
1270 /* Invalid pointer, fail */
1271 ApiMessage->Status = STATUS_INVALID_PARAMETER;
1272 break;
1273 }
1274
1275 /* Get the pointer corresponding to the offset */
1276 CurrentOffset += (ULONG_PTR)ApiMessage;
1277
1278 /* Validate the bounds of the current pointed pointer */
1279 if ( (*(PULONG_PTR)CurrentOffset >= ((ULONG_PTR)ClientCaptureBuffer +
1280 SizeOfBufferThroughOffsetsArray)) &&
1281 (*(PULONG_PTR)CurrentOffset <= (EndOfClientBuffer - sizeof(PVOID))) )
1282 {
1283 /* Modify the pointed pointer to take into account its new position */
1284 *(PULONG_PTR)CurrentOffset += BufferDistance;
1285 }
1286 else
1287 {
1288#ifdef CSR_DBG
1289 DPRINT1("*** CSRSS: CaptureBuffer MessagePointer outside of ClientView\n");
1290 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
1291#endif
1292 /* Invalid pointer, fail */
1293 ApiMessage->Status = STATUS_INVALID_PARAMETER;
1294 break;
1295 }
1296 }
1297
1298 ++OffsetPointer;
1299 }
1300
1301 /* Check if we got success */
1302 if (ApiMessage->Status != STATUS_SUCCESS)
1303 {
1304 /* Failure, free the buffer and return */
1305 RtlFreeHeap(CsrHeap, 0, ServerCaptureBuffer);
1306 return FALSE;
1307 }
1308 else
1309 {
1310 /* Success, save the previous buffer and use the server capture buffer */
1311 ServerCaptureBuffer->PreviousCaptureBuffer = ClientCaptureBuffer;
1312 ApiMessage->CsrCaptureData = ServerCaptureBuffer;
1313 }
1314
1315 /* Success */
1316 return TRUE;
1317}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
ULONG PointerCount
Definition: csrmsg.h:94
ULONG_PTR PointerOffsetsArray[ANYSIZE_ARRAY]
Definition: csrmsg.h:96
struct _CSR_CAPTURE_BUFFER * PreviousCaptureBuffer
Definition: csrmsg.h:93
uint32_t * PULONG_PTR
Definition: typedefs.h:65
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define MAXUSHORT
Definition: typedefs.h:83
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264

Referenced by CsrApiRequestThread().

◆ CsrCreateLocalSystemSD()

NTSTATUS NTAPI CsrCreateLocalSystemSD ( OUT PSECURITY_DESCRIPTOR LocalSystemSd)

this API is used with CsrPopulateDosDevices, deprecated in r55585. NTSTATUS NTAPI CsrPopulateDosDevicesDirectory(IN HANDLE DosDevicesDirectory, IN PPROCESS_DEVICEMAP_INFORMATION DeviceMap);

Definition at line 847 of file init.c.

848{
850 PSID SystemSid;
852 PSECURITY_DESCRIPTOR SystemSd;
853 PACL Dacl;
855
856 /* Initialize the System SID */
859 0, 0, 0, 0, 0, 0, 0,
860 &SystemSid);
861
862 /* Get the length of the SID */
863 Length = RtlLengthSid(SystemSid) + sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE);
864
865 /* Allocate a buffer for the Security Descriptor, with SID and DACL */
867
868 /* Set the pointer to the DACL */
870
871 /* Now create the SD itself */
873 if (!NT_SUCCESS(Status)) goto Quit;
874
875 /* Create the DACL for it */
877
878 /* Create the ACE */
880 if (!NT_SUCCESS(Status)) goto Quit;
881
882 /* Clear the DACL in the SD */
884 if (!NT_SUCCESS(Status)) goto Quit;
885
886Quit:
887 if (!NT_SUCCESS(Status))
888 {
889 RtlFreeHeap(CsrHeap, 0, SystemSd);
890 SystemSd = NULL;
891 }
892
893 /* Free the SID and return*/
894 RtlFreeSid(SystemSid);
895 *LocalSystemSd = SystemSd;
896 return Status;
897}
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
#define PORT_ALL_ACCESS
Definition: lpctypes.h:47
struct _ACL ACL
struct _ACL * PACL
Definition: security.c:105
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1593
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
static SID_IDENTIFIER_AUTHORITY NtSidAuthority
Definition: samrpc.c:14
HANDLE CsrHeap
Definition: init.c:25
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:574
#define ACL_REVISION2
Definition: setypes.h:43
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define SECURITY_DESCRIPTOR_MIN_LENGTH
Definition: setypes.h:815
#define ACL_REVISION
Definition: setypes.h:39

Referenced by CsrSbApiPortInitialize().

◆ CsrCreateObjectDirectory()

NTSTATUS NTAPI CsrCreateObjectDirectory ( IN PCHAR  ObjectDirectory)

◆ CsrCreateSessionObjectDirectory()

NTSTATUS NTAPI CsrCreateSessionObjectDirectory ( IN ULONG  SessionId)

Definition at line 424 of file init.c.

425{
426 WCHAR SessionBuffer[512], BnoBuffer[512];
427 UNICODE_STRING SessionString, BnoString;
429 HANDLE BnoHandle;
430 SECURITY_DESCRIPTOR DosDevicesSd;
432
433 /* Generate the Session BNOLINKS Directory name */
434 swprintf(SessionBuffer, L"%ws\\BNOLINKS", SESSION_ROOT);
435 RtlInitUnicodeString(&SessionString, SessionBuffer);
436
437 /* Create it */
439 &SessionString,
441 NULL,
442 NULL);
446 if (!NT_SUCCESS(Status))
447 {
448 DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
449 "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
450 return Status;
451 }
452
453 /* Now add the Session ID */
454 swprintf(SessionBuffer, L"%ld", Session);
455 RtlInitUnicodeString(&SessionString, SessionBuffer);
456
457 /* Check if this is the first Session */
458 if (Session)
459 {
460 /* Not the first, so the name will be slighly more complex */
461 swprintf(BnoBuffer, L"%ws\\%ld\\BaseNamedObjects", SESSION_ROOT, Session);
462 RtlInitUnicodeString(&BnoString, BnoBuffer);
463 }
464 else
465 {
466 /* Use the direct name */
467 RtlInitUnicodeString(&BnoString, L"\\BaseNamedObjects");
468 }
469
470 /* Create the symlink */
472 &SessionString,
475 NULL);
479 &BnoString);
480 if (!NT_SUCCESS(Status))
481 {
482 DPRINT1("CSRSS: NtCreateSymbolicLinkObject failed in "
483 "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
484 return Status;
485 }
486
487 /* Create the \DosDevices Security Descriptor */
488 Status = GetDosDevicesProtection(&DosDevicesSd);
489 if (!NT_SUCCESS(Status)) return Status;
490
491 /* Now create a directory for this session */
492 swprintf(SessionBuffer, L"%ws\\%ld", SESSION_ROOT, Session);
493 RtlInitUnicodeString(&SessionString, SessionBuffer);
494
495 /* Create the directory */
497 &SessionString,
499 0,
500 &DosDevicesSd);
504 if (!NT_SUCCESS(Status))
505 {
506 DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
507 "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
508 FreeDosDevicesProtection(&DosDevicesSd);
509 return Status;
510 }
511
512 /* Next, create a directory for this session's DOS Devices */
513 RtlInitUnicodeString(&SessionString, L"DosDevices");
515 &SessionString,
518 &DosDevicesSd);
522 if (!NT_SUCCESS(Status))
523 {
524 DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
525 "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
526 }
527
528 /* Release the Security Descriptor */
529 FreeDosDevicesProtection(&DosDevicesSd);
530
531 /* Return */
532 return Status;
533}
#define swprintf
Definition: precomp.h:40
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI NtCreateDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:765
#define SESSION_ROOT
Definition: srv.h:44
VOID NTAPI FreeDosDevicesProtection(IN PSECURITY_DESCRIPTOR DosDevicesSd)
Definition: init.c:392
HANDLE BNOLinksDirectory
Definition: init.c:41
NTSTATUS NTAPI GetDosDevicesProtection(OUT PSECURITY_DESCRIPTOR DosDevicesSd)
Definition: init.c:209
HANDLE DosDevicesDirectory
Definition: init.c:43
HANDLE SessionObjectDirectory
Definition: init.c:42

Referenced by CsrParseServerCommandLine().

◆ CsrDeallocateProcess()

VOID NTAPI CsrDeallocateProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 297 of file procsup.c.

298{
299 /* Free the process object from the heap */
301}

Referenced by CsrCreateProcess(), CsrProcessRefcountZero(), and CsrSbCreateSession().

◆ CsrDeallocateThread()

VOID NTAPI CsrDeallocateThread ( IN PCSR_THREAD  CsrThread)

Definition at line 345 of file thredsup.c.

346{
347 /* Free the process object from the heap */
348 // ASSERT(CsrThread->WaitBlock == NULL);
349 RtlFreeHeap(CsrHeap, 0, CsrThread);
350}

Referenced by CsrCreateProcess(), CsrCreateRemoteThread(), CsrCreateThread(), CsrExecServerThread(), CsrSbCreateSession(), and CsrThreadRefcountZero().

◆ CsrDereferenceNtSession()

VOID NTAPI CsrDereferenceNtSession ( IN PCSR_NT_SESSION  Session,
IN NTSTATUS  ExitStatus 
)

Definition at line 156 of file session.c.

158{
159 /* Acquire the lock */
161
162 /* Sanity checks */
163 ASSERT(!IsListEmpty(&Session->SessionLink));
164 ASSERT(Session->SessionId != 0);
165 ASSERT(Session->ReferenceCount != 0);
166
167 /* Dereference the Session Object */
168 if ((--Session->ReferenceCount) == 0)
169 {
170 /* Remove it from the list */
171 RemoveEntryList(&Session->SessionLink);
172
173 /* Release the lock */
175
176 /* Tell SM that we're done here */
177 SmSessionComplete(CsrSmApiPort, Session->SessionId, ExitStatus);
178
179 /* Free the Session Object */
180 RtlFreeHeap(CsrHeap, 0, Session);
181 }
182 else
183 {
184 /* Release the lock, the Session is still active */
186 }
187}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:867
NTSTATUS NTAPI SmSessionComplete(_In_ HANDLE SmApiPort, _In_ ULONG SessionId, _In_ NTSTATUS SessionStatus)
This function is called by an environment subsystem server to tell the SM it has terminated the sessi...
Definition: smclient.c:220
HANDLE CsrSmApiPort
Definition: init.c:31
#define CsrAcquireNtSessionLock()
Definition: api.h:27
#define CsrReleaseNtSessionLock()
Definition: api.h:30

Referenced by CsrProcessRefcountZero().

◆ CsrInitializeNtSessionList()

NTSTATUS NTAPI CsrInitializeNtSessionList ( VOID  )

Definition at line 53 of file session.c.

54{
55 /* Initialize the Session List */
57
58 /* Initialize the Session Lock */
60}
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
RTL_CRITICAL_SECTION CsrNtSessionLock
Definition: session.c:18
LIST_ENTRY CsrNtSessionList
Definition: session.c:19

Referenced by CsrServerInitialization().

◆ CsrInitializeProcessStructure()

NTSTATUS NTAPI CsrInitializeProcessStructure ( VOID  )

Definition at line 255 of file procsup.c.

256{
258 ULONG i;
259
260 /* Initialize the Lock */
262 if (!NT_SUCCESS(Status)) return Status;
263
264 /* Set up the Root Process */
266 if (!CsrRootProcess) return STATUS_NO_MEMORY;
267
268 /* Set up the minimal information for it */
271 CsrRootProcess->ClientId = NtCurrentTeb()->ClientId;
272
273 /* Initialize the Thread Hash List */
275
276 /* Initialize the Wait Lock */
278}
CLIENT_ID ClientId
Definition: csrsrv.h:38
LIST_ENTRY ListLink
Definition: csrsrv.h:39
HANDLE ProcessHandle
Definition: csrsrv.h:46
RTL_CRITICAL_SECTION CsrWaitListsLock
Definition: api.h:10
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21
#define NUMBER_THREAD_HASH_BUCKETS
Definition: api.h:44
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
PCSR_PROCESS NTAPI CsrAllocateProcess(VOID)
Definition: procsup.c:189
RTL_CRITICAL_SECTION CsrProcessLock
Definition: procsup.c:21
PVOID HANDLE
Definition: typedefs.h:73

Referenced by CsrServerInitialization().

◆ CsrInsertProcess()

VOID NTAPI CsrInsertProcess ( IN PCSR_PROCESS ParentProcess  OPTIONAL,
IN PCSR_PROCESS  CsrProcess 
)

Definition at line 366 of file procsup.c.

368{
369 PCSR_SERVER_DLL ServerDll;
370 ULONG i;
372
373 /* Insert it into the Root List */
375
376 /* Notify the Server DLLs */
377 for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
378 {
379 /* Get the current Server DLL */
380 ServerDll = CsrLoadedServerDll[i];
381
382 /* Make sure it's valid and that it has callback */
383 if (ServerDll && ServerDll->NewProcessCallback)
384 {
385 ServerDll->NewProcessCallback(ParentProcess, CsrProcess);
386 }
387 }
388}
#define InsertTailList(ListHead, Entry)
PCSR_NEWPROCESS_CALLBACK NewProcessCallback
Definition: csrsrv.h:239
#define ProcessStructureListLocked()
Definition: api.h:18

Referenced by CsrCreateProcess(), and CsrSbCreateSession().

◆ CsrInsertThread()

NTSTATUS NTAPI CsrInsertThread ( IN PCSR_PROCESS  Process,
IN PCSR_THREAD  Thread 
)

Definition at line 297 of file thredsup.c.

299{
300 ULONG i;
303 // ASSERT(ProcessStructureListLocked());
304
305 /* Make sure the thread isn't already dead by the time we got this */
306 Status = NtQueryInformationThread(Thread->ThreadHandle,
308 &ThreadInfo,
309 sizeof(ThreadInfo),
310 NULL);
311 if (!NT_SUCCESS(Status)) return Status;
313
314 /* Insert it into the Regular List */
315 InsertTailList(&Process->ThreadList, &Thread->Link);
316
317 /* Increase Thread Count */
318 Process->ThreadCount++;
319
320 /* Hash the Thread */
321 i = CsrHashThread(Thread->ClientId.UniqueThread);
322
323 /* Insert it there too */
325 return STATUS_SUCCESS;
326}
@ ThreadIsTerminated
Definition: compat.h:955
#define InsertHeadList(ListHead, Entry)
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
struct _ThreadInfo ThreadInfo
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2624
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
#define CsrHashThread(t)
Definition: thredsup.c:17
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21

Referenced by CsrCreateProcess(), CsrCreateRemoteThread(), CsrCreateThread(), and CsrSbCreateSession().

◆ CsrLoadServerDll()

NTSTATUS NTAPI CsrLoadServerDll ( IN PCHAR  DllString,
IN PCHAR EntryPoint  OPTIONAL,
IN ULONG  ServerId 
)

Definition at line 126 of file server.c.

129{
131 ANSI_STRING DllName;
132 UNICODE_STRING TempString, ErrorString;
134 HANDLE hServerDll = NULL;
135 ULONG Size;
136 PCSR_SERVER_DLL ServerDll;
137 STRING EntryPointString;
138 PCSR_SERVER_DLL_INIT_CALLBACK ServerDllInitProcedure;
140
141 /* Check if it's beyond the maximum we support */
142 if (ServerId >= CSR_SERVER_DLL_MAX) return STATUS_TOO_MANY_NAMES;
143
144 /* Check if it's already been loaded */
145 if (CsrLoadedServerDll[ServerId]) return STATUS_INVALID_PARAMETER;
146
147 /* Convert the name to Unicode */
148 ASSERT(DllString != NULL);
149 RtlInitAnsiString(&DllName, DllString);
150 Status = RtlAnsiStringToUnicodeString(&TempString, &DllName, TRUE);
151 if (!NT_SUCCESS(Status)) return Status;
152
153 /* If we are loading ourselves, don't actually load us */
154 if (ServerId != CSRSRV_SERVERDLL_INDEX)
155 {
156 /* Load the DLL */
157 Status = LdrLoadDll(NULL, 0, &TempString, &hServerDll);
158 if (!NT_SUCCESS(Status))
159 {
160 /* Setup error parameters */
161 Parameters[0] = (ULONG_PTR)&TempString;
162 Parameters[1] = (ULONG_PTR)&ErrorString;
163 RtlInitUnicodeString(&ErrorString, L"Default Load Path");
164
165 /* Send a hard error */
167 2,
168 3,
170 OptionOk,
171 &Response);
172 }
173
174 /* Get rid of the string */
175 RtlFreeUnicodeString(&TempString);
176 if (!NT_SUCCESS(Status)) return Status;
177 }
178
179 /* Allocate a CSR DLL Object */
180 Size = sizeof(CSR_SERVER_DLL) + DllName.MaximumLength;
182 if (!ServerDll)
183 {
184 if (hServerDll) LdrUnloadDll(hServerDll);
185 return STATUS_NO_MEMORY;
186 }
187
188 /* Set up the Object */
189 ServerDll->Length = Size;
190 ServerDll->SizeOfProcessData = 0;
191 ServerDll->SharedSection = CsrSrvSharedSectionHeap; // Send to the server dll our shared heap pointer.
192 ServerDll->Name.Length = DllName.Length;
193 ServerDll->Name.MaximumLength = DllName.MaximumLength;
194 ServerDll->Name.Buffer = (PCHAR)(ServerDll + 1);
195 if (DllName.Length)
196 {
197 strncpy(ServerDll->Name.Buffer, DllName.Buffer, DllName.Length);
198 }
199 ServerDll->ServerId = ServerId;
200 ServerDll->ServerHandle = hServerDll;
201
202 /* Now get the entrypoint */
203 if (hServerDll)
204 {
205 /* Initialize a string for the entrypoint, or use the default */
206 RtlInitAnsiString(&EntryPointString,
207 EntryPoint ? EntryPoint : "ServerDllInitialization");
208
209 /* Get a pointer to it */
210 Status = LdrGetProcedureAddress(hServerDll,
211 &EntryPointString,
212 0,
213 (PVOID)&ServerDllInitProcedure);
214 }
215 else
216 {
217 /* No handle, so we are loading ourselves */
218#ifdef CSR_DBG
219 RtlInitAnsiString(&EntryPointString, "CsrServerDllInitialization");
220#endif
221 ServerDllInitProcedure = CsrServerDllInitialization;
223 }
224
225 /* Check if we got the pointer, and call it */
226 if (NT_SUCCESS(Status))
227 {
228 /* Call the Server DLL entrypoint */
230 {
231 Status = ServerDllInitProcedure(ServerDll);
232 }
234 {
236#ifdef CSR_DBG
237 DPRINT1("CSRSS: Exception 0x%lx while calling Server DLL entrypoint %Z!%Z()\n",
238 Status, &DllName, &EntryPointString);
239#endif
240 }
241 _SEH2_END;
242
243 if (NT_SUCCESS(Status))
244 {
245 /*
246 * Add this Server's Per-Process Data Size to the total that each
247 * process will need.
248 */
250
251 /* Save the pointer in our list */
252 CsrLoadedServerDll[ServerDll->ServerId] = ServerDll;
253
254 /* Does it use our generic heap? */
255 if (ServerDll->SharedSection != CsrSrvSharedSectionHeap)
256 {
257 /* No, save the pointer to its shared section in our list */
258 CsrSrvSharedStaticServerData[ServerDll->ServerId] = ServerDll->SharedSection;
259 }
260 }
261 }
262
263 if (!NT_SUCCESS(Status))
264 {
265 /* Server Init failed, unload it */
266 if (hServerDll) LdrUnloadDll(hServerDll);
267
268 /* Delete the Object */
269 RtlFreeHeap(CsrHeap, 0, ServerDll);
270 }
271
272 /* Return to caller */
273 return Status;
274}
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define CSRSRV_SERVERDLL_INDEX
Definition: csrmsg.h:20
struct _CSR_SERVER_DLL CSR_SERVER_DLL
NTSTATUS(NTAPI * PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll)
Definition: csrsrv.h:253
std::wstring STRING
Definition: fontsub.cpp:33
NTSTATUS NTAPI NtRaiseHardError(IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
Definition: harderr.c:551
NTSTATUS NTAPI LdrUnloadDll(_In_ PVOID BaseAddress)
Definition: ldrapi.c:1331
NTSTATUS NTAPI DECLSPEC_HOTPATCH LdrLoadDll(_In_opt_ PWSTR SearchPath, _In_opt_ PULONG DllCharacteristics, _In_ PUNICODE_STRING DllName, _Out_ PVOID *BaseAddress)
Definition: ldrapi.c:312
NTSTATUS NTAPI LdrGetProcedureAddress(_In_ PVOID BaseAddress, _In_opt_ _When_(Ordinal==0, _Notnull_) PANSI_STRING Name, _In_opt_ _When_(Name==NULL, _In_range_(>, 0)) ULONG Ordinal, _Out_ PVOID *ProcedureAddress)
Definition: ldrapi.c:829
#define PCHAR
Definition: match.c:90
@ OptionOk
Definition: extypes.h:187
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
Definition: ncftp.h:89
USHORT MaximumLength
Definition: env_spec_w32.h:377
PVOID SharedSection
Definition: csrsrv.h:238
ULONG ServerId
Definition: csrsrv.h:220
ULONG Length
Definition: csrsrv.h:217
HANDLE ServerHandle
Definition: csrsrv.h:219
ULONG SizeOfProcessData
Definition: csrsrv.h:234
ULONG CsrTotalPerProcessDataLength
Definition: init.c:39
NTSTATUS NTAPI CsrServerDllInitialization(IN PCSR_SERVER_DLL LoadedServerDll)
EXCEPTION_DISPOSITION NTAPI CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: server.c:643
PVOID CsrSrvSharedSectionHeap
Definition: server.c:21
PVOID * CsrSrvSharedStaticServerData
Definition: server.c:23
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869

Referenced by CsrParseServerCommandLine().

◆ CsrLocateThreadByClientId()

PCSR_THREAD NTAPI CsrLocateThreadByClientId ( OUT PCSR_PROCESS *Process  OPTIONAL,
IN PCLIENT_ID  ClientId 
)

Definition at line 182 of file thredsup.c.

184{
185 ULONG i;
186 PLIST_ENTRY ListHead, NextEntry;
187 PCSR_THREAD FoundThread;
188 // ASSERT(ProcessStructureListLocked());
189
190 if (Process) *Process = NULL;
191
192 /* Hash the Thread */
194
195 /* Set the list pointers */
196 ListHead = &CsrThreadHashTable[i];
197 NextEntry = ListHead->Flink;
198
199 /* Star the loop */
200 while (NextEntry != ListHead)
201 {
202 /* Get the thread */
203 FoundThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, HashLinks);
204
205 /* Move to the next entry */
206 NextEntry = NextEntry->Flink;
207
208 /* Compare the CID */
209 // if (*(PULONGLONG)&FoundThread->ClientId == *(PULONGLONG)ClientId)
210 if ( FoundThread->ClientId.UniqueProcess == ClientId->UniqueProcess &&
211 FoundThread->ClientId.UniqueThread == ClientId->UniqueThread )
212 {
213 /* Match found, return the process */
214 if (Process) *Process = FoundThread->Process;
215
216 /* Return thread too */
217 return FoundThread;
218 }
219 }
220
221 /* Nothing found */
222 return NULL;
223}

Referenced by CsrApiHandleConnectionRequest(), CsrApiRequestThread(), CsrCreateProcess(), CsrCreateThread(), CsrDestroyProcess(), and CsrDestroyThread().

◆ CsrLocateThreadInProcess()

PCSR_THREAD NTAPI CsrLocateThreadInProcess ( IN PCSR_PROCESS CsrProcess  OPTIONAL,
IN PCLIENT_ID  Cid 
)

Definition at line 248 of file thredsup.c.

250{
251 PLIST_ENTRY ListHead, NextEntry;
252 PCSR_THREAD FoundThread = NULL;
253
254 /* Use the Root Process if none was specified */
256
257 /* Save the List pointers */
258 ListHead = &CsrProcess->ThreadList;
259 NextEntry = ListHead->Flink;
260
261 /* Start the Loop */
262 while (NextEntry != ListHead)
263 {
264 /* Get Thread Entry */
265 FoundThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
266
267 /* Check for TID Match */
268 if (FoundThread->ClientId.UniqueThread == Cid->UniqueThread) break;
269
270 /* Move to the next entry */
271 NextEntry = NextEntry->Flink;
272 }
273
274 /* Return what we found */
275 return FoundThread;
276}

Referenced by CsrConnectToUser().

◆ CsrLockedDereferenceProcess()

VOID NTAPI CsrLockedDereferenceProcess ( PCSR_PROCESS  CsrProcess)

Definition at line 159 of file procsup.c.

160{
162
163 /* Decrease reference count */
164 LockCount = --CsrProcess->ReferenceCount;
165 ASSERT(LockCount >= 0);
166 if (LockCount == 0)
167 {
168 /* Call the generic cleanup code */
169 DPRINT1("Should kill process: %p\n", CsrProcess);
171 /* Acquire the lock again, it was released in CsrProcessRefcountZero */
173 }
174}
LONG LockCount
Definition: comsup.c:6
long LONG
Definition: pedump.c:60
VOID NTAPI CsrProcessRefcountZero(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:119

Referenced by CsrApiHandleConnectionRequest(), CsrRemoveThread(), CsrShutdownProcesses(), and CsrUnlockProcess().

◆ CsrLockedDereferenceThread()

VOID NTAPI CsrLockedDereferenceThread ( IN PCSR_THREAD  CsrThread)

Definition at line 467 of file thredsup.c.

468{
470
471 /* Decrease reference count */
472 LockCount = --CsrThread->ReferenceCount;
473 ASSERT(LockCount >= 0);
474 if (LockCount == 0)
475 {
476 /* Call the generic cleanup code */
477 CsrThreadRefcountZero(CsrThread);
478 /* Acquire the lock again, it was released by CsrThreadRefcountZero */
480 }
481}
VOID NTAPI CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:424

Referenced by CsrApiRequestThread(), CsrDestroyProcess(), CsrDestroyThread(), and CsrUnlockThread().

◆ CsrLockedReferenceProcess()

VOID NTAPI CsrLockedReferenceProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 233 of file procsup.c.

234{
235 /* Increment the reference count */
236 ++CsrProcess->ReferenceCount;
237}

Referenced by CsrAllocateProcess(), CsrAllocateThread(), CsrApiHandleConnectionRequest(), CsrLockProcessByClientId(), and CsrShutdownProcesses().

◆ CsrLockedReferenceThread()

VOID NTAPI CsrLockedReferenceThread ( IN PCSR_THREAD  CsrThread)

Definition at line 154 of file thredsup.c.

155{
156 /* Increment the reference count */
157 ++CsrThread->ReferenceCount;
158}

Referenced by CsrAllocateThread(), CsrApiRequestThread(), and CsrLockThreadByClientId().

◆ CsrNotifyWaitBlock()

BOOLEAN NTAPI CsrNotifyWaitBlock ( IN PCSR_WAIT_BLOCK  WaitBlock,
IN PLIST_ENTRY  WaitList,
IN PVOID  WaitArgument1,
IN PVOID  WaitArgument2,
IN ULONG  WaitFlags,
IN BOOLEAN  DereferenceThread 
)

Definition at line 120 of file wait.c.

126{
127 /* Call the wait function */
128 if (WaitBlock->WaitFunction(WaitList,
129 WaitBlock->WaitThread,
130 &WaitBlock->WaitApiMessage,
131 WaitBlock->WaitContext,
132 WaitArgument1,
133 WaitArgument2,
134 WaitFlags))
135 {
136 /* The wait is done, clear the block */
137 WaitBlock->WaitThread->WaitBlock = NULL;
138
139 /* Check for captured arguments */
140 if (WaitBlock->WaitApiMessage.CsrCaptureData)
141 {
142 /* Release them */
143 CsrReleaseCapturedArguments(&WaitBlock->WaitApiMessage);
144 }
145
146 /* Reply to the port */
147 NtReplyPort(WaitBlock->WaitThread->Process->ClientPort,
148 &WaitBlock->WaitApiMessage.Header);
149
150 /* Check if we should dereference the thread */
151 if (DereferenceThread)
152 {
153 /* Remove it from the Wait List */
154 if (WaitBlock->WaitList.Flink)
155 {
156 RemoveEntryList(&WaitBlock->WaitList);
157 }
158
159 /* Dereference the thread */
160 CsrDereferenceThread(WaitBlock->WaitThread);
161
162 /* Free the wait block */
163 RtlFreeHeap(CsrHeap, 0, WaitBlock);
164 }
165 else
166 {
167 /* The wait is complete, but the thread is being kept alive */
168 WaitBlock->WaitFunction = NULL;
169 }
170
171 /* The wait succeeded */
172 return TRUE;
173 }
174
175 /* The wait failed */
176 return FALSE;
177}

Referenced by CsrDestroyProcess(), CsrDestroyThread(), and CsrNotifyWait().

◆ CsrReferenceNtSession()

VOID NTAPI CsrReferenceNtSession ( IN PCSR_NT_SESSION  Session)

Definition at line 118 of file session.c.

119{
120 /* Acquire the lock */
122
123 /* Sanity checks */
124 ASSERT(!IsListEmpty(&Session->SessionLink));
125 ASSERT(Session->SessionId != 0);
126 ASSERT(Session->ReferenceCount != 0);
127
128 /* Increase the reference count */
129 Session->ReferenceCount++;
130
131 /* Release the lock */
133}

Referenced by CsrCreateProcess().

◆ CsrReleaseCapturedArguments()

VOID NTAPI CsrReleaseCapturedArguments ( IN PCSR_API_MESSAGE  ApiMessage)

Definition at line 1337 of file api.c.

1338{
1339 PCSR_CAPTURE_BUFFER ServerCaptureBuffer, ClientCaptureBuffer;
1340 SIZE_T BufferDistance;
1341 ULONG PointerCount;
1342 PULONG_PTR OffsetPointer;
1343 ULONG_PTR CurrentOffset;
1344
1345 /* Get the server capture buffer */
1346 ServerCaptureBuffer = ApiMessage->CsrCaptureData;
1347
1348 /* Do not continue if there is no captured buffer */
1349 if (!ServerCaptureBuffer) return;
1350
1351 /* If there is one, get the corresponding client capture buffer */
1352 ClientCaptureBuffer = ServerCaptureBuffer->PreviousCaptureBuffer;
1353
1354 /* Free the previous one and use again the client capture buffer */
1355 ServerCaptureBuffer->PreviousCaptureBuffer = NULL;
1356 ApiMessage->CsrCaptureData = ClientCaptureBuffer;
1357
1358 /* Calculate the difference between our buffer and the client's */
1359 BufferDistance = (ULONG_PTR)ServerCaptureBuffer - (ULONG_PTR)ClientCaptureBuffer;
1360
1361 /*
1362 * All the pointer offsets correspond to pointers that point
1363 * to the client data buffer instead of the server one (reverse
1364 * the logic of CsrCaptureArguments()).
1365 */
1366 PointerCount = ServerCaptureBuffer->PointerCount;
1367 OffsetPointer = ServerCaptureBuffer->PointerOffsetsArray;
1368 while (PointerCount--)
1369 {
1370 CurrentOffset = *OffsetPointer;
1371
1372 if (CurrentOffset != 0)
1373 {
1374 /* Get the pointer corresponding to the offset */
1375 CurrentOffset += (ULONG_PTR)ApiMessage;
1376
1377 /* Modify the pointed pointer to take into account its new position */
1378 *(PULONG_PTR)CurrentOffset -= BufferDistance;
1379 }
1380
1381 ++OffsetPointer;
1382 }
1383
1384 /* Copy the data back into the client buffer */
1385 _SEH2_TRY
1386 {
1387 RtlMoveMemory(ClientCaptureBuffer, ServerCaptureBuffer, ServerCaptureBuffer->Size);
1388 }
1390 {
1391#ifdef CSR_DBG
1392 DPRINT1("*** CSRSS: Took exception during release %x\n", _SEH2_GetExceptionCode());
1393 if (NtCurrentPeb()->BeingDebugged) DbgBreakPoint();
1394#endif
1395 /* Return failure */
1396 ApiMessage->Status = _SEH2_GetExceptionCode();
1397 }
1398 _SEH2_END;
1399
1400 /* Free our allocated buffer */
1401 RtlFreeHeap(CsrHeap, 0, ServerCaptureBuffer);
1402}

Referenced by CsrApiRequestThread(), and CsrNotifyWaitBlock().

◆ CsrRemoveProcess()

VOID NTAPI CsrRemoveProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 320 of file procsup.c.

321{
322 PCSR_SERVER_DLL ServerDll;
323 ULONG i;
325
326 /* Remove us from the Process List */
327 RemoveEntryList(&CsrProcess->ListLink);
328
329 /* Release the lock */
331
332 /* Loop every Server DLL */
333 for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
334 {
335 /* Get the Server DLL */
336 ServerDll = CsrLoadedServerDll[i];
337
338 /* Check if it's valid and if it has a Disconnect Callback */
339 if (ServerDll && ServerDll->DisconnectCallback)
340 {
341 /* Call it */
342 ServerDll->DisconnectCallback(CsrProcess);
343 }
344 }
345}
PCSR_DISCONNECT_CALLBACK DisconnectCallback
Definition: csrsrv.h:236

Referenced by CsrProcessRefcountZero().

◆ CsrSbApiHandleConnectionRequest()

NTSTATUS NTAPI CsrSbApiHandleConnectionRequest ( IN PSB_API_MSG  Message)

Definition at line 434 of file session.c.

435{
437 REMOTE_PORT_VIEW RemotePortView;
438 HANDLE hPort;
439
440 /* Set the Port View Structure Length */
441 RemotePortView.Length = sizeof(REMOTE_PORT_VIEW);
442
443 /* Accept the connection */
445 NULL,
446 &Message->h,
447 TRUE,
448 NULL,
449 &RemotePortView);
450 if (!NT_SUCCESS(Status))
451 {
452 DPRINT1("CSRSS: Sb Accept Connection failed %lx\n", Status);
453 return Status;
454 }
455
456 /* Complete the Connection */
458 if (!NT_SUCCESS(Status))
459 {
460 DPRINT1("CSRSS: Sb Complete Connection failed %lx\n",Status);
461 }
462
463 /* Return status */
464 return Status;
465}
static const WCHAR Message[]
Definition: register.c:74

Referenced by CsrSbApiRequestThread().

◆ CsrSbApiPortInitialize()

NTSTATUS NTAPI CsrSbApiPortInitialize ( VOID  )

Definition at line 915 of file init.c.

916{
917 ULONG Size;
921 HANDLE hRequestThread;
923
924 /* Calculate how much space we'll need for the Port Name */
925 Size = CsrDirectoryName.Length + sizeof(SB_PORT_NAME) + sizeof(WCHAR);
926
927 /* Create the buffer for it */
930
931 /* Setup the rest of the empty string */
934
935 /* Now append the full port name */
939 if (CsrDebug & 2) DPRINT1("CSRSS: Creating %wZ port and associated thread\n", &CsrSbApiPortName);
940
941 /* Create Security Descriptor for this Port */
943 if (!NT_SUCCESS(Status)) return Status;
944
945 /* Initialize the Attributes */
948 0,
949 NULL,
950 PortSd);
951
952 /* Create the Port Object */
955 sizeof(SB_CONNECTION_INFO),
956 sizeof(SB_API_MSG),
957 32 * sizeof(SB_API_MSG));
958 if (PortSd) RtlFreeHeap(CsrHeap, 0, PortSd);
959
960 if (NT_SUCCESS(Status))
961 {
962 /* Create the Thread to handle the API Requests */
964 NULL,
965 TRUE,
966 0,
967 0,
968 0,
970 NULL,
971 &hRequestThread,
972 &ClientId);
973 if (NT_SUCCESS(Status))
974 {
975 /* Add it as a Static Server Thread */
977 &ClientId,
978 0);
979
980 /* Activate it */
981 Status = NtResumeThread(hRequestThread, NULL);
982 }
983 }
984
985 return Status;
986}
#define SB_PORT_NAME
Definition: srv.h:47
VOID NTAPI CsrSbApiRequestThread(IN PVOID Parameter)
Definition: session.c:484
PCSR_THREAD CsrSbApiRequestThreadPtr
Definition: init.c:30
UNICODE_STRING CsrDirectoryName
Definition: init.c:27
HANDLE CsrSbApiPort
Definition: init.c:29
ULONG CsrDebug
Definition: init.c:23
UNICODE_STRING CsrSbApiPortName
Definition: init.c:28
NTSTATUS NTAPI CsrCreateLocalSystemSD(OUT PSECURITY_DESCRIPTOR *LocalSystemSd)
Definition: init.c:847

Referenced by CsrServerInitialization().

◆ CsrSbApiRequestThread()

VOID NTAPI CsrSbApiRequestThread ( IN PVOID  Parameter)

Definition at line 484 of file session.c.

485{
487 SB_API_MSG ReceiveMsg;
488 PSB_API_MSG ReplyMsg = NULL;
489 PVOID PortContext;
490 ULONG MessageType;
491
492 /* Start the loop */
493 while (TRUE)
494 {
495 /* Wait for a message to come in */
497 &PortContext,
498 &ReplyMsg->h,
499 &ReceiveMsg.h);
500
501 /* Check if we didn't get success */
502 if (Status != STATUS_SUCCESS)
503 {
504 /* If we only got a warning, keep going */
505 if (NT_SUCCESS(Status)) continue;
506
507 /* We failed big time, so start out fresh */
508 ReplyMsg = NULL;
509 DPRINT1("CSRSS: ReceivePort failed - Status == %X\n", Status);
510 continue;
511 }
512
513 /* Save the message type */
514 MessageType = ReceiveMsg.h.u2.s2.Type;
515
516 /* Check if this is a connection request */
517 if (MessageType == LPC_CONNECTION_REQUEST)
518 {
519 /* Handle connection request */
521
522 /* Start over */
523 ReplyMsg = NULL;
524 continue;
525 }
526
527 /* Check if the port died */
528 if (MessageType == LPC_PORT_CLOSED)
529 {
530 /* Close the handle if we have one */
531 if (PortContext) NtClose((HANDLE)PortContext);
532
533 /* Client died, start over */
534 ReplyMsg = NULL;
535 continue;
536 }
537 else if (MessageType == LPC_CLIENT_DIED)
538 {
539 /* Client died, start over */
540 ReplyMsg = NULL;
541 continue;
542 }
543
544 /*
545 * It's an API Message, check if it's within limits. If it's not,
546 * the NT Behaviour is to set this to the Maximum API.
547 */
548 if (ReceiveMsg.ApiNumber > SbpMaxApiNumber)
549 {
550 ReceiveMsg.ApiNumber = SbpMaxApiNumber;
551 DPRINT1("CSRSS: %lx is invalid Sb ApiNumber\n", ReceiveMsg.ApiNumber);
552 }
553
554 /* Reuse the message */
555 ReplyMsg = &ReceiveMsg;
556
557 /* Make sure that the message is supported */
558 if (ReceiveMsg.ApiNumber < SbpMaxApiNumber)
559 {
560 /* Call the API */
561 if (!CsrServerSbApiDispatch[ReceiveMsg.ApiNumber](&ReceiveMsg))
562 {
563 DPRINT1("CSRSS: %s Session Api called and failed\n",
564 CsrServerSbApiName[ReceiveMsg.ApiNumber]);
565
566 /* It failed, so return nothing */
567 ReplyMsg = NULL;
568 }
569 }
570 else
571 {
572 /* We don't support this API Number */
574 }
575 }
576}
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
@ SbpMaxApiNumber
Definition: smmsg.h:151
NTSTATUS ReturnValue
Definition: smmsg.h:239
SB_API_NUMBER ApiNumber
Definition: smmsg.h:238
PORT_MESSAGE h
Definition: smmsg.h:232
HANDLE CsrSbApiPort
Definition: init.c:29
NTSTATUS NTAPI CsrSbApiHandleConnectionRequest(IN PSB_API_MSG Message)
Definition: session.c:434
PSB_API_ROUTINE CsrServerSbApiDispatch[SbpMaxApiNumber - SbpCreateSession]
Definition: session.c:21
PCHAR CsrServerSbApiName[SbpMaxApiNumber - SbpCreateSession]
Definition: session.c:29

Referenced by CsrSbApiPortInitialize().

◆ CsrSbCreateProcess()

BOOLEAN NTAPI CsrSbCreateProcess ( IN PSB_API_MSG  ApiMessage)

Definition at line 410 of file session.c.

411{
412 ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
413 return TRUE;
414}

◆ CsrSbCreateSession()

BOOLEAN NTAPI CsrSbCreateSession ( IN PSB_API_MSG  ApiMessage)

Definition at line 208 of file session.c.

209{
210 PSB_CREATE_SESSION_MSG CreateSession = &ApiMessage->u.CreateSession;
213 PCSR_THREAD CsrThread;
214 PCSR_SERVER_DLL ServerDll;
215 PVOID ProcessData;
217 KERNEL_USER_TIMES KernelTimes;
218 ULONG i;
219
220 /* Save the Process and Thread Handles */
221 hProcess = CreateSession->ProcessInfo.ProcessHandle;
222 hThread = CreateSession->ProcessInfo.ThreadHandle;
223
224 /* Lock the Processes */
226
227 /* Allocate a new process */
229 if (!CsrProcess)
230 {
231 /* Fail */
232 ApiMessage->ReturnValue = STATUS_NO_MEMORY;
234 return TRUE;
235 }
236
237 /* Set the Exception Port for us */
240 &CsrApiPort,
241 sizeof(CsrApiPort));
242
243 /* Check for success */
244 if (!NT_SUCCESS(Status))
245 {
246 /* Fail the request */
249
250 /* Strange as it seems, NTSTATUSes are actually returned */
252 }
253
254 /* Get the Create Time */
257 &KernelTimes,
258 sizeof(KernelTimes),
259 NULL);
260
261 /* Check for success */
262 if (!NT_SUCCESS(Status))
263 {
264 /* Fail the request */
267
268 /* Strange as it seems, NTSTATUSes are actually returned */
269 return (BOOLEAN)Status;
270 }
271
272 /* Allocate a new Thread */
273 CsrThread = CsrAllocateThread(CsrProcess);
274 if (!CsrThread)
275 {
276 /* Fail the request */
279
280 ApiMessage->ReturnValue = STATUS_NO_MEMORY;
281 return TRUE;
282 }
283
284 /* Setup the Thread Object */
285 CsrThread->CreateTime = KernelTimes.CreateTime;
286 CsrThread->ClientId = CreateSession->ProcessInfo.ClientId;
287 CsrThread->ThreadHandle = hThread;
289 CsrThread->Flags = 0;
290
291 /* Insert it into the Process List */
292 Status = CsrInsertThread(CsrProcess, CsrThread);
293 if (!NT_SUCCESS(Status))
294 {
295 /* Bail out */
297 CsrDeallocateThread(CsrThread);
299
300 /* Strange as it seems, NTSTATUSes are actually returned */
301 return (BOOLEAN)Status;
302 }
303
304 /* Setup Process Data */
305 CsrProcess->ClientId = CreateSession->ProcessInfo.ClientId;
306 CsrProcess->ProcessHandle = hProcess;
307 CsrProcess->NtSession = CsrAllocateNtSession(CreateSession->SessionId);
308
309 /* Set the Process Priority */
311
312 /* Get the first data location */
313 ProcessData = &CsrProcess->ServerData[CSR_SERVER_DLL_MAX];
314
315 /* Loop every DLL */
316 for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
317 {
318 /* Get the current Server */
319 ServerDll = CsrLoadedServerDll[i];
320
321 /* Check if the DLL is loaded and has Process Data */
322 if (ServerDll && ServerDll->SizeOfProcessData)
323 {
324 /* Write the pointer to the data */
325 CsrProcess->ServerData[i] = ProcessData;
326
327 /* Move to the next data location */
328 ProcessData = (PVOID)((ULONG_PTR)ProcessData +
329 ServerDll->SizeOfProcessData);
330 }
331 else
332 {
333 /* Nothing for this Process */
334 CsrProcess->ServerData[i] = NULL;
335 }
336 }
337
338 /* Insert the Process */
340
341 /* Activate the Thread */
342 ApiMessage->ReturnValue = NtResumeThread(hThread, NULL);
343
344 /* Release lock and return */
346 return TRUE;
347}
VOID NTAPI CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1107
@ ThreadTimes
Definition: compat.h:936
@ ProcessExceptionPort
Definition: winternl.h:864
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
MMRESULT CreateSession(DeviceType device_type, UINT device_id, SessionInfo **session_info)
Definition: session.c:63
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
ULONG Flags
Definition: csrsrv.h:72
HANDLE ThreadHandle
Definition: csrsrv.h:71
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
PCSR_PROCESS NTAPI CsrAllocateProcess(VOID)
Definition: procsup.c:189
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
VOID NTAPI CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL, IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:366
VOID NTAPI CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:297
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119
PCSR_NT_SESSION NTAPI CsrAllocateNtSession(IN ULONG SessionId)
Definition: session.c:77

◆ CsrSbForeignSessionComplete()

BOOLEAN NTAPI CsrSbForeignSessionComplete ( IN PSB_API_MSG  ApiMessage)

Definition at line 365 of file session.c.

366{
367 /* Deprecated/Unimplemented in NT */
368 ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
369 return TRUE;
370}

◆ CsrSbTerminateSession()

BOOLEAN NTAPI CsrSbTerminateSession ( IN PSB_API_MSG  ApiMessage)

Definition at line 388 of file session.c.

389{
390 ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
391 return TRUE;
392}

◆ CsrServerDllInitialization()

NTSTATUS NTAPI CsrServerDllInitialization ( IN PCSR_SERVER_DLL  LoadedServerDll)

Referenced by CsrLoadServerDll().

◆ CsrSetDirectorySecurity()

NTSTATUS NTAPI CsrSetDirectorySecurity ( IN HANDLE  ObjectDirectory)

Definition at line 186 of file init.c.

187{
188 /* FIXME: Implement */
189 return STATUS_SUCCESS;
190}

Referenced by CsrParseServerCommandLine().

◆ CsrSrvAttachSharedSection()

NTSTATUS NTAPI CsrSrvAttachSharedSection ( IN PCSR_PROCESS CsrProcess  OPTIONAL,
OUT PCSR_API_CONNECTINFO  ConnectInfo 
)

Definition at line 482 of file server.c.

484{
486 SIZE_T ViewSize = 0;
487
488 /* Check if we have a process */
489 if (CsrProcess)
490 {
491 /* Map the section into this process */
493 CsrProcess->ProcessHandle,
495 0,
496 0,
497 NULL,
498 &ViewSize,
499 ViewUnmap,
502 if (!NT_SUCCESS(Status)) return Status;
503 }
504
505 /* Write the values in the Connection Info structure */
506 ConnectInfo->SharedSectionBase = CsrSrvSharedSectionBase;
507 ConnectInfo->SharedSectionHeap = CsrSrvSharedSectionHeap;
508 ConnectInfo->SharedStaticServerData = CsrSrvSharedStaticServerData;
509
510 /* Return success */
511 return STATUS_SUCCESS;
512}
NTSTATUS NTAPI NtMapViewOfSection(IN HANDLE SectionHandle, IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:3622
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:408
#define SEC_NO_CHANGE
Definition: mmtypes.h:95
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
@ ViewUnmap
Definition: nt_native.h:1279
HANDLE CsrSrvSharedSection
Definition: server.c:25
PVOID CsrSrvSharedSectionBase
Definition: server.c:22

Referenced by CsrApiHandleConnectionRequest().

◆ CsrSrvCreateSharedSection()

NTSTATUS NTAPI CsrSrvCreateSharedSection ( IN PCHAR  ParameterValue)

Definition at line 361 of file server.c.

362{
363 PCHAR SizeValue = ParameterValue;
364 ULONG Size;
366 LARGE_INTEGER SectionSize;
367 SIZE_T ViewSize = 0;
369
370 /* If there's no parameter, fail */
372
373 /* Find the first comma, and null terminate */
374 while (*SizeValue)
375 {
376 if (*SizeValue == ',')
377 {
378 *SizeValue++ = ANSI_NULL;
379 break;
380 }
381 else
382 {
383 SizeValue++;
384 }
385 }
386
387 /* Make sure it's valid */
388 if (!*SizeValue) return STATUS_INVALID_PARAMETER;
389
390 /* Convert it to an integer */
391 Status = RtlCharToInteger(SizeValue, 0, &Size);
392 if (!NT_SUCCESS(Status)) return Status;
393
394 /* Multiply by 1024 entries and round to page size */
396
397 /* Create the Secion */
398 SectionSize.LowPart = CsrSrvSharedSectionSize;
399 SectionSize.HighPart = 0;
402 NULL,
403 &SectionSize,
406 NULL);
407 if (!NT_SUCCESS(Status)) return Status;
408
409 /* Map the section */
413 0,
414 0,
415 NULL,
416 &ViewSize,
417 ViewUnmap,
420 if (!NT_SUCCESS(Status))
421 {
422 /* Fail */
424 return Status;
425 }
426
427 /* FIXME: Write the value to registry */
428
429 /* The Heap is the same place as the Base */
431
432 /* Create the heap */
436 PAGE_SIZE,
437 0,
438 0)))
439 {
440 /* Failure, unmap section and return */
443 return STATUS_NO_MEMORY;
444 }
445
446 /* Now allocate space from the heap for the Shared Data */
449 CSR_SERVER_DLL_MAX * sizeof(PVOID));
451
452 /* Write the values to the PEB */
456
457 /* Return */
458 return STATUS_SUCCESS;
459}
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3848
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3441
_In_opt_ PWSTR _In_ PWSTR _Inout_ PULONG ParameterValue
Definition: cdrom.h:963
PPEB Peb
Definition: dllmain.c:27
#define ROUND_UP(n, align)
Definition: eventvwr.h:34
#define MEM_TOP_DOWN
Definition: nt_native.h:1321
#define HEAP_CLASS_7
Definition: nt_native.h:1717
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define SEC_RESERVE
Definition: nt_native.h:1323
NTSYSAPI PVOID NTAPI RtlCreateHeap(IN ULONG Flags, IN PVOID HeapBase OPTIONAL, IN ULONG ReserveSize OPTIONAL, IN ULONG CommitSize OPTIONAL, IN PVOID Lock OPTIONAL, IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL)
NTSYSAPI NTSTATUS NTAPI RtlCharToInteger(PCSZ String, ULONG Base, PULONG Value)
Definition: unicode.c:261
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define ANSI_NULL
#define SEC_BASED
PVOID ReadOnlySharedMemoryHeap
Definition: ntddk_ex.h:262
PVOID ReadOnlySharedMemoryBase
Definition: ntddk_ex.h:261
PVOID * ReadOnlyStaticServerData
Definition: ntddk_ex.h:263
SYSTEM_BASIC_INFORMATION CsrNtSysInfo
Definition: init.c:44
ULONG CsrSrvSharedSectionSize
Definition: server.c:24
char * PCHAR
Definition: typedefs.h:51
ULONG LowPart
Definition: typedefs.h:106

Referenced by CsrParseServerCommandLine().

◆ ProtectHandle()

BOOLEAN NTAPI ProtectHandle ( IN HANDLE  ObjectHandle)

Definition at line 39 of file thredsup.c.

40{
43
44 /* Query current state */
45 Status = NtQueryObject(ObjectHandle,
46 ObjectHandleFlagInformation,
47 &HandleInfo,
48 sizeof(HandleInfo),
49 NULL);
50 if (NT_SUCCESS(Status))
51 {
52 /* Enable protect from close */
53 HandleInfo.ProtectFromClose = TRUE;
54 Status = NtSetInformationObject(ObjectHandle,
55 ObjectHandleFlagInformation,
56 &HandleInfo,
57 sizeof(HandleInfo));
58 if (NT_SUCCESS(Status)) return TRUE;
59 }
60
61 /* We failed to or set the state */
62 return FALSE;
63}
NTSTATUS NtQueryObject(IN HANDLE Handle, IN OBJECT_INFO_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OUT PULONG ReturnLength)
NTSTATUS NTAPI NtSetInformationObject(IN HANDLE ObjectHandle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, IN PVOID ObjectInformation, IN ULONG Length)
Definition: oblife.c:1824

Referenced by CsrAddStaticServerThread(), CsrCreateProcess(), CsrCreateRemoteThread(), CsrCreateThread(), CsrExecServerThread(), and CsrSbCreateSession().

◆ UnProtectHandle()

BOOLEAN NTAPI UnProtectHandle ( IN HANDLE  ObjectHandle)

Definition at line 78 of file thredsup.c.

79{
82
83 /* Query current state */
84 Status = NtQueryObject(ObjectHandle,
85 ObjectHandleFlagInformation,
86 &HandleInfo,
87 sizeof(HandleInfo),
88 NULL);
89 if (NT_SUCCESS(Status))
90 {
91 /* Disable protect from close */
92 HandleInfo.ProtectFromClose = FALSE;
93 Status = NtSetInformationObject(ObjectHandle,
94 ObjectHandleFlagInformation,
95 &HandleInfo,
96 sizeof(HandleInfo));
97 if (NT_SUCCESS(Status)) return TRUE;
98 }
99
100 /* We failed to or set the state */
101 return FALSE;
102}

Referenced by CsrThreadRefcountZero().

Variable Documentation

◆ CsrApiPort

HANDLE CsrApiPort
extern

Definition at line 27 of file connect.c.

◆ CsrApiPortName

UNICODE_STRING CsrApiPortName
extern

Definition at line 22 of file api.c.

Referenced by CsrApiPortInitialize().

◆ CsrDebug

◆ CsrDirectoryName

UNICODE_STRING CsrDirectoryName
extern

Definition at line 27 of file init.c.

Referenced by CsrApiPortInitialize(), CsrParseServerCommandLine(), and CsrSbApiPortInitialize().

◆ CsrHeap

◆ CsrInitializationEvent

HANDLE CsrInitializationEvent
extern

◆ CsrLoadedServerDll

◆ CsrMaxApiRequestThreads

ULONG CsrMaxApiRequestThreads
extern

Definition at line 38 of file init.c.

Referenced by CsrParseServerCommandLine().

◆ CsrNtSysInfo

SYSTEM_BASIC_INFORMATION CsrNtSysInfo
extern

Definition at line 44 of file init.c.

Referenced by CsrServerInitialization(), and CsrSrvCreateSharedSection().

◆ CsrObjectDirectory

HANDLE CsrObjectDirectory
extern

Definition at line 26 of file init.c.

Referenced by CsrParseServerCommandLine().

◆ CsrProcessLock

RTL_CRITICAL_SECTION CsrProcessLock
extern

Definition at line 60 of file api.h.

Referenced by CsrInitializeProcessStructure().

◆ CsrRootProcess

◆ CsrSbApiPort

HANDLE CsrSbApiPort
extern

Definition at line 29 of file init.c.

Referenced by CsrSbApiPortInitialize(), CsrSbApiRequestThread(), and CsrServerInitialization().

◆ CsrSbApiPortName

UNICODE_STRING CsrSbApiPortName
extern

Definition at line 28 of file init.c.

Referenced by CsrSbApiPortInitialize(), and CsrServerInitialization().

◆ CsrSmApiPort

HANDLE CsrSmApiPort
extern

Definition at line 31 of file init.c.

Referenced by CsrDereferenceNtSession(), and CsrServerInitialization().

◆ CsrSrvSharedSectionHeap

PVOID CsrSrvSharedSectionHeap
extern

Definition at line 21 of file server.c.

Referenced by CsrLoadServerDll(), CsrSrvAttachSharedSection(), and CsrSrvCreateSharedSection().

◆ CsrSrvSharedStaticServerData

PVOID* CsrSrvSharedStaticServerData
extern

Definition at line 23 of file server.c.

Referenced by CsrLoadServerDll(), CsrSrvAttachSharedSection(), and CsrSrvCreateSharedSection().

◆ CsrThreadHashTable

◆ CsrTotalPerProcessDataLength

ULONG CsrTotalPerProcessDataLength
extern

Definition at line 39 of file init.c.

Referenced by CsrLoadServerDll().

◆ CsrWaitListsLock

RTL_CRITICAL_SECTION CsrWaitListsLock

Definition at line 10 of file api.h.

Referenced by CsrInitializeProcessStructure().

◆ hBootstrapOk

HANDLE hBootstrapOk
extern