VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win-legacy.cpp@ 63206

Last change on this file since 63206 was 63125, checked in by vboxsync, 8 years ago

fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1/* $Id: VBoxGuest-win-legacy.cpp 63125 2016-08-07 03:44:00Z vboxsync $ */
2/** @file
3 * VBoxGuest-win-legacy - Windows NT4 specifics.
4 */
5
6/*
7 * Copyright (C) 2010-2016 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
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include "VBoxGuest-win.h"
23#include "VBoxGuestInternal.h"
24#include <VBox/err.h>
25#include <VBox/log.h>
26#include <VBox/version.h>
27#include <VBox/VBoxGuestLib.h>
28#include <iprt/string.h>
29
30
31/*********************************************************************************************************************************
32* Defined Constants And Macros *
33*********************************************************************************************************************************/
34#ifndef PCI_MAX_BUSES
35# define PCI_MAX_BUSES 256
36#endif
37
38
39/*********************************************************************************************************************************
40* Internal Functions *
41*********************************************************************************************************************************/
42RT_C_DECLS_BEGIN
43static NTSTATUS vgdrvNt4FindPciDevice(PULONG pulBusNumber, PPCI_SLOT_NUMBER pSlotNumber);
44RT_C_DECLS_END
45
46#ifdef ALLOC_PRAGMA
47# pragma alloc_text(INIT, vgdrvNt4CreateDevice)
48# pragma alloc_text(INIT, vgdrvNt4FindPciDevice)
49#endif
50
51
52/**
53 * Legacy helper function to create the device object.
54 *
55 * @returns NT status code.
56 *
57 * @param pDrvObj The driver object.
58 * @param pRegPath The driver registry path.
59 */
60NTSTATUS vgdrvNt4CreateDevice(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath)
61{
62 Log(("vgdrvNt4CreateDevice: pDrvObj=%p, pRegPath=%p\n", pDrvObj, pRegPath));
63
64 /*
65 * Find our virtual PCI device
66 */
67 ULONG uBusNumber;
68 PCI_SLOT_NUMBER SlotNumber;
69 NTSTATUS rc = vgdrvNt4FindPciDevice(&uBusNumber, &SlotNumber);
70 if (NT_ERROR(rc))
71 {
72 Log(("vgdrvNt4CreateDevice: Device not found!\n"));
73 return rc;
74 }
75
76 /*
77 * Create device.
78 */
79 UNICODE_STRING szDevName;
80 RtlInitUnicodeString(&szDevName, VBOXGUEST_DEVICE_NAME_NT);
81 PDEVICE_OBJECT pDeviceObject = NULL;
82 rc = IoCreateDevice(pDrvObj, sizeof(VBOXGUESTDEVEXTWIN), &szDevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDeviceObject);
83 if (NT_SUCCESS(rc))
84 {
85 Log(("vgdrvNt4CreateDevice: Device created\n"));
86
87 UNICODE_STRING DosName;
88 RtlInitUnicodeString(&DosName, VBOXGUEST_DEVICE_NAME_DOS);
89 rc = IoCreateSymbolicLink(&DosName, &szDevName);
90 if (NT_SUCCESS(rc))
91 {
92 Log(("vgdrvNt4CreateDevice: Symlink created\n"));
93
94 /*
95 * Setup the device extension.
96 */
97 Log(("vgdrvNt4CreateDevice: Setting up device extension ...\n"));
98
99 PVBOXGUESTDEVEXTWIN pDevExt = (PVBOXGUESTDEVEXTWIN)pDeviceObject->DeviceExtension;
100 RT_ZERO(*pDevExt);
101
102 Log(("vgdrvNt4CreateDevice: Device extension created\n"));
103
104 /* Store a reference to ourself. */
105 pDevExt->pDeviceObject = pDeviceObject;
106
107 /* Store bus and slot number we've queried before. */
108 pDevExt->busNumber = uBusNumber;
109 pDevExt->slotNumber = SlotNumber.u.AsULONG;
110
111#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
112 rc = hlpRegisterBugCheckCallback(pDevExt);
113#endif
114
115 /* Do the actual VBox init ... */
116 if (NT_SUCCESS(rc))
117 {
118 rc = vgdrvNtInit(pDrvObj, pDeviceObject, pRegPath);
119 if (NT_SUCCESS(rc))
120 {
121 Log(("vgdrvNt4CreateDevice: Returning rc = 0x%x (succcess)\n", rc));
122 return rc;
123 }
124
125 /* bail out */
126 }
127 IoDeleteSymbolicLink(&DosName);
128 }
129 else
130 Log(("vgdrvNt4CreateDevice: IoCreateSymbolicLink failed with rc = %#x\n", rc));
131 IoDeleteDevice(pDeviceObject);
132 }
133 else
134 Log(("vgdrvNt4CreateDevice: IoCreateDevice failed with rc = %#x\n", rc));
135 Log(("vgdrvNt4CreateDevice: Returning rc = 0x%x\n", rc));
136 return rc;
137}
138
139
140/**
141 * Helper function to handle the PCI device lookup.
142 *
143 * @returns NT status code.
144 *
145 * @param pulBusNumber Where to return the bus number on success.
146 * @param pSlotNumber Where to return the slot number on success.
147 */
148static NTSTATUS vgdrvNt4FindPciDevice(PULONG pulBusNumber, PPCI_SLOT_NUMBER pSlotNumber)
149{
150 Log(("vgdrvNt4FindPciDevice\n"));
151
152 PCI_SLOT_NUMBER SlotNumber;
153 SlotNumber.u.AsULONG = 0;
154
155 /* Scan each bus. */
156 for (ULONG ulBusNumber = 0; ulBusNumber < PCI_MAX_BUSES; ulBusNumber++)
157 {
158 /* Scan each device. */
159 for (ULONG deviceNumber = 0; deviceNumber < PCI_MAX_DEVICES; deviceNumber++)
160 {
161 SlotNumber.u.bits.DeviceNumber = deviceNumber;
162
163 /* Scan each function (not really required...). */
164 for (ULONG functionNumber = 0; functionNumber < PCI_MAX_FUNCTION; functionNumber++)
165 {
166 SlotNumber.u.bits.FunctionNumber = functionNumber;
167
168 /* Have a look at what's in this slot. */
169 PCI_COMMON_CONFIG PciData;
170 if (!HalGetBusData(PCIConfiguration, ulBusNumber, SlotNumber.u.AsULONG, &PciData, sizeof(ULONG)))
171 {
172 /* No such bus, we're done with it. */
173 deviceNumber = PCI_MAX_DEVICES;
174 break;
175 }
176
177 if (PciData.VendorID == PCI_INVALID_VENDORID)
178 /* We have to proceed to the next function. */
179 continue;
180
181 /* Check if it's another device. */
182 if ( PciData.VendorID != VMMDEV_VENDORID
183 || PciData.DeviceID != VMMDEV_DEVICEID)
184 continue;
185
186 /* Hooray, we've found it! */
187 Log(("vgdrvNt4FindPciDevice: Device found!\n"));
188
189 *pulBusNumber = ulBusNumber;
190 *pSlotNumber = SlotNumber;
191 return STATUS_SUCCESS;
192 }
193 }
194 }
195
196 return STATUS_DEVICE_DOES_NOT_EXIST;
197}
198
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use