[CSRSRV]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 10 Mar 2013 19:37:33 +0000 (19:37 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 10 Mar 2013 19:37:33 +0000 (19:37 +0000)
Clarify few parts of code; remove unneeded comments and DPRINTs; start documentation of the CsrCreateProcess routine.

[BASESRV-CONSRV-WINSRV]
Correct the sizes of the API tables.

[SM]
Correct the API names.

svn path=/branches/ros-csrss/; revision=58464

17 files changed:
base/system/smss/smloop.c
include/reactos/subsys/csr/csr.h
include/reactos/subsys/csr/csrmsg.h
include/reactos/subsys/csr/csrsrv.h
include/reactos/subsys/sm/smmsg.h
lib/smlib/smclient.c
subsystems/win/basesrv/init.c
subsystems/win32/csrsrv/api.c
subsystems/win32/csrsrv/api.h
subsystems/win32/csrsrv/init.c
subsystems/win32/csrsrv/procsup.c
subsystems/win32/csrsrv/server.c
subsystems/win32/csrsrv/session.c
subsystems/win32/csrsrv/thredsup.c
win32ss/user/consrv/handle.c
win32ss/user/consrv/init.c
win32ss/user/winsrv/init.c

index 35fbb9c..06aa46c 100644 (file)
@@ -166,7 +166,7 @@ SmpStopCsr(IN PSM_API_MSG SmApiMsg,
     return STATUS_NOT_IMPLEMENTED;
 }
 
     return STATUS_NOT_IMPLEMENTED;
 }
 
