During my investigations for making working Win2k3 csrsrv.dll (or other CSR servers) into ROS (to compare our behaviour with our own csrsrv.dll and Win2k3 one), I hit a problem: if I test a checked-build version of csrsrv (or other CSR servers), everything was fine when they were loaded, but if I use a release-build version (i.e. without any debug information), I systematically hit a memory access violation which was traced back to the moment when a CSR server's CsrInitialization entry point was called.
So I did the experiment, where I used our (debug-build) csrsrv with a free-build win2k3 CSR server dll (it was winsrv.dll, and I retested with basesrv.dll after). I hit the access violation. But if I took a debug-build version of winsrv.dll, everything was OK.
I then added in our csrsrv' server.c file the following line (around line 212 of the current file version):
DPRINT1("%s ; ServerDll->ValidTable = 0x%p ; ServerDll->NameTable = 0x%p ; ServerDll->SizeOfProcessData = %d ; ServerDll->ConnectCallback = 0x%p\n", DllString, ServerDll->ValidTable, ServerDll->NameTable, ServerDll->SizeOfProcessData, ServerDll->ConnectCallback);
and I saw that, when using a debug-build win2k3 CSR server, everything was fine (in particular the ServerDll->SizeOfProcessData member contained a reasonable value, e.g. a size of 88 bytes), whereas if I used a free-build version, I got an off-by-one problem, with the ServerDll->ValidTable pointer valid but the ServerDll->NameTable member being equal to 88 (i.e. invalid pointer) and the ServerDll->SizeOfProcessData member being equal to a very large value, which looked like a pointer value.
After more investigations, I saw that in debug-build CSR servers the list of API names were stored, whereas it was not the case in free-build versions. Therefore I concluded that the API names table was included *ONLY* in debug builds and not in release builds.

Hence, to be able to test in ROS either debug-builds or release-builds versions of Windows CSR servers in ROS (and vice-versa), I introduced a #define called CSR_DBG, which is defined only if the DBG macro is != 0, and which is not defined otherwise. When the CSR_DBG flag is defined, API names tables are added in CSR servers and otherwise, they are not.

Therefore, we are now able to test debug-build Windows CSR servers in ROS (the default possibility) or free-build versions of these CSR servers (but first, we have to build the other ones without the CSR_DBG flag, to avoid the off-by-one problem described above).

svn path=/trunk/; revision=60560
This commit is contained in:
Hermès Bélusca-Maïto 2013-10-06 13:33:17 +00:00
parent c6ac881351
commit 46e2b227f2
8 changed files with 73 additions and 12 deletions

View file

@ -10,6 +10,14 @@
#ifndef _CSRSRV_H #ifndef _CSRSRV_H
#define _CSRSRV_H #define _CSRSRV_H
/*
* The CSR_DBG macro is defined for building CSR Servers
* with extended debugging information.
*/
#if DBG
#define CSR_DBG
#endif
#include "csrmsg.h" #include "csrmsg.h"
@ -215,7 +223,14 @@ typedef struct _CSR_SERVER_DLL
ULONG HighestApiSupported; ULONG HighestApiSupported;
PCSR_API_ROUTINE *DispatchTable; PCSR_API_ROUTINE *DispatchTable;
PBOOLEAN ValidTable; // Table of booleans which describe whether or not a server function call is valid when it is called via CsrCallServerFromServer. PBOOLEAN ValidTable; // Table of booleans which describe whether or not a server function call is valid when it is called via CsrCallServerFromServer.
/*
* On Windows Server 2003, CSR Servers contain
* the API Names Table only in Debug Builds.
*/
#ifdef CSR_DBG
PCHAR *NameTable; PCHAR *NameTable;
#endif
ULONG SizeOfProcessData; ULONG SizeOfProcessData;
PCSR_CONNECT_CALLBACK ConnectCallback; PCSR_CONNECT_CALLBACK ConnectCallback;
PCSR_DISCONNECT_CALLBACK DisconnectCallback; PCSR_DISCONNECT_CALLBACK DisconnectCallback;
@ -226,7 +241,11 @@ typedef struct _CSR_SERVER_DLL
ULONG Unknown2[3]; ULONG Unknown2[3];
} CSR_SERVER_DLL, *PCSR_SERVER_DLL; } CSR_SERVER_DLL, *PCSR_SERVER_DLL;
#ifndef _WIN64 #ifndef _WIN64
C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL, SharedSection) == 0x3C); #ifdef CSR_DBG
C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL, SharedSection) == 0x3C);
#else
C_ASSERT(FIELD_OFFSET(CSR_SERVER_DLL, SharedSection) == 0x38);
#endif
#endif #endif
typedef typedef

View file

