mirror of
https://github.com/reactos/reactos.git
synced 2025-04-21 04:37:15 +00:00
[NTDLL/INCLUDE]: Rename the CSRSRV API Numbers not to conflict with the actual functions.
[CSRSRV]: Import server.c from CSRSRV2, and move the existing CsrSrv functions we had from wapi.c to server.c (with the reactOS-specific hacks we had). The other CsrSrv* functions are not yet used. svn path=/trunk/; revision=55647
This commit is contained in:
parent
7ed48291c6
commit
d221bdfbb1
9 changed files with 824 additions and 201 deletions
|
@ -48,7 +48,7 @@ CsrSetPriorityClass(HANDLE hProcess,
|
|||
/* Call it */
|
||||
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
||||
NULL,
|
||||
CSR_MAKE_OPCODE(CsrSrvSetPriorityClass,
|
||||
CSR_MAKE_OPCODE(CsrpSetPriorityClass,
|
||||
CSR_SRV_SERVER),
|
||||
sizeof(CSR_SET_PRIORITY_CLASS));
|
||||
|
||||
|
@ -78,7 +78,7 @@ CsrIdentifyAlertableThread (VOID)
|
|||
/* Call it */
|
||||
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
||||
NULL,
|
||||
CSR_MAKE_OPCODE(CsrSrvIdentifyAlertableThread,
|
||||
CSR_MAKE_OPCODE(CsrpIdentifyAlertable,
|
||||
CSR_SRV_SERVER),
|
||||
sizeof(CSR_SET_PRIORITY_CLASS));
|
||||
|
||||
|
|
|
@ -438,7 +438,7 @@ CsrClientConnectToServer(PWSTR ObjectDirectory,
|
|||
#if 0
|
||||
Status = CsrClientCallServer(&ApiMessage,
|
||||
CaptureBuffer,
|
||||
CSR_MAKE_OPCODE(CsrSrvClientConnect,
|
||||
CSR_MAKE_OPCODE(CsrpClientConnect,
|
||||
CSR_SRV_DLL),
|
||||
sizeof(CSR_CLIENT_CONNECT));
|
||||
#endif
|
||||
|
|
|
@ -864,9 +864,15 @@ typedef struct _BASE_STATIC_SERVER_DATA
|
|||
/* Types used in the new CSR. Temporarly here for proper compile of NTDLL */
|
||||
#define CSR_SRV_SERVER 0
|
||||
|
||||
#define CsrSrvClientConnect 0
|
||||
#define CsrSrvIdentifyAlertableThread 3
|
||||
#define CsrSrvSetPriorityClass 4
|
||||
typedef enum _CSR_SRV_API_NUMBER
|
||||
{
|
||||
CsrpClientConnect,
|
||||
CsrpThreadConnect,
|
||||
CsrpProfileControl,
|
||||
CsrpIdentifyAlertable,
|
||||
CsrpSetPriorityClass,
|
||||
CsrpMaxApiNumber
|
||||
} CSR_SRV_API_NUMBER, *PCSR_SRV_API_NUMBER;
|
||||
|
||||
#define CSR_MAKE_OPCODE(s,m) ((s) << 16) | (m)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ list(APPEND SOURCE
|
|||
init.c
|
||||
wait.c
|
||||
session.c
|
||||
server.c
|
||||
${CMAKE_CURRENT_BINARY_DIR}/csrsrv.def)
|
||||
|
||||
add_library(csrsrv SHARED ${SOURCE})
|
||||
|
|
|
@ -113,197 +113,6 @@ CsrHandleHardError(IN PCSR_PROCESS ProcessData,
|
|||
(VOID)CallHardError(ProcessData, Message);
|
||||
}
|
||||
|
||||
PVOID CsrSrvSharedSectionHeap;
|
||||
PVOID CsrSrvSharedSectionBase;
|
||||
PVOID *CsrSrvSharedStaticServerData;
|
||||
ULONG CsrSrvSharedSectionSize;
|
||||
HANDLE CsrSrvSharedSection;
|
||||
|
||||
/*++
|
||||
* @name CsrSrvCreateSharedSection
|
||||
*
|
||||
* 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
|
||||
* othwerwise.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvCreateSharedSection(IN PCHAR ParameterValue)
|
||||
{
|
||||
PCHAR SizeValue = ParameterValue;
|
||||
ULONG Size;
|
||||
NTSTATUS Status;
|
||||
LARGE_INTEGER SectionSize;
|
||||
ULONG ViewSize = 0;
|
||||
SYSTEM_BASIC_INFORMATION CsrNtSysInfo;
|
||||
PPEB Peb = NtCurrentPeb();
|
||||
|
||||
/* ReactOS Hackssss */
|
||||
Status = NtQuerySystemInformation(SystemBasicInformation,
|
||||
&CsrNtSysInfo,
|
||||
sizeof(SYSTEM_BASIC_INFORMATION),
|
||||
NULL);
|
||||
ASSERT(NT_SUCCESS(Status));
|
||||
|
||||
/* Find the first comma, and null terminate */
|
||||
while (*SizeValue)
|
||||
{
|
||||
if (*SizeValue == ',')
|
||||
{
|
||||
*SizeValue++ = '\0';
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
SizeValue++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure it's valid */
|
||||
if (!*SizeValue) return STATUS_INVALID_PARAMETER;
|
||||
|
||||
/* Convert it to an integer */
|
||||
Status = RtlCharToInteger(SizeValue, 0, &Size);
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
|
||||
/* Multiply by 1024 entries and round to page size */
|
||||
CsrSrvSharedSectionSize = ROUND_UP(Size * 1024, CsrNtSysInfo.PageSize);
|
||||
|
||||
/* Create the Secion */
|
||||
SectionSize.LowPart = CsrSrvSharedSectionSize;
|
||||
SectionSize.HighPart = 0;
|
||||
Status = NtCreateSection(&CsrSrvSharedSection,
|
||||
SECTION_ALL_ACCESS,
|
||||
NULL,
|
||||
&SectionSize,
|
||||
PAGE_EXECUTE_READWRITE,
|
||||
SEC_BASED | SEC_RESERVE,
|
||||
NULL);
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
|
||||
/* Map the section */
|
||||
Status = NtMapViewOfSection(CsrSrvSharedSection,
|
||||
NtCurrentProcess(),
|
||||
&CsrSrvSharedSectionBase,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&ViewSize,
|
||||
ViewUnmap,
|
||||
MEM_TOP_DOWN,
|
||||
PAGE_EXECUTE_READWRITE);
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Fail */
|
||||
NtClose(CsrSrvSharedSection);
|
||||
return(Status);
|
||||
}
|
||||
|
||||
/* FIXME: Write the value to registry */
|
||||
|
||||
/* The Heap is the same place as the Base */
|
||||
CsrSrvSharedSectionHeap = CsrSrvSharedSectionBase;
|
||||
|
||||
/* Create the heap */
|
||||
if (!(RtlCreateHeap(HEAP_ZERO_MEMORY,
|
||||
CsrSrvSharedSectionHeap,
|
||||
CsrSrvSharedSectionSize,
|
||||
PAGE_SIZE,
|
||||
0,
|
||||
0)))
|
||||
{
|
||||
/* Failure, unmap section and return */
|
||||
NtUnmapViewOfSection(NtCurrentProcess(),
|
||||
CsrSrvSharedSectionBase);
|
||||
NtClose(CsrSrvSharedSection);
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
/* Now allocate space from the heap for the Shared Data */
|
||||
CsrSrvSharedStaticServerData = RtlAllocateHeap(CsrSrvSharedSectionHeap,
|
||||
0,
|
||||
4 * // HAX CSR_SERVER_DLL_MAX *
|
||||
sizeof(PVOID));
|
||||
|
||||
/* Write the values to the PEB */
|
||||
Peb->ReadOnlySharedMemoryBase = CsrSrvSharedSectionBase;
|
||||
Peb->ReadOnlySharedMemoryHeap = CsrSrvSharedSectionHeap;
|
||||
Peb->ReadOnlyStaticServerData = CsrSrvSharedStaticServerData;
|
||||
|
||||
/* Return */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrSrvAttachSharedSection
|
||||
*
|
||||
* The CsrSrvAttachSharedSection maps the CSR Shared Section into a new
|
||||
* CSR Process' address space, and returns the pointers to the section
|
||||
* through the Connection Info structure.
|
||||
*
|
||||
* @param CsrProcess
|
||||
* Pointer to the CSR Process that is attempting a connection.
|
||||
*
|
||||
* @param ConnectInfo
|
||||
* Pointer to the CSR Connection Info structure for the incoming
|
||||
* connection.
|
||||
*
|
||||
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
|
||||
* othwerwise.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
|
||||
OUT PCSR_CONNECTION_INFO ConnectInfo)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
ULONG ViewSize = 0;
|
||||
|
||||
/* Check if we have a process */
|
||||
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,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&ViewSize,
|
||||
ViewUnmap,
|
||||
SEC_NO_CHANGE,
|
||||
PAGE_EXECUTE_READ);
|
||||
if (Status == STATUS_CONFLICTING_ADDRESSES)
|
||||
{
|
||||
/* I Think our csrss tries to connect to itself... */
|
||||
DPRINT1("Multiple mapping hack\n");
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
}
|
||||
|
||||
/* Write the values in the Connection Info structure */
|
||||
ConnectInfo->SharedSectionBase = CsrSrvSharedSectionBase;
|
||||
ConnectInfo->SharedSectionHeap = CsrSrvSharedSectionHeap;
|
||||
ConnectInfo->SharedSectionData = CsrSrvSharedStaticServerData;
|
||||
|
||||
/* Return success */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrApiPortInitialize
|
||||
*
|
||||
|
|
|
@ -20,5 +20,6 @@
|
|||
<file>init.c</file>
|
||||
<file>wait.c</file>
|
||||
<file>session.c</file>
|
||||
<file>server.c</file>
|
||||
<pch>srv.h</pch>
|
||||
</module>
|
||||
|
|
|
@ -182,10 +182,6 @@ VOID
|
|||
WINAPI
|
||||
BasepFakeStaticServerData(VOID);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvCreateSharedSection(IN PCHAR ParameterValue);
|
||||
|
||||
/*++
|
||||
* @name CsrSetProcessSecurity
|
||||
*
|
||||
|
|
698
reactos/subsystems/win32/csrss/csrsrv/server.c
Normal file
698
reactos/subsystems/win32/csrss/csrsrv/server.c
Normal file
|
@ -0,0 +1,698 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS CSR Sub System
|
||||
* FILE: subsys/csr/csrsrv/server.c
|
||||
* PURPOSE: CSR Server DLL Server Functions
|
||||
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
#include "srv.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
/* DATA **********************************************************************/
|
||||
|
||||
PCSR_API_ROUTINE CsrServerApiDispatchTable[5] =
|
||||
{
|
||||
CsrSrvClientConnect,
|
||||
CsrSrvUnusedFunction,
|
||||
CsrSrvUnusedFunction,
|
||||
CsrSrvIdentifyAlertableThread,
|
||||
CsrSrvSetPriorityClass
|
||||
};
|
||||
|
||||
BOOLEAN CsrServerApiServerValidTable[5] =
|
||||
{
|
||||
TRUE,
|
||||
FALSE,
|
||||
TRUE,
|
||||
TRUE,
|
||||
TRUE
|
||||
};
|
||||
|
||||
PCHAR CsrServerApiNameTable[5] =
|
||||
{
|
||||
"ClientConnect",
|
||||
"ThreadConnect",
|
||||
"ProfileControl",
|
||||
"IdentifyAlertableThread",
|
||||
"SetPriorityClass"
|
||||
};
|
||||
|
||||
PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX];
|
||||
PVOID CsrSrvSharedSectionHeap;
|
||||
PVOID CsrSrvSharedSectionBase;
|
||||
PVOID *CsrSrvSharedStaticServerData;
|
||||
ULONG CsrSrvSharedSectionSize;
|
||||
HANDLE CsrSrvSharedSection;
|
||||
|
||||
/* PRIVATE FUNCTIONS**********************************************************/
|
||||
|
||||
/*++
|
||||
* @name CsrServerDllInitialization
|
||||
* @implemented NT4
|
||||
*
|
||||
* The CsrServerDllInitialization is the initialization routine for
|
||||
* the this Server DLL.
|
||||
*
|
||||
* @param LoadedServerDll
|
||||
* Pointer to the CSR Server DLL structure representing this Server DLL.
|
||||
*
|
||||
* @return STATUS_SUCCESS.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrServerDllInitialization(IN PCSR_SERVER_DLL LoadedServerDll)
|
||||
{
|
||||
/* Setup the DLL Object */
|
||||
LoadedServerDll->ApiBase = 0;
|
||||
LoadedServerDll->HighestApiSupported = 5;
|
||||
LoadedServerDll->DispatchTable = CsrServerApiDispatchTable;
|
||||
LoadedServerDll->ValidTable = CsrServerApiServerValidTable;
|
||||
LoadedServerDll->NameTable = CsrServerApiNameTable;
|
||||
LoadedServerDll->SizeOfProcessData = 0;
|
||||
LoadedServerDll->ConnectCallback = NULL;
|
||||
LoadedServerDll->DisconnectCallback = NULL;
|
||||
|
||||
/* All done */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrLoadServerDll
|
||||
* @implemented NT4
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
|
||||
* othwerwise.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrLoadServerDll(IN PCHAR DllString,
|
||||
IN PCHAR EntryPoint OPTIONAL,
|
||||
IN ULONG ServerId)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
ANSI_STRING DllName;
|
||||
UNICODE_STRING TempString, ErrorString;
|
||||
ULONG_PTR Parameters[2];
|
||||
HANDLE hServerDll = NULL;
|
||||
ULONG Size;
|
||||
PCSR_SERVER_DLL ServerDll;
|
||||
STRING EntryPointString;
|
||||
PCSR_SERVER_DLL_INIT_CALLBACK ServerDllInitProcedure;
|
||||
ULONG Response;
|
||||
|
||||
/* Check if it's beyond the maximum we support */
|
||||
if (ServerId >= CSR_SERVER_DLL_MAX) return STATUS_TOO_MANY_NAMES;
|
||||
|
||||
/* Check if it's already been loaded */
|
||||
if (CsrLoadedServerDll[ServerId]) return STATUS_INVALID_PARAMETER;
|
||||
|
||||
/* Convert the name to Unicode */
|
||||
ASSERT(DllString != NULL);
|
||||
RtlInitAnsiString(&DllName, DllString);
|
||||
Status = RtlAnsiStringToUnicodeString(&TempString, &DllName, TRUE);
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
|
||||
/* If we are loading ourselves, don't actually load us */
|
||||
if (ServerId != CSR_SRV_SERVER)
|
||||
{
|
||||
/* Load the DLL */
|
||||
Status = LdrLoadDll(NULL, 0, &TempString, &hServerDll);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Setup error parameters */
|
||||
Parameters[0] = (ULONG_PTR)&TempString;
|
||||
Parameters[1] = (ULONG_PTR)&ErrorString;
|
||||
RtlInitUnicodeString(&ErrorString, L"Default Load Path");
|
||||
|
||||
/* Send a hard error */
|
||||
NtRaiseHardError(Status,
|
||||
2,
|
||||
3,
|
||||
Parameters,
|
||||
OptionOk,
|
||||
&Response);
|
||||
}
|
||||
|
||||
/* Get rid of the string */
|
||||
RtlFreeUnicodeString(&TempString);
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
}
|
||||
|
||||
/* Allocate a CSR DLL Object */
|
||||
Size = sizeof(CSR_SERVER_DLL) + DllName.MaximumLength;
|
||||
ServerDll = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, Size);
|
||||
if (!ServerDll)
|
||||
{
|
||||
if (hServerDll) LdrUnloadDll(hServerDll);
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
/* Set up the Object */
|
||||
ServerDll->Length = Size;
|
||||
ServerDll->SharedSection = CsrSrvSharedSectionHeap;
|
||||
ServerDll->Event = CsrInitializationEvent;
|
||||
ServerDll->Name.Length = DllName.Length;
|
||||
ServerDll->Name.MaximumLength = DllName.MaximumLength;
|
||||
ServerDll->Name.Buffer = (PCHAR)(ServerDll + 1);
|
||||
if (DllName.Length)
|
||||
{
|
||||
strncpy(ServerDll->Name.Buffer, DllName.Buffer, DllName.Length);
|
||||
}
|
||||
ServerDll->ServerId = ServerId;
|
||||
ServerDll->ServerHandle = hServerDll;
|
||||
|
||||
/* Now get the entrypoint */
|
||||
if (hServerDll)
|
||||
{
|
||||
/* Initialize a string for the entrypoint, or use the default */
|
||||
RtlInitAnsiString(&EntryPointString,
|
||||
!(EntryPoint) ? "ServerDllInitialization" :
|
||||
EntryPoint);
|
||||
|
||||
/* Get a pointer to it */
|
||||
Status = LdrGetProcedureAddress(hServerDll,
|
||||
&EntryPointString,
|
||||
0,
|
||||
(PVOID)&ServerDllInitProcedure);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No handle, so we are loading ourselves */
|
||||
ServerDllInitProcedure = CsrServerDllInitialization;
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* Check if we got the pointer, and call it */
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
/* Get the result from the Server DLL */
|
||||
Status = ServerDllInitProcedure(ServerDll);
|
||||
|
||||
/* Check for Success */
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
/*
|
||||
* Add this Server's Per-Process Data Size to the total that each
|
||||
* process will need.
|
||||
*/
|
||||
CsrTotalPerProcessDataLength += ServerDll->SizeOfProcessData;
|
||||
|
||||
/* Save the pointer in our list */
|
||||
CsrLoadedServerDll[ServerDll->ServerId] = ServerDll;
|
||||
|
||||
/* Does it use our generic heap? */
|
||||
if (ServerDll->SharedSection != CsrSrvSharedSectionHeap)
|
||||
{
|
||||
/* No, save the pointer to its shared section in our list */
|
||||
CsrSrvSharedStaticServerData[ServerDll->ServerId] = ServerDll->SharedSection;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use shared failure code */
|
||||
goto LoadFailed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadFailed:
|
||||
/* Server Init failed, unload it */
|
||||
if (hServerDll) LdrUnloadDll(hServerDll);
|
||||
|
||||
/* Delete the Object */
|
||||
RtlFreeHeap(CsrHeap, 0, ServerDll);
|
||||
}
|
||||
|
||||
/* Return to caller */
|
||||
return Status;
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrSrvClientConnect
|
||||
*
|
||||
* The CsrSrvClientConnect CSR API handles a new connection to a server DLL.
|
||||
*
|
||||
* @param ApiMessage
|
||||
* Pointer to the CSR API Message for this request.
|
||||
*
|
||||
* @param Reply
|
||||
* Optional reply to this request.
|
||||
*
|
||||
* @return STATUS_SUCCESS in case of success, STATUS_INVALID_PARAMETER
|
||||
* or STATUS_TOO_MANY_NAMES in case of failure.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvClientConnect(IN OUT PCSR_API_MESSAGE ApiMessage,
|
||||
IN OUT PULONG Reply OPTIONAL)
|
||||
{
|
||||
/* Hack */
|
||||
return STATUS_SUCCESS;
|
||||
#if 0
|
||||
NTSTATUS Status;
|
||||
PCSR_CLIENT_CONNECT ClientConnect;
|
||||
PCSR_SERVER_DLL ServerDll;
|
||||
PCSR_PROCESS CurrentProcess = ((PCSR_THREAD)NtCurrentTeb()->CsrClientThread)->Process;
|
||||
|
||||
/* Load the Message, set default reply */
|
||||
ClientConnect = (PCSR_CLIENT_CONNECT)&ApiMessage->CsrClientConnect;
|
||||
*Reply = 0;
|
||||
|
||||
/* Validate the ServerID */
|
||||
if (ClientConnect->ServerId >= CSR_SERVER_DLL_MAX)
|
||||
{
|
||||
return STATUS_TOO_MANY_NAMES;
|
||||
}
|
||||
else if (!CsrLoadedServerDll[ClientConnect->ServerId])
|
||||
{
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
/* Validate the Message Buffer */
|
||||
if (!(CsrValidateMessageBuffer(ApiMessage,
|
||||
ClientConnect->ConnectionInfo,
|
||||
ClientConnect->ConnectionInfoSize,
|
||||
1)))
|
||||
{
|
||||
/* Fail due to buffer overflow or other invalid buffer */
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
/* Load the Server DLL */
|
||||
ServerDll = CsrLoadedServerDll[ClientConnect->ServerId];
|
||||
|
||||
/* Check if it has a Connect Callback */
|
||||
if (ServerDll->ConnectCallback)
|
||||
{
|
||||
/* Call the callback */
|
||||
Status = ServerDll->ConnectCallback(CurrentProcess,
|
||||
ClientConnect->ConnectionInfo,
|
||||
&ClientConnect->ConnectionInfoSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Assume success */
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* Return status */
|
||||
return Status;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrSrvCreateSharedSection
|
||||
*
|
||||
* 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
|
||||
* othwerwise.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvCreateSharedSection(IN PCHAR ParameterValue)
|
||||
{
|
||||
PCHAR SizeValue = ParameterValue;
|
||||
ULONG Size;
|
||||
NTSTATUS Status;
|
||||
LARGE_INTEGER SectionSize;
|
||||
ULONG ViewSize = 0;
|
||||
PPEB Peb = NtCurrentPeb();
|
||||
|
||||
/* If there's no parameter, fail */
|
||||
if (!ParameterValue) return STATUS_INVALID_PARAMETER;
|
||||
|
||||
/* Find the first comma, and null terminate */
|
||||
while (*SizeValue)
|
||||
{
|
||||
if (*SizeValue == ',')
|
||||
{
|
||||
*SizeValue++ = ANSI_NULL;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
SizeValue++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure it's valid */
|
||||
if (!*SizeValue) return STATUS_INVALID_PARAMETER;
|
||||
|
||||
/* Convert it to an integer */
|
||||
Status = RtlCharToInteger(SizeValue, 0, &Size);
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
|
||||
/* Multiply by 1024 entries and round to page size */
|
||||
CsrSrvSharedSectionSize = ROUND_UP(Size * 1024, CsrNtSysInfo.PageSize);
|
||||
|
||||
/* Create the Secion */
|
||||
SectionSize.LowPart = CsrSrvSharedSectionSize;
|
||||
SectionSize.HighPart = 0;
|
||||
Status = NtCreateSection(&CsrSrvSharedSection,
|
||||
SECTION_ALL_ACCESS,
|
||||
NULL,
|
||||
&SectionSize,
|
||||
PAGE_EXECUTE_READWRITE,
|
||||
SEC_BASED | SEC_RESERVE,
|
||||
NULL);
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
|
||||
/* Map the section */
|
||||
Status = NtMapViewOfSection(CsrSrvSharedSection,
|
||||
NtCurrentProcess(),
|
||||
&CsrSrvSharedSectionBase,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&ViewSize,
|
||||
ViewUnmap,
|
||||
MEM_TOP_DOWN,
|
||||
PAGE_EXECUTE_READWRITE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Fail */
|
||||
NtClose(CsrSrvSharedSection);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* FIXME: Write the value to registry */
|
||||
|
||||
/* The Heap is the same place as the Base */
|
||||
CsrSrvSharedSectionHeap = CsrSrvSharedSectionBase;
|
||||
|
||||
/* Create the heap */
|
||||
if (!(RtlCreateHeap(HEAP_ZERO_MEMORY | HEAP_CLASS_7,
|
||||
CsrSrvSharedSectionHeap,
|
||||
CsrSrvSharedSectionSize,
|
||||
PAGE_SIZE,
|
||||
0,
|
||||
0)))
|
||||
{
|
||||
/* Failure, unmap section and return */
|
||||
NtUnmapViewOfSection(NtCurrentProcess(), CsrSrvSharedSectionBase);
|
||||
NtClose(CsrSrvSharedSection);
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
/* Now allocate space from the heap for the Shared Data */
|
||||
CsrSrvSharedStaticServerData = RtlAllocateHeap(CsrSrvSharedSectionHeap,
|
||||
0,
|
||||
CSR_SERVER_DLL_MAX *
|
||||
sizeof(PVOID));
|
||||
if (!CsrSrvSharedStaticServerData) return STATUS_NO_MEMORY;
|
||||
|
||||
/* Write the values to the PEB */
|
||||
Peb->ReadOnlySharedMemoryBase = CsrSrvSharedSectionBase;
|
||||
Peb->ReadOnlySharedMemoryHeap = CsrSrvSharedSectionHeap;
|
||||
Peb->ReadOnlyStaticServerData = CsrSrvSharedStaticServerData;
|
||||
|
||||
/* Return */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrSrvAttachSharedSection
|
||||
*
|
||||
* The CsrSrvAttachSharedSection maps the CSR Shared Section into a new
|
||||
* CSR Process' address space, and returns the pointers to the section
|
||||
* through the Connection Info structure.
|
||||
*
|
||||
* @param CsrProcess
|
||||
* Pointer to the CSR Process that is attempting a connection.
|
||||
*
|
||||
* @param ConnectInfo
|
||||
* Pointer to the CSR Connection Info structure for the incoming
|
||||
* connection.
|
||||
*
|
||||
* @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
|
||||
* othwerwise.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
|
||||
OUT PCSR_CONNECTION_INFO ConnectInfo)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
ULONG ViewSize = 0;
|
||||
|
||||
/* Check if we have a process */
|
||||
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,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&ViewSize,
|
||||
ViewUnmap,
|
||||
SEC_NO_CHANGE,
|
||||
PAGE_EXECUTE_READ);
|
||||
if (Status == STATUS_CONFLICTING_ADDRESSES)
|
||||
{
|
||||
/* I Think our csrss tries to connect to itself... */
|
||||
DPRINT1("Multiple mapping hack\n");
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
}
|
||||
|
||||
/* Write the values in the Connection Info structure */
|
||||
ConnectInfo->SharedSectionBase = CsrSrvSharedSectionBase;
|
||||
ConnectInfo->SharedSectionHeap = CsrSrvSharedSectionHeap;
|
||||
ConnectInfo->SharedSectionData = CsrSrvSharedStaticServerData;
|
||||
|
||||
/* Return success */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrSrvIdentifyAlertableThread
|
||||
* @implemented NT4
|
||||
*
|
||||
* The CsrSrvIdentifyAlertableThread CSR API marks a CSR Thread as alertable.
|
||||
*
|
||||
* @param ApiMessage
|
||||
* Pointer to the CSR API Message for this request.
|
||||
*
|
||||
* @param Reply
|
||||
* Pointer to an optional reply to this request.
|
||||
*
|
||||
* @return STATUS_SUCCESS.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvIdentifyAlertableThread(IN OUT PCSR_API_MESSAGE ApiMessage,
|
||||
IN OUT PULONG Reply)
|
||||
{
|
||||
PCSR_THREAD CsrThread = NtCurrentTeb()->CsrClientThread;
|
||||
|
||||
/* Set the alertable flag */
|
||||
CsrThread->Flags |= CsrThreadAltertable;
|
||||
|
||||
/* Return success */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrSrvSetPriorityClass
|
||||
* @implemented NT4
|
||||
*
|
||||
* The CsrSrvSetPriorityClass CSR API is deprecated.
|
||||
*
|
||||
* @param ApiMessage
|
||||
* Pointer to the CSR API Message for this request.
|
||||
*
|
||||
* @param Reply
|
||||
* Pointer to an optional reply to this request.
|
||||
*
|
||||
* @return STATUS_SUCCESS.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvSetPriorityClass(IN OUT PCSR_API_MESSAGE ApiMessage,
|
||||
IN OUT PULONG Reply)
|
||||
{
|
||||
/* Deprecated */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrSrvUnusedFunction
|
||||
* @implemented NT4
|
||||
*
|
||||
* The CsrSrvUnusedFunction CSR API is a stub for deprecated APIs.
|
||||
*
|
||||
* The CsrSrvSetPriorityClass CSR API is deprecated.
|
||||
*
|
||||
* @param ApiMessage
|
||||
* Pointer to the CSR API Message for this request.
|
||||
*
|
||||
* @param Reply
|
||||
* Pointer to an optional reply to this request.
|
||||
*
|
||||
* @return STATUS_INVALID_PARAMETER.
|
||||
*
|
||||
* @remarks CsrSrvSetPriorityClass does not use this stub because it must
|
||||
* return success.
|
||||
*
|
||||
*--*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvUnusedFunction(IN OUT PCSR_API_MESSAGE ApiMessage,
|
||||
IN OUT PULONG Reply)
|
||||
{
|
||||
/* Deprecated */
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
/* PUBLIC FUNCTIONS***********************************************************/
|
||||
|
||||
/*++
|
||||
* @name CsrSetCallingSpooler
|
||||
* @implemented NT4
|
||||
*
|
||||
* the CsrSetCallingSpooler routine is deprecated.
|
||||
*
|
||||
* @param Reserved
|
||||
* Deprecated
|
||||
*
|
||||
* @return None.
|
||||
*
|
||||
* @remarks This routine was used in archaic versions of NT for Printer Drivers.
|
||||
*
|
||||
*--*/
|
||||
VOID
|
||||
NTAPI
|
||||
CsrSetCallingSpooler(ULONG Reserved)
|
||||
{
|
||||
/* Deprecated */
|
||||
return;
|
||||
}
|
||||
|
||||
/*++
|
||||
* @name CsrUnhandledExceptionFilter
|
||||
* @implemented NT5
|
||||
*
|
||||
* The CsrUnhandledExceptionFilter routine handles all exceptions
|
||||
* within SEH-protected blocks.
|
||||
*
|
||||
* @param ExceptionPointers
|
||||
* System-defined Argument.
|
||||
*
|
||||
* @return EXCEPTION_EXECUTE_HANDLER.
|
||||
*
|
||||
* @remarks None.
|
||||
*
|
||||
*--*/
|
||||
LONG
|
||||
NTAPI
|
||||
CsrUnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
|
||||
{
|
||||
SYSTEM_KERNEL_DEBUGGER_INFORMATION DebuggerInfo;
|
||||
EXCEPTION_DISPOSITION Result = EXCEPTION_EXECUTE_HANDLER;
|
||||
BOOLEAN OldValue;
|
||||
NTSTATUS Status;
|
||||
UNICODE_STRING ErrorSource;
|
||||
ULONG_PTR ErrorParameters[4];
|
||||
ULONG Response;
|
||||
|
||||
/* Check if a debugger is installed */
|
||||
Status = NtQuerySystemInformation(SystemKernelDebuggerInformation,
|
||||
&DebuggerInfo,
|
||||
sizeof(DebuggerInfo),
|
||||
NULL);
|
||||
|
||||
/* Check if this is Session 0, and the Debugger is Enabled */
|
||||
if ((NtCurrentPeb()->SessionId) && (NT_SUCCESS(Status)) &&
|
||||
(DebuggerInfo.KernelDebuggerEnabled))
|
||||
{
|
||||
/* Call the Unhandled Exception Filter */
|
||||
if ((Result = RtlUnhandledExceptionFilter(ExceptionInfo)) !=
|
||||
EXCEPTION_CONTINUE_EXECUTION)
|
||||
{
|
||||
/* We're going to raise an error. Get Shutdown Privilege first */
|
||||
Status = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE,
|
||||
TRUE,
|
||||
TRUE,
|
||||
&OldValue);
|
||||
|
||||
/* Use the Process token if that failed */
|
||||
if (Status == STATUS_NO_TOKEN)
|
||||
{
|
||||
Status = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE,
|
||||
TRUE,
|
||||
FALSE,
|
||||
&OldValue);
|
||||
}
|
||||
|
||||
/* Initialize our Name String */
|
||||
RtlInitUnicodeString(&ErrorSource, L"Windows SubSystem");
|
||||
|
||||
/* Set the parameters */
|
||||
ErrorParameters[0] = PtrToUlong(&ErrorSource);
|
||||
ErrorParameters[1] = ExceptionInfo->ExceptionRecord->ExceptionCode;
|
||||
ErrorParameters[2] = PtrToUlong(ExceptionInfo->ExceptionRecord->ExceptionAddress);
|
||||
ErrorParameters[3] = PtrToUlong(ExceptionInfo->ContextRecord);
|
||||
|
||||
/* Bugcheck */
|
||||
Status = NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED,
|
||||
4,
|
||||
1,
|
||||
ErrorParameters,
|
||||
OptionShutdownSystem,
|
||||
&Response);
|
||||
}
|
||||
|
||||
/* Just terminate us */
|
||||
NtTerminateProcess(NtCurrentProcess(),
|
||||
ExceptionInfo->ExceptionRecord->ExceptionCode);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/* EOF */
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <csrss/csrss.h>
|
||||
|
||||
#define CSR_SRV_SERVER 0
|
||||
#define CSR_SERVER_DLL_MAX 4
|
||||
#define LOCK RtlEnterCriticalSection(&ProcessDataLock)
|
||||
#define UNLOCK RtlLeaveCriticalSection(&ProcessDataLock)
|
||||
|
@ -151,6 +152,75 @@ typedef struct _CSR_WAIT_BLOCK
|
|||
CSR_API_MESSAGE WaitApiMessage;
|
||||
} CSR_WAIT_BLOCK, *PCSR_WAIT_BLOCK;
|
||||
|
||||
typedef
|
||||
NTSTATUS
|
||||
(NTAPI *PCSR_CONNECT_CALLBACK)(
|
||||
IN PCSR_PROCESS CsrProcess,
|
||||
IN OUT PVOID ConnectionInfo,
|
||||
IN OUT PULONG ConnectionInfoLength
|
||||
);
|
||||
|
||||
typedef
|
||||
VOID
|
||||
(NTAPI *PCSR_DISCONNECT_CALLBACK)(IN PCSR_PROCESS CsrProcess);
|
||||
|
||||
typedef
|
||||
NTSTATUS
|
||||
(NTAPI *PCSR_NEWPROCESS_CALLBACK)(
|
||||
IN PCSR_PROCESS Parent,
|
||||
IN PCSR_PROCESS CsrProcess
|
||||
);
|
||||
|
||||
typedef
|
||||
VOID
|
||||
(NTAPI *PCSR_HARDERROR_CALLBACK)(
|
||||
IN PCSR_THREAD CsrThread,
|
||||
IN PHARDERROR_MSG HardErrorMessage
|
||||
);
|
||||
|
||||
typedef
|
||||
ULONG
|
||||
(NTAPI *PCSR_SHUTDOWNPROCESS_CALLBACK)(
|
||||
IN PCSR_PROCESS CsrProcess,
|
||||
IN ULONG Flags,
|
||||
IN BOOLEAN FirstPhase
|
||||
);
|
||||
|
||||
typedef
|
||||
NTSTATUS
|
||||
(NTAPI *PCSR_API_ROUTINE)(
|
||||
IN OUT PCSR_API_MESSAGE ApiMessage,
|
||||
IN OUT PULONG Reply
|
||||
);
|
||||
|
||||
typedef struct _CSR_SERVER_DLL
|
||||
{
|
||||
ULONG Length;
|
||||
HANDLE Event;
|
||||
ANSI_STRING Name;
|
||||
HANDLE ServerHandle;
|
||||
ULONG ServerId;
|
||||
ULONG Unknown;
|
||||
ULONG ApiBase;
|
||||
ULONG HighestApiSupported;
|
||||
PCSR_API_ROUTINE *DispatchTable;
|
||||
PBOOLEAN ValidTable;
|
||||
PCHAR *NameTable;
|
||||
ULONG SizeOfProcessData;
|
||||
PCSR_CONNECT_CALLBACK ConnectCallback;
|
||||
PCSR_DISCONNECT_CALLBACK DisconnectCallback;
|
||||
PCSR_HARDERROR_CALLBACK HardErrorCallback;
|
||||
PVOID SharedSection;
|
||||
PCSR_NEWPROCESS_CALLBACK NewProcessCallback;
|
||||
PCSR_SHUTDOWNPROCESS_CALLBACK ShutdownProcessCallback;
|
||||
ULONG Unknown2[3];
|
||||
} CSR_SERVER_DLL, *PCSR_SERVER_DLL;
|
||||
|
||||
typedef
|
||||
NTSTATUS
|
||||
(NTAPI *PCSR_SERVER_DLL_INIT_CALLBACK)(IN PCSR_SERVER_DLL ServerDll);
|
||||
|
||||
|
||||
typedef NTSTATUS (WINAPI *CSRSS_API_PROC)(PCSR_PROCESS ProcessData,
|
||||
PCSR_API_MESSAGE Request);
|
||||
|
||||
|
@ -237,6 +307,11 @@ extern PCSR_PROCESS CsrRootProcess;
|
|||
extern RTL_CRITICAL_SECTION ProcessDataLock, CsrWaitListsLock;
|
||||
extern UNICODE_STRING CsrDirectoryName;
|
||||
extern ULONG CsrDebug;
|
||||
extern ULONG CsrTotalPerProcessDataLength;
|
||||
extern SYSTEM_BASIC_INFORMATION CsrNtSysInfo;
|
||||
extern PVOID CsrSrvSharedSectionHeap;
|
||||
extern PVOID *CsrSrvSharedStaticServerData;
|
||||
extern HANDLE CsrInitializationEvent;
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
|
@ -273,6 +348,43 @@ NTSTATUS
|
|||
NTAPI
|
||||
CsrInitializeNtSessionList(VOID);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvAttachSharedSection(IN PCSR_PROCESS CsrProcess OPTIONAL,
|
||||
OUT PCSR_CONNECTION_INFO ConnectInfo);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvCreateSharedSection(IN PCHAR ParameterValue);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvClientConnect(
|
||||
IN OUT PCSR_API_MESSAGE ApiMessage,
|
||||
IN OUT PULONG Reply
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvUnusedFunction(
|
||||
IN OUT PCSR_API_MESSAGE ApiMessage,
|
||||
IN OUT PULONG Reply
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvIdentifyAlertableThread(
|
||||
IN OUT PCSR_API_MESSAGE ApiMessage,
|
||||
IN OUT PULONG Reply
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CsrSrvSetPriorityClass(
|
||||
IN OUT PCSR_API_MESSAGE ApiMessage,
|
||||
IN OUT PULONG Reply
|
||||
);
|
||||
|
||||
/* api/user.c */
|
||||
CSR_API(CsrRegisterServicesProcess);
|
||||
|
||||
|
|
Loading…
Reference in a new issue