Author: ion
Date: Thu Feb 16 06:57:27 2012
New Revision: 55626
URL:
http://svn.reactos.org/svn/reactos?rev=55626&view=rev
Log:
[CSRSRV]: Port the CsrWait* and CsrSession* APIs from CSRSRV2. Not yet used, so no real
functional change. Fixup a few structures where needed. Initalize session support during
CSRSRV initialization. We have a pretty good hybrid now, some few more changes here and
there and we can perhaps start having the beginnings our own "basesrv.dll",
Added:
trunk/reactos/subsystems/win32/csrss/csrsrv/session.c
- copied, changed from r55585, trunk/reactos/subsystems/csr/csrsrv/session.c
trunk/reactos/subsystems/win32/csrss/csrsrv/wait.c
- copied unchanged from r55585, trunk/reactos/subsystems/csr/csrsrv/wait.c
Modified:
trunk/reactos/subsystems/win32/csrss/csrsrv/CMakeLists.txt
trunk/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c
trunk/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rbuild
trunk/reactos/subsystems/win32/csrss/csrsrv/init.c
trunk/reactos/subsystems/win32/csrss/csrsrv/procsup.c
trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c
trunk/reactos/subsystems/win32/csrss/include/api.h
Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/CMakeLists.txt [iso-8859-1] Thu Feb 16
06:57:27 2012
@@ -11,6 +11,8 @@
procsup.c
thredsup.c
init.c
+ wait.c
+ session.c
${CMAKE_CURRENT_BINARY_DIR}/csrsrv.def)
add_library(csrsrv SHARED ${SOURCE})
Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c [iso-8859-1] Thu Feb 16
06:57:27 2012
@@ -986,6 +986,70 @@
RtlExitUserThread(STATUS_SUCCESS);
}
+/*++
+ * @name CsrReleaseCapturedArguments
+ * @implemented NT5.1
+ *
+ * The CsrReleaseCapturedArguments routine releases a Capture Buffer
+ * that was previously captured with CsrCaptureArguments.
+ *
+ * @param ApiMessage
+ * Pointer to the CSR API Message containing the Capture Buffer
+ * that needs to be released.
+ *
+ * @return None.
+ *
+ * @remarks None.
+ *
+ *--*/
+VOID
+NTAPI
+CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage)
+{
+ PCSR_CAPTURE_BUFFER RemoteCaptureBuffer, LocalCaptureBuffer;
+ SIZE_T BufferDistance;
+ ULONG PointerCount;
+ ULONG_PTR **PointerOffsets, *CurrentPointer;
+
+ /* Get the capture buffers */
+ RemoteCaptureBuffer = ApiMessage->CsrCaptureData;
+ LocalCaptureBuffer = RemoteCaptureBuffer->PreviousCaptureBuffer;
+
+ /* Free the previous one */
+ RemoteCaptureBuffer->PreviousCaptureBuffer = NULL;
+
+ /* Find out the difference between the two buffers */
+ BufferDistance = (ULONG_PTR)LocalCaptureBuffer - (ULONG_PTR)RemoteCaptureBuffer;
+
+ /* Save the pointer count and offset pointer */
+ PointerCount = RemoteCaptureBuffer->PointerCount;
+ PointerOffsets = (ULONG_PTR**)(RemoteCaptureBuffer + 1);
+
+ /* Start the loop */
+ while (PointerCount)
+ {
+ /* Get the current pointer */
+ CurrentPointer = *PointerOffsets++;
+ if (CurrentPointer)
+ {
+ /* Add it to the CSR Message structure */
+ CurrentPointer += (ULONG_PTR)ApiMessage;
+
+ /* Modify the pointer to take into account its new position */
+ *CurrentPointer += BufferDistance;
+ }
+
+ /* Move to the next Pointer */
+ PointerCount--;
+ }
+
+ /* Copy the data back */
+ RtlMoveMemory(LocalCaptureBuffer, RemoteCaptureBuffer,
RemoteCaptureBuffer->Size);
+
+ /* Free our allocated buffer */
+ RtlFreeHeap(CsrHeap, 0, RemoteCaptureBuffer);
+}
+
/* SESSION MANAGER FUNCTIONS**************************************************/
/*++
Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rbuild [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/csrsrv.rbuild [iso-8859-1] Thu Feb 16
06:57:27 2012
@@ -18,5 +18,7 @@
<file>procsup.c</file>
<file>thredsup.c</file>
<file>init.c</file>
+ <file>wait.c</file>
+ <file>session.c</file
<pch>srv.h</pch>
</module>
Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/init.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/init.c [iso-8859-1] Thu Feb 16 06:57:27
2012
@@ -1116,6 +1116,15 @@
__FUNCTION__, Status);
return Status;
}
+
+ /* Set up Session Support */
+ Status = CsrInitializeNtSessionList();
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("CSRSRV:%s: CsrInitializeSessions failed (Status=%08lx)\n",
+ __FUNCTION__, Status);
+ return Status;
+ }
/* Set up Process Support */
Status = CsrInitializeProcessStructure();
Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/procsup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/procsup.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/procsup.c [iso-8859-1] Thu Feb 16 06:57:27
2012
@@ -16,7 +16,7 @@
/* GLOBALS ********************************************************************/
-RTL_CRITICAL_SECTION ProcessDataLock, CsrWaitListsLock;
+RTL_CRITICAL_SECTION ProcessDataLock;
PCSR_PROCESS CsrRootProcess;
SECURITY_QUALITY_OF_SERVICE CsrSecurityQos =
{
Copied: trunk/reactos/subsystems/win32/csrss/csrsrv/session.c (from r55585,
trunk/reactos/subsystems/csr/csrsrv/session.c)
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
==============================================================================
--- trunk/reactos/subsystems/csr/csrsrv/session.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/session.c [iso-8859-1] Thu Feb 16 06:57:27
2012
@@ -17,25 +17,6 @@
RTL_CRITICAL_SECTION CsrNtSessionLock;
LIST_ENTRY CsrNtSessionList;
-HANDLE CsrSmApiPort;
-
-PSB_API_ROUTINE CsrServerSbApiDispatch[5] =
-{
- CsrSbCreateSession,
- CsrSbTerminateSession,
- CsrSbForeignSessionComplete,
- CsrSbCreateProcess,
- NULL
-};
-
-PCHAR CsrServerSbApiName[5] =
-{
- "SbCreateSession",
- "SbTerminateSession",
- "SbForeignSessionComplete",
- "SbCreateProcess",
- "Unknown Csr Sb Api Number"
-};
/* PRIVATE FUNCTIONS *********************************************************/
@@ -191,217 +172,4 @@
}
}
-
-/* SESSION MANAGER FUNCTIONS**************************************************/
-
-/*++
- * @name CsrSbCreateSession
- *
- * The CsrSbCreateSession API is called by the Session Manager whenever a new
- * session is created.
- *
- * @param ApiMessage
- * Pointer to the Session Manager API Message.
- *
- * @return TRUE in case of success, FALSE othwerwise.
- *
- * @remarks The CsrSbCreateSession routine will initialize a new CSR NT
- * Session and allocate a new CSR Process for the subsystem process.
- *
- *--*/
-BOOLEAN
-NTAPI
-CsrSbCreateSession(IN PSB_API_MSG ApiMessage)
-{
- PSB_CREATE_SESSION_MSG CreateSession = &ApiMessage->CreateSession;
- HANDLE hProcess, hThread;
- PCSR_PROCESS CsrProcess;
- NTSTATUS Status;
- KERNEL_USER_TIMES KernelTimes;
- PCSR_THREAD CsrThread;
- PVOID ProcessData;
- ULONG i;
-
- /* Save the Process and Thread Handles */
- hProcess = CreateSession->ProcessInfo.ProcessHandle;
- hThread = CreateSession->ProcessInfo.ThreadHandle;
-
- /* Lock the Processes */
- CsrAcquireProcessLock();
-
- /* Allocate a new process */
- CsrProcess = CsrAllocateProcess();
- if (!CsrProcess)
- {
- /* Fail */
- ApiMessage->ReturnValue = STATUS_NO_MEMORY;
- CsrReleaseProcessLock();
- return TRUE;
- }
-
- /* Set the exception port */
- Status = NtSetInformationProcess(hProcess,
- ProcessExceptionPort,
- &CsrApiPort,
- sizeof(HANDLE));
-
- /* Check for success */
- if (!NT_SUCCESS(Status))
- {
- /* Fail the request */
- CsrDeallocateProcess(CsrProcess);
- CsrReleaseProcessLock();
-
- /* Strange as it seems, NTSTATUSes are actually returned */
- return (BOOLEAN)STATUS_NO_MEMORY;
- }
-
- /* Get the Create Time */
- Status = NtQueryInformationThread(hThread,
- ThreadTimes,
- &KernelTimes,
- sizeof(KERNEL_USER_TIMES),
- NULL);
-
- /* Check for success */
- if (!NT_SUCCESS(Status))
- {
- /* Fail the request */
- CsrDeallocateProcess(CsrProcess);
- CsrReleaseProcessLock();
-
- /* Strange as it seems, NTSTATUSes are actually returned */
- return (BOOLEAN)Status;
- }
-
- /* Allocate a new Thread */
- CsrThread = CsrAllocateThread(CsrProcess);
- if (!CsrThread)
- {
- /* Fail the request */
- CsrDeallocateProcess(CsrProcess);
- ApiMessage->ReturnValue = STATUS_NO_MEMORY;
- CsrReleaseProcessLock();
- return TRUE;
- }
-
- /* Setup the Thread Object */
- CsrThread->CreateTime = KernelTimes.CreateTime;
- CsrThread->ClientId = CreateSession->ProcessInfo.ClientId;
- CsrThread->ThreadHandle = hThread;
- ProtectHandle(hThread);
- CsrThread->Flags = 0;
-
- /* Insert it into the Process List */
- CsrInsertThread(CsrProcess, CsrThread);
-
- /* Setup Process Data */
- CsrProcess->ClientId = CreateSession->ProcessInfo.ClientId;
- CsrProcess->ProcessHandle = hProcess;
- CsrProcess->NtSession = CsrAllocateNtSession(CreateSession->SessionId);
-
- /* Set the Process Priority */
- CsrSetBackgroundPriority(CsrProcess);
-
- /* Get the first data location */
- ProcessData = &CsrProcess->ServerData[CSR_SERVER_DLL_MAX];
-
- /* Loop every DLL */
- for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
- {
- /* Check if the DLL is loaded and has Process Data */
- if (CsrLoadedServerDll[i] &&
CsrLoadedServerDll[i]->SizeOfProcessData)
- {
- /* Write the pointer to the data */
- CsrProcess->ServerData[i] = ProcessData;
-
- /* Move to the next data location */
- ProcessData = (PVOID)((ULONG_PTR)ProcessData +
- CsrLoadedServerDll[i]->SizeOfProcessData);
- }
- else
- {
- /* Nothing for this Process */
- CsrProcess->ServerData[i] = NULL;
- }
- }
-
- /* Insert the Process */
- CsrInsertProcess(NULL, NULL, CsrProcess);
-
- /* Activate the Thread */
- ApiMessage->ReturnValue = NtResumeThread(hThread, NULL);
-
- /* Release lock and return */
- CsrReleaseProcessLock();
- return TRUE;
-}
-
-/*++
- * @name CsrSbForeignSessionComplete
- *
- * The CsrSbForeignSessionComplete API is called by the Session Manager
- * whenever a foreign session is completed (ie: terminated).
- *
- * @param ApiMessage
- * Pointer to the Session Manager API Message.
- *
- * @return TRUE in case of success, FALSE othwerwise.
- *
- * @remarks The CsrSbForeignSessionComplete API is not yet implemented.
- *
- *--*/
-BOOLEAN
-NTAPI
-CsrSbForeignSessionComplete(IN PSB_API_MSG ApiMessage)
-{
- /* Deprecated/Unimplemented in NT */
- ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
- return TRUE;
-}
-
-/*++
- * @name CsrSbTerminateSession
- *
- * The CsrSbTerminateSession API is called by the Session Manager
- * whenever a foreign session should be destroyed.
- *
- * @param ApiMessage
- * Pointer to the Session Manager API Message.
- *
- * @return TRUE in case of success, FALSE othwerwise.
- *
- * @remarks The CsrSbTerminateSession API is not yet implemented.
- *
- *--*/
-BOOLEAN
-NTAPI
-CsrSbTerminateSession(IN PSB_API_MSG ApiMessage)
-{
- ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
- return TRUE;
-}
-
-/*++
- * @name CsrSbCreateProcess
- *
- * The CsrSbCreateProcess API is called by the Session Manager
- * whenever a foreign session is created and a new process should be started.
- *
- * @param ApiMessage
- * Pointer to the Session Manager API Message.
- *
- * @return TRUE in case of success, FALSE othwerwise.
- *
- * @remarks The CsrSbCreateProcess API is not yet implemented.
- *
- *--*/
-BOOLEAN
-NTAPI
-CsrSbCreateProcess(IN PSB_API_MSG ApiMessage)
-{
- ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
- return TRUE;
-}
-
/* EOF */
Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csr…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/csrsrv/thredsup.c [iso-8859-1] Thu Feb 16
06:57:27 2012
@@ -407,4 +407,40 @@
return CsrThread;
}
+/*++
+ * @name CsrDereferenceThread
+ * @implemented NT4
+ *
+ * The CsrDereferenceThread routine removes a reference from a CSR Thread.
+ *
+ * @param CsrThread
+ * Pointer to the CSR Thread to dereference.
+ *
+ * @return None.
+ *
+ * @remarks If the reference count has reached zero (ie: the CSR Thread has
+ * no more active references), it will be deleted.
+ *
+ *--*/
+VOID
+NTAPI
+CsrDereferenceThread(IN PCSR_THREAD CsrThread)
+{
+ /* Acquire process lock */
+ CsrAcquireProcessLock();
+
+ /* Decrease reference count */
+ ASSERT(CsrThread->ReferenceCount > 0);
+ if (!(--CsrThread->ReferenceCount))
+ {
+ /* Call the generic cleanup code */
+ CsrThreadRefcountZero(CsrThread);
+ }
+ else
+ {
+ /* Just release the lock */
+ CsrReleaseProcessLock();
+ }
+}
+
/* EOF */
Modified: trunk/reactos/subsystems/win32/csrss/include/api.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/inc…
==============================================================================
--- trunk/reactos/subsystems/win32/csrss/include/api.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/csrss/include/api.h [iso-8859-1] Thu Feb 16 06:57:27
2012
@@ -21,6 +21,18 @@
#define CsrReleaseProcessLock() UNLOCK
#define ProcessStructureListLocked() \
(ProcessDataLock.OwningThread == NtCurrentTeb()->ClientId.UniqueThread)
+
+#define CsrAcquireWaitLock() \
+ RtlEnterCriticalSection(&CsrWaitListsLock);
+
+#define CsrReleaseWaitLock() \
+ RtlLeaveCriticalSection(&CsrWaitListsLock);
+
+#define CsrAcquireNtSessionLock() \
+ RtlEnterCriticalSection(&CsrNtSessionLock);
+
+#define CsrReleaseNtSessionLock() \
+ RtlLeaveCriticalSection(&CsrNtSessionLock);
typedef enum _CSR_THREAD_FLAGS
{
@@ -65,6 +77,13 @@
PCONTROLDISPATCHER CtrlDispatcher;
LIST_ENTRY ConsoleLink;
} CSRSS_CON_PROCESS_DATA, *PCSRSS_CON_PROCESS_DATA;
+
+typedef struct _CSR_NT_SESSION
+{
+ ULONG ReferenceCount;
+ LIST_ENTRY SessionLink;
+ ULONG SessionId;
+} CSR_NT_SESSION, *PCSR_NT_SESSION;
typedef struct _CSR_PROCESS
{
@@ -102,12 +121,35 @@
LIST_ENTRY HashLinks;
CLIENT_ID ClientId;
PCSR_PROCESS Process;
- //struct _CSR_WAIT_BLOCK *WaitBlock;
+ struct _CSR_WAIT_BLOCK *WaitBlock;
HANDLE ThreadHandle;
ULONG Flags;
ULONG ReferenceCount;
ULONG ImpersonationCount;
} CSR_THREAD, *PCSR_THREAD;
+
+typedef
+BOOLEAN
+(*CSR_WAIT_FUNCTION)(
+ IN PLIST_ENTRY WaitList,
+ IN PCSR_THREAD WaitThread,
+ IN PCSR_API_MESSAGE WaitApiMessage,
+ IN PVOID WaitContext,
+ IN PVOID WaitArgument1,
+ IN PVOID WaitArgument2,
+ IN ULONG WaitFlags
+);
+
+typedef struct _CSR_WAIT_BLOCK
+{
+ ULONG Size;
+ LIST_ENTRY WaitList;
+ LIST_ENTRY UserWaitList;
+ PVOID WaitContext;
+ PCSR_THREAD WaitThread;
+ CSR_WAIT_FUNCTION WaitFunction;
+ CSR_API_MESSAGE WaitApiMessage;
+} CSR_WAIT_BLOCK, *PCSR_WAIT_BLOCK;
typedef NTSTATUS (WINAPI *CSRSS_API_PROC)(PCSR_PROCESS ProcessData,
PCSR_API_MESSAGE Request);
@@ -167,6 +209,10 @@
VOID
NTAPI
+CsrDereferenceThread(IN PCSR_THREAD CsrThread);
+
+VOID
+NTAPI
CsrInsertProcess(IN PCSR_PROCESS Parent OPTIONAL,
IN PCSR_PROCESS CurrentProcess OPTIONAL,
IN PCSR_PROCESS CsrProcess);
@@ -179,6 +225,11 @@
VOID WINAPI CsrSbApiRequestThread (PVOID PortHandle);
VOID NTAPI ClientConnectionThread(HANDLE ServerPort);
+VOID
+NTAPI
+CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
+
+extern HANDLE CsrSmApiPort;
extern HANDLE CsrSbApiPort;
extern LIST_ENTRY CsrThreadHashTable[256];
extern PCSR_PROCESS CsrRootProcess;
@@ -211,6 +262,10 @@
//hack
VOID NTAPI CsrThreadRefcountZero(IN PCSR_THREAD CsrThread);
+NTSTATUS
+NTAPI
+CsrInitializeNtSessionList(VOID);
+
/* api/user.c */
CSR_API(CsrRegisterServicesProcess);