From: Emanuele Aliberti Date: Mon, 2 Feb 2004 23:48:42 +0000 (+0000) Subject: LPC: initial work on NT/ROS compatibility. X-Git-Tag: backups/avendor@12434^2~39 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=3356caccb30516f464cc36c2b132a134c8862f97 LPC: initial work on NT/ROS compatibility. svn path=/trunk/; revision=8007 --- diff --git a/reactos/include/ntos/zwtypes.h b/reactos/include/ntos/zwtypes.h index 1a68143c320..f0ce6d51971 100755 --- a/reactos/include/ntos/zwtypes.h +++ b/reactos/include/ntos/zwtypes.h @@ -1704,6 +1704,8 @@ typedef struct _LPC_MESSAGE ULONG SectionSize; /* CallbackID */ } LPC_MESSAGE, *PLPC_MESSAGE; +typedef LPC_MESSAGE PORT_MESSAGE, *PPORT_MESSAGE; + #define MAX_MESSAGE_DATA (0x130) typedef struct _LPC_MAX_MESSAGE @@ -1712,6 +1714,8 @@ typedef struct _LPC_MAX_MESSAGE BYTE Data[MAX_MESSAGE_DATA]; } LPC_MAX_MESSAGE, *PLPC_MAX_MESSAGE; +typedef LPC_MAX_MESSAGE PORT_MAX_MESSAGE, *PPORT_MAX_MESSAGE; + #define PORT_MESSAGE_TYPE(m) (LPC_TYPE)((m).Header.MessageType) #define PORT_MAX_DATA_LENGTH 0x104 diff --git a/reactos/ntoskrnl/include/internal/port.h b/reactos/ntoskrnl/include/internal/port.h index 8830fef0dad..a857ef7adc9 100644 --- a/reactos/ntoskrnl/include/internal/port.h +++ b/reactos/ntoskrnl/include/internal/port.h @@ -11,9 +11,11 @@ typedef struct _EPORT { KSPIN_LOCK Lock; KSEMAPHORE Semaphore; - - ULONG State; - + + USHORT Type; + USHORT State; + + struct _EPORT * RequestPort; struct _EPORT * OtherPort; ULONG QueueLength; @@ -69,6 +71,11 @@ STDCALL LpcSendTerminationPort (PEPORT Port, TIME CreationTime); +/* EPORT.Type */ + +#define EPORT_TYPE_SERVER_RQST_PORT (0) +#define EPORT_TYPE_SERVER_COMM_PORT (1) +#define EPORT_TYPE_CLIENT_COMM_PORT (2) /* EPORT.State */ @@ -125,7 +132,9 @@ NiCreatePort (PVOID ObjectBody, /* Code in ntoskrnl/lpc/port.c */ NTSTATUS STDCALL -NiInitializePort (IN OUT PEPORT Port); +NiInitializePort (IN OUT PEPORT Port, + IN USHORT Type, + IN PEPORT Parent OPTIONAL); NTSTATUS NiInitPort (VOID); diff --git a/reactos/ntoskrnl/lpc/complete.c b/reactos/ntoskrnl/lpc/complete.c index f1427cabe02..3f4c0fd0d17 100644 --- a/reactos/ntoskrnl/lpc/complete.c +++ b/reactos/ntoskrnl/lpc/complete.c @@ -1,4 +1,4 @@ -/* $Id: complete.c,v 1.10 2003/12/30 18:52:05 fireball Exp $ +/* $Id: complete.c,v 1.11 2004/02/02 23:48:42 ea Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -23,34 +23,62 @@ /*********************************************************************** * NAME EXPORTED - * NtCompleteConnectPort@4 + * NtCompleteConnectPort/1 * + * DESCRIPTION + * Wake up the client thread that issued the NtConnectPort call + * this server-side port was created for communicating with. + * To be used in LPC servers processes on reply ports only. + * + * ARGUMENTS + * hServerSideCommPort: a reply port handle returned by + * NtAcceptConnectPort. + * + * RETURN VALUE + * STATUS_SUCCESS or an error code from Ob. */ -/*EXPORTED*/ NTSTATUS STDCALL -NtCompleteConnectPort (HANDLE PortHandle) +NTSTATUS STDCALL +NtCompleteConnectPort (HANDLE hServerSideCommPort) { NTSTATUS Status; - PEPORT OurPort; - - DPRINT("NtCompleteConnectPort(PortHandle %x)\n", PortHandle); + PEPORT ReplyPort; - Status = ObReferenceObjectByHandle (PortHandle, + DPRINT("NtCompleteConnectPort(hServerSideCommPort %x)\n", hServerSideCommPort); + + /* + * Ask Ob to translate the port handle to EPORT + */ + Status = ObReferenceObjectByHandle (hServerSideCommPort, PORT_ALL_ACCESS, ExPortType, UserMode, - (PVOID*)&OurPort, + (PVOID*)&ReplyPort, NULL); if (!NT_SUCCESS(Status)) { return (Status); } + /* + * Verify EPORT type is a server-side reply port; + * otherwise tell the caller the port handle is not + * valid. + */ + if (ReplyPort->Type != EPORT_TYPE_SERVER_COMM_PORT) + { + ObDereferenceObject (ReplyPort); + return STATUS_INVALID_PORT_HANDLE; + } - OurPort->State = EPORT_CONNECTED_SERVER; - - KeReleaseSemaphore(&OurPort->OtherPort->Semaphore, IO_NO_INCREMENT, 1, + ReplyPort->State = EPORT_CONNECTED_SERVER; + /* + * Wake up the client thread that issued NtConnectPort. + */ + KeReleaseSemaphore(&ReplyPort->OtherPort->Semaphore, IO_NO_INCREMENT, 1, FALSE); - - ObDereferenceObject (OurPort); + /* + * Tell Ob we are no more interested in ReplyPort + */ + ObDereferenceObject (ReplyPort); return (STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/lpc/connect.c b/reactos/ntoskrnl/lpc/connect.c index 0a12bad8f36..c2066be4677 100644 --- a/reactos/ntoskrnl/lpc/connect.c +++ b/reactos/ntoskrnl/lpc/connect.c @@ -1,4 +1,4 @@ -/* $Id: connect.c,v 1.24 2004/02/01 18:19:28 ea Exp $ +/* $Id: connect.c,v 1.25 2004/02/02 23:48:42 ea Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -86,7 +86,7 @@ EiConnectPort(IN PEPORT* ConnectedPort, { return (Status); } - NiInitializePort(OurPort); + NiInitializePort(OurPort, EPORT_TYPE_CLIENT_COMM_PORT, NamedPort); /* * Allocate a request message. @@ -600,7 +600,7 @@ NtAcceptConnectPort (PHANDLE ServerPortHandle, return(Status); } - NiInitializePort(OurPort); + NiInitializePort(OurPort, EPORT_TYPE_SERVER_COMM_PORT, NamedPort); } /* diff --git a/reactos/ntoskrnl/lpc/create.c b/reactos/ntoskrnl/lpc/create.c index 034a9ddc05f..56856f98053 100644 --- a/reactos/ntoskrnl/lpc/create.c +++ b/reactos/ntoskrnl/lpc/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.15 2004/02/01 18:19:28 ea Exp $ +/* $Id: create.c,v 1.16 2004/02/02 23:48:42 ea Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -163,7 +163,7 @@ NtCreatePort (PHANDLE PortHandle, return (Status); } - Status = NiInitializePort (Port); + Status = NiInitializePort (Port, EPORT_TYPE_SERVER_RQST_PORT, NULL); Port->MaxConnectInfoLength = PORT_MAX_DATA_LENGTH; Port->MaxDataLength = PORT_MAX_MESSAGE_LENGTH; diff --git a/reactos/ntoskrnl/lpc/port.c b/reactos/ntoskrnl/lpc/port.c index 77af0657327..d370116b4e0 100644 --- a/reactos/ntoskrnl/lpc/port.c +++ b/reactos/ntoskrnl/lpc/port.c @@ -1,4 +1,4 @@ -/* $Id: port.c,v 1.16 2003/12/14 17:44:02 hbirr Exp $ +/* $Id: port.c,v 1.17 2004/02/02 23:48:42 ea Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -89,18 +89,28 @@ NiInitPort (VOID) * otherwise. */ NTSTATUS STDCALL -NiInitializePort (IN OUT PEPORT Port) +NiInitializePort (IN OUT PEPORT Port, + IN USHORT Type, + IN PEPORT Parent OPTIONAL) { + if ((Type != EPORT_TYPE_SERVER_RQST_PORT) && + (Type != EPORT_TYPE_SERVER_COMM_PORT) && + (Type != EPORT_TYPE_CLIENT_COMM_PORT)) + { + return STATUS_INVALID_PARAMETER_2; + } memset (Port, 0, sizeof(EPORT)); KeInitializeSpinLock (& Port->Lock); KeInitializeSemaphore( &Port->Semaphore, 0, LONG_MAX ); + Port->RequestPort = Parent; Port->OtherPort = NULL; Port->QueueLength = 0; Port->ConnectQueueLength = 0; + Port->Type = Type; Port->State = EPORT_INACTIVE; InitializeListHead (& Port->QueueListHead); InitializeListHead (& Port->ConnectQueueListHead); - + return (STATUS_SUCCESS); }