ReactOS  0.4.14-dev-815-ge410a12
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)
 
 CSR_API (CsrSrvIdentifyAlertableThread)
 
 CSR_API (CsrSrvSetPriorityClass)
 
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/4]

CSR_API ( CsrSrvClientConnect  )

Definition at line 267 of file server.c.

268 {
270  PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage->Data.CsrClientConnect;
271  PCSR_SERVER_DLL ServerDll;
273 
274  /* Set default reply */
275  *ReplyCode = CsrReplyImmediately;
276 
277  /* Validate the ServerID */
278  if (ClientConnect->ServerId >= CSR_SERVER_DLL_MAX)
279  {
280  return STATUS_TOO_MANY_NAMES;
281  }
282  else if (!CsrLoadedServerDll[ClientConnect->ServerId])
283  {
285  }
286 
287  /* Validate the Message Buffer */
288  if (!(CsrValidateMessageBuffer(ApiMessage,
289  &ClientConnect->ConnectionInfo,
290  ClientConnect->ConnectionInfoSize,
291  sizeof(BYTE))))
292  {
293  /* Fail due to buffer overflow or other invalid buffer */
295  }
296 
297  /* Load the Server DLL */
298  ServerDll = CsrLoadedServerDll[ClientConnect->ServerId];
299 
300  /* Check if it has a Connect Callback */
301  if (ServerDll->ConnectCallback)
302  {
303  /* Call the callback */
305  ClientConnect->ConnectionInfo,
306  &ClientConnect->ConnectionInfoSize);
307  }
308  else
309  {
310  /* Assume success */
312  }
313 
314  /* Return status */
315  return Status;
316 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
PCSR_CONNECT_CALLBACK ConnectCallback
Definition: csrsrv.h:235
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
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:1315
PVOID ConnectionInfo
Definition: csrmsg.h:88
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
ULONG CurrentProcess
Definition: shell.c:125
ULONG ConnectionInfoSize
Definition: csrmsg.h:89
unsigned char BYTE
Definition: mem.h:68
Status
Definition: gdiplustypes.h:24
#define STATUS_TOO_MANY_NAMES
Definition: ntstatus.h:427
return STATUS_SUCCESS
Definition: btrfs.c:2938
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

◆ CSR_API() [2/4]

CSR_API ( CsrSrvUnusedFunction  )

Definition at line 559 of file server.c.

560 {
561  /* Deprecated */
563 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

◆ CSR_API() [3/4]

CSR_API ( CsrSrvIdentifyAlertableThread  )

Definition at line 505 of file server.c.

506 {
507  PCSR_THREAD CsrThread = CsrGetClientThread();
508 
509  /* Set the alertable flag */
510  CsrThread->Flags |= CsrThreadAlertable;
511 
512  /* Return success */
513  return STATUS_SUCCESS;
514 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ CSR_API() [4/4]

CSR_API ( CsrSrvSetPriorityClass  )

Definition at line 533 of file server.c.

534 {
535  /* Deprecated */
536  return STATUS_SUCCESS;
537 }
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ CsrAllocateProcess()

PCSR_PROCESS NTAPI CsrAllocateProcess ( VOID  )

Definition at line 188 of file procsup.c.

189 {
191  ULONG TotalSize;
192 
193  /* Calculate the amount of memory this should take */
194  TotalSize = sizeof(CSR_PROCESS) +
195  (CSR_SERVER_DLL_MAX * sizeof(PVOID)) +
197 
198  /* Allocate a Process */
200  if (!CsrProcess) return NULL;
201 
202  /* Handle the Sequence Number and protect against overflow */
203  CsrProcess->SequenceNumber = CsrProcessSequenceCount++;
205 
206  /* Increase the reference count */
208 
209  /* Initialize the Thread List */
210  InitializeListHead(&CsrProcess->ThreadList);
211 
212  /* Return the Process */
213  return CsrProcess;
214 }
PKPROCESS CsrProcess
Definition: videoprt.c:37
ULONG CsrProcessSequenceCount
Definition: procsup.c:30
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
struct _CSR_PROCESS CSR_PROCESS
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:232
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
HANDLE CsrHeap
Definition: init.c:25
ULONG CsrTotalPerProcessDataLength
Definition: init.c:35

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 }
VOID NTAPI CsrLockedReferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:154
PKPROCESS CsrProcess
Definition: videoprt.c:37
PCSR_PROCESS Process
Definition: csrsrv.h:69
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:232
HANDLE CsrHeap
Definition: init.c:25

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

◆ CsrApiHandleConnectionRequest()

NTSTATUS NTAPI CsrApiHandleConnectionRequest ( IN PCSR_API_MESSAGE  ApiMessage)

Definition at line 140 of file api.c.

141 {
142  PCSR_THREAD CsrThread = NULL;
145  PCSR_API_CONNECTINFO ConnectInfo = &ApiMessage->ConnectionInfo;
146  BOOLEAN AllowConnection = FALSE;
147  REMOTE_PORT_VIEW RemotePortView;
149 
150  /* Acquire the Process Lock */
152 
153  /* Lookup the CSR Thread */
154  CsrThread = CsrLocateThreadByClientId(NULL, &ApiMessage->Header.ClientId);
155 
156  /* Check if we have a thread */
157  if (CsrThread)
158  {
159  /* Get the Process and make sure we have it as well */
160  CsrProcess = CsrThread->Process;
161  if (CsrProcess)
162  {
163  /* Reference the Process */
165 
166  /* Attach the Shared Section */
168  if (NT_SUCCESS(Status))
169  {
170  /* Allow the connection and return debugging flag */
171  ConnectInfo->DebugFlags = CsrDebug;
172  AllowConnection = TRUE;
173  }
174 
175  /* Dereference the Process */
177  }
178  }
179 
180  /* Release the Process Lock */
182 
183  /* Setup the Port View Structure */
184  RemotePortView.Length = sizeof(REMOTE_PORT_VIEW);
185  RemotePortView.ViewSize = 0;
186  RemotePortView.ViewBase = NULL;
187 
188  /* Save the Process ID */
189  ConnectInfo->ServerProcessId = NtCurrentTeb()->ClientId.UniqueProcess;
190 
191  /* Accept the Connection */
193  AllowConnection ? UlongToPtr(CsrProcess->SequenceNumber) : 0,
194  &ApiMessage->Header,
195  AllowConnection,
196  NULL,
197  &RemotePortView);
198  if (!NT_SUCCESS(Status))
199  {
200  DPRINT1("CSRSS: NtAcceptConnectPort - failed. Status == %X\n", Status);
201  }
202  else if (AllowConnection)
203  {
204  if (CsrDebug & 2)
205  {
206  DPRINT1("CSRSS: ClientId: %lx.%lx has ClientView: Base=%p, Size=%lx\n",
207  ApiMessage->Header.ClientId.UniqueProcess,
208  ApiMessage->Header.ClientId.UniqueThread,
209  RemotePortView.ViewBase,
210  RemotePortView.ViewSize);
211  }
212 
213  /* Set some Port Data in the Process */
214  CsrProcess->ClientPort = ServerPort;
215  CsrProcess->ClientViewBase = (ULONG_PTR)RemotePortView.ViewBase;
216  CsrProcess->ClientViewBounds = (ULONG_PTR)((ULONG_PTR)RemotePortView.ViewBase +
217  (ULONG_PTR)RemotePortView.ViewSize);
218 
219  /* Complete the connection */
221  if (!NT_SUCCESS(Status))
222  {
223  DPRINT1("CSRSS: NtCompleteConnectPort - failed. Status == %X\n", Status);
224  }
225  }
226  else
227  {
228  DPRINT1("CSRSS: Rejecting Connection Request from ClientId: %lx.%lx\n",
229  ApiMessage->Header.ClientId.UniqueProcess,
230  ApiMessage->Header.ClientId.UniqueThread);
231  }
232 
233  /* Return status to caller */
234  return Status;
235 }
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _Outptr_ PFLT_PORT * ServerPort
Definition: fltkernel.h:1873
LONG NTSTATUS
Definition: precomp.h:26
ULONG CsrDebug
Definition: init.c:23
PKPROCESS CsrProcess
Definition: videoprt.c:37
#define CsrReleaseProcessLock()
Definition: api.h:15
uint32_t ULONG_PTR
Definition: typedefs.h:63
PCSR_PROCESS Process
Definition: csrsrv.h:69
HANDLE ServerProcessId
Definition: csrmsg.h:57
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
struct _REMOTE_PORT_VIEW REMOTE_PORT_VIEW
#define UlongToPtr(u)
Definition: config.h:106
NTSTATUS NTAPI CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL, OUT PCSR_API_CONNECTINFO ConnectInfo)
Definition: server.c:456
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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CsrAcquireProcessLock()
Definition: api.h:12
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
Status
Definition: gdiplustypes.h:24
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI NtCompleteConnectPort(IN HANDLE PortHandle)
Definition: complete.c:421
#define ULONG_PTR
Definition: config.h:101
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:232
return STATUS_SUCCESS
Definition: btrfs.c:2938
VOID NTAPI CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
Definition: procsup.c:159

