mirror of
https://github.com/reactos/reactos.git
synced 2025-04-15 01:47:30 +00:00
[NTOS:LPC]: Improve the lisibility of some functions:
- Group together the local parameters used for capturing user variables; - Add some space between the list of parameters and the beginning of the code proper; - Rename some variables or move some code to make some different functions look more similar (helps in finding functionality-similar functions in the code); - Improve some comments; - Whitespace fixes; - Few code formatting. - Use a ExFreePoolWithTag instead of ExFreePool, but otherwise no other functional code changes. svn path=/trunk/; revision=73162
This commit is contained in:
parent
bb59ec3e6e
commit
06807aee1b
8 changed files with 116 additions and 112 deletions
|
@ -116,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);
|
||||
|
||||
|
@ -229,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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -245,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*/
|
||||
|
@ -305,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)
|
||||
{
|
||||
|
@ -347,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);
|
||||
|
|
|
@ -44,19 +44,20 @@ NtAcceptConnectPort(OUT PHANDLE PortHandle,
|
|||
IN PPORT_VIEW ServerView,
|
||||
IN PREMOTE_PORT_VIEW ClientView)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
ULONG ConnectionInfoLength;
|
||||
PLPCP_PORT_OBJECT ConnectionPort, ServerPort, ClientPort;
|
||||
PLPCP_CONNECTION_MESSAGE ConnectMessage;
|
||||
PLPCP_MESSAGE Message;
|
||||
PVOID ClientSectionToMap = NULL;
|
||||
HANDLE Handle;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
NTSTATUS Status;
|
||||
ULONG ConnectionInfoLength;
|
||||
PLPCP_MESSAGE Message;
|
||||
PLPCP_CONNECTION_MESSAGE ConnectMessage;
|
||||
PEPROCESS ClientProcess;
|
||||
PETHREAD ClientThread;
|
||||
LARGE_INTEGER SectionOffset;
|
||||
CLIENT_ID ClientId;
|
||||
ULONG MessageId;
|
||||
|
||||
PAGED_CODE();
|
||||
LPCTRACE(LPC_COMPLETE_DEBUG,
|
||||
"Context: %p. Message: %p. Accept: %lx. Views: %p/%p\n",
|
||||
|
@ -407,9 +408,10 @@ NTAPI
|
|||
NtCompleteConnectPort(IN HANDLE PortHandle)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PLPCP_PORT_OBJECT Port;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
PLPCP_PORT_OBJECT Port;
|
||||
PETHREAD Thread;
|
||||
|
||||
PAGED_CODE();
|
||||
LPCTRACE(LPC_COMPLETE_DEBUG, "Handle: %p\n", PortHandle);
|
||||
|
||||
|
@ -462,7 +464,7 @@ NtCompleteConnectPort(IN HANDLE PortHandle)
|
|||
KeReleaseGuardedMutex(&LpcpLock);
|
||||
LpcpCompleteWait(&Thread->LpcReplySemaphore);
|
||||
|
||||
/* Dereference the Thread and Port and return */
|
||||
/* Dereference the Thread and Port and return */
|
||||
ObDereferenceObject(Port);
|
||||
ObDereferenceObject(Thread);
|
||||
LPCTRACE(LPC_COMPLETE_DEBUG, "Port: %p. Thread: %p\n", Port, Thread);
|
||||
|
|
|
@ -87,19 +87,20 @@ NtSecureConnectPort(OUT PHANDLE PortHandle,
|
|||
IN OUT PVOID ConnectionInformation OPTIONAL,
|
||||
IN OUT PULONG ConnectionInformationLength OPTIONAL)
|
||||
{
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
PETHREAD Thread = PsGetCurrentThread();
|
||||
ULONG ConnectionInfoLength = 0;
|
||||
PLPCP_PORT_OBJECT Port, ClientPort;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
HANDLE Handle;
|
||||
PVOID SectionToMap;
|
||||
PLPCP_MESSAGE Message;
|
||||
PLPCP_CONNECTION_MESSAGE ConnectMessage;
|
||||
PETHREAD Thread = PsGetCurrentThread();
|
||||
ULONG PortMessageLength;
|
||||
HANDLE Handle;
|
||||
PVOID SectionToMap;
|
||||
LARGE_INTEGER SectionOffset;
|
||||
PTOKEN Token;
|
||||
PTOKEN_USER TokenUserInfo;
|
||||
|
||||
PAGED_CODE();
|
||||
LPCTRACE(LPC_CONNECT_DEBUG,
|
||||
"Name: %wZ. Qos: %p. Views: %p/%p. Sid: %p\n",
|
||||
|
@ -138,7 +139,7 @@ NtSecureConnectPort(OUT PHANDLE PortHandle,
|
|||
LpcPortObjectType,
|
||||
PreviousMode,
|
||||
NULL,
|
||||
(PVOID *)&Port);
|
||||
(PVOID*)&Port);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("Failed to reference port '%wZ': 0x%lx\n", PortName, Status);
|
||||
|
@ -206,7 +207,7 @@ NtSecureConnectPort(OUT PHANDLE PortHandle,
|
|||
sizeof(LPCP_PORT_OBJECT),
|
||||
0,
|
||||
0,
|
||||
(PVOID *)&ClientPort);
|
||||
(PVOID*)&ClientPort);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Failed, dereference the server port and return */
|
||||
|
@ -395,7 +396,7 @@ NtSecureConnectPort(OUT PHANDLE PortHandle,
|
|||
InsertTailList(&Port->LpcReplyChainHead, &Thread->LpcReplyChain);
|
||||
Thread->LpcReplyMessage = Message;
|
||||
|
||||
/* Now we can finally reference the client port and link it*/
|
||||
/* Now we can finally reference the client port and link it */
|
||||
ObReferenceObject(ClientPort);
|
||||
ConnectMessage->ClientPort = ClientPort;
|
||||
|
||||
|
@ -421,15 +422,14 @@ NtSecureConnectPort(OUT PHANDLE PortHandle,
|
|||
Status);
|
||||
|
||||
/* If this is a waitable port, set the event */
|
||||
if (Port->Flags & LPCP_WAITABLE_PORT) KeSetEvent(&Port->WaitEvent,
|
||||
1,
|
||||
FALSE);
|
||||
if (Port->Flags & LPCP_WAITABLE_PORT)
|
||||
KeSetEvent(&Port->WaitEvent, 1, FALSE);
|
||||
|
||||
/* Release the queue semaphore and leave the critical region */
|
||||
LpcpCompleteWait(Port->MsgQueue.Semaphore);
|
||||
KeLeaveCriticalRegion();
|
||||
|
||||
/* Now wait for a reply */
|
||||
/* Now wait for a reply and set 'Status' */
|
||||
LpcpConnectWait(&Thread->LpcReplySemaphore, PreviousMode);
|
||||
}
|
||||
|
||||
|
@ -478,7 +478,7 @@ NtSecureConnectPort(OUT PHANDLE PortHandle,
|
|||
NULL,
|
||||
PORT_ALL_ACCESS,
|
||||
0,
|
||||
(PVOID *)NULL,
|
||||
NULL,
|
||||
&Handle);
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
|
|
|
@ -19,11 +19,12 @@ NTAPI
|
|||
LpcpInitializePortQueue(IN PLPCP_PORT_OBJECT Port)
|
||||
{
|
||||
PLPCP_NONPAGED_PORT_QUEUE MessageQueue;
|
||||
|
||||
PAGED_CODE();
|
||||
|
||||
/* Allocate the queue */
|
||||
MessageQueue = ExAllocatePoolWithTag(NonPagedPool,
|
||||
sizeof(LPCP_NONPAGED_PORT_QUEUE),
|
||||
sizeof(*MessageQueue),
|
||||
'troP');
|
||||
if (!MessageQueue) return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
|
@ -46,12 +47,13 @@ LpcpCreatePort(OUT PHANDLE PortHandle,
|
|||
IN ULONG MaxPoolUsage,
|
||||
IN BOOLEAN Waitable)
|
||||
{
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
NTSTATUS Status;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
PLPCP_PORT_OBJECT Port;
|
||||
HANDLE Handle;
|
||||
PUNICODE_STRING ObjectName;
|
||||
BOOLEAN NoName;
|
||||
|
||||
PAGED_CODE();
|
||||
LPCTRACE(LPC_CREATE_DEBUG, "Name: %wZ\n", ObjectAttributes->ObjectName);
|
||||
|
||||
|
@ -170,7 +172,7 @@ LpcpCreatePort(OUT PHANDLE PortHandle,
|
|||
Port->MaxMessageLength = MaxMessageLength;
|
||||
|
||||
/* Insert it now */
|
||||
Status = ObInsertObject((PVOID)Port,
|
||||
Status = ObInsertObject(Port,
|
||||
NULL,
|
||||
PORT_ALL_ACCESS,
|
||||
0,
|
||||
|
|
|
@ -23,10 +23,11 @@ NtListenPort(IN HANDLE PortHandle,
|
|||
OUT PPORT_MESSAGE ConnectMessage)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
|
||||
PAGED_CODE();
|
||||
LPCTRACE(LPC_LISTEN_DEBUG, "Handle: %p\n", PortHandle);
|
||||
|
||||
/* Wait forever for a connection request. */
|
||||
/* Wait forever for a connection request */
|
||||
for (;;)
|
||||
{
|
||||
/* Do the wait */
|
||||
|
@ -35,7 +36,7 @@ NtListenPort(IN HANDLE PortHandle,
|
|||
NULL,
|
||||
ConnectMessage);
|
||||
|
||||
/* Accept only LPC_CONNECTION_REQUEST requests. */
|
||||
/* Accept only LPC_CONNECTION_REQUEST requests */
|
||||
if ((Status != STATUS_SUCCESS) ||
|
||||
(LpcpGetMessageType(ConnectMessage) == LPC_CONNECTION_REQUEST))
|
||||
{
|
||||
|
@ -48,5 +49,4 @@ NtListenPort(IN HANDLE PortHandle,
|
|||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -60,6 +60,7 @@ LpcInitSystem(VOID)
|
|||
NULL,
|
||||
&LpcPortObjectType);
|
||||
|
||||
/* Create the Waitable Port Object Type */
|
||||
RtlInitUnicodeString(&Name, L"WaitablePort");
|
||||
ObjectTypeInitializer.PoolType = NonPagedPool;
|
||||
ObjectTypeInitializer.DefaultNonPagedPoolCharge += sizeof(LPCP_PORT_OBJECT);
|
||||
|
@ -125,13 +126,14 @@ NTAPI
|
|||
NtImpersonateClientOfPort(IN HANDLE PortHandle,
|
||||
IN PPORT_MESSAGE ClientMessage)
|
||||
{
|
||||
KPROCESSOR_MODE PreviousMode;
|
||||
NTSTATUS Status;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
CLIENT_ID ClientId;
|
||||
ULONG MessageId;
|
||||
PLPCP_PORT_OBJECT Port = NULL, ConnectedPort = NULL;
|
||||
PETHREAD ClientThread = NULL;
|
||||
SECURITY_CLIENT_CONTEXT ClientContext;
|
||||
NTSTATUS Status;
|
||||
|
||||
PAGED_CODE();
|
||||
|
||||
/* Check the previous mode */
|
||||
|
@ -192,8 +194,7 @@ NtImpersonateClientOfPort(IN HANDLE PortHandle,
|
|||
|
||||
/* Get the connected port and try to reference it */
|
||||
ConnectedPort = Port->ConnectedPort;
|
||||
if ((ConnectedPort == NULL) ||
|
||||
!ObReferenceObjectSafe(ConnectedPort))
|
||||
if ((ConnectedPort == NULL) || !ObReferenceObjectSafe(ConnectedPort))
|
||||
{
|
||||
DPRINT1("Failed to reference the connected port\n");
|
||||
ConnectedPort = NULL;
|
||||
|
@ -254,13 +255,6 @@ NtImpersonateClientOfPort(IN HANDLE PortHandle,
|
|||
/* Get rid of the security context */
|
||||
SeDeleteClientSecurity(&ClientContext);
|
||||
|
||||
goto Cleanup;
|
||||
|
||||
CleanupWithLock:
|
||||
|
||||
/* Release the lock */
|
||||
KeReleaseGuardedMutex(&LpcpLock);
|
||||
|
||||
Cleanup:
|
||||
|
||||
if (ConnectedPort != NULL)
|
||||
|
@ -272,6 +266,12 @@ Cleanup:
|
|||
ObDereferenceObject(Port);
|
||||
|
||||
return Status;
|
||||
|
||||
CleanupWithLock:
|
||||
|
||||
/* Release the lock */
|
||||
KeReleaseGuardedMutex(&LpcpLock);
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
|
|
|
@ -99,6 +99,7 @@ LpcpFindDataInfoMessage(
|
|||
{
|
||||
PLPCP_MESSAGE Message;
|
||||
PLIST_ENTRY ListEntry;
|
||||
|
||||
PAGED_CODE();
|
||||
|
||||
/* Check if the port we want is the connection port */
|
||||
|
@ -141,13 +142,14 @@ LpcpMoveMessage(IN PPORT_MESSAGE Destination,
|
|||
IN ULONG MessageType,
|
||||
IN PCLIENT_ID ClientId)
|
||||
{
|
||||
/* Set the Message size */
|
||||
LPCTRACE((LPC_REPLY_DEBUG | LPC_SEND_DEBUG),
|
||||
"Destination/Origin: %p/%p. Data: %p. Length: %lx\n",
|
||||
Destination,
|
||||
Origin,
|
||||
Data,
|
||||
Origin->u1.Length);
|
||||
|
||||
/* Set the Message size */
|
||||
Destination->u1.Length = Origin->u1.Length;
|
||||
|
||||
/* Set the Message Type */
|
||||
|
@ -188,12 +190,12 @@ NTAPI
|
|||
NtReplyPort(IN HANDLE PortHandle,
|
||||
IN PPORT_MESSAGE ReplyMessage)
|
||||
{
|
||||
PLPCP_PORT_OBJECT Port;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
NTSTATUS Status;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
// PORT_MESSAGE CapturedReplyMessage;
|
||||
PLPCP_PORT_OBJECT Port;
|
||||
PLPCP_MESSAGE Message;
|
||||
PETHREAD Thread = PsGetCurrentThread(), WakeupThread;
|
||||
//PORT_MESSAGE CapturedReplyMessage;
|
||||
|
||||
PAGED_CODE();
|
||||
LPCTRACE(LPC_REPLY_DEBUG,
|
||||
|
@ -274,8 +276,8 @@ NtReplyPort(IN HANDLE PortHandle,
|
|||
/* Make sure this is the reply the thread is waiting for */
|
||||
if ((WakeupThread->LpcReplyMessageId != ReplyMessage->MessageId) ||
|
||||
((LpcpGetMessageFromThread(WakeupThread)) &&
|
||||
(LpcpGetMessageType(&LpcpGetMessageFromThread(WakeupThread)->
|
||||
Request) != LPC_REQUEST)))
|
||||
(LpcpGetMessageType(&LpcpGetMessageFromThread(WakeupThread)-> Request)
|
||||
!= LPC_REQUEST)))
|
||||
{
|
||||
/* It isn't, fail */
|
||||
LpcpFreeToPortZone(Message, LPCP_LOCK_HELD | LPCP_LOCK_RELEASE);
|
||||
|
@ -295,7 +297,7 @@ NtReplyPort(IN HANDLE PortHandle,
|
|||
}
|
||||
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
/* Fail */
|
||||
/* Cleanup and return the exception code */
|
||||
LpcpFreeToPortZone(Message, LPCP_LOCK_HELD | LPCP_LOCK_RELEASE);
|
||||
ObDereferenceObject(WakeupThread);
|
||||
ObDereferenceObject(Port);
|
||||
|
@ -358,15 +360,15 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle,
|
|||
OUT PPORT_MESSAGE ReceiveMessage,
|
||||
IN PLARGE_INTEGER Timeout OPTIONAL)
|
||||
{
|
||||
PLPCP_PORT_OBJECT Port, ReceivePort, ConnectionPort = NULL;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(), WaitMode = PreviousMode;
|
||||
NTSTATUS Status;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(), WaitMode = PreviousMode;
|
||||
// PORT_MESSAGE CapturedReplyMessage;
|
||||
LARGE_INTEGER CapturedTimeout;
|
||||
PLPCP_PORT_OBJECT Port, ReceivePort, ConnectionPort = NULL;
|
||||
PLPCP_MESSAGE Message;
|
||||
PETHREAD Thread = PsGetCurrentThread(), WakeupThread;
|
||||
PLPCP_CONNECTION_MESSAGE ConnectMessage;
|
||||
ULONG ConnectionInfoLength;
|
||||
//PORT_MESSAGE CapturedReplyMessage;
|
||||
LARGE_INTEGER CapturedTimeout;
|
||||
|
||||
PAGED_CODE();
|
||||
LPCTRACE(LPC_REPLY_DEBUG,
|
||||
|
@ -516,8 +518,8 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle,
|
|||
/* Make sure this is the reply the thread is waiting for */
|
||||
if ((WakeupThread->LpcReplyMessageId != ReplyMessage->MessageId) ||
|
||||
((LpcpGetMessageFromThread(WakeupThread)) &&
|
||||
(LpcpGetMessageType(&LpcpGetMessageFromThread(WakeupThread)->
|
||||
Request) != LPC_REQUEST)))
|
||||
(LpcpGetMessageType(&LpcpGetMessageFromThread(WakeupThread)->Request)
|
||||
!= LPC_REQUEST)))
|
||||
{
|
||||
/* It isn't, fail */
|
||||
LpcpFreeToPortZone(Message, LPCP_LOCK_HELD | LPCP_LOCK_RELEASE);
|
||||
|
@ -599,8 +601,7 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle,
|
|||
}
|
||||
|
||||
/* Get the message on the queue */
|
||||
Message = CONTAINING_RECORD(RemoveHeadList(&ReceivePort->
|
||||
MsgQueue.ReceiveHead),
|
||||
Message = CONTAINING_RECORD(RemoveHeadList(&ReceivePort->MsgQueue.ReceiveHead),
|
||||
LPCP_MESSAGE,
|
||||
Entry);
|
||||
|
||||
|
@ -756,17 +757,18 @@ LpcpCopyRequestData(
|
|||
IN ULONG Index,
|
||||
IN PVOID Buffer,
|
||||
IN ULONG BufferLength,
|
||||
OUT PULONG Returnlength)
|
||||
OUT PULONG ReturnLength)
|
||||
{
|
||||
KPROCESSOR_MODE PreviousMode;
|
||||
NTSTATUS Status;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
PORT_MESSAGE CapturedMessage;
|
||||
PLPCP_PORT_OBJECT Port = NULL;
|
||||
PETHREAD ClientThread = NULL;
|
||||
SIZE_T LocalReturnlength;
|
||||
SIZE_T LocalReturnLength;
|
||||
PLPCP_MESSAGE InfoMessage;
|
||||
PLPCP_DATA_INFO DataInfo;
|
||||
PVOID DataInfoBaseAddress;
|
||||
NTSTATUS Status;
|
||||
|
||||
PAGED_CODE();
|
||||
|
||||
/* Check the previous mode */
|
||||
|
@ -889,7 +891,7 @@ LpcpCopyRequestData(
|
|||
DataInfoBaseAddress,
|
||||
BufferLength,
|
||||
PreviousMode,
|
||||
&LocalReturnlength);
|
||||
&LocalReturnLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -900,7 +902,7 @@ LpcpCopyRequestData(
|
|||
Buffer,
|
||||
BufferLength,
|
||||
PreviousMode,
|
||||
&LocalReturnlength);
|
||||
&LocalReturnLength);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
|
@ -910,16 +912,16 @@ LpcpCopyRequestData(
|
|||
}
|
||||
|
||||
/* Check if the caller asked to return the copied length */
|
||||
if (Returnlength != NULL)
|
||||
if (ReturnLength != NULL)
|
||||
{
|
||||
_SEH2_TRY
|
||||
{
|
||||
*Returnlength = LocalReturnlength;
|
||||
*ReturnLength = LocalReturnLength;
|
||||
}
|
||||
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
/* Ignore */
|
||||
DPRINT1("Exception writing Returnlength, ignoring\n");
|
||||
DPRINT1("Exception writing ReturnLength, ignoring\n");
|
||||
}
|
||||
_SEH2_END;
|
||||
}
|
||||
|
@ -941,7 +943,7 @@ CleanupWithLock:
|
|||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
* @implemented
|
||||
*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
|
@ -963,7 +965,7 @@ NtReadRequestData(IN HANDLE PortHandle,
|
|||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
* @implemented
|
||||
*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
|
|
|
@ -179,17 +179,17 @@ LpcRequestWaitReplyPort(IN PVOID PortObject,
|
|||
IN PPORT_MESSAGE LpcRequest,
|
||||
OUT PPORT_MESSAGE LpcReply)
|
||||
{
|
||||
PLPCP_PORT_OBJECT Port, QueuePort, ReplyPort, ConnectionPort = NULL;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PLPCP_MESSAGE Message;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
PETHREAD Thread = PsGetCurrentThread();
|
||||
PLPCP_PORT_OBJECT Port = (PLPCP_PORT_OBJECT)PortObject;
|
||||
PLPCP_PORT_OBJECT QueuePort, ReplyPort, ConnectionPort = NULL;
|
||||
USHORT MessageType;
|
||||
PLPCP_MESSAGE Message;
|
||||
BOOLEAN Callback = FALSE;
|
||||
PKSEMAPHORE Semaphore;
|
||||
USHORT MessageType;
|
||||
PAGED_CODE();
|
||||
|
||||
Port = (PLPCP_PORT_OBJECT)PortObject;
|
||||
PAGED_CODE();
|
||||
|
||||
LPCTRACE(LPC_SEND_DEBUG,
|
||||
"Port: %p. Messages: %p/%p. Type: %lx\n",
|
||||
|
@ -205,33 +205,26 @@ LpcRequestWaitReplyPort(IN PVOID PortObject,
|
|||
MessageType = LpcpGetMessageType(LpcRequest);
|
||||
switch (MessageType)
|
||||
{
|
||||
/* No type */
|
||||
/* No type, assume LPC request */
|
||||
case 0:
|
||||
|
||||
/* Assume LPC request */
|
||||
MessageType = LPC_REQUEST;
|
||||
break;
|
||||
|
||||
/* LPC request callback */
|
||||
case LPC_REQUEST:
|
||||
|
||||
/* This is a callback */
|
||||
Callback = TRUE;
|
||||
break;
|
||||
|
||||
/* Anything else */
|
||||
/* Anything else, nothing to do */
|
||||
case LPC_CLIENT_DIED:
|
||||
case LPC_PORT_CLOSED:
|
||||
case LPC_EXCEPTION:
|
||||
case LPC_DEBUG_EVENT:
|
||||
case LPC_ERROR_EVENT:
|
||||
|
||||
/* Nothing to do */
|
||||
break;
|
||||
|
||||
/* Invalid message type */
|
||||
default:
|
||||
|
||||
/* Invalid message type */
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
|
@ -448,15 +441,14 @@ NtRequestPort(IN HANDLE PortHandle,
|
|||
IN PPORT_MESSAGE LpcRequest)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PLPCP_PORT_OBJECT Port, QueuePort, ConnectionPort = NULL;
|
||||
ULONG MessageType;
|
||||
PLPCP_MESSAGE Message;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
PETHREAD Thread = PsGetCurrentThread();
|
||||
PORT_MESSAGE CapturedLpcRequest;
|
||||
PLPCP_PORT_OBJECT Port, QueuePort, ConnectionPort = NULL;
|
||||
ULONG MessageType;
|
||||
PLPCP_MESSAGE Message;
|
||||
|
||||
PAGED_CODE();
|
||||
|
||||
LPCTRACE(LPC_SEND_DEBUG,
|
||||
"Handle: %p. Message: %p. Type: %lx\n",
|
||||
PortHandle,
|
||||
|
@ -538,7 +530,7 @@ NtRequestPort(IN HANDLE PortHandle,
|
|||
}
|
||||
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
/* Fail */
|
||||
/* Cleanup and return the exception code */
|
||||
LpcpFreeToPortZone(Message, 0);
|
||||
ObDereferenceObject(Port);
|
||||
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
||||
|
@ -578,8 +570,7 @@ NtRequestPort(IN HANDLE PortHandle,
|
|||
return STATUS_PORT_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
else if ((Port->Flags & LPCP_PORT_TYPE_MASK) !=
|
||||
LPCP_COMMUNICATION_PORT)
|
||||
else if ((Port->Flags & LPCP_PORT_TYPE_MASK) != LPCP_COMMUNICATION_PORT)
|
||||
{
|
||||
/* Use the connection port for anything but communication ports */
|
||||
ConnectionPort = QueuePort = Port->ConnectionPort;
|
||||
|
@ -706,17 +697,18 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
|
|||
IN PPORT_MESSAGE LpcRequest,
|
||||
IN OUT PPORT_MESSAGE LpcReply)
|
||||
{
|
||||
PORT_MESSAGE LocalLpcRequest;
|
||||
NTSTATUS Status;
|
||||
PORT_MESSAGE CapturedLpcRequest;
|
||||
ULONG NumberOfDataEntries;
|
||||
PLPCP_PORT_OBJECT Port, QueuePort, ReplyPort, ConnectionPort = NULL;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
NTSTATUS Status;
|
||||
PLPCP_MESSAGE Message;
|
||||
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
||||
PETHREAD Thread = PsGetCurrentThread();
|
||||
BOOLEAN Callback;
|
||||
PKSEMAPHORE Semaphore;
|
||||
ULONG MessageType;
|
||||
PLPCP_DATA_INFO DataInfo;
|
||||
|
||||
PAGED_CODE();
|
||||
LPCTRACE(LPC_SEND_DEBUG,
|
||||
"Handle: %p. Messages: %p/%p. Type: %lx\n",
|
||||
|
@ -736,7 +728,7 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
|
|||
/* Probe the full request message and copy the base structure */
|
||||
ProbeForRead(LpcRequest, sizeof(*LpcRequest), sizeof(ULONG));
|
||||
ProbeForRead(LpcRequest, LpcRequest->u1.s1.TotalLength, sizeof(ULONG));
|
||||
LocalLpcRequest = *LpcRequest;
|
||||
CapturedLpcRequest = *LpcRequest;
|
||||
|
||||
/* Probe the reply message for write */
|
||||
ProbeForWrite(LpcReply, sizeof(*LpcReply), sizeof(ULONG));
|
||||
|
@ -758,7 +750,7 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
|
|||
}
|
||||
else
|
||||
{
|
||||
LocalLpcRequest = *LpcRequest;
|
||||
CapturedLpcRequest = *LpcRequest;
|
||||
Status = LpcpVerifyMessageDataInfo(LpcRequest, &NumberOfDataEntries);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
|
@ -768,15 +760,15 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
|
|||
}
|
||||
|
||||
/* This flag is undocumented. Remove it before continuing */
|
||||
LocalLpcRequest.u2.s2.Type &= ~0x4000;
|
||||
CapturedLpcRequest.u2.s2.Type &= ~0x4000;
|
||||
|
||||
/* Check if this is an LPC Request */
|
||||
if (LpcpGetMessageType(&LocalLpcRequest) == LPC_REQUEST)
|
||||
if (LpcpGetMessageType(&CapturedLpcRequest) == LPC_REQUEST)
|
||||
{
|
||||
/* Then it's a callback */
|
||||
Callback = TRUE;
|
||||
}
|
||||
else if (LpcpGetMessageType(&LocalLpcRequest))
|
||||
else if (LpcpGetMessageType(&CapturedLpcRequest))
|
||||
{
|
||||
/* This is a not kernel-mode message */
|
||||
DPRINT1("Not a kernel-mode message!\n");
|
||||
|
@ -785,24 +777,24 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
|
|||
else
|
||||
{
|
||||
/* This is a kernel-mode message without a callback */
|
||||
LocalLpcRequest.u2.s2.Type |= LPC_REQUEST;
|
||||
CapturedLpcRequest.u2.s2.Type |= LPC_REQUEST;
|
||||
Callback = FALSE;
|
||||
}
|
||||
|
||||
/* Get the message type */
|
||||
MessageType = LocalLpcRequest.u2.s2.Type;
|
||||
MessageType = CapturedLpcRequest.u2.s2.Type;
|
||||
|
||||
/* Due to the above probe, we know that TotalLength is positive */
|
||||
ASSERT(LocalLpcRequest.u1.s1.TotalLength >= 0);
|
||||
ASSERT(CapturedLpcRequest.u1.s1.TotalLength >= 0);
|
||||
|
||||
/* Validate the length */
|
||||
if ((((ULONG)(USHORT)LocalLpcRequest.u1.s1.DataLength + sizeof(PORT_MESSAGE)) >
|
||||
(ULONG)LocalLpcRequest.u1.s1.TotalLength))
|
||||
if ((((ULONG)(USHORT)CapturedLpcRequest.u1.s1.DataLength + sizeof(PORT_MESSAGE)) >
|
||||
(ULONG)CapturedLpcRequest.u1.s1.TotalLength))
|
||||
{
|
||||
/* Fail */
|
||||
DPRINT1("Invalid message length: %u, %u\n",
|
||||
LocalLpcRequest.u1.s1.DataLength,
|
||||
LocalLpcRequest.u1.s1.TotalLength);
|
||||
CapturedLpcRequest.u1.s1.DataLength,
|
||||
CapturedLpcRequest.u1.s1.TotalLength);
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
|
@ -816,13 +808,13 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
|
|||
if (!NT_SUCCESS(Status)) return Status;
|
||||
|
||||
/* Validate the message length */
|
||||
if (((ULONG)LocalLpcRequest.u1.s1.TotalLength > Port->MaxMessageLength) ||
|
||||
((ULONG)LocalLpcRequest.u1.s1.TotalLength <= (ULONG)LocalLpcRequest.u1.s1.DataLength))
|
||||
if (((ULONG)CapturedLpcRequest.u1.s1.TotalLength > Port->MaxMessageLength) ||
|
||||
((ULONG)CapturedLpcRequest.u1.s1.TotalLength <= (ULONG)CapturedLpcRequest.u1.s1.DataLength))
|
||||
{
|
||||
/* Fail */
|
||||
DPRINT1("Invalid message length: %u, %u\n",
|
||||
LocalLpcRequest.u1.s1.DataLength,
|
||||
LocalLpcRequest.u1.s1.TotalLength);
|
||||
CapturedLpcRequest.u1.s1.DataLength,
|
||||
CapturedLpcRequest.u1.s1.TotalLength);
|
||||
ObDereferenceObject(Port);
|
||||
return STATUS_PORT_MESSAGE_TOO_LONG;
|
||||
}
|
||||
|
@ -874,7 +866,7 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle,
|
|||
}
|
||||
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
/* Fail */
|
||||
/* Cleanup and return the exception code */
|
||||
DPRINT1("Got exception!\n");
|
||||
LpcpFreeToPortZone(Message, 0);
|
||||
ObDereferenceObject(Port);
|
||||
|
|
Loading…
Reference in a new issue