ReactOS  0.4.12-dev-918-g6c6e7b8
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 
95  /* Validate size */
96  if (BufferSize >= MAXLONG) return NULL;
97 
98  /* Add the size of the header and for each offset to the pointers */
99  BufferSize += FIELD_OFFSET(CSR_CAPTURE_BUFFER, PointerOffsetsArray) +
100  (ArgumentCount * sizeof(ULONG_PTR));
101 
102  /* Align it to a 4-byte boundary */
103  BufferSize = (BufferSize + 3) & ~3;
104 
105  /* Add the size of the alignment padding for each argument */
106  BufferSize += ArgumentCount * 3;
107 
108  /* Allocate memory from the port heap */
110  if (CaptureBuffer == NULL) return NULL;
111 
112  /* Initialize the header */
113  CaptureBuffer->Size = BufferSize;
114  CaptureBuffer->PointerCount = 0;
115 
116  /* Initialize all the offsets */
117  RtlZeroMemory(CaptureBuffer->PointerOffsetsArray,
118  ArgumentCount * sizeof(ULONG_PTR));
119 
120  /* Point to the start of the free buffer */
121  CaptureBuffer->BufferEnd = (PVOID)((ULONG_PTR)CaptureBuffer->PointerOffsetsArray +
122  ArgumentCount * sizeof(ULONG_PTR));
123 
124  /* Return the address of the buffer */
125  return CaptureBuffer;
126 }
#define MAXLONG
Definition: umtypes.h:116
HANDLE CsrPortHeap
Definition: connect.c:23
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
#define BufferSize
Definition: classpnp.h:419
ULONG PointerCount
Definition: csrmsg.h:96
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
ULONG_PTR PointerOffsetsArray[ANYSIZE_ARRAY]
Definition: csrmsg.h:98

Referenced by BaseCheckVDM(), CreateConsoleScreenBuffer(), CsrCaptureMessageMultiUnicodeStringsInPlace(), CsrClientConnectToServer(), DefineDosDeviceW(), 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 133 of file capture.c.

136 {
137  if (MessageLength == 0)
138  {
139  *CapturedData = NULL;
140  CapturedData = NULL;
141  }
142  else
143  {
144  /* Set the capture data at our current available buffer */
145  *CapturedData = CaptureBuffer->BufferEnd;
146 
147  /* Validate the size */
148  if (MessageLength >= MAXLONG) return 0;
149 
150  /* Align it to a 4-byte boundary */
151  MessageLength = (MessageLength + 3) & ~3;
152 
153  /* Move our available buffer beyond this space */
154  CaptureBuffer->BufferEnd = (PVOID)((ULONG_PTR)CaptureBuffer->BufferEnd + MessageLength);
155  }
156 
157  /* Write down this pointer in the array and increase the count */
158  CaptureBuffer->PointerOffsetsArray[CaptureBuffer->PointerCount++] = (ULONG_PTR)CapturedData;
159 
160  /* Return the aligned length */
161  return MessageLength;
162 }
#define MAXLONG
Definition: umtypes.h:116
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define ULONG_PTR
Definition: config.h:101

Referenced by CsrCaptureMessageBuffer(), CsrCaptureMessageString(), 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 169 of file capture.c.

173 {
174  /* Simply allocate a message pointer in the buffer */
175  CsrAllocateMessagePointer(CaptureBuffer, MessageLength, CapturedData);
176 
177  /* Check if there was any data */
178  if (!MessageBuffer || !MessageLength) return;
179 
180  /* Copy the data into the buffer */
181  RtlMoveMemory(*CapturedData, MessageBuffer, MessageLength);
182 }
ULONG NTAPI CsrAllocateMessagePointer(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN ULONG MessageLength, OUT PVOID *CapturedData)
Definition: capture.c:133
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by BaseCheckVDM(), CreateConsoleScreenBuffer(), CsrClientConnectToServer(), DefineDosDeviceW(), 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 271 of file capture.c.

274 {
275  ULONG Count;
276 
277  if (!CaptureBuffer) return STATUS_INVALID_PARAMETER;
278 
279  /* Allocate a new capture buffer if we don't have one already */
280  if (!*CaptureBuffer)
281  {
282  /* Compute the required size for the capture buffer */
283  ULONG Size = 0;
284 
285  Count = 0;
286  while (Count < StringsCount)
287  {
288  if (MessageStrings[Count])
289  Size += MessageStrings[Count]->MaximumLength;
290 
291  ++Count;
292  }
293 
294  /* Allocate the capture buffer */
295  *CaptureBuffer = CsrAllocateCaptureBuffer(StringsCount, Size);
296  if (!*CaptureBuffer) return STATUS_NO_MEMORY;
297  }
298 
299  /* Now capture each UNICODE string */
300  Count = 0;
301  while (Count < StringsCount)
302  {
303  if (MessageStrings[Count])
304  CsrCaptureMessageUnicodeStringInPlace(*CaptureBuffer, MessageStrings[Count]);
305 
306  ++Count;
307  }
308 
309  return STATUS_SUCCESS;
310 }
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer(IN ULONG ArgumentCount, IN ULONG BufferSize)
Definition: capture.c:90
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
static VOID CsrCaptureMessageUnicodeStringInPlace(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN PUNICODE_STRING String)
Definition: capture.c:247
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2725