Referenced by CsrApiRequestThread().

◆ CsrApiPortInitialize()

NTSTATUS NTAPI CsrApiPortInitialize ( VOID  )

Definition at line 882 of file api.c.

883 {
884  ULONG Size;
887  HANDLE hRequestEvent, hThread;
889  PLIST_ENTRY ListHead, NextEntry;
891 
892  /* Calculate how much space we'll need for the Port Name */
893  Size = CsrDirectoryName.Length + sizeof(CSR_PORT_NAME) + sizeof(WCHAR);
894 
895  /* Create the buffer for it */
898 
899  /* Setup the rest of the empty string */
905  if (CsrDebug & 1)
906  {
907  DPRINT1("CSRSS: Creating %wZ port and associated threads\n", &CsrApiPortName);
908  DPRINT1("CSRSS: sizeof( CONNECTINFO ) == %ld sizeof( API_MSG ) == %ld\n",
909  sizeof(CSR_API_CONNECTINFO), sizeof(CSR_API_MESSAGE));
910  }
911 
912  /* FIXME: Create a Security Descriptor */
913 
914  /* Initialize the Attributes */
917  0,
918  NULL,
919  NULL /* FIXME: Use the Security Descriptor */);
920 
921  /* Create the Port Object */
924  sizeof(CSR_API_CONNECTINFO),
925  sizeof(CSR_API_MESSAGE),
926  16 * PAGE_SIZE);
927  if (NT_SUCCESS(Status))
928  {
929  /* Create the event the Port Thread will use */
930  Status = NtCreateEvent(&hRequestEvent,
932  NULL,
934  FALSE);
935  if (NT_SUCCESS(Status))
936  {
937  /* Create the Request Thread */
939  NULL,
940  TRUE,
941  0,
942  0,
943  0,
945  (PVOID)hRequestEvent,
946  &hThread,
947  &ClientId);
948  if (NT_SUCCESS(Status))
949  {
950  /* Add this as a static thread to CSRSRV */
952 
953  /* Get the Thread List Pointers */
954  ListHead = &CsrRootProcess->ThreadList;
955  NextEntry = ListHead->Flink;
956 
957  /* Start looping the list */
958  while (NextEntry != ListHead)
959  {
960  /* Get the Thread */
962 
963  /* Start it up */
964  Status = NtResumeThread(ServerThread->ThreadHandle, NULL);
965 
966  /* Is this a Server Thread? */
968  {
969  /* If so, then wait for it to initialize */
970  Status = NtWaitForSingleObject(hRequestEvent, FALSE, NULL);
972  }
973 
974  /* Next thread */
975  NextEntry = NextEntry->Flink;
976  }
977 
978  /* We don't need this anymore */
979  NtClose(hRequestEvent);
980  }
981  }
982  }
983 
984  /* Return */
985  return Status;
986 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
LONG NTSTATUS
Definition: precomp.h:26
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:100
ULONG CsrDebug
Definition: init.c:23
#define CSR_PORT_NAME
Definition: csrmsg.h:17
static int Link(const char **args)
Definition: vfdcmd.c:2414
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
PCSR_THREAD NTAPI CsrAddStaticServerThread(IN HANDLE hThread, IN PCLIENT_ID ClientId, IN ULONG ThreadFlags)
Definition: thredsup.c:511
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
UINT CALLBACK ServerThread(_Inout_ PVOID Parameter)
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
NTSTATUS NTAPI NtCreatePort(OUT PHANDLE PortHandle, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG MaxConnectInfoLength, IN ULONG MaxDataLength, IN ULONG MaxPoolUsage)
Definition: create.c:212
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI CsrApiRequestThread(IN PVOID Parameter)
Definition: api.c:331
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:117
UNICODE_STRING CsrDirectoryName
Definition: init.c:27
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)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
HANDLE CsrApiPort
Definition: connect.c:21
unsigned short USHORT
Definition: pedump.c:61
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
#define UNICODE_PATH_SEP
Definition: connect.c:33
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
HANDLE hThread
Definition: wizard.c:27
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING CsrApiPortName
Definition: api.c:22
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
HANDLE CsrHeap
Definition: init.c:25
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)

Referenced by CsrServerInitialization().

◆ CsrApiRequestThread()

NTSTATUS NTAPI CsrApiRequestThread ( IN PVOID  Parameter)

Definition at line 331 of file api.c.

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

Referenced by CsrApiPortInitialize(), and CsrpCheckRequestThreads().

◆ CsrCaptureArguments()

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

Definition at line 1104 of file api.c.

1106 {
1107  PCSR_CAPTURE_BUFFER LocalCaptureBuffer = NULL, RemoteCaptureBuffer = NULL;
1108  SIZE_T BufferDistance;
1109  ULONG Length = 0;
1110  ULONG PointerCount;
1111  PULONG_PTR OffsetPointer;
1112  ULONG_PTR CurrentOffset;
1113 
1114  /* Use SEH to make sure this is valid */
1115  _SEH2_TRY
1116  {
1117  /* Get the buffer we got from whoever called NTDLL */
1118  LocalCaptureBuffer = ApiMessage->CsrCaptureData;
1119  Length = LocalCaptureBuffer->Size;
1120 
1121  /* Now check if the buffer is inside our mapped section */
1122  if (((ULONG_PTR)LocalCaptureBuffer < CsrThread->Process->ClientViewBase) ||
1123  (((ULONG_PTR)LocalCaptureBuffer + Length) >= CsrThread->Process->ClientViewBounds))
1124  {
1125  /* Return failure */
1126  DPRINT1("*** CSRSS: CaptureBuffer outside of ClientView\n");
1127  ApiMessage->Status = STATUS_INVALID_PARAMETER;
1128  _SEH2_YIELD(return FALSE);
1129  }
1130 
1131  /* Check if the Length is valid */
1132  if ((FIELD_OFFSET(CSR_CAPTURE_BUFFER, PointerOffsetsArray) +
1133  (LocalCaptureBuffer->PointerCount * sizeof(PVOID)) > Length) ||
1134  (LocalCaptureBuffer->PointerCount > MAXUSHORT))
1135  {
1136  /* Return failure */
1137  DPRINT1("*** CSRSS: CaptureBuffer %p has bad length\n", LocalCaptureBuffer);
1138  DbgBreakPoint();
1139  ApiMessage->Status = STATUS_INVALID_PARAMETER;
1140  _SEH2_YIELD(return FALSE);
1141  }
1142  }
1144  {
1145  /* Return failure */
1146  ApiMessage->Status = STATUS_INVALID_PARAMETER;
1147  _SEH2_YIELD(return FALSE);
1148  } _SEH2_END;
1149 
1150  /* We validated the incoming buffer, now allocate the remote one */
1151  RemoteCaptureBuffer = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, Length);
1152  if (!RemoteCaptureBuffer)
1153  {
1154  /* We're out of memory */
1155  ApiMessage->Status = STATUS_NO_MEMORY;
1156  return FALSE;
1157  }
1158 
1159  /* Copy the client's buffer */
1160  RtlMoveMemory(RemoteCaptureBuffer, LocalCaptureBuffer, Length);
1161 
1162  /* Calculate the difference between our buffer and the client's */
1163  BufferDistance = (ULONG_PTR)RemoteCaptureBuffer - (ULONG_PTR)LocalCaptureBuffer;
1164 
1165  /*
1166  * All the pointer offsets correspond to pointers which point
1167  * to the remote data buffer instead of the local one.
1168  */
1169  PointerCount = RemoteCaptureBuffer->PointerCount;
1170  OffsetPointer = RemoteCaptureBuffer->PointerOffsetsArray;
1171  while (PointerCount--)
1172  {
1173  CurrentOffset = *OffsetPointer;
1174 
1175  if (CurrentOffset != 0)
1176  {
1177  /* Get the pointer corresponding to the offset */
1178  CurrentOffset += (ULONG_PTR)ApiMessage;
1179 
1180  /* Validate the bounds of the current pointed pointer */
1181  if ((*(PULONG_PTR)CurrentOffset >= CsrThread->Process->ClientViewBase) &&
1182  (*(PULONG_PTR)CurrentOffset < CsrThread->Process->ClientViewBounds))
1183  {
1184  /* Modify the pointed pointer to take into account its new position */
1185  *(PULONG_PTR)CurrentOffset += BufferDistance;
1186  }
1187  else
1188  {
1189  /* Invalid pointer, fail */
1190  DPRINT1("*** CSRSS: CaptureBuffer MessagePointer outside of ClientView\n");
1191  DbgBreakPoint();
1192  ApiMessage->Status = STATUS_INVALID_PARAMETER;
1193  }
1194  }
1195 
1196  ++OffsetPointer;
1197  }
1198 
1199  /* Check if we got success */
1200  if (ApiMessage->Status != STATUS_SUCCESS)
1201  {
1202  /* Failure. Free the buffer and return */
1203  RtlFreeHeap(CsrHeap, 0, RemoteCaptureBuffer);
1204  return FALSE;
1205  }
1206  else
1207  {
1208  /* Success, save the previous buffer and use the remote capture buffer */
1209  RemoteCaptureBuffer->PreviousCaptureBuffer = LocalCaptureBuffer;
1210  ApiMessage->CsrCaptureData = RemoteCaptureBuffer;
1211  }
1212 
1213  /* Success */
1214  return TRUE;
1215 }
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
void DbgBreakPoint()
Definition: mach.c:553
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ULONG PointerCount
Definition: csrmsg.h:96
ULONG_PTR SIZE_T
Definition: typedefs.h:78
_SEH2_END
Definition: create.c:4424
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define MAXUSHORT
Definition: typedefs.h:81
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
uint32_t * PULONG_PTR
Definition: typedefs.h:63
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
HANDLE CsrHeap
Definition: init.c:25
return STATUS_SUCCESS
Definition: btrfs.c:2938

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 801 of file init.c.

802 {
804  PSID SystemSid;
805  ULONG Length;
806  PSECURITY_DESCRIPTOR SystemSd;
807  PACL Dacl;
809 
810  /* Initialize the System SID */
813  0, 0, 0, 0, 0, 0, 0,
814  &SystemSid);
815 
816  /* Get the length of the SID */
817  Length = RtlLengthSid(SystemSid) + sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE);
818 
819  /* Allocate a buffer for the Security Descriptor, with SID and DACL */
821 
822  /* Set the pointer to the DACL */
824 
825  /* Now create the SD itself */
827  if (!NT_SUCCESS(Status)) goto Quit;
828 
829  /* Create the DACL for it */
831 
832  /* Create the ACE */
834  if (!NT_SUCCESS(Status)) goto Quit;
835 
836  /* Clear the DACL in the SD */
838  if (!NT_SUCCESS(Status)) goto Quit;
839 
840 Quit:
841  if (!NT_SUCCESS(Status))
842  {
843  RtlFreeHeap(CsrHeap, 0, SystemSd);
844  SystemSd = NULL;
845  }
846 
847  /* Free the SID and return*/
848  RtlFreeSid(SystemSid);
849  *LocalSystemSd = SystemSd;
850  return Status;
851 }
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
#define TRUE
Definition: types.h:120
#define SECURITY_DESCRIPTOR_MIN_LENGTH
Definition: setypes.h:761
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
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
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define ACL_REVISION2
Definition: setypes.h:43
struct _ACL ACL
smooth NULL
Definition: ftsmooth.c:416
static SID_IDENTIFIER_AUTHORITY NtSidAuthority
Definition: samrpc.c:14
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:526
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _ACL * PACL
Definition: security.c:104
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
Status
Definition: gdiplustypes.h:24
#define ACL_REVISION
Definition: setypes.h:39
#define PORT_ALL_ACCESS
Definition: lpctypes.h:47
unsigned int ULONG
Definition: retypes.h:1
HANDLE CsrHeap
Definition: init.c:25

Referenced by CsrSbApiPortInitialize().

◆ CsrCreateObjectDirectory()

NTSTATUS NTAPI CsrCreateObjectDirectory ( IN PCHAR  ObjectDirectory)

◆ CsrCreateSessionObjectDirectory()

NTSTATUS NTAPI CsrCreateSessionObjectDirectory ( IN ULONG  SessionId)

Definition at line 414 of file init.c.

