ReactOS  0.4.15-dev-1389-g828d5fa
csr.h File Reference
#include "csrmsg.h"
Include dependency graph for csr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

NTSTATUS NTAPI CsrClientConnectToServer (IN PWSTR ObjectDirectory, IN ULONG ServerId, IN PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoSize, OUT PBOOLEAN ServerToServerCall)
 
NTSTATUS NTAPI CsrClientCallServer (IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
 
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer (IN ULONG ArgumentCount, IN ULONG BufferSize)
 
ULONG NTAPI CsrAllocateMessagePointer (IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN ULONG MessageLength, OUT PVOID *CapturedData)
 
VOID NTAPI CsrCaptureMessageBuffer (IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN PVOID MessageBuffer OPTIONAL, IN ULONG MessageLength, OUT PVOID *CapturedData)
 
VOID NTAPI CsrFreeCaptureBuffer (IN PCSR_CAPTURE_BUFFER CaptureBuffer)
 
VOID NTAPI CsrCaptureMessageString (IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN PCSTR String OPTIONAL, IN ULONG StringLength, IN ULONG MaximumLength, OUT PSTRING CapturedString)
 
NTSTATUS NTAPI CsrCaptureMessageMultiUnicodeStringsInPlace (OUT PCSR_CAPTURE_BUFFER *CaptureBuffer, IN ULONG StringsCount, IN PUNICODE_STRING *MessageStrings)
 
PLARGE_INTEGER NTAPI CsrCaptureTimeout (IN ULONG Milliseconds, OUT PLARGE_INTEGER Timeout)
 
VOID NTAPI CsrProbeForRead (IN PVOID Address, IN ULONG Length, IN ULONG Alignment)
 
VOID NTAPI CsrProbeForWrite (IN PVOID Address, IN ULONG Length, IN ULONG Alignment)
 
NTSTATUS NTAPI CsrIdentifyAlertableThread (VOID)
 
HANDLE NTAPI CsrGetProcessId (VOID)
 
NTSTATUS NTAPI CsrNewThread (VOID)
 
NTSTATUS NTAPI CsrSetPriorityClass (IN HANDLE Process, IN OUT PULONG PriorityClass)
 

Function Documentation

◆ CsrAllocateCaptureBuffer()

PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer ( IN ULONG  ArgumentCount,
IN ULONG  BufferSize 
)

Definition at line 90 of file capture.c.

92 {
93  PCSR_CAPTURE_BUFFER CaptureBuffer;
94  ULONG OffsetsArraySize;
96 
97  /* Validate the argument count. Note that on server side, CSRSRV
98  * limits the count to MAXUSHORT; here we are a bit more lenient. */
99  if (ArgumentCount > (MAXLONG / sizeof(ULONG_PTR)))
100  return NULL;
101 
102  OffsetsArraySize = ArgumentCount * sizeof(ULONG_PTR);
103 
104  /*
105  * Validate the total buffer size.
106  * The total size of the header plus the pointer-offset array and the
107  * provided buffer, together with the alignment padding for each argument,
108  * must be less than MAXLONG aligned to 4-byte boundary.
109  */
110  MaximumSize = (MAXLONG & ~3) - FIELD_OFFSET(CSR_CAPTURE_BUFFER, PointerOffsetsArray);
111  if (OffsetsArraySize >= MaximumSize)
112  return NULL;
113  MaximumSize -= OffsetsArraySize;
114  if (BufferSize >= MaximumSize)
115  return NULL;
117  if ((ArgumentCount * 3) + 3 >= MaximumSize)
118  return NULL;
119 
120  /* Add the size of the header and of the pointer-offset array */
121  BufferSize += FIELD_OFFSET(CSR_CAPTURE_BUFFER, PointerOffsetsArray) +
122  OffsetsArraySize;
123 
124  /* Add the size of the alignment padding for each argument */
125  BufferSize += ArgumentCount * 3;
126 
127  /* Align it to a 4-byte boundary */
128  BufferSize = (BufferSize + 3) & ~3;
129 
130  /* Allocate memory from the port heap */
132  if (CaptureBuffer == NULL) return NULL;
133 
134  /* Initialize the header */
135  CaptureBuffer->Size = BufferSize;
136  CaptureBuffer->PointerCount = 0;
137 
138  /* Initialize the pointer-offset array */
139  RtlZeroMemory(CaptureBuffer->PointerOffsetsArray, OffsetsArraySize);
140 
141  /* Point to the start of the free buffer */
142  CaptureBuffer->BufferEnd = (PVOID)((ULONG_PTR)CaptureBuffer->PointerOffsetsArray +
143  OffsetsArraySize);
144 
145  /* Return the address of the buffer */
146  return CaptureBuffer;
147 }
#define MAXLONG
Definition: umtypes.h:116
HANDLE CsrPortHeap
Definition: connect.c:23
uint32_t ULONG_PTR
Definition: typedefs.h:65
void * PVOID
Definition: retypes.h:9
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
ULONG PointerCount
Definition: csrmsg.h:96
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
ULONG_PTR PointerOffsetsArray[ANYSIZE_ARRAY]
Definition: csrmsg.h:98
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251

Referenced by BaseCheckVDM(), CreateConsoleScreenBuffer(), CsrCaptureMessageMultiUnicodeStringsInPlace(), CsrClientConnectToServer(), DefineDosDeviceW(), DeviceEventWorker(), GetConsoleFontInfo(), GetConsoleProcessList(), GetNextVDMCommand(), GetVDMCurrentDirectories(), IntAddConsoleAlias(), IntAllocConsole(), IntAttachConsole(), IntExpungeConsoleCommandHistory(), IntGetConsoleAlias(), IntGetConsoleAliases(), IntGetConsoleAliasesLength(), IntGetConsoleAliasExes(), IntGetConsoleCommandHistory(), IntGetConsoleCommandHistoryLength(), IntGetConsoleInput(), IntGetConsoleTitle(), IntReadConsole(), IntReadConsoleOutput(), IntReadConsoleOutputCode(), IntSetConsoleNumberOfCommands(), IntSetConsoleTitle(), IntWriteConsole(), IntWriteConsoleInput(), IntWriteConsoleOutput(), IntWriteConsoleOutputCode(), RegisterConsoleVDM(), and SetVDMCurrentDirectories().

◆ CsrAllocateMessagePointer()

ULONG NTAPI CsrAllocateMessagePointer ( IN OUT PCSR_CAPTURE_BUFFER  CaptureBuffer,
IN ULONG  MessageLength,
OUT PVOID CapturedData 
)

Definition at line 154 of file capture.c.

157 {
158  if (MessageLength == 0)
159  {
160  *CapturedData = NULL;
161  CapturedData = NULL;
162  }
163  else
164  {
165  /* Set the capture data at our current available buffer */
166  *CapturedData = CaptureBuffer->BufferEnd;
167 
168  /* Validate the size */
169  if (MessageLength >= MAXLONG) return 0;
170 
171  /* Align it to a 4-byte boundary */
172  MessageLength = (MessageLength + 3) & ~3;
173 
174  /* Move our available buffer beyond this space */
175  CaptureBuffer->BufferEnd = (PVOID)((ULONG_PTR)CaptureBuffer->BufferEnd + MessageLength);
176  }
177 
178  /* Write down this pointer in the array and increase the count */
179  CaptureBuffer->PointerOffsetsArray[CaptureBuffer->PointerCount++] = (ULONG_PTR)CapturedData;
180 
181  /* Return the aligned length */
182  return MessageLength;
183 }
#define MAXLONG
Definition: umtypes.h:116
uint32_t ULONG_PTR
Definition: typedefs.h:65
void * PVOID
Definition: retypes.h:9
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101

Referenced by CsrCaptureMessageBuffer(), CsrCaptureMessageString(), DefineDosDeviceW(), GetConsoleFontInfo(), GetConsoleProcessList(), GetNextVDMCommand(), GetVDMCurrentDirectories(), IntGetConsoleAlias(), IntGetConsoleAliases(), IntGetConsoleAliasExes(), IntGetConsoleCommandHistory(), IntGetConsoleInput(), IntGetConsoleTitle(), IntReadConsole(), IntReadConsoleOutput(), IntReadConsoleOutputCode(), and IntWriteConsoleOutput().

◆ CsrCaptureMessageBuffer()

VOID NTAPI CsrCaptureMessageBuffer ( IN OUT PCSR_CAPTURE_BUFFER  CaptureBuffer,
IN PVOID MessageBuffer  OPTIONAL,
IN ULONG  MessageLength,
OUT PVOID CapturedData 
)

Definition at line 190 of file capture.c.

194 {
195  /* Simply allocate a message pointer in the buffer */
196  CsrAllocateMessagePointer(CaptureBuffer, MessageLength, CapturedData);
197 
198  /* Check if there was any data */
199  if (!MessageBuffer || !MessageLength) return;
200 
201  /* Copy the data into the buffer */
202  RtlMoveMemory(*CapturedData, MessageBuffer, MessageLength);
203 }
ULONG NTAPI CsrAllocateMessagePointer(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN ULONG MessageLength, OUT PVOID *CapturedData)
Definition: capture.c:154
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264

Referenced by BaseCheckVDM(), CreateConsoleScreenBuffer(), CsrClientConnectToServer(), DeviceEventWorker(), IntAddConsoleAlias(), IntAllocConsole(), IntAttachConsole(), IntExpungeConsoleCommandHistory(), IntGetConsoleAlias(), IntGetConsoleAliases(), IntGetConsoleAliasesLength(), IntGetConsoleCommandHistory(), IntGetConsoleCommandHistoryLength(), IntSetConsoleNumberOfCommands(), IntSetConsoleTitle(), IntWriteConsole(), IntWriteConsoleInput(), IntWriteConsoleOutputCode(), RegisterConsoleVDM(), and SetVDMCurrentDirectories().

◆ CsrCaptureMessageMultiUnicodeStringsInPlace()

NTSTATUS NTAPI CsrCaptureMessageMultiUnicodeStringsInPlace ( OUT PCSR_CAPTURE_BUFFER CaptureBuffer,
IN ULONG  StringsCount,
IN PUNICODE_STRING MessageStrings 
)

Definition at line 292 of file capture.c.

295 {
296  ULONG Count;
297 
298  if (!CaptureBuffer) return STATUS_INVALID_PARAMETER;
299 
300  /* Allocate a new capture buffer if we don't have one already */
301  if (!*CaptureBuffer)
302  {
303  /* Compute the required size for the capture buffer */
304  ULONG Size = 0;
305 
306  Count = 0;
307  while (Count < StringsCount)
308  {
309  if (MessageStrings[Count])
310  Size += MessageStrings[Count]->MaximumLength;
311 
312  ++Count;
313  }
314 
315  /* Allocate the capture buffer */
316  *CaptureBuffer = CsrAllocateCaptureBuffer(StringsCount, Size);
317  if (!*CaptureBuffer) return STATUS_NO_MEMORY;
318  }
319 
320  /* Now capture each UNICODE string */
321  Count = 0;
322  while (Count < StringsCount)
323  {
324  if (MessageStrings[Count])
325  CsrCaptureMessageUnicodeStringInPlace(*CaptureBuffer, MessageStrings[Count]);
326 
327  ++Count;
328  }
329 
330  return STATUS_SUCCESS;
331 }
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer(IN ULONG ArgumentCount, IN ULONG BufferSize)
Definition: capture.c:90
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
int Count
Definition: noreturn.cpp:7
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
static VOID CsrCaptureMessageUnicodeStringInPlace(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN PUNICODE_STRING String)
Definition: capture.c:268
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ CsrCaptureMessageString()

VOID NTAPI CsrCaptureMessageString ( IN OUT PCSR_CAPTURE_BUFFER  CaptureBuffer,
IN PCSTR String  OPTIONAL,
IN ULONG  StringLength,
IN ULONG  MaximumLength,
OUT PSTRING  CapturedString 
)

Definition at line 221 of file capture.c.

226 {
227  ASSERT(CapturedString != NULL);
228 
229  /*
230  * If we don't have a string, initialize an empty one,
231  * otherwise capture the given string.
232  */
233  if (!String)
234  {
235  CapturedString->Length = 0;
236  CapturedString->MaximumLength = (USHORT)MaximumLength;
237 
238  /* Allocate a pointer for it */
239  CsrAllocateMessagePointer(CaptureBuffer,
241  (PVOID*)&CapturedString->Buffer);
242  }
243  else
244  {
245  /* Cut-off the string length if needed */
246  if (StringLength > MaximumLength)
247  StringLength = MaximumLength;
248 
249  CapturedString->Length = (USHORT)StringLength;
250 
251  /* Allocate a buffer and get its size */
252  CapturedString->MaximumLength =
253  (USHORT)CsrAllocateMessagePointer(CaptureBuffer,
255  (PVOID*)&CapturedString->Buffer);
256 
257  /* If the string has data, copy it into the buffer */
258  if (StringLength)
259  RtlMoveMemory(CapturedString->Buffer, String, StringLength);
260  }
261 
262  /* Null-terminate the string if we don't take up the whole space */
263  if (CapturedString->Length < CapturedString->MaximumLength)
264  CapturedString->Buffer[CapturedString->Length] = '\0';
265 }
ULONG NTAPI CsrAllocateMessagePointer(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN ULONG MessageLength, OUT PVOID *CapturedData)
Definition: capture.c:154
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength
#define ASSERT(a)
Definition: mode.c:45
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112

Referenced by CsrCaptureMessageUnicodeStringInPlace().

◆ CsrCaptureTimeout()

PLARGE_INTEGER NTAPI CsrCaptureTimeout ( IN ULONG  Milliseconds,
OUT PLARGE_INTEGER  Timeout 
)

Definition at line 338 of file capture.c.

340 {
341  /* Validate the time */
342  if (Milliseconds == -1) return NULL;
343 
344  /* Convert to relative ticks */
345  Timeout->QuadPart = Milliseconds * -10000LL;
346  return Timeout;
347 }
#define LL
Definition: tui.h:84
static ULONG Timeout
Definition: ping.c:61
#define NULL
Definition: types.h:112

◆ CsrClientCallServer()

NTSTATUS NTAPI CsrClientCallServer ( IN OUT PCSR_API_MESSAGE  ApiMessage,
IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer  OPTIONAL,
IN CSR_API_NUMBER  ApiNumber,
IN ULONG  DataLength 
)

Definition at line 365 of file connect.c.

369 {
371  ULONG PointerCount;
372  PULONG_PTR OffsetPointer;
373 
374  /* Make sure the length is valid */
375  if (DataLength > (MAXSHORT - sizeof(CSR_API_MESSAGE)))
376  {
377  DPRINT1("DataLength too big: %lu", DataLength);
379  }
380 
381  /* Fill out the Port Message Header */
382  ApiMessage->Header.u2.ZeroInit = 0;
383  ApiMessage->Header.u1.s1.TotalLength = (CSHORT)DataLength +
384  sizeof(CSR_API_MESSAGE) - sizeof(ApiMessage->Data); // FIELD_OFFSET(CSR_API_MESSAGE, Data) + DataLength;
385  ApiMessage->Header.u1.s1.DataLength = (CSHORT)DataLength +
386  FIELD_OFFSET(CSR_API_MESSAGE, Data) - sizeof(ApiMessage->Header); // ApiMessage->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE);
387 
388  /* Fill out the CSR Header */
389  ApiMessage->ApiNumber = ApiNumber;
390  ApiMessage->CsrCaptureData = NULL;
391 
392  DPRINT("API: %lx, u1.s1.DataLength: %x, u1.s1.TotalLength: %x\n",
393  ApiNumber,
394  ApiMessage->Header.u1.s1.DataLength,
395  ApiMessage->Header.u1.s1.TotalLength);
396 
397  /* Check if we are already inside a CSR Server */
398  if (!InsideCsrProcess)
399  {
400  /* Check if we got a Capture Buffer */
401  if (CaptureBuffer)
402  {
403  /*
404  * We have to convert from our local (client) view
405  * to the remote (server) view.
406  */
407  ApiMessage->CsrCaptureData = (PCSR_CAPTURE_BUFFER)
408  ((ULONG_PTR)CaptureBuffer + CsrPortMemoryDelta);
409 
410  /* Lock the buffer */
411  CaptureBuffer->BufferEnd = NULL;
412 
413  /*
414  * Each client pointer inside the CSR message is converted into
415  * a server pointer, and each pointer to these message pointers
416  * is converted into an offset.
417  */
418  PointerCount = CaptureBuffer->PointerCount;
419  OffsetPointer = CaptureBuffer->PointerOffsetsArray;
420  while (PointerCount--)
421  {
422  if (*OffsetPointer != 0)
423  {
424  *(PULONG_PTR)*OffsetPointer += CsrPortMemoryDelta;
425  *OffsetPointer -= (ULONG_PTR)ApiMessage;
426  }
427  ++OffsetPointer;
428  }
429  }
430 
431  /* Send the LPC Message */
433  &ApiMessage->Header,
434  &ApiMessage->Header);
435 
436  /* Check if we got a Capture Buffer */
437  if (CaptureBuffer)
438  {
439  /*
440  * We have to convert back from the remote (server) view
441  * to our local (client) view.
442  */
443  ApiMessage->CsrCaptureData = (PCSR_CAPTURE_BUFFER)
444  ((ULONG_PTR)ApiMessage->CsrCaptureData - CsrPortMemoryDelta);
445 
446  /*
447  * Convert back the offsets into pointers to CSR message
448  * pointers, and convert back these message server pointers
449  * into client pointers.
450  */
451  PointerCount = CaptureBuffer->PointerCount;
452  OffsetPointer = CaptureBuffer->PointerOffsetsArray;
453  while (PointerCount--)
454  {
455  if (*OffsetPointer != 0)
456  {
457  *OffsetPointer += (ULONG_PTR)ApiMessage;
458  *(PULONG_PTR)*OffsetPointer -= CsrPortMemoryDelta;
459  }
460  ++OffsetPointer;
461  }
462  }
463 
464  /* Check for success */
465  if (!NT_SUCCESS(Status))
466  {
467  /* We failed. Overwrite the return value with the failure. */
468  DPRINT1("LPC Failed: %lx\n", Status);
469  ApiMessage->Status = Status;
470  }
471  }
472  else
473  {
474  /* This is a server-to-server call. Save our CID and do a direct call. */
475  DPRINT("Next gen server-to-server call\n");
476 
477  /* We check this equality inside CsrValidateMessageBuffer */
478  ApiMessage->Header.ClientId = NtCurrentTeb()->ClientId;
479 
480  Status = CsrServerApiRoutine(&ApiMessage->Header,
481  &ApiMessage->Header);
482 
483  /* Check for success */
484  if (!NT_SUCCESS(Status))
485  {
486  /* We failed. Overwrite the return value with the failure. */
487  ApiMessage->Status = Status;
488  }
489  }
490 
491  /* Return the CSR Result */
492  DPRINT("Got back: 0x%lx\n", ApiMessage->Status);
493  return ApiMessage->Status;
494 }
PCSR_SERVER_API_ROUTINE CsrServerApiRoutine
Definition: connect.c:31
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:695
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:65
void DPRINT(...)
Definition: polytest.cpp:61
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1437
struct _CSR_CAPTURE_BUFFER * PCSR_CAPTURE_BUFFER
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN InsideCsrProcess
Definition: connect.c:25
ULONG_PTR CsrPortMemoryDelta
Definition: connect.c:24
#define MAXSHORT
Definition: umtypes.h:114
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
HANDLE CsrApiPort
Definition: connect.c:21
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
uint32_t * PULONG_PTR
Definition: typedefs.h:65
short CSHORT
Definition: umtypes.h:127

