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.

361 lines
11 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. regiodls.cxx
  5. Abstract:
  6. This module contains the definitions of the member functions
  7. of IO_DESCRIPTOR_LIST class.
  8. Author:
  9. Jaime Sasson (jaimes) 02-Dec-1993
  10. Environment:
  11. ULIB, User Mode
  12. --*/
  13. #include "regiodls.hxx"
  14. #include "regiodsc.hxx"
  15. #include "iterator.hxx"
  16. DEFINE_CONSTRUCTOR ( IO_DESCRIPTOR_LIST, OBJECT );
  17. IO_DESCRIPTOR_LIST::~IO_DESCRIPTOR_LIST (
  18. )
  19. /*++
  20. Routine Description:
  21. Destroy an IO_DESCRIPTOR_LIST.
  22. Arguments:
  23. None.
  24. Return Value:
  25. None.
  26. --*/
  27. {
  28. Destroy();
  29. }
  30. VOID
  31. IO_DESCRIPTOR_LIST::Construct (
  32. )
  33. /*++
  34. Routine Description:
  35. Construct an IO_DESCRIPTOR_LIST object.
  36. Arguments:
  37. None.
  38. Return Value:
  39. None.
  40. --*/
  41. {
  42. _Version = 0;
  43. _Revision = 0;
  44. _DescriptorsList = NULL;
  45. }
  46. VOID
  47. IO_DESCRIPTOR_LIST::Destroy (
  48. )
  49. /*++
  50. Routine Description:
  51. Worker method for object destruction.
  52. Arguments:
  53. None.
  54. Return Value:
  55. None.
  56. --*/
  57. {
  58. _Version = 0;
  59. _Revision = 0;
  60. if( _DescriptorsList != NULL ) {
  61. _DescriptorsList->DeleteAllMembers();
  62. DELETE( _DescriptorsList );
  63. }
  64. _DescriptorsList = NULL;
  65. }
  66. BOOLEAN
  67. IO_DESCRIPTOR_LIST::Initialize(
  68. IN PCBYTE Data,
  69. IN ULONG Size,
  70. OUT PULONG DescriptorSize
  71. )
  72. /*++
  73. Routine Description:
  74. Initialize an object of type IO_DESCRIPTOR_LIST.
  75. Arguments:
  76. Data - Pointer to a buffer that contains an IO_RESOURCE_LIST.
  77. Size - Buffer size.
  78. Return Value:
  79. BOOLEAN - Returns TRUE if the initialization succeeds.
  80. --*/
  81. {
  82. PIO_RESOURCE_LIST IoResourceList;
  83. ULONG Count;
  84. ULONG i;
  85. ULONG j;
  86. PARRAY TmpList;
  87. PIO_PORT_DESCRIPTOR PortDescriptor;
  88. PIO_INTERRUPT_DESCRIPTOR InterruptDescriptor;
  89. PIO_MEMORY_DESCRIPTOR MemoryDescriptor;
  90. PIO_DMA_DESCRIPTOR DmaDescriptor;
  91. if( Data == NULL ) {
  92. return( FALSE );
  93. }
  94. Count = 1;
  95. IoResourceList = ( PIO_RESOURCE_LIST )Data;
  96. TmpList = ( PARRAY )NEW( ARRAY );
  97. DebugPtrAssert( TmpList );
  98. if( ( TmpList == NULL ) ||
  99. ( !TmpList->Initialize() ) ) {
  100. DebugPrintTrace(("REGEDIT: Out of memory" ));
  101. DELETE( TmpList );
  102. return( FALSE );
  103. }
  104. _Version = IoResourceList->Version;
  105. _Revision = IoResourceList->Revision;
  106. //
  107. // For each CM_FULL_RESOURCE DESCRIPTOR in the current value...
  108. //
  109. for( i = 0; i < Count; i++ )
  110. {
  111. PIO_RESOURCE_DESCRIPTOR IoResourceDescriptor = NULL;
  112. //
  113. // For each IO_RESOURCE_DESCRIPTOR in the list...
  114. //
  115. for( j = 0; j < IoResourceList->Count; j++ )
  116. {
  117. //
  118. // Get a pointer to the current IO_RESOURCE_DESCRIPTOR
  119. // in the current IO_RESOURCE_LIST.
  120. //
  121. IoResourceDescriptor = &( IoResourceList->Descriptors[ j ]);
  122. //
  123. // Ignore invalid data
  124. //
  125. if( ( ULONG_PTR )IoResourceDescriptor >
  126. ( ULONG_PTR )( Data + Size - sizeof( IO_RESOURCE_DESCRIPTOR ) ) ) {
  127. DebugPrintTrace(( "REGEDIT: Invalid IO_RESOURCE_DESCRIPTOR, j = %d \n", j ));
  128. if( DescriptorSize != NULL ) {
  129. *DescriptorSize = Size;
  130. }
  131. _DescriptorsList = TmpList;
  132. return( TRUE );
  133. }
  134. switch( IoResourceDescriptor->Type ) {
  135. case CmResourceTypePort:
  136. PortDescriptor = ( PIO_PORT_DESCRIPTOR )NEW( IO_PORT_DESCRIPTOR );
  137. if( ( PortDescriptor == NULL ) ||
  138. ( !PortDescriptor->Initialize( IoResourceDescriptor->u.Port.Length,
  139. IoResourceDescriptor->u.Port.Alignment,
  140. &IoResourceDescriptor->u.Port.MinimumAddress,
  141. &IoResourceDescriptor->u.Port.MaximumAddress,
  142. IoResourceDescriptor->Option,
  143. IoResourceDescriptor->ShareDisposition,
  144. IoResourceDescriptor->Flags ) )
  145. ) {
  146. DebugPrintTrace(( "REGEDIT: Unable to create IO_PORT_DESCRIPTOR" ));
  147. DELETE( PortDescriptor );
  148. TmpList->DeleteAllMembers();
  149. DELETE( TmpList );
  150. return( FALSE );
  151. }
  152. TmpList->Put( PortDescriptor );
  153. break;
  154. case CmResourceTypeInterrupt:
  155. InterruptDescriptor = ( PIO_INTERRUPT_DESCRIPTOR )NEW( IO_INTERRUPT_DESCRIPTOR );
  156. if( ( InterruptDescriptor == NULL ) ||
  157. ( !InterruptDescriptor->Initialize( IoResourceDescriptor->u.Interrupt.MinimumVector,
  158. IoResourceDescriptor->u.Interrupt.MaximumVector,
  159. IoResourceDescriptor->Option,
  160. IoResourceDescriptor->ShareDisposition,
  161. IoResourceDescriptor->Flags ) )
  162. ) {
  163. DebugPrintTrace(( "REGEDIT: Unable to create IO_INTERRUPT_DESCRIPTOR" ));
  164. DELETE( InterruptDescriptor );
  165. TmpList->DeleteAllMembers();
  166. DELETE( TmpList );
  167. return( FALSE );
  168. }
  169. TmpList->Put( InterruptDescriptor );
  170. break;
  171. case CmResourceTypeMemory:
  172. MemoryDescriptor = ( PIO_MEMORY_DESCRIPTOR )NEW( IO_MEMORY_DESCRIPTOR );
  173. if( ( MemoryDescriptor == NULL ) ||
  174. ( !MemoryDescriptor->Initialize( IoResourceDescriptor->u.Memory.Length,
  175. IoResourceDescriptor->u.Memory.Alignment,
  176. &IoResourceDescriptor->u.Memory.MinimumAddress,
  177. &IoResourceDescriptor->u.Memory.MaximumAddress,
  178. IoResourceDescriptor->Option,
  179. IoResourceDescriptor->ShareDisposition,
  180. IoResourceDescriptor->Flags ) )
  181. ) {
  182. DebugPrintTrace(( "REGEDIT: Unable to create IO_MEMORY_DESCRIPTOR" ));
  183. DELETE( MemoryDescriptor );
  184. TmpList->DeleteAllMembers();
  185. DELETE( TmpList );
  186. return( FALSE );
  187. }
  188. TmpList->Put( MemoryDescriptor );
  189. break;
  190. case CmResourceTypeDma:
  191. DmaDescriptor = ( PIO_DMA_DESCRIPTOR )NEW( IO_DMA_DESCRIPTOR );
  192. if( ( DmaDescriptor == NULL ) ||
  193. ( !DmaDescriptor->Initialize( IoResourceDescriptor->u.Dma.MinimumChannel,
  194. IoResourceDescriptor->u.Dma.MaximumChannel,
  195. IoResourceDescriptor->Option,
  196. IoResourceDescriptor->ShareDisposition,
  197. IoResourceDescriptor->Flags ) )
  198. ) {
  199. DebugPrintTrace(( "REGEDIT: Unable to create IO_DMA_DESCRIPTOR" ));
  200. DELETE( DmaDescriptor );
  201. TmpList->DeleteAllMembers();
  202. DELETE( TmpList );
  203. return( FALSE );
  204. }
  205. TmpList->Put( DmaDescriptor );
  206. break;
  207. default:
  208. DebugPrintTrace(( "REGEDIT: Unknown IoResourceDescriptor->Type == %#x \n",
  209. IoResourceDescriptor->Type ));
  210. continue;
  211. }
  212. }
  213. _DescriptorsList = TmpList;
  214. //
  215. // Get the next IO_RESOURCE_LIST from the list.
  216. //
  217. if (IoResourceDescriptor)
  218. {
  219. IoResourceList = ( PIO_RESOURCE_LIST )( IoResourceDescriptor + 1 );
  220. }
  221. }
  222. if( DescriptorSize != NULL ) {
  223. *DescriptorSize = ( ULONG )( ( ULONG_PTR )IoResourceList - ( ULONG_PTR )Data );
  224. #if DBG
  225. if( *DescriptorSize > Size ) {
  226. DebugPrintTrace(( "REGEDIT: Invalid sizes, *DescriptorSize = %d, Size = %d \n", *DescriptorSize, Size ));
  227. }
  228. #endif
  229. }
  230. return( TRUE );
  231. }
  232. #if DBG
  233. VOID
  234. IO_DESCRIPTOR_LIST::DbgDumpObject(
  235. )
  236. /*++
  237. Routine Description:
  238. Print an IO_DESCRIPTOR_LIST object.
  239. Arguments:
  240. None.
  241. Return Value:
  242. None.
  243. --*/
  244. {
  245. PITERATOR Iterator;
  246. PIO_DESCRIPTOR Descriptor;
  247. DebugPrintTrace(( "\tVersion = %#x \n", _Version ));
  248. DebugPrintTrace(( "\tRevision = %#x \n", _Revision ));
  249. if( _DescriptorsList != NULL ) {
  250. Iterator = _DescriptorsList->QueryIterator();
  251. while( Descriptor = ( PIO_DESCRIPTOR ) Iterator->GetNext() ) {
  252. if( Descriptor->IsDescriptorTypePort() ) {
  253. ( ( PIO_PORT_DESCRIPTOR )Descriptor )->DbgDumpObject();
  254. } else if( Descriptor->IsDescriptorTypeInterrupt() ) {
  255. ( ( PIO_INTERRUPT_DESCRIPTOR )Descriptor )->DbgDumpObject();
  256. } else if( Descriptor->IsDescriptorTypeMemory() ) {
  257. ( ( PIO_MEMORY_DESCRIPTOR )Descriptor )->DbgDumpObject();
  258. } else if( Descriptor->IsDescriptorTypeDma() ) {
  259. ( ( PIO_DMA_DESCRIPTOR )Descriptor )->DbgDumpObject();
  260. } else {
  261. DebugPrintTrace(( "\tERROR: Unknown Descriptor \n\n" ));
  262. }
  263. }
  264. DELETE( Iterator );
  265. }
  266. }
  267. #endif