VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/win/SUPR0IdcClient-win.c@ 55747

Last change on this file since 55747 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/* $Id: SUPR0IdcClient-win.c 44529 2013-02-04 15:54:15Z vboxsync $ */
2/** @file
3 * VirtualBox Support Driver - IDC Client Lib, Windows Specific Code.
4 */
5
6/*
7 * Copyright (C) 2008-2011 Oracle Corporation
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
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include "../SUPR0IdcClientInternal.h"
31#include <VBox/err.h>
32
33
34/*******************************************************************************
35* Defined Constants And Macros *
36*******************************************************************************/
37/** NT Device name. */
38#define DEVICE_NAME_NT L"\\Device\\VBoxDrv"
39
40
41/**
42 * Internal I/O Control call worker.
43 *
44 * @returns VBox status code.
45 * @param pDeviceObject The device object to call.
46 * @param pFileObject The file object for the connection.
47 * @param uReq The request.
48 * @param pReq The request packet.
49 */
50static int supR0IdcNtCallInternal(PDEVICE_OBJECT pDeviceObject, PFILE_OBJECT pFileObject, uint32_t uReq, PSUPDRVIDCREQHDR pReq)
51{
52 int rc;
53 IO_STATUS_BLOCK IoStatusBlock;
54 KEVENT Event;
55 PIRP pIrp;
56 NTSTATUS rcNt;
57
58 /*
59 * Build the request.
60 */
61 KeInitializeEvent(&Event, NotificationEvent, FALSE);
62 pIrp = IoBuildDeviceIoControlRequest(uReq, /* IoControlCode */
63 pDeviceObject,
64 pReq, /* InputBuffer */
65 pReq->cb, /* InputBufferLength */
66 pReq, /* OutputBuffer */
67 pReq->cb, /* OutputBufferLength */
68 TRUE, /* InternalDeviceIoControl (=> IRP_MJ_INTERNAL_DEVICE_CONTROL) */
69 &Event, /* Event */
70 &IoStatusBlock); /* IoStatusBlock */
71 if (pIrp)
72 {
73 IoGetNextIrpStackLocation(pIrp)->FileObject = pFileObject;
74
75 /*
76 * Call the driver, wait for an async request to complete (should never happen).
77 */
78 rcNt = IoCallDriver(pDeviceObject, pIrp);
79 if (rcNt == STATUS_PENDING)
80 {
81 rcNt = KeWaitForSingleObject(&Event, /* Object */
82 Executive, /* WaitReason */
83 KernelMode, /* WaitMode */
84 FALSE, /* Alertable */
85 NULL); /* TimeOut */
86 rcNt = IoStatusBlock.Status;
87 }
88 if (NT_SUCCESS(rcNt))
89 rc = pReq->rc;
90 else
91 rc = RTErrConvertFromNtStatus(rcNt);
92 }
93 else
94 rc = VERR_NO_MEMORY;
95 return rc;
96}
97
98
99int VBOXCALL supR0IdcNativeOpen(PSUPDRVIDCHANDLE pHandle, PSUPDRVIDCREQCONNECT pReq)
100{
101 PDEVICE_OBJECT pDeviceObject = NULL;
102 PFILE_OBJECT pFileObject = NULL;
103 UNICODE_STRING wszDeviceName;
104 NTSTATUS rcNt;
105 int rc;
106
107 /*
108 * Get the device object pointer.
109 */
110 RtlInitUnicodeString(&wszDeviceName, DEVICE_NAME_NT);
111 rcNt = IoGetDeviceObjectPointer(&wszDeviceName, FILE_ALL_ACCESS, &pFileObject, &pDeviceObject);
112 if (NT_SUCCESS(rcNt))
113 {
114 /*
115 * Make the connection call.
116 */
117 rc = supR0IdcNtCallInternal(pDeviceObject, pFileObject, SUPDRV_IDC_REQ_CONNECT, &pReq->Hdr);
118 if (RT_SUCCESS(rc))
119 {
120 pHandle->s.pDeviceObject = pDeviceObject;
121 pHandle->s.pFileObject = pFileObject;
122 return rc;
123 }
124
125 /* only the file object. */
126 ObDereferenceObject(pFileObject);
127 }
128 else
129 rc = RTErrConvertFromNtStatus(rcNt);
130
131 pHandle->s.pDeviceObject = NULL;
132 pHandle->s.pFileObject = NULL;
133 return rc;
134}
135
136
137int VBOXCALL supR0IdcNativeClose(PSUPDRVIDCHANDLE pHandle, PSUPDRVIDCREQHDR pReq)
138{
139 PFILE_OBJECT pFileObject = pHandle->s.pFileObject;
140 int rc = supR0IdcNtCallInternal(pHandle->s.pDeviceObject, pFileObject, SUPDRV_IDC_REQ_DISCONNECT, pReq);
141 if (RT_SUCCESS(rc))
142 {
143 pHandle->s.pDeviceObject = NULL;
144 pHandle->s.pFileObject = NULL;
145 ObDereferenceObject(pFileObject);
146 }
147
148 return rc;
149}
150
151
152int VBOXCALL supR0IdcNativeCall(PSUPDRVIDCHANDLE pHandle, uint32_t uReq, PSUPDRVIDCREQHDR pReq)
153{
154 return supR0IdcNtCallInternal(pHandle->s.pDeviceObject, pHandle->s.pFileObject, uReq, pReq);
155}
156
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette