Author: hbelusca Date: Tue Dec 4 23:01:54 2012 New Revision: 57801
URL: http://svn.reactos.org/svn/reactos?rev=57801&view=rev Log: [CSRSRV] - Correct a misspelling 'CsrThreadAltertable' -> 'CsrThreadAlertable'. - Introduce CSR_REPLY_CODEs instead of using hardcoded values, and use them with CSR_API_ROUTINE-type functions. They correspond to which decision CSRSRV should take after a server function is called: answer to the client or not, and perform according tasks.
[BASESRV] Use CSR_REPLY_CODEs.
Modified: branches/ros-csrss/include/reactos/subsys/csr/csrsrv.h branches/ros-csrss/subsystems/win/basesrv/server.c branches/ros-csrss/subsystems/win32/csrsrv/api.c branches/ros-csrss/subsystems/win32/csrsrv/server.c
Modified: branches/ros-csrss/include/reactos/subsys/csr/csrsrv.h URL: http://svn.reactos.org/svn/reactos/branches/ros-csrss/include/reactos/subsys... ============================================================================== --- branches/ros-csrss/include/reactos/subsys/csr/csrsrv.h [iso-8859-1] (original) +++ branches/ros-csrss/include/reactos/subsys/csr/csrsrv.h [iso-8859-1] Tue Dec 4 23:01:54 2012 @@ -21,7 +21,8 @@
#include "csrmsg.h"
-/* TYPES **********************************************************************/ + +/* STRUCTURES *****************************************************************/
// Used in ntdll/csr/connect.c #define CSR_CSRSS_SECTION_SIZE 65536 @@ -102,7 +103,7 @@
typedef enum _CSR_THREAD_FLAGS { - CsrThreadAltertable = 0x1, + CsrThreadAlertable = 0x1, CsrThreadInTermination = 0x2, CsrThreadTerminated = 0x4, CsrThreadIsServerThread = 0x10 @@ -127,6 +128,16 @@ CsrDebugProcessChildren = 2 } CSR_PROCESS_DEBUG_FLAGS, *PCSR_PROCESS_DEBUG_FLAGS;
+typedef enum _CSR_REPLY_CODE +{ + CsrReplyImmediately = 0, + CsrReplyPending = 1, + CsrReplyDeadClient = 2, + CsrReplyAlreadyDone = 3 +} CSR_REPLY_CODE, *PCSR_REPLY_CODE; + + +/* FUNCTION TYPES AND STRUCTURES **********************************************/
/* * Wait block @@ -162,13 +173,12 @@ NTSTATUS (NTAPI *PCSR_API_ROUTINE)( IN OUT PCSR_API_MESSAGE ApiMessage, - OUT PULONG Reply + IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL );
#define CSR_API(n) \ NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \ - OUT PULONG Reply) - // IN OUT PCSR_REPLY_STATUS ReplyStatus) + IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
typedef NTSTATUS @@ -228,8 +238,6 @@ } CSR_SERVER_DLL, *PCSR_SERVER_DLL;
-/* FUNCTION TYPES *************************************************************/ - typedef NTSTATUS (NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll);
Modified: branches/ros-csrss/subsystems/win/basesrv/server.c URL: http://svn.reactos.org/svn/reactos/branches/ros-csrss/subsystems/win/basesrv... ============================================================================== --- branches/ros-csrss/subsystems/win/basesrv/server.c [iso-8859-1] (original) +++ branches/ros-csrss/subsystems/win/basesrv/server.c [iso-8859-1] Tue Dec 4 23:01:54 2012 @@ -94,6 +94,10 @@ if (Status == STATUS_THREAD_IS_TERMINATING) { DPRINT1("Thread already dead\n"); + + /* Set the special reply value so we don't reply this message back */ + *ReplyCode = CsrReplyDeadClient; + return Status; }
@@ -189,7 +193,7 @@ ASSERT(CsrThread != NULL);
/* Set the special reply value so we don't reply this message back */ - *Reply = 2; + *ReplyCode = CsrReplyDeadClient;
/* Remove the CSR_THREADs and CSR_PROCESS */ return CsrDestroyProcess(&CsrThread->ClientId,
Modified: branches/ros-csrss/subsystems/win32/csrsrv/api.c URL: http://svn.reactos.org/svn/reactos/branches/ros-csrss/subsystems/win32/csrsr... ============================================================================== --- branches/ros-csrss/subsystems/win32/csrsrv/api.c [iso-8859-1] (original) +++ branches/ros-csrss/subsystems/win32/csrsrv/api.c [iso-8859-1] Tue Dec 4 23:01:54 2012 @@ -52,8 +52,7 @@ ULONG ServerId; PCSR_SERVER_DLL ServerDll; ULONG ApiId; - ULONG Reply; - NTSTATUS Status; + CSR_REPLY_CODE ReplyCode = CsrReplyImmediately;
/* Get the Server ID */ ServerId = CSR_API_NUMBER_TO_SERVER_ID(ReceiveMsg->ApiNumber); @@ -97,12 +96,8 @@ /* Validation complete, start SEH */ _SEH2_TRY { - /* Call the API and get the result */ - /// CsrApiCallHandler(ReplyMsg, /*ProcessData*/ &ReplyCode); /// - Status = (ServerDll->DispatchTable[ApiId])(ReceiveMsg, &Reply); - - /* Return the result, no matter what it is */ - ReplyMsg->Status = Status; + /* Call the API, get the reply code and return the result */ + ReplyMsg->Status = ServerDll->DispatchTable[ApiId](ReceiveMsg, &ReplyCode); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -350,6 +345,7 @@ LARGE_INTEGER TimeOut; PCSR_THREAD CurrentThread, CsrThread; NTSTATUS Status; + CSR_REPLY_CODE ReplyCode; PCSR_API_MESSAGE ReplyMsg; CSR_API_MESSAGE ReceiveMsg; PCSR_PROCESS CsrProcess; @@ -358,7 +354,7 @@ PCSR_SERVER_DLL ServerDll; PCLIENT_DIED_MSG ClientDiedMsg; PDBGKM_MSG DebugMessage; - ULONG ServerId, ApiId, Reply, MessageType, i; + ULONG ServerId, ApiId, MessageType, i; HANDLE ReplyPort;
/* Setup LPC loop port and message */ @@ -453,8 +449,9 @@ { /* Handle the Connection Request */ CsrApiHandleConnectionRequest(&ReceiveMsg); + + ReplyMsg = NULL; ReplyPort = CsrApiPort; - ReplyMsg = NULL; continue; }
@@ -550,8 +547,9 @@ DPRINT1("CSRSS: %lx is invalid ServerDllIndex (%08x)\n", ServerId, ServerDll); DbgBreakPoint(); + + ReplyMsg = NULL; ReplyPort = CsrApiPort; - ReplyMsg = NULL; continue; }
@@ -565,6 +563,7 @@ DPRINT1("CSRSS: %lx is invalid ApiTableIndex for %Z\n", CSR_API_NUMBER_TO_API_ID(ReceiveMsg.ApiNumber), &ServerDll->Name); + ReplyPort = CsrApiPort; ReplyMsg = NULL; continue; @@ -589,10 +588,10 @@ /* Make sure we have enough threads */ CsrpCheckRequestThreads();
- /* Call the API and get the result */ + /* Call the API and get the reply code */ ReplyMsg = NULL; ReplyPort = CsrApiPort; - ServerDll->DispatchTable[ApiId](&ReceiveMsg, &Reply); + ServerDll->DispatchTable[ApiId](&ReceiveMsg, &ReplyCode);
/* Increase the static thread count */ _InterlockedIncrement(&CsrpStaticThreadCount); @@ -644,6 +643,7 @@
/* Release the lock and keep looping */ CsrReleaseProcessLock(); + ReplyMsg = NULL; ReplyPort = CsrApiPort; continue; @@ -807,36 +807,40 @@
Teb->CsrClientThread = CsrThread;
- /* Call the API and get the result */ - Reply = 0; - ServerDll->DispatchTable[ApiId](&ReceiveMsg, &Reply); + /* Call the API, get the reply code and return the result */ + ReplyCode = CsrReplyImmediately; + ReplyMsg->Status = ServerDll->DispatchTable[ApiId](&ReceiveMsg, &ReplyCode);
/* Increase the static thread count */ _InterlockedIncrement(&CsrpStaticThreadCount);
Teb->CsrClientThread = CurrentThread;
- if (Reply == 3) - { + if (ReplyCode == CsrReplyAlreadyDone) + { + if (ReceiveMsg.CsrCaptureData) + { + CsrReleaseCapturedArguments(&ReceiveMsg); + } ReplyMsg = NULL; - if (ReceiveMsg.CsrCaptureData) - { - CsrReleaseCapturedArguments(&ReceiveMsg); - } + ReplyPort = CsrApiPort; CsrDereferenceThread(CsrThread); + } + else if (ReplyCode == CsrReplyDeadClient) + { + /* Reply to the death message */ + NtReplyPort(ReplyPort, &ReplyMsg->Header); + + /* Reply back to the API port now */ + ReplyMsg = NULL; ReplyPort = CsrApiPort; - } - else if (Reply == 2) - { - NtReplyPort(ReplyPort, &ReplyMsg->Header); + + CsrDereferenceThread(CsrThread); + } + else if (ReplyCode == CsrReplyPending) + { + ReplyMsg = NULL; ReplyPort = CsrApiPort; - ReplyMsg = NULL; - CsrDereferenceThread(CsrThread); - } - else if (Reply == 1) - { - ReplyPort = CsrApiPort; - ReplyMsg = NULL; } else {
Modified: branches/ros-csrss/subsystems/win32/csrsrv/server.c URL: http://svn.reactos.org/svn/reactos/branches/ros-csrss/subsystems/win32/csrsr... ============================================================================== --- branches/ros-csrss/subsystems/win32/csrsrv/server.c [iso-8859-1] (original) +++ branches/ros-csrss/subsystems/win32/csrsrv/server.c [iso-8859-1] Tue Dec 4 23:01:54 2012 @@ -253,7 +253,7 @@ * @param ApiMessage * Pointer to the CSR API Message for this request. * - * @param Reply + * @param ReplyCode * Optional reply to this request. * * @return STATUS_SUCCESS in case of success, STATUS_INVALID_PARAMETER @@ -262,10 +262,7 @@ * @remarks None. * *--*/ -NTSTATUS -NTAPI -CsrSrvClientConnect(IN OUT PCSR_API_MESSAGE ApiMessage, - IN OUT PULONG Reply OPTIONAL) +CSR_API(CsrSrvClientConnect) { NTSTATUS Status; PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage->Data.CsrClientConnect; @@ -273,7 +270,7 @@ PCSR_PROCESS CurrentProcess = CsrGetClientThread()->Process;
/* Set default reply */ - *Reply = 0; + *ReplyCode = CsrReplyImmediately;
/* Validate the ServerID */ if (ClientConnect->ServerId >= CSR_SERVER_DLL_MAX) @@ -498,7 +495,7 @@ * @param ApiMessage * Pointer to the CSR API Message for this request. * - * @param Reply + * @param ReplyCode * Pointer to an optional reply to this request. * * @return STATUS_SUCCESS. @@ -506,15 +503,12 @@ * @remarks None. * *--*/ -NTSTATUS -NTAPI -CsrSrvIdentifyAlertableThread(IN OUT PCSR_API_MESSAGE ApiMessage, - IN OUT PULONG Reply) +CSR_API(CsrSrvIdentifyAlertableThread) { PCSR_THREAD CsrThread = CsrGetClientThread();
/* Set the alertable flag */ - CsrThread->Flags |= CsrThreadAltertable; + CsrThread->Flags |= CsrThreadAlertable;
/* Return success */ return STATUS_SUCCESS; @@ -529,7 +523,7 @@ * @param ApiMessage * Pointer to the CSR API Message for this request. * - * @param Reply + * @param ReplyCode * Pointer to an optional reply to this request. * * @return STATUS_SUCCESS. @@ -537,10 +531,7 @@ * @remarks None. * *--*/ -NTSTATUS -NTAPI -CsrSrvSetPriorityClass(IN OUT PCSR_API_MESSAGE ApiMessage, - IN OUT PULONG Reply) +CSR_API(CsrSrvSetPriorityClass) { /* Deprecated */ return STATUS_SUCCESS; @@ -557,7 +548,7 @@ * @param ApiMessage * Pointer to the CSR API Message for this request. * - * @param Reply + * @param ReplyCode * Pointer to an optional reply to this request. * * @return STATUS_INVALID_PARAMETER. @@ -566,10 +557,7 @@ * return success. * *--*/ -NTSTATUS -NTAPI -CsrSrvUnusedFunction(IN OUT PCSR_API_MESSAGE ApiMessage, - IN OUT PULONG Reply) +CSR_API(CsrSrvUnusedFunction) { /* Deprecated */ return STATUS_INVALID_PARAMETER;