|
From: Aliberti E. <ea...@us...> - 2002-05-21 22:46:09
|
CSRSS Explained
---------------
This is very basic overview of the csrss.exe internals.
A thing to keep in mind is that, at the origins of NT, there was a
single user-mode server that made environment subsystems live. That
is why the meta-server is still called "client/server runtime" (CSR)
even if actually now is the runtime exclusively for the Win32 server.
Today you can see its command line in
HKLM\SYSTEM\CurrentControlSet\Control\
Session Manager\Subsystems\Windows
I write it down here (from an NT 4.0 system):
%SystemRoot%\system32\csrss.exe
ObjectDirectory=\Windows
SharedSection=1024,3072
Windows=On
SubSystemType=Windows
ServerDll=basesrv,1
ServerDll=winsrv:UserServerDllInitialization,3
ServerDll=winsrv:ConServerDllInitialization,2
ProfileControl=Off
MaxRequestThreads=16
In those days, if I was going to write a new environment subsystem, I
just needed to write a DLL and add one more parameter to that key
ServerDll={module}[:{entrypoint}],{subsystem_id}
where
{module} is the server DLL file name without ".dll" suffix;
{entrypoint} is optional and needs to be specified only if the DLL
does not export the symbol "ServerDllInitialization" (winsrv.dll
contains two servers);
{subsystem_id} is a nonnegative integer to be used in
NTDLL.CsrClientCallServer to specify the subsystem to the which the
LPC message is sent to:
The key element in this entry is the subsystem_id, because it allows
the client side DLLs to communicate with a server side DLL loaded by
csrss.exe.
Id 0 is only used in NTDLL.DLL itself to call service code in
CSRSS.EXE;
Id 1 and 2 are used in KERNEL32.DLL;
Id 3 is used in USER32.DLL and probably other libraries.
To call service number n in a server DLL loaded with server number m
you just need to fill a CSR_CCS object and pass it (by value) as the
3rd parameter of NTDLL.CsrClientCallServer().
/* CSRSS basics */
typedef struct _CSR_CCS
{
WORD Index; // API number
WORD ServerId; // Server's ID
} CSR_CCS, * PCSR_CCS;
#define CSR_SERVER_INTERNAL 0
#define CSR_SERVER_WINDOWS_BASE 1
#define CSR_SERVER_WINDOWS_CONSOLE 2
#define CSR_SERVER_WINDOWS_USER 3
NTSTATUS STDCALL
CsrClientCallServer(
PVOID RequestData,
PVOID Unknown OPTIONAL, // Csr capture facility related
CSR_CCS SvrApi,
ULONG SizeOfRequestData
);
/* Pseudo code for a call:
CSR_CCS svrapi;
NTSTATUS Status;
DWORD data[16];
svrapi.ServerId = CSR_SERVER_WINDOWS_CONSOLE;
svrapi.Index = 0x0208; // GetConsoleMode()
Status = CsrClientCallServer (data, NULL, svrapi, sizeof data);
*/
Just like in ReactOS, in NT, NTDLL.CsrClientCallServer() uses the LPC
facility.
|