From f475efbd85e6b9268e2fe6620f18cd66c73820a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Mon, 2 Sep 2013 21:09:56 +0000 Subject: [PATCH] [NTOS:LPC]: Code formatting, with hardocded_flags--; svn path=/trunk/; revision=59965 --- reactos/ntoskrnl/include/internal/lpc.h | 10 +++- reactos/ntoskrnl/lpc/close.c | 17 ++++--- reactos/ntoskrnl/lpc/reply.c | 16 ++++--- reactos/ntoskrnl/lpc/send.c | 61 +++++++++++++------------ 4 files changed, 59 insertions(+), 45 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/lpc.h b/reactos/ntoskrnl/include/internal/lpc.h index 34392c4c185..28bb3b31761 100644 --- a/reactos/ntoskrnl/include/internal/lpc.h +++ b/reactos/ntoskrnl/include/internal/lpc.h @@ -57,6 +57,12 @@ #define LPCP_THREAD_FLAGS (LPCP_THREAD_FLAG_IS_PORT | \ LPCP_THREAD_FLAG_NO_IMPERSONATION) +// +// LPC Locking Flags +// +#define LPCP_LOCK_OWNED 1 +#define LPCP_LOCK_RELEASE 2 + // // Internal Port Management // @@ -86,7 +92,7 @@ VOID NTAPI LpcpFreeToPortZone( IN PLPCP_MESSAGE Message, - IN ULONG Flags + IN ULONG LockFlags ); VOID @@ -104,7 +110,7 @@ NTAPI LpcpSaveDataInfoMessage( IN PLPCP_PORT_OBJECT Port, IN PLPCP_MESSAGE Message, - IN ULONG LockHeld + IN ULONG LockFlags ); // diff --git a/reactos/ntoskrnl/lpc/close.c b/reactos/ntoskrnl/lpc/close.c index 1d37b593b5b..eb301c46137 100644 --- a/reactos/ntoskrnl/lpc/close.c +++ b/reactos/ntoskrnl/lpc/close.c @@ -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_OWNED); + 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); @@ -183,7 +186,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_OWNED); NextEntry = Port->LpcReplyChainHead.Flink; } @@ -210,7 +213,7 @@ LpcpDestroyPortQueue(IN PLPCP_PORT_OBJECT Port, InitializeListHead(&Message->Entry); /* Remove it from the port zone */ - LpcpFreeToPortZone(Message, 1); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED); } /* Release the lock */ @@ -404,7 +407,7 @@ LpcpDeletePort(IN PVOID ObjectBody) /* Free queued messages */ RemoveEntryList(&Message->Entry); InitializeListHead(&Message->Entry); - LpcpFreeToPortZone(Message, 1); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED); /* Restart at the head */ NextEntry = ListHead->Flink; @@ -417,7 +420,7 @@ LpcpDeletePort(IN PVOID ObjectBody) /* Remove it */ RemoveEntryList(&Message->Entry); InitializeListHead(&Message->Entry); - LpcpFreeToPortZone(Message, 1); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED); /* Restart at the head */ NextEntry = ListHead->Flink; diff --git a/reactos/ntoskrnl/lpc/reply.c b/reactos/ntoskrnl/lpc/reply.c index d5ccd7a6ded..fa89d58970e 100644 --- a/reactos/ntoskrnl/lpc/reply.c +++ b/reactos/ntoskrnl/lpc/reply.c @@ -48,7 +48,7 @@ LpcpFreeDataInfoMessage(IN PLPCP_PORT_OBJECT Port, /* Unlink and free it */ RemoveEntryList(&Message->Entry); InitializeListHead(&Message->Entry); - LpcpFreeToPortZone(Message, 1); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED); break; } @@ -61,8 +61,10 @@ VOID NTAPI LpcpSaveDataInfoMessage(IN PLPCP_PORT_OBJECT Port, IN PLPCP_MESSAGE Message, - IN ULONG LockHeld) + IN ULONG LockFlags) { + BOOLEAN LockHeld = (LockFlags & LPCP_LOCK_OWNED); + PAGED_CODE(); /* Acquire the lock */ @@ -236,7 +238,7 @@ NtReplyPort(IN HANDLE PortHandle, Request) != LPC_REQUEST))) { /* It isn't, fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); if (ConnectionPort) ObDereferenceObject(ConnectionPort); ObDereferenceObject(WakeupThread); ObDereferenceObject(Port); @@ -255,7 +257,7 @@ NtReplyPort(IN HANDLE PortHandle, _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { /* Fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); ObDereferenceObject(WakeupThread); ObDereferenceObject(Port); _SEH2_YIELD(return _SEH2_GetExceptionCode()); @@ -480,7 +482,7 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle, Request) != LPC_REQUEST))) { /* It isn't, fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); if (ConnectionPort) ObDereferenceObject(ConnectionPort); ObDereferenceObject(WakeupThread); ObDereferenceObject(Port); @@ -637,7 +639,7 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle, if (Message->Request.u2.s2.DataInfoOffset) { /* It does, save it, and don't free the message below */ - LpcpSaveDataInfoMessage(Port, Message, 1); + LpcpSaveDataInfoMessage(Port, Message, LPCP_LOCK_OWNED); Message = NULL; } } @@ -659,7 +661,7 @@ NtReplyWaitReceivePortEx(IN HANDLE PortHandle, if (Message) { /* Free it and release the lock */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); } else { diff --git a/reactos/ntoskrnl/lpc/send.c b/reactos/ntoskrnl/lpc/send.c index 9cd5fb459ab..72ae7dde0ec 100644 --- a/reactos/ntoskrnl/lpc/send.c +++ b/reactos/ntoskrnl/lpc/send.c @@ -26,7 +26,10 @@ LpcRequestPort(IN PVOID PortObject, ULONG MessageType; PLPCP_MESSAGE Message; KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(); + PETHREAD Thread = PsGetCurrentThread(); + PAGED_CODE(); + LPCTRACE(LPC_SEND_DEBUG, "Port: %p. Message: %p\n", Port, LpcMessage); /* Check if this is a non-datagram message */ @@ -59,7 +62,7 @@ LpcRequestPort(IN PVOID PortObject, /* Can't have data information on this type of call */ if (LpcMessage->u2.s2.DataInfoOffset) return STATUS_INVALID_PARAMETER; - /* Validate message sizes */ + /* Validate the message length */ if (((ULONG)LpcMessage->u1.s1.TotalLength > Port->MaxMessageLength) || ((ULONG)LpcMessage->u1.s1.TotalLength <= (ULONG)LpcMessage->u1.s1.DataLength)) { @@ -80,7 +83,7 @@ LpcRequestPort(IN PVOID PortObject, LpcMessage, LpcMessage + 1, MessageType, - &PsGetCurrentThread()->Cid); + &Thread->Cid); /* Acquire the LPC lock */ KeAcquireGuardedMutex(&LpcpLock); @@ -101,7 +104,7 @@ LpcRequestPort(IN PVOID PortObject, if (!ConnectionPort) { /* Fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); return STATUS_PORT_DISCONNECTED; } } @@ -112,7 +115,7 @@ LpcRequestPort(IN PVOID PortObject, if (!ConnectionPort) { /* Fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); return STATUS_PORT_DISCONNECTED; } } @@ -136,7 +139,7 @@ LpcRequestPort(IN PVOID PortObject, Message->Request.CallbackId = 0; /* No Message ID for the thread */ - PsGetCurrentThread()->LpcReplyMessageId = 0; + Thread->LpcReplyMessageId = 0; /* Insert the message in our chain */ InsertTailList(&QueuePort->MsgQueue.ReceiveHead, &Message->Entry); @@ -161,7 +164,7 @@ LpcRequestPort(IN PVOID PortObject, } /* If we got here, then free the message and fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); if (ConnectionPort) ObDereferenceObject(ConnectionPort); return STATUS_PORT_DISCONNECTED; } @@ -281,7 +284,7 @@ LpcRequestWaitReplyPort(IN PVOID PortObject, if (!QueuePort) { /* We have no connected port, fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); return STATUS_PORT_DISCONNECTED; } @@ -297,7 +300,7 @@ LpcRequestWaitReplyPort(IN PVOID PortObject, if (!ConnectionPort) { /* Fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); return STATUS_PORT_DISCONNECTED; } } @@ -309,7 +312,7 @@ LpcRequestWaitReplyPort(IN PVOID PortObject, if (!ConnectionPort) { /* Fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); return STATUS_PORT_DISCONNECTED; } } @@ -409,9 +412,8 @@ LpcRequestWaitReplyPort(IN PVOID PortObject, Message->RepliedToThread = NULL; } - /* Free the message */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); } else { @@ -444,15 +446,16 @@ NTAPI NtRequestPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest) { - PLPCP_PORT_OBJECT Port, QueuePort, ConnectionPort = NULL; - KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(); NTSTATUS Status; - PLPCP_MESSAGE Message; - PETHREAD Thread = PsGetCurrentThread(); - - PKSEMAPHORE Semaphore; + PLPCP_PORT_OBJECT Port, QueuePort, ConnectionPort = NULL; ULONG MessageType; + PLPCP_MESSAGE Message; + KPROCESSOR_MODE PreviousMode = KeGetPreviousMode(); + PETHREAD Thread = PsGetCurrentThread(); + PKSEMAPHORE Semaphore; + PAGED_CODE(); + LPCTRACE(LPC_SEND_DEBUG, "Handle: %p. Message: %p. Type: %lx\n", PortHandle, @@ -505,10 +508,10 @@ NtRequestPort(IN HANDLE PortHandle, { /* Copy it */ LpcpMoveMessage(&Message->Request, - LpcRequest, - LpcRequest + 1, - MessageType, - &Thread->Cid); + LpcRequest, + LpcRequest + 1, + MessageType, + &Thread->Cid); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -533,7 +536,7 @@ NtRequestPort(IN HANDLE PortHandle, if (!QueuePort) { /* We have no connected port, fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); ObDereferenceObject(Port); return STATUS_PORT_DISCONNECTED; } @@ -547,7 +550,7 @@ NtRequestPort(IN HANDLE PortHandle, if (!ConnectionPort) { /* Fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); ObDereferenceObject(Port); return STATUS_PORT_DISCONNECTED; } @@ -560,7 +563,7 @@ NtRequestPort(IN HANDLE PortHandle, if (!ConnectionPort) { /* Fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); ObDereferenceObject(Port); return STATUS_PORT_DISCONNECTED; } @@ -587,7 +590,7 @@ NtRequestPort(IN HANDLE PortHandle, Message->Request.CallbackId = 0; /* No Message ID for the thread */ - PsGetCurrentThread()->LpcReplyMessageId = 0; + Thread->LpcReplyMessageId = 0; /* Insert the message in our chain */ InsertTailList(&QueuePort->MsgQueue.ReceiveHead, &Message->Entry); @@ -626,7 +629,7 @@ NtRequestPort(IN HANDLE PortHandle, Status); /* The wait failed, free the message */ - if (Message) LpcpFreeToPortZone(Message, 3); + if (Message) LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); ObDereferenceObject(Port); if (ConnectionPort) ObDereferenceObject(ConnectionPort); @@ -759,7 +762,7 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle, if (!QueuePort) { /* We have no connected port, fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); ObDereferenceObject(Port); return STATUS_PORT_DISCONNECTED; } @@ -776,7 +779,7 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle, if (!ConnectionPort) { /* Fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); ObDereferenceObject(Port); return STATUS_PORT_DISCONNECTED; } @@ -789,7 +792,7 @@ NtRequestWaitReplyPort(IN HANDLE PortHandle, if (!ConnectionPort) { /* Fail */ - LpcpFreeToPortZone(Message, 3); + LpcpFreeToPortZone(Message, LPCP_LOCK_OWNED | LPCP_LOCK_RELEASE); ObDereferenceObject(Port); return STATUS_PORT_DISCONNECTED; }