SUPDrv-win.cpp revision 8f50537150bbf274d26335ff88bbe36d0e8358f6
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/* $Id$ */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** @file
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VBoxDrv - The VirtualBox Support Driver - Windows NT specifics.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * available from http://www.virtualbox.org. This file is free software;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * you can redistribute it and/or modify it under the terms of the GNU
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * General Public License (GPL) as published by the Free Software
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * The contents of this file may alternatively be used under the terms
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * of the Common Development and Distribution License Version 1.0
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * VirtualBox OSE distribution, in which case the provisions of the
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * CDDL are applicable instead of those of the GPL.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * You may elect to license modified versions of this file under the
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * terms and conditions of either the GPL or the CDDL or both.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * additional information or have any questions.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Header Files *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#define LOG_GROUP LOG_GROUP_SUP_DRV
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include "../SUPDrvInternal.h"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <excpt.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <iprt/assert.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <iprt/process.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <iprt/initterm.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#include <VBox/log.h>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Defined Constants And Macros *
881b5ff6bc55e1fb0f4ef42f9782ccec79c0a138vboxsync*******************************************************************************/
881b5ff6bc55e1fb0f4ef42f9782ccec79c0a138vboxsync/** The support service name. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#define SERVICE_NAME "VBoxDrv"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** Win32 Device name. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#define DEVICE_NAME "\\\\.\\VBoxDrv"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** NT Device name. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#define DEVICE_NAME_NT L"\\Device\\VBoxDrv"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** Win Symlink name. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#define DEVICE_NAME_DOS L"\\DosDevices\\VBoxDrv"
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** The Pool tag (VBox). */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#define SUPDRV_NT_POOL_TAG 'xoBV'
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Structures and Typedefs *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#if 0 //def RT_ARCH_AMD64
9621896680fea9b2078823e8ef2e64cec5bf2da0vboxsynctypedef struct SUPDRVEXECMEM
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PMDL pMdl;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync void *pvMapping;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync void *pvAllocation;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync} SUPDRVEXECMEM, *PSUPDRVEXECMEM;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#endif
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Internal Functions *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic NTSTATUS VBoxDrvNtErr2NtStatus(int rc);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Exported Functions *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync__BEGIN_DECLS
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync__END_DECLS
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/**
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Driver entry point.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @returns appropriate status code.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pDrvObj Pointer to driver object.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pRegPath Registry base path.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync NTSTATUS rc;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("VBoxDrv::DriverEntry\n"));
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Create device.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * (That means creating a device object and a symbolic link so the DOS
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync * subsystems (OS/2, win32, ++) can access the device.)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync UNICODE_STRING DevName;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RtlInitUnicodeString(&DevName, DEVICE_NAME_NT);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PDEVICE_OBJECT pDevObj;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rc = IoCreateDevice(pDrvObj, sizeof(SUPDRVDEVEXT), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDevObj);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (NT_SUCCESS(rc))
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
3f1eb07aba9eee6394f3084c956149ee9a27df09vboxsync UNICODE_STRING DosName;
3f1eb07aba9eee6394f3084c956149ee9a27df09vboxsync RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS);
3f1eb07aba9eee6394f3084c956149ee9a27df09vboxsync rc = IoCreateSymbolicLink(&DosName, &DevName);
3f1eb07aba9eee6394f3084c956149ee9a27df09vboxsync if (NT_SUCCESS(rc))
3f1eb07aba9eee6394f3084c956149ee9a27df09vboxsync {
3f1eb07aba9eee6394f3084c956149ee9a27df09vboxsync int vrc = RTR0Init(0);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (RT_SUCCESS(rc))
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Initialize the device extension.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync memset(pDevExt, 0, sizeof(*pDevExt));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync vrc = supdrvInitDevExt(pDevExt);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (!vrc)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Setup the driver entry points in pDrvObj.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pDrvObj->DriverUnload = VBoxDrvNtUnload;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pDrvObj->MajorFunction[IRP_MJ_CREATE] = VBoxDrvNtCreate;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pDrvObj->MajorFunction[IRP_MJ_CLOSE] = VBoxDrvNtClose;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pDrvObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VBoxDrvNtDeviceControl;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync//#if 0 /** @todo test IDC on windows. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pDrvObj->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = VBoxDrvNtInternalDeviceControl;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync//#endif
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pDrvObj->MajorFunction[IRP_MJ_READ] = VBoxDrvNtNotSupportedStub;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pDrvObj->MajorFunction[IRP_MJ_WRITE] = VBoxDrvNtNotSupportedStub;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /* more? */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("VBoxDrv::DriverEntry returning STATUS_SUCCESS\n"));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return STATUS_SUCCESS;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("supdrvInitDevExit failed with vrc=%d!\n", vrc));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rc = VBoxDrvNtErr2NtStatus(vrc);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync IoDeleteSymbolicLink(&DosName);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RTR0Term();
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync else
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("RTR0Init failed with vrc=%d!\n", vrc));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rc = VBoxDrvNtErr2NtStatus(vrc);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync else
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("IoCreateSymbolicLink failed with rc=%#x!\n", rc));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync IoDeleteDevice(pDevObj);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync else
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("IoCreateDevice failed with rc=%#x!\n", rc));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (NT_SUCCESS(rc))
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rc = STATUS_INVALID_PARAMETER;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("VBoxDrv::DriverEntry returning %#x\n", rc));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return rc;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/**
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Unload the driver.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pDrvObj Driver object.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncvoid _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDrvObj->DeviceObject->DeviceExtension;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("VBoxDrvNtUnload at irql %d\n", KeGetCurrentIrql()));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * We ASSUME that it's not possible to unload a driver with open handles.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Start by deleting the symbolic link
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync UNICODE_STRING DosName;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync NTSTATUS rc = IoDeleteSymbolicLink(&DosName);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Terminate the GIP page and delete the device extension.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync supdrvDeleteDevExt(pDevExt);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync RTR0Term();
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync IoDeleteDevice(pDrvObj->DeviceObject);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/**
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Create (i.e. Open) file entry point.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pDevObj Device object.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pIrp Request packet.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncNTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("VBoxDrvNtCreate\n"));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PFILE_OBJECT pFileObj = pStack->FileObject;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * We are not remotely similar to a directory...
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * (But this is possible.)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (pStack->Parameters.Create.Options & FILE_DIRECTORY_FILE)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pIrp->IoStatus.Status = STATUS_NOT_A_DIRECTORY;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pIrp->IoStatus.Information = 0;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return STATUS_NOT_A_DIRECTORY;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Call common code for the rest.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pFileObj->FsContext = NULL;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PSUPDRVSESSION pSession;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync//#if 0 /** @todo check if this works, consider OBJ_KERNEL_HANDLE too. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync bool fUser = pIrp->RequestorMode != KernelMode;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync//#else
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync // bool fUser = true;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync//#endif
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync int rc = supdrvCreateSession(pDevExt, fUser, &pSession);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (!rc)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pFileObj->FsContext = pSession;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync NTSTATUS rcNt = pIrp->IoStatus.Status = VBoxDrvNtErr2NtStatus(rc);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pIrp->IoStatus.Information = 0;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return rcNt;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/**
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Close file entry point.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pDevObj Device object.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pIrp Request packet.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncNTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PFILE_OBJECT pFileObj = pStack->FileObject;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("VBoxDrvNtClose: pDevExt=%p pFileObj=%p pSession=%p\n",
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pDevExt, pFileObj, pFileObj->FsContext));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pFileObj->FsContext = NULL;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pIrp->IoStatus.Information = 0;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pIrp->IoStatus.Status = STATUS_SUCCESS;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return STATUS_SUCCESS;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/**
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Device I/O Control entry point.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pDevObj Device object.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pIrp Request packet.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncNTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PSUPDRVSESSION pSession = (PSUPDRVSESSION)pStack->FileObject->FsContext;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Deal with the two high-speed IOCtl that takes it's arguments from
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * the session and iCmd, and only returns a VBox status code.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Note: The previous method of returning the rc prior to IOC version
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * 7.4 has been abandond, we're no longer compatible with that
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * interface.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync ULONG ulCmd = pStack->Parameters.DeviceIoControl.IoControlCode;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if ( ulCmd == SUP_IOCTL_FAST_DO_RAW_RUN
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync || ulCmd == SUP_IOCTL_FAST_DO_HWACC_RUN
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync || ulCmd == SUP_IOCTL_FAST_DO_NOP)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /* Raise the IRQL to DISPATCH_LEVEl to prevent Windows from rescheduling us to another CPU/core. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync Assert(KeGetCurrentIrql() <= DISPATCH_LEVEL);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync KIRQL oldIrql;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync KeRaiseIrql(DISPATCH_LEVEL, &oldIrql);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync int rc = supdrvIOCtlFast(ulCmd, pDevExt, pSession);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync KeLowerIrql(oldIrql);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /* Complete the I/O request. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync NTSTATUS rcNt = pIrp->IoStatus.Status = RT_SUCCESS(rc) ? STATUS_SUCCESS : STATUS_INVALID_PARAMETER;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync IoCompleteRequest(pIrp, IO_NO_INCREMENT);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return rcNt;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync return VBoxDrvNtDeviceControlSlow(pDevExt, pSession, pIrp, pStack);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync}
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/**
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Worker for VBoxDrvNtDeviceControl that takes the slow IOCtl functions.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @returns NT status code.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync *
0f77dc54d7ec617480988ccdfcd080f480e79698vboxsync * @param pDevObj Device object.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pSession The session.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pIrp Request packet.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * @param pStack The stack location containing the DeviceControl parameters.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncstatic int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync{
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync NTSTATUS rcNt;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync unsigned cbOut = 0;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync int rc = 0;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf2(("VBoxDrvNtDeviceControlSlow(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#ifdef RT_ARCH_AMD64
0f77dc54d7ec617480988ccdfcd080f480e79698vboxsync /* Don't allow 32-bit processes to do any I/O controls. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (!IoIs32bitProcess(pIrp))
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#endif
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /* Verify that it's a buffered CTL. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /* Verify that the sizes in the request header are correct. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PSUPREQHDR pHdr = (PSUPREQHDR)pIrp->AssociatedIrp.SystemBuffer;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cbIn
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cbOut)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /*
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Do the job.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (!rc)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rcNt = STATUS_SUCCESS;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync cbOut = pHdr->cbOut;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (cbOut > pStack->Parameters.DeviceIoControl.OutputBufferLength)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync OSDBGPRINT(("VBoxDrvLinuxIOCtl: too much output! %#x > %#x; uCmd=%#x!\n",
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pHdr->cbOut, cbOut, pStack->Parameters.DeviceIoControl.IoControlCode));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync else
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync rcNt = STATUS_INVALID_PARAMETER;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf2(("VBoxDrvNtDeviceControlSlow: returns %#x cbOut=%d rc=%#x\n", rcNt, cbOut, rc));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync }
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync else
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync {
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync dprintf(("VBoxDrvNtDeviceControlSlow: Mismatching sizes (%#x) - Hdr=%#lx/%#lx Irp=%#lx/%#lx!\n",
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pStack->Parameters.DeviceIoControl.IoControlCode,
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbIn : 0,
pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbOut : 0,
pStack->Parameters.DeviceIoControl.InputBufferLength,
pStack->Parameters.DeviceIoControl.OutputBufferLength));
rcNt = STATUS_INVALID_PARAMETER;
}
}
else
{
dprintf(("VBoxDrvNtDeviceControlSlow: not buffered request (%#x) - not supported\n",
pStack->Parameters.DeviceIoControl.IoControlCode));
rcNt = STATUS_NOT_SUPPORTED;
}
}
#ifdef RT_ARCH_AMD64
else
{
dprintf(("VBoxDrvNtDeviceControlSlow: WOW64 req - not supported\n"));
rcNt = STATUS_NOT_SUPPORTED;
}
#endif
/* complete the request. */
pIrp->IoStatus.Status = rcNt;
pIrp->IoStatus.Information = cbOut;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return rcNt;
}
/**
* Internal Device I/O Control entry point, used for IDC.
*
* @param pDevObj Device object.
* @param pIrp Request packet.
*/
NTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
PFILE_OBJECT pFileObj = pStack ? pStack->FileObject : NULL;
PSUPDRVSESSION pSession = pFileObj ? (PSUPDRVSESSION)pFileObj->FsContext : NULL;
NTSTATUS rcNt;
unsigned cbOut = 0;
int rc = 0;
dprintf2(("VBoxDrvNtInternalDeviceControl(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
/** @todo IDC on NT: figure when to create the session and that stuff... */
/* Verify that it's a buffered CTL. */
if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
{
/* Verify the pDevExt in the session. */
if ( ( !pSession
&& pStack->Parameters.DeviceIoControl.IoControlCode == SUPDRV_IDC_REQ_CONNECT)
|| ( VALID_PTR(pSession)
&& pSession->pDevExt == pDevExt))
{
/* Verify that the size in the request header is correct. */
PSUPDRVIDCREQHDR pHdr = (PSUPDRVIDCREQHDR)pIrp->AssociatedIrp.SystemBuffer;
if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
&& pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cb
&& pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cb)
{
/*
* Do the job.
*/
rc = supdrvIDC(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
if (!rc)
{
rcNt = STATUS_SUCCESS;
cbOut = pHdr->cb;
}
else
rcNt = STATUS_INVALID_PARAMETER;
dprintf2(("VBoxDrvNtInternalDeviceControl: returns %#x/rc=%#x\n", rcNt, rc));
}
else
{
dprintf(("VBoxDrvNtInternalDeviceControl: Mismatching sizes (%#x) - Hdr=%#lx Irp=%#lx/%#lx!\n",
pStack->Parameters.DeviceIoControl.IoControlCode,
pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cb : 0,
pStack->Parameters.DeviceIoControl.InputBufferLength,
pStack->Parameters.DeviceIoControl.OutputBufferLength));
rcNt = STATUS_INVALID_PARAMETER;
}
}
else
rcNt = STATUS_NOT_SUPPORTED;
}
else
{
dprintf(("VBoxDrvNtInternalDeviceControl: not buffered request (%#x) - not supported\n",
pStack->Parameters.DeviceIoControl.IoControlCode));
rcNt = STATUS_NOT_SUPPORTED;
}
/* complete the request. */
pIrp->IoStatus.Status = rcNt;
pIrp->IoStatus.Information = cbOut;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return rcNt;
}
/**
* Stub function for functions we don't implemented.
*
* @returns STATUS_NOT_SUPPORTED
* @param pDevObj Device object.
* @param pIrp IRP.
*/
NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp)
{
dprintf(("VBoxDrvNtNotSupportedStub\n"));
pDevObj = pDevObj;
pIrp->IoStatus.Information = 0;
pIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_NOT_SUPPORTED;
}
/**
* Initializes any OS specific object creator fields.
*/
void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
{
NOREF(pObj);
NOREF(pSession);
}
/**
* Checks if the session can access the object.
*
* @returns true if a decision has been made.
* @returns false if the default access policy should be applied.
*
* @param pObj The object in question.
* @param pSession The session wanting to access the object.
* @param pszObjName The object name, can be NULL.
* @param prc Where to store the result when returning true.
*/
bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
{
NOREF(pObj);
NOREF(pSession);
NOREF(pszObjName);
NOREF(prc);
return false;
}
/**
* Force async tsc mode (stub).
*/
bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
{
return false;
}
/**
* 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;
}