- 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
This commit is contained in:
Hermès Bélusca-Maïto 2012-12-04 23:01:54 +00:00
parent 24087a3b01
commit 2599e85e27
4 changed files with 57 additions and 53 deletions

View file

@ -21,7 +21,8 @@
#include "csrmsg.h" #include "csrmsg.h"
/* TYPES **********************************************************************/
/* STRUCTURES *****************************************************************/
// Used in ntdll/csr/connect.c // Used in ntdll/csr/connect.c
#define CSR_CSRSS_SECTION_SIZE 65536 #define CSR_CSRSS_SECTION_SIZE 65536
@ -102,7 +103,7 @@ typedef enum _CSR_PROCESS_FLAGS
typedef enum _CSR_THREAD_FLAGS typedef enum _CSR_THREAD_FLAGS
{ {
CsrThreadAltertable = 0x1, CsrThreadAlertable = 0x1,
CsrThreadInTermination = 0x2, CsrThreadInTermination = 0x2,
CsrThreadTerminated = 0x4, CsrThreadTerminated = 0x4,
CsrThreadIsServerThread = 0x10 CsrThreadIsServerThread = 0x10
@ -127,6 +128,16 @@ typedef enum _CSR_DEBUG_FLAGS
CsrDebugProcessChildren = 2 CsrDebugProcessChildren = 2
} CSR_PROCESS_DEBUG_FLAGS, *PCSR_PROCESS_DEBUG_FLAGS; } 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 * Wait block
@ -162,13 +173,12 @@ typedef
NTSTATUS NTSTATUS
(NTAPI *PCSR_API_ROUTINE)( (NTAPI *PCSR_API_ROUTINE)(
IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_API_MESSAGE ApiMessage,
OUT PULONG Reply IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL
); );
#define CSR_API(n) \ #define CSR_API(n) \
NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \ NTSTATUS NTAPI n(IN OUT PCSR_API_MESSAGE ApiMessage, \
OUT PULONG Reply) IN OUT PCSR_REPLY_CODE ReplyCode OPTIONAL)
// IN OUT PCSR_REPLY_STATUS ReplyStatus)
typedef typedef
NTSTATUS NTSTATUS
@ -228,8 +238,6 @@ typedef struct _CSR_SERVER_DLL
} CSR_SERVER_DLL, *PCSR_SERVER_DLL; } CSR_SERVER_DLL, *PCSR_SERVER_DLL;
/* FUNCTION TYPES *************************************************************/
typedef typedef
NTSTATUS NTSTATUS
(NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll); (NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll);

View file