◆ CsrClientConnectToServer()

NTSTATUS NTAPI CsrClientConnectToServer ( IN PWSTR  ObjectDirectory,
IN ULONG  ServerId,
IN PVOID  ConnectionInfo,
IN OUT PULONG  ConnectionInfoSize,
OUT PBOOLEAN  ServerToServerCall 
)

Definition at line 197 of file connect.c.

202 {
204  PIMAGE_NT_HEADERS NtHeader;
205  UNICODE_STRING CsrSrvName;
206  HANDLE hCsrSrv;
207  ANSI_STRING CsrServerRoutineName;
208  CSR_API_MESSAGE ApiMessage;
209  PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage.Data.CsrClientConnect;
210  PCSR_CAPTURE_BUFFER CaptureBuffer;
211 
212  DPRINT("CsrClientConnectToServer: %lx %p\n", ServerId, ConnectionInfo);
213 
214  /* Validate the Connection Info */
215  if (ConnectionInfo && (!ConnectionInfoSize || !*ConnectionInfoSize))
216  {
217  DPRINT1("Connection info given, but no length\n");
219  }
220 
221  /* Check if we're inside a CSR Process */
222  if (InsideCsrProcess)
223  {
224  /* Tell the client that we're already inside CSR */
225  if (ServerToServerCall) *ServerToServerCall = TRUE;
226  return STATUS_SUCCESS;
227  }
228 
229  /*
230  * We might be in a CSR Process but not know it, if this is the first call.
231  * So let's find out.
232  */
233  if (!(NtHeader = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress)))
234  {
235  /* The image isn't valid */
236  DPRINT1("Invalid image\n");
238  }
240 
241  /* Now we can check if we are inside or not */
242  if (InsideCsrProcess)
243  {
244  /* We're inside, so let's find csrsrv */
245  DPRINT("Next-GEN CSRSS support\n");
246  RtlInitUnicodeString(&CsrSrvName, L"csrsrv");
248  NULL,
249  &CsrSrvName,
250  &hCsrSrv);
251 
252  /* Now get the Server to Server routine */
253  RtlInitAnsiString(&CsrServerRoutineName, "CsrCallServerFromServer");
254  Status = LdrGetProcedureAddress(hCsrSrv,
255  &CsrServerRoutineName,
256  0L,
258 
259  /* Use the local heap as port heap */
260  CsrPortHeap = RtlGetProcessHeap();
261 
262  /* Tell the caller we're inside the server */
263  if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
264  return STATUS_SUCCESS;
265  }
266 
267  /* Now check if connection info is given */
268  if (ConnectionInfo)
269  {
270  /* Well, we're definitely in a client now */
272 
273  /* Do we have a connection to CSR yet? */
274  if (!CsrApiPort)
275  {
276  /* No, set it up now */
277  Status = CsrpConnectToServer(ObjectDirectory);
278  if (!NT_SUCCESS(Status))
279  {
280  /* Failed */
281  DPRINT1("Failure to connect to CSR\n");
282  return Status;
283  }
284  }
285 
286  /* Setup the connect message header */
287  ClientConnect->ServerId = ServerId;
288  ClientConnect->ConnectionInfoSize = *ConnectionInfoSize;
289 
290  /* Setup a buffer for the connection info */
291  CaptureBuffer = CsrAllocateCaptureBuffer(1, ClientConnect->ConnectionInfoSize);
292  if (CaptureBuffer == NULL)
293  {
295  }
296 
297  /* Capture the connection info data */
298  CsrCaptureMessageBuffer(CaptureBuffer,
299  ConnectionInfo,
300  ClientConnect->ConnectionInfoSize,
301  &ClientConnect->ConnectionInfo);
302 
303  /* Return the allocated length */
304  *ConnectionInfoSize = ClientConnect->ConnectionInfoSize;
305 
306  /* Call CSR */
307  Status = CsrClientCallServer(&ApiMessage,
308  CaptureBuffer,
310  sizeof(CSR_CLIENT_CONNECT));
311 
312  /* Copy the updated connection info data back into the user buffer */
313  RtlMoveMemory(ConnectionInfo,
314  ClientConnect->ConnectionInfo,
315  *ConnectionInfoSize);
316 
317  /* Free the capture buffer */
318  CsrFreeCaptureBuffer(CaptureBuffer);
319  }
320  else
321  {
322  /* No connection info, just return */
324  }
325 
326  /* Let the caller know if this was server to server */
327  DPRINT("Status was: 0x%lx. Are we in server: 0x%x\n", Status, InsideCsrProcess);
328  if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
329 
330  return Status;
331 }
VOID NTAPI CsrFreeCaptureBuffer(IN PCSR_CAPTURE_BUFFER CaptureBuffer)
Definition: capture.c:210
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI LdrGetDllHandle(IN PWSTR DllPath OPTIONAL, IN PULONG DllCharacteristics OPTIONAL, IN PUNICODE_STRING DllName, OUT PVOID *DllHandle)
Definition: ldrapi.c:805
PCSR_SERVER_API_ROUTINE CsrServerApiRoutine
Definition: connect.c:31
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer(IN ULONG ArgumentCount, IN ULONG BufferSize)
Definition: capture.c:90
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
Definition: connect.c:365
LONG NTSTATUS
Definition: precomp.h:26
PVOID ConnectionInfo
Definition: csrmsg.h:88
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
VOID NTAPI CsrCaptureMessageBuffer(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN PVOID MessageBuffer OPTIONAL, IN ULONG MessageLength, OUT PVOID *CapturedData)
Definition: capture.c:190
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI LdrGetProcedureAddress(IN PVOID BaseAddress, IN PANSI_STRING Name, IN ULONG Ordinal, OUT PVOID *ProcedureAddress)
Definition: ldrapi.c:823
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
void DPRINT(...)
Definition: polytest.cpp:61
union _CSR_API_MESSAGE::@3457::@3459::@3461 Data
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
Status
Definition: gdiplustypes.h:24
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG ConnectionInfoSize
Definition: csrmsg.h:89
BOOLEAN InsideCsrProcess
Definition: connect.c:25
NTSTATUS NTAPI CsrpConnectToServer(IN PWSTR ObjectDirectory)
Definition: connect.c:39
static const WCHAR L[]
Definition: oid.c:1250
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
#define NtCurrentPeb()
Definition: FLS.c:20
#define CSRSRV_SERVERDLL_INDEX
Definition: csrmsg.h:20
HANDLE CsrApiPort
Definition: connect.c:21
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define RtlImageNtHeader
Definition: compat.h:665
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
HANDLE CsrPortHeap
Definition: connect.c:23