415 {
416  WCHAR SessionBuffer[512], BnoBuffer[512];
417  UNICODE_STRING SessionString, BnoString;
419  HANDLE BnoHandle;
420  SECURITY_DESCRIPTOR DosDevicesSd;
422 
423  /* Generate the Session BNOLINKS Directory name */
424  swprintf(SessionBuffer, L"%ws\\BNOLINKS", SESSION_ROOT);
425  RtlInitUnicodeString(&SessionString, SessionBuffer);
426 
427  /* Create it */
429  &SessionString,
431  NULL,
432  NULL);
436  if (!NT_SUCCESS(Status))
437  {
438  DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
439  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
440  return Status;
441  }
442 
443  /* Now add the Session ID */
444  swprintf(SessionBuffer, L"%ld", Session);
445  RtlInitUnicodeString(&SessionString, SessionBuffer);
446 
447  /* Check if this is the first Session */
448  if (Session)
449  {
450  /* Not the first, so the name will be slighly more complex */
451  swprintf(BnoBuffer, L"%ws\\%ld\\BaseNamedObjects", SESSION_ROOT, Session);
452  RtlInitUnicodeString(&BnoString, BnoBuffer);
453  }
454  else
455  {
456  /* Use the direct name */
457  RtlInitUnicodeString(&BnoString, L"\\BaseNamedObjects");
458  }
459 
460  /* Create the symlink */
462  &SessionString,
465  NULL);
466  Status = NtCreateSymbolicLinkObject(&BnoHandle,
469  &BnoString);
470  if (!NT_SUCCESS(Status))
471  {
472  DPRINT1("CSRSS: NtCreateSymbolicLinkObject failed in "
473  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
474  return Status;
475  }
476 
477  /* Create the \DosDevices Security Descriptor */
478  Status = GetDosDevicesProtection(&DosDevicesSd);
479  if (!NT_SUCCESS(Status)) return Status;
480 
481  /* Now create a directory for this session */
482  swprintf(SessionBuffer, L"%ws\\%ld", SESSION_ROOT, Session);
483  RtlInitUnicodeString(&SessionString, SessionBuffer);
484 
485  /* Create the directory */
487  &SessionString,
489  0,
490  &DosDevicesSd);
494  if (!NT_SUCCESS(Status))
495  {
496  DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
497  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
498  FreeDosDevicesProtection(&DosDevicesSd);
499  return Status;
500  }
501 
502  /* Next, create a directory for this session's DOS Devices */
503  RtlInitUnicodeString(&SessionString, L"DosDevices");
505  &SessionString,
508  &DosDevicesSd);
512  if (!NT_SUCCESS(Status))
513  {
514  DPRINT1("CSRSS: NtCreateDirectoryObject failed in "
515  "CsrCreateSessionObjectDirectory - status = %lx\n", Status);
516  }
517 
518  /* Release the Security Descriptor */
519  FreeDosDevicesProtection(&DosDevicesSd);
520 
521  /* Return */
522  return Status;
523 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS NTAPI GetDosDevicesProtection(OUT PSECURITY_DESCRIPTOR DosDevicesSd)
Definition: init.c:199
LONG NTSTATUS
Definition: precomp.h:26
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
VOID NTAPI FreeDosDevicesProtection(IN PSECURITY_DESCRIPTOR DosDevicesSd)
Definition: init.c:382
#define OBJ_OPENIF
Definition: winternl.h:229
HANDLE DosDevicesDirectory
Definition: init.c:39
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
HANDLE SessionObjectDirectory
Definition: init.c:38
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtCreateDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:773
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
HANDLE BNOLinksDirectory
Definition: init.c:37
#define SESSION_ROOT
Definition: srv.h:44

Referenced by CsrParseServerCommandLine().

◆ CsrDeallocateProcess()

VOID NTAPI CsrDeallocateProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 296 of file procsup.c.

297 {
298  /* Free the process object from the heap */
300 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
PKPROCESS CsrProcess
Definition: videoprt.c:37
HANDLE CsrHeap
Definition: init.c:25

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 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
HANDLE CsrHeap
Definition: init.c:25

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 }
NTSTATUS NTAPI SmSessionComplete(IN HANDLE SmApiPort, IN ULONG SessionId, IN NTSTATUS SessionStatus)
Definition: smclient.c:135
#define CsrAcquireNtSessionLock()
Definition: api.h:27
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define CsrReleaseNtSessionLock()
Definition: api.h:30
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
HANDLE CsrSmApiPort
Definition: init.c:31
HANDLE CsrHeap
Definition: init.c:25

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 }
RTL_CRITICAL_SECTION CsrNtSessionLock
Definition: session.c:18
LIST_ENTRY CsrNtSessionList
Definition: session.c:19
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

Referenced by CsrServerInitialization().

◆ CsrInitializeProcessStructure()

NTSTATUS NTAPI CsrInitializeProcessStructure ( VOID  )

Definition at line 254 of file procsup.c.

255 {
257  ULONG i;
258 
259  /* Initialize the Lock */
261  if (!NT_SUCCESS(Status)) return Status;
262 
263  /* Set up the Root Process */
265  if (!CsrRootProcess) return STATUS_NO_MEMORY;
266 
267  /* Set up the minimal information for it */
270  CsrRootProcess->ClientId = NtCurrentTeb()->ClientId;
271 
272  /* Initialize the Thread Hash List */
274 
275  /* Initialize the Wait Lock */
277 }
RTL_CRITICAL_SECTION CsrProcessLock
Definition: procsup.c:21
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21
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
HANDLE ProcessHandle
Definition: csrsrv.h:46
CLIENT_ID ClientId
Definition: csrsrv.h:38
LIST_ENTRY ListLink
Definition: csrsrv.h:39
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
PVOID HANDLE
Definition: typedefs.h:71
PCSR_PROCESS NTAPI CsrAllocateProcess(VOID)
Definition: procsup.c:188
Status
Definition: gdiplustypes.h:24
RTL_CRITICAL_SECTION CsrWaitListsLock
Definition: api.h:61
#define NUMBER_THREAD_HASH_BUCKETS
Definition: api.h:44
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int ULONG
Definition: retypes.h:1

Referenced by CsrServerInitialization().

◆ CsrInsertProcess()

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

Definition at line 365 of file procsup.c.

367 {
368  PCSR_SERVER_DLL ServerDll;
369  ULONG i;
371 
372  /* Insert it into the Root List */
374 
375  /* Notify the Server DLLs */
376  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
377  {
378  /* Get the current Server DLL */
379  ServerDll = CsrLoadedServerDll[i];
380 
381  /* Make sure it's valid and that it has callback */
382  if (ServerDll && ServerDll->NewProcessCallback)
383  {
384  ServerDll->NewProcessCallback(ParentProcess, CsrProcess);
385  }
386  }
387 }
PKPROCESS CsrProcess
Definition: videoprt.c:37
#define InsertTailList(ListHead, Entry)
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define ProcessStructureListLocked()
Definition: api.h:18
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
LIST_ENTRY ListLink
Definition: csrsrv.h:39
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1
PCSR_NEWPROCESS_CALLBACK NewProcessCallback
Definition: csrsrv.h:239
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

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 */
324  InsertHeadList(&CsrThreadHashTable[i], &Thread->HashLinks);
325  return STATUS_SUCCESS;
326 }
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:297
LONG NTSTATUS
Definition: precomp.h:26
struct _ThreadInfo ThreadInfo
#define InsertTailList(ListHead, Entry)
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
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CsrHashThread(t)
Definition: thredsup.c:17
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2497
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938

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

◆ CsrLoadServerDll()

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

Definition at line 116 of file server.c.

