#include "srv.h"
+#include <ndk/mmfuncs.h>
+
#define NDEBUG
#include <debug.h>
/* DATA ***********************************************************************/
+PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX];
+PVOID CsrSrvSharedSectionHeap = NULL;
+PVOID CsrSrvSharedSectionBase = NULL;
+PVOID *CsrSrvSharedStaticServerData = NULL;
+ULONG CsrSrvSharedSectionSize = 0;
+HANDLE CsrSrvSharedSection = NULL;
+
PCSR_API_ROUTINE CsrServerApiDispatchTable[CsrpMaxApiNumber] =
{
CsrSrvClientConnect,
TRUE
};
+/*
+ * On Windows Server 2003, CSR Servers contain
+ * the API Names Table only in Debug Builds.
+ */
+#ifdef CSR_DBG
PCHAR CsrServerApiNameTable[CsrpMaxApiNumber] =
{
"ClientConnect",
"IdentifyAlertableThread",
"SetPriorityClass"
};
-
-PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX];
-PVOID CsrSrvSharedSectionHeap = NULL;
-PVOID CsrSrvSharedSectionBase = NULL;
-PVOID *CsrSrvSharedStaticServerData = NULL;
-ULONG CsrSrvSharedSectionSize = 0;
-HANDLE CsrSrvSharedSection = NULL;
+#endif
/* PRIVATE FUNCTIONS **********************************************************/
CSR_SERVER_DLL_INIT(CsrServerDllInitialization)
{
/* Setup the DLL Object */
- LoadedServerDll->ApiBase = 0;
+ LoadedServerDll->ApiBase = CSRSRV_FIRST_API_NUMBER;
LoadedServerDll->HighestApiSupported = CsrpMaxApiNumber;
LoadedServerDll->DispatchTable = CsrServerApiDispatchTable;
LoadedServerDll->ValidTable = CsrServerApiServerValidTable;
+#ifdef CSR_DBG
LoadedServerDll->NameTable = CsrServerApiNameTable;
+#endif
LoadedServerDll->SizeOfProcessData = 0;
LoadedServerDll->ConnectCallback = NULL;
LoadedServerDll->DisconnectCallback = NULL;
/* Set up the Object */
ServerDll->Length = Size;
+ ServerDll->SizeOfProcessData = 0;
ServerDll->SharedSection = CsrSrvSharedSectionHeap; // Send to the server dll our shared heap pointer.
- ServerDll->Event = CsrInitializationEvent;
ServerDll->Name.Length = DllName.Length;
ServerDll->Name.MaximumLength = DllName.MaximumLength;
ServerDll->Name.Buffer = (PCHAR)(ServerDll + 1);
else
{
/* No handle, so we are loading ourselves */
+#ifdef CSR_DBG
+ RtlInitAnsiString(&EntryPointString, "CsrServerDllInitialization");
+#endif
ServerDllInitProcedure = CsrServerDllInitialization;
Status = STATUS_SUCCESS;
}
/* Check if we got the pointer, and call it */
if (NT_SUCCESS(Status))
{
- /* Get the result from the Server DLL */
- Status = ServerDllInitProcedure(ServerDll);
+ /* Call the Server DLL entrypoint */
+ _SEH2_TRY
+ {
+ Status = ServerDllInitProcedure(ServerDll);
+ }
+ _SEH2_EXCEPT(CsrUnhandledExceptionFilter(_SEH2_GetExceptionInformation()))
+ {
+ Status = _SEH2_GetExceptionCode();
+#ifdef CSR_DBG
+ DPRINT1("CSRSS: Exception 0x%lx while calling Server DLL entrypoint %Z!%Z()\n",
+ Status, &DllName, &EntryPointString);
+#endif
+ }
+ _SEH2_END;
+
if (NT_SUCCESS(Status))
{
/*
ULONG Size;
NTSTATUS Status;
LARGE_INTEGER SectionSize;
- ULONG ViewSize = 0;
+ SIZE_T ViewSize = 0;
PPEB Peb = NtCurrentPeb();
/* If there's no parameter, fail */
NTSTATUS
NTAPI
CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
- OUT PCSR_CONNECTION_INFO ConnectInfo)
+ OUT PCSR_API_CONNECTINFO ConnectInfo)
{
NTSTATUS Status;
- ULONG ViewSize = 0;
+ SIZE_T ViewSize = 0;
/* Check if we have a process */
if (CsrProcess)
/* Write the values in the Connection Info structure */
ConnectInfo->SharedSectionBase = CsrSrvSharedSectionBase;
ConnectInfo->SharedSectionHeap = CsrSrvSharedSectionHeap;
- ConnectInfo->SharedSectionData = CsrSrvSharedStaticServerData;
+ ConnectInfo->SharedStaticServerData = CsrSrvSharedStaticServerData;
/* Return success */
return STATUS_SUCCESS;
FALSE,
&OldValue);
}
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("CsrUnhandledExceptionFilter(): RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE) failed, Status = 0x%08lx\n", Status);
+ goto NoPrivilege;
+ }
/* Initialize our Name String */
RtlInitUnicodeString(&ErrorSource, L"Windows SubSystem");
ErrorParameters[3] = (ULONG_PTR)ExceptionInfo->ContextRecord;
/* Bugcheck */
- Status = NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED,
- 4,
- 1,
- ErrorParameters,
- OptionShutdownSystem,
- &Response);
+ NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED,
+ 4,
+ 1,
+ ErrorParameters,
+ OptionShutdownSystem,
+ &Response);
}
+NoPrivilege:
/* Just terminate us */
NtTerminateProcess(NtCurrentProcess(),
ExceptionInfo->ExceptionRecord->ExceptionCode);