@ -97,6 +97,11 @@ BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMB
TRUE, // BaseSrvNlsGetUserInfo TRUE, // BaseSrvNlsGetUserInfo
}; };
/*
* On Windows Server 2003, CSR Servers contain
* the API Names Table only in Debug Builds.
*/
#ifdef CSR_DBG
PCHAR BaseServerApiNameTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER] = PCHAR BaseServerApiNameTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER] =
{ {
"BaseCreateProcess", "BaseCreateProcess",
@ -131,6 +136,7 @@ PCHAR BaseServerApiNameTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER] =
"BaseRegisterThread", "BaseRegisterThread",
"BaseNlsGetUserInfo", "BaseNlsGetUserInfo",
}; };
#endif
/* FUNCTIONS ******************************************************************/ /* FUNCTIONS ******************************************************************/
@ -567,7 +573,9 @@ CSR_SERVER_DLL_INIT(ServerDllInitialization)
LoadedServerDll->HighestApiSupported = BasepMaxApiNumber; LoadedServerDll->HighestApiSupported = BasepMaxApiNumber;
LoadedServerDll->DispatchTable = BaseServerApiDispatchTable; LoadedServerDll->DispatchTable = BaseServerApiDispatchTable;
LoadedServerDll->ValidTable = BaseServerApiServerValidTable; LoadedServerDll->ValidTable = BaseServerApiServerValidTable;
#ifdef CSR_DBG
LoadedServerDll->NameTable = BaseServerApiNameTable; LoadedServerDll->NameTable = BaseServerApiNameTable;
#endif
LoadedServerDll->SizeOfProcessData = 0; LoadedServerDll->SizeOfProcessData = 0;
LoadedServerDll->ConnectCallback = NULL; LoadedServerDll->ConnectCallback = NULL;
LoadedServerDll->DisconnectCallback = NULL; LoadedServerDll->DisconnectCallback = NULL;

View file

@ -77,23 +77,27 @@ CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg,
{ {
/* We are beyond the Maximum API ID, or it doesn't exist */ /* We are beyond the Maximum API ID, or it doesn't exist */
DPRINT1("API: %d\n", ApiId); DPRINT1("API: %d\n", ApiId);
#ifdef CSR_DBG
DPRINT1("CSRSS: %lx (%s) is invalid ApiTableIndex for %Z or is an " DPRINT1("CSRSS: %lx (%s) is invalid ApiTableIndex for %Z or is an "
"invalid API to call from the server.\n", "invalid API to call from the server.\n",
ApiId, ApiId,
((ServerDll->NameTable) && (ServerDll->NameTable[ApiId])) ? ((ServerDll->NameTable) && (ServerDll->NameTable[ApiId])) ?
ServerDll->NameTable[ApiId] : "*** UNKNOWN ***", ServerDll->NameTable[ApiId] : "*** UNKNOWN ***",
&ServerDll->Name); &ServerDll->Name);
#endif
// DbgBreakPoint(); // DbgBreakPoint();
ReplyMsg->Status = STATUS_ILLEGAL_FUNCTION; ReplyMsg->Status = STATUS_ILLEGAL_FUNCTION;
return STATUS_ILLEGAL_FUNCTION; return STATUS_ILLEGAL_FUNCTION;
} }
} }
#ifdef CSR_DBG
if (CsrDebug & 2) if (CsrDebug & 2)
{ {
DPRINT1("CSRSS: %s Api Request received from server process\n", DPRINT1("CSRSS: %s Api Request received from server process\n",
ServerDll->NameTable[ApiId]); ServerDll->NameTable[ApiId]);
} }
#endif
/* Validation complete, start SEH */ /* Validation complete, start SEH */
_SEH2_TRY _SEH2_TRY
@ -577,6 +581,7 @@ CsrApiRequestThread(IN PVOID Parameter)
continue; continue;
} }
#ifdef CSR_DBG
if (CsrDebug & 2) if (CsrDebug & 2)
{ {
DPRINT1("[%02x] CSRSS: [%02x,%02x] - %s Api called from %08x\n", DPRINT1("[%02x] CSRSS: [%02x,%02x] - %s Api called from %08x\n",
@ -586,6 +591,7 @@ CsrApiRequestThread(IN PVOID Parameter)
ServerDll->NameTable[ApiId], ServerDll->NameTable[ApiId],
NULL); NULL);
} }
#endif
/* Assume success */ /* Assume success */
ReceiveMsg.Status = STATUS_SUCCESS; ReceiveMsg.Status = STATUS_SUCCESS;
@ -781,6 +787,7 @@ CsrApiRequestThread(IN PVOID Parameter)
continue; continue;
} }
#ifdef CSR_DBG
if (CsrDebug & 2) if (CsrDebug & 2)
{ {
DPRINT1("[%02x] CSRSS: [%02x,%02x] - %s Api called from %08x, Process %08x - %08x\n", DPRINT1("[%02x] CSRSS: [%02x,%02x] - %s Api called from %08x, Process %08x - %08x\n",
@ -792,6 +799,7 @@ CsrApiRequestThread(IN PVOID Parameter)
CsrThread->Process, CsrThread->Process,
CsrProcess); CsrProcess);
} }
#endif
/* Assume success */ /* Assume success */
ReplyMsg = &ReceiveMsg; ReplyMsg = &ReceiveMsg;

