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

lpcinit.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1989 Microsoft Corporation 00004 00005 Module Name: 00006 00007 lpcinit.c 00008 00009 Abstract: 00010 00011 Initialization module for the LPC subcomponent of NTOS 00012 00013 Author: 00014 00015 Steve Wood (stevewo) 15-May-1989 00016 00017 Revision History: 00018 00019 --*/ 00020 00021 #include "lpcp.h" 00022 00023 // 00024 // The following two object types are defined system wide to handle lpc ports 00025 // 00026 00027 POBJECT_TYPE LpcPortObjectType; 00028 POBJECT_TYPE LpcWaitablePortObjectType; 00029 00030 // 00031 // This is the default access mask mapping for lpc port objects 00032 // 00033 00034 GENERIC_MAPPING LpcpPortMapping = { 00035 READ_CONTROL | PORT_CONNECT, 00036 DELETE | PORT_CONNECT, 00037 0, 00038 PORT_ALL_ACCESS 00039 }; 00040 00041 // 00042 // This lock is used to protect practically everything in lpc 00043 // 00044 00045 LPC_MUTEX LpcpLock; 00046 00047 // 00048 // The following array of strings is used to debugger purposes and the 00049 // values correspond to the Port message types defined in ntlpcapi.h 00050 // 00051 00052 #if ENABLE_LPC_TRACING 00053 00054 char *LpcpMessageTypeName[] = { 00055 "UNUSED_MSG_TYPE", 00056 "LPC_REQUEST", 00057 "LPC_REPLY", 00058 "LPC_DATAGRAM", 00059 "LPC_LOST_REPLY", 00060 "LPC_PORT_CLOSED", 00061 "LPC_CLIENT_DIED", 00062 "LPC_EXCEPTION", 00063 "LPC_DEBUG_EVENT", 00064 "LPC_ERROR_EVENT", 00065 "LPC_CONNECTION_REQUEST" 00066 }; 00067 00068 #endif // ENABLE_LPC_TRACING 00069 00070 #ifdef ALLOC_PRAGMA 00071 #pragma alloc_text(INIT,LpcInitSystem) 00072 #endif 00073 00074 00075 BOOLEAN 00076 LpcInitSystem ( 00077 VOID 00078 ) 00079 00080 /*++ 00081 00082 Routine Description: 00083 00084 This function performs the system initialization for the LPC package. 00085 LPC stands for Local Inter-Process Communication. 00086 00087 Arguments: 00088 00089 None. 00090 00091 Return Value: 00092 00093 TRUE if successful and FALSE if an error occurred. 00094 00095 The following errors can occur: 00096 00097 - insufficient memory 00098 00099 --*/ 00100 00101 { 00102 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; 00103 UNICODE_STRING PortTypeName; 00104 ULONG ZoneElementSize; 00105 NTSTATUS Status; 00106 00107 // 00108 // Initialize our global lpc lock 00109 // 00110 00111 LpcpInitializeLpcpLock(); 00112 00113 // 00114 // Create the object type for the port object 00115 // 00116 00117 RtlInitUnicodeString( &PortTypeName, L"Port" ); 00118 00119 RtlZeroMemory( &ObjectTypeInitializer, sizeof( ObjectTypeInitializer )); 00120 00121 ObjectTypeInitializer.Length = sizeof( ObjectTypeInitializer ); 00122 ObjectTypeInitializer.GenericMapping = LpcpPortMapping; 00123 ObjectTypeInitializer.MaintainTypeList = TRUE; 00124 ObjectTypeInitializer.PoolType = PagedPool; 00125 ObjectTypeInitializer.DefaultPagedPoolCharge = sizeof( LPCP_PORT_OBJECT ); 00126 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof( LPCP_NONPAGED_PORT_QUEUE ); 00127 ObjectTypeInitializer.InvalidAttributes = OBJ_VALID_ATTRIBUTES ^ PORT_VALID_OBJECT_ATTRIBUTES; 00128 ObjectTypeInitializer.ValidAccessMask = PORT_ALL_ACCESS; 00129 ObjectTypeInitializer.CloseProcedure = LpcpClosePort; 00130 ObjectTypeInitializer.DeleteProcedure = LpcpDeletePort; 00131 ObjectTypeInitializer.UseDefaultObject = TRUE ; 00132 00133 ObCreateObjectType( &PortTypeName, 00134 &ObjectTypeInitializer, 00135 (PSECURITY_DESCRIPTOR)NULL, 00136 &LpcPortObjectType ); 00137 00138 // 00139 // Create the object type for the waitable port object 00140 // 00141 00142 RtlInitUnicodeString( &PortTypeName, L"WaitablePort" ); 00143 ObjectTypeInitializer.PoolType = NonPagedPool ; 00144 ObjectTypeInitializer.UseDefaultObject = FALSE ; 00145 00146 ObCreateObjectType( &PortTypeName, 00147 &ObjectTypeInitializer, 00148 (PSECURITY_DESCRIPTOR)NULL, 00149 &LpcWaitablePortObjectType ); 00150 00151 // 00152 // Initialize the lpc message and callback id counters 00153 // 00154 00155 LpcpNextMessageId = 1; 00156 LpcpNextCallbackId = 1; 00157 00158 // 00159 // Initialize the lpc port zone. Each element can contain a max 00160 // message, plus an LPCP message structure, plus an LPCP connection 00161 // message 00162 // 00163 00164 ZoneElementSize = PORT_MAXIMUM_MESSAGE_LENGTH + 00165 sizeof( LPCP_MESSAGE ) + 00166 sizeof( LPCP_CONNECTION_MESSAGE ); 00167 00168 // 00169 // Round up the size to the next 16 byte alignment 00170 // 00171 00172 ZoneElementSize = (ZoneElementSize + LPCP_ZONE_ALIGNMENT - 1) & 00173 LPCP_ZONE_ALIGNMENT_MASK; 00174 00175 // 00176 // Initialize the zone 00177 // 00178 00179 Status = LpcpInitializePortZone( ZoneElementSize, 00180 PAGE_SIZE, 00181 LPCP_ZONE_MAX_POOL_USAGE ); 00182 00183 if (!NT_SUCCESS( Status )) { 00184 00185 return( FALSE ); 00186 } 00187 00188 return( TRUE ); 00189 } 00190 00191 00192 char * 00193 LpcpGetCreatorName ( 00194 PLPCP_PORT_OBJECT PortObject 00195 ) 00196 00197 /*++ 00198 00199 Routine Description: 00200 00201 This routine returns the name of the process that created the specified 00202 port object 00203 00204 Arguments: 00205 00206 PortObject - Supplies the port object being queried 00207 00208 Return Value: 00209 00210 char * - The image name of the process that created the port process 00211 00212 --*/ 00213 00214 { 00215 NTSTATUS Status; 00216 PEPROCESS Process; 00217 00218 // 00219 // First find the process that created the port object 00220 // 00221 00222 Status = PsLookupProcessByProcessId( PortObject->Creator.UniqueProcess, &Process ); 00223 00224 // 00225 // If we were able to get the process then return the name of the process 00226 // to our caller 00227 // 00228 00229 if (NT_SUCCESS( Status )) { 00230 00231 return Process->ImageFileName; 00232 00233 } else { 00234 00235 // 00236 // Otherwise tell our caller we don't know the name 00237 // 00238 00239 return "Unknown"; 00240 } 00241 } 00242 00243 #ifdef LPCP_TRACE_SERVER_THREADS 00244 00245 VOID LpcpPortExtraDataCreate ( PLPCP_PORT_OBJECT PortObject ) 00246 /*++ 00247 00248 Routine Description: 00249 00250 Allocate a LPCP_PORT_EXTRA_DATA structure and initializate it. 00251 00252 Arguments: 00253 00254 PortObject - The port object that will contains this structure 00255 00256 Return Value: 00257 00258 None 00259 00260 00261 --*/ 00262 { 00263 PLPCP_PORT_EXTRA_DATA PortData; 00264 00265 PortData = ExAllocatePoolWithTag(NonPagedPool, sizeof(LPCP_PORT_EXTRA_DATA), 'DEPL'); 00266 00267 PortData->ThreadCount = 0; 00268 00269 PortData->PortObject = PortObject; 00270 00271 PortObject->Reserved = (ULONG)PortData; 00272 00273 } 00274 00275 VOID LpcpPortExtraDataDestroy (PLPCP_PORT_OBJECT PortObject) 00276 /*++ 00277 00278 Routine Description: 00279 00280 Free the memory alocated for the extra data structure 00281 00282 Arguments: 00283 00284 PortObject - The port object that will contains this structure 00285 00286 Return Value: 00287 00288 None 00289 00290 --*/ 00291 { 00292 PLPCP_PORT_EXTRA_DATA PortData; 00293 00294 PortData = (PLPCP_PORT_EXTRA_DATA) PortObject->Reserved; 00295 00296 if ((PortData != NULL) && 00297 (PortData->PortObject == PortObject)) { 00298 00299 ExFreePoolWithTag( PortData, 'DEPL'); 00300 00301 PortObject->Reserved = 0; 00302 } 00303 } 00304 00305 VOID LpcpPortExtraDataPush (PLPCP_PORT_EXTRA_DATA PortData, PVOID Thread) 00306 /*++ 00307 00308 Routine Description: 00309 00310 Push a new thread on the array. The opperation occurs only if the thread is first time 00311 using this port. 00312 00313 Arguments: 00314 00315 PortData - the pointer to the Extra data port structure 00316 00317 Thread - The thread that should be added to the thread array 00318 00319 00320 Return Value: 00321 00322 None 00323 00324 00325 --*/ 00326 { 00327 ULONG Position; 00328 ULONG EndSearch; 00329 00330 EndSearch = PortData->ThreadCount; 00331 00332 if ( EndSearch >= LPCP_SERVER_THREAD_ARRAY_SIZE) { 00333 00334 EndSearch = LPCP_SERVER_THREAD_ARRAY_SIZE - 1; 00335 } 00336 00337 for (Position = 0; Position < EndSearch ; Position++) { 00338 00339 if ( PortData->Threads[Position] == Thread ) { 00340 00341 return; 00342 } 00343 } 00344 00345 PortData->Threads[PortData->ThreadCount % LPCP_SERVER_THREAD_ARRAY_SIZE] = Thread; 00346 00347 PortData->ThreadCount += 1; 00348 00349 // DbgPrint( "Port %lx : Threads: %ld (%lx)\n", PortData->PortObject, PortData->ThreadCount, Thread); 00350 00351 } 00352 00353 00354 VOID LpcpSaveThread (PLPCP_PORT_OBJECT PortObject) 00355 /*++ 00356 00357 Routine Description: 00358 00359 This function is used to store the current thread to the PortObject. If the port object does not 00360 have the extra-data structure allocated, this function will call LpcpPortExtraDataCreate to do this. 00361 00362 Arguments: 00363 00364 PortObject - The port object that will contains this structure 00365 00366 Return Value: 00367 00368 None 00369 00370 --*/ 00371 { 00372 00373 if (PortObject->Reserved == 0) { 00374 00375 LpcpPortExtraDataCreate( PortObject ); 00376 } 00377 00378 if ( ((PortObject->Flags & PORT_TYPE) == SERVER_COMMUNICATION_PORT) && 00379 (PortObject->Reserved != 0) ) { 00380 00381 LpcpPortExtraDataPush( (PLPCP_PORT_EXTRA_DATA)PortObject->Reserved, PsGetCurrentThread()); 00382 } 00383 } 00384 00385 #endif // LPCP_TRACE_SERVER_THREADS 00386

Generated on Sat May 15 19:40:39 2004 for test by doxygen 1.3.7