ReactOS  0.4.15-dev-507-g90aff8d
server.c File Reference
#include "srv.h"
#include <ndk/mmfuncs.h>
#include <debug.h>
Include dependency graph for server.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

 CSR_SERVER_DLL_INIT (CsrServerDllInitialization)
 
NTSTATUS NTAPI CsrLoadServerDll (IN PCHAR DllString, IN PCHAR EntryPoint OPTIONAL, IN ULONG ServerId)
 
 CSR_API (CsrSrvClientConnect)
 
NTSTATUS NTAPI CsrSrvCreateSharedSection (IN PCHAR ParameterValue)
 
NTSTATUS NTAPI CsrSrvAttachSharedSection (IN PCSR_PROCESS CsrProcess OPTIONAL, OUT PCSR_API_CONNECTINFO ConnectInfo)
 
 CSR_API (CsrSrvIdentifyAlertableThread)
 
 CSR_API (CsrSrvSetPriorityClass)
 
 CSR_API (CsrSrvUnusedFunction)
 
VOID NTAPI CsrSetCallingSpooler (ULONG Reserved)
 
EXCEPTION_DISPOSITION NTAPI CsrUnhandledExceptionFilter (IN PEXCEPTION_POINTERS ExceptionInfo)
 

Variables

PCSR_SERVER_DLL CsrLoadedServerDll [CSR_SERVER_DLL_MAX]
 
PVOID CsrSrvSharedSectionHeap = NULL
 
PVOID CsrSrvSharedSectionBase = NULL
 
PVOIDCsrSrvSharedStaticServerData = NULL
 
ULONG CsrSrvSharedSectionSize = 0
 
HANDLE CsrSrvSharedSection = NULL
 
PCSR_API_ROUTINE CsrServerApiDispatchTable [CsrpMaxApiNumber]
 
BOOLEAN CsrServerApiServerValidTable [CsrpMaxApiNumber]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file server.c.

Function Documentation

◆ CSR_API() [1/4]

CSR_API ( CsrSrvClientConnect  )

Definition at line 283 of file server.c.

284 {
286  PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage->Data.CsrClientConnect;
287  PCSR_SERVER_DLL ServerDll;
289 
290  /* Set default reply */
291  *ReplyCode = CsrReplyImmediately;
292 
293  /* Validate the ServerID */
294  if (ClientConnect->ServerId >= CSR_SERVER_DLL_MAX)
295  {
296  return STATUS_TOO_MANY_NAMES;
297  }
298  else if (!CsrLoadedServerDll[ClientConnect->ServerId])
299  {
301  }
302 
303  /* Validate the Message Buffer */
304  if (!(CsrValidateMessageBuffer(ApiMessage,
305  &ClientConnect->ConnectionInfo,
306  ClientConnect->ConnectionInfoSize,
307  sizeof(BYTE))))
308  {
309  /* Fail due to buffer overflow or other invalid buffer */
311  }
312 
313  /* Load the Server DLL */
314  ServerDll = CsrLoadedServerDll[ClientConnect->ServerId];
315 
316  /* Check if it has a Connect Callback */
317  if (ServerDll->ConnectCallback)
318  {
319  /* Call the callback */
321  ClientConnect->ConnectionInfo,
322  &ClientConnect->ConnectionInfoSize);
323  }
324  else
325  {
326  /* Assume success */
328  }
329 
330  /* Return status */
331  return Status;
332 }
#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:1426
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: xxhash.c:193
Status
Definition: gdiplustypes.h:24
#define STATUS_TOO_MANY_NAMES
Definition: ntstatus.h:427
return STATUS_SUCCESS
Definition: btrfs.c:3014
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

◆ CSR_API() [2/4]

CSR_API ( CsrSrvIdentifyAlertableThread  )

Definition at line 521 of file server.c.

