From: Hermès Bélusca-Maïto Date: Tue, 4 Dec 2012 23:01:54 +0000 (+0000) Subject: [CSRSRV] X-Git-Tag: backups/ros-csrss@60644~117 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=2599e85e27c48bb36fca5eb7700b2a55ea27f57c [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. svn path=/branches/ros-csrss/; revision=57801 --- diff --git a/include/reactos/subsys/csr/csrsrv.h b/include/reactos/subsys/csr/csrsrv.h index ae0db7d149d..87337ca4ca4 100644 --- a/include/reactos/subsys/csr/csrsrv.h +++ b/include/reactos/subsys/csr/csrsrv.h @@ -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_PROCESS_FLAGS typedef enum _CSR_THREAD_FLAGS { - CsrThreadAltertable = 0x1, + CsrThreadAlertable = 0x1, CsrThreadInTermination = 0x2, CsrThreadTerminated = 0x4, CsrThreadIsServerThread = 0x10 @@ -127,6 +128,16 @@ typedef enum _CSR_DEBUG_FLAGS 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 @@ typedef 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 @@ typedef struct _CSR_SERVER_DLL } CSR_SERVER_DLL, *PCSR_SERVER_DLL; -/* FUNCTION TYPES *************************************************************/ - typedef NTSTATUS (NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll); diff --git a/subsystems/win/basesrv/server.c b/subsystems/win/basesrv/server.c index ec567b02330..f30ca3bc2d0 100644 --- a/subsystems/win/basesrv/server.c +++ b/subsystems/win/basesrv/server.c @@ -94,6 +94,10 @@ CSR_API(BaseSrvCreateProcess) 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 @@ CSR_API(BaseSrvExitProcess) 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, diff --git a/subsystems/win32/csrsrv/api.c b/subsystems/win32/csrsrv/api.c index 94464004e25..d2030139054 100644 --- a/subsystems/win32/csrsrv/api.c +++ b/subsystems/win32/csrsrv/api.c @@ -52,8 +52,7 @@ CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg, 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 @@ CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg, /* 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 @@ CsrApiRequestThread(IN PVOID Parameter) 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 @@ CsrApiRequestThread(IN PVOID Parameter) 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 @@ CsrApiRequestThread(IN PVOID Parameter) { /* Handle the Connection Request */ CsrApiHandleConnectionRequest(&ReceiveMsg); - ReplyPort = CsrApiPort; + ReplyMsg = NULL; + ReplyPort = CsrApiPort; continue; } @@ -550,8 +547,9 @@ CsrApiRequestThread(IN PVOID Parameter) DPRINT1("CSRSS: %lx is invalid ServerDllIndex (%08x)\n", ServerId, ServerDll); DbgBreakPoint(); - ReplyPort = CsrApiPort; + ReplyMsg = NULL; + ReplyPort = CsrApiPort; continue; } @@ -565,6 +563,7 @@ CsrApiRequestThread(IN PVOID Parameter) 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 @@ CsrApiRequestThread(IN PVOID Parameter) /* 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 @@ CsrApiRequestThread(IN PVOID Parameter) /* Release the lock and keep looping */ CsrReleaseProcessLock(); + ReplyMsg = NULL; ReplyPort = CsrApiPort; continue; @@ -807,36 +807,40 @@ CsrApiRequestThread(IN PVOID Parameter) 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) { - ReplyMsg = NULL; if (ReceiveMsg.CsrCaptureData) { CsrReleaseCapturedArguments(&ReceiveMsg); } - CsrDereferenceThread(CsrThread); + ReplyMsg = NULL; ReplyPort = CsrApiPort; + CsrDereferenceThread(CsrThread); } - else if (Reply == 2) + else if (ReplyCode == CsrReplyDeadClient) { + /* Reply to the death message */ NtReplyPort(ReplyPort, &ReplyMsg->Header); - ReplyPort = CsrApiPort; + + /* Reply back to the API port now */ ReplyMsg = NULL; + ReplyPort = CsrApiPort; + CsrDereferenceThread(CsrThread); } - else if (Reply == 1) + else if (ReplyCode == CsrReplyPending) { - ReplyPort = CsrApiPort; ReplyMsg = NULL; + ReplyPort = CsrApiPort; } else { diff --git a/subsystems/win32/csrsrv/server.c b/subsystems/win32/csrsrv/server.c index 9f176dbeb1e..c20ec56e091 100644 --- a/subsystems/win32/csrsrv/server.c +++ b/subsystems/win32/csrsrv/server.c @@ -253,7 +253,7 @@ LoadFailed: * @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 @@ LoadFailed: * @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 @@ CsrSrvClientConnect(IN OUT PCSR_API_MESSAGE ApiMessage, 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 @@ CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL, * @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 @@ CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL, * @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 @@ CsrSrvIdentifyAlertableThread(IN OUT PCSR_API_MESSAGE ApiMessage, * @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 @@ CsrSrvIdentifyAlertableThread(IN OUT PCSR_API_MESSAGE ApiMessage, * @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 @@ CsrSrvSetPriorityClass(IN OUT PCSR_API_MESSAGE ApiMessage, * @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 @@ CsrSrvSetPriorityClass(IN OUT PCSR_API_MESSAGE ApiMessage, * return success. * *--*/ -NTSTATUS -NTAPI -CsrSrvUnusedFunction(IN OUT PCSR_API_MESSAGE ApiMessage, - IN OUT PULONG Reply) +CSR_API(CsrSrvUnusedFunction) { /* Deprecated */ return STATUS_INVALID_PARAMETER;