119 {
121  ANSI_STRING DllName;
122  UNICODE_STRING TempString, ErrorString;
124  HANDLE hServerDll = NULL;
125  ULONG Size;
126  PCSR_SERVER_DLL ServerDll;
127  STRING EntryPointString;
128  PCSR_SERVER_DLL_INIT_CALLBACK ServerDllInitProcedure;
129  ULONG Response;
130 
131  /* Check if it's beyond the maximum we support */
132  if (ServerId >= CSR_SERVER_DLL_MAX) return STATUS_TOO_MANY_NAMES;
133 
134  /* Check if it's already been loaded */
135  if (CsrLoadedServerDll[ServerId]) return STATUS_INVALID_PARAMETER;
136 
137  /* Convert the name to Unicode */
138  ASSERT(DllString != NULL);
139  RtlInitAnsiString(&DllName, DllString);
140  Status = RtlAnsiStringToUnicodeString(&TempString, &DllName, TRUE);
141  if (!NT_SUCCESS(Status)) return Status;
142 
143  /* If we are loading ourselves, don't actually load us */
144  if (ServerId != CSRSRV_SERVERDLL_INDEX)
145  {
146  /* Load the DLL */
147  Status = LdrLoadDll(NULL, 0, &TempString, &hServerDll);
148  if (!NT_SUCCESS(Status))
149  {
150  /* Setup error parameters */
151  Parameters[0] = (ULONG_PTR)&TempString;
152  Parameters[1] = (ULONG_PTR)&ErrorString;
153  RtlInitUnicodeString(&ErrorString, L"Default Load Path");
154 
155  /* Send a hard error */
157  2,
158  3,
159  Parameters,
160  OptionOk,
161  &Response);
162  }
163 
164  /* Get rid of the string */
165  RtlFreeUnicodeString(&TempString);
166  if (!NT_SUCCESS(Status)) return Status;
167  }
168 
169  /* Allocate a CSR DLL Object */
170  Size = sizeof(CSR_SERVER_DLL) + DllName.MaximumLength;
172  if (!ServerDll)
173  {
174  if (hServerDll) LdrUnloadDll(hServerDll);
175  return STATUS_NO_MEMORY;
176  }
177 
178  /* Set up the Object */
179  ServerDll->Length = Size;
180  ServerDll->SizeOfProcessData = 0;
181  ServerDll->SharedSection = CsrSrvSharedSectionHeap; // Send to the server dll our shared heap pointer.
182  ServerDll->Name.Length = DllName.Length;
183  ServerDll->Name.MaximumLength = DllName.MaximumLength;
184  ServerDll->Name.Buffer = (PCHAR)(ServerDll + 1);
185  if (DllName.Length)
186  {
187  strncpy(ServerDll->Name.Buffer, DllName.Buffer, DllName.Length);
188  }
189  ServerDll->ServerId = ServerId;
190  ServerDll->ServerHandle = hServerDll;
191 
192  /* Now get the entrypoint */
193  if (hServerDll)
194  {
195  /* Initialize a string for the entrypoint, or use the default */
196  RtlInitAnsiString(&EntryPointString,
197  EntryPoint ? EntryPoint : "ServerDllInitialization");
198 
199  /* Get a pointer to it */
200  Status = LdrGetProcedureAddress(hServerDll,
201  &EntryPointString,
202  0,
203  (PVOID)&ServerDllInitProcedure);
204  }
205  else
206  {
207  /* No handle, so we are loading ourselves */
208  ServerDllInitProcedure = CsrServerDllInitialization;
210  }
211 
212  /* Check if we got the pointer, and call it */
213  if (NT_SUCCESS(Status))
214  {
215  /* Get the result from the Server DLL */
216  Status = ServerDllInitProcedure(ServerDll);
217  if (NT_SUCCESS(Status))
218  {
219  /*
220  * Add this Server's Per-Process Data Size to the total that each
221  * process will need.
222  */
224 
225  /* Save the pointer in our list */
226  CsrLoadedServerDll[ServerDll->ServerId] = ServerDll;
227 
228  /* Does it use our generic heap? */
229  if (ServerDll->SharedSection != CsrSrvSharedSectionHeap)
230  {
231  /* No, save the pointer to its shared section in our list */
232  CsrSrvSharedStaticServerData[ServerDll->ServerId] = ServerDll->SharedSection;
233  }
234  }
235  }
236 
237  if (!NT_SUCCESS(Status))
238  {
239  /* Server Init failed, unload it */
240  if (hServerDll) LdrUnloadDll(hServerDll);
241 
242  /* Delete the Object */
243  RtlFreeHeap(CsrHeap, 0, ServerDll);
244  }
245 
246  /* Return to caller */
247  return Status;
248 }
#define TRUE
Definition: types.h:120
ULONG SizeOfProcessData
Definition: csrsrv.h:234
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:553
PVOID CsrSrvSharedSectionHeap
Definition: server.c:21
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
ANSI_STRING Name
Definition: csrsrv.h:218
ULONG CsrTotalPerProcessDataLength
Definition: init.c:35
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS NTAPI CsrServerDllInitialization(IN PCSR_SERVER_DLL LoadedServerDll)
PVOID * CsrSrvSharedStaticServerData
Definition: server.c:23
NTSTATUS NTAPI LdrGetProcedureAddress(IN PVOID BaseAddress, IN PANSI_STRING Name, IN ULONG Ordinal, OUT PVOID *ProcedureAddress)
Definition: ldrapi.c:823
smooth NULL
Definition: ftsmooth.c:416
ULONG ServerId
Definition: csrsrv.h:220
#define PCHAR
Definition: match.c:90
HANDLE ServerHandle
Definition: csrsrv.h:219
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
USHORT MaximumLength
Definition: env_spec_w32.h:377
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
Definition: ncftp.h:89
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
std::wstring STRING
Definition: fontsub.cpp:33
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
static const WCHAR L[]
Definition: oid.c:1250
PVOID SharedSection
Definition: csrsrv.h:238
NTSTATUS NTAPI DECLSPEC_HOTPATCH LdrLoadDll(IN PWSTR SearchPath OPTIONAL, IN PULONG DllCharacteristics OPTIONAL, IN PUNICODE_STRING DllName, OUT PVOID *BaseAddress)
Definition: ldrapi.c:310
ULONG Length
Definition: csrsrv.h:217
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
struct _CSR_SERVER_DLL CSR_SERVER_DLL
NTSTATUS NTAPI LdrUnloadDll(IN PVOID BaseAddress)
Definition: ldrapi.c:1322
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define CSRSRV_SERVERDLL_INDEX
Definition: csrmsg.h:20
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct Response Response
#define ULONG_PTR
Definition: config.h:101
HANDLE CsrHeap
Definition: init.c:25
#define STATUS_TOO_MANY_NAMES
Definition: ntstatus.h:427
NTSTATUS(NTAPI * PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll)
Definition: csrsrv.h:253
return STATUS_SUCCESS
Definition: btrfs.c:2938
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

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 }
HANDLE UniqueProcess
Definition: compat.h:482
PCSR_PROCESS Process
Definition: csrsrv.h:69
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
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
CLIENT_ID ClientId
Definition: csrsrv.h:68
#define CsrHashThread(t)
Definition: thredsup.c:17
HANDLE UniqueThread
Definition: compat.h:483
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21
Definition: typedefs.h:117
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1

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 }
PKPROCESS CsrProcess
Definition: videoprt.c:37
static int Link(const char **args)
Definition: vfdcmd.c:2414
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
CLIENT_ID ClientId
Definition: csrsrv.h:68
HANDLE UniqueThread
Definition: compat.h:483
Definition: typedefs.h:117