522 {
523  PCSR_THREAD CsrThread = CsrGetClientThread();
524 
525  /* Set the alertable flag */
526  CsrThread->Flags |= CsrThreadAlertable;
527 
528  /* Return success */
529  return STATUS_SUCCESS;
530 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CSR_API() [3/4]

CSR_API ( CsrSrvSetPriorityClass  )

Definition at line 549 of file server.c.

550 {
551  /* Deprecated */
552  return STATUS_SUCCESS;
553 }
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ CSR_API() [4/4]

CSR_API ( CsrSrvUnusedFunction  )

Definition at line 575 of file server.c.

576 {
577  /* Deprecated */
579 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

◆ CSR_SERVER_DLL_INIT()

CSR_SERVER_DLL_INIT ( CsrServerDllInitialization  )

Definition at line 77 of file server.c.

78 {
79  /* Setup the DLL Object */
80  LoadedServerDll->ApiBase = CSRSRV_FIRST_API_NUMBER;
81  LoadedServerDll->HighestApiSupported = CsrpMaxApiNumber;
82  LoadedServerDll->DispatchTable = CsrServerApiDispatchTable;
83  LoadedServerDll->ValidTable = CsrServerApiServerValidTable;
84 #ifdef CSR_DBG
85  LoadedServerDll->NameTable = CsrServerApiNameTable;
86 #endif
87  LoadedServerDll->SizeOfProcessData = 0;
88  LoadedServerDll->ConnectCallback = NULL;
89  LoadedServerDll->DisconnectCallback = NULL;
90 
91  /* All done */
92  return STATUS_SUCCESS;
93 }
PCSR_API_ROUTINE CsrServerApiDispatchTable[CsrpMaxApiNumber]
Definition: server.c:27
smooth NULL
Definition: ftsmooth.c:416
#define CSRSRV_FIRST_API_NUMBER
Definition: csrmsg.h:21
return STATUS_SUCCESS
Definition: btrfs.c:3014
BOOLEAN CsrServerApiServerValidTable[CsrpMaxApiNumber]
Definition: server.c:36

◆ 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 #ifdef CSR_DBG
209  RtlInitAnsiString(&EntryPointString, "CsrServerDllInitialization");
210 #endif
211  ServerDllInitProcedure = CsrServerDllInitialization;
213  }
214 
215  /* Check if we got the pointer, and call it */
216  if (NT_SUCCESS(Status))
217  {
218  /* Call the Server DLL entrypoint */
219  _SEH2_TRY
220  {
221  Status = ServerDllInitProcedure(ServerDll);
222  }
224  {
226 #ifdef CSR_DBG
227  DPRINT1("CSRSS: Exception 0x%lx while calling Server DLL entrypoint %Z!%Z()\n",
228  Status, &DllName, &EntryPointString);
229 #endif
230  }
231  _SEH2_END;
232 
233  if (NT_SUCCESS(Status))
234  {
235  /*
236  * Add this Server's Per-Process Data Size to the total that each
237  * process will need.
238  */
240 
241  /* Save the pointer in our list */
242  CsrLoadedServerDll[ServerDll->ServerId] = ServerDll;
243 
244  /* Does it use our generic heap? */
245  if (ServerDll->SharedSection != CsrSrvSharedSectionHeap)
246  {
247  /* No, save the pointer to its shared section in our list */
248  CsrSrvSharedStaticServerData[ServerDll->ServerId] = ServerDll->SharedSection;
249  }
250  }
251  }
252 
253  if (!NT_SUCCESS(Status))
254  {
255  /* Server Init failed, unload it */
256  if (hServerDll) LdrUnloadDll(hServerDll);
257 
258  /* Delete the Object */
259  RtlFreeHeap(CsrHeap, 0, ServerDll);
260  }
261 
262  /* Return to caller */
263  return Status;
264 }
#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
EXCEPTION_DISPOSITION NTAPI CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: server.c:622
ULONG CsrTotalPerProcessDataLength
Definition: init.c:35
#define CSR_SERVER_DLL_MAX
Definition: api.h:34
_SEH2_TRY
Definition: create.c:4226
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
uint32_t ULONG_PTR
Definition: typedefs.h:64
NTSTATUS NTAPI CsrServerDllInitialization(IN PCSR_SERVER_DLL LoadedServerDll)
PVOID * CsrSrvSharedStaticServerData
Definition: server.c:23
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
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:874
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:361
Status
Definition: gdiplustypes.h:24
struct _CSR_SERVER_DLL CSR_SERVER_DLL
NTSTATUS NTAPI LdrUnloadDll(IN PVOID BaseAddress)
Definition: ldrapi.c:1322
_SEH2_END
Definition: create.c:4400
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
#define DPRINT1
Definition: precomp.h:8
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
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
HANDLE CsrHeap
Definition: init.c:25
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#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:3014
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]
Definition: server.c:20