-PSM_API_HANDLER SmpApiDispatch[SmMaxApiNumber] =
+PSM_API_HANDLER SmpApiDispatch[SmpMaxApiNumber - SmpCreateForeignSessionApi] =
 {
     SmpCreateForeignSession,
     SmpSessionComplete,
 {
     SmpCreateForeignSession,
     SmpSessionComplete,
@@ -401,13 +401,13 @@ SmpApiLoop(IN PVOID Parameter)
                 RequestMsg.ReturnValue = STATUS_PENDING;
 
                 /* Check if the API is valid */
                 RequestMsg.ReturnValue = STATUS_PENDING;
 
                 /* Check if the API is valid */
-                if (RequestMsg.ApiNumber >= SmMaxApiNumber)
+                if (RequestMsg.ApiNumber >= SmpMaxApiNumber)
                 {
                     /* It isn't, fail */
                     DPRINT1("Invalid API: %lx\n", RequestMsg.ApiNumber);
                     Status = STATUS_NOT_IMPLEMENTED;
                 }
                 {
                     /* It isn't, fail */
                     DPRINT1("Invalid API: %lx\n", RequestMsg.ApiNumber);
                     Status = STATUS_NOT_IMPLEMENTED;
                 }
-                else if ((RequestMsg.ApiNumber <= SmTerminateForeignSessionApi) &&
+                else if ((RequestMsg.ApiNumber <= SmpTerminateForeignSessionApi) &&
                          !(ClientContext->Subsystem))
                 {
                     /* It's valid, but doesn't have a subsystem with it */
                          !(ClientContext->Subsystem))
                 {
                     /* It's valid, but doesn't have a subsystem with it */
index 1516860..5c45090 100644 (file)
 
 #include "csrmsg.h"
 
 
 #include "csrmsg.h"
 
-/*
-BOOLEAN
-NTAPI
-CsrCaptureArguments(IN PCSR_THREAD CsrThread,
-                    IN PCSR_API_MESSAGE ApiMessage);
-
-VOID
-NTAPI
-CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
-*/
-
 NTSTATUS
 NTAPI
 CsrClientConnectToServer(IN PWSTR ObjectDirectory,
 NTSTATUS
 NTAPI
 CsrClientConnectToServer(IN PWSTR ObjectDirectory,
index 26680d6..20d7933 100644 (file)
@@ -107,7 +107,7 @@ typedef struct _CSR_API_MESSAGE
     PORT_MESSAGE Header;
     union
     {
     PORT_MESSAGE Header;
     union
     {
-        CSR_CONNECTION_INFO ConnectionInfo; // Uniquely used in csrss/csrsrv for internal signaling (opening a new connection).
+        CSR_CONNECTION_INFO ConnectionInfo; // Uniquely used in CSRSRV for internal signaling (opening a new connection).
         struct
         {
             PCSR_CAPTURE_BUFFER CsrCaptureData;
         struct
         {
             PCSR_CAPTURE_BUFFER CsrCaptureData;
index 0815360..fb4a946 100644 (file)
@@ -247,19 +247,6 @@ NTSTATUS
 
 /* PROTOTYPES ****************************************************************/
 
 
 /* PROTOTYPES ****************************************************************/
 
-///////////
-BOOLEAN
-NTAPI
-CsrCaptureArguments(IN PCSR_THREAD CsrThread,
-                    IN PCSR_API_MESSAGE ApiMessage);
-
-VOID
-NTAPI
-CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
-//////////
-
-
-
 NTSTATUS
 NTAPI
 CsrServerInitialization(IN ULONG ArgumentCount,
 NTSTATUS
 NTAPI
 CsrServerInitialization(IN ULONG ArgumentCount,
index 023a381..3ef1d4e 100644 (file)
 // in the checked build of SMSS, which is probably a close approximation. We add
 // "p" to use the similar nomenclature seen/leaked out in the Base CSRSS APIs.
 //
 // in the checked build of SMSS, which is probably a close approximation. We add
 // "p" to use the similar nomenclature seen/leaked out in the Base CSRSS APIs.
 //
+// The enumeration finishes with an enumeratee holding the maximum API number.
+// Its name is based on BasepMaxApiNumber, UserpMaxApiNumber...
+//
 //
 typedef enum _SMSRV_API_NUMBER
 {
 //
 typedef enum _SMSRV_API_NUMBER
 {
-    SmCreateForeignSessionApi,
-    SmSessionCompleteApi,
-    SmTerminateForeignSessionApi,
-    SmExecPgmApi,
-    SmLoadDeferedSubsystemApi,
-    SmStartCsrApi,
-    SmStopCsrApi,
-    SmMaxApiNumber // Based on BasepMaxApiNumber, UserpMaxApiNumber...
+    SmpCreateForeignSessionApi,
+    SmpSessionCompleteApi,
+    SmpTerminateForeignSessionApi,
+    SmpExecPgmApi,
+    SmpLoadDeferedSubsystemApi,
+    SmpStartCsrApi,
+    SmpStopCsrApi,
+
+    SmpMaxApiNumber
 } SMSRV_API_NUMBER;
 
 //
 } SMSRV_API_NUMBER;
 
 //
@@ -108,7 +112,7 @@ C_ASSERT(sizeof(SM_API_MSG) == 0x130);
 #endif
 
 //
 #endif
 
 //
-// There are the APIs that the SMSS Serve can send to a client (such as CSRSS)
+// There are the APIs that the SMSS Server can send to a client (such as CSRSS).
 //
 // These are called "SB" APIs.
 //
 //
 // These are called "SB" APIs.
 //
@@ -117,6 +121,9 @@ C_ASSERT(sizeof(SM_API_MSG) == 0x130);
 // We add "p" to use the similar nomenclature seen/leaked out in the Base CSRSS
 // APIs.
 //
 // We add "p" to use the similar nomenclature seen/leaked out in the Base CSRSS
 // APIs.
 //
+// The enumeration finishes with an enumeratee holding the maximum API number.
+// Its name is based on BasepMaxApiNumber, UserpMaxApiNumber...
+//
 //
 typedef enum _SB_API_NUMBER
 {
 //
 typedef enum _SB_API_NUMBER
 {
@@ -124,7 +131,8 @@ typedef enum _SB_API_NUMBER
     SbpTerminateSession,
     SbpForeignSessionComplete,
     SbpCreateProcess,
     SbpTerminateSession,
     SbpForeignSessionComplete,
     SbpCreateProcess,
-    SbpMaxApiNumber // Based on BasepMaxApiNumber, UserpMaxApiNumber...
+
+    SbpMaxApiNumber
 } SB_API_NUMBER;
 
 //
 } SB_API_NUMBER;
 
 //
index 3f6311e..df89854 100644 (file)
@@ -38,7 +38,7 @@ SmExecPgm(IN HANDLE SmApiPort,
     SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
 
     /* Initalize this specific API's parameters */
     SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
 
     /* Initalize this specific API's parameters */
-    SmApiMsg.ApiNumber = SmExecPgmApi;
+    SmApiMsg.ApiNumber = SmpExecPgmApi;
     RtlCopyMemory(&SmApiMsg.u.ExecPgm.ProcessInformation,
                   ProcessInformation,
                   sizeof(SmApiMsg.u.ExecPgm.ProcessInformation));
     RtlCopyMemory(&SmApiMsg.u.ExecPgm.ProcessInformation,
                   ProcessInformation,
                   sizeof(SmApiMsg.u.ExecPgm.ProcessInformation));
@@ -144,7 +144,7 @@ SmSessionComplete(IN HANDLE SmApiPort,
     SessionComplete->SessionStatus = SessionStatus;
 
     /* Set the API Message Port Message header */
     SessionComplete->SessionStatus = SessionStatus;
 
     /* Set the API Message Port Message header */
-    ApiMessage.ApiNumber = SmSessionCompleteApi;
+    ApiMessage.ApiNumber = SmpSessionCompleteApi;
     ApiMessage.h.u1.s1.DataLength = sizeof(SM_SESSION_COMPLETE_MSG) + 8;
     ApiMessage.h.u1.s1.TotalLength = sizeof(SM_API_MSG);
     ApiMessage.h.u2.ZeroInit = 0;
     ApiMessage.h.u1.s1.DataLength = sizeof(SM_SESSION_COMPLETE_MSG) + 8;
     ApiMessage.h.u1.s1.TotalLength = sizeof(SM_API_MSG);
     ApiMessage.h.u2.ZeroInit = 0;
index 2b0e9ae..569988d 100644 (file)
@@ -23,7 +23,7 @@ HANDLE BaseSrvSharedHeap = NULL;    // Shared heap with CSR. (CsrSrvSharedSectio
 PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL;   // Data that we can share amongst processes. Initialized inside BaseSrvSharedHeap.
 
 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
 PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL;   // Data that we can share amongst processes. Initialized inside BaseSrvSharedHeap.
 
 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
-PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber] =
+PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER] =
 {
     BaseSrvCreateProcess,
     BaseSrvCreateThread,
 {
     BaseSrvCreateProcess,
     BaseSrvCreateThread,
@@ -57,7 +57,7 @@ PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber] =
     // BaseSrvNlsGetUserInfo,
 };
 
     // BaseSrvNlsGetUserInfo,
 };
 
-BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber] =
+BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER] =
 {
     TRUE,   // BaseSrvCreateProcess
     TRUE,   // BaseSrvCreateThread
 {
     TRUE,   // BaseSrvCreateProcess
     TRUE,   // BaseSrvCreateThread
@@ -91,7 +91,7 @@ BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber] =
     // FALSE,  // BaseSrvNlsGetUserInfo
 };
 
     // FALSE,  // BaseSrvNlsGetUserInfo
 };
 
-PCHAR BaseServerApiNameTable[BasepMaxApiNumber] =
+PCHAR BaseServerApiNameTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER] =
 {
     "BaseCreateProcess",
     "BaseCreateThread",
 {
     "BaseCreateProcess",
     "BaseCreateThread",
index 72b802c..740a007 100644 (file)
@@ -269,7 +269,7 @@ CsrpCheckRequestThreads(VOID)
     NTSTATUS Status;
 
     /* Decrease the count, and see if we're out */
     NTSTATUS Status;
 
     /* Decrease the count, and see if we're out */
-    if (!(_InterlockedDecrement(&CsrpStaticThreadCount)))
+    if (_InterlockedDecrement(&CsrpStaticThreadCount) == 0)
     {
         /* Check if we've still got space for a Dynamic Thread */
         if (CsrpDynamicThreadTotal < CsrMaxApiRequestThreads)
     {
         /* Check if we've still got space for a Dynamic Thread */
         if (CsrpDynamicThreadTotal < CsrMaxApiRequestThreads)
@@ -879,8 +879,7 @@ CsrApiRequestThread(IN PVOID Parameter)
  *
  * @param None
  *
  *
  * @param None
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -1010,7 +1009,7 @@ PCSR_THREAD
 NTAPI
 CsrConnectToUser(VOID)
 {
 NTAPI
 CsrConnectToUser(VOID)
 {
-#if 0 // This code is OK, however it is ClientThreadSetup which sucks.
+#if 0 // FIXME: This code is OK, however it is ClientThreadSetup which sucks.
     NTSTATUS Status;
     ANSI_STRING DllName;
     UNICODE_STRING TempName;
     NTSTATUS Status;
     ANSI_STRING DllName;
     UNICODE_STRING TempName;
@@ -1074,7 +1073,9 @@ CsrConnectToUser(VOID)
     PCSR_THREAD CsrThread;
 
     /* Save pointer to this thread in TEB */
     PCSR_THREAD CsrThread;
 
     /* Save pointer to this thread in TEB */
+    CsrAcquireProcessLock();
     CsrThread = CsrLocateThreadInProcess(NULL, &Teb->ClientId);
     CsrThread = CsrLocateThreadInProcess(NULL, &Teb->ClientId);
+    CsrReleaseProcessLock();
     if (CsrThread) Teb->CsrClientThread = CsrThread;
 
     /* Return it */
     if (CsrThread) Teb->CsrClientThread = CsrThread;
 
     /* Return it */
@@ -1099,7 +1100,6 @@ HANDLE
 NTAPI
 CsrQueryApiPort(VOID)
 {
 NTAPI
 CsrQueryApiPort(VOID)
 {
-    DPRINT("CSRSRV: %s called\n", __FUNCTION__);
     return CsrApiPort;
 }
 
     return CsrApiPort;
 }
 
@@ -1309,7 +1309,6 @@ CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage)
     RtlFreeHeap(CsrHeap, 0, RemoteCaptureBuffer);
 }
 
     RtlFreeHeap(CsrHeap, 0, RemoteCaptureBuffer);
 }
 
-
 /*++
  * @name CsrValidateMessageBuffer
  * @implemented NT5.1
 /*++
  * @name CsrValidateMessageBuffer
  * @implemented NT5.1
@@ -1404,36 +1403,6 @@ CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage,
     return FALSE;
 }
 
     return FALSE;
 }
 
-/*** This is what we have in consrv/server.c ***
-
-/\* Ensure that a captured buffer is safe to access *\/
-BOOL FASTCALL
-Win32CsrValidateBuffer(PCSR_PROCESS ProcessData, PVOID Buffer,
-                       SIZE_T NumElements, SIZE_T ElementSize)
-{
-    /\* Check that the following conditions are true:
-     * 1. The start of the buffer is somewhere within the process's
-     *    shared memory section view.
-     * 2. The remaining space in the view is at least as large as the buffer.
-     *    (NB: Please don't try to "optimize" this by using multiplication
-     *    instead of division; remember that 2147483648 * 2 = 0.)
-     * 3. The buffer is DWORD-aligned.
-     *\/
-    ULONG_PTR Offset = (BYTE *)Buffer - (BYTE *)ProcessData->ClientViewBase;
-    if (Offset >= ProcessData->ClientViewBounds
-            || NumElements > (ProcessData->ClientViewBounds - Offset) / ElementSize
-            || (Offset & (sizeof(DWORD) - 1)) != 0)
-    {
-        DPRINT1("Invalid buffer %p(%u*%u); section view is %p(%u)\n",
-                Buffer, NumElements, ElementSize,
-                ProcessData->ClientViewBase, ProcessData->ClientViewBounds);
-        return FALSE;
-    }
-    return TRUE;
-}
-
-***********************************************/
-
 /*++
  * @name CsrValidateMessageString
  * @implemented NT5.1
 /*++
  * @name CsrValidateMessageString
  * @implemented NT5.1
index a499079..c45e35e 100644 (file)
@@ -64,7 +64,6 @@ extern UNICODE_STRING CsrApiPortName;
 extern RTL_CRITICAL_SECTION CsrProcessLock;
 extern RTL_CRITICAL_SECTION CsrWaitListsLock;
 extern HANDLE CsrObjectDirectory;
 extern RTL_CRITICAL_SECTION CsrProcessLock;
 extern RTL_CRITICAL_SECTION CsrWaitListsLock;
 extern HANDLE CsrObjectDirectory;
-extern PSB_API_ROUTINE CsrServerSbApiDispatch[5];
 /****************************************************/
 
 
 /****************************************************/
 
 
@@ -75,25 +74,20 @@ CSR_API(CsrSrvIdentifyAlertableThread);
 CSR_API(CsrSrvSetPriorityClass);
 
 
 CSR_API(CsrSrvSetPriorityClass);
 
 
-/***
+NTSTATUS
+NTAPI
+CsrServerDllInitialization(IN PCSR_SERVER_DLL LoadedServerDll);
+
 
 BOOLEAN
 NTAPI
 
 BOOLEAN
 NTAPI
-CsrCaptureArguments(
-    IN PCSR_THREAD CsrThread,
-    IN PCSR_API_MESSAGE ApiMessage
-);
+CsrCaptureArguments(IN PCSR_THREAD CsrThread,
+                    IN PCSR_API_MESSAGE ApiMessage);
 
 VOID
 NTAPI
 CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
 
 
 VOID
 NTAPI
 CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
 
-NTSTATUS
-NTAPI
-CsrServerDllInitialization(IN PCSR_SERVER_DLL LoadedServerDll);
-
-***/
-
 NTSTATUS
 NTAPI
 CsrLoadServerDll(IN PCHAR DllString,
 NTSTATUS
 NTAPI
 CsrLoadServerDll(IN PCHAR DllString,
@@ -115,16 +109,16 @@ CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess);
 
 VOID
 NTAPI
 
 VOID
 NTAPI
-CsrRemoveProcess(IN PCSR_PROCESS CsrProcess);
+CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL,
+                 IN PCSR_PROCESS CsrProcess);
 
 VOID
 NTAPI
 
 VOID
 NTAPI
-CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL,
-                 IN PCSR_PROCESS CsrProcess);
+CsrRemoveProcess(IN PCSR_PROCESS CsrProcess);
 
 NTSTATUS
 NTAPI
 
 NTSTATUS
 NTAPI
-CsrApiRequestThread(IN PVOID Parameter); // HANDLE ServerPort ??
+CsrApiRequestThread(IN PVOID Parameter);
 
 VOID
 NTAPI
 
 VOID
 NTAPI
index 751797e..69dbbd8 100644 (file)
@@ -48,8 +48,7 @@ SYSTEM_BASIC_INFORMATION CsrNtSysInfo;
  *
  * @param None.
  *
  *
  * @param None.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -163,8 +162,7 @@ Quickie:
  * @param ObjectDirectory
  *        Handle fo the Object Directory to protect.
  *
  * @param ObjectDirectory
  *        Handle fo the Object Directory to protect.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -186,8 +184,7 @@ CsrSetDirectorySecurity(IN HANDLE ObjectDirectory)
  * @param DosDevicesSd
  *        Pointer to the Security Descriptor to return.
  *
  * @param DosDevicesSd
  *        Pointer to the Security Descriptor to return.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks Depending on the DOS Devices Protection Mode (set in the registry),
  *          regular users may or may not have full access to the directory.
  *
  * @remarks Depending on the DOS Devices Protection Mode (set in the registry),
  *          regular users may or may not have full access to the directory.
@@ -403,8 +400,7 @@ FreeDosDevicesProtection(IN PSECURITY_DESCRIPTOR DosDevicesSd)
  * @param Session
  *        Session ID for which to create the directories.
  *
  * @param Session
  *        Session ID for which to create the directories.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -534,8 +530,7 @@ CsrCreateSessionObjectDirectory(IN ULONG Session)
  * @param Arguments
  *        Array of arguments.
  *
  * @param Arguments
  *        Array of arguments.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -714,8 +709,7 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
  *
  * @param None.
  *
  *
  * @param None.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -777,7 +771,6 @@ CsrInitCsrRootProcess(VOID)
         if (ServerDll && ServerDll->NewProcessCallback)
         {
             /* Call the callback */
         if (ServerDll && ServerDll->NewProcessCallback)
         {
             /* Call the callback */
-            DPRINT1("Call NewProcessCallback(NULL, 0x%p) called\n", CsrRootProcess);
             ServerDll->NewProcessCallback(NULL, CsrRootProcess);
         }
     }
             ServerDll->NewProcessCallback(NULL, CsrRootProcess);
         }
     }
@@ -794,8 +787,7 @@ CsrInitCsrRootProcess(VOID)
  * @param LocalSystemSd
  *        Pointer to a pointer to the security descriptor to create.
  *
  * @param LocalSystemSd
  *        Pointer to a pointer to the security descriptor to create.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -871,8 +863,7 @@ CsrCreateLocalSystemSD(OUT PSECURITY_DESCRIPTOR *LocalSystemSd)
  *
  * @param None
  *
  *
  * @param None
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -960,7 +951,7 @@ CsrSbApiPortInitialize(VOID)
  * @implemented NT4
  *
  * The CsrServerInitialization routine is the native (not Server) entrypoint
  * @implemented NT4
  *
  * The CsrServerInitialization routine is the native (not Server) entrypoint
- * of this Server DLL. It serves as the entrypoint for csrss.
+ * of this Server DLL. It serves as the entrypoint for CSRSS.
  *
  * @param ArgumentCount
  *        Number of arguments on the command line.
  *
  * @param ArgumentCount
  *        Number of arguments on the command line.
@@ -968,8 +959,7 @@ CsrSbApiPortInitialize(VOID)
  * @param Arguments
  *        Array of arguments from the command line.
  *
  * @param Arguments
  *        Array of arguments from the command line.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -980,7 +970,6 @@ CsrServerInitialization(IN ULONG ArgumentCount,
                         IN PCHAR Arguments[])
 {
     NTSTATUS Status = STATUS_SUCCESS;
                         IN PCHAR Arguments[])
 {
     NTSTATUS Status = STATUS_SUCCESS;
-    DPRINT("CSRSRV: %s called\n", __FUNCTION__);
 
     /* Create the Init Event */
     Status = NtCreateEvent(&CsrInitializationEvent,
 
     /* Create the Init Event */
     Status = NtCreateEvent(&CsrInitializationEvent,
index fe96ddb..75adf20 100644 (file)
@@ -41,7 +41,7 @@ extern ULONG CsrTotalPerProcessDataLength;
  *
  * @return None.
  *
  *
  * @return None.
  *
- * @remarks The "Normal" Priority corresponds to the Normal Forground
+ * @remarks The "Normal" Priority corresponds to the Normal Foreground
  *          Priority (9) plus a boost of 4.
  *
  *--*/
  *          Priority (9) plus a boost of 4.
  *
  *--*/
@@ -69,7 +69,7 @@ CsrSetToNormalPriority(VOID)
  *
  * @return None.
  *
  *
  * @return None.
  *
- * @remarks The "Shutdown" Priority corresponds to the Normal Forground
+ * @remarks The "Shutdown" Priority corresponds to the Normal Foreground
  *          Priority (9) plus a boost of 6.
  *
  *--*/
  *          Priority (9) plus a boost of 6.
  *
  *--*/
@@ -264,7 +264,7 @@ CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
     /* Decrease reference count */
     LockCount = --CsrProcess->ReferenceCount;
     ASSERT(LockCount >= 0);
     /* Decrease reference count */
     LockCount = --CsrProcess->ReferenceCount;
     ASSERT(LockCount >= 0);
-    if (!LockCount)
+    if (LockCount == 0)
     {
         /* Call the generic cleanup code */
         DPRINT1("Should kill process: %p\n", CsrProcess);
     {
         /* Call the generic cleanup code */
         DPRINT1("Should kill process: %p\n", CsrProcess);
@@ -345,8 +345,7 @@ CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
  *
  * @param None.
  *
  *
  * @param None.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -495,18 +494,25 @@ CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL,
  * @name CsrCreateProcess
  * @implemented NT4
  *
  * @name CsrCreateProcess
  * @implemented NT4
  *
- * Do nothing for 500ms.
+ * The CsrCreateProcess routine creates a CSR Process object for an NT Process.
  *
  *
- * @param ArgumentCount
- *        Description of the parameter. Wrapped to more lines on ~70th
- *        column.
+ * @param hProcess
+ *        Handle to an existing NT Process to which to associate this
+ *        CSR Process.
+ *
+ * @param hThread
+ *        Handle to an existing NT Thread to which to create its
+ *        corresponding CSR Thread for this CSR Process.
+ *
+ * @param ClientId
+ *        Pointer to the Client ID structure of the NT Process to associate
+ *        with this CSR Process.
  *
  *
- * @param Arguments
- *        Description of the parameter. Wrapped to more lines on ~70th
- *        column.
+ * @param NtSession
+ * @param Flags
+ * @param DebugCid
  *
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -597,7 +603,7 @@ CsrCreateProcess(IN HANDLE hProcess,
     }
 
     /* Check if CreateProcess got CREATE_NEW_PROCESS_GROUP */
     }
 
     /* Check if CreateProcess got CREATE_NEW_PROCESS_GROUP */
-    if (!(Flags & CsrProcessCreateNewGroup))
+    if ((Flags & CsrProcessCreateNewGroup) == 0)
     {
         /* Create new data */
         CsrProcess->ProcessGroupId = HandleToUlong(ClientId->UniqueProcess);
     {
         /* Create new data */
         CsrProcess->ProcessGroupId = HandleToUlong(ClientId->UniqueProcess);
@@ -781,7 +787,7 @@ CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess)
     /* Decrease reference count */
     LockCount = --CsrProcess->ReferenceCount;
     ASSERT(LockCount >= 0);
     /* Decrease reference count */
     LockCount = --CsrProcess->ReferenceCount;
     ASSERT(LockCount >= 0);
-    if (!LockCount)
+    if (LockCount == 0)
     {
         /* Call the generic cleanup code */
         CsrProcessRefcountZero(CsrProcess);
     {
         /* Call the generic cleanup code */
         CsrProcessRefcountZero(CsrProcess);
@@ -891,16 +897,15 @@ CsrDestroyProcess(IN PCLIENT_ID Cid,
  * @name CsrGetProcessLuid
  * @implemented NT4
  *
  * @name CsrGetProcessLuid
  * @implemented NT4
  *
- * Do nothing for 500ms.
+ * The CsrGetProcessLuid routine gets the LUID of the given process.
  *
  * @param hProcess
  *        Optional handle to the process whose LUID should be returned.
  *
  * @param Luid
  *
  * @param hProcess
  *        Optional handle to the process whose LUID should be returned.
  *
  * @param Luid
- *        Pointer to a LUID Pointer which will receive the CSR Process' LUID
+ *        Pointer to a LUID Pointer which will receive the CSR Process' LUID.
  *
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks If hProcess is not supplied, then the current thread's token will
  *          be used. If that too is missing, then the current process' token
  *
  * @remarks If hProcess is not supplied, then the current thread's token will
  *          be used. If that too is missing, then the current process' token
@@ -1000,7 +1005,7 @@ CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL,
  * @param CsrThread
  *        Pointer to the CSR Thread to impersonate.
  *
  * @param CsrThread
  *        Pointer to the CSR Thread to impersonate.
  *
- * @return TRUE if impersonation succeeded, false otherwise.
+ * @return TRUE if impersonation succeeded, FALSE otherwise.
  *
  * @remarks Impersonation can be recursive.
  *
  *
  * @remarks Impersonation can be recursive.
  *
@@ -1030,10 +1035,8 @@ CsrImpersonateClient(IN PCSR_THREAD CsrThread)
     if (!NT_SUCCESS(Status))
     {
         /* Failure */
     if (!NT_SUCCESS(Status))
     {
         /* Failure */
-/*
         DPRINT1("CSRSS: Can't impersonate client thread - Status = %lx\n", Status);
         DPRINT1("CSRSS: Can't impersonate client thread - Status = %lx\n", Status);
-        if (Status != STATUS_BAD_IMPERSONATION_LEVEL) DbgBreakPoint();
-*/
+        // if (Status != STATUS_BAD_IMPERSONATION_LEVEL) DbgBreakPoint();
         return FALSE;
     }
 
         return FALSE;
     }
 
@@ -1058,8 +1061,7 @@ CsrImpersonateClient(IN PCSR_THREAD CsrThread)
  *        Optional pointer to a CSR Process pointer which will hold the
  *        CSR Process corresponding to the given Process ID.
  *
  *        Optional pointer to a CSR Process pointer which will hold the
  *        CSR Process corresponding to the given Process ID.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks Locking a CSR Process is defined as acquiring an extra
  *          reference to it and returning with the Process Lock held.
  *
  * @remarks Locking a CSR Process is defined as acquiring an extra
  *          reference to it and returning with the Process Lock held.
@@ -1124,7 +1126,7 @@ CsrLockProcessByClientId(IN HANDLE Pid,
  *
  * @param None.
  *
  *
  * @param None.
  *
- * @return TRUE if the reversion was succesful, false otherwise.
+ * @return TRUE if the reversion was succesful, FALSE otherwise.
  *
  * @remarks Impersonation can be recursive; as such, the impersonation token
  *          will only be deleted once the CSR Thread's impersonaton count
  *
  * @remarks Impersonation can be recursive; as such, the impersonation token
  *          will only be deleted once the CSR Thread's impersonaton count
@@ -1145,11 +1147,11 @@ CsrRevertToSelf(VOID)
         /* Make sure impersonation is on */
         if (!CurrentThread->ImpersonationCount)
         {
         /* Make sure impersonation is on */
         if (!CurrentThread->ImpersonationCount)
         {
-            // DPRINT1("CSRSS: CsrRevertToSelf called while not impersonating\n");
+            DPRINT1("CSRSS: CsrRevertToSelf called while not impersonating\n");
             // DbgBreakPoint();
             return FALSE;
         }
             // DbgBreakPoint();
             return FALSE;
         }
-        else if (--CurrentThread->ImpersonationCount > 0)
+        else if ((--CurrentThread->ImpersonationCount) > 0)
         {
             /* Success; impersonation count decreased but still not zero */
             return TRUE;
         {
             /* Success; impersonation count decreased but still not zero */
             return TRUE;
@@ -1242,8 +1244,7 @@ CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess)
  * @param Flags
  *        Flags to send to the shutdown notification routine.
  *
  * @param Flags
  *        Flags to send to the shutdown notification routine.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
index a858a5e..380c999 100644 (file)
@@ -55,8 +55,8 @@ HANDLE CsrSrvSharedSection = NULL;
  * @name CsrServerDllInitialization
  * @implemented NT4
  *
  * @name CsrServerDllInitialization
  * @implemented NT4
  *
- * The CsrServerDllInitialization is the initialization routine for
- * the this Server DLL.
+ * The CsrServerDllInitialization is the initialization routine
+ * for this Server DLL.
  *
  * @param LoadedServerDll
  *        Pointer to the CSR Server DLL structure representing this Server DLL.
  *
  * @param LoadedServerDll
  *        Pointer to the CSR Server DLL structure representing this Server DLL.
@@ -86,18 +86,17 @@ CSR_SERVER_DLL_INIT(CsrServerDllInitialization)
  * @name CsrLoadServerDll
  * @implemented NT4
  *
  * @name CsrLoadServerDll
  * @implemented NT4
  *
- * The CsrLoadServerDll routine loads a CSR Server DLL and calls its entrypoint
+ * The CsrLoadServerDll routine loads a CSR Server DLL and calls its entrypoint.
  *
  * @param DllString
  *        Pointer to the CSR Server DLL to load and call.
  *
  * @param EntryPoint
  *
  * @param DllString
  *        Pointer to the CSR Server DLL to load and call.
  *
  * @param EntryPoint
- *        Pointer to the name of the server's initialization function. If
- *        this parameter is NULL, the default ServerDllInitialize will be
- *        assumed.
+ *        Pointer to the name of the server's initialization function.
+ *        If this parameter is NULL, the default ServerDllInitialize
+ *        will be assumed.
  *
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -119,8 +118,6 @@ CsrLoadServerDll(IN PCHAR DllString,
     PCSR_SERVER_DLL_INIT_CALLBACK ServerDllInitProcedure;
     ULONG Response;
 
     PCSR_SERVER_DLL_INIT_CALLBACK ServerDllInitProcedure;
     ULONG Response;
 
-    DPRINT1("CsrLoadServerDll(%s, 0x%p, %lu)\n", DllString, EntryPoint, ServerId);
-
     /* Check if it's beyond the maximum we support */
     if (ServerId >= CSR_SERVER_DLL_MAX) return STATUS_TOO_MANY_NAMES;
 
     /* Check if it's beyond the maximum we support */
     if (ServerId >= CSR_SERVER_DLL_MAX) return STATUS_TOO_MANY_NAMES;
 
@@ -225,15 +222,10 @@ CsrLoadServerDll(IN PCHAR DllString,
                 CsrSrvSharedStaticServerData[ServerDll->ServerId] = ServerDll->SharedSection;
             }
         }
                 CsrSrvSharedStaticServerData[ServerDll->ServerId] = ServerDll->SharedSection;
             }
         }
-        else
-        {
-            /* Use shared failure code */
-            goto LoadFailed;
-        }
     }
     }
-    else
+
+    if (!NT_SUCCESS(Status))
     {
     {
-LoadFailed:
         /* Server Init failed, unload it */
         if (hServerDll) LdrUnloadDll(hServerDll);
 
         /* Server Init failed, unload it */
         if (hServerDll) LdrUnloadDll(hServerDll);
 
@@ -316,15 +308,14 @@ CSR_API(CsrSrvClientConnect)
 /*++
  * @name CsrSrvCreateSharedSection
  *
 /*++
  * @name CsrSrvCreateSharedSection
  *
- * The CsrSrvCreateSharedSection creates the Shared Section that all CSR Server
- * DLLs and Clients can use to share data.
+ * The CsrSrvCreateSharedSection creates the Shared Section that all
+ * CSR Server DLLs and Clients can use to share data.
  *
  * @param ParameterValue
  *        Specially formatted string from our registry command-line which
  *        specifies various arguments for the shared section.
  *
  *
  * @param ParameterValue
  *        Specially formatted string from our registry command-line which
  *        specifies various arguments for the shared section.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -445,8 +436,7 @@ CsrSrvCreateSharedSection(IN PCHAR ParameterValue)
  *        Pointer to the CSR Connection Info structure for the incoming
  *        connection.
  *
  *        Pointer to the CSR Connection Info structure for the incoming
  *        connection.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -463,7 +453,6 @@ CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
     if (CsrProcess)
     {
         /* Map the section into this process */
     if (CsrProcess)
     {
         /* Map the section into this process */
-        DPRINT("CSR Process Handle: %p. CSR Process: %p\n", CsrProcess->ProcessHandle, CsrProcess);
         Status = NtMapViewOfSection(CsrSrvSharedSection,
                                     CsrProcess->ProcessHandle,
                                     &CsrSrvSharedSectionBase,
         Status = NtMapViewOfSection(CsrSrvSharedSection,
                                     CsrProcess->ProcessHandle,
                                     &CsrSrvSharedSectionBase,
@@ -553,8 +542,8 @@ CSR_API(CsrSrvSetPriorityClass)
  *
  * @return STATUS_INVALID_PARAMETER.
  *
  *
  * @return STATUS_INVALID_PARAMETER.
  *
- * @remarks CsrSrvSetPriorityClass does not use this stub because it must
- *          return success.
+ * @remarks CsrSrvSetPriorityClass does not use this stub because
+ *          it must return success.
  *
  *--*/
 CSR_API(CsrSrvUnusedFunction)
  *
  *--*/
 CSR_API(CsrSrvUnusedFunction)
@@ -621,12 +610,12 @@ CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
                                       NULL);
 
     /* Check if this is Session 0, and the Debugger is Enabled */
                                       NULL);
 
     /* Check if this is Session 0, and the Debugger is Enabled */
-    if ((NtCurrentPeb()->SessionId) && (NT_SUCCESS(Status)) &&
+    if ((NtCurrentPeb()->SessionId != 0) && (NT_SUCCESS(Status)) &&
         (DebuggerInfo.KernelDebuggerEnabled))
     {
         /* Call the Unhandled Exception Filter */
         (DebuggerInfo.KernelDebuggerEnabled))
     {
         /* Call the Unhandled Exception Filter */
-        if ((Result = RtlUnhandledExceptionFilter(ExceptionInfo)) !=
-            EXCEPTION_CONTINUE_EXECUTION)
+        Result = RtlUnhandledExceptionFilter(ExceptionInfo);
+        if (Result != EXCEPTION_CONTINUE_EXECUTION)
         {
             /* We're going to raise an error. Get Shutdown Privilege first */
             Status = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE,
         {
             /* We're going to raise an error. Get Shutdown Privilege first */
             Status = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE,
index 8a2039b..7970290 100644 (file)
 RTL_CRITICAL_SECTION CsrNtSessionLock;
 LIST_ENTRY CsrNtSessionList;
 
 RTL_CRITICAL_SECTION CsrNtSessionLock;
 LIST_ENTRY CsrNtSessionList;
 
-// Does it exist a enumeration associated with it ?
-PSB_API_ROUTINE CsrServerSbApiDispatch[5] =
+PSB_API_ROUTINE CsrServerSbApiDispatch[SbpMaxApiNumber - SbpCreateSession] =
 {
     CsrSbCreateSession,
     CsrSbTerminateSession,
     CsrSbForeignSessionComplete,
 {
     CsrSbCreateSession,
     CsrSbTerminateSession,
     CsrSbForeignSessionComplete,
-    CsrSbCreateProcess,
-    NULL
+    CsrSbCreateProcess
 };
 
 };
 
-PCHAR CsrServerSbApiName[5] =
+PCHAR CsrServerSbApiName[SbpMaxApiNumber - SbpCreateSession] =
 {
     "SbCreateSession",
     "SbTerminateSession",
     "SbForeignSessionComplete",
 {
     "SbCreateSession",
     "SbTerminateSession",
     "SbForeignSessionComplete",
-    "SbCreateProcess",
-    "Unknown Csr Sb Api Number"
+    "SbCreateProcess"
 };
 
 /* PRIVATE FUNCTIONS **********************************************************/
 };
 
 /* PRIVATE FUNCTIONS **********************************************************/
@@ -55,8 +52,6 @@ NTSTATUS
 NTAPI
 CsrInitializeNtSessionList(VOID)
 {
 NTAPI
 CsrInitializeNtSessionList(VOID)
 {
-    DPRINT("CSRSRV: %s called\n", __FUNCTION__);
-
     /* Initialize the Session List */
     InitializeListHead(&CsrNtSessionList);
 
     /* Initialize the Session List */
     InitializeListHead(&CsrNtSessionList);
 
@@ -170,7 +165,7 @@ CsrDereferenceNtSession(IN PCSR_NT_SESSION Session,
     ASSERT(Session->ReferenceCount != 0);
 
     /* Dereference the Session Object */
     ASSERT(Session->ReferenceCount != 0);
 
     /* Dereference the Session Object */
-    if (!(--Session->ReferenceCount))
+    if ((--Session->ReferenceCount) == 0)
     {
         /* Remove it from the list */
         RemoveEntryList(&Session->SessionLink);
     {
         /* Remove it from the list */
         RemoveEntryList(&Session->SessionLink);
@@ -537,8 +532,8 @@ CsrSbApiRequestThread(IN PVOID Parameter)
         }
 
         /*
         }
 
         /*
-         * It's an API Message, check if it's within limits. If it's not, the
-         * NT Behaviour is to set this to the Maximum API.
+         * It's an API Message, check if it's within limits. If it's not,
+         * the NT Behaviour is to set this to the Maximum API.
          */
         if (ReceiveMsg.ApiNumber > SbpMaxApiNumber)
         {
          */
         if (ReceiveMsg.ApiNumber > SbpMaxApiNumber)
         {
@@ -555,6 +550,9 @@ CsrSbApiRequestThread(IN PVOID Parameter)
             /* Call the API */
             if (!CsrServerSbApiDispatch[ReceiveMsg.ApiNumber](&ReceiveMsg))
             {
             /* Call the API */
             if (!CsrServerSbApiDispatch[ReceiveMsg.ApiNumber](&ReceiveMsg))
             {
+                DPRINT1("CSRSS: %s Session Api called and failed\n",
+                        CsrServerSbApiName[ReceiveMsg.ApiNumber]);
+
                 /* It failed, so return nothing */
                 ReplyMsg = NULL;
             }
                 /* It failed, so return nothing */
                 ReplyMsg = NULL;
             }
index 7363372..1682185 100644 (file)
@@ -14,8 +14,7 @@
 #define NDEBUG
 #include <debug.h>
 
 #define NDEBUG
 #include <debug.h>
 
-#define CsrHashThread(t) \
-    (HandleToUlong(t)&(256 - 1))
+#define CsrHashThread(t) (HandleToUlong(t)&(256 - 1))
 
 /* GLOBALS ********************************************************************/
 
 
 /* GLOBALS ********************************************************************/
 
@@ -215,7 +214,6 @@ CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL,
             if (Process) *Process = FoundThread->Process;
 
             /* Return thread too */
             if (Process) *Process = FoundThread->Process;
 
             /* Return thread too */
-//            DPRINT1("Found: %p %p\n", FoundThread, FoundThread->Process);
             return FoundThread;
         }
     }
             return FoundThread;
         }
     }
@@ -257,7 +255,6 @@ CsrLocateThreadInProcess(IN PCSR_PROCESS CsrProcess OPTIONAL,
     if (!CsrProcess) CsrProcess = CsrRootProcess;
 
     /* Save the List pointers */
     if (!CsrProcess) CsrProcess = CsrRootProcess;
 
     /* Save the List pointers */
-//    DPRINT1("Searching in: %p %d\n", CsrProcess, CsrProcess->ThreadCount);
     ListHead = &CsrProcess->ThreadList;
     NextEntry = ListHead->Flink;
 
     ListHead = &CsrProcess->ThreadList;
     NextEntry = ListHead->Flink;
 
@@ -275,7 +272,6 @@ CsrLocateThreadInProcess(IN PCSR_PROCESS CsrProcess OPTIONAL,
     }
 
     /* Return what we found */
     }
 
     /* Return what we found */
-//    DPRINT1("Found: %p\n", FoundThread);
     return FoundThread;
 }
 
     return FoundThread;
 }
 
@@ -312,7 +308,6 @@ CsrInsertThread(IN PCSR_PROCESS Process,
 
     /* Hash the Thread */
     i = CsrHashThread(Thread->ClientId.UniqueThread);
 
     /* Hash the Thread */
     i = CsrHashThread(Thread->ClientId.UniqueThread);
-//    DPRINT1("TID %lx HASH: %lx\n", Thread->ClientId.UniqueThread, i);
 
     /* Insert it there too */
     InsertHeadList(&CsrThreadHashTable[i], &Thread->HashLinks);
 
     /* Insert it there too */
     InsertHeadList(&CsrThreadHashTable[i], &Thread->HashLinks);
@@ -377,10 +372,10 @@ CsrRemoveThread(IN PCSR_THREAD CsrThread)
     if (CsrThread->HashLinks.Flink) RemoveEntryList(&CsrThread->HashLinks);
 
     /* Check if this is the last Thread */
     if (CsrThread->HashLinks.Flink) RemoveEntryList(&CsrThread->HashLinks);
 
     /* Check if this is the last Thread */
-    if (!CsrThread->Process->ThreadCount)
+    if (CsrThread->Process->ThreadCount == 0)
     {
         /* Check if it's not already been marked for deletion */
     {
         /* Check if it's not already been marked for deletion */
-        if (!(CsrThread->Process->Flags & CsrProcessLastThreadTerminated))
+        if ((CsrThread->Process->Flags & CsrProcessLastThreadTerminated) == 0)
         {
             /* Let everyone know this process is about to lose the thread */
             CsrThread->Process->Flags |= CsrProcessLastThreadTerminated;
         {
             /* Let everyone know this process is about to lose the thread */
             CsrThread->Process->Flags |= CsrProcessLastThreadTerminated;
@@ -464,7 +459,7 @@ CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
     /* Decrease reference count */
     LockCount = --CsrThread->ReferenceCount;
     ASSERT(LockCount >= 0);
     /* Decrease reference count */
     LockCount = --CsrThread->ReferenceCount;
     ASSERT(LockCount >= 0);
-    if (!LockCount)
+    if (LockCount == 0)
     {
         /* Call the generic cleanup code */
         CsrAcquireProcessLock();
     {
         /* Call the generic cleanup code */
         CsrAcquireProcessLock();
@@ -551,8 +546,7 @@ CsrAddStaticServerThread(IN HANDLE hThread,
  *        Pointer to the Client ID structure of the NT Thread to associate
  *        with this CSR Thread.
  *
  *        Pointer to the Client ID structure of the NT Thread to associate
  *        with this CSR Thread.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -567,7 +561,6 @@ CsrCreateRemoteThread(IN HANDLE hThread,
     PCSR_THREAD CsrThread;
     PCSR_PROCESS CsrProcess;
     KERNEL_USER_TIMES KernelTimes;
     PCSR_THREAD CsrThread;
     PCSR_PROCESS CsrProcess;
     KERNEL_USER_TIMES KernelTimes;
-    DPRINT("CSRSRV: %s called\n", __FUNCTION__);
 
     /* Get the Thread Create Time */
     Status = NtQueryInformationThread(hThread,
 
     /* Get the Thread Create Time */
     Status = NtQueryInformationThread(hThread,
@@ -602,7 +595,7 @@ CsrCreateRemoteThread(IN HANDLE hThread,
     CsrThread = CsrAllocateThread(CsrProcess);
     if (!CsrThread)
     {
     CsrThread = CsrAllocateThread(CsrProcess);
     if (!CsrThread)
     {
-        DPRINT1("CSRSRV:%s: out of memory!\n", __FUNCTION__);
+        DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
         CsrUnlockProcess(CsrProcess);
         return STATUS_NO_MEMORY;
     }
         CsrUnlockProcess(CsrProcess);
         return STATUS_NO_MEMORY;
     }
@@ -654,8 +647,7 @@ CsrCreateRemoteThread(IN HANDLE hThread,
  *        Pointer to the Client ID structure of the NT Thread to associate
  *        with this CSR Thread.
  *
  *        Pointer to the Client ID structure of the NT Thread to associate
  *        with this CSR Thread.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks None.
  *
  *
  * @remarks None.
  *
@@ -673,8 +665,6 @@ CsrCreateThread(IN PCSR_PROCESS CsrProcess,
     CLIENT_ID CurrentCid;
     KERNEL_USER_TIMES KernelTimes;
 
     CLIENT_ID CurrentCid;
     KERNEL_USER_TIMES KernelTimes;
 
-    DPRINT("CSRSRV: %s called\n", __FUNCTION__);
-
     if (HaveClient)
     {
         /* Get the current thread and CID */
     if (HaveClient)
     {
         /* Get the current thread and CID */
@@ -690,7 +680,7 @@ CsrCreateThread(IN PCSR_PROCESS CsrProcess,
         /* Something is wrong if we get an empty thread back */
         if (!CurrentThread)
         {
         /* Something is wrong if we get an empty thread back */
         if (!CurrentThread)
         {
-            DPRINT1("CSRSRV:%s: invalid thread!\n", __FUNCTION__);
+            DPRINT1("CSRSRV: %s: invalid thread!\n", __FUNCTION__);
             CsrReleaseProcessLock();
             return STATUS_THREAD_IS_TERMINATING;
         }
             CsrReleaseProcessLock();
             return STATUS_THREAD_IS_TERMINATING;
         }
@@ -717,7 +707,7 @@ CsrCreateThread(IN PCSR_PROCESS CsrProcess,
     CsrThread = CsrAllocateThread(CsrProcess);
     if (!CsrThread)
     {
     CsrThread = CsrAllocateThread(CsrProcess);
     if (!CsrThread)
     {
-        DPRINT1("CSRSRV:%s: out of memory!\n", __FUNCTION__);
+        DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
         CsrReleaseProcessLock();
         return STATUS_NO_MEMORY;
     }
         CsrReleaseProcessLock();
         return STATUS_NO_MEMORY;
     }
@@ -762,7 +752,7 @@ CsrDereferenceThread(IN PCSR_THREAD CsrThread)
 
     /* Decrease reference count */
     ASSERT(CsrThread->ReferenceCount > 0);
 
     /* Decrease reference count */
     ASSERT(CsrThread->ReferenceCount > 0);
-    if (!(--CsrThread->ReferenceCount))
+    if ((--CsrThread->ReferenceCount) == 0)
     {
         /* Call the generic cleanup code */
         CsrThreadRefcountZero(CsrThread);
     {
         /* Call the generic cleanup code */
         CsrThreadRefcountZero(CsrThread);
@@ -807,7 +797,7 @@ CsrDestroyThread(IN PCLIENT_ID Cid)
                                           &ClientId);
 
     /* Make sure we got one back, and that it's not already gone */
                                           &ClientId);
 
     /* Make sure we got one back, and that it's not already gone */
-    if (!CsrThread || CsrThread->Flags & CsrThreadTerminated)
+    if (!CsrThread || (CsrThread->Flags & CsrThreadTerminated))
     {
         /* Release the lock and return failure */
         CsrReleaseProcessLock();
     {
         /* Release the lock and return failure */
         CsrReleaseProcessLock();
@@ -856,8 +846,7 @@ CsrDestroyThread(IN PCLIENT_ID Cid)
  * @param Flags
  *        Initial CSR Thread Flags to set to the CSR Thread.
  *
  * @param Flags
  *        Initial CSR Thread Flags to set to the CSR Thread.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks This routine is similar to CsrAddStaticServerThread, but it
  *          also creates an NT Thread instead of expecting one to already
  *
  * @remarks This routine is similar to CsrAddStaticServerThread, but it
  *          also creates an NT Thread instead of expecting one to already
@@ -937,8 +926,7 @@ CsrExecServerThread(IN PVOID ThreadHandler,
  *        Optional pointer to a CSR Thread pointer which will hold the
  *        CSR Thread corresponding to the given Thread ID.
  *
  *        Optional pointer to a CSR Thread pointer which will hold the
  *        CSR Thread corresponding to the given Thread ID.
  *
- * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
- *         otherwise.
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
  *
  * @remarks Locking a CSR Thread is defined as acquiring an extra
  *          reference to it and returning with the Process Lock held.
  *
  * @remarks Locking a CSR Thread is defined as acquiring an extra
  *          reference to it and returning with the Process Lock held.
@@ -975,7 +963,7 @@ CsrLockThreadByClientId(IN HANDLE Tid,
 
         /* Check for PID Match */
         if ((CurrentThread->ClientId.UniqueThread == Tid) &&
 
         /* Check for PID Match */
         if ((CurrentThread->ClientId.UniqueThread == Tid) &&
-            !(CurrentThread->Flags & CsrThreadTerminated))
+            (CurrentThread->Flags & CsrThreadTerminated) == 0)
         {
             /* Get out of here */
             break;
         {
             /* Get out of here */
             break;
index e2d2521..339dbb3 100644 (file)
@@ -666,7 +666,6 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
     /* If we don't need a console, then get out of here */
     if (!ConnectInfo->ConsoleNeeded || !ProcessData->ConsoleApp) // In fact, it is for GUI apps.
     {
     /* If we don't need a console, then get out of here */
     if (!ConnectInfo->ConsoleNeeded || !ProcessData->ConsoleApp) // In fact, it is for GUI apps.
     {
-        DPRINT("ConSrvConnect - No console needed\n");
         return STATUS_SUCCESS;
     }
 
         return STATUS_SUCCESS;
     }
 
index 9feb75e..e1b3063 100644 (file)
@@ -23,7 +23,7 @@ HANDLE ConSrvHeap = NULL;   // Our own heap.
 
 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
 // plus a little bit of Windows 7.
 
 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
 // plus a little bit of Windows 7.
-PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber] =
+PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER] =
 {
     SrvOpenConsole,
     SrvGetConsoleInput,
 {
     SrvOpenConsole,
     SrvGetConsoleInput,
@@ -114,7 +114,7 @@ PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber] =
     SrvSetConsoleHistory,
 };
 
     SrvSetConsoleHistory,
 };
 
-BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber] =
+BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER] =
 {
     FALSE,   // SrvOpenConsole,
     FALSE,   // SrvGetConsoleInput,
 {
     FALSE,   // SrvOpenConsole,
     FALSE,   // SrvGetConsoleInput,
@@ -205,7 +205,7 @@ BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber] =
     FALSE,   // SrvSetConsoleHistory
 };
 
     FALSE,   // SrvSetConsoleHistory
 };
 
-PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber] =
+PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER] =
 {
     "OpenConsole",
     "GetConsoleInput",
 {
     "OpenConsole",
     "GetConsoleInput",
index 4fa1a45..074fb40 100644 (file)
@@ -22,7 +22,7 @@ HINSTANCE UserServerDllInstance = NULL;
 HANDLE UserServerHeap = NULL;   // Our own heap.
 
 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
 HANDLE UserServerHeap = NULL;   // Our own heap.
 
 // Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
-PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber] =
+PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
 {
     SrvExitWindowsEx,
     // SrvEndTask,
 {
     SrvExitWindowsEx,
     // SrvEndTask,
@@ -39,7 +39,7 @@ PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber] =
     // SrvGetSetShutdownBlockReason,   // Added in Vista
 };
 
     // SrvGetSetShutdownBlockReason,   // Added in Vista
 };
 
-BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber] =
+BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
 {
     FALSE,   // SrvExitWindowsEx
     // FALSE,   // SrvEndTask
 {
     FALSE,   // SrvExitWindowsEx
     // FALSE,   // SrvEndTask
@@ -56,7 +56,7 @@ BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber] =
     // FALSE,   // SrvGetSetShutdownBlockReason
 };
 
     // FALSE,   // SrvGetSetShutdownBlockReason
 };
 
-PCHAR UserServerApiNameTable[UserpMaxApiNumber] =
+PCHAR UserServerApiNameTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
 {
     "SrvExitWindowsEx",
     // "SrvEndTask",
 {
     "SrvExitWindowsEx",
     // "SrvEndTask",