Referenced by ConnectConsole(), and DllMain().

◆ CsrFreeCaptureBuffer()

◆ CsrGetProcessId()

HANDLE NTAPI CsrGetProcessId ( VOID  )

Definition at line 501 of file connect.c.

502 {
503  return CsrProcessId;
504 }
HANDLE CsrProcessId
Definition: connect.c:22

Referenced by ProcessIdToHandle().

◆ CsrIdentifyAlertableThread()

NTSTATUS NTAPI CsrIdentifyAlertableThread ( VOID  )

Definition at line 68 of file api.c.

69 {
71  CSR_API_MESSAGE ApiMessage;
72  PCSR_IDENTIFY_ALTERTABLE_THREAD IdentifyAlertableThread;
73 
74  /* Set up the data for CSR */
75  DbgBreakPoint();
76  IdentifyAlertableThread = &ApiMessage.Data.IdentifyAlertableThread;
77  IdentifyAlertableThread->Cid = NtCurrentTeb()->ClientId;
78 
79  /* Call it */
80  Status = CsrClientCallServer(&ApiMessage,
81  NULL,
84 
85  /* Return to caller */
86  return Status;
87 }
NTSTATUS NTAPI CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
Definition: connect.c:365
LONG NTSTATUS
Definition: precomp.h:26
void DbgBreakPoint()
Definition: mach.c:553
union _CSR_API_MESSAGE::@3457::@3459::@3461 Data
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
Status
Definition: gdiplustypes.h:24
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define CSRSRV_SERVERDLL_INDEX
Definition: csrmsg.h:20
#define NULL
Definition: types.h:112

◆ CsrNewThread()

NTSTATUS NTAPI CsrNewThread ( VOID  )

Definition at line 27 of file api.c.

28 {
29  /* Register the termination port to CSR's */
31 }
HANDLE CsrApiPort
Definition: connect.c:21
NTSTATUS NTAPI NtRegisterThreadTerminatePort(IN HANDLE PortHandle)
Definition: kill.c:1341

Referenced by __declspec(), and DllMain().

◆ CsrProbeForRead()

VOID NTAPI CsrProbeForRead ( IN PVOID  Address,
IN ULONG  Length,
IN ULONG  Alignment 
)

Definition at line 28 of file capture.c.

31 {
32  volatile UCHAR *Pointer;
33  UCHAR Data;
34 
35  /* Validate length */
36  if (Length == 0) return;
37 
38  /* Validate alignment */
39  if ((ULONG_PTR)Address & (Alignment - 1))
40  {
41  /* Raise exception if it doesn't match */
43  }
44 
45  /* Probe first byte */
46  Pointer = Address;
47  Data = *Pointer;
48 
49  /* Probe last byte */
50  Pointer = (PUCHAR)Address + Length - 1;
51  Data = *Pointer;
52  (void)Data;
53 }
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
uint32_t ULONG_PTR
Definition: typedefs.h:65
static WCHAR Address[46]
Definition: ping.c:68
unsigned char UCHAR
Definition: xmlstorage.h:181
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183

◆ CsrProbeForWrite()

VOID NTAPI CsrProbeForWrite ( IN PVOID  Address,
IN ULONG  Length,
IN ULONG  Alignment 
)

Definition at line 60 of file capture.c.

63 {
64  volatile UCHAR *Pointer;
65 
66  /* Validate length */
67  if (Length == 0) return;
68 
69  /* Validate alignment */
70  if ((ULONG_PTR)Address & (Alignment - 1))
71  {
72  /* Raise exception if it doesn't match */
74  }
75 
76  /* Probe first byte */
77  Pointer = Address;
78  *Pointer = *Pointer;
79 
80  /* Probe last byte */
81  Pointer = (PUCHAR)Address + Length - 1;
82  *Pointer = *Pointer;
83 }
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char * PUCHAR
Definition: retypes.h:3
uint32_t ULONG_PTR
Definition: typedefs.h:65
static WCHAR Address[46]
Definition: ping.c:68
unsigned char UCHAR
Definition: xmlstorage.h:181
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183

◆ CsrSetPriorityClass()

NTSTATUS NTAPI CsrSetPriorityClass ( IN HANDLE  Process,
IN OUT PULONG  PriorityClass 
)