SUPDrv-win.cpp revision 66ea204fee5b52547bf4f9ed20bf4020ff0ac55e
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/* $Id$ */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/** @file
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * VBoxDrv - The VirtualBox Support Driver - Windows NT specifics.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync *
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 *
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.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
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 *
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 */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/*******************************************************************************
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync* Header Files *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#define LOG_GROUP LOG_GROUP_SUP_DRV
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#include "../SUPDrvInternal.h"
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#include <excpt.h>
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#include <iprt/assert.h>
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#include <iprt/initterm.h>
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#include <iprt/mem.h>
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#include <iprt/process.h>
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#include <iprt/power.h>
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#include <iprt/string.h>
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#include <VBox/log.h>
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/*******************************************************************************
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync* Defined Constants And Macros *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** The support service name. */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#define SERVICE_NAME "VBoxDrv"
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** Win32 Device name. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#define DEVICE_NAME "\\\\.\\VBoxDrv"
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** NT Device name. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#define DEVICE_NAME_NT L"\\Device\\VBoxDrv"
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** Win Symlink name. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#define DEVICE_NAME_DOS L"\\DosDevices\\VBoxDrv"
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** The Pool tag (VBox). */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#define SUPDRV_NT_POOL_TAG 'xoBV'
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/*******************************************************************************
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync* Structures and Typedefs *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#if 0 //def RT_ARCH_AMD64
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsynctypedef struct SUPDRVEXECMEM
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PMDL pMdl;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync void *pvMapping;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync void *pvAllocation;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync} SUPDRVEXECMEM, *PSUPDRVEXECMEM;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#endif
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
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);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic NTSTATUS VBoxDrvNtErr2NtStatus(int rc);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/*******************************************************************************
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync* External Functions *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncDECLASM(int) UNWIND_WRAP(RTPowerSignalEvent)(RTPOWEREVENT enmEvent);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/*******************************************************************************
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync* Exported Functions *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncRT_C_DECLS_BEGIN
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncRT_C_DECLS_END
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Driver entry point.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns appropriate status code.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDrvObj Pointer to driver object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pRegPath Registry base path.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NTSTATUS rc;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrv::DriverEntry\n"));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
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 */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync UNICODE_STRING DevName;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync RtlInitUnicodeString(&DevName, DEVICE_NAME_NT);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PDEVICE_OBJECT pDevObj;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = IoCreateDevice(pDrvObj, sizeof(SUPDRVDEVEXT), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDevObj);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (NT_SUCCESS(rc))
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync UNICODE_STRING DosName;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = IoCreateSymbolicLink(&DosName, &DevName);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (NT_SUCCESS(rc))
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int vrc = RTR0Init(0);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (RT_SUCCESS(rc))
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Initialize the device extension.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync memset(pDevExt, 0, sizeof(*pDevExt));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync vrc = supdrvInitDevExt(pDevExt);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (!vrc)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Setup the driver entry points in pDrvObj.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDrvObj->DriverUnload = VBoxDrvNtUnload;
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//#endif
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDrvObj->MajorFunction[IRP_MJ_READ] = VBoxDrvNtNotSupportedStub;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDrvObj->MajorFunction[IRP_MJ_WRITE] = VBoxDrvNtNotSupportedStub;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* more? */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Register ourselves for power state changes. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync UNICODE_STRING CallbackName;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync OBJECT_ATTRIBUTES Attr;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync RtlInitUnicodeString(&CallbackName, L"\\Callback\\PowerState");
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync InitializeObjectAttributes(&Attr, &CallbackName, OBJ_CASE_INSENSITIVE, NULL, NULL);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = ExCreateCallback(&pDevExt->pObjPowerCallback, &Attr, TRUE, TRUE);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (rc == STATUS_SUCCESS)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDevExt->hPowerCallback = ExRegisterCallback(pDevExt->pObjPowerCallback, VBoxPowerDispatchCallback, pDevObj);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrv::DriverEntry returning STATUS_SUCCESS\n"));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return STATUS_SUCCESS;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("supdrvInitDevExit failed with vrc=%d!\n", vrc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = VBoxDrvNtErr2NtStatus(vrc);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoDeleteSymbolicLink(&DosName);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync RTR0Term();
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("RTR0Init failed with vrc=%d!\n", vrc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = VBoxDrvNtErr2NtStatus(vrc);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("IoCreateSymbolicLink failed with rc=%#x!\n", rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoDeleteDevice(pDevObj);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("IoCreateDevice failed with rc=%#x!\n", rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (NT_SUCCESS(rc))
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = STATUS_INVALID_PARAMETER;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrv::DriverEntry returning %#x\n", rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return rc;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Unload the driver.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDrvObj Driver object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncvoid _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDrvObj->DeviceObject->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtUnload at irql %d\n", KeGetCurrentIrql()));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Clean up the power callback registration. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (pDevExt->hPowerCallback)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ExUnregisterCallback(pDevExt->hPowerCallback);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (pDevExt->pObjPowerCallback)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ObDereferenceObject(pDevExt->pObjPowerCallback);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * We ASSUME that it's not possible to unload a driver with open handles.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Start by deleting the symbolic link
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync UNICODE_STRING DosName;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NTSTATUS rc = IoDeleteSymbolicLink(&DosName);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Terminate the GIP page and delete the device extension.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync supdrvDeleteDevExt(pDevExt);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync RTR0Term();
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoDeleteDevice(pDrvObj->DeviceObject);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Create (i.e. Open) file entry point.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pIrp Request packet.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncNTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtCreate\n"));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PFILE_OBJECT pFileObj = pStack->FileObject;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * We are not remotely similar to a directory...
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * (But this is possible.)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (pStack->Parameters.Create.Options & FILE_DIRECTORY_FILE)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pIrp->IoStatus.Status = STATUS_NOT_A_DIRECTORY;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pIrp->IoStatus.Information = 0;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return STATUS_NOT_A_DIRECTORY;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Call common code for the rest.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pFileObj->FsContext = NULL;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVSESSION pSession;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync//#if 0 /** @todo check if this works, consider OBJ_KERNEL_HANDLE too. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync bool fUser = pIrp->RequestorMode != KernelMode;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync//#else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync // bool fUser = true;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync//#endif
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = supdrvCreateSession(pDevExt, fUser, &pSession);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (!rc)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pFileObj->FsContext = pSession;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NTSTATUS rcNt = pIrp->IoStatus.Status = VBoxDrvNtErr2NtStatus(rc);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pIrp->IoStatus.Information = 0;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return rcNt;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Close file entry point.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pIrp Request packet.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncNTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PFILE_OBJECT pFileObj = pStack->FileObject;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtClose: pDevExt=%p pFileObj=%p pSession=%p\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pDevExt, pFileObj, pFileObj->FsContext));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pFileObj->FsContext = NULL;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pIrp->IoStatus.Information = 0;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pIrp->IoStatus.Status = STATUS_SUCCESS;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return STATUS_SUCCESS;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Device I/O Control entry point.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pIrp Request packet.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncNTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PSUPDRVSESSION pSession = (PSUPDRVSESSION)pStack->FileObject->FsContext;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
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 *
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 */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ULONG ulCmd = pStack->Parameters.DeviceIoControl.IoControlCode;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ( ulCmd == SUP_IOCTL_FAST_DO_RAW_RUN
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync || ulCmd == SUP_IOCTL_FAST_DO_HWACC_RUN
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync || ulCmd == SUP_IOCTL_FAST_DO_NOP)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = supdrvIOCtlFast(ulCmd, (unsigned)(uintptr_t)pIrp->UserBuffer /* VMCPU id */, pDevExt, pSession);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Raise the IRQL to DISPATCH_LEVEL to prevent Windows from rescheduling us to another CPU/core. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync Assert(KeGetCurrentIrql() <= DISPATCH_LEVEL);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync KIRQL oldIrql;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync KeRaiseIrql(DISPATCH_LEVEL, &oldIrql);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = supdrvIOCtlFast(ulCmd, (unsigned)(uintptr_t)pIrp->UserBuffer /* VMCPU id */, pDevExt, pSession);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync KeLowerIrql(oldIrql);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#endif
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Complete the I/O request. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NTSTATUS rcNt = pIrp->IoStatus.Status = RT_SUCCESS(rc) ? STATUS_SUCCESS : STATUS_INVALID_PARAMETER;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return rcNt;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return VBoxDrvNtDeviceControlSlow(pDevExt, pSession, pIrp, pStack);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Worker for VBoxDrvNtDeviceControl that takes the slow IOCtl functions.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns NT status code.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
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.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NTSTATUS rcNt;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync unsigned cbOut = 0;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = 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
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#ifdef RT_ARCH_AMD64
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Don't allow 32-bit processes to do any I/O controls. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (!IoIs32bitProcess(pIrp))
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#endif
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Verify that it's a buffered CTL. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
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 {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Do the job.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (!rc)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rcNt = STATUS_SUCCESS;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync cbOut = pHdr->cbOut;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (cbOut > pStack->Parameters.DeviceIoControl.OutputBufferLength)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
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 }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rcNt = STATUS_INVALID_PARAMETER;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf2(("VBoxDrvNtDeviceControlSlow: returns %#x cbOut=%d rc=%#x\n", rcNt, cbOut, rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtDeviceControlSlow: Mismatching sizes (%#x) - Hdr=%#lx/%#lx Irp=%#lx/%#lx!\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.IoControlCode,
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 rcNt = STATUS_INVALID_PARAMETER;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtDeviceControlSlow: not buffered request (%#x) - not supported\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.IoControlCode));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rcNt = STATUS_NOT_SUPPORTED;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#ifdef RT_ARCH_AMD64
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtDeviceControlSlow: WOW64 req - not supported\n"));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rcNt = STATUS_NOT_SUPPORTED;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#endif
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync /* complete the request. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pIrp->IoStatus.Status = rcNt;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync pIrp->IoStatus.Information = cbOut;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return rcNt;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Internal Device I/O Control entry point, used for IDC.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pIrp Request packet.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncNTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
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 NTSTATUS rcNt;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync unsigned cbOut = 0;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = 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
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/** @todo IDC on NT: figure when to create the session and that stuff... */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Verify that it's a buffered CTL. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Verify the pDevExt in the session. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ( ( !pSession
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync && pStack->Parameters.DeviceIoControl.IoControlCode == SUPDRV_IDC_REQ_CONNECT)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync || ( VALID_PTR(pSession)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync && pSession->pDevExt == pDevExt))
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
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 {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Do the job.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = supdrvIDC(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (!rc)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rcNt = STATUS_SUCCESS;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync cbOut = pHdr->cb;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rcNt = STATUS_INVALID_PARAMETER;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf2(("VBoxDrvNtInternalDeviceControl: returns %#x/rc=%#x\n", rcNt, rc));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtInternalDeviceControl: Mismatching sizes (%#x) - Hdr=%#lx Irp=%#lx/%#lx!\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.IoControlCode,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cb : 0,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.InputBufferLength,
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.OutputBufferLength));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rcNt = STATUS_INVALID_PARAMETER;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rcNt = STATUS_NOT_SUPPORTED;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxDrvNtInternalDeviceControl: not buffered request (%#x) - not supported\n",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pStack->Parameters.DeviceIoControl.IoControlCode));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rcNt = STATUS_NOT_SUPPORTED;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* complete the request. */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync pIrp->IoStatus.Status = rcNt;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync pIrp->IoStatus.Information = cbOut;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return rcNt;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/**
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * Stub function for functions we don't implemented.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns STATUS_NOT_SUPPORTED
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pDevObj Device object.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * @param pIrp IRP.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsyncNTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp)
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync{
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync dprintf(("VBoxDrvNtNotSupportedStub\n"));
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync pDevObj = pDevObj;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync pIrp->IoStatus.Information = 0;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync pIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync return STATUS_NOT_SUPPORTED;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync}
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * ExRegisterCallback handler for power events
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pCallbackContext User supplied parameter (pDevObj)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pArgument1 First argument
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param pArgument2 Second argument
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncVOID _stdcall VBoxPowerDispatchCallback(PVOID pCallbackContext, PVOID pArgument1, PVOID pArgument2)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PDEVICE_OBJECT pDevObj = (PDEVICE_OBJECT)pCallbackContext;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxPowerDispatchCallback: %x %x\n", pArgument1, pArgument2));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Power change imminent? */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ((unsigned)pArgument1 == PO_CB_SYSTEM_STATE_LOCK)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ((unsigned)pArgument2 == 0)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxPowerDispatchCallback: about to go into suspend mode!\n"));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync dprintf(("VBoxPowerDispatchCallback: resumed!\n"));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Inform any clients that have registered themselves with IPRT. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync UNWIND_WRAP(RTPowerSignalEvent)(((unsigned)pArgument2 == 0) ? RTPOWEREVENT_SUSPEND : RTPOWEREVENT_RESUME);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Initializes any OS specific object creator fields.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncvoid VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NOREF(pObj);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NOREF(pSession);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Checks if the session can access the object.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns true if a decision has been made.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @returns false if the default access policy should be applied.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync *
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.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncbool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NOREF(pObj);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NOREF(pSession);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NOREF(pszObjName);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NOREF(prc);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/**
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Force async tsc mode (stub).
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncbool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync}
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#define MY_SystemLoadGdiDriverInSystemSpaceInformation 54
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#define MY_SystemUnloadGdiDriverInformation 27
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsynctypedef struct MYSYSTEMGDIDRIVERINFO
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync{
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync UNICODE_STRING Name; /**< In: image file name. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PVOID ImageAddress; /**< Out: the load address. */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync PVOID SectionPointer; /**< Out: section object. */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync PVOID EntryPointer; /**< Out: entry point address. */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync PVOID ExportSectionPointer; /**< Out: export directory/section. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ULONG ImageLength; /**< Out: SizeOfImage. */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync} MYSYSTEMGDIDRIVERINFO;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncextern "C" __declspec(dllimport) NTSTATUS NTAPI ZwSetSystemInformation(ULONG, PVOID, ULONG);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncint VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync{
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#ifdef VBOX_WITHOUT_NATIVE_R0_LOADER
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NOREF(pDevExt); NOREF(pszFilename); NOREF(pImage);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return VERR_NOT_SUPPORTED;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Convert the filename from DOS UTF-8 to NT UTF-16.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync size_t cwcFilename;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync int rc = RTStrCalcUtf16LenEx(pszFilename, RTSTR_MAX, &cwcFilename);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (RT_FAILURE(rc))
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return rc;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PRTUTF16 pwcsFilename = (PRTUTF16)RTMemTmpAlloc((4 + cwcFilename + 1) * sizeof(RTUTF16));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (!pwcsFilename)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return VERR_NO_TMP_MEMORY;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pwcsFilename[0] = '\\';
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pwcsFilename[1] = '?';
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pwcsFilename[2] = '?';
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pwcsFilename[3] = '\\';
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync PRTUTF16 pwcsTmp = &pwcsFilename[4];
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = RTStrToUtf16Ex(pszFilename, RTSTR_MAX, &pwcsTmp, cwcFilename + 1, NULL);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (RT_SUCCESS(rc))
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Try load it.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync MYSYSTEMGDIDRIVERINFO Info;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync RtlInitUnicodeString(&Info.Name, pwcsFilename);
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync Info.ImageAddress = NULL;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync Info.SectionPointer = NULL;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync Info.EntryPointer = NULL;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync Info.ExportSectionPointer = NULL;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync Info.ImageLength = 0;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync NTSTATUS rcNt = ZwSetSystemInformation(MY_SystemLoadGdiDriverInSystemSpaceInformation, &Info, sizeof(Info));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (NT_SUCCESS(rcNt))
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pImage->pvImage = Info.ImageAddress;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pImage->pvNtSectionObj = Info.SectionPointer;
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));
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync# ifdef DEBUG_bird
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# endif
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if (pImage->cbImageBits == Info.ImageLength)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** @todo do we need to lock down the image? */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = VINF_SUCCESS;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync supdrvOSLdrUnload(pDevExt, pImage);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = VERR_LDR_MISMATCH_NATIVE;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync }
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync Log(("rcNt=%#x '%ws'\n", rcNt, pwcsFilename));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync SUPR0Printf("VBoxDrv: rcNt=%#x '%ws'\n", rcNt, pwcsFilename);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync switch (rcNt)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync {
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync case /* 0xc0000003 */ STATUS_INVALID_INFO_CLASS:
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /*
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 *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Note! Using the 64-bit wrappers will require hacking the
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * image verfication in supdrvOSLdrLoad.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync# if !defined(RT_ARCH_AMD64) || defined(RT_WITH_W64_UNWIND_HACK)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = VERR_NOT_SUPPORTED;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync# else
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync rc = VERR_NOT_IMPLEMENTED;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync# endif
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync break;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync case /* 0xc0000034 */ STATUS_OBJECT_NAME_NOT_FOUND:
rc = VERR_MODULE_NOT_FOUND;
break;
case /* 0xC0000263 */ STATUS_DRIVER_ENTRYPOINT_NOT_FOUND:
rc = VERR_LDR_IMPORTED_SYMBOL_NOT_FOUND;
break;
default:
rc = VERR_LDR_GENERAL_FAILURE;
break;
}
pImage->pvNtSectionObj = NULL;
}
}
RTMemTmpFree(pwcsFilename);
NOREF(pDevExt);
return rc;
#endif
}
int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, const uint8_t *pbImageBits)
{
NOREF(pDevExt); NOREF(pImage); NOREF(pv); NOREF(pbImageBits);
return VINF_SUCCESS;
}
int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits)
{
NOREF(pDevExt); NOREF(pImage); NOREF(pbImageBits);
if (pImage->pvNtSectionObj)
{
if (!memcmp(pImage->pvImage, pbImageBits, pImage->cbImageBits))
return VINF_SUCCESS;
/* trac down the difference and log it. */
uint32_t cbLeft = pImage->cbImageBits;
const uint8_t *pbNativeBits = (const uint8_t *)pImage->pvImage;
for (size_t off = 0; cbLeft > 0; off++, cbLeft--)
if (pbNativeBits[off] != pbImageBits[off])
{
char szBytes[128];
RTStrPrintf(szBytes, sizeof(szBytes), "native: %.*Rhxs our: %.*Rhxs",
RT_MIN(12, cbLeft), &pbNativeBits[off],
RT_MIN(12, cbLeft), &pbImageBits[off]);
SUPR0Printf("VBoxDrv: Mismatch at %#x of %s: %s\n", off, pImage->szName, szBytes);
return VERR_LDR_MISMATCH_NATIVE;
}
}
return VERR_INTERNAL_ERROR_4;
}
void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
{
if (pImage->pvNtSectionObj)
{
NTSTATUS rc = ZwSetSystemInformation(MY_SystemUnloadGdiDriverInformation,
&pImage->pvNtSectionObj, sizeof(pImage->pvNtSectionObj));
}
NOREF(pDevExt);
}
/**
* Converts a supdrv error code to an nt status code.
*
* @returns corresponding nt status code.
* @param rc supdrv error code (SUPDRV_ERR_* defines).
*/
static NTSTATUS VBoxDrvNtErr2NtStatus(int rc)
{
switch (rc)
{
case 0: return STATUS_SUCCESS;
case SUPDRV_ERR_GENERAL_FAILURE: return STATUS_NOT_SUPPORTED;
case SUPDRV_ERR_INVALID_PARAM: return STATUS_INVALID_PARAMETER;
case SUPDRV_ERR_INVALID_MAGIC: return STATUS_UNKNOWN_REVISION;
case SUPDRV_ERR_INVALID_HANDLE: return STATUS_INVALID_HANDLE;
case SUPDRV_ERR_INVALID_POINTER: return STATUS_INVALID_ADDRESS;
case SUPDRV_ERR_LOCK_FAILED: return STATUS_NOT_LOCKED;
case SUPDRV_ERR_ALREADY_LOADED: return STATUS_IMAGE_ALREADY_LOADED;
case SUPDRV_ERR_PERMISSION_DENIED: return STATUS_ACCESS_DENIED;
case SUPDRV_ERR_VERSION_MISMATCH: return STATUS_REVISION_MISMATCH;
}
return STATUS_UNSUCCESSFUL;
}
/** @todo use the nocrt stuff? */
int VBOXCALL mymemcmp(const void *pv1, const void *pv2, size_t cb)
{
const uint8_t *pb1 = (const uint8_t *)pv1;
const uint8_t *pb2 = (const uint8_t *)pv2;
for (; cb > 0; cb--, pb1++, pb2++)
if (*pb1 != *pb2)
return *pb1 - *pb2;
return 0;
}
#if 0 /* See alternative in SUPDrvA-win.asm */
/**
* Alternative version of SUPR0Printf for Windows.
*
* @returns 0.
* @param pszFormat The format string.
*/
SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...)
{
va_list va;
char szMsg[512];
va_start(va, pszFormat);
size_t cch = RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
szMsg[sizeof(szMsg) - 1] = '\0';
va_end(va);
RTLogWriteDebugger(szMsg, cch);
return 0;
}
#endif