◆ 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 200 of file capture.c.

205 {
206  ASSERT(CapturedString != NULL);
207 
208  /*
209  * If we don't have a string, initialize an empty one,
210  * otherwise capture the given string.
211  */
212  if (!String)
213  {
214  CapturedString->Length = 0;
215  CapturedString->MaximumLength = (USHORT)MaximumLength;
216 
217  /* Allocate a pointer for it */
218  CsrAllocateMessagePointer(CaptureBuffer,
220  (PVOID*)&CapturedString->Buffer);
221  }
222  else
223  {
224  /* Cut-off the string length if needed */
225  if (StringLength > MaximumLength)
226  StringLength = MaximumLength;
227 
228  CapturedString->Length = (USHORT)StringLength;
229 
230  /* Allocate a buffer and get its size */
231  CapturedString->MaximumLength =
232  (USHORT)CsrAllocateMessagePointer(CaptureBuffer,
234  (PVOID*)&CapturedString->Buffer);
235 
236  /* If the string has data, copy it into the buffer */
237  if (StringLength)
238  RtlMoveMemory(CapturedString->Buffer, String, StringLength);
239  }
240 
241  /* Null-terminate the string if we don't take up the whole space */
242  if (CapturedString->Length < CapturedString->MaximumLength)
243  CapturedString->Buffer[CapturedString->Length] = '\0';
244 }
ULONG NTAPI CsrAllocateMessagePointer(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN ULONG MessageLength, OUT PVOID *CapturedData)
Definition: capture.c:133
static WCHAR String[]
Definition: stringtable.c:55
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982
unsigned short USHORT
Definition: pedump.c:61

Referenced by CsrCaptureMessageUnicodeStringInPlace().

◆ CsrCaptureTimeout()

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

Definition at line 317 of file capture.c.

319 {
320  /* Validate the time */
321  if (Milliseconds == -1) return NULL;
322 
323  /* Convert to relative ticks */
324  Timeout->QuadPart = Milliseconds * -10000LL;
325  return Timeout;
326 }
#define LL
Definition: tui.h:72
smooth NULL
Definition: ftsmooth.c:416
static ULONG Timeout
Definition: ping.c:61

◆ 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 360 of file connect.c.

