[STORPORT] Fix x64 build
[reactos.git] / ntoskrnl / lpc / close.c
index 1d37b59..6ac3f62 100644 (file)
@@ -50,14 +50,17 @@ LpcExitThread(IN PETHREAD Thread)
 VOID
 NTAPI
 LpcpFreeToPortZone(IN PLPCP_MESSAGE Message,
-                   IN ULONG Flags)
+                   IN ULONG LockFlags)
 {
     PLPCP_CONNECTION_MESSAGE ConnectMessage;
     PLPCP_PORT_OBJECT ClientPort = NULL;
     PETHREAD Thread = NULL;
-    BOOLEAN LockHeld = Flags & 1, ReleaseLock = Flags & 2;
+    BOOLEAN LockHeld = (LockFlags & LPCP_LOCK_HELD);
+    BOOLEAN ReleaseLock = (LockFlags & LPCP_LOCK_RELEASE);
+
     PAGED_CODE();
-    LPCTRACE(LPC_CLOSE_DEBUG, "Message: %p. Flags: %lx\n", Message, Flags);
+
+    LPCTRACE(LPC_CLOSE_DEBUG, "Message: %p. LockFlags: %lx\n", Message, LockFlags);
 
     /* Acquire the lock if not already */
     if (!LockHeld) KeAcquireGuardedMutex(&LpcpLock);
@@ -113,6 +116,8 @@ LpcpDestroyPortQueue(IN PLPCP_PORT_OBJECT Port,
     PLPCP_MESSAGE Message;
     PLPCP_PORT_OBJECT ConnectionPort = NULL;
     PLPCP_CONNECTION_MESSAGE ConnectMessage;
+    PLPCP_NONPAGED_PORT_QUEUE MessageQueue;
+
     PAGED_CODE();
     LPCTRACE(LPC_CLOSE_DEBUG, "Port: %p. Flags: %lx\n", Port, Port->Flags);
 
@@ -183,7 +188,7 @@ LpcpDestroyPortQueue(IN PLPCP_PORT_OBJECT Port,
                 Thread->LpcReplyMessage = NULL;
 
                 /* And remove the message from the port zone */
-                LpcpFreeToPortZone(Message, 1);
+                LpcpFreeToPortZone(Message, LPCP_LOCK_HELD);
                 NextEntry = Port->LpcReplyChainHead.Flink;
             }
 
@@ -210,7 +215,7 @@ LpcpDestroyPortQueue(IN PLPCP_PORT_OBJECT Port,
         InitializeListHead(&Message->Entry);
 
         /* Remove it from the port zone */
-        LpcpFreeToPortZone(Message, 1);
+        LpcpFreeToPortZone(Message, LPCP_LOCK_HELD);
     }
 
     /* Release the lock */
@@ -226,9 +231,10 @@ LpcpDestroyPortQueue(IN PLPCP_PORT_OBJECT Port,
         if (Port->MsgQueue.Semaphore)
         {
             /* Use the semaphore to find the port queue and free it */
-            ExFreePool(CONTAINING_RECORD(Port->MsgQueue.Semaphore,
-                                         LPCP_NONPAGED_PORT_QUEUE,
-                                         Semaphore));
+            MessageQueue = CONTAINING_RECORD(Port->MsgQueue.Semaphore,
+                                             LPCP_NONPAGED_PORT_QUEUE,
+                                             Semaphore);
+            ExFreePoolWithTag(MessageQueue, 'troP');
         }
     }
 }
@@ -242,6 +248,7 @@ LpcpClosePort(IN PEPROCESS Process OPTIONAL,
               IN ULONG SystemHandleCount)
 {
     PLPCP_PORT_OBJECT Port = (PLPCP_PORT_OBJECT)Object;
+
     LPCTRACE(LPC_CLOSE_DEBUG, "Port: %p. Flags: %lx\n", Port, Port->Flags);
 
     /* Only Server-side Connection Ports need clean up*/
@@ -302,10 +309,12 @@ LpcpDeletePort(IN PVOID ObjectBody)
     PLIST_ENTRY ListHead, NextEntry;
     HANDLE Pid;
     CLIENT_DIED_MSG ClientDiedMsg;
-    Timeout.QuadPart = -1000000;
+
     PAGED_CODE();
     LPCTRACE(LPC_CLOSE_DEBUG, "Port: %p. Flags: %lx\n", Port, Port->Flags);
 
+    Timeout.QuadPart = -1000000;
+
     /* Check if this is a communication port */
     if ((Port->Flags & LPCP_PORT_TYPE_MASK) == LPCP_COMMUNICATION_PORT)
     {
@@ -344,8 +353,8 @@ LpcpDeletePort(IN PVOID ObjectBody)
         for (;;)
         {
             /* Send the message */
-            if (LpcRequestPort(Port,
-                               &ClientDiedMsg.h) != STATUS_NO_MEMORY) break;
+            if (LpcRequestPort(Port, &ClientDiedMsg.h) != STATUS_NO_MEMORY)
+                break;
 
             /* Wait until trying again */
             KeDelayExecutionThread(KernelMode, FALSE, &Timeout);
@@ -404,7 +413,7 @@ LpcpDeletePort(IN PVOID ObjectBody)
                 /* Free queued messages */
                 RemoveEntryList(&Message->Entry);
                 InitializeListHead(&Message->Entry);
-                LpcpFreeToPortZone(Message, 1);
+                LpcpFreeToPortZone(Message, LPCP_LOCK_HELD);
 
                 /* Restart at the head */
                 NextEntry = ListHead->Flink;
@@ -417,7 +426,7 @@ LpcpDeletePort(IN PVOID ObjectBody)
                 /* Remove it */
                 RemoveEntryList(&Message->Entry);
                 InitializeListHead(&Message->Entry);
-                LpcpFreeToPortZone(Message, 1);
+                LpcpFreeToPortZone(Message, LPCP_LOCK_HELD);
 
                 /* Restart at the head */
                 NextEntry = ListHead->Flink;
@@ -429,6 +438,15 @@ LpcpDeletePort(IN PVOID ObjectBody)
 
         /* Dereference the object unless it's the same port */
         if (ConnectionPort != Port) ObDereferenceObject(ConnectionPort);
+
+        /* Check if this is a connection port with a server process */
+        if (((Port->Flags & LPCP_PORT_TYPE_MASK) == LPCP_CONNECTION_PORT) &&
+            (ConnectionPort->ServerProcess))
+        {
+            /* Dereference the server process */
+            ObDereferenceObject(ConnectionPort->ServerProcess);
+            ConnectionPort->ServerProcess = NULL;
+        }
     }
     else
     {
@@ -436,15 +454,6 @@ LpcpDeletePort(IN PVOID ObjectBody)
         KeReleaseGuardedMutex(&LpcpLock);
     }
 
-    /* Check if this is a connection port with a server process*/
-    if (((Port->Flags & LPCP_PORT_TYPE_MASK) == LPCP_CONNECTION_PORT) &&
-        (ConnectionPort->ServerProcess))
-    {
-        /* Dereference the server process */
-        ObDereferenceObject(ConnectionPort->ServerProcess);
-        ConnectionPort->ServerProcess = NULL;
-    }
-
     /* Free client security */
     LpcpFreePortClientSecurity(Port);
     LPCTRACE(LPC_CLOSE_DEBUG, "Port: %p deleted\n", Port);