Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

csrdll.h File Reference

#include "csr.h"
#include "ntcsrdll.h"
#include "ntcsrsrv.h"

Go to the source code of this file.

Defines

#define IF_CSR_DEBUG(ComponentFlag)   if (FALSE)
#define CSR_HEAP_MEMORY_SIZE   (64*1024)
#define CSR_PORT_MEMORY_SIZE   0x10000
#define ROUND_UP_TO_PAGES(SIZE)   (((ULONG)(SIZE) + CsrNtSysInfo.PageSize - 1) & ~(CsrNtSysInfo.PageSize - 1))
#define ROUND_DOWN_TO_PAGES(SIZE)   (((ULONG)(SIZE)) & ~(CsrNtSysInfo.PageSize - 1))
#define MAKE_CSRPORT_TAG(t)   (RTL_HEAP_MAKE_TAG( CsrPortBaseTag, t ))
#define CAPTURE_TAG   0
#define CSR_MAX_CLIENT_DLL   16

Functions

BOOLEAN CsrDllInitialize (IN PVOID DllHandle, IN ULONG Reason, IN PCONTEXT Context OPTIONAL)
NTSTATUS CsrpConnectToServer (IN PWSTR ObjectDirectory)

Variables

BOOLEAN CsrInitOnceDone
BOOLEAN CsrServerProcess
NTSTATUS(* CsrServerApiRoutine )(PCSR_API_MSG, PCSR_API_MSG)
SYSTEM_BASIC_INFORMATION CsrNtSysInfo
ULONG CsrDebugFlag
PVOID CsrHeap
UNICODE_STRING CsrPortName
HANDLE CsrPortHandle
PVOID CsrPortHeap
ULONG_PTR CsrPortMemoryRemoteDelta
ULONG CsrPortBaseTag
HANDLE CsrDllHandle
HANDLE CsrObjectDirectory
PCSR_CALLBACK_INFO CsrLoadedClientDll [CSR_MAX_CLIENT_DLL]


Define Documentation

#define CAPTURE_TAG   0
 

Definition at line 167 of file csrdll.h.

Referenced by CsrAllocateCaptureBuffer().

#define CSR_HEAP_MEMORY_SIZE   (64*1024)
 

Definition at line 86 of file csrdll.h.

#define CSR_MAX_CLIENT_DLL   16
 

Definition at line 191 of file csrdll.h.

#define CSR_PORT_MEMORY_SIZE   0x10000
 

Definition at line 95 of file csrdll.h.

Referenced by CsrpConnectToServer().

#define IF_CSR_DEBUG ComponentFlag   )     if (FALSE)
 

Definition at line 73 of file csrdll.h.

Referenced by CsrpConnectToServer().

#define MAKE_CSRPORT_TAG  )     (RTL_HEAP_MAKE_TAG( CsrPortBaseTag, t ))
 

Definition at line 165 of file csrdll.h.

Referenced by CsrAllocateCaptureBuffer().

#define ROUND_DOWN_TO_PAGES SIZE   )     (((ULONG)(SIZE)) & ~(CsrNtSysInfo.PageSize - 1))
 

Definition at line 125 of file csrdll.h.

#define ROUND_UP_TO_PAGES SIZE   )     (((ULONG)(SIZE) + CsrNtSysInfo.PageSize - 1) & ~(CsrNtSysInfo.PageSize - 1))
 

Definition at line 124 of file csrdll.h.

Referenced by InitCreateSharedSection().


Function Documentation

BOOLEAN CsrDllInitialize IN PVOID  DllHandle,
IN ULONG  Reason,
IN PCONTEXT Context  OPTIONAL
 

Definition at line 30 of file csrinit.c.

References CsrDllHandle, and TRUE.

00038 : 00039 00040 This function is the DLL initialization routine for the Client DLL 00041 This function gets control when the application links to this DLL 00042 are snapped. 00043 00044 Arguments: 00045 00046 Context - Supplies an optional context buffer that will be restore 00047 after all DLL initialization has been completed. If this 00048 parameter is NULL then this is a dynamic snap of this module. 00049 Otherwise this is a static snap prior to the user process 00050 gaining control. 00051 00052 Return Value: 00053 00054 Status value. 00055 00056 --*/ 00057 00058 { 00059 Context; 00060 00061 if (Reason != DLL_PROCESS_ATTACH) { 00062 return( TRUE ); 00063 } 00064 00065 // 00066 // Remember our DLL handle in a global variable. 00067 // 00068 00069 CsrDllHandle = DllHandle; 00070 00071 return( TRUE ); 00072 }

NTSTATUS CsrpConnectToServer IN PWSTR  ObjectDirectory  ) 
 

Definition at line 359 of file csrinit.c.

