Author: ion Date: Mon Oct 30 17:17:37 2006 New Revision: 24664
URL: http://svn.reactos.org/svn/reactos?rev=24664&view=rev Log: - SMSS: Send QOS structure when creating new ports, it's not optional on NT LPC. Send maximum port length when creating new ports, it's not optional on NT LPC. Create 2 listening threads on NTLPC, instead of just one. [AUDIT: Unlock smlib, it's fully internal and specific to ROS without any relationship to NT. The author used clean-room tests and documentation]. - Fix various LPC structures in the NDK. Fix some prototypes too. - Don't export PEPORT or PLPCP_PORT_OBJECT outside of /lpc and use PVOID isntead. - Add a new RBUILD setting called NTLPC, which enables NTLPC when turned on.
Modified: trunk/reactos/base/system/smss/debug.c trunk/reactos/base/system/smss/smapi.c trunk/reactos/base/system/smss/smss.rbuild trunk/reactos/include/ndk/extypes.h trunk/reactos/include/ndk/lpcfuncs.h trunk/reactos/include/ndk/lpctypes.h trunk/reactos/include/ndk/psfuncs.h trunk/reactos/lib/smlib/compses.c (props changed) trunk/reactos/lib/smlib/connect.c (contents, props changed) trunk/reactos/lib/smlib/execpgm.c (props changed) trunk/reactos/lib/smlib/lookupss.c (props changed) trunk/reactos/lib/smlib/precomp.h (props changed) trunk/reactos/ntoskrnl/ex/error.c trunk/reactos/ntoskrnl/include/internal/lpc.h trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h trunk/reactos/ntoskrnl/lpc/send.c trunk/reactos/ntoskrnl/ntoskrnl.rbuild trunk/reactos/ntoskrnl/ps/process.c trunk/reactos/ntoskrnl/ps/query.c
Modified: trunk/reactos/base/system/smss/debug.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/smss/debug.c?re... ============================================================================== --- trunk/reactos/base/system/smss/debug.c (original) +++ trunk/reactos/base/system/smss/debug.c Mon Oct 30 17:17:37 2006 @@ -153,7 +153,7 @@ Status = SmpCreatePT(& DbgSsApiPort, SM_DBGSS_PORT_NAME, 0, /* MaxDataSize */ - 0, /* MaxMessageSize */ + sizeof(PORT_MESSAGE), /* MaxMessageSize */ 0, /* PoolCharge */ DbgSsApiPortThread, & hDbgSsApiPortThread); @@ -166,7 +166,7 @@ Status = SmpCreatePT(& DbgUiApiPort, SM_DBGUI_PORT_NAME, 0, /* MaxDataSize */ - 0, /* MaxMessageSize */ + sizeof(PORT_MESSAGE), /* MaxMessageSize */ 0, /* PoolCharge */ DbgUiApiPortThread, NULL);
Modified: trunk/reactos/base/system/smss/smapi.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/smss/smapi.c?re... ============================================================================== --- trunk/reactos/base/system/smss/smapi.c (original) +++ trunk/reactos/base/system/smss/smapi.c Mon Oct 30 17:17:37 2006 @@ -44,10 +44,8 @@ return (PSM_CONNECT_DATA)(PortMessage + 1); }
-#if !defined(__USE_NT_LPC__) NTSTATUS STDCALL SmpHandleConnectionRequest (PSM_PORT_MESSAGE Request); -#endif
/********************************************************************** * SmpCallbackServer/2 @@ -68,6 +66,7 @@ ULONG CallbackPortNameLength = SM_SB_NAME_MAX_LENGTH; /* TODO: compute length */ SB_CONNECT_DATA SbConnectData; ULONG SbConnectDataLength = sizeof SbConnectData; + SECURITY_QUALITY_OF_SERVICE SecurityQos;
DPRINT("SM: %s called\n", __FUNCTION__);
@@ -84,10 +83,15 @@ RtlInitUnicodeString (& CallbackPortName, ClientData->SbApiPortName);
+ SecurityQos.Length = sizeof (SecurityQos); + SecurityQos.ImpersonationLevel = SecurityIdentification; + SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING; + SecurityQos.EffectiveOnly = TRUE; + SbConnectData.SmApiMax = (sizeof SmApi / sizeof SmApi[0]); Status = NtConnectPort (& ClientData->SbApiPort, & CallbackPortName, - NULL, + &SecurityQos, NULL, NULL, NULL, @@ -245,7 +249,7 @@ } } DPRINT("SM: %s: before NtAcceptConnectPort\n", __FUNCTION__); -#if defined(__USE_NT_LPC__) +#if defined(NTLPC) Status = NtAcceptConnectPort (ClientDataApiPort, Context, (PPORT_MESSAGE) Request, @@ -276,7 +280,7 @@ __FUNCTION__, Status); return Status; } -#if !defined(__USE_NT_LPC__) /* ReactOS LPC */ +#if !defined(NTLPC) /* ReactOS LPC */ DPRINT("SM: %s: server side comm port thread (ROS LPC)\n", __FUNCTION__); Status = RtlCreateUserThread(NtCurrentProcess(), NULL, @@ -369,8 +373,8 @@
Status = NtCreatePort(&SmApiPort, &ObjectAttributes, - 0, - 0, + sizeof(SM_CONNECT_DATA), + sizeof(SM_PORT_MESSAGE), 0); if (!NT_SUCCESS(Status)) { @@ -386,11 +390,35 @@ 0, 0, 0, +#ifdef NTLPC + (PTHREAD_START_ROUTINE)SmpApiConnectedThread, + &SmApiPort, +#else (PTHREAD_START_ROUTINE)SmpApiThread, (PVOID)SmApiPort, +#endif NULL, NULL);
+#ifdef NTLPC + // + // On NT LPC, we need a second thread to handle incoming connections + // generated by incoming requests, otherwise the thread handling + // the request will be busy sending the LPC message, without any other + // thread being busy to receive the LPC message. + // + Status = RtlCreateUserThread(NtCurrentProcess(), + NULL, + FALSE, + 0, + 0, + 0, + (PTHREAD_START_ROUTINE)SmpApiConnectedThread, + &SmApiPort, + NULL, + NULL); +#endif + return(Status); }
Modified: trunk/reactos/base/system/smss/smss.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/smss/smss.rbuil... ============================================================================== --- trunk/reactos/base/system/smss/smss.rbuild (original) +++ trunk/reactos/base/system/smss/smss.rbuild Mon Oct 30 17:17:37 2006 @@ -3,6 +3,9 @@ <include base="ReactOS">include/reactos/subsys</include> <define name="__USE_W32API" /> <define name="_DISABLE_TIDENTS" /> + <if property="NTLPC" value="1"> + <define name="NTLPC" /> + </if> <library>nt</library> <library>smlib</library> <library>ntdll</library>
Modified: trunk/reactos/include/ndk/extypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/extypes.h?rev=2... ============================================================================== --- trunk/reactos/include/ndk/extypes.h (original) +++ trunk/reactos/include/ndk/extypes.h Mon Oct 30 17:17:37 2006 @@ -185,7 +185,9 @@ ResponseNo, ResponseOk, ResponseRetry, - ResponseYes + ResponseYes, + ResponseTryAgain, + ResponseContinue } HARDERROR_RESPONSE, *PHARDERROR_RESPONSE;
//
Modified: trunk/reactos/include/ndk/lpcfuncs.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/lpcfuncs.h?rev=... ============================================================================== --- trunk/reactos/include/ndk/lpcfuncs.h (original) +++ trunk/reactos/include/ndk/lpcfuncs.h Mon Oct 30 17:17:37 2006 @@ -34,8 +34,15 @@ LpcRequestWaitReplyPort( IN PVOID Port, IN PPORT_MESSAGE LpcMessageRequest, - OUT PPORT_MESSAGE LpcMessageReply) -; + OUT PPORT_MESSAGE LpcMessageReply +); + +NTSTATUS +NTAPI +LpcRequestPort( + IN PVOID Port, + IN PPORT_MESSAGE LpcMessage +); #endif
//
Modified: trunk/reactos/include/ndk/lpctypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/lpctypes.h?rev=... ============================================================================== --- trunk/reactos/include/ndk/lpctypes.h (original) +++ trunk/reactos/include/ndk/lpctypes.h Mon Oct 30 17:17:37 2006 @@ -39,7 +39,21 @@ // // Port Object Access Masks // +#define PORT_CONNECT 0x1 #define PORT_ALL_ACCESS 0x1 + +// +// Port Object Flags +// +#define LPCP_CONNECTION_PORT 0x00000001 +#define LPCP_UNCONNECTED_PORT 0x00000002 +#define LPCP_COMMUNICATION_PORT 0x00000003 +#define LPCP_CLIENT_PORT 0x00000004 +#define LPCP_PORT_TYPE_MASK 0x0000000F +#define LPCP_PORT_DELETED 0x10000000 +#define LPCP_WAITABLE_PORT 0x20000000 +#define LPCP_NAME_DELETED 0x40000000 +#define LPCP_SECURITY_DYNAMIC 0x80000000
// // LPC Message Types @@ -170,7 +184,7 @@ typedef struct _LPCP_PORT_QUEUE { PLPCP_NONPAGED_PORT_QUEUE NonPagedPortQueue; - KSEMAPHORE Semaphore; + PKSEMAPHORE Semaphore; LIST_ENTRY ReceiveHead; } LPCP_PORT_QUEUE, *PLPCP_PORT_QUEUE;
@@ -179,8 +193,6 @@ // typedef struct _LPCP_PORT_OBJECT { - ULONG Length; - ULONG Flags; struct _LPCP_PORT_OBJECT *ConnectionPort; struct _LPCP_PORT_OBJECT *ConnectedPort; LPCP_PORT_QUEUE MsgQueue; @@ -188,13 +200,17 @@ PVOID ClientSectionBase; PVOID ServerSectionBase; PVOID PortContext; - ULONG MaxMessageLength; - ULONG MaxConnectionInfoLength; PETHREAD ClientThread; SECURITY_QUALITY_OF_SERVICE SecurityQos; SECURITY_CLIENT_CONTEXT StaticSecurity; LIST_ENTRY LpcReplyChainHead; LIST_ENTRY LpcDataInfoChainHead; + PEPROCESS ServerProcess; + PEPROCESS MappingProcess; + ULONG MaxMessageLength; + ULONG MaxConnectionInfoLength; + ULONG Flags; + KEVENT WaitEvent; } LPCP_PORT_OBJECT, *PLPCP_PORT_OBJECT;
//
Modified: trunk/reactos/include/ndk/psfuncs.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/psfuncs.h?rev=2... ============================================================================== --- trunk/reactos/include/ndk/psfuncs.h (original) +++ trunk/reactos/include/ndk/psfuncs.h Mon Oct 30 17:17:37 2006 @@ -109,6 +109,14 @@ HANDLE NTAPI PsGetProcessId(PEPROCESS Process); + +NTSTATUS +NTAPI +PsLookupProcessThreadByCid( + IN PCLIENT_ID Cid, + OUT PEPROCESS *Process OPTIONAL, + OUT PETHREAD *Thread +);
#endif
Propchange: trunk/reactos/lib/smlib/compses.c ------------------------------------------------------------------------------ --- svn:needs-lock (original) +++ svn:needs-lock (removed) @@ -1,1 +1,0 @@ -*
Modified: trunk/reactos/lib/smlib/connect.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/smlib/connect.c?rev=246... ============================================================================== --- trunk/reactos/lib/smlib/connect.c (original) +++ trunk/reactos/lib/smlib/connect.c Mon Oct 30 17:17:37 2006 @@ -78,7 +78,7 @@
SecurityQos.Length = sizeof (SecurityQos); SecurityQos.ImpersonationLevel = SecurityIdentification; - SecurityQos.ContextTrackingMode = TRUE; + SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING; SecurityQos.EffectiveOnly = TRUE;
RtlInitUnicodeString (& SmApiPortName, SM_API_PORT_NAME);
Propchange: trunk/reactos/lib/smlib/connect.c ------------------------------------------------------------------------------ --- svn:needs-lock (original) +++ svn:needs-lock (removed) @@ -1,1 +1,0 @@ -*
Propchange: trunk/reactos/lib/smlib/execpgm.c ------------------------------------------------------------------------------ --- svn:needs-lock (original) +++ svn:needs-lock (removed) @@ -1,1 +1,0 @@ -*
Propchange: trunk/reactos/lib/smlib/lookupss.c ------------------------------------------------------------------------------ --- svn:needs-lock (original) +++ svn:needs-lock (removed) @@ -1,1 +1,0 @@ -*
Propchange: trunk/reactos/lib/smlib/precomp.h ------------------------------------------------------------------------------ --- svn:needs-lock (original) +++ svn:needs-lock (removed) @@ -1,1 +1,0 @@ -*
Modified: trunk/reactos/ntoskrnl/ex/error.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/error.c?rev=246... ============================================================================== --- trunk/reactos/ntoskrnl/ex/error.c (original) +++ trunk/reactos/ntoskrnl/ex/error.c Mon Oct 30 17:17:37 2006 @@ -17,7 +17,7 @@ /* GLOBALS ****************************************************************/
BOOLEAN ExReadyForErrors = FALSE; -PEPORT ExpDefaultErrorPort = NULL; +PVOID ExpDefaultErrorPort = NULL; PEPROCESS ExpDefaultErrorPortProcess = NULL;
/* FUNCTIONS ****************************************************************/
Modified: trunk/reactos/ntoskrnl/include/internal/lpc.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/l... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/lpc.h (original) +++ trunk/reactos/ntoskrnl/include/internal/lpc.h Mon Oct 30 17:17:37 2006 @@ -20,7 +20,9 @@
extern POBJECT_TYPE LpcPortObjectType; extern ULONG LpcpNextMessageId; +#ifndef NTLPC extern FAST_MUTEX LpcpLock; +#endif
typedef struct _EPORT_LISTENER { @@ -73,13 +75,6 @@ LIST_ENTRY QueueListEntry; PORT_MESSAGE Message; } QUEUEDMESSAGE, *PQUEUEDMESSAGE; - -NTSTATUS -NTAPI -LpcRequestPort( - PEPORT Port, - PPORT_MESSAGE LpcMessage -);
NTSTATUS NTAPI
Modified: trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/n... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ntoskrnl.h Mon Oct 30 17:17:37 2006 @@ -175,7 +175,7 @@ { NTSTATUS Status = STATUS_SUCCESS;
- if (Class >= 0 && Class < ClassListEntries) + if (Class < ClassListEntries) { if (!(ClassList[Class].Flags & ICIF_SET)) { @@ -226,7 +226,7 @@ { NTSTATUS Status = STATUS_SUCCESS;
- if (Class >= 0 && Class < ClassListEntries) + if (Class < ClassListEntries) { if (!(ClassList[Class].Flags & ICIF_QUERY)) {
Modified: trunk/reactos/ntoskrnl/lpc/send.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/lpc/send.c?rev=246... ============================================================================== --- trunk/reactos/ntoskrnl/lpc/send.c (original) +++ trunk/reactos/ntoskrnl/lpc/send.c Mon Oct 30 17:17:37 2006 @@ -34,10 +34,11 @@ * * @implemented */ -NTSTATUS STDCALL LpcRequestPort (IN PEPORT Port, +NTSTATUS STDCALL LpcRequestPort (IN PVOID PortObject, IN PPORT_MESSAGE LpcMessage) { NTSTATUS Status; + PEPORT Port = (PEPORT)PortObject;
DPRINT("LpcRequestPort(PortHandle %08x, LpcMessage %08x)\n", Port, LpcMessage);
Modified: trunk/reactos/ntoskrnl/ntoskrnl.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl.rbuild?re... ============================================================================== --- trunk/reactos/ntoskrnl/ntoskrnl.rbuild (original) +++ trunk/reactos/ntoskrnl/ntoskrnl.rbuild Mon Oct 30 17:17:37 2006 @@ -9,6 +9,9 @@ <define name="__NO_CTYPE_INLINES" /> <define name="__USE_W32API" /> <define name="WIN9X_COMPAT_SPINLOCK" /> + <if property="NTLPC" value="1"> + <define name="NTLPC" /> + </if> <include base="cmlib">.</include> <include base="ntoskrnl">include</include> <include base="ReactOS">include/reactos/drivers</include> @@ -220,19 +223,35 @@ <file>loader.c</file> <file>rtl.c</file> </directory> - <directory name="lpc"> - <file>close.c</file> - <file>complete.c</file> - <file>connect.c</file> - <file>create.c</file> - <file>listen.c</file> - <file>port.c</file> - <file>query.c</file> - <file>queue.c</file> - <file>receive.c</file> - <file>reply.c</file> - <file>send.c</file> - </directory> + <if property="NTLPC" value="0"> + <directory name="lpc"> + <file>close.c</file> + <file>complete.c</file> + <file>connect.c</file> + <file>create.c</file> + <file>listen.c</file> + <file>port.c</file> + <file>query.c</file> + <file>queue.c</file> + <file>receive.c</file> + <file>reply.c</file> + <file>send.c</file> + </directory> + </if> + <if property="NTLPC" value="1"> + <directory name="lpc"> + <directory name="ntlpc"> + <file>close.c</file> + <file>complete.c</file> + <file>connect.c</file> + <file>create.c</file> + <file>listen.c</file> + <file>port.c</file> + <file>reply.c</file> + <file>send.c</file> + </directory> + </directory> + </if> <directory name="mm"> <if property="ARCH" value="i386"> <directory name="i386">
Modified: trunk/reactos/ntoskrnl/ps/process.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/process.c?rev=2... ============================================================================== --- trunk/reactos/ntoskrnl/ps/process.c (original) +++ trunk/reactos/ntoskrnl/ps/process.c Mon Oct 30 17:17:37 2006 @@ -361,7 +361,7 @@ { HANDLE hProcess; PEPROCESS Process, Parent; - PEPORT ExceptionPortObject; + PVOID ExceptionPortObject; PDEBUG_OBJECT DebugObject; PSECTION_OBJECT SectionObject; NTSTATUS Status, AccessStatus;
Modified: trunk/reactos/ntoskrnl/ps/query.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/query.c?rev=246... ============================================================================== --- trunk/reactos/ntoskrnl/ps/query.c (original) +++ trunk/reactos/ntoskrnl/ps/query.c Mon Oct 30 17:17:37 2006 @@ -486,7 +486,7 @@ HANDLE PortHandle = NULL; HANDLE TokenHandle = NULL; PROCESS_SESSION_INFORMATION SessionInfo = {0}; - PEPORT ExceptionPort; + PVOID ExceptionPort; PAGED_CODE();
/* Verify Information Class validity */