Referenced by CsrParseServerCommandLine().

◆ CsrSetCallingSpooler()

VOID NTAPI CsrSetCallingSpooler ( ULONG  Reserved)

Definition at line 599 of file server.c.

600 {
601  /* Deprecated */
602  return;
603 }

◆ CsrSrvAttachSharedSection()

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

Definition at line 472 of file server.c.

474 {
476  SIZE_T ViewSize = 0;
477 
478  /* Check if we have a process */
479  if (CsrProcess)
480  {
481  /* Map the section into this process */
483  CsrProcess->ProcessHandle,
485  0,
486  0,
487  NULL,
488  &ViewSize,
489  ViewUnmap,
492  if (!NT_SUCCESS(Status)) return Status;
493  }
494 
495  /* Write the values in the Connection Info structure */
496  ConnectInfo->SharedSectionBase = CsrSrvSharedSectionBase;
497  ConnectInfo->SharedSectionHeap = CsrSrvSharedSectionHeap;
498  ConnectInfo->SharedStaticServerData = CsrSrvSharedStaticServerData;
499 
500  /* Return success */
501  return STATUS_SUCCESS;
502 }
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:79
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:3014
#define SEC_NO_CHANGE
Definition: mmtypes.h:94

Referenced by CsrApiHandleConnectionRequest().

◆ CsrSrvCreateSharedSection()

NTSTATUS NTAPI CsrSrvCreateSharedSection ( IN PCHAR  ParameterValue)

Definition at line 351 of file server.c.

352 {
353  PCHAR SizeValue = ParameterValue;
354  ULONG Size;
356  LARGE_INTEGER SectionSize;
357  SIZE_T ViewSize = 0;
358  PPEB Peb = NtCurrentPeb();
359 
360  /* If there's no parameter, fail */
362 
363  /* Find the first comma, and null terminate */
364  while (*SizeValue)
365  {
366  if (*SizeValue == ',')
367  {
368  *SizeValue++ = ANSI_NULL;
369  break;
370  }
371  else
372  {
373  SizeValue++;
374  }
375  }
376 
377  /* Make sure it's valid */
378  if (!*SizeValue) return STATUS_INVALID_PARAMETER;
379 
380  /* Convert it to an integer */
381  Status = RtlCharToInteger(SizeValue, 0, &Size);
382  if (!NT_SUCCESS(Status)) return Status;
383 
384  /* Multiply by 1024 entries and round to page size */
386 
387  /* Create the Secion */
388  SectionSize.LowPart = CsrSrvSharedSectionSize;
389  SectionSize.HighPart = 0;
392  NULL,
393  &SectionSize,
396  NULL);
397  if (!NT_SUCCESS(Status)) return Status;
398 
399  /* Map the section */
403  0,
404  0,
405  NULL,
406  &ViewSize,
407  ViewUnmap,
408  MEM_TOP_DOWN,
410  if (!NT_SUCCESS(Status))
411  {
412  /* Fail */
414  return Status;
415  }
416 
417  /* FIXME: Write the value to registry */
418 
419  /* The Heap is the same place as the Base */
421 
422  /* Create the heap */
426  PAGE_SIZE,
427  0,
428  0)))
429  {
430  /* Failure, unmap section and return */
433  return STATUS_NO_MEMORY;
434  }
435 
436  /* Now allocate space from the heap for the Shared Data */
439  CSR_SERVER_DLL_MAX * sizeof(PVOID));
441 
442  /* Write the values to the PEB */
446 
447  /* Return */
448  return STATUS_SUCCESS;
449 }
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:105
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:361
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:79
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:3014

Referenced by CsrParseServerCommandLine().

◆ CsrUnhandledExceptionFilter()

EXCEPTION_DISPOSITION NTAPI CsrUnhandledExceptionFilter ( IN PEXCEPTION_POINTERS  ExceptionInfo)

Definition at line 622 of file server.c.

