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);
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);
Thread->LpcReplyMessage = NULL;
/* And remove the message from the port zone */
- LpcpFreeToPortZone(Message, 1);
+ LpcpFreeToPortZone(Message, LPCP_LOCK_HELD);
NextEntry = Port->LpcReplyChainHead.Flink;
}
InitializeListHead(&Message->Entry);
/* Remove it from the port zone */
- LpcpFreeToPortZone(Message, 1);
+ LpcpFreeToPortZone(Message, LPCP_LOCK_HELD);
}
/* Release the lock */
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');
}
}
}
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*/
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)
{
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);
/* Free queued messages */
RemoveEntryList(&Message->Entry);
InitializeListHead(&Message->Entry);
- LpcpFreeToPortZone(Message, 1);
+ LpcpFreeToPortZone(Message, LPCP_LOCK_HELD);
/* Restart at the head */
NextEntry = ListHead->Flink;
/* Remove it */
RemoveEntryList(&Message->Entry);
InitializeListHead(&Message->Entry);
- LpcpFreeToPortZone(Message, 1);
+ LpcpFreeToPortZone(Message, LPCP_LOCK_HELD);
/* Restart at the head */
NextEntry = ListHead->Flink;
/* 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
{
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);