Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. lpcinit.c
  5. Abstract:
  6. Initialization module for the LPC subcomponent of NTOS
  7. Author:
  8. Steve Wood (stevewo) 15-May-1989
  9. Revision History:
  10. --*/
  11. #include "lpcp.h"
  12. //
  13. // The following two object types are defined system wide to handle lpc ports
  14. //
  15. POBJECT_TYPE LpcPortObjectType;
  16. POBJECT_TYPE LpcWaitablePortObjectType;
  17. //
  18. // This is the default access mask mapping for lpc port objects
  19. //
  20. #ifdef ALLOC_DATA_PRAGMA
  21. #pragma const_seg("INITCONST")
  22. #pragma data_seg("PAGEDATA")
  23. #endif // ALLOC_DATA_PRAGMA
  24. const GENERIC_MAPPING LpcpPortMapping = {
  25. READ_CONTROL | PORT_CONNECT,
  26. DELETE | PORT_CONNECT,
  27. 0,
  28. PORT_ALL_ACCESS
  29. };
  30. ULONG LpcpNextMessageId = 1;
  31. ULONG LpcpNextCallbackId = 1;
  32. #ifdef ALLOC_DATA_PRAGMA
  33. #pragma const_seg()
  34. #pragma data_seg()
  35. #endif // ALLOC_DATA_PRAGMA
  36. //
  37. // This lock is used to protect practically everything in lpc
  38. //
  39. LPC_MUTEX LpcpLock;
  40. //
  41. // The following array of strings is used to debugger purposes and the
  42. // values correspond to the Port message types defined in ntlpcapi.h
  43. //
  44. #if ENABLE_LPC_TRACING
  45. char *LpcpMessageTypeName[] = {
  46. "UNUSED_MSG_TYPE",
  47. "LPC_REQUEST",
  48. "LPC_REPLY",
  49. "LPC_DATAGRAM",
  50. "LPC_LOST_REPLY",
  51. "LPC_PORT_CLOSED",
  52. "LPC_CLIENT_DIED",
  53. "LPC_EXCEPTION",
  54. "LPC_DEBUG_EVENT",
  55. "LPC_ERROR_EVENT",
  56. "LPC_CONNECTION_REQUEST"
  57. };
  58. #endif // ENABLE_LPC_TRACING
  59. #ifdef ALLOC_PRAGMA
  60. #pragma alloc_text(INIT,LpcInitSystem)
  61. #if ENABLE_LPC_TRACING
  62. #pragma alloc_text(PAGE,LpcpGetCreatorName)
  63. #endif // ENABLE_LPC_TRACING
  64. #endif // ALLOC_PRAGMA
  65. BOOLEAN
  66. LpcInitSystem (
  67. VOID
  68. )
  69. /*++
  70. Routine Description:
  71. This function performs the system initialization for the LPC package.
  72. LPC stands for Local Inter-Process Communication.
  73. Arguments:
  74. None.
  75. Return Value:
  76. TRUE if successful and FALSE if an error occurred.
  77. The following errors can occur:
  78. - insufficient memory
  79. --*/
  80. {
  81. OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
  82. UNICODE_STRING PortTypeName;
  83. ULONG ZoneElementSize;
  84. //
  85. // Initialize our global lpc lock
  86. //
  87. LpcpInitializeLpcpLock();
  88. //
  89. // Create the object type for the port object
  90. //
  91. RtlInitUnicodeString( &PortTypeName, L"Port" );
  92. RtlZeroMemory( &ObjectTypeInitializer, sizeof( ObjectTypeInitializer ));
  93. ObjectTypeInitializer.Length = sizeof( ObjectTypeInitializer );
  94. ObjectTypeInitializer.GenericMapping = LpcpPortMapping;
  95. ObjectTypeInitializer.MaintainTypeList = FALSE;
  96. ObjectTypeInitializer.PoolType = PagedPool;
  97. ObjectTypeInitializer.DefaultPagedPoolCharge = FIELD_OFFSET( LPCP_PORT_OBJECT, WaitEvent );
  98. ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof( LPCP_NONPAGED_PORT_QUEUE );
  99. ObjectTypeInitializer.InvalidAttributes = OBJ_VALID_ATTRIBUTES ^ PORT_VALID_OBJECT_ATTRIBUTES;
  100. ObjectTypeInitializer.ValidAccessMask = PORT_ALL_ACCESS;
  101. ObjectTypeInitializer.CloseProcedure = LpcpClosePort;
  102. ObjectTypeInitializer.DeleteProcedure = LpcpDeletePort;
  103. ObjectTypeInitializer.UseDefaultObject = TRUE ;
  104. ObCreateObjectType( &PortTypeName,
  105. &ObjectTypeInitializer,
  106. (PSECURITY_DESCRIPTOR)NULL,
  107. &LpcPortObjectType );
  108. //
  109. // Create the object type for the waitable port object
  110. //
  111. RtlInitUnicodeString( &PortTypeName, L"WaitablePort" );
  112. ObjectTypeInitializer.PoolType = NonPagedPool;
  113. ObjectTypeInitializer.DefaultNonPagedPoolCharge += sizeof( LPCP_PORT_OBJECT );
  114. ObjectTypeInitializer.DefaultPagedPoolCharge = 0;
  115. ObjectTypeInitializer.UseDefaultObject = FALSE;
  116. ObCreateObjectType( &PortTypeName,
  117. &ObjectTypeInitializer,
  118. (PSECURITY_DESCRIPTOR)NULL,
  119. &LpcWaitablePortObjectType );
  120. //
  121. // Initialize the lpc port zone. Each element can contain a max
  122. // message, plus an LPCP message structure, plus an LPCP connection
  123. // message
  124. //
  125. ZoneElementSize = PORT_MAXIMUM_MESSAGE_LENGTH +
  126. sizeof( LPCP_MESSAGE ) +
  127. sizeof( LPCP_CONNECTION_MESSAGE );
  128. //
  129. // Round up the size to the next 16 byte alignment
  130. //
  131. ZoneElementSize = (ZoneElementSize + LPCP_ZONE_ALIGNMENT - 1) &
  132. LPCP_ZONE_ALIGNMENT_MASK;
  133. //
  134. // Initialize the zone
  135. //
  136. LpcpInitializePortZone( ZoneElementSize );
  137. LpcpInitilizeLogging();
  138. return( TRUE );
  139. }
  140. #if ENABLE_LPC_TRACING
  141. char *
  142. LpcpGetCreatorName (
  143. PLPCP_PORT_OBJECT PortObject
  144. )
  145. /*++
  146. Routine Description:
  147. This routine returns the name of the process that created the specified
  148. port object
  149. Arguments:
  150. PortObject - Supplies the port object being queried
  151. Return Value:
  152. char * - The image name of the process that created the port process
  153. --*/
  154. {
  155. NTSTATUS Status;
  156. PEPROCESS Process;
  157. //
  158. // First find the process that created the port object
  159. //
  160. Status = PsLookupProcessByProcessId( PortObject->Creator.UniqueProcess, &Process );
  161. //
  162. // If we were able to get the process then return the name of the process
  163. // to our caller
  164. //
  165. if (NT_SUCCESS( Status )) {
  166. return (char *)Process->ImageFileName;
  167. } else {
  168. //
  169. // Otherwise tell our caller we don't know the name
  170. //
  171. return "Unknown";
  172. }
  173. }
  174. #endif // ENABLE_LPC_TRACING