Changeset 58113 in vbox for trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-pnp.cpp
- Timestamp:
- Oct 8, 2015 10:13:54 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-pnp.cpp
r58053 r58113 32 32 *********************************************************************************************************************************/ 33 33 RT_C_DECLS_BEGIN 34 static NTSTATUS v bgdNtSendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict);35 static NTSTATUS v bgdNtPnPIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT pEvent);36 static VOID v bgdNtShowDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList);34 static NTSTATUS vgdrvNtSendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict); 35 static NTSTATUS vgdrvNtPnPIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT pEvent); 36 static VOID vgdrvNtShowDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList); 37 37 RT_C_DECLS_END 38 38 39 39 #ifdef ALLOC_PRAGMA 40 # pragma alloc_text(PAGE, v bgdNtPnP)41 # pragma alloc_text(PAGE, v bgdNtPower)42 # pragma alloc_text(PAGE, v bgdNtSendIrpSynchronously)43 # pragma alloc_text(PAGE, v bgdNtShowDeviceResources)40 # pragma alloc_text(PAGE, vgdrvNtPnP) 41 # pragma alloc_text(PAGE, vgdrvNtPower) 42 # pragma alloc_text(PAGE, vgdrvNtSendIrpSynchronously) 43 # pragma alloc_text(PAGE, vgdrvNtShowDeviceResources) 44 44 #endif 45 45 … … 48 48 * Irp completion routine for PnP Irps we send. 49 49 * 50 * @returns NT status code. 50 51 * @param pDevObj Device object. 51 52 * @param pIrp Request packet. 52 53 * @param pEvent Semaphore. 53 * @return NT status code 54 */ 55 static NTSTATUS vbgdNtPnpIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT pEvent) 54 */ 55 static NTSTATUS vgdrvNtPnpIrpComplete(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT pEvent) 56 56 { 57 57 KeSetEvent(pEvent, 0, FALSE); … … 63 63 * Helper to send a PnP IRP and wait until it's done. 64 64 * 65 * @returns NT status code. 65 66 * @param pDevObj Device object. 66 67 * @param pIrp Request packet. 67 68 * @param fStrict When set, returns an error if the IRP gives an error. 68 * @return NT status code 69 */ 70 static NTSTATUS vbgdNtSendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict) 69 */ 70 static NTSTATUS vgdrvNtSendIrpSynchronously(PDEVICE_OBJECT pDevObj, PIRP pIrp, BOOLEAN fStrict) 71 71 { 72 72 KEVENT Event; … … 75 75 76 76 IoCopyCurrentIrpStackLocationToNext(pIrp); 77 IoSetCompletionRoutine(pIrp, (PIO_COMPLETION_ROUTINE)vbgdNtPnpIrpComplete, 78 &Event, TRUE, TRUE, TRUE); 77 IoSetCompletionRoutine(pIrp, (PIO_COMPLETION_ROUTINE)vgdrvNtPnpIrpComplete, &Event, TRUE, TRUE, TRUE); 79 78 80 79 NTSTATUS rc = IoCallDriver(pDevObj, pIrp); … … 86 85 } 87 86 88 if ( !fStrict87 if ( !fStrict 89 88 && (rc == STATUS_NOT_SUPPORTED || rc == STATUS_INVALID_DEVICE_REQUEST)) 90 89 { … … 92 91 } 93 92 94 Log((" VBoxGuest::vbgdNtSendIrpSynchronously: Returning 0x%x\n", rc));93 Log(("vgdrvNtSendIrpSynchronously: Returning 0x%x\n", rc)); 95 94 return rc; 96 95 } … … 103 102 * @param pIrp Request packet. 104 103 */ 105 NTSTATUS v bgdNtPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp)104 NTSTATUS vgdrvNtPnP(PDEVICE_OBJECT pDevObj, PIRP pIrp) 106 105 { 107 106 PVBOXGUESTDEVEXTWIN pDevExt = (PVBOXGUESTDEVEXTWIN)pDevObj->DeviceExtension; … … 136 135 "IRP_MN_SURPRISE_REMOVAL", 137 136 }; 138 Log((" VBoxGuest::vbgdNtGuestPnp: MinorFunction: %s\n",137 Log(("vgdrvNtPnP: MinorFunction: %s\n", 139 138 pStack->MinorFunction < RT_ELEMENTS(s_apszFnctName) ? s_apszFnctName[pStack->MinorFunction] : "Unknown")); 140 139 #endif … … 145 144 case IRP_MN_START_DEVICE: 146 145 { 147 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: START_DEVICE\n"));146 Log(("vgdrvNtPnP: START_DEVICE\n")); 148 147 149 148 /* This must be handled first by the lower driver. */ 150 rc = v bgdNtSendIrpSynchronously(pDevExt->pNextLowerDriver, pIrp, TRUE);149 rc = vgdrvNtSendIrpSynchronously(pDevExt->pNextLowerDriver, pIrp, TRUE); 151 150 152 151 if ( NT_SUCCESS(rc) 153 152 && NT_SUCCESS(pIrp->IoStatus.Status)) 154 153 { 155 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: START_DEVICE: pStack->Parameters.StartDevice.AllocatedResources = %p\n",154 Log(("vgdrvNtPnP: START_DEVICE: pStack->Parameters.StartDevice.AllocatedResources = %p\n", 156 155 pStack->Parameters.StartDevice.AllocatedResources)); 157 156 158 if (!pStack->Parameters.StartDevice.AllocatedResources) 157 if (pStack->Parameters.StartDevice.AllocatedResources) 158 rc = vgdrvNtInit(pDevObj, pIrp); 159 else 159 160 { 160 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: START_DEVICE: No resources, pDevExt = %p, nextLowerDriver = %p!\n",161 Log(("vgdrvNtPnP: START_DEVICE: No resources, pDevExt = %p, nextLowerDriver = %p!\n", 161 162 pDevExt, pDevExt ? pDevExt->pNextLowerDriver : NULL)); 162 163 rc = STATUS_UNSUCCESSFUL; 163 164 } 164 else165 {166 rc = vbgdNtInit(pDevObj, pIrp);167 }168 165 } 169 166 170 167 if (NT_ERROR(rc)) 171 168 { 172 Log((" VBoxGuest::vbgdNtGuestPnp: START_DEVICE: Error: rc = 0x%x\n", rc));169 Log(("vgdrvNtPnP: START_DEVICE: Error: rc = 0x%x\n", rc)); 173 170 174 171 /* Need to unmap memory in case of errors ... */ 175 vbgdNtUnmapVMMDevMemory(pDevExt); 172 /** @todo r=bird: vgdrvNtInit maps it and is responsible for cleaning up its own friggin mess... 173 * Fix it instead of kind of working around things there!! */ 174 vgdrvNtUnmapVMMDevMemory(pDevExt); 176 175 } 177 176 break; … … 180 179 case IRP_MN_CANCEL_REMOVE_DEVICE: 181 180 { 182 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: CANCEL_REMOVE_DEVICE\n"));181 Log(("vgdrvNtPnP: CANCEL_REMOVE_DEVICE\n")); 183 182 184 183 /* This must be handled first by the lower driver. */ 185 rc = v bgdNtSendIrpSynchronously(pDevExt->pNextLowerDriver, pIrp, TRUE);186 187 if (NT_SUCCESS(rc) && pDevExt-> devState ==PENDINGREMOVE)184 rc = vgdrvNtSendIrpSynchronously(pDevExt->pNextLowerDriver, pIrp, TRUE); 185 186 if (NT_SUCCESS(rc) && pDevExt->enmDevState == VGDRVNTDEVSTATE_PENDINGREMOVE) 188 187 { 189 188 /* Return to the state prior to receiving the IRP_MN_QUERY_REMOVE_DEVICE request. */ 190 pDevExt-> devState = pDevExt->prevDevState;189 pDevExt->enmDevState = pDevExt->enmPrevDevState; 191 190 } 192 191 … … 197 196 case IRP_MN_SURPRISE_REMOVAL: 198 197 { 199 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: IRP_MN_SURPRISE_REMOVAL\n"));200 201 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, SURPRISEREMOVED);198 Log(("vgdrvNtPnP: IRP_MN_SURPRISE_REMOVAL\n")); 199 200 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, VGDRVNTDEVSTATE_SURPRISEREMOVED); 202 201 203 202 /* Do nothing here actually. Cleanup is done in IRP_MN_REMOVE_DEVICE. … … 219 218 case IRP_MN_QUERY_REMOVE_DEVICE: 220 219 { 221 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: QUERY_REMOVE_DEVICE\n"));220 Log(("vgdrvNtPnP: QUERY_REMOVE_DEVICE\n")); 222 221 223 222 #ifdef VBOX_REBOOT_ON_UNINSTALL 224 Log((" VBoxGuest::vbgdNtGuestPnp: QUERY_REMOVE_DEVICE: Device cannot be removed without a reboot.\n"));223 Log(("vgdrvNtPnP: QUERY_REMOVE_DEVICE: Device cannot be removed without a reboot.\n")); 225 224 rc = STATUS_UNSUCCESSFUL; 226 225 #endif … … 228 227 if (NT_SUCCESS(rc)) 229 228 { 230 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, PENDINGREMOVE);229 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, VGDRVNTDEVSTATE_PENDINGREMOVE); 231 230 232 231 /* This IRP passed down to lower driver. */ … … 236 235 237 236 rc = IoCallDriver(pDevExt->pNextLowerDriver, pIrp); 238 Log((" VBoxGuest::vbgdNtGuestPnp: QUERY_REMOVE_DEVICE: Next lower driver replied rc = 0x%x\n", rc));237 Log(("vgdrvNtPnP: QUERY_REMOVE_DEVICE: Next lower driver replied rc = 0x%x\n", rc)); 239 238 240 239 /* we must not do anything the IRP after doing IoSkip & CallDriver … … 250 249 case IRP_MN_REMOVE_DEVICE: 251 250 { 252 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: REMOVE_DEVICE\n"));253 254 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, REMOVED);251 Log(("vgdrvNtPnP: REMOVE_DEVICE\n")); 252 253 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, VGDRVNTDEVSTATE_REMOVED); 255 254 256 255 /* Free hardware resources. */ 257 256 /** @todo this should actually free I/O ports, interrupts, etc. 258 * Update/bird: v bgdNtCleanup actually does that... So, what's there to do? */259 rc = v bgdNtCleanup(pDevObj);260 Log((" VBoxGuest::vbgdNtGuestPnp: REMOVE_DEVICE: vbgdNtCleanup rc = 0x%08X\n", rc));257 * Update/bird: vgdrvNtCleanup actually does that... So, what's there to do? */ 258 rc = vgdrvNtCleanup(pDevObj); 259 Log(("vgdrvNtPnP: REMOVE_DEVICE: vgdrvNtCleanup rc = 0x%08X\n", rc)); 261 260 262 261 /* … … 270 269 271 270 rc = IoCallDriver(pDevExt->pNextLowerDriver, pIrp); 272 Log((" VBoxGuest::vbgdNtGuestPnp: REMOVE_DEVICE: Next lower driver replied rc = 0x%x\n", rc));271 Log(("vgdrvNtPnP: REMOVE_DEVICE: Next lower driver replied rc = 0x%x\n", rc)); 273 272 274 273 IoDetachDevice(pDevExt->pNextLowerDriver); 275 274 276 Log((" VBoxGuest::vbgdNtGuestPnp: REMOVE_DEVICE: Removing device ...\n"));275 Log(("vgdrvNtPnP: REMOVE_DEVICE: Removing device ...\n")); 277 276 278 277 /* Destroy device extension and clean up everything else. */ … … 284 283 IoDeleteSymbolicLink(&win32Name); 285 284 286 Log((" VBoxGuest::vbgdNtGuestPnp: REMOVE_DEVICE: Deleting device ...\n"));285 Log(("vgdrvNtPnP: REMOVE_DEVICE: Deleting device ...\n")); 287 286 288 287 /* Last action: Delete our device! pDevObj is *not* failed … … 290 289 IoDeleteDevice(pDevObj); 291 290 292 Log((" VBoxGuest::vbgdNtGuestPnp: REMOVE_DEVICE: Device removed!\n"));291 Log(("vgdrvNtPnP: REMOVE_DEVICE: Device removed!\n")); 293 292 294 293 /* Propagating rc from IoCallDriver. */ … … 298 297 case IRP_MN_CANCEL_STOP_DEVICE: 299 298 { 300 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: CANCEL_STOP_DEVICE\n"));299 Log(("vgdrvNtPnP: CANCEL_STOP_DEVICE\n")); 301 300 302 301 /* This must be handled first by the lower driver. */ 303 rc = v bgdNtSendIrpSynchronously(pDevExt->pNextLowerDriver, pIrp, TRUE);304 305 if (NT_SUCCESS(rc) && pDevExt-> devState ==PENDINGSTOP)302 rc = vgdrvNtSendIrpSynchronously(pDevExt->pNextLowerDriver, pIrp, TRUE); 303 304 if (NT_SUCCESS(rc) && pDevExt->enmDevState == VGDRVNTDEVSTATE_PENDINGSTOP) 306 305 { 307 306 /* Return to the state prior to receiving the IRP_MN_QUERY_STOP_DEVICE request. */ 308 pDevExt-> devState = pDevExt->prevDevState;307 pDevExt->enmDevState = pDevExt->enmPrevDevState; 309 308 } 310 309 … … 315 314 case IRP_MN_QUERY_STOP_DEVICE: 316 315 { 317 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: QUERY_STOP_DEVICE\n"));316 Log(("vgdrvNtPnP: QUERY_STOP_DEVICE\n")); 318 317 319 318 #ifdef VBOX_REBOOT_ON_UNINSTALL 320 Log((" VBoxGuest::vbgdNtGuestPnp: QUERY_STOP_DEVICE: Device cannot be stopped without a reboot!\n"));319 Log(("vgdrvNtPnP: QUERY_STOP_DEVICE: Device cannot be stopped without a reboot!\n")); 321 320 pIrp->IoStatus.Status = STATUS_UNSUCCESSFUL; 322 321 #endif … … 324 323 if (NT_SUCCESS(rc)) 325 324 { 326 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, PENDINGSTOP);325 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, VGDRVNTDEVSTATE_PENDINGSTOP); 327 326 328 327 /* This IRP passed down to lower driver. */ … … 332 331 333 332 rc = IoCallDriver(pDevExt->pNextLowerDriver, pIrp); 334 Log((" VBoxGuest::vbgdNtGuestPnp: QUERY_STOP_DEVICE: Next lower driver replied rc = 0x%x\n", rc));333 Log(("vgdrvNtPnP: QUERY_STOP_DEVICE: Next lower driver replied rc = 0x%x\n", rc)); 335 334 336 335 /* we must not do anything with the IRP after doing IoSkip & CallDriver … … 346 345 case IRP_MN_STOP_DEVICE: 347 346 { 348 Log((" VBoxGuest::vbgdNtVBoxGuestPnP: STOP_DEVICE\n"));349 350 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, STOPPED);347 Log(("vgdrvNtPnP: STOP_DEVICE\n")); 348 349 VBOXGUEST_UPDATE_DEVSTATE(pDevExt, VGDRVNTDEVSTATE_STOPPED); 351 350 352 351 /* Free hardware resources. */ 353 352 /** @todo this should actually free I/O ports, interrupts, etc. 354 * Update/bird: v bgdNtCleanup actually does that... So, what's there to do? */355 rc = v bgdNtCleanup(pDevObj);356 Log((" VBoxGuest::vbgdNtGuestPnp: STOP_DEVICE: cleaning up, rc = 0x%x\n", rc));353 * Update/bird: vgdrvNtCleanup actually does that... So, what's there to do? */ 354 rc = vgdrvNtCleanup(pDevObj); 355 Log(("vgdrvNtPnP: STOP_DEVICE: cleaning up, rc = 0x%x\n", rc)); 357 356 358 357 /* Pass to the lower driver. */ … … 362 361 363 362 rc = IoCallDriver(pDevExt->pNextLowerDriver, pIrp); 364 Log((" VBoxGuest::vbgdNtGuestPnp: STOP_DEVICE: Next lower driver replied rc = 0x%x\n", rc));363 Log(("vgdrvNtPnP: STOP_DEVICE: Next lower driver replied rc = 0x%x\n", rc)); 365 364 366 365 return rc; … … 378 377 IoCompleteRequest(pIrp, IO_NO_INCREMENT); 379 378 380 Log((" VBoxGuest::vbgdNtGuestPnp: Returning with rc = 0x%x\n", rc));379 Log(("vgdrvNtPnP: Returning with rc = 0x%x\n", rc)); 381 380 return rc; 382 381 } … … 391 390 * @param pContext Context value passed to IoSetCompletionRoutine in VBoxGuestPower. 392 391 */ 393 static NTSTATUS v bgdNtPowerComplete(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp, IN PVOID pContext)392 static NTSTATUS vgdrvNtPowerComplete(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp, IN PVOID pContext) 394 393 { 395 394 #ifdef VBOX_STRICT … … 407 406 { 408 407 case IRP_MN_SET_POWER: 409 410 408 switch (pIrpSp->Parameters.Power.Type) 411 409 { … … 435 433 * @param pIrp IRP 436 434 */ 437 NTSTATUS v bgdNtPower(PDEVICE_OBJECT pDevObj, PIRP pIrp)435 NTSTATUS vgdrvNtPower(PDEVICE_OBJECT pDevObj, PIRP pIrp) 438 436 { 439 437 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp); … … 443 441 POWER_ACTION enmPowerAction = pStack->Parameters.Power.ShutdownType; 444 442 445 Log((" VBoxGuest::vbgdNtGuestPower\n"));443 Log(("vgdrvNtPower:\n")); 446 444 447 445 switch (pStack->MinorFunction) … … 449 447 case IRP_MN_SET_POWER: 450 448 { 451 Log((" VBoxGuest::vbgdNtGuestPower: IRP_MN_SET_POWER, type= %d\n", enmPowerType));449 Log(("vgdrvNtPower: IRP_MN_SET_POWER, type= %d\n", enmPowerType)); 452 450 switch (enmPowerType) 453 451 { 454 452 case SystemPowerState: 455 453 { 456 Log((" VBoxGuest::vbgdNtGuestPower: SystemPowerState, action = %d, state = %d/%d\n",454 Log(("vgdrvNtPower: SystemPowerState, action = %d, state = %d/%d\n", 457 455 enmPowerAction, PowerState.SystemState, PowerState.DeviceState)); 458 456 … … 467 465 && pDevExt->LastSystemPowerAction == PowerActionHibernate) 468 466 { 469 Log((" VBoxGuest::vbgdNtGuestPower: Returning from hibernation!\n"));467 Log(("vgdrvNtPower: Returning from hibernation!\n")); 470 468 int rc = VGDrvCommonReinitDevExtAfterHibernation(&pDevExt->Core, 471 v bgdNtVersionToOSType(g_enmVbgdNtVer));469 vgdrvNtVersionToOSType(g_enmVGDrvNtVer)); 472 470 if (RT_FAILURE(rc)) 473 Log((" VBoxGuest::vbgdNtGuestPower: Cannot re-init VMMDev chain, rc = %d!\n", rc));471 Log(("vgdrvNtPower: Cannot re-init VMMDev chain, rc = %d!\n", rc)); 474 472 } 475 473 } … … 478 476 case PowerActionShutdownReset: 479 477 { 480 Log((" VBoxGuest::vbgdNtGuestPower: Power action reset!\n"));478 Log(("vgdrvNtPower: Power action reset!\n")); 481 479 482 480 /* Tell the VMM that we no longer support mouse pointer integration. */ … … 493 491 if (RT_FAILURE(vrc)) 494 492 { 495 Log((" VBoxGuest::PowerStateRequest: error communicating new power status to VMMDev. vrc = %Rrc\n", vrc));493 Log(("vgdrvNtPower: error communicating new power status to VMMDev. vrc = %Rrc\n", vrc)); 496 494 } 497 495 … … 507 505 case PowerActionShutdownOff: 508 506 { 509 Log((" VBoxGuest::vbgdNtGuestPower: Power action shutdown!\n"));507 Log(("vgdrvNtPower: Power action shutdown!\n")); 510 508 if (PowerState.SystemState >= PowerSystemShutdown) 511 509 { 512 Log((" VBoxGuest::vbgdNtGuestPower: Telling the VMMDev to close the VM ...\n"));510 Log(("vgdrvNtPower: Telling the VMMDev to close the VM ...\n")); 513 511 514 512 VMMDevPowerStateRequest *pReq = pDevExt->pPowerStateRequest; … … 522 520 } 523 521 if (RT_FAILURE(vrc)) 524 Log((" VBoxGuest::PowerStateRequest: Error communicating new power status to VMMDev. vrc = %Rrc\n", vrc));522 Log(("vgdrvNtPower: Error communicating new power status to VMMDev. vrc = %Rrc\n", vrc)); 525 523 526 524 /* No need to do cleanup here; at this point we should've been … … 532 530 case PowerActionHibernate: 533 531 534 Log((" VBoxGuest::vbgdNtGuestPower: Power action hibernate!\n"));532 Log(("vgdrvNtPower: Power action hibernate!\n")); 535 533 break; 536 534 } … … 566 564 IoCopyCurrentIrpStackLocationToNext(pIrp); 567 565 IoSetCompletionRoutine(pIrp, 568 v bgdNtPowerComplete,566 vgdrvNtPowerComplete, 569 567 (PVOID)pDevExt, 570 568 TRUE,
Note:
See TracChangeset
for help on using the changeset viewer.