623 {
626  BOOLEAN OldValue;
628  UNICODE_STRING ErrorSource;
629  ULONG_PTR ErrorParameters[4];
630  ULONG Response;
631 
632  DPRINT1("CsrUnhandledExceptionFilter called\n");
633 
634  /* Check if a debugger is installed */
636  &DebuggerInfo,
637  sizeof(DebuggerInfo),
638  NULL);
639 
640  /* Check if this is Session 0, and the Debugger is Enabled */
641  if ((NtCurrentPeb()->SessionId != 0) && (NT_SUCCESS(Status)) &&
642  (DebuggerInfo.KernelDebuggerEnabled))
643  {
644  /* Call the Unhandled Exception Filter */
645  Result = RtlUnhandledExceptionFilter(ExceptionInfo);
647  {
648  /* We're going to raise an error. Get Shutdown Privilege first */
650  TRUE,
651  TRUE,
652  &OldValue);
653 
654  /* Use the Process token if that failed */
655  if (Status == STATUS_NO_TOKEN)
656  {
658  TRUE,
659  FALSE,
660  &OldValue);
661  }
662  if (!NT_SUCCESS(Status))
663  {
664  DPRINT1("CsrUnhandledExceptionFilter(): RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE) failed, Status = 0x%08lx\n", Status);
665  goto NoPrivilege;
666  }
667 
668  /* Initialize our Name String */
669  RtlInitUnicodeString(&ErrorSource, L"Windows SubSystem");
670 
671  /* Set the parameters */
672  ErrorParameters[0] = (ULONG_PTR)&ErrorSource;
673  ErrorParameters[1] = ExceptionInfo->ExceptionRecord->ExceptionCode;
674  ErrorParameters[2] = (ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress;
675  ErrorParameters[3] = (ULONG_PTR)ExceptionInfo->ContextRecord;
676 
677  /* Bugcheck */
679  4,
680  1,
681  ErrorParameters,
683  &Response);
684  }
685 
686 NoPrivilege:
687  /* Just terminate us */
689  ExceptionInfo->ExceptionRecord->ExceptionCode);
690  }
691 
692  return Result;
693 }
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
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
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_TOKEN
Definition: ntstatus.h:346
Definition: ncftp.h:89
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
LONG NTAPI RtlUnhandledExceptionFilter(IN struct _EXCEPTION_POINTERS *ExceptionInfo)
Definition: exception.c:306
#define NtCurrentPeb()
Definition: FLS.c:20
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
enum _EXCEPTION_DISPOSITION EXCEPTION_DISPOSITION
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct Response Response
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
#define ULONG_PTR
Definition: config.h:101
#define STATUS_SYSTEM_PROCESS_TERMINATED
Definition: ntstatus.h:656
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:87

Referenced by CsrApiRequestThread(), and CsrLoadServerDll().

Variable Documentation

◆ CsrLoadedServerDll

◆ CsrServerApiDispatchTable

PCSR_API_ROUTINE CsrServerApiDispatchTable[CsrpMaxApiNumber]
Initial value:
=
{
CsrSrvClientConnect,
CsrSrvUnusedFunction,
CsrSrvUnusedFunction,
CsrSrvIdentifyAlertableThread,
CsrSrvSetPriorityClass
}

Definition at line 27 of file server.c.

Referenced by CSR_SERVER_DLL_INIT().

◆ CsrServerApiServerValidTable

BOOLEAN CsrServerApiServerValidTable[CsrpMaxApiNumber]
Initial value:
=
{
}
#define TRUE
Definition: types.h:120

Definition at line 36 of file server.c.

Referenced by CSR_SERVER_DLL_INIT().

◆ CsrSrvSharedSection

HANDLE CsrSrvSharedSection = NULL

Definition at line 25 of file server.c.

Referenced by CsrSrvAttachSharedSection(), and CsrSrvCreateSharedSection().

◆ CsrSrvSharedSectionBase

PVOID CsrSrvSharedSectionBase = NULL

Definition at line 22 of file server.c.

Referenced by CsrSrvAttachSharedSection(), and CsrSrvCreateSharedSection().

◆ CsrSrvSharedSectionHeap

PVOID CsrSrvSharedSectionHeap = NULL

Definition at line 21 of file server.c.

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

◆ CsrSrvSharedSectionSize

ULONG CsrSrvSharedSectionSize = 0

Definition at line 24 of file server.c.

Referenced by CsrSrvCreateSharedSection().

◆ CsrSrvSharedStaticServerData

PVOID* CsrSrvSharedStaticServerData = NULL

Definition at line 23 of file server.c.

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