Referenced by CsrConnectToUser().

◆ CsrLockedDereferenceProcess()

VOID NTAPI CsrLockedDereferenceProcess ( PCSR_PROCESS  CsrProcess)

Definition at line 159 of file procsup.c.

160 {
161  LONG LockCount;
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);
172  }
173 }
PKPROCESS CsrProcess
Definition: videoprt.c:37
LONG LockCount
Definition: comsup.c:6
long LONG
Definition: pedump.c:60
VOID NTAPI CsrProcessRefcountZero(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:119
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12
#define DPRINT1
Definition: precomp.h:8

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

◆ CsrLockedDereferenceThread()

VOID NTAPI CsrLockedDereferenceThread ( IN PCSR_THREAD  CsrThread)

Definition at line 467 of file thredsup.c.

468 {
469  LONG LockCount;
470 
471  /* Decrease reference count */
472  LockCount = --CsrThread->ReferenceCount;
473  ASSERT(LockCount >= 0);
474  if (LockCount == 0)
475  {
476  /* Call the generic cleanup code */
478  CsrThreadRefcountZero(CsrThread);
479  }
480 }
LONG LockCount
Definition: comsup.c:6
long LONG
Definition: pedump.c:60
VOID NTAPI CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:424
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12

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

◆ CsrLockedReferenceProcess()

VOID NTAPI CsrLockedReferenceProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 232 of file procsup.c.

233 {
234  /* Increment the reference count */
235  ++CsrProcess->ReferenceCount;
236 }
PKPROCESS CsrProcess
Definition: videoprt.c:37

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 }
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
VOID NTAPI CsrDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:775
NTSTATUS NTAPI NtReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE ReplyMessage)
Definition: reply.c:190
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
VOID NTAPI CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage)
Definition: api.c:1235
smooth NULL
Definition: ftsmooth.c:416
HANDLE CsrHeap
Definition: init.c:25

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 }
#define CsrAcquireNtSessionLock()
Definition: api.h:27
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define CsrReleaseNtSessionLock()
Definition: api.h:30
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by CsrCreateProcess().

◆ CsrReleaseCapturedArguments()

VOID NTAPI CsrReleaseCapturedArguments ( IN PCSR_API_MESSAGE  ApiMessage)

Definition at line 1235 of file api.c.

1236 {
1237  PCSR_CAPTURE_BUFFER RemoteCaptureBuffer, LocalCaptureBuffer;
1238  SIZE_T BufferDistance;
1239  ULONG PointerCount;
1240  PULONG_PTR OffsetPointer;
1241  ULONG_PTR CurrentOffset;
1242 
1243  /* Get the remote capture buffer */
1244  RemoteCaptureBuffer = ApiMessage->CsrCaptureData;
1245 
1246  /* Do not continue if there is no captured buffer */
1247  if (!RemoteCaptureBuffer) return;
1248 
1249  /* If there is one, get the corresponding local capture buffer */
1250  LocalCaptureBuffer = RemoteCaptureBuffer->PreviousCaptureBuffer;
1251 
1252  /* Free the previous one and use again the local capture buffer */
1253  RemoteCaptureBuffer->PreviousCaptureBuffer = NULL;
1254  ApiMessage->CsrCaptureData = LocalCaptureBuffer;
1255 
1256  /* Calculate the difference between our buffer and the client's */
1257  BufferDistance = (ULONG_PTR)RemoteCaptureBuffer - (ULONG_PTR)LocalCaptureBuffer;
1258 
1259  /*
1260  * All the pointer offsets correspond to pointers which point
1261  * to the local data buffer instead of the remote one (revert
1262  * the logic of CsrCaptureArguments).
1263  */
1264  PointerCount = RemoteCaptureBuffer->PointerCount;
1265  OffsetPointer = RemoteCaptureBuffer->PointerOffsetsArray;
1266  while (PointerCount--)
1267  {
1268  CurrentOffset = *OffsetPointer;
1269 
1270  if (CurrentOffset != 0)
1271  {
1272  /* Get the pointer corresponding to the offset */
1273  CurrentOffset += (ULONG_PTR)ApiMessage;
1274 
1275  /* Modify the pointed pointer to take into account its new position */
1276  *(PULONG_PTR)CurrentOffset -= BufferDistance;
1277  }
1278 
1279  ++OffsetPointer;
1280  }
1281 
1282  /* Copy the data back */
1283  RtlMoveMemory(LocalCaptureBuffer, RemoteCaptureBuffer, RemoteCaptureBuffer->Size);
1284 
1285  /* Free our allocated buffer */
1286  RtlFreeHeap(CsrHeap, 0, RemoteCaptureBuffer);
1287 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
struct _CSR_CAPTURE_BUFFER * PreviousCaptureBuffer
Definition: csrmsg.h:95
ULONG PointerCount
Definition: csrmsg.h:96
ULONG_PTR SIZE_T
Definition: typedefs.h:78
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
uint32_t * PULONG_PTR
Definition: typedefs.h:63
HANDLE CsrHeap
Definition: init.c:25
ULONG_PTR PointerOffsetsArray[ANYSIZE_ARRAY]
Definition: csrmsg.h:98

Referenced by CsrApiRequestThread(), and CsrNotifyWaitBlock().

◆ CsrRemoveProcess()

VOID NTAPI CsrRemoveProcess ( IN PCSR_PROCESS  CsrProcess)

Definition at line 319 of file procsup.c.

320 {
321  PCSR_SERVER_DLL ServerDll;
322  ULONG i;
324 
325  /* Remove us from the Process List */
326  RemoveEntryList(&CsrProcess->ListLink);
327 
328  /* Release the lock */
330 
331  /* Loop every Server DLL */
332  for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
333  {
334  /* Get the Server DLL */
335  ServerDll = CsrLoadedServerDll[i];
336 
337  /* Check if it's valid and if it has a Disconnect Callback */
338  if (ServerDll && ServerDll->DisconnectCallback)
339  {
340  /* Call it */
341  ServerDll->DisconnectCallback(CsrProcess);
342  }
343  }
344 }
PKPROCESS CsrProcess
Definition: videoprt.c:37
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define CsrReleaseProcessLock()
Definition: api.h:15
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define ProcessStructureListLocked()
Definition: api.h:18
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
PCSR_DISCONNECT_CALLBACK DisconnectCallback
Definition: csrsrv.h:236
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

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 */
444  Status = NtAcceptConnectPort(&hPort,
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 */
457  Status = NtCompleteConnectPort(hPort);
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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
struct _REMOTE_PORT_VIEW REMOTE_PORT_VIEW
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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CHAR Message[80]
Definition: alive.c:5
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI NtCompleteConnectPort(IN HANDLE PortHandle)
Definition: complete.c:421

Referenced by CsrSbApiRequestThread().

◆ CsrSbApiPortInitialize()

NTSTATUS NTAPI CsrSbApiPortInitialize ( VOID  )

Definition at line 869 of file init.c.

870 {
871  ULONG Size;
872  PSECURITY_DESCRIPTOR PortSd;
875  HANDLE hRequestThread;
877 
878  /* Calculate how much space we'll need for the Port Name */
879  Size = CsrDirectoryName.Length + sizeof(SB_PORT_NAME) + sizeof(WCHAR);
880 
881  /* Create the buffer for it */
884 
885  /* Setup the rest of the empty string */
888 
889  /* Now append the full port name */
893  if (CsrDebug & 2) DPRINT1("CSRSS: Creating %wZ port and associated thread\n", &CsrSbApiPortName);
894 
895  /* Create Security Descriptor for this Port */
896  Status = CsrCreateLocalSystemSD(&PortSd);
897  if (!NT_SUCCESS(Status)) return Status;
898 
899  /* Initialize the Attributes */
902  0,
903  NULL,
904  PortSd);
905 
906  /* Create the Port Object */
909  sizeof(SB_CONNECTION_INFO),
910  sizeof(SB_API_MSG),
911  32 * sizeof(SB_API_MSG));
912  if (PortSd) RtlFreeHeap(CsrHeap, 0, PortSd);
913 
914  if (NT_SUCCESS(Status))
915  {
916  /* Create the Thread to handle the API Requests */
918  NULL,
919  TRUE,
920  0,
921  0,
922  0,
924  NULL,
925  &hRequestThread,
926  &ClientId);
927  if (NT_SUCCESS(Status))
928  {
929  /* Add it as a Static Server Thread */
931  &ClientId,
932  0);
933 
934  /* Activate it */
935  Status = NtResumeThread(hRequestThread, NULL);
936  }
937  }
938 
939  return Status;
940 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define SB_PORT_NAME
Definition: srv.h:47
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
PCSR_THREAD CsrSbApiRequestThreadPtr
Definition: init.c:30
VOID NTAPI CsrSbApiRequestThread(IN PVOID Parameter)
Definition: session.c:484
UNICODE_STRING CsrSbApiPortName
Definition: init.c:28
PCSR_THREAD NTAPI CsrAddStaticServerThread(IN HANDLE hThread, IN PCLIENT_ID ClientId, IN ULONG ThreadFlags)
Definition: thredsup.c:511
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
NTSTATUS NTAPI NtCreatePort(OUT PHANDLE PortHandle, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG MaxConnectInfoLength, IN ULONG MaxDataLength, IN ULONG MaxPoolUsage)
Definition: create.c:212
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI CsrCreateLocalSystemSD(OUT PSECURITY_DESCRIPTOR *LocalSystemSd)
Definition: init.c:801
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)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
HANDLE CsrSbApiPort
Definition: init.c:29
unsigned short USHORT
Definition: pedump.c:61
#define UNICODE_PATH_SEP
Definition: connect.c:33
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING CsrDirectoryName
Definition: init.c:27
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
ULONG CsrDebug
Definition: init.c:23
HANDLE CsrHeap
Definition: init.c:25

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 */
520  CsrSbApiHandleConnectionRequest(&ReceiveMsg);
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 TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
PORT_MESSAGE h
Definition: smmsg.h:202
NTSTATUS NTAPI CsrSbApiHandleConnectionRequest(IN PSB_API_MSG Message)
Definition: session.c:434
LONG NTSTATUS
Definition: precomp.h:26
PSB_API_ROUTINE CsrServerSbApiDispatch[SbpMaxApiNumber - SbpCreateSession]
Definition: session.c:21
SB_API_NUMBER ApiNumber
Definition: smmsg.h:208
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS ReturnValue
Definition: smmsg.h:209
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
PCHAR CsrServerSbApiName[SbpMaxApiNumber - SbpCreateSession]
Definition: session.c:29
NTSTATUS NTAPI NtReplyWaitReceivePort(IN HANDLE PortHandle, OUT PVOID *PortContext OPTIONAL, IN PPORT_MESSAGE ReplyMessage OPTIONAL, OUT PPORT_MESSAGE ReceiveMessage)
Definition: reply.c:743
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938
HANDLE CsrSbApiPort
Definition: init.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 }
#define TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225

