Author: hbelusca
Date: Mon Nov 7 00:55:34 2016
New Revision: 73162
URL:
http://svn.reactos.org/svn/reactos?rev=73162&view=rev
Log:
[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.
Modified:
trunk/reactos/ntoskrnl/lpc/close.c
trunk/reactos/ntoskrnl/lpc/complete.c
trunk/reactos/ntoskrnl/lpc/connect.c
trunk/reactos/ntoskrnl/lpc/create.c
trunk/reactos/ntoskrnl/lpc/listen.c
trunk/reactos/ntoskrnl/lpc/port.c
trunk/reactos/ntoskrnl/lpc/reply.c
trunk/reactos/ntoskrnl/lpc/send.c
Modified: trunk/reactos/ntoskrnl/lpc/close.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/close.c?rev=7…
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/close.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/close.c [iso-8859-1] Mon Nov 7 00:55:34 2016
@@ -116,6 +116,8 @@
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 @@
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 @@
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,9 +309,11 @@
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 @@
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);
Modified: trunk/reactos/ntoskrnl/lpc/complete.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/complete.c?re…
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/complete.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/complete.c [iso-8859-1] Mon Nov 7 00:55:34 2016
@@ -44,19 +44,20 @@
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 @@
NtCompleteConnectPort(IN HANDLE PortHandle)
{
NTSTATUS Status;
+ KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
PLPCP_PORT_OBJECT Port;
- KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
PETHREAD Thread;
+
PAGED_CODE();
LPCTRACE(LPC_COMPLETE_DEBUG, "Handle: %p\n", PortHandle);
@@ -462,7 +464,7 @@
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);
Modified: trunk/reactos/ntoskrnl/lpc/connect.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/connect.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/connect.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/connect.c [iso-8859-1] Mon Nov 7 00:55:34 2016
@@ -87,19 +87,20 @@
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;
+ PLPCP_MESSAGE Message;
+ PLPCP_CONNECTION_MESSAGE ConnectMessage;
+ ULONG PortMessageLength;
HANDLE Handle;
PVOID SectionToMap;
- PLPCP_MESSAGE Message;
- PLPCP_CONNECTION_MESSAGE ConnectMessage;
- PETHREAD Thread = PsGetCurrentThread();
- ULONG PortMessageLength;
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 @@
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 @@
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 @@
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 @@
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 @@
NULL,
PORT_ALL_ACCESS,
0,
- (PVOID *)NULL,
+ NULL,
&Handle);
if (NT_SUCCESS(Status))
{
Modified: trunk/reactos/ntoskrnl/lpc/create.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/create.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/create.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/create.c [iso-8859-1] Mon Nov 7 00:55:34 2016
@@ -19,11 +19,12 @@
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 @@
IN ULONG MaxPoolUsage,
IN BOOLEAN Waitable)
{
+ NTSTATUS Status;
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
- NTSTATUS Status;
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 @@
Port->MaxMessageLength = MaxMessageLength;
/* Insert it now */
- Status = ObInsertObject((PVOID)Port,
+ Status = ObInsertObject(Port,
NULL,
PORT_ALL_ACCESS,
0,
Modified: trunk/reactos/ntoskrnl/lpc/listen.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/listen.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/listen.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/listen.c [iso-8859-1] Mon Nov 7 00:55:34 2016
@@ -23,10 +23,11 @@
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 @@
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 @@
return Status;
}
-
/* EOF */
Modified: trunk/reactos/ntoskrnl/lpc/port.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/port.c?rev=73…
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/port.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/port.c [iso-8859-1] Mon Nov 7 00:55:34 2016
@@ -60,6 +60,7 @@
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 @@
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 @@
/* 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,24 +255,23 @@
/* Get rid of the security context */
SeDeleteClientSecurity(&ClientContext);
- goto Cleanup;
+Cleanup:
+
+ if (ConnectedPort != NULL)
+ ObDereferenceObject(ConnectedPort);
+
+ if (ClientThread != NULL)
+ ObDereferenceObject(ClientThread);
+
+ ObDereferenceObject(Port);
+
+ return Status;
CleanupWithLock:
/* Release the lock */
KeReleaseGuardedMutex(&LpcpLock);
-
-Cleanup:
-
- if (ConnectedPort != NULL)
- ObDereferenceObject(ConnectedPort);
-
- if (ClientThread != NULL)
- ObDereferenceObject(ClientThread);
-
- ObDereferenceObject(Port);
-
- return Status;
+ goto Cleanup;
}
NTSTATUS
Modified: trunk/reactos/ntoskrnl/lpc/reply.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/reply.c?rev=7…
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/reply.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/reply.c [iso-8859-1] Mon Nov 7 00:55:34 2016
@@ -99,6 +99,7 @@
{
PLPCP_MESSAGE Message;
PLIST_ENTRY ListEntry;
+
PAGED_CODE();
/* Check if the port we want is the connection port */
@@ -141,13 +142,14 @@
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 @@
NtReplyPort(IN HANDLE PortHandle,
IN PPORT_MESSAGE ReplyMessage)
{
+ NTSTATUS Status;
+ KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
+ // PORT_MESSAGE CapturedReplyMessage;
PLPCP_PORT_OBJECT Port;
- KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
- NTSTATUS Status;
PLPCP_MESSAGE Message;
PETHREAD Thread = PsGetCurrentThread(), WakeupThread;
- //PORT_MESSAGE CapturedReplyMessage;
PAGED_CODE();
LPCTRACE(LPC_REPLY_DEBUG,
@@ -274,8 +276,8 @@
/* 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 @@
}
_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 @@
OUT PPORT_MESSAGE ReceiveMessage,
IN PLARGE_INTEGER Timeout OPTIONAL)
{
+ NTSTATUS Status;
+ KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(), WaitMode = PreviousMode;
+ // PORT_MESSAGE CapturedReplyMessage;
+ LARGE_INTEGER CapturedTimeout;
PLPCP_PORT_OBJECT Port, ReceivePort, ConnectionPort = NULL;
- KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(), WaitMode = PreviousMode;
- NTSTATUS Status;
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 @@
/* 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 @@
}
/* 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 @@
IN ULONG Index,
IN PVOID Buffer,
IN ULONG BufferLength,
- OUT PULONG Returnlength)
-{
- KPROCESSOR_MODE PreviousMode;
+ OUT PULONG ReturnLength)
+{
+ 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 @@
DataInfoBaseAddress,
BufferLength,
PreviousMode,
- &LocalReturnlength);
+ &LocalReturnLength);
}
else
{
@@ -900,7 +902,7 @@
Buffer,
BufferLength,
PreviousMode,
- &LocalReturnlength);
+ &LocalReturnLength);
}
if (!NT_SUCCESS(Status))
@@ -910,16 +912,16 @@
}
/* 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 @@
}
/*
- * @unimplemented
+ * @implemented
*/
NTSTATUS
NTAPI
@@ -963,7 +965,7 @@
}
/*
- * @unimplemented
+ * @implemented
*/
NTSTATUS
NTAPI
Modified: trunk/reactos/ntoskrnl/lpc/send.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/send.c?rev=73…
==============================================================================
--- trunk/reactos/ntoskrnl/lpc/send.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/lpc/send.c [iso-8859-1] Mon Nov 7 00:55:34 2016
@@ -179,17 +179,17 @@
IN PPORT_MESSAGE LpcRequest,
OUT PPORT_MESSAGE LpcReply)
{
- PLPCP_PORT_OBJECT Port, QueuePort, ReplyPort, ConnectionPort = NULL;
+ NTSTATUS Status = STATUS_SUCCESS;
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
- NTSTATUS Status = STATUS_SUCCESS;
+ PETHREAD Thread = PsGetCurrentThread();
+ PLPCP_PORT_OBJECT Port = (PLPCP_PORT_OBJECT)PortObject;
+ PLPCP_PORT_OBJECT QueuePort, ReplyPort, ConnectionPort = NULL;
+ USHORT MessageType;
PLPCP_MESSAGE Message;
- PETHREAD Thread = PsGetCurrentThread();
BOOLEAN Callback = FALSE;
PKSEMAPHORE Semaphore;
- USHORT MessageType;
+
PAGED_CODE();
-
- Port = (PLPCP_PORT_OBJECT)PortObject;
LPCTRACE(LPC_SEND_DEBUG,
"Port: %p. Messages: %p/%p. Type: %lx\n",
@@ -205,33 +205,26 @@
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 @@
IN PPORT_MESSAGE LpcRequest)
{
NTSTATUS Status;
+ KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
+ PETHREAD Thread = PsGetCurrentThread();
+ PORT_MESSAGE CapturedLpcRequest;
PLPCP_PORT_OBJECT Port, QueuePort, ConnectionPort = NULL;
ULONG MessageType;
PLPCP_MESSAGE Message;
- KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
- PETHREAD Thread = PsGetCurrentThread();
- PORT_MESSAGE CapturedLpcRequest;
PAGED_CODE();
-
LPCTRACE(LPC_SEND_DEBUG,
"Handle: %p. Message: %p. Type: %lx\n",
PortHandle,
@@ -538,7 +530,7 @@
}
_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 @@
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 @@
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;
+ PLPCP_MESSAGE Message;
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
- NTSTATUS Status;
- PLPCP_MESSAGE Message;
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 @@
/* 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 @@
}
else
{
- LocalLpcRequest = *LpcRequest;
+ CapturedLpcRequest = *LpcRequest;
Status = LpcpVerifyMessageDataInfo(LpcRequest, &NumberOfDataEntries);
if (!NT_SUCCESS(Status))
{
@@ -768,15 +760,15 @@
}
/* 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 @@
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 @@
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 @@
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- /* Fail */
+ /* Cleanup and return the exception code */
DPRINT1("Got exception!\n");
LpcpFreeToPortZone(Message, 0);
ObDereferenceObject(Port);