VirtualBox

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

Last change on this file since 53402 was 44988, checked in by vboxsync, 12 years ago

VBoxGuest-win*: Reversed the VBOXGUESTDEVEXTWIN and VBOXGUESTDEVEXT relationship, VBOXGUESTDEVEXTWIN now includes VBOXGUESTDEVEXT as member 'Core' (first). (untested)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: VBoxGuest-win-legacy.cpp 44988 2013-03-11 14:34:08Z vboxsync $ */
2/** @file
3 * VBoxGuest-win-legacy - Windows NT4 specifics.
4 */
5
6/*
7 * Copyright (C) 2010-2013 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* Header Files *
20*******************************************************************************/
21#include "VBoxGuest-win.h"
22#include "VBoxGuestInternal.h"
23#include <VBox/err.h>
24#include <VBox/log.h>
25#include <VBox/version.h>
26#include <VBox/VBoxGuestLib.h>
27#include <iprt/string.h>
28
29
30/*******************************************************************************
31* Defined Constants And Macros *
32*******************************************************************************/
33#ifndef PCI_MAX_BUSES
34# define PCI_MAX_BUSES 256
35#endif
36
37
38/*******************************************************************************
39* Internal Functions *
40*******************************************************************************/
41RT_C_DECLS_BEGIN
42static NTSTATUS vbgdNt4FindPciDevice(PULONG pulBusNumber, PPCI_SLOT_NUMBER pSlotNumber);
43RT_C_DECLS_END
44
45#ifdef ALLOC_PRAGMA
46# pragma alloc_text(INIT, vbgdNt4CreateDevice)
47# pragma alloc_text(INIT, vbgdNt4FindPciDevice)
48#endif
49
50
51/**
52 * Legacy helper function to create the device object.
53 *
54 * @returns NT status code.
55 *
56 * @param pDrvObj The driver object.
57 * @param pDevObj Unused. NULL. Dunno why it's here, makes no sense.
58 * @param pRegPath The driver registry path.
59 */
60NTSTATUS vbgdNt4CreateDevice(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath)
61{
62 Log(("VBoxGuest::vbgdNt4CreateDevice: pDrvObj=%p, pDevObj=%p, pRegPath=%p\n", pDrvObj, pDevObj, pRegPath));
63
64 /*
65 * Find our virtual PCI device
66 */
67 ULONG uBusNumber;
68 PCI_SLOT_NUMBER SlotNumber;
69 NTSTATUS rc = vbgdNt4FindPciDevice(&uBusNumber, &SlotNumber);
70 if (NT_ERROR(rc))
71 {
72 Log(("VBoxGuest::vbgdNt4CreateDevice: 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(("VBoxGuest::vbgdNt4CreateDevice: 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(("VBoxGuest::vbgdNt4CreateDevice: Symlink created\n"));
93
94 /*
95 * Setup the device extension.
96 */
97 Log(("VBoxGuest::vbgdNt4CreateDevice: Setting up device extension ...\n"));
98
99 PVBOXGUESTDEVEXTWIN pDevExt = (PVBOXGUESTDEVEXTWIN)pDeviceObject->DeviceExtension;
100 RT_ZERO(*pDevExt);
101
102 Log(("VBoxGuest::vbgdNt4CreateDevice: 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 = vbgdNtInit(pDrvObj, pDeviceObject, pRegPath);
119 if (NT_SUCCESS(rc))
120 {
121 Log(("VBoxGuest::vbgdNt4CreateDevice: Returning rc = 0x%x (succcess)\n", rc));
122 return rc;
123 }
124
125 /* bail out */
126 }
127 IoDeleteSymbolicLink(&DosName);
128 }
129 else
130 Log(("VBoxGuest::vbgdNt4CreateDevice: IoCreateSymbolicLink failed with rc = %#x\n", rc));
131 IoDeleteDevice(pDeviceObject);
132 }
133 else
134 Log(("VBoxGuest::vbgdNt4CreateDevice: IoCreateDevice failed with rc = %#x\n", rc));
135 Log(("VBoxGuest::vbgdNt4CreateDevice: 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 vbgdNt4FindPciDevice(PULONG pulBusNumber, PPCI_SLOT_NUMBER pSlotNumber)
149{
150 Log(("VBoxGuest::vbgdNt4FindPciDevice\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(("VBoxGuest::vbgdNt4FindPciDevice: 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.

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