[10258] | 1 | /* $Id: SUPR0IdcClient-win.c 62490 2016-07-22 18:41:49Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VirtualBox Support Driver - IDC Client Lib, Windows Specific Code.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[62490] | 7 | * Copyright (C) 2008-2016 Oracle Corporation
|
---|
[10258] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
| 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 16 | *
|
---|
| 17 | * The contents of this file may alternatively be used under the terms
|
---|
| 18 | * of the Common Development and Distribution License Version 1.0
|
---|
| 19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
| 20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
| 21 | * CDDL are applicable instead of those of the GPL.
|
---|
| 22 | *
|
---|
| 23 | * You may elect to license modified versions of this file under the
|
---|
| 24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
| 25 | */
|
---|
| 26 |
|
---|
[57358] | 27 |
|
---|
| 28 | /*********************************************************************************************************************************
|
---|
| 29 | * Header Files *
|
---|
| 30 | *********************************************************************************************************************************/
|
---|
[10258] | 31 | #include "../SUPR0IdcClientInternal.h"
|
---|
| 32 | #include <VBox/err.h>
|
---|
| 33 |
|
---|
| 34 |
|
---|
[57358] | 35 | /*********************************************************************************************************************************
|
---|
| 36 | * Defined Constants And Macros *
|
---|
| 37 | *********************************************************************************************************************************/
|
---|
[10258] | 38 | /** NT Device name. */
|
---|
| 39 | #define DEVICE_NAME_NT L"\\Device\\VBoxDrv"
|
---|
| 40 |
|
---|
| 41 |
|
---|
[10260] | 42 | /**
|
---|
| 43 | * Internal I/O Control call worker.
|
---|
| 44 | *
|
---|
| 45 | * @returns VBox status code.
|
---|
| 46 | * @param pDeviceObject The device object to call.
|
---|
[10261] | 47 | * @param pFileObject The file object for the connection.
|
---|
[10263] | 48 | * @param uReq The request.
|
---|
[10260] | 49 | * @param pReq The request packet.
|
---|
| 50 | */
|
---|
[10263] | 51 | static int supR0IdcNtCallInternal(PDEVICE_OBJECT pDeviceObject, PFILE_OBJECT pFileObject, uint32_t uReq, PSUPDRVIDCREQHDR pReq)
|
---|
[10258] | 52 | {
|
---|
| 53 | int rc;
|
---|
| 54 | IO_STATUS_BLOCK IoStatusBlock;
|
---|
| 55 | KEVENT Event;
|
---|
| 56 | PIRP pIrp;
|
---|
[10261] | 57 | NTSTATUS rcNt;
|
---|
[10258] | 58 |
|
---|
| 59 | /*
|
---|
| 60 | * Build the request.
|
---|
| 61 | */
|
---|
| 62 | KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
---|
[10263] | 63 | pIrp = IoBuildDeviceIoControlRequest(uReq, /* IoControlCode */
|
---|
[10258] | 64 | pDeviceObject,
|
---|
| 65 | pReq, /* InputBuffer */
|
---|
| 66 | pReq->cb, /* InputBufferLength */
|
---|
| 67 | pReq, /* OutputBuffer */
|
---|
| 68 | pReq->cb, /* OutputBufferLength */
|
---|
| 69 | TRUE, /* InternalDeviceIoControl (=> IRP_MJ_INTERNAL_DEVICE_CONTROL) */
|
---|
| 70 | &Event, /* Event */
|
---|
| 71 | &IoStatusBlock); /* IoStatusBlock */
|
---|
| 72 | if (pIrp)
|
---|
| 73 | {
|
---|
[10261] | 74 | IoGetNextIrpStackLocation(pIrp)->FileObject = pFileObject;
|
---|
| 75 |
|
---|
[10258] | 76 | /*
|
---|
| 77 | * Call the driver, wait for an async request to complete (should never happen).
|
---|
| 78 | */
|
---|
[10261] | 79 | rcNt = IoCallDriver(pDeviceObject, pIrp);
|
---|
[10258] | 80 | if (rcNt == STATUS_PENDING)
|
---|
| 81 | {
|
---|
| 82 | rcNt = KeWaitForSingleObject(&Event, /* Object */
|
---|
| 83 | Executive, /* WaitReason */
|
---|
| 84 | KernelMode, /* WaitMode */
|
---|
[33540] | 85 | FALSE, /* Alertable */
|
---|
[10258] | 86 | NULL); /* TimeOut */
|
---|
| 87 | rcNt = IoStatusBlock.Status;
|
---|
| 88 | }
|
---|
| 89 | if (NT_SUCCESS(rcNt))
|
---|
| 90 | rc = pReq->rc;
|
---|
| 91 | else
|
---|
| 92 | rc = RTErrConvertFromNtStatus(rcNt);
|
---|
| 93 | }
|
---|
| 94 | else
|
---|
| 95 | rc = VERR_NO_MEMORY;
|
---|
| 96 | return rc;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[10263] | 99 |
|
---|
[10258] | 100 | int VBOXCALL supR0IdcNativeOpen(PSUPDRVIDCHANDLE pHandle, PSUPDRVIDCREQCONNECT pReq)
|
---|
| 101 | {
|
---|
| 102 | PDEVICE_OBJECT pDeviceObject = NULL;
|
---|
| 103 | PFILE_OBJECT pFileObject = NULL;
|
---|
| 104 | UNICODE_STRING wszDeviceName;
|
---|
| 105 | NTSTATUS rcNt;
|
---|
| 106 | int rc;
|
---|
| 107 |
|
---|
| 108 | /*
|
---|
| 109 | * Get the device object pointer.
|
---|
| 110 | */
|
---|
| 111 | RtlInitUnicodeString(&wszDeviceName, DEVICE_NAME_NT);
|
---|
| 112 | rcNt = IoGetDeviceObjectPointer(&wszDeviceName, FILE_ALL_ACCESS, &pFileObject, &pDeviceObject);
|
---|
| 113 | if (NT_SUCCESS(rcNt))
|
---|
| 114 | {
|
---|
| 115 | /*
|
---|
| 116 | * Make the connection call.
|
---|
| 117 | */
|
---|
[10261] | 118 | rc = supR0IdcNtCallInternal(pDeviceObject, pFileObject, SUPDRV_IDC_REQ_CONNECT, &pReq->Hdr);
|
---|
[10258] | 119 | if (RT_SUCCESS(rc))
|
---|
| 120 | {
|
---|
| 121 | pHandle->s.pDeviceObject = pDeviceObject;
|
---|
[38321] | 122 | pHandle->s.pFileObject = pFileObject;
|
---|
[10258] | 123 | return rc;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | /* only the file object. */
|
---|
| 127 | ObDereferenceObject(pFileObject);
|
---|
| 128 | }
|
---|
| 129 | else
|
---|
| 130 | rc = RTErrConvertFromNtStatus(rcNt);
|
---|
| 131 |
|
---|
| 132 | pHandle->s.pDeviceObject = NULL;
|
---|
| 133 | pHandle->s.pFileObject = NULL;
|
---|
| 134 | return rc;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | int VBOXCALL supR0IdcNativeClose(PSUPDRVIDCHANDLE pHandle, PSUPDRVIDCREQHDR pReq)
|
---|
| 139 | {
|
---|
[10261] | 140 | PFILE_OBJECT pFileObject = pHandle->s.pFileObject;
|
---|
| 141 | int rc = supR0IdcNtCallInternal(pHandle->s.pDeviceObject, pFileObject, SUPDRV_IDC_REQ_DISCONNECT, pReq);
|
---|
[10258] | 142 | if (RT_SUCCESS(rc))
|
---|
| 143 | {
|
---|
| 144 | pHandle->s.pDeviceObject = NULL;
|
---|
| 145 | pHandle->s.pFileObject = NULL;
|
---|
| 146 | ObDereferenceObject(pFileObject);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | return rc;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 |
|
---|
[10263] | 153 | int VBOXCALL supR0IdcNativeCall(PSUPDRVIDCHANDLE pHandle, uint32_t uReq, PSUPDRVIDCREQHDR pReq)
|
---|
[10258] | 154 | {
|
---|
[10263] | 155 | return supR0IdcNtCallInternal(pHandle->s.pDeviceObject, pHandle->s.pFileObject, uReq, pReq);
|
---|
[10258] | 156 | }
|
---|
| 157 |
|
---|