SUPDrv-win.cpp revision 66ea204fee5b52547bf4f9ed20bf4020ff0ac55e
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * VBoxDrv - The VirtualBox Support Driver - Windows NT specifics.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * available from http://www.virtualbox.org. This file is free software;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * General Public License (GPL) as published by the Free Software
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * The contents of this file may alternatively be used under the terms
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * of the Common Development and Distribution License Version 1.0
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * CDDL are applicable instead of those of the GPL.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * You may elect to license modified versions of this file under the
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * terms and conditions of either the GPL or the CDDL or both.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * additional information or have any questions.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/*******************************************************************************
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync* Header Files *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/*******************************************************************************
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync* Defined Constants And Macros *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** The support service name. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** Win32 Device name. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** NT Device name. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** Win Symlink name. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** The Pool tag (VBox). */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/*******************************************************************************
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync* Structures and Typedefs *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#if 0 //def RT_ARCH_AMD64
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/*******************************************************************************
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync* Internal Functions *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic VOID _stdcall VBoxPowerDispatchCallback(PVOID pCallbackContext, PVOID pArgument1, PVOID pArgument2);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/*******************************************************************************
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync* External Functions *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncDECLASM(int) UNWIND_WRAP(RTPowerSignalEvent)(RTPOWEREVENT enmEvent);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/*******************************************************************************
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync* Exported Functions *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Driver entry point.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns appropriate status code.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDrvObj Pointer to driver object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pRegPath Registry base path.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Create device.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * (That means creating a device object and a symbolic link so the DOS
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * subsystems (OS/2, win32, ++) can access the device.)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = IoCreateDevice(pDrvObj, sizeof(SUPDRVDEVEXT), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDevObj);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Initialize the device extension.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Setup the driver entry points in pDrvObj.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDrvObj->MajorFunction[IRP_MJ_CREATE] = VBoxDrvNtCreate;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDrvObj->MajorFunction[IRP_MJ_CLOSE] = VBoxDrvNtClose;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDrvObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VBoxDrvNtDeviceControl;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync//#if 0 /** @todo test IDC on windows. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDrvObj->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = VBoxDrvNtInternalDeviceControl;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDrvObj->MajorFunction[IRP_MJ_READ] = VBoxDrvNtNotSupportedStub;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDrvObj->MajorFunction[IRP_MJ_WRITE] = VBoxDrvNtNotSupportedStub;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* more? */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Register ourselves for power state changes. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync RtlInitUnicodeString(&CallbackName, L"\\Callback\\PowerState");
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync InitializeObjectAttributes(&Attr, &CallbackName, OBJ_CASE_INSENSITIVE, NULL, NULL);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = ExCreateCallback(&pDevExt->pObjPowerCallback, &Attr, TRUE, TRUE);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDevExt->hPowerCallback = ExRegisterCallback(pDevExt->pObjPowerCallback, VBoxPowerDispatchCallback, pDevObj);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrv::DriverEntry returning STATUS_SUCCESS\n"));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("supdrvInitDevExit failed with vrc=%d!\n", vrc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("IoCreateSymbolicLink failed with rc=%#x!\n", rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("IoCreateDevice failed with rc=%#x!\n", rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrv::DriverEntry returning %#x\n", rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Unload the driver.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDrvObj Driver object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncvoid _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDrvObj->DeviceObject->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtUnload at irql %d\n", KeGetCurrentIrql()));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Clean up the power callback registration. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * We ASSUME that it's not possible to unload a driver with open handles.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Start by deleting the symbolic link
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Terminate the GIP page and delete the device extension.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Create (i.e. Open) file entry point.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pIrp Request packet.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncNTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * We are not remotely similar to a directory...
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * (But this is possible.)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (pStack->Parameters.Create.Options & FILE_DIRECTORY_FILE)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Call common code for the rest.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync//#if 0 /** @todo check if this works, consider OBJ_KERNEL_HANDLE too. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync // bool fUser = true;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = supdrvCreateSession(pDevExt, fUser, &pSession);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NTSTATUS rcNt = pIrp->IoStatus.Status = VBoxDrvNtErr2NtStatus(rc);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Close file entry point.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pIrp Request packet.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncNTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtClose: pDevExt=%p pFileObj=%p pSession=%p\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Device I/O Control entry point.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pIrp Request packet.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncNTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVSESSION pSession = (PSUPDRVSESSION)pStack->FileObject->FsContext;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Deal with the two high-speed IOCtl that takes it's arguments from
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * the session and iCmd, and only returns a VBox status code.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Note: The previous method of returning the rc prior to IOC version
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * 7.4 has been abandond, we're no longer compatible with that
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * interface.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ULONG ulCmd = pStack->Parameters.DeviceIoControl.IoControlCode;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = supdrvIOCtlFast(ulCmd, (unsigned)(uintptr_t)pIrp->UserBuffer /* VMCPU id */, pDevExt, pSession);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Raise the IRQL to DISPATCH_LEVEL to prevent Windows from rescheduling us to another CPU/core. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = supdrvIOCtlFast(ulCmd, (unsigned)(uintptr_t)pIrp->UserBuffer /* VMCPU id */, pDevExt, pSession);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Complete the I/O request. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NTSTATUS rcNt = pIrp->IoStatus.Status = RT_SUCCESS(rc) ? STATUS_SUCCESS : STATUS_INVALID_PARAMETER;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return VBoxDrvNtDeviceControlSlow(pDevExt, pSession, pIrp, pStack);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Worker for VBoxDrvNtDeviceControl that takes the slow IOCtl functions.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns NT status code.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pSession The session.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pIrp Request packet.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pStack The stack location containing the DeviceControl parameters.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync unsigned cbOut = 0;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf2(("VBoxDrvNtDeviceControlSlow(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Don't allow 32-bit processes to do any I/O controls. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Verify that it's a buffered CTL. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Verify that the sizes in the request header are correct. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPREQHDR pHdr = (PSUPREQHDR)pIrp->AssociatedIrp.SystemBuffer;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cbIn
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cbOut)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Do the job.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (cbOut > pStack->Parameters.DeviceIoControl.OutputBufferLength)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync OSDBGPRINT(("VBoxDrvLinuxIOCtl: too much output! %#x > %#x; uCmd=%#x!\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pHdr->cbOut, cbOut, pStack->Parameters.DeviceIoControl.IoControlCode));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf2(("VBoxDrvNtDeviceControlSlow: returns %#x cbOut=%d rc=%#x\n", rcNt, cbOut, rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtDeviceControlSlow: Mismatching sizes (%#x) - Hdr=%#lx/%#lx Irp=%#lx/%#lx!\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbIn : 0,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbOut : 0,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.InputBufferLength,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.OutputBufferLength));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtDeviceControlSlow: not buffered request (%#x) - not supported\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.IoControlCode));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtDeviceControlSlow: WOW64 req - not supported\n"));
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync /* complete the request. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Internal Device I/O Control entry point, used for IDC.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pIrp Request packet.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncNTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PFILE_OBJECT pFileObj = pStack ? pStack->FileObject : NULL;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVSESSION pSession = pFileObj ? (PSUPDRVSESSION)pFileObj->FsContext : NULL;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync unsigned cbOut = 0;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf2(("VBoxDrvNtInternalDeviceControl(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** @todo IDC on NT: figure when to create the session and that stuff... */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Verify that it's a buffered CTL. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Verify the pDevExt in the session. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync && pStack->Parameters.DeviceIoControl.IoControlCode == SUPDRV_IDC_REQ_CONNECT)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Verify that the size in the request header is correct. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVIDCREQHDR pHdr = (PSUPDRVIDCREQHDR)pIrp->AssociatedIrp.SystemBuffer;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cb
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cb)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Do the job.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = supdrvIDC(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf2(("VBoxDrvNtInternalDeviceControl: returns %#x/rc=%#x\n", rcNt, rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtInternalDeviceControl: Mismatching sizes (%#x) - Hdr=%#lx Irp=%#lx/%#lx!\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cb : 0,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.InputBufferLength,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.OutputBufferLength));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtInternalDeviceControl: not buffered request (%#x) - not supported\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.IoControlCode));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* complete the request. */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * Stub function for functions we don't implemented.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns STATUS_NOT_SUPPORTED
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * @param pIrp IRP.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsyncNTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * ExRegisterCallback handler for power events
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pCallbackContext User supplied parameter (pDevObj)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pArgument1 First argument
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pArgument2 Second argument
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncVOID _stdcall VBoxPowerDispatchCallback(PVOID pCallbackContext, PVOID pArgument1, PVOID pArgument2)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PDEVICE_OBJECT pDevObj = (PDEVICE_OBJECT)pCallbackContext;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxPowerDispatchCallback: %x %x\n", pArgument1, pArgument2));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Power change imminent? */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ((unsigned)pArgument1 == PO_CB_SYSTEM_STATE_LOCK)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ((unsigned)pArgument2 == 0)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxPowerDispatchCallback: about to go into suspend mode!\n"));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxPowerDispatchCallback: resumed!\n"));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Inform any clients that have registered themselves with IPRT. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync UNWIND_WRAP(RTPowerSignalEvent)(((unsigned)pArgument2 == 0) ? RTPOWEREVENT_SUSPEND : RTPOWEREVENT_RESUME);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Initializes any OS specific object creator fields.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncvoid VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Checks if the session can access the object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns true if a decision has been made.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns false if the default access policy should be applied.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pObj The object in question.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pSession The session wanting to access the object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pszObjName The object name, can be NULL.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param prc Where to store the result when returning true.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncbool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Force async tsc mode (stub).
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncbool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#define MY_SystemLoadGdiDriverInSystemSpaceInformation 54
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync PVOID EntryPointer; /**< Out: entry point address. */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync PVOID ExportSectionPointer; /**< Out: export directory/section. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncextern "C" __declspec(dllimport) NTSTATUS NTAPI ZwSetSystemInformation(ULONG, PVOID, ULONG);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncint VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Convert the filename from DOS UTF-8 to NT UTF-16.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = RTStrCalcUtf16LenEx(pszFilename, RTSTR_MAX, &cwcFilename);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PRTUTF16 pwcsFilename = (PRTUTF16)RTMemTmpAlloc((4 + cwcFilename + 1) * sizeof(RTUTF16));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = RTStrToUtf16Ex(pszFilename, RTSTR_MAX, &pwcsTmp, cwcFilename + 1, NULL);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Try load it.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NTSTATUS rcNt = ZwSetSystemInformation(MY_SystemLoadGdiDriverInSystemSpaceInformation, &Info, sizeof(Info));
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync Log(("ImageAddress=%p SectionPointer=%p ImageLength=%#x cbImageBits=%#x rcNt=%#x '%ls'\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync Info.ImageAddress, Info.SectionPointer, Info.ImageLength, pImage->cbImageBits, rcNt, Info.Name.Buffer));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync SUPR0Printf("ImageAddress=%p SectionPointer=%p ImageLength=%#x cbImageBits=%#x rcNt=%#x '%ws'\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync Info.ImageAddress, Info.SectionPointer, Info.ImageLength, pImage->cbImageBits, rcNt, Info.Name.Buffer);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** @todo do we need to lock down the image? */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync SUPR0Printf("VBoxDrv: rcNt=%#x '%ws'\n", rcNt, pwcsFilename);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Use the old way of loading the modules if we can. We do
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * not try class 26 because it will not work correctly on
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * terminal server and have issues with paging of the image.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Note! Using the 64-bit wrappers will require hacking the
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * image verfication in supdrvOSLdrLoad.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync# if !defined(RT_ARCH_AMD64) || defined(RT_WITH_W64_UNWIND_HACK)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync case /* 0xc0000034 */ STATUS_OBJECT_NAME_NOT_FOUND:
return rc;
int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, const uint8_t *pbImageBits)
return VINF_SUCCESS;
int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits)
return VINF_SUCCESS;
return VERR_LDR_MISMATCH_NATIVE;
return VERR_INTERNAL_ERROR_4;
switch (rc)
case 0: return STATUS_SUCCESS;
return STATUS_UNSUCCESSFUL;