#include "csrmsg.h"
-/* TYPES **********************************************************************/
+
+/* STRUCTURES *****************************************************************/
// Used in ntdll/csr/connect.c
#define CSR_CSRSS_SECTION_SIZE 65536
typedef enum _CSR_THREAD_FLAGS
{
- CsrThreadAltertable = 0x1,
+ CsrThreadAlertable = 0x1,
CsrThreadInTermination = 0x2,
CsrThreadTerminated = 0x4,
CsrThreadIsServerThread = 0x10
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
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
} CSR_SERVER_DLL, *PCSR_SERVER_DLL;
-/* FUNCTION TYPES *************************************************************/
-
typedef
NTSTATUS
(NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL LoadedServerDll);
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);
/* 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)
{
LARGE_INTEGER TimeOut;
PCSR_THREAD CurrentThread, CsrThread;
NTSTATUS Status;
+ CSR_REPLY_CODE ReplyCode;
PCSR_API_MESSAGE ReplyMsg;
CSR_API_MESSAGE ReceiveMsg;
PCSR_PROCESS CsrProcess;
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 */
{
/* Handle the Connection Request */
CsrApiHandleConnectionRequest(&ReceiveMsg);
- ReplyPort = CsrApiPort;
+
ReplyMsg = NULL;
+ ReplyPort = CsrApiPort;
continue;
}
DPRINT1("CSRSS: %lx is invalid ServerDllIndex (%08x)\n",
ServerId, ServerDll);
DbgBreakPoint();
- ReplyPort = CsrApiPort;
+
ReplyMsg = NULL;
+ ReplyPort = CsrApiPort;
continue;
}
DPRINT1("CSRSS: %lx is invalid ApiTableIndex for %Z\n",
CSR_API_NUMBER_TO_API_ID(ReceiveMsg.ApiNumber),
&ServerDll->Name);
+
ReplyPort = CsrApiPort;
ReplyMsg = NULL;
continue;
/* 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);
/* Release the lock and keep looping */
CsrReleaseProcessLock();
+
ReplyMsg = NULL;
ReplyPort = CsrApiPort;
continue;
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
{
* @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
* @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;
PCSR_PROCESS CurrentProcess = CsrGetClientThread()->Process;
/* Set default reply */
- *Reply = 0;
+ *ReplyCode = CsrReplyImmediately;
/* Validate the ServerID */
if (ClientConnect->ServerId >= CSR_SERVER_DLL_MAX)
* @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.
* @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;
* @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.
* @remarks None.
*
*--*/
-NTSTATUS
-NTAPI
-CsrSrvSetPriorityClass(IN OUT PCSR_API_MESSAGE ApiMessage,
- IN OUT PULONG Reply)
+CSR_API(CsrSrvSetPriorityClass)
{
/* Deprecated */
return STATUS_SUCCESS;
* @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.
* return success.
*
*--*/
-NTSTATUS
-NTAPI
-CsrSrvUnusedFunction(IN OUT PCSR_API_MESSAGE ApiMessage,
- IN OUT PULONG Reply)
+CSR_API(CsrSrvUnusedFunction)
{
/* Deprecated */
return STATUS_INVALID_PARAMETER;