◆ 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->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 */
251  return (BOOLEAN)STATUS_NO_MEMORY;
252  }
253 
254  /* Get the Create Time */
256  ThreadTimes,
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 }
#define TRUE
Definition: types.h:120
PCSR_PROCESS NTAPI CsrAllocateProcess(VOID)
Definition: procsup.c:188
ULONG SizeOfProcessData
Definition: csrsrv.h:234
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
PKPROCESS CsrProcess
Definition: videoprt.c:37
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define CsrReleaseProcessLock()
Definition: api.h:15
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
void * PVOID
Definition: retypes.h:9
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
LARGE_INTEGER CreateTime
Definition: csrsrv.h:65
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID ClientId
Definition: csrsrv.h:68
VOID NTAPI CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:296
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
PCSR_NT_SESSION NTAPI CsrAllocateNtSession(IN ULONG SessionId)
Definition: session.c:77
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2497
HANDLE ThreadHandle
Definition: csrsrv.h:71
#define CsrAcquireProcessLock()
Definition: api.h:12
Status
Definition: gdiplustypes.h:24
HANDLE CsrApiPort
Definition: connect.c:21
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
HANDLE hThread
Definition: wizard.c:27
VOID NTAPI CsrSetBackgroundPriority(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1098
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL, IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:365
ULONG Flags
Definition: csrsrv.h:72
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20
MMRESULT CreateSession(DeviceType device_type, UINT device_id, SessionInfo **session_info)
Definition: session.c:63

◆ 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 }
#define TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225

◆ 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 }
#define TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225

◆ CsrServerDllInitialization()

NTSTATUS NTAPI CsrServerDllInitialization ( IN PCSR_SERVER_DLL  LoadedServerDll)

Referenced by CsrLoadServerDll().

◆ CsrSetDirectorySecurity()

NTSTATUS NTAPI CsrSetDirectorySecurity ( IN HANDLE  ObjectDirectory)

Definition at line 176 of file init.c.

177 {
178  /* FIXME: Implement */
179  return STATUS_SUCCESS;
180 }
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by CsrParseServerCommandLine().

◆ CsrSrvAttachSharedSection()

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

Definition at line 456 of file server.c.

458 {
460  SIZE_T ViewSize = 0;
461 
462  /* Check if we have a process */
463  if (CsrProcess)
464  {
465  /* Map the section into this process */
467  CsrProcess->ProcessHandle,
469  0,
470  0,
471  NULL,
472  &ViewSize,
473  ViewUnmap,
476  if (!NT_SUCCESS(Status)) return Status;
477  }
478 
479  /* Write the values in the Connection Info structure */
480  ConnectInfo->SharedSectionBase = CsrSrvSharedSectionBase;
481  ConnectInfo->SharedSectionHeap = CsrSrvSharedSectionHeap;
482  ConnectInfo->SharedStaticServerData = CsrSrvSharedStaticServerData;
483 
484  /* Return success */
485  return STATUS_SUCCESS;
486 }
PVOID CsrSrvSharedSectionHeap
Definition: server.c:21
LONG NTSTATUS
Definition: precomp.h:26
PKPROCESS CsrProcess
Definition: videoprt.c:37
PVOID * CsrSrvSharedStaticServerData
Definition: server.c:23
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:3554
PVOID CsrSrvSharedSectionBase
Definition: server.c:22
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
HANDLE CsrSrvSharedSection
Definition: server.c:25
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define SEC_NO_CHANGE
Definition: mmtypes.h:94

