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.

317 lines
9.6 KiB

  1. #include "wdmsys.h"
  2. #pragma PAGEDCODE
  3. CSystem* CWDMSystem::create(VOID)
  4. { return new (NonPagedPool) CWDMSystem; }
  5. #pragma PAGEDCODE
  6. NTSTATUS CWDMSystem::createDevice(PDRIVER_OBJECT DriverObject,
  7. ULONG DeviceExtensionSize,
  8. PUNICODE_STRING DeviceName OPTIONAL,
  9. DEVICE_TYPE DeviceType,
  10. ULONG DeviceCharacteristics,
  11. BOOLEAN Reserved,
  12. PDEVICE_OBJECT *DeviceObject)
  13. {
  14. return ::IoCreateDevice(DriverObject,DeviceExtensionSize,DeviceName,
  15. DeviceType,DeviceCharacteristics,Reserved,DeviceObject);
  16. }
  17. #pragma PAGEDCODE
  18. VOID CWDMSystem::deleteDevice(PDEVICE_OBJECT DeviceObject)
  19. {
  20. ::IoDeleteDevice(DeviceObject);
  21. }
  22. #pragma PAGEDCODE
  23. PDEVICE_OBJECT CWDMSystem::attachDevice(PDEVICE_OBJECT SourceDevice,PDEVICE_OBJECT TargetDevice)
  24. {
  25. return ::IoAttachDeviceToDeviceStack(SourceDevice,TargetDevice);
  26. }
  27. #pragma PAGEDCODE
  28. VOID CWDMSystem::detachDevice(PDEVICE_OBJECT TargetDevice)
  29. {
  30. ::IoDetachDevice(TargetDevice);
  31. }
  32. #pragma PAGEDCODE
  33. NTSTATUS CWDMSystem::callDriver(PDEVICE_OBJECT DeviceObject,PIRP Irp)
  34. {
  35. return IoCallDriver(DeviceObject,Irp);
  36. }
  37. #pragma PAGEDCODE
  38. NTSTATUS CWDMSystem::registerDeviceInterface(PDEVICE_OBJECT PhysicalDeviceObject,
  39. CONST GUID *InterfaceClassGuid,
  40. PUNICODE_STRING ReferenceString,
  41. PUNICODE_STRING SymbolicLinkName)
  42. {
  43. return ::IoRegisterDeviceInterface(PhysicalDeviceObject,
  44. InterfaceClassGuid,
  45. ReferenceString,SymbolicLinkName);
  46. }
  47. #pragma PAGEDCODE
  48. NTSTATUS CWDMSystem::setDeviceInterfaceState(PUNICODE_STRING SymbolicLinkName,
  49. BOOLEAN Enable )
  50. {
  51. return ::IoSetDeviceInterfaceState(SymbolicLinkName,Enable);
  52. }
  53. #pragma PAGEDCODE
  54. NTSTATUS CWDMSystem::createSystemThread(
  55. OUT PHANDLE ThreadHandle,
  56. IN ULONG DesiredAccess,
  57. IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
  58. IN HANDLE ProcessHandle OPTIONAL,
  59. OUT PCLIENT_ID ClientId OPTIONAL,
  60. IN PKSTART_ROUTINE StartRoutine,
  61. IN PVOID StartContext)
  62. {
  63. return PsCreateSystemThread(ThreadHandle,DesiredAccess,ObjectAttributes,
  64. ProcessHandle,ClientId, StartRoutine,StartContext);
  65. }
  66. #pragma PAGEDCODE
  67. NTSTATUS CWDMSystem::terminateSystemThread(IN NTSTATUS ExitStatus)
  68. {
  69. return PsTerminateSystemThread(ExitStatus);
  70. }
  71. #pragma PAGEDCODE
  72. NTSTATUS CWDMSystem::referenceObjectByHandle(
  73. IN HANDLE Handle,
  74. IN ACCESS_MASK DesiredAccess,
  75. IN POBJECT_TYPE ObjectType OPTIONAL,
  76. IN KPROCESSOR_MODE AccessMode,
  77. OUT PVOID *Object,
  78. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL
  79. )
  80. {
  81. return ObReferenceObjectByHandle(Handle,DesiredAccess,ObjectType,AccessMode,Object,HandleInformation);
  82. }
  83. #pragma PAGEDCODE
  84. VOID CWDMSystem::referenceObject(IN PVOID Object)
  85. {
  86. ObReferenceObject(Object);
  87. }
  88. #pragma PAGEDCODE
  89. VOID CWDMSystem::dereferenceObject(IN PVOID Object)
  90. {
  91. ObfDereferenceObject(Object);
  92. }
  93. #pragma PAGEDCODE
  94. PDEVICE_OBJECT CWDMSystem::getAttachedDeviceReference(IN PDEVICE_OBJECT DeviceObject)
  95. {
  96. return ::IoGetAttachedDeviceReference(DeviceObject);
  97. }
  98. NTKERNELAPI
  99. PDEVICE_OBJECT
  100. IoGetAttachedDeviceReference(
  101. IN PDEVICE_OBJECT DeviceObject
  102. );
  103. #pragma PAGEDCODE
  104. NTSTATUS CWDMSystem::ZwClose(IN HANDLE Handle)
  105. {
  106. return ::ZwClose(Handle);
  107. }
  108. #pragma PAGEDCODE
  109. NTSTATUS CWDMSystem::createSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,IN PUNICODE_STRING DeviceName)
  110. {
  111. return ::IoCreateSymbolicLink(SymbolicLinkName,DeviceName);
  112. }
  113. #pragma PAGEDCODE
  114. NTSTATUS CWDMSystem::deleteSymbolicLink(IN PUNICODE_STRING SymbolicLinkName)
  115. {
  116. return ::IoDeleteSymbolicLink(SymbolicLinkName);
  117. }
  118. #pragma PAGEDCODE
  119. VOID CWDMSystem::invalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject,IN DEVICE_RELATION_TYPE Type)
  120. {
  121. IoInvalidateDeviceRelations(DeviceObject,Type);
  122. }
  123. #pragma PAGEDCODE
  124. NTSTATUS CWDMSystem::getDeviceObjectPointer(IN PUNICODE_STRING ObjectName,
  125. IN ACCESS_MASK DesiredAccess,
  126. OUT PFILE_OBJECT *FileObject,
  127. OUT PDEVICE_OBJECT *DeviceObject)
  128. {
  129. return IoGetDeviceObjectPointer(ObjectName,DesiredAccess,FileObject,DeviceObject);
  130. }
  131. #pragma PAGEDCODE
  132. VOID CWDMSystem::raiseIrql(IN KIRQL NewIrql,OUT KIRQL* oldIrql)
  133. {
  134. KeRaiseIrql(NewIrql,oldIrql);
  135. };
  136. #pragma PAGEDCODE
  137. VOID CWDMSystem::lowerIrql (IN KIRQL NewIrql)
  138. {
  139. KeLowerIrql(NewIrql);
  140. };
  141. #pragma PAGEDCODE
  142. KIRQL CWDMSystem::getCurrentIrql ()
  143. {
  144. return KeGetCurrentIrql();
  145. };
  146. #pragma PAGEDCODE
  147. VOID CWDMSystem::initializeDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
  148. {
  149. KeInitializeDeviceQueue (DeviceQueue);
  150. };
  151. #pragma PAGEDCODE
  152. BOOLEAN CWDMSystem::insertDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)
  153. {
  154. return KeInsertDeviceQueue (DeviceQueue,DeviceQueueEntry);
  155. }
  156. #pragma PAGEDCODE
  157. BOOLEAN CWDMSystem::insertByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,IN ULONG SortKey)
  158. {
  159. return KeInsertByKeyDeviceQueue(DeviceQueue,DeviceQueueEntry,SortKey);
  160. }
  161. #pragma PAGEDCODE
  162. PKDEVICE_QUEUE_ENTRY CWDMSystem::removeDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
  163. {
  164. return KeRemoveDeviceQueue (DeviceQueue);
  165. }
  166. #pragma PAGEDCODE
  167. PKDEVICE_QUEUE_ENTRY CWDMSystem::removeByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,IN ULONG SortKey)
  168. {
  169. return KeRemoveByKeyDeviceQueue (DeviceQueue,SortKey);
  170. }
  171. #pragma PAGEDCODE
  172. BOOLEAN CWDMSystem::removeEntryDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue,IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)
  173. {
  174. return KeRemoveEntryDeviceQueue(DeviceQueue,DeviceQueueEntry);
  175. }
  176. #pragma PAGEDCODE
  177. NTSTATUS CWDMSystem::openDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject,
  178. IN ULONG DevInstKeyType,
  179. IN ACCESS_MASK DesiredAccess,
  180. OUT PHANDLE DevInstRegKey)
  181. {
  182. return IoOpenDeviceRegistryKey(DeviceObject,DevInstKeyType,DesiredAccess,DevInstRegKey);
  183. }
  184. #pragma PAGEDCODE
  185. NTSTATUS CWDMSystem::ZwQueryValueKey(IN HANDLE KeyHandle,
  186. IN PUNICODE_STRING ValueName,
  187. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  188. OUT PVOID KeyValueInformation,
  189. IN ULONG Length,
  190. OUT PULONG ResultLength)
  191. {
  192. return ZwQueryValueKey(KeyHandle,ValueName,KeyValueInformationClass,KeyValueInformation,
  193. Length,ResultLength);
  194. }
  195. #pragma PAGEDCODE
  196. NTSTATUS CWDMSystem::getDeviceProperty(
  197. IN PDEVICE_OBJECT DeviceObject,
  198. IN DEVICE_REGISTRY_PROPERTY Property,
  199. IN ULONG BufferLength,
  200. OUT PVOID PropertyBuffer,
  201. OUT PULONG ResultLength )
  202. {
  203. return IoGetDeviceProperty(DeviceObject,Property,BufferLength,PropertyBuffer,ResultLength);
  204. /*
  205. // Define PnP Device Property for IoGetDeviceProperty
  206. #define DEVICE_PROPERTY_TABSIZE DevicePropertyEnumeratorName+1
  207. WCHAR* DeviceProperty[DEVICE_PROPERTY_TABSIZE];
  208. DeviceProperty[DevicePropertyDeviceDescription] = L"DeviceDesc";
  209. DeviceProperty[DevicePropertyHardwareID] = L"HardwareID";
  210. DeviceProperty[DevicePropertyCompatibleIDs] = L"CompatibleIDs";
  211. DeviceProperty[DevicePropertyBootConfiguration] = L"BootConfiguration";
  212. DeviceProperty[DevicePropertyBootConfigurationTranslated] = L"BootConfigurationTranslated";
  213. DeviceProperty[DevicePropertyClassName] = L"ClassName";
  214. DeviceProperty[DevicePropertyClassGuid] = L"ClassGuid";
  215. DeviceProperty[DevicePropertyDriverKeyName] = L"DriverKeyName";
  216. DeviceProperty[DevicePropertyManufacturer] = L"Manufacturer";
  217. DeviceProperty[DevicePropertyFriendlyName] = L"FriendlyName";
  218. DeviceProperty[DevicePropertyLocationInformation] = L"LocationInformation";
  219. DeviceProperty[DevicePropertyPhysicalDeviceObjectName] = L"PhysicalDeviceObjectName";
  220. DeviceProperty[DevicePropertyBusTypeGuid] = L"BusTypeGuid";
  221. DeviceProperty[DevicePropertyLegacyBusType] = L"LegacyBusType";
  222. DeviceProperty[DevicePropertyBusNumber] = L"BusNumber";
  223. DeviceProperty[DevicePropertyEnumeratorName] = L"EnumeratorName";
  224. if (isWin98())
  225. { // use registry
  226. HANDLE hkey;
  227. status = IoOpenDeviceRegistryKey(pdo, PLUGPLAY_REGKEY_DEVICE, KEY_READ, &hkey);
  228. if (NT_SUCCESS(status))
  229. { // get & report description
  230. UNICODE_STRING valname;
  231. RtlInitUnicodeString(&valname, L"DeviceDesc");
  232. kernel->RegistryPath = new (NonPagedPool)CUString(RegistryPath);
  233. ULONG size = 0;
  234. status = ZwQueryValueKey(hkey, &valname, KeyValuePartialInformation, NULL, 0, &size);
  235. if (status != STATUS_OBJECT_NAME_NOT_FOUND && size)
  236. { // value exists
  237. PKEY_VALUE_PARTIAL_INFORMATION vpip = (PKEY_VALUE_PARTIAL_INFORMATION) ExAllocatePool(PagedPool, size);
  238. status = ZwQueryValueKey(hkey, &valname, KeyValuePartialInformation, vpip, size, &size);
  239. if (NT_SUCCESS(status))
  240. KdPrint((DRIVERNAME " - AddDevice has succeeded for '%ws' device\n", vpip->Data));
  241. ExFreePool(vpip);
  242. } // value exists
  243. ZwClose(hkey);
  244. } // get & report description
  245. } // use registry
  246. else
  247. { // get property
  248. status = IoGetDeviceProperty(DeviceObject,DeviceProperty,BufferLength,PropertyBuffer,ResultLength);
  249. } // get property
  250. */
  251. }
  252. #pragma PAGEDCODE
  253. VOID CWDMSystem::initializeFastMutex(IN PFAST_MUTEX FastMutex)
  254. {
  255. ExInitializeFastMutex (FastMutex);
  256. }
  257. #pragma PAGEDCODE
  258. VOID CWDMSystem::acquireFastMutex(IN PFAST_MUTEX FastMutex)
  259. {
  260. ExAcquireFastMutex (FastMutex);
  261. }
  262. #pragma PAGEDCODE
  263. VOID CWDMSystem::releaseFastMutex(IN PFAST_MUTEX FastMutex)
  264. {
  265. ExReleaseFastMutex(FastMutex);
  266. }