forget update de.rc
[reactos.git] / reactos / ntoskrnl / lpc / reply.c
index b3c7af8..e67db08 100644 (file)
  */
 NTSTATUS STDCALL
 EiReplyOrRequestPort (IN       PEPORT          Port,
-                     IN        PLPC_MESSAGE    LpcReply,
+                     IN        PPORT_MESSAGE   LpcReply,
                      IN        ULONG           MessageType,
                      IN        PEPORT          Sender)
 {
    KIRQL oldIrql;
    PQUEUEDMESSAGE MessageReply;
+   ULONG Size;
 
    if (Port == NULL)
      {
        KEBUGCHECK(0);
      }
 
-   MessageReply = ExAllocatePoolWithTag(NonPagedPool, sizeof(QUEUEDMESSAGE),
+   Size = sizeof(QUEUEDMESSAGE);
+   if (LpcReply && LpcReply->u1.s1.TotalLength > (CSHORT)sizeof(PORT_MESSAGE))
+     {
+       Size += LpcReply->u1.s1.TotalLength - sizeof(PORT_MESSAGE);
+     }
+   MessageReply = ExAllocatePoolWithTag(NonPagedPool, Size, 
                                        TAG_LPC_MESSAGE);
    MessageReply->Sender = Sender;
 
    if (LpcReply != NULL)
      {
-       memcpy(&MessageReply->Message, LpcReply, LpcReply->MessageSize);
+       memcpy(&MessageReply->Message, LpcReply, LpcReply->u1.s1.TotalLength);
+     }
+   else
+     {
+       MessageReply->Message.u1.s1.TotalLength = sizeof(PORT_MESSAGE);
+       MessageReply->Message.u1.s1.DataLength = 0;
      }
 
    MessageReply->Message.ClientId.UniqueProcess = PsGetCurrentProcessId();
    MessageReply->Message.ClientId.UniqueThread = PsGetCurrentThreadId();
-   MessageReply->Message.MessageType = MessageType;
+   MessageReply->Message.u2.s2.Type = MessageType;
    MessageReply->Message.MessageId = InterlockedIncrementUL(&LpcpNextMessageId);
 
    KeAcquireSpinLock(&Port->Lock, &oldIrql);
@@ -78,7 +89,7 @@ EiReplyOrRequestPort (IN      PEPORT          Port,
  */
 NTSTATUS STDCALL
 NtReplyPort (IN        HANDLE          PortHandle,
-            IN PLPC_MESSAGE    LpcReply)
+            IN PPORT_MESSAGE   LpcReply)
 {
    NTSTATUS Status;
    PEPORT Port;
@@ -135,11 +146,11 @@ NtReplyPort (IN   HANDLE          PortHandle,
  * REVISIONS
  */
 NTSTATUS STDCALL
-NtReplyWaitReceivePortEx(IN  HANDLE            PortHandle,
-                        OUT PULONG             PortId,
-                        IN  PLPC_MESSAGE       LpcReply,
-                        OUT PLPC_MESSAGE       LpcMessage,
-                        IN  PLARGE_INTEGER     Timeout)
+NtReplyWaitReceivePortEx(IN HANDLE PortHandle,
+                         OUT PVOID *PortContext OPTIONAL,
+                         IN PPORT_MESSAGE ReplyMessage OPTIONAL,
+                         OUT PPORT_MESSAGE ReceiveMessage,
+                                    IN PLARGE_INTEGER Timeout OPTIONAL)
 {
    PEPORT Port;
    KIRQL oldIrql;
@@ -152,14 +163,14 @@ NtReplyWaitReceivePortEx(IN  HANDLE               PortHandle,
    PreviousMode = ExGetPreviousMode();
 
    DPRINT("NtReplyWaitReceivePortEx(PortHandle %x, LpcReply %x, "
-         "LpcMessage %x)\n", PortHandle, LpcReply, LpcMessage);
+         "LpcMessage %x)\n", PortHandle, ReplyMessage, ReceiveMessage);
 
    if (PreviousMode != KernelMode)
      {
        _SEH_TRY
          {
-           ProbeForWrite(LpcMessage,
-                         sizeof(LPC_MESSAGE),
+           ProbeForWrite(ReceiveMessage,
+                         sizeof(PORT_MESSAGE),
                          1);
          }
        _SEH_HANDLE
@@ -200,10 +211,10 @@ NtReplyWaitReceivePortEx(IN  HANDLE               PortHandle,
    /*
     * Send the reply, only if port is connected
     */
-   if (LpcReply != NULL && !Disconnected)
+   if (ReplyMessage != NULL && !Disconnected)
      {
        Status = EiReplyOrRequestPort(Port->OtherPort,
-                                     LpcReply,
+                                     ReplyMessage,
                                      LPC_REPLY,
                                      Port);
        KeReleaseSemaphore(&Port->OtherPort->Semaphore, IO_NO_INCREMENT, 1,
@@ -252,28 +263,34 @@ NtReplyWaitReceivePortEx(IN  HANDLE               PortHandle,
    Request = EiDequeueMessagePort(Port);
    KeReleaseSpinLock(&Port->Lock, oldIrql);
 
-   if (Request->Message.MessageType == LPC_CONNECTION_REQUEST)
+   if (Request == NULL)
+     {
+       ObDereferenceObject(Port);
+       return STATUS_UNSUCCESSFUL;
+     }
+
+   if (Request->Message.u2.s2.Type == LPC_CONNECTION_REQUEST)
      {
-       LPC_MESSAGE Header;
+       PORT_MESSAGE Header;
        PEPORT_CONNECT_REQUEST_MESSAGE CRequest;
 
        CRequest = (PEPORT_CONNECT_REQUEST_MESSAGE)&Request->Message;
-       memcpy(&Header, &Request->Message, sizeof(LPC_MESSAGE));
-       Header.DataSize = CRequest->ConnectDataLength;
-       Header.MessageSize = Header.DataSize + sizeof(LPC_MESSAGE);
+       memcpy(&Header, &Request->Message, sizeof(PORT_MESSAGE));
+       Header.u1.s1.DataLength = CRequest->ConnectDataLength;
+       Header.u1.s1.TotalLength = Header.u1.s1.DataLength + sizeof(PORT_MESSAGE);
        
        if (PreviousMode != KernelMode)
          {
            _SEH_TRY
              {
-               ProbeForWrite((PVOID)(LpcMessage + 1),
+               ProbeForWrite((PVOID)(ReceiveMessage + 1),
                              CRequest->ConnectDataLength,
                              1);
 
-               RtlCopyMemory(LpcMessage,
+               RtlCopyMemory(ReceiveMessage,
                              &Header,
-                             sizeof(LPC_MESSAGE));
-               RtlCopyMemory((PVOID)(LpcMessage + 1),
+                             sizeof(PORT_MESSAGE));
+               RtlCopyMemory((PVOID)(ReceiveMessage + 1),
                              CRequest->ConnectData,
                              CRequest->ConnectDataLength);
              }
@@ -285,10 +302,10 @@ NtReplyWaitReceivePortEx(IN  HANDLE               PortHandle,
          }
        else
          {
-           RtlCopyMemory(LpcMessage,
+           RtlCopyMemory(ReceiveMessage,
                          &Header,
-                         sizeof(LPC_MESSAGE));
-           RtlCopyMemory((PVOID)(LpcMessage + 1),
+                         sizeof(PORT_MESSAGE));
+           RtlCopyMemory((PVOID)(ReceiveMessage + 1),
                          CRequest->ConnectData,
                          CRequest->ConnectDataLength);
          }
@@ -299,13 +316,13 @@ NtReplyWaitReceivePortEx(IN  HANDLE               PortHandle,
          {
            _SEH_TRY
              {
-               ProbeForWrite(LpcMessage,
-                             Request->Message.MessageSize,
+               ProbeForWrite(ReceiveMessage,
+                             Request->Message.u1.s1.TotalLength,
                              1);
 
-               RtlCopyMemory(LpcMessage,
+               RtlCopyMemory(ReceiveMessage,
                              &Request->Message,
-                             Request->Message.MessageSize);
+                             Request->Message.u1.s1.TotalLength);
              }
            _SEH_HANDLE
              {
@@ -315,9 +332,9 @@ NtReplyWaitReceivePortEx(IN  HANDLE         PortHandle,
          }
        else
          {
-           RtlCopyMemory(LpcMessage,
+           RtlCopyMemory(ReceiveMessage,
                          &Request->Message,
-                         Request->Message.MessageSize);
+                         Request->Message.u1.s1.TotalLength);
          }
      }
    if (!NT_SUCCESS(Status))
@@ -333,7 +350,7 @@ NtReplyWaitReceivePortEx(IN  HANDLE         PortHandle,
        ObDereferenceObject(Port);
        return(Status);
      }
-   if (Request->Message.MessageType == LPC_CONNECTION_REQUEST)
+   if (Request->Message.u2.s2.Type == LPC_CONNECTION_REQUEST)
      {
        KeAcquireSpinLock(&Port->Lock, &oldIrql);
        EiEnqueueConnectMessagePort(Port, Request);
@@ -370,16 +387,16 @@ NtReplyWaitReceivePortEx(IN  HANDLE               PortHandle,
  * REVISIONS
  */
 NTSTATUS STDCALL
-NtReplyWaitReceivePort (IN  HANDLE             PortHandle,
-                       OUT PULONG              PortId,
-                       IN  PLPC_MESSAGE        LpcReply,
-                       OUT PLPC_MESSAGE        LpcMessage)
+NtReplyWaitReceivePort(IN HANDLE PortHandle,
+                       OUT PVOID *PortContext OPTIONAL,
+                       IN PPORT_MESSAGE ReplyMessage OPTIONAL,
+                       OUT PPORT_MESSAGE ReceiveMessage)
 {
-  return(NtReplyWaitReceivePortEx (PortHandle,
-                                  PortId,
-                                  LpcReply,
-                                  LpcMessage,
-                                  NULL));
+    return NtReplyWaitReceivePortEx(PortHandle,
+                                                   PortContext,
+                                                   ReplyMessage,
+                                                   ReceiveMessage,
+                                                   NULL);
 }
 
 /**********************************************************************
@@ -395,7 +412,7 @@ NtReplyWaitReceivePort (IN  HANDLE          PortHandle,
  */
 NTSTATUS STDCALL
 NtReplyWaitReplyPort (HANDLE           PortHandle,
-                     PLPC_MESSAGE      ReplyMessage)
+                     PPORT_MESSAGE     ReplyMessage)
 {
    UNIMPLEMENTED;
    return(STATUS_NOT_IMPLEMENTED);
@@ -408,8 +425,8 @@ NTSTATUS
 STDCALL
 LpcRequestWaitReplyPort (
        IN PEPORT               Port,
-       IN PLPC_MESSAGE LpcMessageRequest,
-       OUT PLPC_MESSAGE        LpcMessageReply
+       IN PPORT_MESSAGE        LpcMessageRequest,
+       OUT PPORT_MESSAGE       LpcMessageReply
        )
 {
        UNIMPLEMENTED;