@ -94,6 +94,10 @@ CSR_API(BaseSrvCreateProcess)
if (Status == STATUS_THREAD_IS_TERMINATING) if (Status == STATUS_THREAD_IS_TERMINATING)
{ {
DPRINT1("Thread already dead\n"); DPRINT1("Thread already dead\n");
/* Set the special reply value so we don't reply this message back */
*ReplyCode = CsrReplyDeadClient;
return Status; return Status;
} }
@ -189,7 +193,7 @@ CSR_API(BaseSrvExitProcess)
ASSERT(CsrThread != NULL); ASSERT(CsrThread != NULL);
/* Set the special reply value so we don't reply this message back */ /* Set the special reply value so we don't reply this message back */
*Reply = 2; *ReplyCode = CsrReplyDeadClient;
/* Remove the CSR_THREADs and CSR_PROCESS */ /* Remove the CSR_THREADs and CSR_PROCESS */
return CsrDestroyProcess(&CsrThread->ClientId, return CsrDestroyProcess(&CsrThread->ClientId,

View file

@ -52,8 +52,7 @@ CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg,
ULONG ServerId; ULONG ServerId;
PCSR_SERVER_DLL ServerDll; PCSR_SERVER_DLL ServerDll;
ULONG ApiId; ULONG ApiId;
ULONG Reply; CSR_REPLY_CODE ReplyCode = CsrReplyImmediately;
NTSTATUS Status;
/* Get the Server ID */ /* Get the Server ID */
ServerId = CSR_API_NUMBER_TO_SERVER_ID(ReceiveMsg->ApiNumber); ServerId = CSR_API_NUMBER_TO_SERVER_ID(ReceiveMsg->ApiNumber);
@ -97,12 +96,8 @@ CsrCallServerFromServer(IN PCSR_API_MESSAGE ReceiveMsg,
/* Validation complete, start SEH */ /* Validation complete, start SEH */
_SEH2_TRY _SEH2_TRY
{ {
/* Call the API and get the result */ /* Call the API, get the reply code and return the result */
/// CsrApiCallHandler(ReplyMsg, /*ProcessData*/ &ReplyCode); /// ReplyMsg->Status = ServerDll->DispatchTable[ApiId](ReceiveMsg, &ReplyCode);
Status = (ServerDll->DispatchTable[ApiId])(ReceiveMsg, &Reply);
/* Return the result, no matter what it is */
ReplyMsg->Status = Status;
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -350,6 +345,7 @@ CsrApiRequestThread(IN PVOID Parameter)
LARGE_INTEGER TimeOut; LARGE_INTEGER TimeOut;
PCSR_THREAD CurrentThread, CsrThread; PCSR_THREAD CurrentThread, CsrThread;
NTSTATUS Status; NTSTATUS Status;
CSR_REPLY_CODE ReplyCode;
PCSR_API_MESSAGE ReplyMsg; PCSR_API_MESSAGE ReplyMsg;
CSR_API_MESSAGE ReceiveMsg; CSR_API_MESSAGE ReceiveMsg;
PCSR_PROCESS CsrProcess; PCSR_PROCESS CsrProcess;
@ -358,7 +354,7 @@ CsrApiRequestThread(IN PVOID Parameter)
PCSR_SERVER_DLL ServerDll; PCSR_SERVER_DLL ServerDll;
PCLIENT_DIED_MSG ClientDiedMsg; PCLIENT_DIED_MSG ClientDiedMsg;
PDBGKM_MSG DebugMessage; PDBGKM_MSG DebugMessage;
ULONG ServerId, ApiId, Reply, MessageType, i; ULONG ServerId, ApiId, MessageType, i;
HANDLE ReplyPort; HANDLE ReplyPort;
/* Setup LPC loop port and message */ /* Setup LPC loop port and message */
@ -453,8 +449,9 @@ CsrApiRequestThread(IN PVOID Parameter)
{ {
/* Handle the Connection Request */ /* Handle the Connection Request */
CsrApiHandleConnectionRequest(&ReceiveMsg); CsrApiHandleConnectionRequest(&ReceiveMsg);
ReplyPort = CsrApiPort;
ReplyMsg = NULL; ReplyMsg = NULL;
ReplyPort = CsrApiPort;
continue; continue;
} }
@ -550,8 +547,9 @@ CsrApiRequestThread(IN PVOID Parameter)
DPRINT1("CSRSS: %lx is invalid ServerDllIndex (%08x)\n", DPRINT1("CSRSS: %lx is invalid ServerDllIndex (%08x)\n",
ServerId, ServerDll); ServerId, ServerDll);
DbgBreakPoint(); DbgBreakPoint();
ReplyPort = CsrApiPort;
ReplyMsg = NULL; ReplyMsg = NULL;
ReplyPort = CsrApiPort;
continue; continue;
} }
@ -565,6 +563,7 @@ CsrApiRequestThread(IN PVOID Parameter)
DPRINT1("CSRSS: %lx is invalid ApiTableIndex for %Z\n", DPRINT1("CSRSS: %lx is invalid ApiTableIndex for %Z\n",
CSR_API_NUMBER_TO_API_ID(ReceiveMsg.ApiNumber), CSR_API_NUMBER_TO_API_ID(ReceiveMsg.ApiNumber),
&ServerDll->Name); &ServerDll->Name);
ReplyPort = CsrApiPort; ReplyPort = CsrApiPort;
ReplyMsg = NULL; ReplyMsg = NULL;
continue; continue;
@ -589,10 +588,10 @@ CsrApiRequestThread(IN PVOID Parameter)
/* Make sure we have enough threads */ /* Make sure we have enough threads */
CsrpCheckRequestThreads(); CsrpCheckRequestThreads();
/* Call the API and get the result */ /* Call the API and get the reply code */
ReplyMsg = NULL; ReplyMsg = NULL;
ReplyPort = CsrApiPort; ReplyPort = CsrApiPort;
ServerDll->DispatchTable[ApiId](&ReceiveMsg, &Reply); ServerDll->DispatchTable[ApiId](&ReceiveMsg, &ReplyCode);
/* Increase the static thread count */ /* Increase the static thread count */
_InterlockedIncrement(&CsrpStaticThreadCount); _InterlockedIncrement(&CsrpStaticThreadCount);
@ -644,6 +643,7 @@ CsrApiRequestThread(IN PVOID Parameter)
/* Release the lock and keep looping */ /* Release the lock and keep looping */
CsrReleaseProcessLock(); CsrReleaseProcessLock();
ReplyMsg = NULL; ReplyMsg = NULL;
ReplyPort = CsrApiPort; ReplyPort = CsrApiPort;
continue; continue;
@ -807,36 +807,40 @@ CsrApiRequestThread(IN PVOID Parameter)
Teb->CsrClientThread = CsrThread; Teb->CsrClientThread = CsrThread;
/* Call the API and get the result */ /* Call the API, get the reply code and return the result */
Reply = 0; ReplyCode = CsrReplyImmediately;
ServerDll->DispatchTable[ApiId](&ReceiveMsg, &Reply); ReplyMsg->Status = ServerDll->DispatchTable[ApiId](&ReceiveMsg, &ReplyCode);
/* Increase the static thread count */ /* Increase the static thread count */
_InterlockedIncrement(&CsrpStaticThreadCount); _InterlockedIncrement(&CsrpStaticThreadCount);
Teb->CsrClientThread = CurrentThread; Teb->CsrClientThread = CurrentThread;
if (Reply == 3) if (ReplyCode == CsrReplyAlreadyDone)
{ {
ReplyMsg = NULL;
if (ReceiveMsg.CsrCaptureData) if (ReceiveMsg.CsrCaptureData)
{ {
CsrReleaseCapturedArguments(&ReceiveMsg); CsrReleaseCapturedArguments(&ReceiveMsg);
} }
CsrDereferenceThread(CsrThread); ReplyMsg = NULL;
ReplyPort = CsrApiPort; ReplyPort = CsrApiPort;
CsrDereferenceThread(CsrThread);
} }
else if (Reply == 2) else if (ReplyCode == CsrReplyDeadClient)
{ {
/* Reply to the death message */
NtReplyPort(ReplyPort, &ReplyMsg->Header); NtReplyPort(ReplyPort, &ReplyMsg->Header);
ReplyPort = CsrApiPort;
/* Reply back to the API port now */
ReplyMsg = NULL; ReplyMsg = NULL;
ReplyPort = CsrApiPort;
CsrDereferenceThread(CsrThread); CsrDereferenceThread(CsrThread);
} }
else if (Reply == 1) else if (ReplyCode == CsrReplyPending)
{ {
ReplyPort = CsrApiPort;
ReplyMsg = NULL; ReplyMsg = NULL;
ReplyPort = CsrApiPort;
} }
else else
{ {

View file

@ -253,7 +253,7 @@ LoadFailed:
* @param ApiMessage * @param ApiMessage
* Pointer to the CSR API Message for this request. * Pointer to the CSR API Message for this request.
* *
* @param Reply * @param ReplyCode
* Optional reply to this request. * Optional reply to this request.
* *
* @return STATUS_SUCCESS in case of success, STATUS_INVALID_PARAMETER * @return STATUS_SUCCESS in case of success, STATUS_INVALID_PARAMETER
@ -262,10 +262,7 @@ LoadFailed:
* @remarks None. * @remarks None.
* *
*--*/ *--*/
NTSTATUS CSR_API(CsrSrvClientConnect)
NTAPI
CsrSrvClientConnect(IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply OPTIONAL)
{ {
NTSTATUS Status; NTSTATUS Status;
PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage->Data.CsrClientConnect; PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage->Data.CsrClientConnect;
@ -273,7 +270,7 @@ CsrSrvClientConnect(IN OUT PCSR_API_MESSAGE ApiMessage,
PCSR_PROCESS CurrentProcess = CsrGetClientThread()->Process; PCSR_PROCESS CurrentProcess = CsrGetClientThread()->Process;
/* Set default reply */ /* Set default reply */
*Reply = 0; *ReplyCode = CsrReplyImmediately;
/* Validate the ServerID */ /* Validate the ServerID */
if (ClientConnect->ServerId >= CSR_SERVER_DLL_MAX) if (ClientConnect->ServerId >= CSR_SERVER_DLL_MAX)
@ -498,7 +495,7 @@ CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
* @param ApiMessage * @param ApiMessage
* Pointer to the CSR API Message for this request. * Pointer to the CSR API Message for this request.
* *
* @param Reply * @param ReplyCode
* Pointer to an optional reply to this request. * Pointer to an optional reply to this request.
* *
* @return STATUS_SUCCESS. * @return STATUS_SUCCESS.
@ -506,15 +503,12 @@ CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
* @remarks None. * @remarks None.
* *
*--*/ *--*/
NTSTATUS CSR_API(CsrSrvIdentifyAlertableThread)
NTAPI
CsrSrvIdentifyAlertableThread(IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply)
{ {
PCSR_THREAD CsrThread = CsrGetClientThread(); PCSR_THREAD CsrThread = CsrGetClientThread();
/* Set the alertable flag */ /* Set the alertable flag */
CsrThread->Flags |= CsrThreadAltertable; CsrThread->Flags |= CsrThreadAlertable;
/* Return success */ /* Return success */
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -529,7 +523,7 @@ CsrSrvIdentifyAlertableThread(IN OUT PCSR_API_MESSAGE ApiMessage,
* @param ApiMessage * @param ApiMessage
* Pointer to the CSR API Message for this request. * Pointer to the CSR API Message for this request.
* *
* @param Reply * @param ReplyCode
* Pointer to an optional reply to this request. * Pointer to an optional reply to this request.
* *
* @return STATUS_SUCCESS. * @return STATUS_SUCCESS.
@ -537,10 +531,7 @@ CsrSrvIdentifyAlertableThread(IN OUT PCSR_API_MESSAGE ApiMessage,
* @remarks None. * @remarks None.
* *
*--*/ *--*/
NTSTATUS CSR_API(CsrSrvSetPriorityClass)
NTAPI
CsrSrvSetPriorityClass(IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply)
{ {
/* Deprecated */ /* Deprecated */
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -557,7 +548,7 @@ CsrSrvSetPriorityClass(IN OUT PCSR_API_MESSAGE ApiMessage,
* @param ApiMessage * @param ApiMessage
* Pointer to the CSR API Message for this request. * Pointer to the CSR API Message for this request.
* *
* @param Reply * @param ReplyCode
* Pointer to an optional reply to this request. * Pointer to an optional reply to this request.
* *
* @return STATUS_INVALID_PARAMETER. * @return STATUS_INVALID_PARAMETER.
@ -566,10 +557,7 @@ CsrSrvSetPriorityClass(IN OUT PCSR_API_MESSAGE ApiMessage,
* return success. * return success.
* *
*--*/ *--*/
NTSTATUS CSR_API(CsrSrvUnusedFunction)
NTAPI
CsrSrvUnusedFunction(IN OUT PCSR_API_MESSAGE ApiMessage,
IN OUT PULONG Reply)
{ {
/* Deprecated */ /* Deprecated */
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;