364 {
366  ULONG PointerCount;
367  PULONG_PTR OffsetPointer;
368 
369  /* Fill out the Port Message Header */
370  ApiMessage->Header.u2.ZeroInit = 0;
371  ApiMessage->Header.u1.s1.TotalLength = DataLength +
372  sizeof(CSR_API_MESSAGE) - sizeof(ApiMessage->Data); // FIELD_OFFSET(CSR_API_MESSAGE, Data) + DataLength;
373  ApiMessage->Header.u1.s1.DataLength = DataLength +
374  FIELD_OFFSET(CSR_API_MESSAGE, Data) - sizeof(ApiMessage->Header); // ApiMessage->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE);
375 
376  /* Fill out the CSR Header */
377  ApiMessage->ApiNumber = ApiNumber;
378  ApiMessage->CsrCaptureData = NULL;
379 
380  DPRINT("API: %lx, u1.s1.DataLength: %x, u1.s1.TotalLength: %x\n",
381  ApiNumber,
382  ApiMessage->Header.u1.s1.DataLength,
383  ApiMessage->Header.u1.s1.TotalLength);
384 
385  /* Check if we are already inside a CSR Server */
386  if (!InsideCsrProcess)
387  {
388  /* Check if we got a Capture Buffer */
389  if (CaptureBuffer)
390  {
391  /*
392  * We have to convert from our local (client) view
393  * to the remote (server) view.
394  */
395  ApiMessage->CsrCaptureData = (PCSR_CAPTURE_BUFFER)
396  ((ULONG_PTR)CaptureBuffer + CsrPortMemoryDelta);
397 
398  /* Lock the buffer. */
399  CaptureBuffer->BufferEnd = NULL;
400 
401  /*
402  * Each client pointer inside the CSR message is converted into
403  * a server pointer, and each pointer to these message pointers
404  * is converted into an offset.
405  */
406  PointerCount = CaptureBuffer->PointerCount;
407  OffsetPointer = CaptureBuffer->PointerOffsetsArray;
408  while (PointerCount--)
409  {
410  if (*OffsetPointer != 0)
411  {
412  *(PULONG_PTR)*OffsetPointer += CsrPortMemoryDelta;
413  *OffsetPointer -= (ULONG_PTR)ApiMessage;
414  }
415  ++OffsetPointer;
416  }
417  }
418 
419  /* Send the LPC Message */
421  &ApiMessage->Header,
422  &ApiMessage->Header);
423 
424  /* Check if we got a Capture Buffer */
425  if (CaptureBuffer)
426  {
427  /*
428  * We have to convert back from the remote (server) view
429  * to our local (client) view.
430  */
431  ApiMessage->CsrCaptureData = (PCSR_CAPTURE_BUFFER)
432  ((ULONG_PTR)ApiMessage->CsrCaptureData - CsrPortMemoryDelta);
433 
434  /*
435  * Convert back the offsets into pointers to CSR message
436  * pointers, and convert back these message server pointers
437  * into client pointers.
438  */
439  PointerCount = CaptureBuffer->PointerCount;
440  OffsetPointer = CaptureBuffer->PointerOffsetsArray;
441  while (PointerCount--)
442  {
443  if (*OffsetPointer != 0)
444  {
445  *OffsetPointer += (ULONG_PTR)ApiMessage;
446  *(PULONG_PTR)*OffsetPointer -= CsrPortMemoryDelta;
447  }
448  ++OffsetPointer;
449  }
450  }
451 
452  /* Check for success */
453  if (!NT_SUCCESS(Status))
454  {
455  /* We failed. Overwrite the return value with the failure. */
456  DPRINT1("LPC Failed: %lx\n", Status);
457  ApiMessage->Status = Status;
458  }
459  }
460  else
461  {
462  /* This is a server-to-server call. Save our CID and do a direct call. */
463  DPRINT("Next gen server-to-server call\n");
464 
465  /* We check this equality inside CsrValidateMessageBuffer */
466  ApiMessage->Header.ClientId = NtCurrentTeb()->ClientId;
467 
468  Status = CsrServerApiRoutine(&ApiMessage->Header,
469  &ApiMessage->Header);
470 
471  /* Check for success */
472  if (!NT_SUCCESS(Status))
473  {
474  /* We failed. Overwrite the return value with the failure. */
475  ApiMessage->Status = Status;
476  }
477  }
478 
479  /* Return the CSR Result */
480  DPRINT("Got back: 0x%lx\n", ApiMessage->Status);
481  return ApiMessage->Status;
482 }
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
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
struct _CSR_CAPTURE_BUFFER * PCSR_CAPTURE_BUFFER
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN InsideCsrProcess
Definition: connect.c:25
ULONG_PTR CsrPortMemoryDelta
Definition: connect.c:24
Status
Definition: gdiplustypes.h:24
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
HANDLE CsrApiPort
Definition: connect.c:21
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#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:63
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
struct _CSR_API_MESSAGE CSR_API_MESSAGE

◆ CsrClientConnectToServer()

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

Definition at line 192 of file connect.c.

