[CSRSS/CSRSRV]

- Rename ProcessDataLock to CsrProcessLock (as it was in the "old" csrsrv, see r57579).
- Merge the APIs from the "old" csrsrv (subsystems/csr , see r57579) with the other ones (subsystems/win32/csrss/csrsrv).
- Reorganize the functions into Private & Public functions.
- Add temporary comments.
- Start removing things which should be present in basesrv instead of in csrsrv.

This breaks build of this branch at the moment...

svn path=/branches/ros-csrss/; revision=57580
This commit is contained in:
Hermès Bélusca-Maïto 2012-10-20 13:00:41 +00:00
parent 13811a0034
commit f40ade26d9
9 changed files with 1227 additions and 943 deletions

View file

@ -1,8 +1,7 @@
include_directories(
include
${REACTOS_SOURCE_DIR}/include/reactos/subsys
${REACTOS_SOURCE_DIR}/include/reactos/drivers)
${REACTOS_SOURCE_DIR}/include/reactos/subsys)
add_executable(csrss csrss.c csrss.rc)

View file

@ -489,271 +489,6 @@ CreateBaseAcls(OUT PACL* Dacl,
return Status;
}
VOID
WINAPI
BasepFakeStaticServerData(VOID)
{
NTSTATUS Status;
WCHAR Buffer[MAX_PATH];
PWCHAR HeapBuffer;
UNICODE_STRING SystemRootString;
UNICODE_STRING UnexpandedSystemRootString = RTL_CONSTANT_STRING(L"%SystemRoot%");
UNICODE_STRING BaseSrvCSDString;
UNICODE_STRING BaseSrvWindowsDirectory;
UNICODE_STRING BaseSrvWindowsSystemDirectory;
UNICODE_STRING BnoString;
OBJECT_ATTRIBUTES ObjectAttributes;
ULONG SessionId;
HANDLE BaseSrvNamedObjectDirectory;
HANDLE BaseSrvRestrictedObjectDirectory;
PACL BnoDacl, BnoRestrictedDacl;
PSECURITY_DESCRIPTOR BnoSd;
HANDLE SymHandle;
UNICODE_STRING DirectoryName, SymlinkName;
ULONG LuidEnabled;
RTL_QUERY_REGISTRY_TABLE BaseServerRegistryConfigurationTable[2] =
{
{
NULL,
RTL_QUERY_REGISTRY_DIRECT,
L"CSDVersion",
&BaseSrvCSDString
},
{0}
};
/* Get the session ID */
SessionId = NtCurrentPeb()->SessionId;
/* Get the Windows directory */
RtlInitEmptyUnicodeString(&SystemRootString, Buffer, sizeof(Buffer));
Status = RtlExpandEnvironmentStrings_U(NULL,
&UnexpandedSystemRootString,
&SystemRootString,
NULL);
ASSERT(NT_SUCCESS(Status));
/* Create the base directory */
Buffer[SystemRootString.Length / sizeof(WCHAR)] = UNICODE_NULL;
Status = RtlCreateUnicodeString(&BaseSrvWindowsDirectory,
SystemRootString.Buffer);
ASSERT(NT_SUCCESS(Status));
/* Create the system directory */
wcscat(SystemRootString.Buffer, L"\\system32");
Status = RtlCreateUnicodeString(&BaseSrvWindowsSystemDirectory,
SystemRootString.Buffer);
ASSERT(NT_SUCCESS(Status));
/* FIXME: Check Session ID */
wcscpy(Buffer, L"\\BaseNamedObjects");
RtlInitUnicodeString(&BnoString, Buffer);
/* Allocate the server data */
BaseStaticServerData = RtlAllocateHeap(CsrSrvSharedSectionHeap,
HEAP_ZERO_MEMORY,
sizeof(BASE_STATIC_SERVER_DATA));
ASSERT(BaseStaticServerData != NULL);
/* Process timezone information */
BaseStaticServerData->TermsrvClientTimeZoneId = TIME_ZONE_ID_INVALID;
BaseStaticServerData->TermsrvClientTimeZoneChangeNum = 0;
Status = NtQuerySystemInformation(SystemTimeOfDayInformation,
&BaseStaticServerData->TimeOfDay,
sizeof(BaseStaticServerData->TimeOfDay),
NULL);
ASSERT(NT_SUCCESS(Status));
/* Make a shared heap copy of the Windows directory */
BaseStaticServerData->WindowsDirectory = BaseSrvWindowsDirectory;
HeapBuffer = RtlAllocateHeap(CsrSrvSharedSectionHeap,
0,
BaseSrvWindowsDirectory.MaximumLength);
ASSERT(HeapBuffer);
RtlCopyMemory(HeapBuffer,
BaseStaticServerData->WindowsDirectory.Buffer,
BaseSrvWindowsDirectory.MaximumLength);
BaseStaticServerData->WindowsDirectory.Buffer = HeapBuffer;
/* Make a shared heap copy of the System directory */
BaseStaticServerData->WindowsSystemDirectory = BaseSrvWindowsSystemDirectory;
HeapBuffer = RtlAllocateHeap(CsrSrvSharedSectionHeap,
0,
BaseSrvWindowsSystemDirectory.MaximumLength);
ASSERT(HeapBuffer);
RtlCopyMemory(HeapBuffer,
BaseStaticServerData->WindowsSystemDirectory.Buffer,
BaseSrvWindowsSystemDirectory.MaximumLength);
BaseStaticServerData->WindowsSystemDirectory.Buffer = HeapBuffer;
/* This string is not used */
RtlInitEmptyUnicodeString(&BaseStaticServerData->WindowsSys32x86Directory,
NULL,
0);
/* Make a shared heap copy of the BNO directory */
BaseStaticServerData->NamedObjectDirectory = BnoString;
BaseStaticServerData->NamedObjectDirectory.MaximumLength = BnoString.Length +
sizeof(UNICODE_NULL);
HeapBuffer = RtlAllocateHeap(CsrSrvSharedSectionHeap,
0,
BaseStaticServerData->NamedObjectDirectory.MaximumLength);
ASSERT(HeapBuffer);
RtlCopyMemory(HeapBuffer,
BaseStaticServerData->NamedObjectDirectory.Buffer,
BaseStaticServerData->NamedObjectDirectory.MaximumLength);
BaseStaticServerData->NamedObjectDirectory.Buffer = HeapBuffer;
/*
* Confirmed that in Windows, CSDNumber and RCNumber are actually Length
* and MaximumLength of the CSD String, since the same UNICODE_STRING is
* being queried twice, the first time as a ULONG!
*
* Somehow, in Windows this doesn't cause a buffer overflow, but it might
* in ReactOS, so this code is disabled until someone figures out WTF.
*/
BaseStaticServerData->CSDNumber = 0;
BaseStaticServerData->RCNumber = 0;
/* Initialize the CSD string and query its value from the registry */
RtlInitEmptyUnicodeString(&BaseSrvCSDString, Buffer, sizeof(Buffer));
Status = RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT,
L"",
BaseServerRegistryConfigurationTable,
NULL,
NULL);
if (NT_SUCCESS(Status))
{
/* Copy into the shared buffer */
wcsncpy(BaseStaticServerData->CSDVersion,
BaseSrvCSDString.Buffer,
BaseSrvCSDString.Length / sizeof(WCHAR));
}
else
{
/* NULL-terminate to indicate nothing is there */
BaseStaticServerData->CSDVersion[0] = UNICODE_NULL;
}
/* Cache the system information */
Status = NtQuerySystemInformation(SystemBasicInformation,
&BaseStaticServerData->SysInfo,
sizeof(BaseStaticServerData->SysInfo),
NULL);
ASSERT(NT_SUCCESS(Status));
/* FIXME: Should query the registry for these */
BaseStaticServerData->DefaultSeparateVDM = FALSE;
BaseStaticServerData->IsWowTaskReady = FALSE;
/* Allocate a security descriptor and create it */
BnoSd = RtlAllocateHeap(CsrHeap, 0, 1024);
ASSERT(BnoSd);
Status = RtlCreateSecurityDescriptor(BnoSd, SECURITY_DESCRIPTOR_REVISION);
ASSERT(NT_SUCCESS(Status));
/* Create the BNO and \Restricted DACLs */
Status = CreateBaseAcls(&BnoDacl, &BnoRestrictedDacl);
ASSERT(NT_SUCCESS(Status));
/* Set the BNO DACL as active for now */
Status = RtlSetDaclSecurityDescriptor(BnoSd, TRUE, BnoDacl, FALSE);
ASSERT(NT_SUCCESS(Status));
/* Create the BNO directory */
RtlInitUnicodeString(&BnoString, L"\\BaseNamedObjects");
InitializeObjectAttributes(&ObjectAttributes,
&BnoString,
OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
NULL,
BnoSd);
Status = NtCreateDirectoryObject(&BaseSrvNamedObjectDirectory,
DIRECTORY_ALL_ACCESS,
&ObjectAttributes);
ASSERT(NT_SUCCESS(Status));
/* Check if we are session 0 */
if (!SessionId)
{
/* Mark this as a session 0 directory */
Status = NtSetInformationObject(BaseSrvNamedObjectDirectory,
ObjectSessionInformation,
NULL,
0);
ASSERT(NT_SUCCESS(Status));
}
/* Check if LUID device maps are enabled */
Status = NtQueryInformationProcess(NtCurrentProcess(),
ProcessLUIDDeviceMapsEnabled,
&LuidEnabled,
sizeof(LuidEnabled),
NULL);
ASSERT(NT_SUCCESS(Status));
BaseStaticServerData->LUIDDeviceMapsEnabled = LuidEnabled;
if (!BaseStaticServerData->LUIDDeviceMapsEnabled)
{
/* Make Global point back to BNO */
RtlInitUnicodeString(&DirectoryName, L"Global");
RtlInitUnicodeString(&SymlinkName, L"\\BaseNamedObjects");
InitializeObjectAttributes(&ObjectAttributes,
&DirectoryName,
OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
BaseSrvNamedObjectDirectory,
BnoSd);
Status = NtCreateSymbolicLinkObject(&SymHandle,
SYMBOLIC_LINK_ALL_ACCESS,
&ObjectAttributes,
&SymlinkName);
if ((NT_SUCCESS(Status)) && !(SessionId)) NtClose(SymHandle);
/* Make local point back to \Sessions\x\BNO */
RtlInitUnicodeString(&DirectoryName, L"Local");
ASSERT(SessionId == 0);
InitializeObjectAttributes(&ObjectAttributes,
&DirectoryName,
OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
BaseSrvNamedObjectDirectory,
BnoSd);
Status = NtCreateSymbolicLinkObject(&SymHandle,
SYMBOLIC_LINK_ALL_ACCESS,
&ObjectAttributes,
&SymlinkName);
if ((NT_SUCCESS(Status)) && !(SessionId)) NtClose(SymHandle);
/* Make Session point back to BNOLINKS */
RtlInitUnicodeString(&DirectoryName, L"Session");
RtlInitUnicodeString(&SymlinkName, L"\\Sessions\\BNOLINKS");
InitializeObjectAttributes(&ObjectAttributes,
&DirectoryName,
OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
BaseSrvNamedObjectDirectory,
BnoSd);
Status = NtCreateSymbolicLinkObject(&SymHandle,
SYMBOLIC_LINK_ALL_ACCESS,
&ObjectAttributes,
&SymlinkName);
if ((NT_SUCCESS(Status)) && !(SessionId)) NtClose(SymHandle);
/* Create the BNO\Restricted directory and set the restricted DACL */
RtlInitUnicodeString(&DirectoryName, L"Restricted");
Status = RtlSetDaclSecurityDescriptor(BnoSd, TRUE, BnoRestrictedDacl, FALSE);
ASSERT(NT_SUCCESS(Status));
InitializeObjectAttributes(&ObjectAttributes,
&DirectoryName,
OBJ_OPENIF | OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
BaseSrvNamedObjectDirectory,
BnoSd);
Status = NtCreateDirectoryObject(&BaseSrvRestrictedObjectDirectory,
DIRECTORY_ALL_ACCESS,
&ObjectAttributes);
ASSERT(NT_SUCCESS(Status));
}
/* Finally, set the pointer */
CsrSrvSharedStaticServerData[CSR_CONSOLE] = BaseStaticServerData;
}
NTSTATUS WINAPI
CsrpHandleConnectionRequest(PPORT_MESSAGE Request)
{

View file

@ -1,36 +1,36 @@
@ stdcall CsrAddStaticServerThread(ptr ptr long)
@ stdcall CsrCallServerFromServer(ptr ptr)
;@ stdcall CsrConnectToUser()
;@ stdcall CsrCreateProcess(ptr ptr ptr ptr long ptr)
@ stdcall CsrConnectToUser()
@ stdcall CsrCreateProcess(ptr ptr ptr ptr long ptr)
@ stdcall CsrCreateRemoteThread(ptr ptr)
@ stdcall CsrCreateThread(ptr ptr ptr)
;@ stdcall CsrCreateWait(ptr ptr ptr ptr ptr ptr)
;@ stdcall CsrDebugProcess(ptr)
;@ stdcall CsrDebugProcessStop(ptr)
;@ stdcall CsrDereferenceProcess(ptr)
;@ stdcall CsrDereferenceThread(ptr)
;@ stdcall CsrDereferenceWait(ptr)
;@ stdcall CsrDestroyProcess(ptr long)
;@ stdcall CsrDestroyThread(ptr)
@ stdcall CsrEnumProcesses(ptr ptr) ; Temporary hack
;@ stdcall CsrExecServerThread(ptr long)
@ stdcall CsrCreateThread(ptr ptr ptr) ;;; @ stdcall CsrCreateThread(ptr ptr ptr long) ??
@ stdcall CsrCreateWait(ptr ptr ptr ptr ptr ptr)
@ stdcall CsrDebugProcess(ptr)
@ stdcall CsrDebugProcessStop(ptr)
@ stdcall CsrDereferenceProcess(ptr)
@ stdcall CsrDereferenceThread(ptr)
@ stdcall CsrDereferenceWait(ptr)
@ stdcall CsrDestroyProcess(ptr long)
@ stdcall CsrDestroyThread(ptr)
@ stdcall CsrEnumProcesses(ptr ptr) ;;;;;;; Temporary hack used in win32csr, to be removed
@ stdcall CsrExecServerThread(ptr long)
@ stdcall CsrGetProcessLuid(ptr ptr)
@ stdcall CsrImpersonateClient(ptr)
@ stdcall CsrLockProcessByClientId(ptr ptr)
;@ stdcall CsrLockThreadByClientId(ptr ptr)
;@ stdcall CsrMoveSatisfiedWait(ptr ptr)
;@ stdcall CsrNotifyWait(ptr long ptr ptr)
;@ stdcall CsrPopulateDosDevices()
;@ stdcall CsrQueryApiPort()
;@ stdcall CsrReferenceThread(ptr)
@ stdcall CsrLockThreadByClientId(ptr ptr)
@ stdcall CsrMoveSatisfiedWait(ptr ptr)
@ stdcall CsrNotifyWait(ptr long ptr ptr)
@ stdcall CsrPopulateDosDevices()
@ stdcall CsrQueryApiPort()
@ stdcall CsrReferenceThread(ptr)
@ stdcall CsrRevertToSelf()
@ stdcall CsrServerInitialization(long ptr)
;@ stdcall CsrSetBackgroundPriority(ptr)
;@ stdcall CsrSetCallingSpooler(long)
;@ stdcall CsrSetForegroundPriority(ptr)
;@ stdcall CsrShutdownProcesses(ptr long)
;@ stdcall CsrUnhandledExceptionFilter(ptr)
@ stdcall CsrSetBackgroundPriority(ptr)
@ stdcall CsrSetCallingSpooler(long)
@ stdcall CsrSetForegroundPriority(ptr)
@ stdcall CsrShutdownProcesses(ptr long)
@ stdcall CsrUnhandledExceptionFilter(ptr)
@ stdcall CsrUnlockProcess(ptr)
;@ stdcall CsrUnlockThread(ptr)
;@ stdcall CsrValidateMessageBuffer(ptr ptr long long)
;@ stdcall CsrValidateMessageString(ptr ptr)
@ stdcall CsrUnlockThread(ptr)
@ stdcall CsrValidateMessageBuffer(ptr ptr long long)
@ stdcall CsrValidateMessageString(ptr ptr)

View file

@ -1,6 +1,6 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CSR Sub System
* PROJECT: ReactOS CSR SubSystem
* FILE: subsystems/win32/csrss/csrsrv/init.c
* PURPOSE: CSR Server DLL Initialization
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
@ -10,6 +10,7 @@
/* INCLUDES *******************************************************************/
#include "srv.h"
#define NDEBUG
#include <debug.h>
@ -40,7 +41,7 @@ VOID
CallHardError(IN PCSR_THREAD ThreadData,
IN PHARDERROR_MSG HardErrorMessage)
{
unsigned i;
ULONG i;
PCSR_SERVER_DLL ServerDll;
DPRINT("CSR: %s called\n", __FUNCTION__);
@ -64,7 +65,7 @@ CallProcessCreated(IN PCSR_PROCESS SourceProcessData,
IN PCSR_PROCESS TargetProcessData)
{
NTSTATUS Status = STATUS_SUCCESS;
unsigned i;
ULONG i;
PCSR_SERVER_DLL ServerDll;
DPRINT("CSR: %s called\n", __FUNCTION__);
@ -85,8 +86,14 @@ CallProcessCreated(IN PCSR_PROCESS SourceProcessData,
return Status;
}
/***
*** Some APIs from here will go to basesrv.dll, some others to winsrv.dll.
*** Furthermore, this structure uses the old definition of APIs list.
*** The new one is in fact three arrays, one of APIs pointers, one other of
*** corresponding indexes, and the third one of names (not very efficient...).
***/
CSRSS_API_DEFINITION NativeDefinitions[] =
{
{
CSRSS_DEFINE_API(CREATE_PROCESS, CsrSrvCreateProcess),
CSRSS_DEFINE_API(CREATE_THREAD, CsrSrvCreateThread),
CSRSS_DEFINE_API(TERMINATE_PROCESS, CsrTerminateProcess),
@ -95,14 +102,10 @@ CSRSS_API_DEFINITION NativeDefinitions[] =
CSRSS_DEFINE_API(GET_SHUTDOWN_PARAMETERS, CsrGetShutdownParameters),
CSRSS_DEFINE_API(SET_SHUTDOWN_PARAMETERS, CsrSetShutdownParameters),
{ 0, 0, NULL }
};
};
/* === INIT ROUTINES === */
VOID
WINAPI
BasepFakeStaticServerData(VOID);
/*++
* @name CsrSetProcessSecurity
*
@ -640,9 +643,10 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
ParameterValue = NULL;
ParameterValue = strchr(ParameterName, '=');
if (ParameterValue) *ParameterValue++ = ANSI_NULL;
DPRINT1("Name=%s, Value=%s\n", ParameterName, ParameterValue);
/* Check for Object Directory */
if (!_stricmp(ParameterName, "ObjectDirectory"))
if (_stricmp(ParameterName, "ObjectDirectory") == 0)
{
/* Check if a session ID is specified */
if (SessionId)
@ -674,26 +678,26 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
Status = CsrSetDirectorySecurity(CsrObjectDirectory);
if (!NT_SUCCESS(Status)) return Status;
}
else if (!_stricmp(ParameterName, "SubSystemType"))
else if (_stricmp(ParameterName, "SubSystemType") == 0)
{
/* Ignored */
}
else if (!_stricmp(ParameterName, "MaxRequestThreads"))
else if (_stricmp(ParameterName, "MaxRequestThreads") == 0)
{
Status = RtlCharToInteger(ParameterValue,
0,
&CsrMaxApiRequestThreads);
}
else if (!_stricmp(ParameterName, "RequestThreads"))
else if (_stricmp(ParameterName, "RequestThreads") == 0)
{
/* Ignored */
Status = STATUS_SUCCESS;
}
else if (!_stricmp(ParameterName, "ProfileControl"))
else if (_stricmp(ParameterName, "ProfileControl") == 0)
{
/* Ignored */
}
else if (!_stricmp(ParameterName, "SharedSection"))
else if (_stricmp(ParameterName, "SharedSection") == 0)
{
/* Create the Section */
Status = CsrSrvCreateSharedSection(ParameterValue);
@ -705,9 +709,9 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
}
/* Load us */
Status = CsrLoadServerDll("CSRSS", NULL, CSR_SRV_SERVER);
Status = CsrLoadServerDll("CSRSS" /* "CSRSRV" */, NULL, CSR_SRV_SERVER);
}
else if (!_stricmp(ParameterName, "ServerDLL"))
else if (_stricmp(ParameterName, "ServerDLL") == 0)
{
/* Loop the command line */
EntryPoint = NULL;
@ -743,19 +747,7 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
/* Load it */
if (CsrDebug & 1) DPRINT1("CSRSS: Loading ServerDll=%s:%s\n", ParameterValue, EntryPoint);
/* Hackito ergo sum */
Status = STATUS_SUCCESS;
if (strstr(ParameterValue, "basesrv"))
{
DPRINT1("Fake basesrv init\n");
BasepFakeStaticServerData();
}
// else
// {
// Status = CsrLoadServerDll(ParameterValue, EntryPoint, 2);
// }
// Status = CsrLoadServerDll(ParameterValue, EntryPoint, DllIndex);
Status = CsrLoadServerDll(ParameterValue, EntryPoint, DllIndex);
if (!NT_SUCCESS(Status))
{
DPRINT1("CSRSS: *** Failed loading ServerDll=%s (Status == 0x%x)\n",
@ -763,9 +755,10 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
return Status;
}
}
else if (!_stricmp(ParameterName, "Windows"))
else if (_stricmp(ParameterName, "Windows") == 0)
{
/* Ignored */
// Check whether we want to start in pure GUI or pure CLI.
}
else
{
@ -945,6 +938,8 @@ CsrSbApiPortInitialize(VOID)
return Status;
}
/* PUBLIC FUNCTIONS ***********************************************************/
/*++
@ -1053,12 +1048,16 @@ CsrServerInitialization(IN ULONG ArgumentCount,
return Status;
}
/* Initialize Win32csr */
//////////////////////////// ADDED ////////////////////////////
/*
/\* Initialize Win32csr *\/
Status = CsrLoadServerDll("win32csr", "Win32CsrInitialization", 2);
if (!NT_SUCCESS(Status))
{
DPRINT1("CSRSRV failed in %s with status %lx\n", "CsrLoadServerDll", Status);
}
*/
//////////////////////////// END ADDED ////////////////////////////
/* Initialize the API Port for SM communication */
Status = CsrSbApiPortInitialize();
@ -1138,6 +1137,7 @@ DllMain(IN HANDLE hDll,
UNREFERENCED_PARAMETER(hDll);
UNREFERENCED_PARAMETER(dwReason);
UNREFERENCED_PARAMETER(lpReserved);
return TRUE;
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CSR Sub System
* PROJECT: ReactOS CSR SubSystem
* FILE: subsystems/win32/csrss/csrsrv/session.c
* PURPOSE: CSR Server DLL Session Implementation
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
@ -18,6 +18,16 @@
RTL_CRITICAL_SECTION CsrNtSessionLock;
LIST_ENTRY CsrNtSessionList;
// Does it exist a enumeration associated with it ?
PSB_API_ROUTINE CsrServerSbApiDispatch[5] =
{
CsrSbCreateSession,
CsrSbTerminateSession,
CsrSbForeignSessionComplete,
CsrSbCreateProcess,
NULL
};
PCHAR CsrServerSbApiName[5] =
{
"SbCreateSession",
@ -208,8 +218,8 @@ CsrSbCreateSession(IN PSB_API_MSG ApiMessage)
NTSTATUS Status;
KERNEL_USER_TIMES KernelTimes;
PCSR_THREAD CsrThread;
//PVOID ProcessData;
//ULONG i;
PVOID ProcessData;
ULONG i;
/* Save the Process and Thread Handles */
hProcess = CreateSession->ProcessInfo.ProcessHandle;
@ -292,7 +302,7 @@ CsrSbCreateSession(IN PSB_API_MSG ApiMessage)
/* Set the Process Priority */
CsrSetBackgroundPriority(CsrProcess);
#if 0
/* Get the first data location */
ProcessData = &CsrProcess->ServerData[CSR_SERVER_DLL_MAX];
@ -315,10 +325,10 @@ CsrSbCreateSession(IN PSB_API_MSG ApiMessage)
CsrProcess->ServerData[i] = NULL;
}
}
#else
/* HACKZ: should go in BaseSrv part of CreateCallback done in Insert below */
RtlInitializeCriticalSection(&CsrProcess->HandleTableLock);
#endif
/* HACK: FIXME: should go in BaseSrv part of CreateCallback done in Insert below */
// RtlInitializeCriticalSection(&CsrProcess->HandleTableLock);
/* Insert the Process */
CsrInsertProcess(NULL, NULL, CsrProcess);
@ -397,15 +407,6 @@ CsrSbCreateProcess(IN PSB_API_MSG ApiMessage)
return TRUE;
}
PSB_API_ROUTINE CsrServerSbApiDispatch[5] =
{
CsrSbCreateSession,
CsrSbTerminateSession,
CsrSbForeignSessionComplete,
CsrSbCreateProcess,
NULL
};
/*++
* @name CsrSbApiHandleConnectionRequest
*

View file

@ -1,10 +1,10 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CSR Sub System
* PROJECT: ReactOS CSR SubSystem
* FILE: subsystems/win32/csrss/csrsrv/thredsup.c
* PURPOSE: CSR Server DLL Thread Implementation
* PURPOSE: CSR Server DLL Thread Management
* PROGRAMMERS: ReactOS Portable Systems Group
* Alex Ionescu
* Alex Ionescu (alex@relsoft.net)
*/
/* INCLUDES *******************************************************************/
@ -21,7 +21,8 @@
LIST_ENTRY CsrThreadHashTable[256];
/* FUNCTIONS ******************************************************************/
/* PRIVATE FUNCTIONS **********************************************************/
/*++
* @name ProtectHandle
@ -201,6 +202,7 @@ CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL,
FoundThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, HashLinks);
/* Compare the CID */
// FIXME: if (*(PULONGLONG)&FoundThread->ClientId == *(PULONGLONG)ClientId)
if (FoundThread->ClientId.UniqueThread == ClientId->UniqueThread)
{
/* Match found, return the process */
@ -389,6 +391,87 @@ CsrRemoveThread(IN PCSR_THREAD CsrThread)
CsrThread->Flags |= CsrThreadInTermination;
}
/*++
* @name CsrThreadRefcountZero
*
* The CsrThreadRefcountZero routine is executed when a CSR Thread has lost
* all its active references. It removes and de-allocates the CSR Thread.
*
* @param CsrThread
* Pointer to the CSR Thread that is to be deleted.
*
* @return None.
*
* @remarks Do not call this routine. It is reserved for the internal
* thread management routines when a CSR Thread has lost all
* its references.
*
* This routine is called with the Process Lock held.
*
*--*/
VOID
NTAPI
CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
{
PCSR_PROCESS CsrProcess = CsrThread->Process;
NTSTATUS Status;
ASSERT(ProcessStructureListLocked());
/* Remove this thread */
CsrRemoveThread(CsrThread);
/* Release the Process Lock */
CsrReleaseProcessLock();
/* Close the NT Thread Handle */
if (CsrThread->ThreadHandle)
{
UnProtectHandle(CsrThread->ThreadHandle);
Status = NtClose(CsrThread->ThreadHandle);
ASSERT(NT_SUCCESS(Status));
}
/* De-allocate the CSR Thread Object */
CsrDeallocateThread(CsrThread);
/* Remove a reference from the process */
CsrDereferenceProcess(CsrProcess);
}
/*++
* @name CsrLockedDereferenceThread
*
* The CsrLockedDereferenceThread dereferences a CSR Thread while the
* Process Lock is already being held.
*
* @param CsrThread
* Pointer to the CSR Thread to be dereferenced.
*
* @return None.
*
* @remarks This routine will return with the Process Lock held.
*
*--*/
VOID
NTAPI
CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
{
LONG LockCount;
/* Decrease reference count */
LockCount = --CsrThread->ReferenceCount;
ASSERT(LockCount >= 0);
if (!LockCount)
{
/* Call the generic cleanup code */
CsrThreadRefcountZero(CsrThread);
CsrAcquireProcessLock();
}
}
/* PUBLIC FUNCTIONS ***********************************************************/
/*++
* @name CsrCreateRemoteThread
* @implemented NT4
@ -490,53 +573,6 @@ CsrCreateRemoteThread(IN HANDLE hThread,
return STATUS_SUCCESS;
}
/*++
* @name CsrThreadRefcountZero
*
* The CsrThreadRefcountZero routine is executed when a CSR Thread has lost
* all its active references. It removes and de-allocates the CSR Thread.
*
* @param CsrThread
* Pointer to the CSR Thread that is to be deleted.
*
* @return None.
*
* @remarks Do not call this routine. It is reserved for the internal
* thread management routines when a CSR Thread has lost all
* its references.
*
* This routine is called with the Process Lock held.
*
*--*/
VOID
NTAPI
CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
{
PCSR_PROCESS CsrProcess = CsrThread->Process;
NTSTATUS Status;
ASSERT(ProcessStructureListLocked());
/* Remove this thread */
CsrRemoveThread(CsrThread);
/* Release the Process Lock */
CsrReleaseProcessLock();
/* Close the NT Thread Handle */
if (CsrThread->ThreadHandle)
{
UnProtectHandle(CsrThread->ThreadHandle);
Status = NtClose(CsrThread->ThreadHandle);
ASSERT(NT_SUCCESS(Status));
}
/* De-allocate the CSR Thread Object */
CsrDeallocateThread(CsrThread);
/* Remove a reference from the process */
CsrDereferenceProcess(CsrProcess);
}
/*++
* @name CsrDestroyThread
* @implemented NT4
@ -606,37 +642,6 @@ CsrDestroyThread(IN PCLIENT_ID Cid)
return STATUS_SUCCESS;
}
/*++
* @name CsrLockedDereferenceThread
*
* The CsrLockedDereferenceThread dereferences a CSR Thread while the
* Process Lock is already being held.
*
* @param CsrThread
* Pointer to the CSR Thread to be dereferenced.
*
* @return None.
*
* @remarks This routine will return with the Process Lock held.
*
*--*/
VOID
NTAPI
CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
{
LONG LockCount;
/* Decrease reference count */
LockCount = --CsrThread->ReferenceCount;
ASSERT(LockCount >= 0);
if (!LockCount)
{
/* Call the generic cleanup code */
CsrThreadRefcountZero(CsrThread);
CsrAcquireProcessLock();
}
}
/*++
* @name CsrCreateThread
* @implemented NT4
@ -662,6 +667,79 @@ CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
*--*/
NTSTATUS
NTAPI
#if 0
CsrCreateThread(IN PCSR_PROCESS CsrProcess,
IN HANDLE hThread,
IN PCLIENT_ID ClientId,
IN BOOLEAN HaveClient)
{
NTSTATUS Status;
PCSR_THREAD CsrThread, CurrentThread;
PCSR_PROCESS CurrentProcess;
CLIENT_ID CurrentCid;
KERNEL_USER_TIMES KernelTimes;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
if (HaveClient)
{
/* Get the current thread and CID */
CurrentThread = NtCurrentTeb()->CsrClientThread;
CurrentCid = CurrentThread->ClientId;
/* Acquire the Process Lock */
CsrAcquireProcessLock();
/* Get the current Process and make sure the Thread is valid with this CID */
CurrentThread = CsrLocateThreadByClientId(&CurrentProcess, &CurrentCid);
if (!CurrentThread)
{
DPRINT1("CSRSRV:%s: invalid thread!\n", __FUNCTION__);
CsrReleaseProcessLock();
return STATUS_THREAD_IS_TERMINATING;
}
}
else
{
/* Acquire the Process Lock */
CsrAcquireProcessLock();
}
/* Get the Thread Create Time */
Status = NtQueryInformationThread(hThread,
ThreadTimes,
(PVOID)&KernelTimes,
sizeof(KernelTimes),
NULL);
if (!NT_SUCCESS(Status))
{
CsrReleaseProcessLock();
return Status;
}
/* Allocate a CSR Thread Structure */
CsrThread = CsrAllocateThread(CsrProcess);
if (!CsrThread)
{
DPRINT1("CSRSRV:%s: out of memory!\n", __FUNCTION__);
CsrReleaseProcessLock();
return STATUS_NO_MEMORY;
}
/* Save the data we have */
CsrThread->CreateTime = KernelTimes.CreateTime;
CsrThread->ClientId = *ClientId;
CsrThread->ThreadHandle = hThread;
ProtectHandle(hThread);
CsrThread->Flags = 0;
/* Insert the Thread into the Process */
CsrInsertThread(CsrProcess, CsrThread);
/* Release the lock and return */
CsrReleaseProcessLock();
return STATUS_SUCCESS;
}
#else
CsrCreateThread(IN PCSR_PROCESS CsrProcess,
IN HANDLE hThread,
IN PCLIENT_ID ClientId)
@ -718,6 +796,7 @@ CsrCreateThread(IN PCSR_PROCESS CsrProcess,
CsrReleaseProcessLock();
return STATUS_SUCCESS;
}
#endif
/*++
* @name CsrAddStaticServerThread
@ -816,4 +895,229 @@ CsrDereferenceThread(IN PCSR_THREAD CsrThread)
}
}
/*++
* @name CsrExecServerThread
* @implemented NT4
*
* The CsrExecServerThread routine creates an NT Thread and then
* initializes a CSR Thread for it.
*
* @param ThreadHandler
* Pointer to the thread's startup routine.
*
* @param Flags
* Initial CSR Thread Flags to set to the CSR Thread.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
*
* @remarks This routine is similar to CsrAddStaticServerThread, but it
* also creates an NT Thread instead of expecting one to already
* exist.
*
*--*/
NTSTATUS
NTAPI
CsrExecServerThread(IN PVOID ThreadHandler,
IN ULONG Flags)
{
PCSR_THREAD CsrThread;
HANDLE hThread;
CLIENT_ID ClientId;
NTSTATUS Status;
/* Acquire process lock */
CsrAcquireProcessLock();
/* Allocate a CSR Thread in the Root Process */
ASSERT(CsrRootProcess != NULL);
CsrThread = CsrAllocateThread(CsrRootProcess);
if (!CsrThread)
{
/* Fail */
CsrReleaseProcessLock();
return STATUS_NO_MEMORY;
}
/* Create the Thread */
Status = RtlCreateUserThread(NtCurrentProcess(),
NULL,
FALSE,
0,
0,
0,
ThreadHandler,
NULL,
&hThread,
&ClientId);
if (!NT_SUCCESS(Status))
{
/* Fail */
CsrDeallocateThread(CsrThread);
CsrReleaseProcessLock();
return Status;
}
/* Setup the Thread Object */
CsrThread->ThreadHandle = hThread;
ProtectHandle(hThread);
CsrThread->ClientId = ClientId;
CsrThread->Flags = Flags;
/* Insert it into the Thread List */
InsertHeadList(&CsrRootProcess->ThreadList, &CsrThread->Link);
/* Increase the thread count */
CsrRootProcess->ThreadCount++;
/* Return */
CsrReleaseProcessLock();
return Status;
}
/*++
* @name CsrLockThreadByClientId
* @implemented NT4
*
* The CsrLockThreadByClientId routine locks the CSR Thread corresponding
* to the given Thread ID and optionally returns it.
*
* @param Tid
* Thread ID corresponding to the CSR Thread which will be locked.
*
* @param CsrThread
* Optional pointer to a CSR Thread pointer which will hold the
* CSR Thread corresponding to the given Thread ID.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
*
* @remarks Locking a CSR Thread is defined as acquiring an extra
* reference to it and returning with the Process Lock held.
*
*--*/
NTSTATUS
NTAPI
CsrLockThreadByClientId(IN HANDLE Tid,
OUT PCSR_THREAD *CsrThread)
{
PLIST_ENTRY NextEntry;
PCSR_THREAD CurrentThread = NULL;
NTSTATUS Status = STATUS_UNSUCCESSFUL;
ULONG i;
/* Acquire the lock */
CsrAcquireProcessLock();
/* Assume failure */
ASSERT(CsrThread != NULL);
*CsrThread = NULL;
/* Convert to Hash */
i = CsrHashThread(Tid);
/* Setup the List Pointers */
NextEntry = CsrThreadHashTable[i].Flink;
/* Start Loop */
while (NextEntry != &CsrThreadHashTable[i])
{
/* Get the Process */
CurrentThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, HashLinks);
/* Check for PID Match */
if ((CurrentThread->ClientId.UniqueThread == Tid) &&
!(CurrentThread->Flags & CsrThreadTerminated))
{
/* Get out of here */
break;
}
/* Next entry */
NextEntry = NextEntry->Flink;
}
/* Nothing found if we got back to the list */
if (NextEntry == &CsrThreadHashTable[i]) CurrentThread = NULL;
/* Did the loop find something? */
if (CurrentThread)
{
/* Reference the found thread */
Status = STATUS_SUCCESS;
CurrentThread->ReferenceCount++;
*CsrThread = CurrentThread;
}
else
{
/* Nothing found, release the lock */
Status = STATUS_UNSUCCESSFUL;
CsrReleaseProcessLock();
}
/* Return the status */
return Status;
}
/*++
* @name CsrReferenceThread
* @implemented NT4
*
* The CsrReferenceThread routine increases the active reference count of
* a CSR Thread.
*
* @param CsrThread
* Pointer to the CSR Thread whose reference count will be increased.
*
* @return None.
*
* @remarks Do not use this routine if the Process Lock is already held.
*
*--*/
VOID
NTAPI
CsrReferenceThread(IN PCSR_THREAD CsrThread)
{
/* Acquire process lock */
CsrAcquireProcessLock();
/* Sanity checks */
ASSERT(CsrThread->Flags & CsrThreadTerminated); // CSR_THREAD_DESTROYED in ASSERT
ASSERT(CsrThread->ReferenceCount != 0);
/* Increment reference count */
CsrThread->ReferenceCount++;
/* Release the lock */
CsrReleaseProcessLock();
}
/*++
* @name CsrUnlockThread
* @implemented NT4
*
* The CsrUnlockThread undoes a previous CsrLockThreadByClientId operation.
*
* @param CsrThread
* Pointer to a previously locked CSR Thread.
*
* @return STATUS_SUCCESS.
*
* @remarks This routine must be called with the Process Lock held.
*
*--*/
NTSTATUS
NTAPI
CsrUnlockThread(IN PCSR_THREAD CsrThread)
{
/* Dereference the Thread */
ASSERT(ProcessStructureListLocked());
CsrLockedDereferenceThread(CsrThread);
/* Release the lock and return */
CsrReleaseProcessLock();
return STATUS_SUCCESS;
}
/* EOF */

View file

@ -2,8 +2,8 @@
* PROJECT: ReactOS Client Server Runtime SubSystem (CSRSS)
* LICENSE: BSD - See COPYING.ARM in root directory
* FILE: subsystems/win32/csrss/csrss.c
* PURPOSE: Main Executable Code
* PROGRAMMERS: Alex Ionescu
* PURPOSE: CSRSS Main Executable Code
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
* ReactOS Portable Systems Group
*/
@ -14,6 +14,8 @@
#define NTOS_MODE_USER
#include <ndk/ntndk.h>
#include <api.h>
// #include <csr/server.h>
#define NDEBUG
#include <debug.h>
@ -41,7 +43,7 @@ _main(int argc,
{
KPRIORITY BasePriority = (8 + 1) + 4;
NTSTATUS Status;
//ULONG Response;
//ULONG Response; // see the #if 0
UNREFERENCED_PARAMETER(envp);
UNREFERENCED_PARAMETER(DebugFlag);
@ -83,7 +85,7 @@ _main(int argc,
CsrpSetDefaultProcessHardErrorMode();
/* If this is Session 0, make sure killing us bugchecks the system */
if (!NtCurrentPeb()->SessionId) RtlSetProcessIsCritical(TRUE, NULL, FALSE);
if (NtCurrentPeb()->SessionId == 0) RtlSetProcessIsCritical(TRUE, NULL, FALSE);
/* Kill this thread. CSRSRV keeps us going */
NtTerminateThread(NtCurrentThread(), Status);

View file

@ -15,13 +15,13 @@
#define CsrAcquireProcessLock() \
RtlEnterCriticalSection(&ProcessDataLock); // CsrProcessLock
RtlEnterCriticalSection(&CsrProcessLock);
#define CsrReleaseProcessLock() \
RtlLeaveCriticalSection(&ProcessDataLock);
RtlLeaveCriticalSection(&CsrProcessLock);
#define ProcessStructureListLocked() \
(ProcessDataLock.OwningThread == NtCurrentTeb()->ClientId.UniqueThread)
(CsrProcessLock.OwningThread == NtCurrentTeb()->ClientId.UniqueThread)
#define CsrAcquireWaitLock() \
RtlEnterCriticalSection(&CsrWaitListsLock);
@ -119,7 +119,7 @@ extern HANDLE CsrSmApiPort;
extern HANDLE CsrSbApiPort;
extern LIST_ENTRY CsrThreadHashTable[256];
extern PCSR_PROCESS CsrRootProcess;
extern RTL_CRITICAL_SECTION ProcessDataLock, CsrWaitListsLock;
extern RTL_CRITICAL_SECTION CsrProcessLock, CsrWaitListsLock;
extern UNICODE_STRING CsrDirectoryName;
extern ULONG CsrDebug;
extern ULONG CsrTotalPerProcessDataLength;