ReactOS  0.4.14-dev-77-gd9e7c48
csr.h File Reference
#include <ndk/lpcfuncs.h>
#include <csr/csr.h>
#include <win/winmsg.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.

Macros

#define ST_RIT   (1<<0)
 
#define ST_DESKTOP_THREAD   (1<<1)
 
#define ST_GHOST_THREAD   (1<<2)
 

Functions

VOID InitCsrProcess (VOID)
 
VOID ResetCsrProcess (VOID)
 
NTSTATUS InitCsrApiPort (IN HANDLE CsrPortHandle)
 
VOID ResetCsrApiPort (VOID)
 
NTSTATUS NTAPI CsrClientCallServer (IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
 
DWORD UserSystemThreadProc (BOOL bRemoteProcess)
 
BOOL UserCreateSystemThread (DWORD Type)
 

Variables

PEPROCESS gpepCSRSS
 
PVOID CsrApiPort
 

Macro Definition Documentation

◆ ST_DESKTOP_THREAD

#define ST_DESKTOP_THREAD   (1<<1)

Definition at line 36 of file csr.h.

◆ ST_GHOST_THREAD

#define ST_GHOST_THREAD   (1<<2)

Definition at line 37 of file csr.h.

◆ ST_RIT

#define ST_RIT   (1<<0)

Definition at line 35 of file csr.h.

Function Documentation

◆ 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: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
#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: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
short CSHORT
Definition: umtypes.h:127

Referenced by BaseCheckForVDM(), BaseCheckVDM(), BasepNotifyCsrOfThread(), BaseUpdateVDMEntry(), CloseConsoleHandle(), ConsoleMenuControl(), CreateConsoleScreenBuffer(), CreateProcessInternalW(), CsrClientConnectToServer(), CsrIdentifyAlertableThread(), CsrSetPriorityClass(), DefineDosDeviceW(), DuplicateConsoleHandle(), EndTask(), ExitProcess(), ExitVDM(), ExitWindowsWorker(), FlushConsoleInputBuffer(), FreeConsole(), GenerateConsoleCtrlEvent(), GetConsoleCP(), GetConsoleCursorInfo(), GetConsoleDisplayMode(), GetConsoleFontInfo(), GetConsoleFontSize(), GetConsoleHandleInformation(), GetConsoleHardwareState(), GetConsoleMode(), GetConsoleOutputCP(), GetConsoleProcessList(), GetConsoleScreenBufferInfo(), GetConsoleSelectionInfo(), GetConsoleWindow(), GetCurrentConsoleFont(), GetLargestConsoleWindowSize(), GetNextVDMCommand(), GetNumberOfConsoleFonts(), GetNumberOfConsoleInputEvents(), GetNumberOfConsoleMouseButtons(), GetProcessShutdownParameters(), GetTempFileNameW(), GetThreadDesktop(), GetVDMCurrentDirectories(), IntAddConsoleAlias(), IntAllocConsole(), IntAttachConsole(), IntExpungeConsoleCommandHistory(), IntFillConsoleOutputCode(), IntGetConsoleAlias(), IntGetConsoleAliases(), IntGetConsoleAliasesLength(), IntGetConsoleAliasExes(), IntGetConsoleAliasExesLength(), IntGetConsoleCommandHistory(), IntGetConsoleCommandHistoryLength(), IntGetConsoleInput(), IntGetConsoleKeyboardLayoutName(), IntGetConsoleTitle(), IntReadConsole(), IntReadConsoleOutput(), IntReadConsoleOutputCode(), IntScrollConsoleScreenBuffer(), IntSetConsoleNumberOfCommands(), IntSetConsoleTitle(), IntWriteConsole(), IntWriteConsoleInput(), IntWriteConsoleOutput(), IntWriteConsoleOutputCode(), InvalidateConsoleDIBits(), Logon(), NotifySoundSentry(), OpenConsoleW(), RegisterConsoleVDM(), RegisterLogonProcess(), RegisterServicesProcess(), SetConsoleActiveScreenBuffer(), SetConsoleCommandHistoryMode(), SetConsoleCP(), SetConsoleCursor(), SetConsoleCursorInfo(), SetConsoleCursorPosition(), SetConsoleDisplayMode(), SetConsoleFont(), SetConsoleHandleInformation(), SetConsoleHardwareState(), SetConsoleIcon(), SetConsoleMenuClose(), SetConsoleMode(), SetConsoleOutputCP(), SetConsolePalette(), SetConsoleScreenBufferSize(), SetConsoleTextAttribute(), SetConsoleWindowInfo(), SetLastConsoleEventActive(), SetProcessShutdownParameters(), SetVDMCurrentDirectories(), ShowConsoleCursor(), UserCreateSystemThread(), and VerifyConsoleIoHandle().

◆ InitCsrApiPort()

NTSTATUS InitCsrApiPort ( IN HANDLE  CsrPortHandle)

Definition at line 38 of file csr.c.

39 {
41 
42  Status = ObReferenceObjectByHandle(CsrPortHandle,
43  0,
44  /* * */LpcPortObjectType, // or NULL,
45  UserMode,
46  &CsrApiPort,
47  NULL);
48  if (!NT_SUCCESS(Status))
49  {
50  CsrApiPort = NULL;
51  ERR("Failed to set CSR API Port.\n");
52  }
53 
54  return Status;
55 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
PVOID CsrApiPort
Definition: csr.c:16
smooth NULL
Definition: ftsmooth.c:416
POBJECT_TYPE LpcPortObjectType
Definition: port.c:17
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109

Referenced by NtUserSetInformationThread().

◆ InitCsrProcess()

VOID InitCsrProcess ( VOID  )

Definition at line 20 of file csr.c.

21 {
22  /* Save the EPROCESS of CSRSS */
24  // gpepCSRSS = CsrProcess;
26 }
PEPROCESS gpepCSRSS
Definition: csr.c:15
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by NtUserInitialize().

◆ ResetCsrApiPort()

VOID ResetCsrApiPort ( VOID  )

Definition at line 58 of file csr.c.

59 {
60  if (CsrApiPort)
62 
63  CsrApiPort = NULL;
64 }
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PVOID CsrApiPort
Definition: csr.c:16
smooth NULL
Definition: ftsmooth.c:416

Referenced by _Function_class_().

◆ ResetCsrProcess()

VOID ResetCsrProcess ( VOID  )

Definition at line 29 of file csr.c.

30 {
31  if (gpepCSRSS)
33 
34  gpepCSRSS = NULL;
35 }
PEPROCESS gpepCSRSS
Definition: csr.c:15
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
smooth NULL
Definition: ftsmooth.c:416

Referenced by _Function_class_().

◆ UserCreateSystemThread()

BOOL UserCreateSystemThread ( DWORD  Type)

Definition at line 247 of file csr.c.

248 {
249  USER_API_MESSAGE ApiMessage;
250  PUSER_CREATE_SYSTEM_THREAD pCreateThreadRequest = &ApiMessage.Data.CreateSystemThreadRequest;
251 
252  TRACE("UserCreateSystemThread: %d\n", Type);
253 
255 
257  {
258  ERR("System thread 0x%x already pending for creation\n", Type);
259  return TRUE;
260  }
261 
262  /* We can't pass a parameter to the new thread so mark what the new thread needs to do */
264 
265  /* Ask winsrv to create a new system thread. This new thread will enter win32k again calling UserSystemThreadProc */
266  pCreateThreadRequest->bRemote = FALSE;
268  NULL,
270  sizeof(USER_CREATE_SYSTEM_THREAD));
271  if (!NT_SUCCESS(ApiMessage.Status))
272  {
273  ERR("Csr call failed!\n");
274  return FALSE;
275  }
276 
277  return TRUE;
278 }
DWORD gdwPendingSystemThreads
Definition: csr.c:17
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
#define USERSRV_SERVERDLL_INDEX
Definition: winmsg.h:15
NTSTATUS Status
Definition: csrmsg.h:112
smooth NULL
Definition: ftsmooth.c:416
union _USER_API_MESSAGE::@3391 Data
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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: csr.c:74
#define ERR(fmt,...)
Definition: debug.h:109
BOOL FASTCALL UserIsEnteredExclusive(VOID)
Definition: ntuser.c:231
USER_CREATE_SYSTEM_THREAD CreateSystemThreadRequest
Definition: winmsg.h:106

Referenced by IntCreateWindowStation(), and IntMakeHungWindowGhosted().

◆ UserSystemThreadProc()

DWORD UserSystemThreadProc ( BOOL  bRemoteProcess)

Definition at line 207 of file csr.c.

208 {
209  DWORD Type;
210 
212  {
213  ERR("gdwPendingSystemThreads is 0!\n");
214  return 0;
215  }
216 
217  /* Decide which thread this will be */
219  Type = ST_RIT;
222  else
224 
225  ASSERT(Type);
226 
227  /* We will handle one of these threads right here so unmark it as pending */
229 
230  UserLeave();
231 
232  TRACE("UserSystemThreadProc: %d\n", Type);
233 
234  switch (Type)
235  {
236  case ST_RIT: RawInputThreadMain(); break;
237  case ST_DESKTOP_THREAD: DesktopThreadMain(); break;
238  case ST_GHOST_THREAD: UserGhostThreadEntry(); break;
239  default: ERR("Wrong type: %x\n", Type);
240  }
241 
242  UserEnterShared();
243 
244  return 0;
245 }
VOID FASTCALL UserEnterShared(VOID)
Definition: ntuser.c:241
DWORD gdwPendingSystemThreads
Definition: csr.c:17
Type
Definition: Type.h:6
VOID NTAPI RawInputThreadMain(VOID)
Definition: input.c:124
#define TRACE(s)
Definition: solgame.cpp:4
#define ST_GHOST_THREAD
Definition: csr.h:37
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI DesktopThreadMain(VOID)
Definition: desktop.c:1508
#define ST_RIT
Definition: csr.h:35
#define ERR(fmt,...)
Definition: debug.h:109
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
VOID NTAPI UserGhostThreadEntry(VOID)
Definition: ghost.c:27
#define ST_DESKTOP_THREAD
Definition: csr.h:36

Referenced by NtUserCallOneParam().

Variable Documentation

◆ CsrApiPort

PVOID CsrApiPort

Definition at line 21 of file connect.c.

◆ gpepCSRSS