- get csrss, ntvdm, smss compiling on msvc.
[reactos.git] / reactos / subsys / csrss / api / wapi.c
index a80ef0b..92a726e 100644 (file)
@@ -10,7 +10,9 @@
 
 /* INCLUDES ******************************************************************/
 
-#include "csrss.h"
+#include <csrss.h>
+
+#define NDEBUG
 
 #define NDEBUG
 #include <debug.h>
@@ -79,11 +81,11 @@ CsrApiCallHandler(PCSRSS_PROCESS_DATA ProcessData,
     {
       if (ApiDefinitions[DefIndex].Type == Type)
         {
-          if (Request->Header.DataSize < ApiDefinitions[DefIndex].MinRequestSize)
+          if (Request->Header.u1.s1.DataLength < ApiDefinitions[DefIndex].MinRequestSize)
             {
               DPRINT1("Request type %d min request size %d actual %d\n",
                       Type, ApiDefinitions[DefIndex].MinRequestSize,
-                      Request->Header.DataSize);
+                      Request->Header.u1.s1.DataLength);
               Request->Status = STATUS_INVALID_PARAMETER;
             }
           else
@@ -96,20 +98,20 @@ CsrApiCallHandler(PCSRSS_PROCESS_DATA ProcessData,
   if (! Found)
     {
       DPRINT1("CSR: Unknown request type 0x%x\n", Request->Type);
-      Request->Header.MessageSize = sizeof(CSR_API_MESSAGE);
-      Request->Header.DataSize = sizeof(CSR_API_MESSAGE) - LPC_MESSAGE_BASE_SIZE;
+      Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
+      Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
       Request->Status = STATUS_INVALID_SYSTEM_SERVICE;
     }
 }
 
-STATIC
+static
 VOID
 STDCALL
 ClientConnectionThread(HANDLE ServerPort)
 {
     NTSTATUS Status;
-    LPC_MAX_MESSAGE LpcRequest;
-    PCSR_API_MESSAGE Request;
+    BYTE RawRequest[LPC_MAX_DATA_LENGTH];
+    PCSR_API_MESSAGE Request = (PCSR_API_MESSAGE)RawRequest;
     PCSR_API_MESSAGE Reply;
     PCSRSS_PROCESS_DATA ProcessData;
   
@@ -125,36 +127,39 @@ ClientConnectionThread(HANDLE ServerPort)
         Status = NtReplyWaitReceivePort(ServerPort,
                                         0,
                                         &Reply->Header,
-                                        &LpcRequest.Header);
+                                        &Request->Header);
         if (!NT_SUCCESS(Status))
         {
-            DPRINT1("CSR: NtReplyWaitReceivePort failed\n");
-            break;
+          DPRINT1("NtReplyWaitReceivePort failed\n");
+          break;
         }
         
         /* If the connection was closed, handle that */
-        if (LpcRequest.Header.MessageType == LPC_PORT_CLOSED)
+        if (Request->Header.u2.s2.Type == LPC_PORT_CLOSED)
         {
-            CsrFreeProcessData( LpcRequest.Header.ClientId.UniqueProcess );
+            CsrFreeProcessData( Request->Header.ClientId.UniqueProcess );
             break;
         }
-        
-        /* Get the CSR Message */
-        Request = (PCSR_API_MESSAGE)&LpcRequest;
-      
+
         DPRINT("CSR: Got CSR API: %x [Message Origin: %x]\n", 
-                Request->Type, 
-                Request->Header.ClientId.UniqueProcess);
+               Request->Type, 
+               Request->Header.ClientId.UniqueProcess);
 
         /* Get the Process Data */
-        ProcessData = CsrGetProcessData(LpcRequest.Header.ClientId.UniqueProcess);
+        ProcessData = CsrGetProcessData(Request->Header.ClientId.UniqueProcess);
         if (ProcessData == NULL)
         {
-            DPRINT1("CSR: Message %d: Unable to find data for process 0x%x\n",
-                    LpcRequest.Header.MessageType,
-                    LpcRequest.Header.ClientId.UniqueProcess);
+            DPRINT1("Message %d: Unable to find data for process 0x%x\n",
+                    Request->Header.u2.s2.Type,
+                    Request->Header.ClientId.UniqueProcess);
             break;
         }
+        if (ProcessData->Terminated)
+        {
+            DPRINT1("Message %d: process %d already terminated\n",
+                   Request->Type, (ULONG)Request->Header.ClientId.UniqueProcess);
+            continue;
+        }
 
         /* Call the Handler */
         CsrApiCallHandler(ProcessData, Request);
@@ -180,7 +185,8 @@ DWORD STDCALL
 ServerApiPortThread (PVOID PortHandle)
 {
    NTSTATUS Status = STATUS_SUCCESS;
-   LPC_MAX_MESSAGE Request;
+   BYTE RawRequest[sizeof(PORT_MESSAGE) + sizeof(CSR_CONNECTION_INFO)];
+   PPORT_MESSAGE Request = (PPORT_MESSAGE)RawRequest;
    HANDLE hApiListenPort = * (PHANDLE) PortHandle;
    HANDLE ServerPort = (HANDLE) 0;
    HANDLE ServerThread = (HANDLE) 0;
@@ -192,13 +198,13 @@ ServerApiPortThread (PVOID PortHandle)
 
    for (;;)
      {
-        LPC_SECTION_READ LpcRead;
+        REMOTE_PORT_VIEW LpcRead;
         ServerPort = NULL;
 
-       Status = NtListenPort (hApiListenPort, & Request.Header);
+       Status = NtListenPort (hApiListenPort, Request);
        if (!NT_SUCCESS(Status))
          {
-            DPRINT1("CSR: NtListenPort() failed\n");
+            DPRINT1("CSR: NtListenPort() failed, status=%x\n", Status);
             break;
          }
        Status = NtAcceptConnectPort(& ServerPort,
@@ -213,11 +219,11 @@ ServerApiPortThread (PVOID PortHandle)
             break;
          }
 
-       ProcessData = CsrCreateProcessData(Request.Header.ClientId.UniqueProcess);
+       ProcessData = CsrCreateProcessData(Request->ClientId.UniqueProcess);
        if (ProcessData == NULL)
          {
             DPRINT1("Unable to allocate or find data for process 0x%x\n",
-                    Request.Header.ClientId.UniqueProcess);
+                    Request->ClientId.UniqueProcess);
             Status = STATUS_UNSUCCESSFUL;
             break;
          }
@@ -273,13 +279,15 @@ ServerSbApiPortThread (PVOID PortHandle)
 {
        HANDLE          hSbApiPortListen = * (PHANDLE) PortHandle;
        HANDLE          hConnectedPort = (HANDLE) 0;
-       LPC_MAX_MESSAGE Request = {{0}};
+       PORT_MESSAGE    Request;
        PVOID           Context = NULL;
        NTSTATUS        Status = STATUS_SUCCESS;
+    PPORT_MESSAGE Reply = NULL;
 
        DPRINT("CSR: %s called\n", __FUNCTION__);
 
-       Status = NtListenPort (hSbApiPortListen, & Request.Header);
+    RtlZeroMemory(&Request, sizeof(PORT_MESSAGE));
+       Status = NtListenPort (hSbApiPortListen, & Request);
        if (!NT_SUCCESS(Status))
        {
                DPRINT1("CSR: %s: NtListenPort(SB) failed (Status=0x%08lx)\n",
@@ -305,7 +313,7 @@ DPRINT("-- 2\n");
                                        __FUNCTION__, Status);
                        } else {
 DPRINT("-- 3\n");
-                               PLPC_MESSAGE Reply = NULL;
+                               
                                /*
                                 * Tell the init thread the SM gave the
                                 * green light for boostrapping.
@@ -323,19 +331,19 @@ DPRINT("-- 4\n");
                                        Status = NtReplyWaitReceivePort(hConnectedPort,
                                                                        Context,
                                                                        Reply,
-                                                                       & Request.Header);
+                                                                       & Request);
                                        if(!NT_SUCCESS(Status))
                                        {
                                                DPRINT1("CSR: %s: NtReplyWaitReceivePort failed (Status=0x%08lx)\n",
                                                        __FUNCTION__, Status);
                                                break;
                                        }
-                                       switch (Request.Header.MessageType)//fix .h PORT_MESSAGE_TYPE(Request))
+                                       switch (Request.u2.s2.Type)//fix .h PORT_MESSAGE_TYPE(Request))
                                        {
                                                /* TODO */
                                        default:
                                                DPRINT1("CSR: %s received message (type=%d)\n",
-                                                       __FUNCTION__, Request.Header.MessageType);
+                                                       __FUNCTION__, Request.u2.s2.Type);
                                        }
 DPRINT("-- 5\n");
                                }