{
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->u1.s1.TotalLength);
+ 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();
* REVISIONS
*/
NTSTATUS STDCALL
-NtReplyWaitReceivePortEx(IN HANDLE PortHandle,
- OUT PULONG PortId,
- IN PPORT_MESSAGE LpcReply,
- OUT PPORT_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;
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,
+ ProbeForWrite(ReceiveMessage,
sizeof(PORT_MESSAGE),
1);
}
/*
* 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,
Request = EiDequeueMessagePort(Port);
KeReleaseSpinLock(&Port->Lock, oldIrql);
+ if (Request == NULL)
+ {
+ ObDereferenceObject(Port);
+ return STATUS_UNSUCCESSFUL;
+ }
+
if (Request->Message.u2.s2.Type == LPC_CONNECTION_REQUEST)
{
PORT_MESSAGE Header;
{
_SEH_TRY
{
- ProbeForWrite((PVOID)(LpcMessage + 1),
+ ProbeForWrite((PVOID)(ReceiveMessage + 1),
CRequest->ConnectDataLength,
1);
- RtlCopyMemory(LpcMessage,
+ RtlCopyMemory(ReceiveMessage,
&Header,
sizeof(PORT_MESSAGE));
- RtlCopyMemory((PVOID)(LpcMessage + 1),
+ RtlCopyMemory((PVOID)(ReceiveMessage + 1),
CRequest->ConnectData,
CRequest->ConnectDataLength);
}
}
else
{
- RtlCopyMemory(LpcMessage,
+ RtlCopyMemory(ReceiveMessage,
&Header,
sizeof(PORT_MESSAGE));
- RtlCopyMemory((PVOID)(LpcMessage + 1),
+ RtlCopyMemory((PVOID)(ReceiveMessage + 1),
CRequest->ConnectData,
CRequest->ConnectDataLength);
}
{
_SEH_TRY
{
- ProbeForWrite(LpcMessage,
+ ProbeForWrite(ReceiveMessage,
Request->Message.u1.s1.TotalLength,
1);
- RtlCopyMemory(LpcMessage,
+ RtlCopyMemory(ReceiveMessage,
&Request->Message,
Request->Message.u1.s1.TotalLength);
}
}
else
{
- RtlCopyMemory(LpcMessage,
+ RtlCopyMemory(ReceiveMessage,
&Request->Message,
Request->Message.u1.s1.TotalLength);
}
* REVISIONS
*/
NTSTATUS STDCALL
-NtReplyWaitReceivePort (IN HANDLE PortHandle,
- OUT PULONG PortId,
- IN PPORT_MESSAGE LpcReply,
- OUT PPORT_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);
}
/**********************************************************************