References CSR_PORT_MEMORY_SIZE, CSR_TAG, CsrHeap, CsrNtSysInfo, CsrObjectDirectory, CsrPortBaseTag, CsrPortHandle, CsrPortHeap, CsrPortMemoryRemoteDelta, CsrPortName, DbgPrint, DynamicQos, IF_CSR_DEBUG, IF_DEBUG, L, MAKE_TAG, n, NT_SUCCESS, NtClose(), NtCreateSection(), NtSecureConnectPort(), NTSTATUS(), NULL, RtlAllocateAndInitializeSid(), RtlAllocateHeap, RtlAppendUnicodeToString(), RtlCreateHeap(), RtlCreateTagHeap(), RtlFreeSid(), Status, TRUE, USHORT, and xProtectHandle().

Referenced by CsrClientConnectToServer().

00362 { 00363 NTSTATUS Status; 00364 REMOTE_PORT_VIEW ServerView; 00365 ULONG MaxMessageLength; 00366 ULONG ConnectionInformationLength; 00367 CSR_API_CONNECTINFO ConnectionInformation; 00368 SECURITY_QUALITY_OF_SERVICE DynamicQos; 00369 HANDLE PortSection; 00370 PORT_VIEW ClientView; 00371 ULONG n; 00372 LARGE_INTEGER SectionSize; 00373 SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; 00374 PSID SystemSid; 00375 00376 // 00377 // Create the port name string by combining the passed in object directory 00378 // name with the port name. 00379 // 00380 00381 n = ((wcslen( ObjectDirectory ) + 1) * sizeof( WCHAR )) + 00382 sizeof( CSR_API_PORT_NAME ); 00383 CsrPortName.Length = 0; 00384 CsrPortName.MaximumLength = (USHORT)n; 00385 CsrPortName.Buffer = RtlAllocateHeap( CsrHeap, MAKE_TAG( CSR_TAG ), n ); 00386 if (CsrPortName.Buffer == NULL) { 00387 return( STATUS_NO_MEMORY ); 00388 } 00389 RtlAppendUnicodeToString( &CsrPortName, ObjectDirectory ); 00390 RtlAppendUnicodeToString( &CsrPortName, L"\\" ); 00391 RtlAppendUnicodeToString( &CsrPortName, CSR_API_PORT_NAME ); 00392 00393 // 00394 // Set up the security quality of service parameters to use over the 00395 // port. Use the most efficient (least overhead) - which is dynamic 00396 // rather than static tracking. 00397 // 00398 00399 DynamicQos.ImpersonationLevel = SecurityImpersonation; 00400 DynamicQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING; 00401 DynamicQos.EffectiveOnly = TRUE; 00402 00403 00404 // 00405 // Create a section to contain the Port Memory. Port Memory is private 00406 // memory that is shared between the client and server processes. 00407 // This allows data that is too large to fit into an API request message 00408 // to be passed to the server. 00409 // 00410 00411 SectionSize.LowPart = CSR_PORT_MEMORY_SIZE; 00412 SectionSize.HighPart = 0; 00413 00414 Status = NtCreateSection( &PortSection, 00415 SECTION_ALL_ACCESS, 00416 NULL, 00417 &SectionSize, 00418 PAGE_READWRITE, 00419 SEC_RESERVE, 00420 NULL 00421 ); 00422 if (!NT_SUCCESS( Status )) { 00423 return( Status ); 00424 } 00425 00426 // 00427 // Connect to the server. This includes a description of the Port Memory 00428 // section so that the LPC connection logic can make the section visible 00429 // to both the client and server processes. Also pass information the 00430 // server needs in the connection information structure. 00431 // 00432 00433 ClientView.Length = sizeof( ClientView ); 00434 ClientView.SectionHandle = PortSection; 00435 ClientView.SectionOffset = 0; 00436 ClientView.ViewSize = SectionSize.LowPart; 00437 ClientView.ViewBase = 0; 00438 ClientView.ViewRemoteBase = 0; 00439 00440 ServerView.Length = sizeof( ServerView ); 00441 ServerView.ViewSize = 0; 00442 ServerView.ViewBase = 0; 00443 00444 ConnectionInformationLength = sizeof( ConnectionInformation ); 00445 ConnectionInformation.ExpectedVersion = CSR_VERSION; 00446 00447 SystemSid = NULL; 00448 Status = RtlAllocateAndInitializeSid( &NtAuthority, 00449 1, 00450 SECURITY_LOCAL_SYSTEM_RID, 00451 0, 0, 0, 0, 0, 0, 0, 00452 &SystemSid 00453 ); 00454 Status = NtSecureConnectPort( &CsrPortHandle, 00455 &CsrPortName, 00456 &DynamicQos, 00457 &ClientView, 00458 SystemSid, 00459 &ServerView, 00460 (PULONG)&MaxMessageLength, 00461 (PVOID)&ConnectionInformation, 00462 (PULONG)&ConnectionInformationLength 00463 ); 00464 RtlFreeSid( SystemSid ); 00465 NtClose( PortSection ); 00466 if (!NT_SUCCESS( Status )) { 00467 IF_DEBUG { 00468 DbgPrint( "CSRDLL: Unable to connect to %wZ Server - Status == %X\n", 00469 &CsrPortName, 00470 Status 00471 ); 00472 } 00473 00474 return( Status ); 00475 } 00476 xProtectHandle(CsrPortHandle); 00477 00478 NtCurrentPeb()->ReadOnlySharedMemoryBase = ConnectionInformation.SharedSectionBase; 00479 NtCurrentPeb()->ReadOnlySharedMemoryHeap = ConnectionInformation.SharedSectionHeap; 00480 NtCurrentPeb()->ReadOnlyStaticServerData = (PVOID *)ConnectionInformation.SharedStaticServerData; 00481 00482 #if DBG 00483 CsrDebug = ConnectionInformation.DebugFlags; 00484 #endif 00485 CsrObjectDirectory = ConnectionInformation.ObjectDirectory; 00486 00487 CsrPortMemoryRemoteDelta = (ULONG_PTR)ClientView.ViewRemoteBase - 00488 (ULONG_PTR)ClientView.ViewBase; 00489 00490 IF_CSR_DEBUG( LPC ) { 00491 DbgPrint( "CSRDLL: ClientView: Base=%p RemoteBase=%p Delta: %lX Size=%lX\n", 00492 ClientView.ViewBase, 00493 ClientView.ViewRemoteBase, 00494 CsrPortMemoryRemoteDelta, 00495 (ULONG)ClientView.ViewSize 00496 ); 00497 } 00498 00499 // 00500 // Create a sparse heap in the share memory section. Initially 00501 // commit just one page. 00502 // 00503 00504 CsrPortHeap = RtlCreateHeap( HEAP_CLASS_8, // Flags 00505 ClientView.ViewBase, // HeapBase 00506 ClientView.ViewSize, // ReserveSize 00507 CsrNtSysInfo.PageSize, // CommitSize 00508 0, // Reserved 00509 0 // GrowthThreshold 00510 ); 00511 if (CsrPortHeap == NULL) { 00512 NtClose( CsrPortHandle ); 00513 CsrPortHandle = NULL; 00514 00515 return( STATUS_NO_MEMORY ); 00516 } 00517 00518 CsrPortBaseTag = RtlCreateTagHeap( CsrPortHeap, 00519 0, 00520 L"CSRPORT!", 00521 L"!CSRPORT\0" 00522 L"CAPTURE\0" 00523 ); 00524 00525 return( STATUS_SUCCESS ); 00526 }


Variable Documentation

ULONG CsrDebugFlag
 

Definition at line 132 of file csrdll.h.

HANDLE CsrDllHandle
 

Definition at line 174 of file csrdll.h.

Referenced by CsrDllInitialize().

PVOID CsrHeap
 

Definition at line 140 of file csrdll.h.

Referenced by CsrClientConnectToServer(), CsrOneTimeInitialize(), and CsrpConnectToServer().

BOOLEAN CsrInitOnceDone
 

Definition at line 101 of file csrdll.h.

Referenced by CsrClientConnectToServer(), and CsrOneTimeInitialize().

PCSR_CALLBACK_INFO CsrLoadedClientDll[CSR_MAX_CLIENT_DLL]
 

Definition at line 193 of file csrdll.h.

Referenced by CsrClientConnectToServer().

SYSTEM_BASIC_INFORMATION CsrNtSysInfo
 

Definition at line 122 of file csrdll.h.

Referenced by CsrOneTimeInitialize(), CsrpConnectToServer(), and CsrProbeForWrite().

HANDLE CsrObjectDirectory
 

Definition at line 182 of file csrdll.h.

Referenced by CsrpConnectToServer().

ULONG CsrPortBaseTag
 

Definition at line 163 of file csrdll.h.

Referenced by CsrClientConnectToServer(), and CsrpConnectToServer().

HANDLE CsrPortHandle
 

Definition at line 150 of file csrdll.h.

Referenced by CsrClientCallServer(), CsrClientConnectToServer(), CsrNewThread(), CsrpConnectToServer(), and xxxSetInformationThread().

PVOID CsrPortHeap
 

Definition at line 160 of file csrdll.h.

Referenced by CsrAllocateCaptureBuffer(), CsrClientConnectToServer(), CsrFreeCaptureBuffer(), and CsrpConnectToServer().

ULONG_PTR CsrPortMemoryRemoteDelta
 

Definition at line 161 of file csrdll.h.

Referenced by CsrClientCallServer(), and CsrpConnectToServer().

UNICODE_STRING CsrPortName
 

Definition at line 149 of file csrdll.h.

Referenced by CsrpConnectToServer().

NTSTATUS(* CsrServerApiRoutine)(PCSR_API_MSG, PCSR_API_MSG)
 

Definition at line 114 of file csrdll.h.

Referenced by CsrClientCallServer(), and CsrClientConnectToServer().

BOOLEAN CsrServerProcess
 

Definition at line 107 of file csrdll.h.

Referenced by CsrClientCallServer(), and CsrClientConnectToServer().


Generated on Sat May 15 19:43:20 2004 for test by doxygen 1.3.7