197 {
199  PIMAGE_NT_HEADERS NtHeader;
200  UNICODE_STRING CsrSrvName;
201  HANDLE hCsrSrv;
202  ANSI_STRING CsrServerRoutineName;
203  CSR_API_MESSAGE ApiMessage;
204  PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage.Data.CsrClientConnect;
205  PCSR_CAPTURE_BUFFER CaptureBuffer;
206 
207  DPRINT("CsrClientConnectToServer: %lx %p\n", ServerId, ConnectionInfo);
208 
209  /* Validate the Connection Info */
210  if (ConnectionInfo && (!ConnectionInfoSize || !*ConnectionInfoSize))
211  {
212  DPRINT1("Connection info given, but no length\n");
214  }
215 
216  /* Check if we're inside a CSR Process */
217  if (InsideCsrProcess)
218  {
219  /* Tell the client that we're already inside CSR */
220  if (ServerToServerCall) *ServerToServerCall = TRUE;
221  return STATUS_SUCCESS;
222  }
223 
224  /*
225  * We might be in a CSR Process but not know it, if this is the first call.
226  * So let's find out.
227  */
228  if (!(NtHeader = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress)))
229  {
230  /* The image isn't valid */
231  DPRINT1("Invalid image\n");
233  }
235 
236  /* Now we can check if we are inside or not */
237  if (InsideCsrProcess)
238  {
239  /* We're inside, so let's find csrsrv */
240  DPRINT("Next-GEN CSRSS support\n");
241  RtlInitUnicodeString(&CsrSrvName, L"csrsrv");
243  NULL,
244  &CsrSrvName,
245  &hCsrSrv);
246 
247  /* Now get the Server to Server routine */
248  RtlInitAnsiString(&CsrServerRoutineName, "CsrCallServerFromServer");
249  Status = LdrGetProcedureAddress(hCsrSrv,
250  &CsrServerRoutineName,
251  0L,
253 
254  /* Use the local heap as port heap */
255  CsrPortHeap = RtlGetProcessHeap();
256 
257  /* Tell the caller we're inside the server */
258  if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
259  return STATUS_SUCCESS;
260  }
261 
262  /* Now check if connection info is given */
263  if (ConnectionInfo)
264  {
265  /* Well, we're definitely in a client now */
267 
268  /* Do we have a connection to CSR yet? */
269  if (!CsrApiPort)
270  {
271  /* No, set it up now */
272  Status = CsrpConnectToServer(ObjectDirectory);
273  if (!NT_SUCCESS(Status))
274  {
275  /* Failed */
276  DPRINT1("Failure to connect to CSR\n");
277  return Status;
278  }
279  }
280 
281  /* Setup the connect message header */
282  ClientConnect->ServerId = ServerId;
283  ClientConnect->ConnectionInfoSize = *ConnectionInfoSize;
284 
285  /* Setup a buffer for the connection info */
286  CaptureBuffer = CsrAllocateCaptureBuffer(1, ClientConnect->ConnectionInfoSize);
287  if (CaptureBuffer == NULL)
288  {
290  }
291 
292  /* Capture the connection info data */
293  CsrCaptureMessageBuffer(CaptureBuffer,
294  ConnectionInfo,
295  ClientConnect->ConnectionInfoSize,
296  &ClientConnect->ConnectionInfo);
297 
298  /* Return the allocated length */
299  *ConnectionInfoSize = ClientConnect->ConnectionInfoSize;
300 
301  /* Call CSR */
302  Status = CsrClientCallServer(&ApiMessage,
303  CaptureBuffer,
305  sizeof(CSR_CLIENT_CONNECT));
306 
307  /* Copy the updated connection info data back into the user buffer */
308  RtlMoveMemory(ConnectionInfo,
309  ClientConnect->ConnectionInfo,
310  *ConnectionInfoSize);
311 
312  /* Free the capture buffer */
313  CsrFreeCaptureBuffer(CaptureBuffer);
314  }
315  else
316  {
317  /* No connection info, just return */
319  }
320 
321  /* Let the caller know if this was server to server */
322  DPRINT("Status was: 0x%lx. Are we in server: 0x%x\n", Status, InsideCsrProcess);
323  if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
324 
325  return Status;
326 }
VOID NTAPI CsrFreeCaptureBuffer(IN PCSR_CAPTURE_BUFFER CaptureBuffer)
Definition: capture.c:189
#define TRUE
Definition: types.h:120
#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 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:360
LONG NTSTATUS
Definition: precomp.h:26
PVOID ConnectionInfo
Definition: csrmsg.h:88
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
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:169
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
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
void DPRINT(...)
Definition: polytest.cpp:61
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
union _CSR_API_MESSAGE::@3317::@3319::@3321 Data
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#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
Status
Definition: gdiplustypes.h:24
#define NtCurrentPeb()
Definition: FLS.c:19
#define CSRSRV_SERVERDLL_INDEX
Definition: csrmsg.h:20
HANDLE CsrApiPort
Definition: connect.c:21
#define DPRINT1
Definition: precomp.h:8
#define RtlImageNtHeader
Definition: compat.h:457
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:2725
HANDLE CsrPortHeap
Definition: connect.c:23

Referenced by ConnectConsole(), and DllMain().

◆ CsrFreeCaptureBuffer()

◆ CsrGetProcessId()

HANDLE NTAPI CsrGetProcessId ( VOID  )

Definition at line 489 of file connect.c.

490 {
491  return CsrProcessId;
492 }
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:360
LONG NTSTATUS
Definition: precomp.h:26
void DbgBreakPoint()
Definition: mach.c:558
smooth NULL
Definition: ftsmooth.c:416
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
union _CSR_API_MESSAGE::@3317::@3319::@3321 Data
Status
Definition: gdiplustypes.h:24
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define CSRSRV_SERVERDLL_INDEX
Definition: csrmsg.h:20

◆ 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)
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
uint32_t ULONG_PTR
Definition: typedefs.h:63
static WCHAR Address[46]
Definition: ping.c:68
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char UCHAR
Definition: xmlstorage.h:181
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:171

◆ 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)
unsigned char * PUCHAR
Definition: retypes.h:3
uint32_t ULONG_PTR
Definition: typedefs.h:63
static WCHAR Address[46]
Definition: ping.c:68
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char UCHAR
Definition: xmlstorage.h:181
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:171

◆ CsrSetPriorityClass()

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