View file

@ -41,6 +41,9 @@ extern RTL_CRITICAL_SECTION CsrProcessLock, CsrWaitListsLock;
#define CSR_SERVER_DLL_MAX 4 #define CSR_SERVER_DLL_MAX 4
// Debug Flag
extern ULONG CsrDebug;
extern HANDLE hBootstrapOk; extern HANDLE hBootstrapOk;
extern HANDLE CsrApiPort; extern HANDLE CsrApiPort;
extern HANDLE CsrSmApiPort; extern HANDLE CsrSmApiPort;
@ -49,7 +52,6 @@ extern HANDLE CsrSbApiPort;
extern LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]; extern LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS];
extern PCSR_PROCESS CsrRootProcess; extern PCSR_PROCESS CsrRootProcess;
extern UNICODE_STRING CsrDirectoryName; extern UNICODE_STRING CsrDirectoryName;
extern ULONG CsrDebug;
extern ULONG CsrTotalPerProcessDataLength; extern ULONG CsrTotalPerProcessDataLength;
extern SYSTEM_BASIC_INFORMATION CsrNtSysInfo; extern SYSTEM_BASIC_INFORMATION CsrNtSysInfo;
extern HANDLE CsrHeap; extern HANDLE CsrHeap;

View file

@ -16,6 +16,9 @@
/* DATA ***********************************************************************/ /* DATA ***********************************************************************/
// Debug Flag
ULONG CsrDebug = 0; // 0xFFFFFFFF;
HANDLE CsrHeap = NULL; HANDLE CsrHeap = NULL;
HANDLE CsrObjectDirectory = NULL; HANDLE CsrObjectDirectory = NULL;
UNICODE_STRING CsrDirectoryName; UNICODE_STRING CsrDirectoryName;
@ -25,7 +28,6 @@ PCSR_THREAD CsrSbApiRequestThreadPtr;
HANDLE CsrSmApiPort = NULL; HANDLE CsrSmApiPort = NULL;
HANDLE hSbApiPort = NULL; HANDLE hSbApiPort = NULL;
HANDLE CsrApiPort = NULL; HANDLE CsrApiPort = NULL;
ULONG CsrDebug = 0; // 0xFFFFFFFF;
ULONG CsrMaxApiRequestThreads; ULONG CsrMaxApiRequestThreads;
ULONG CsrTotalPerProcessDataLength; ULONG CsrTotalPerProcessDataLength;
ULONG SessionId; ULONG SessionId;

View file

@ -15,6 +15,13 @@
/* DATA ***********************************************************************/ /* 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] = PCSR_API_ROUTINE CsrServerApiDispatchTable[CsrpMaxApiNumber] =
{ {
CsrSrvClientConnect, CsrSrvClientConnect,
@ -33,6 +40,11 @@ BOOLEAN CsrServerApiServerValidTable[CsrpMaxApiNumber] =
TRUE TRUE
}; };
/*
* On Windows Server 2003, CSR Servers contain
* the API Names Table only in Debug Builds.
*/
#ifdef CSR_DBG
PCHAR CsrServerApiNameTable[CsrpMaxApiNumber] = PCHAR CsrServerApiNameTable[CsrpMaxApiNumber] =
{ {
"ClientConnect", "ClientConnect",
@ -41,13 +53,7 @@ PCHAR CsrServerApiNameTable[CsrpMaxApiNumber] =
"IdentifyAlertableThread", "IdentifyAlertableThread",
"SetPriorityClass" "SetPriorityClass"
}; };
#endif
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX];
PVOID CsrSrvSharedSectionHeap = NULL;
PVOID CsrSrvSharedSectionBase = NULL;
PVOID *CsrSrvSharedStaticServerData = NULL;
ULONG CsrSrvSharedSectionSize = 0;
HANDLE CsrSrvSharedSection = NULL;
/* PRIVATE FUNCTIONS **********************************************************/ /* PRIVATE FUNCTIONS **********************************************************/
@ -73,7 +79,9 @@ CSR_SERVER_DLL_INIT(CsrServerDllInitialization)
LoadedServerDll->HighestApiSupported = CsrpMaxApiNumber; LoadedServerDll->HighestApiSupported = CsrpMaxApiNumber;
LoadedServerDll->DispatchTable = CsrServerApiDispatchTable; LoadedServerDll->DispatchTable = CsrServerApiDispatchTable;
LoadedServerDll->ValidTable = CsrServerApiServerValidTable; LoadedServerDll->ValidTable = CsrServerApiServerValidTable;
#ifdef CSR_DBG
LoadedServerDll->NameTable = CsrServerApiNameTable; LoadedServerDll->NameTable = CsrServerApiNameTable;
#endif
LoadedServerDll->SizeOfProcessData = 0; LoadedServerDll->SizeOfProcessData = 0;
LoadedServerDll->ConnectCallback = NULL; LoadedServerDll->ConnectCallback = NULL;
LoadedServerDll->DisconnectCallback = NULL; LoadedServerDll->DisconnectCallback = NULL;

