Clarify few parts of code; remove unneeded comments and DPRINTs; start documentation of the CsrCreateProcess routine.

[BASESRV-CONSRV-WINSRV]
Correct the sizes of the API tables.

[SM]
Correct the API names.

svn path=/branches/ros-csrss/; revision=58464
This commit is contained in:
Hermès Bélusca-Maïto 2013-03-10 19:37:33 +00:00
parent 0a679dbf86
commit e2d2cb40e2
17 changed files with 136 additions and 225 deletions

View file

@ -166,7 +166,7 @@ SmpStopCsr(IN PSM_API_MSG SmApiMsg,
return STATUS_NOT_IMPLEMENTED;
}
PSM_API_HANDLER SmpApiDispatch[SmMaxApiNumber] =
PSM_API_HANDLER SmpApiDispatch[SmpMaxApiNumber - SmpCreateForeignSessionApi] =
{
SmpCreateForeignSession,
SmpSessionComplete,
@ -401,13 +401,13 @@ SmpApiLoop(IN PVOID Parameter)
RequestMsg.ReturnValue = STATUS_PENDING;
/* Check if the API is valid */
if (RequestMsg.ApiNumber >= SmMaxApiNumber)
if (RequestMsg.ApiNumber >= SmpMaxApiNumber)
{
/* It isn't, fail */
DPRINT1("Invalid API: %lx\n", RequestMsg.ApiNumber);
Status = STATUS_NOT_IMPLEMENTED;
}
else if ((RequestMsg.ApiNumber <= SmTerminateForeignSessionApi) &&
else if ((RequestMsg.ApiNumber <= SmpTerminateForeignSessionApi) &&
!(ClientContext->Subsystem))
{
/* It's valid, but doesn't have a subsystem with it */

View file

@ -12,17 +12,6 @@
#include "csrmsg.h"
/*
BOOLEAN
NTAPI
CsrCaptureArguments(IN PCSR_THREAD CsrThread,
IN PCSR_API_MESSAGE ApiMessage);
VOID
NTAPI
CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
*/
NTSTATUS
NTAPI
CsrClientConnectToServer(IN PWSTR ObjectDirectory,

View file

@ -107,7 +107,7 @@ typedef struct _CSR_API_MESSAGE
PORT_MESSAGE Header;
union
{
CSR_CONNECTION_INFO ConnectionInfo; // Uniquely used in csrss/csrsrv for internal signaling (opening a new connection).
CSR_CONNECTION_INFO ConnectionInfo; // Uniquely used in CSRSRV for internal signaling (opening a new connection).
struct
{
PCSR_CAPTURE_BUFFER CsrCaptureData;

View file

@ -247,19 +247,6 @@ NTSTATUS
/* PROTOTYPES ****************************************************************/
///////////
BOOLEAN
NTAPI
CsrCaptureArguments(IN PCSR_THREAD CsrThread,
IN PCSR_API_MESSAGE ApiMessage);
VOID
NTAPI
CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
//////////
NTSTATUS
NTAPI
CsrServerInitialization(IN ULONG ArgumentCount,

View file

@ -18,17 +18,21 @@
// in the checked build of SMSS, which is probably a close approximation. We add
// "p" to use the similar nomenclature seen/leaked out in the Base CSRSS APIs.
//
// The enumeration finishes with an enumeratee holding the maximum API number.
// Its name is based on BasepMaxApiNumber, UserpMaxApiNumber...
//
//
typedef enum _SMSRV_API_NUMBER
{
SmCreateForeignSessionApi,
SmSessionCompleteApi,
SmTerminateForeignSessionApi,
SmExecPgmApi,
SmLoadDeferedSubsystemApi,
SmStartCsrApi,
SmStopCsrApi,
SmMaxApiNumber // Based on BasepMaxApiNumber, UserpMaxApiNumber...
SmpCreateForeignSessionApi,
SmpSessionCompleteApi,
SmpTerminateForeignSessionApi,
SmpExecPgmApi,
SmpLoadDeferedSubsystemApi,
SmpStartCsrApi,
SmpStopCsrApi,
SmpMaxApiNumber
} SMSRV_API_NUMBER;
//
@ -108,7 +112,7 @@ C_ASSERT(sizeof(SM_API_MSG) == 0x130);
#endif
//
// There are the APIs that the SMSS Serve can send to a client (such as CSRSS)
// There are the APIs that the SMSS Server can send to a client (such as CSRSS).
//
// These are called "SB" APIs.
//
@ -117,6 +121,9 @@ C_ASSERT(sizeof(SM_API_MSG) == 0x130);
// We add "p" to use the similar nomenclature seen/leaked out in the Base CSRSS
// APIs.
//
// The enumeration finishes with an enumeratee holding the maximum API number.
// Its name is based on BasepMaxApiNumber, UserpMaxApiNumber...
//
//
typedef enum _SB_API_NUMBER
{
@ -124,7 +131,8 @@ typedef enum _SB_API_NUMBER
SbpTerminateSession,
SbpForeignSessionComplete,
SbpCreateProcess,
SbpMaxApiNumber // Based on BasepMaxApiNumber, UserpMaxApiNumber...
SbpMaxApiNumber
} SB_API_NUMBER;
//

View file

@ -38,7 +38,7 @@ SmExecPgm(IN HANDLE SmApiPort,
SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
/* Initalize this specific API's parameters */
SmApiMsg.ApiNumber = SmExecPgmApi;
SmApiMsg.ApiNumber = SmpExecPgmApi;
RtlCopyMemory(&SmApiMsg.u.ExecPgm.ProcessInformation,
ProcessInformation,
sizeof(SmApiMsg.u.ExecPgm.ProcessInformation));
@ -144,7 +144,7 @@ SmSessionComplete(IN HANDLE SmApiPort,
SessionComplete->SessionStatus = SessionStatus;
/* Set the API Message Port Message header */
ApiMessage.ApiNumber = SmSessionCompleteApi;
ApiMessage.ApiNumber = SmpSessionCompleteApi;
ApiMessage.h.u1.s1.DataLength = sizeof(SM_SESSION_COMPLETE_MSG) + 8;
ApiMessage.h.u1.s1.TotalLength = sizeof(SM_API_MSG);
ApiMessage.h.u2.ZeroInit = 0;

View file

@ -23,7 +23,7 @@ HANDLE BaseSrvSharedHeap = NULL; // Shared heap with CSR. (CsrSrvSharedSectio
PBASE_STATIC_SERVER_DATA BaseStaticServerData = NULL; // Data that we can share amongst processes. Initialized inside BaseSrvSharedHeap.
// Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber] =
PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER] =
{
BaseSrvCreateProcess,
BaseSrvCreateThread,
@ -57,7 +57,7 @@ PCSR_API_ROUTINE BaseServerApiDispatchTable[BasepMaxApiNumber] =
// BaseSrvNlsGetUserInfo,
};
BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber] =
BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER] =
{
TRUE, // BaseSrvCreateProcess
TRUE, // BaseSrvCreateThread
@ -91,7 +91,7 @@ BOOLEAN BaseServerApiServerValidTable[BasepMaxApiNumber] =
// FALSE, // BaseSrvNlsGetUserInfo
};
PCHAR BaseServerApiNameTable[BasepMaxApiNumber] =
PCHAR BaseServerApiNameTable[BasepMaxApiNumber - BASESRV_FIRST_API_NUMBER] =
{
"BaseCreateProcess",
"BaseCreateThread",

View file

@ -269,7 +269,7 @@ CsrpCheckRequestThreads(VOID)
NTSTATUS Status;
/* Decrease the count, and see if we're out */
if (!(_InterlockedDecrement(&CsrpStaticThreadCount)))
if (_InterlockedDecrement(&CsrpStaticThreadCount) == 0)
{
/* Check if we've still got space for a Dynamic Thread */
if (CsrpDynamicThreadTotal < CsrMaxApiRequestThreads)
@ -879,8 +879,7 @@ CsrApiRequestThread(IN PVOID Parameter)
*
* @param None
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -1010,7 +1009,7 @@ PCSR_THREAD
NTAPI
CsrConnectToUser(VOID)
{
#if 0 // This code is OK, however it is ClientThreadSetup which sucks.
#if 0 // FIXME: This code is OK, however it is ClientThreadSetup which sucks.
NTSTATUS Status;
ANSI_STRING DllName;
UNICODE_STRING TempName;
@ -1074,7 +1073,9 @@ CsrConnectToUser(VOID)
PCSR_THREAD CsrThread;
/* Save pointer to this thread in TEB */
CsrAcquireProcessLock();
CsrThread = CsrLocateThreadInProcess(NULL, &Teb->ClientId);
CsrReleaseProcessLock();
if (CsrThread) Teb->CsrClientThread = CsrThread;
/* Return it */
@ -1099,7 +1100,6 @@ HANDLE
NTAPI
CsrQueryApiPort(VOID)
{
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
return CsrApiPort;
}
@ -1309,7 +1309,6 @@ CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage)
RtlFreeHeap(CsrHeap, 0, RemoteCaptureBuffer);
}
/*++
* @name CsrValidateMessageBuffer
* @implemented NT5.1
@ -1404,36 +1403,6 @@ CsrValidateMessageBuffer(IN PCSR_API_MESSAGE ApiMessage,
return FALSE;
}
/*** This is what we have in consrv/server.c ***
/\* Ensure that a captured buffer is safe to access *\/
BOOL FASTCALL
Win32CsrValidateBuffer(PCSR_PROCESS ProcessData, PVOID Buffer,
SIZE_T NumElements, SIZE_T ElementSize)
{
/\* Check that the following conditions are true:
* 1. The start of the buffer is somewhere within the process's
* shared memory section view.
* 2. The remaining space in the view is at least as large as the buffer.
* (NB: Please don't try to "optimize" this by using multiplication
* instead of division; remember that 2147483648 * 2 = 0.)
* 3. The buffer is DWORD-aligned.
*\/
ULONG_PTR Offset = (BYTE *)Buffer - (BYTE *)ProcessData->ClientViewBase;
if (Offset >= ProcessData->ClientViewBounds
|| NumElements > (ProcessData->ClientViewBounds - Offset) / ElementSize
|| (Offset & (sizeof(DWORD) - 1)) != 0)
{
DPRINT1("Invalid buffer %p(%u*%u); section view is %p(%u)\n",
Buffer, NumElements, ElementSize,
ProcessData->ClientViewBase, ProcessData->ClientViewBounds);
return FALSE;
}
return TRUE;
}
***********************************************/
/*++
* @name CsrValidateMessageString
* @implemented NT5.1

View file

@ -64,7 +64,6 @@ extern UNICODE_STRING CsrApiPortName;
extern RTL_CRITICAL_SECTION CsrProcessLock;
extern RTL_CRITICAL_SECTION CsrWaitListsLock;
extern HANDLE CsrObjectDirectory;
extern PSB_API_ROUTINE CsrServerSbApiDispatch[5];
/****************************************************/
@ -75,24 +74,19 @@ CSR_API(CsrSrvIdentifyAlertableThread);
CSR_API(CsrSrvSetPriorityClass);
/***
BOOLEAN
NTAPI
CsrCaptureArguments(
IN PCSR_THREAD CsrThread,
IN PCSR_API_MESSAGE ApiMessage
);
VOID
NTAPI
CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
NTSTATUS
NTAPI
CsrServerDllInitialization(IN PCSR_SERVER_DLL LoadedServerDll);
***/
BOOLEAN
NTAPI
CsrCaptureArguments(IN PCSR_THREAD CsrThread,
IN PCSR_API_MESSAGE ApiMessage);
VOID
NTAPI
CsrReleaseCapturedArguments(IN PCSR_API_MESSAGE ApiMessage);
NTSTATUS
NTAPI
@ -113,18 +107,18 @@ VOID
NTAPI
CsrDeallocateProcess(IN PCSR_PROCESS CsrProcess);
VOID
NTAPI
CsrRemoveProcess(IN PCSR_PROCESS CsrProcess);
VOID
NTAPI
CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL,
IN PCSR_PROCESS CsrProcess);
VOID
NTAPI
CsrRemoveProcess(IN PCSR_PROCESS CsrProcess);
NTSTATUS
NTAPI
CsrApiRequestThread(IN PVOID Parameter); // HANDLE ServerPort ??
CsrApiRequestThread(IN PVOID Parameter);
VOID
NTAPI

View file

@ -48,8 +48,7 @@ SYSTEM_BASIC_INFORMATION CsrNtSysInfo;
*
* @param None.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -163,8 +162,7 @@ Quickie:
* @param ObjectDirectory
* Handle fo the Object Directory to protect.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -186,8 +184,7 @@ CsrSetDirectorySecurity(IN HANDLE ObjectDirectory)
* @param DosDevicesSd
* Pointer to the Security Descriptor to return.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks Depending on the DOS Devices Protection Mode (set in the registry),
* regular users may or may not have full access to the directory.
@ -403,8 +400,7 @@ FreeDosDevicesProtection(IN PSECURITY_DESCRIPTOR DosDevicesSd)
* @param Session
* Session ID for which to create the directories.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -534,8 +530,7 @@ CsrCreateSessionObjectDirectory(IN ULONG Session)
* @param Arguments
* Array of arguments.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -714,8 +709,7 @@ CsrParseServerCommandLine(IN ULONG ArgumentCount,
*
* @param None.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -777,7 +771,6 @@ CsrInitCsrRootProcess(VOID)
if (ServerDll && ServerDll->NewProcessCallback)
{
/* Call the callback */
DPRINT1("Call NewProcessCallback(NULL, 0x%p) called\n", CsrRootProcess);
ServerDll->NewProcessCallback(NULL, CsrRootProcess);
}
}
@ -794,8 +787,7 @@ CsrInitCsrRootProcess(VOID)
* @param LocalSystemSd
* Pointer to a pointer to the security descriptor to create.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -871,8 +863,7 @@ CsrCreateLocalSystemSD(OUT PSECURITY_DESCRIPTOR *LocalSystemSd)
*
* @param None
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -960,7 +951,7 @@ CsrSbApiPortInitialize(VOID)
* @implemented NT4
*
* The CsrServerInitialization routine is the native (not Server) entrypoint
* of this Server DLL. It serves as the entrypoint for csrss.
* of this Server DLL. It serves as the entrypoint for CSRSS.
*
* @param ArgumentCount
* Number of arguments on the command line.
@ -968,8 +959,7 @@ CsrSbApiPortInitialize(VOID)
* @param Arguments
* Array of arguments from the command line.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -980,7 +970,6 @@ CsrServerInitialization(IN ULONG ArgumentCount,
IN PCHAR Arguments[])
{
NTSTATUS Status = STATUS_SUCCESS;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
/* Create the Init Event */
Status = NtCreateEvent(&CsrInitializationEvent,

View file

@ -41,7 +41,7 @@ extern ULONG CsrTotalPerProcessDataLength;
*
* @return None.
*
* @remarks The "Normal" Priority corresponds to the Normal Forground
* @remarks The "Normal" Priority corresponds to the Normal Foreground
* Priority (9) plus a boost of 4.
*
*--*/
@ -69,7 +69,7 @@ CsrSetToNormalPriority(VOID)
*
* @return None.
*
* @remarks The "Shutdown" Priority corresponds to the Normal Forground
* @remarks The "Shutdown" Priority corresponds to the Normal Foreground
* Priority (9) plus a boost of 6.
*
*--*/
@ -264,7 +264,7 @@ CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
/* Decrease reference count */
LockCount = --CsrProcess->ReferenceCount;
ASSERT(LockCount >= 0);
if (!LockCount)
if (LockCount == 0)
{
/* Call the generic cleanup code */
DPRINT1("Should kill process: %p\n", CsrProcess);
@ -345,8 +345,7 @@ CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
*
* @param None.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -495,18 +494,25 @@ CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL,
* @name CsrCreateProcess
* @implemented NT4
*
* Do nothing for 500ms.
* The CsrCreateProcess routine creates a CSR Process object for an NT Process.
*
* @param ArgumentCount
* Description of the parameter. Wrapped to more lines on ~70th
* column.
* @param hProcess
* Handle to an existing NT Process to which to associate this
* CSR Process.
*
* @param Arguments
* Description of the parameter. Wrapped to more lines on ~70th
* column.
* @param hThread
* Handle to an existing NT Thread to which to create its
* corresponding CSR Thread for this CSR Process.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @param ClientId
* Pointer to the Client ID structure of the NT Process to associate
* with this CSR Process.
*
* @param NtSession
* @param Flags
* @param DebugCid
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -597,7 +603,7 @@ CsrCreateProcess(IN HANDLE hProcess,
}
/* Check if CreateProcess got CREATE_NEW_PROCESS_GROUP */
if (!(Flags & CsrProcessCreateNewGroup))
if ((Flags & CsrProcessCreateNewGroup) == 0)
{
/* Create new data */
CsrProcess->ProcessGroupId = HandleToUlong(ClientId->UniqueProcess);
@ -781,7 +787,7 @@ CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess)
/* Decrease reference count */
LockCount = --CsrProcess->ReferenceCount;
ASSERT(LockCount >= 0);
if (!LockCount)
if (LockCount == 0)
{
/* Call the generic cleanup code */
CsrProcessRefcountZero(CsrProcess);
@ -891,16 +897,15 @@ CsrDestroyProcess(IN PCLIENT_ID Cid,
* @name CsrGetProcessLuid
* @implemented NT4
*
* Do nothing for 500ms.
* The CsrGetProcessLuid routine gets the LUID of the given process.
*
* @param hProcess
* Optional handle to the process whose LUID should be returned.
*
* @param Luid
* Pointer to a LUID Pointer which will receive the CSR Process' LUID
* Pointer to a LUID Pointer which will receive the CSR Process' LUID.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks If hProcess is not supplied, then the current thread's token will
* be used. If that too is missing, then the current process' token
@ -1000,7 +1005,7 @@ CsrGetProcessLuid(IN HANDLE hProcess OPTIONAL,
* @param CsrThread
* Pointer to the CSR Thread to impersonate.
*
* @return TRUE if impersonation succeeded, false otherwise.
* @return TRUE if impersonation succeeded, FALSE otherwise.
*
* @remarks Impersonation can be recursive.
*
@ -1030,10 +1035,8 @@ CsrImpersonateClient(IN PCSR_THREAD CsrThread)
if (!NT_SUCCESS(Status))
{
/* Failure */
/*
DPRINT1("CSRSS: Can't impersonate client thread - Status = %lx\n", Status);
if (Status != STATUS_BAD_IMPERSONATION_LEVEL) DbgBreakPoint();
*/
// if (Status != STATUS_BAD_IMPERSONATION_LEVEL) DbgBreakPoint();
return FALSE;
}
@ -1058,8 +1061,7 @@ CsrImpersonateClient(IN PCSR_THREAD CsrThread)
* Optional pointer to a CSR Process pointer which will hold the
* CSR Process corresponding to the given Process ID.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks Locking a CSR Process is defined as acquiring an extra
* reference to it and returning with the Process Lock held.
@ -1124,7 +1126,7 @@ CsrLockProcessByClientId(IN HANDLE Pid,
*
* @param None.
*
* @return TRUE if the reversion was succesful, false otherwise.
* @return TRUE if the reversion was succesful, FALSE otherwise.
*
* @remarks Impersonation can be recursive; as such, the impersonation token
* will only be deleted once the CSR Thread's impersonaton count
@ -1145,11 +1147,11 @@ CsrRevertToSelf(VOID)
/* Make sure impersonation is on */
if (!CurrentThread->ImpersonationCount)
{
// DPRINT1("CSRSS: CsrRevertToSelf called while not impersonating\n");
DPRINT1("CSRSS: CsrRevertToSelf called while not impersonating\n");
// DbgBreakPoint();
return FALSE;
}
else if (--CurrentThread->ImpersonationCount > 0)
else if ((--CurrentThread->ImpersonationCount) > 0)
{
/* Success; impersonation count decreased but still not zero */
return TRUE;
@ -1242,8 +1244,7 @@ CsrSetForegroundPriority(IN PCSR_PROCESS CsrProcess)
* @param Flags
* Flags to send to the shutdown notification routine.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*

View file

@ -55,8 +55,8 @@ HANDLE CsrSrvSharedSection = NULL;
* @name CsrServerDllInitialization
* @implemented NT4
*
* The CsrServerDllInitialization is the initialization routine for
* the this Server DLL.
* The CsrServerDllInitialization is the initialization routine
* for this Server DLL.
*
* @param LoadedServerDll
* Pointer to the CSR Server DLL structure representing this Server DLL.
@ -86,18 +86,17 @@ CSR_SERVER_DLL_INIT(CsrServerDllInitialization)
* @name CsrLoadServerDll
* @implemented NT4
*
* The CsrLoadServerDll routine loads a CSR Server DLL and calls its entrypoint
* The CsrLoadServerDll routine loads a CSR Server DLL and calls its entrypoint.
*
* @param DllString
* Pointer to the CSR Server DLL to load and call.
*
* @param EntryPoint
* Pointer to the name of the server's initialization function. If
* this parameter is NULL, the default ServerDllInitialize will be
* assumed.
* Pointer to the name of the server's initialization function.
* If this parameter is NULL, the default ServerDllInitialize
* will be assumed.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -119,8 +118,6 @@ CsrLoadServerDll(IN PCHAR DllString,
PCSR_SERVER_DLL_INIT_CALLBACK ServerDllInitProcedure;
ULONG Response;
DPRINT1("CsrLoadServerDll(%s, 0x%p, %lu)\n", DllString, EntryPoint, ServerId);
/* Check if it's beyond the maximum we support */
if (ServerId >= CSR_SERVER_DLL_MAX) return STATUS_TOO_MANY_NAMES;
@ -225,15 +222,10 @@ CsrLoadServerDll(IN PCHAR DllString,
CsrSrvSharedStaticServerData[ServerDll->ServerId] = ServerDll->SharedSection;
}
}
else
{
/* Use shared failure code */
goto LoadFailed;
}
}
else
if (!NT_SUCCESS(Status))
{
LoadFailed:
/* Server Init failed, unload it */
if (hServerDll) LdrUnloadDll(hServerDll);
@ -316,15 +308,14 @@ CSR_API(CsrSrvClientConnect)
/*++
* @name CsrSrvCreateSharedSection
*
* The CsrSrvCreateSharedSection creates the Shared Section that all CSR Server
* DLLs and Clients can use to share data.
* The CsrSrvCreateSharedSection creates the Shared Section that all
* CSR Server DLLs and Clients can use to share data.
*
* @param ParameterValue
* Specially formatted string from our registry command-line which
* specifies various arguments for the shared section.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -445,8 +436,7 @@ CsrSrvCreateSharedSection(IN PCHAR ParameterValue)
* Pointer to the CSR Connection Info structure for the incoming
* connection.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -463,7 +453,6 @@ CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
if (CsrProcess)
{
/* Map the section into this process */
DPRINT("CSR Process Handle: %p. CSR Process: %p\n", CsrProcess->ProcessHandle, CsrProcess);
Status = NtMapViewOfSection(CsrSrvSharedSection,
CsrProcess->ProcessHandle,
&CsrSrvSharedSectionBase,
@ -553,8 +542,8 @@ CSR_API(CsrSrvSetPriorityClass)
*
* @return STATUS_INVALID_PARAMETER.
*
* @remarks CsrSrvSetPriorityClass does not use this stub because it must
* return success.
* @remarks CsrSrvSetPriorityClass does not use this stub because
* it must return success.
*
*--*/
CSR_API(CsrSrvUnusedFunction)
@ -621,12 +610,12 @@ CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
NULL);
/* Check if this is Session 0, and the Debugger is Enabled */
if ((NtCurrentPeb()->SessionId) && (NT_SUCCESS(Status)) &&
if ((NtCurrentPeb()->SessionId != 0) && (NT_SUCCESS(Status)) &&
(DebuggerInfo.KernelDebuggerEnabled))
{
/* Call the Unhandled Exception Filter */
if ((Result = RtlUnhandledExceptionFilter(ExceptionInfo)) !=
EXCEPTION_CONTINUE_EXECUTION)
Result = RtlUnhandledExceptionFilter(ExceptionInfo);
if (Result != EXCEPTION_CONTINUE_EXECUTION)
{
/* We're going to raise an error. Get Shutdown Privilege first */
Status = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE,

View file

@ -18,23 +18,20 @@
RTL_CRITICAL_SECTION CsrNtSessionLock;
LIST_ENTRY CsrNtSessionList;
// Does it exist a enumeration associated with it ?
PSB_API_ROUTINE CsrServerSbApiDispatch[5] =
PSB_API_ROUTINE CsrServerSbApiDispatch[SbpMaxApiNumber - SbpCreateSession] =
{
CsrSbCreateSession,
CsrSbTerminateSession,
CsrSbForeignSessionComplete,
CsrSbCreateProcess,
NULL
CsrSbCreateProcess
};
PCHAR CsrServerSbApiName[5] =
PCHAR CsrServerSbApiName[SbpMaxApiNumber - SbpCreateSession] =
{
"SbCreateSession",
"SbTerminateSession",
"SbForeignSessionComplete",
"SbCreateProcess",
"Unknown Csr Sb Api Number"
"SbCreateProcess"
};
/* PRIVATE FUNCTIONS **********************************************************/
@ -55,8 +52,6 @@ NTSTATUS
NTAPI
CsrInitializeNtSessionList(VOID)
{
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
/* Initialize the Session List */
InitializeListHead(&CsrNtSessionList);
@ -170,7 +165,7 @@ CsrDereferenceNtSession(IN PCSR_NT_SESSION Session,
ASSERT(Session->ReferenceCount != 0);
/* Dereference the Session Object */
if (!(--Session->ReferenceCount))
if ((--Session->ReferenceCount) == 0)
{
/* Remove it from the list */
RemoveEntryList(&Session->SessionLink);
@ -537,8 +532,8 @@ CsrSbApiRequestThread(IN PVOID Parameter)
}
/*
* It's an API Message, check if it's within limits. If it's not, the
* NT Behaviour is to set this to the Maximum API.
* It's an API Message, check if it's within limits. If it's not,
* the NT Behaviour is to set this to the Maximum API.
*/
if (ReceiveMsg.ApiNumber > SbpMaxApiNumber)
{
@ -555,6 +550,9 @@ CsrSbApiRequestThread(IN PVOID Parameter)
/* Call the API */
if (!CsrServerSbApiDispatch[ReceiveMsg.ApiNumber](&ReceiveMsg))
{
DPRINT1("CSRSS: %s Session Api called and failed\n",
CsrServerSbApiName[ReceiveMsg.ApiNumber]);
/* It failed, so return nothing */
ReplyMsg = NULL;
}

View file

@ -14,8 +14,7 @@
#define NDEBUG
#include <debug.h>
#define CsrHashThread(t) \
(HandleToUlong(t)&(256 - 1))
#define CsrHashThread(t) (HandleToUlong(t)&(256 - 1))
/* GLOBALS ********************************************************************/
@ -215,7 +214,6 @@ CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL,
if (Process) *Process = FoundThread->Process;
/* Return thread too */
// DPRINT1("Found: %p %p\n", FoundThread, FoundThread->Process);
return FoundThread;
}
}
@ -257,7 +255,6 @@ CsrLocateThreadInProcess(IN PCSR_PROCESS CsrProcess OPTIONAL,
if (!CsrProcess) CsrProcess = CsrRootProcess;
/* Save the List pointers */
// DPRINT1("Searching in: %p %d\n", CsrProcess, CsrProcess->ThreadCount);
ListHead = &CsrProcess->ThreadList;
NextEntry = ListHead->Flink;
@ -275,7 +272,6 @@ CsrLocateThreadInProcess(IN PCSR_PROCESS CsrProcess OPTIONAL,
}
/* Return what we found */
// DPRINT1("Found: %p\n", FoundThread);
return FoundThread;
}
@ -312,7 +308,6 @@ CsrInsertThread(IN PCSR_PROCESS Process,
/* Hash the Thread */
i = CsrHashThread(Thread->ClientId.UniqueThread);
// DPRINT1("TID %lx HASH: %lx\n", Thread->ClientId.UniqueThread, i);
/* Insert it there too */
InsertHeadList(&CsrThreadHashTable[i], &Thread->HashLinks);
@ -377,10 +372,10 @@ CsrRemoveThread(IN PCSR_THREAD CsrThread)
if (CsrThread->HashLinks.Flink) RemoveEntryList(&CsrThread->HashLinks);
/* Check if this is the last Thread */
if (!CsrThread->Process->ThreadCount)
if (CsrThread->Process->ThreadCount == 0)
{
/* Check if it's not already been marked for deletion */
if (!(CsrThread->Process->Flags & CsrProcessLastThreadTerminated))
if ((CsrThread->Process->Flags & CsrProcessLastThreadTerminated) == 0)
{
/* Let everyone know this process is about to lose the thread */
CsrThread->Process->Flags |= CsrProcessLastThreadTerminated;
@ -464,7 +459,7 @@ CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
/* Decrease reference count */
LockCount = --CsrThread->ReferenceCount;
ASSERT(LockCount >= 0);
if (!LockCount)
if (LockCount == 0)
{
/* Call the generic cleanup code */
CsrAcquireProcessLock();
@ -551,8 +546,7 @@ CsrAddStaticServerThread(IN HANDLE hThread,
* Pointer to the Client ID structure of the NT Thread to associate
* with this CSR Thread.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -567,7 +561,6 @@ CsrCreateRemoteThread(IN HANDLE hThread,
PCSR_THREAD CsrThread;
PCSR_PROCESS CsrProcess;
KERNEL_USER_TIMES KernelTimes;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
/* Get the Thread Create Time */
Status = NtQueryInformationThread(hThread,
@ -602,7 +595,7 @@ CsrCreateRemoteThread(IN HANDLE hThread,
CsrThread = CsrAllocateThread(CsrProcess);
if (!CsrThread)
{
DPRINT1("CSRSRV:%s: out of memory!\n", __FUNCTION__);
DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
CsrUnlockProcess(CsrProcess);
return STATUS_NO_MEMORY;
}
@ -654,8 +647,7 @@ CsrCreateRemoteThread(IN HANDLE hThread,
* Pointer to the Client ID structure of the NT Thread to associate
* with this CSR Thread.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL otherwise.
*
* @remarks None.
*
@ -673,8 +665,6 @@ CsrCreateThread(IN PCSR_PROCESS CsrProcess,
CLIENT_ID CurrentCid;
KERNEL_USER_TIMES KernelTimes;
DPRINT("CSRSRV: %s called\n", __FUNCTION__);
if (HaveClient)
{
/* Get the current thread and CID */
@ -690,7 +680,7 @@ CsrCreateThread(IN PCSR_PROCESS CsrProcess,
/* Something is wrong if we get an empty thread back */
if (!CurrentThread)
{
DPRINT1("CSRSRV:%s: invalid thread!\n", __FUNCTION__);
DPRINT1("CSRSRV: %s: invalid thread!\n", __FUNCTION__);
CsrReleaseProcessLock();
return STATUS_THREAD_IS_TERMINATING;
}
@ -717,7 +707,7 @@ CsrCreateThread(IN PCSR_PROCESS CsrProcess,
CsrThread = CsrAllocateThread(CsrProcess);
if (!CsrThread)
{
DPRINT1("CSRSRV:%s: out of memory!\n", __FUNCTION__);
DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
CsrReleaseProcessLock();
return STATUS_NO_MEMORY;
}
@ -762,7 +752,7 @@ CsrDereferenceThread(IN PCSR_THREAD CsrThread)
/* Decrease reference count */
ASSERT(CsrThread->ReferenceCount > 0);
if (!(--CsrThread->ReferenceCount))
if ((--CsrThread->ReferenceCount) == 0)
{
/* Call the generic cleanup code */
CsrThreadRefcountZero(CsrThread);
@ -807,7 +797,7 @@ CsrDestroyThread(IN PCLIENT_ID Cid)
&ClientId);
/* Make sure we got one back, and that it's not already gone */
if (!CsrThread || CsrThread->Flags & CsrThreadTerminated)
if (!CsrThread || (CsrThread->Flags & CsrThreadTerminated))
{
/* Release the lock and return failure */
CsrReleaseProcessLock();
@ -856,8 +846,7 @@ CsrDestroyThread(IN PCLIENT_ID Cid)
* @param Flags
* Initial CSR Thread Flags to set to the CSR Thread.
*
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
* otherwise.
* @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
@ -937,8 +926,7 @@ CsrExecServerThread(IN PVOID ThreadHandler,
* 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.
* @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.
@ -975,7 +963,7 @@ CsrLockThreadByClientId(IN HANDLE Tid,
/* Check for PID Match */
if ((CurrentThread->ClientId.UniqueThread == Tid) &&
!(CurrentThread->Flags & CsrThreadTerminated))
(CurrentThread->Flags & CsrThreadTerminated) == 0)
{
/* Get out of here */
break;

View file

@ -666,7 +666,6 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
/* If we don't need a console, then get out of here */
if (!ConnectInfo->ConsoleNeeded || !ProcessData->ConsoleApp) // In fact, it is for GUI apps.
{
DPRINT("ConSrvConnect - No console needed\n");
return STATUS_SUCCESS;
}

View file

@ -23,7 +23,7 @@ HANDLE ConSrvHeap = NULL; // Our own heap.
// Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
// plus a little bit of Windows 7.
PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber] =
PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER] =
{
SrvOpenConsole,
SrvGetConsoleInput,
@ -114,7 +114,7 @@ PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber] =
SrvSetConsoleHistory,
};
BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber] =
BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER] =
{
FALSE, // SrvOpenConsole,
FALSE, // SrvGetConsoleInput,
@ -205,7 +205,7 @@ BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber] =
FALSE, // SrvSetConsoleHistory
};
PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber] =
PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER] =
{
"OpenConsole",
"GetConsoleInput",

View file

@ -22,7 +22,7 @@ HINSTANCE UserServerDllInstance = NULL;
HANDLE UserServerHeap = NULL; // Our own heap.
// Windows Server 2003 table from http://j00ru.vexillium.org/csrss_list/api_list.html#Windows_2k3
PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber] =
PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
{
SrvExitWindowsEx,
// SrvEndTask,
@ -39,7 +39,7 @@ PCSR_API_ROUTINE UserServerApiDispatchTable[UserpMaxApiNumber] =
// SrvGetSetShutdownBlockReason, // Added in Vista
};
BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber] =
BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
{
FALSE, // SrvExitWindowsEx
// FALSE, // SrvEndTask
@ -56,7 +56,7 @@ BOOLEAN UserServerApiServerValidTable[UserpMaxApiNumber] =
// FALSE, // SrvGetSetShutdownBlockReason
};
PCHAR UserServerApiNameTable[UserpMaxApiNumber] =
PCHAR UserServerApiNameTable[UserpMaxApiNumber - USERSRV_FIRST_API_NUMBER] =
{
"SrvExitWindowsEx",
// "SrvEndTask",