Referenced by CsrApiHandleConnectionRequest().

◆ CsrSrvCreateSharedSection()

NTSTATUS NTAPI CsrSrvCreateSharedSection ( IN PCHAR  ParameterValue)

Definition at line 335 of file server.c.

336 {
337  PCHAR SizeValue = ParameterValue;
338  ULONG Size;
340  LARGE_INTEGER SectionSize;
341  SIZE_T ViewSize = 0;
342  PPEB Peb = NtCurrentPeb();
343 
344  /* If there's no parameter, fail */
346 
347  /* Find the first comma, and null terminate */
348  while (*SizeValue)
349  {
350  if (*SizeValue == ',')
351  {
352  *SizeValue++ = ANSI_NULL;
353  break;
354  }
355  else
356  {
357  SizeValue++;
358  }
359  }
360 
361  /* Make sure it's valid */
362  if (!*SizeValue) return STATUS_INVALID_PARAMETER;
363 
364  /* Convert it to an integer */
365  Status = RtlCharToInteger(SizeValue, 0, &Size);
366  if (!NT_SUCCESS(Status)) return Status;
367 
368  /* Multiply by 1024 entries and round to page size */
370 
371  /* Create the Secion */
372  SectionSize.LowPart = CsrSrvSharedSectionSize;
373  SectionSize.HighPart = 0;
376  NULL,
377  &SectionSize,
380  NULL);
381  if (!NT_SUCCESS(Status)) return Status;
382 
383  /* Map the section */
387  0,
388  0,
389  NULL,
390  &ViewSize,
391  ViewUnmap,
392  MEM_TOP_DOWN,
394  if (!NT_SUCCESS(Status))
395  {
396  /* Fail */
398  return Status;
399  }
400 
401  /* FIXME: Write the value to registry */
402 
403  /* The Heap is the same place as the Base */
405 
406  /* Create the heap */
410  PAGE_SIZE,
411  0,
412  0)))
413  {
414  /* Failure, unmap section and return */
417  return STATUS_NO_MEMORY;
418  }
419 
420  /* Now allocate space from the heap for the Shared Data */
423  CSR_SERVER_DLL_MAX * sizeof(PVOID));
425 
426  /* Write the values to the PEB */
430 
431  /* Return */
432  return STATUS_SUCCESS;
433 }
signed char * PCHAR
Definition: retypes.h:7
NTSYSAPI NTSTATUS NTAPI RtlCharToInteger(PCSZ String, ULONG Base, PULONG Value)
Definition: unicode.c:261
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
PPEB Peb
Definition: dllmain.c:27
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
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:3373
PVOID CsrSrvSharedSectionHeap
Definition: server.c:21
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
ULONG CsrSrvSharedSectionSize
Definition: server.c:24
LONG NTSTATUS
Definition: precomp.h:26
PVOID ReadOnlySharedMemoryHeap
Definition: ntddk_ex.h:262
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
#define SEC_BASED
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
PVOID * CsrSrvSharedStaticServerData
Definition: server.c:23
#define ANSI_NULL
#define SEC_RESERVE
Definition: nt_native.h:1323
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:3554
PVOID CsrSrvSharedSectionBase
Definition: server.c:22
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define HEAP_CLASS_7
Definition: nt_native.h:1717
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
SYSTEM_BASIC_INFORMATION CsrNtSysInfo
Definition: init.c:40
_In_opt_ PWSTR _In_ PWSTR _Inout_ PULONG ParameterValue
Definition: classpnp.h:1209
ULONG LowPart
Definition: typedefs.h:104
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)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
HANDLE CsrSrvSharedSection
Definition: server.c:25
#define NtCurrentPeb()
Definition: FLS.c:20
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
unsigned int ULONG
Definition: retypes.h:1
PVOID ReadOnlySharedMemoryBase
Definition: ntddk_ex.h:261
PVOID * ReadOnlyStaticServerData
Definition: ntddk_ex.h:263
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define MEM_TOP_DOWN
Definition: nt_native.h:1321
return STATUS_SUCCESS
Definition: btrfs.c:2938

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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtSetInformationObject(IN HANDLE ObjectHandle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, IN PVOID ObjectInformation, IN ULONG Length)
Definition: oblife.c:1735
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NtQueryObject(IN HANDLE Handle, IN OBJECT_INFO_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OUT PULONG ReturnLength)
Status
Definition: gdiplustypes.h:24

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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtSetInformationObject(IN HANDLE ObjectHandle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, IN PVOID ObjectInformation, IN ULONG Length)
Definition: oblife.c:1735
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NtQueryObject(IN HANDLE Handle, IN OBJECT_INFO_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OUT PULONG ReturnLength)
Status
Definition: gdiplustypes.h:24

Referenced by CsrThreadRefcountZero().

Variable Documentation

◆ CsrApiPort

HANDLE CsrApiPort

Definition at line 21 of file connect.c.

◆ CsrApiPortName

UNICODE_STRING CsrApiPortName

Definition at line 22 of file api.c.

Referenced by CsrApiPortInitialize().

◆ CsrDebug

◆ CsrDirectoryName

UNICODE_STRING CsrDirectoryName

Definition at line 27 of file init.c.

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

◆ CsrHeap

◆ CsrInitializationEvent

HANDLE CsrInitializationEvent

◆ CsrLoadedServerDll

◆ CsrMaxApiRequestThreads

ULONG CsrMaxApiRequestThreads

Definition at line 34 of file init.c.

Referenced by CsrParseServerCommandLine().

◆ CsrNtSysInfo

Definition at line 40 of file init.c.

Referenced by CsrServerInitialization(), and CsrSrvCreateSharedSection().

◆ CsrObjectDirectory

HANDLE CsrObjectDirectory

Definition at line 26 of file init.c.

Referenced by CsrParseServerCommandLine().

◆ CsrProcessLock

RTL_CRITICAL_SECTION CsrProcessLock

Definition at line 60 of file api.h.

Referenced by CsrInitializeProcessStructure().

◆ CsrRootProcess

◆ CsrSbApiPort

HANDLE CsrSbApiPort

Definition at line 29 of file init.c.

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

◆ CsrSbApiPortName

UNICODE_STRING CsrSbApiPortName

Definition at line 28 of file init.c.

Referenced by CsrSbApiPortInitialize(), and CsrServerInitialization().

◆ CsrSmApiPort

HANDLE CsrSmApiPort

Definition at line 31 of file init.c.

Referenced by CsrDereferenceNtSession(), and CsrServerInitialization().

◆ CsrSrvSharedSectionHeap

PVOID CsrSrvSharedSectionHeap

Definition at line 21 of file server.c.

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

◆ CsrSrvSharedStaticServerData

PVOID* CsrSrvSharedStaticServerData

Definition at line 23 of file server.c.

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

◆ CsrThreadHashTable

◆ CsrTotalPerProcessDataLength

ULONG CsrTotalPerProcessDataLength

Definition at line 35 of file init.c.

Referenced by CsrLoadServerDll().

◆ CsrWaitListsLock

RTL_CRITICAL_SECTION CsrWaitListsLock

Definition at line 61 of file api.h.

Referenced by CsrInitializeProcessStructure().

◆ hBootstrapOk

HANDLE hBootstrapOk