View file

@ -218,6 +218,11 @@ BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber - CONSRV_FIRST_API
// FALSE, // SrvConsoleClientConnect, // FALSE, // SrvConsoleClientConnect,
}; };
/*
* On Windows Server 2003, CSR Servers contain
* the API Names Table only in Debug Builds.
*/
#ifdef CSR_DBG
PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER] = PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER] =
{ {
"OpenConsole", "OpenConsole",
@ -313,7 +318,7 @@ PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER]
// "SetScreenBufferInfo", // "SetScreenBufferInfo",
// "ConsoleClientConnect", // "ConsoleClientConnect",
}; };
#endif
/* FUNCTIONS ******************************************************************/ /* FUNCTIONS ******************************************************************/
@ -532,7 +537,9 @@ CSR_SERVER_DLL_INIT(ConServerDllInitialization)
LoadedServerDll->HighestApiSupported = ConsolepMaxApiNumber; LoadedServerDll->HighestApiSupported = ConsolepMaxApiNumber;
LoadedServerDll->DispatchTable = ConsoleServerApiDispatchTable; LoadedServerDll->DispatchTable = ConsoleServerApiDispatchTable;
LoadedServerDll->ValidTable = ConsoleServerApiServerValidTable; LoadedServerDll->ValidTable = ConsoleServerApiServerValidTable;
#ifdef CSR_DBG
LoadedServerDll->NameTable = ConsoleServerApiNameTable; LoadedServerDll->NameTable = ConsoleServerApiNameTable;
#endif
LoadedServerDll->SizeOfProcessData = sizeof(CONSOLE_PROCESS_DATA); LoadedServerDll->SizeOfProcessData = sizeof(CONSOLE_PROCESS_DATA);
LoadedServerDll->ConnectCallback = ConSrvConnect; LoadedServerDll->ConnectCallback = ConSrvConnect;
LoadedServerDll->DisconnectCallback = ConSrvDisconnect; LoadedServerDll->DisconnectCallback = ConSrvDisconnect;

View file

@ -57,6 +57,11 @@ BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMB
// FALSE, // SrvGetSetShutdownBlockReason // FALSE, // SrvGetSetShutdownBlockReason
}; };
/*
* On Windows Server 2003, CSR Servers contain
* the API Names Table only in Debug Builds.
*/
#ifdef CSR_DBG
PCHAR UserServerApiNameTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] = PCHAR UserServerApiNameTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
{ {
"SrvExitWindowsEx", "SrvExitWindowsEx",
@ -73,7 +78,7 @@ PCHAR UserServerApiNameTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
// "SrvConsoleHandleOperation", // "SrvConsoleHandleOperation",
// "SrvGetSetShutdownBlockReason", // "SrvGetSetShutdownBlockReason",
}; };
#endif
/* FUNCTIONS ******************************************************************/ /* FUNCTIONS ******************************************************************/
@ -291,7 +296,9 @@ CSR_SERVER_DLL_INIT(UserServerDllInitialization)
LoadedServerDll->HighestApiSupported = UserpMaxApiNumber; LoadedServerDll->HighestApiSupported = UserpMaxApiNumber;
LoadedServerDll->DispatchTable = UserServerApiDispatchTable; LoadedServerDll->DispatchTable = UserServerApiDispatchTable;
LoadedServerDll->ValidTable = UserServerApiServerValidTable; LoadedServerDll->ValidTable = UserServerApiServerValidTable;
#ifdef CSR_DBG
LoadedServerDll->NameTable = UserServerApiNameTable; LoadedServerDll->NameTable = UserServerApiNameTable;
#endif
LoadedServerDll->SizeOfProcessData = 0; LoadedServerDll->SizeOfProcessData = 0;
LoadedServerDll->ConnectCallback = NULL; LoadedServerDll->ConnectCallback = NULL;
LoadedServerDll->DisconnectCallback = NULL; LoadedServerDll->DisconnectCallback = NULL;