1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxGuest -- VirtualBox Win32 guest support driver
|
---|
4 | *
|
---|
5 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
6 | *
|
---|
7 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | * available from http://www.virtualbox.org. This file is free software;
|
---|
9 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | * General Public License as published by the Free Software Foundation,
|
---|
11 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
12 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
13 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | */
|
---|
15 |
|
---|
16 | #ifndef __VBOXGUESTINTERNAL_h__
|
---|
17 | #define __VBOXGUESTINTERNAL_h__
|
---|
18 |
|
---|
19 |
|
---|
20 | /*******************************************************************************
|
---|
21 | * Header Files *
|
---|
22 | *******************************************************************************/
|
---|
23 |
|
---|
24 | #include <iprt/cdefs.h>
|
---|
25 |
|
---|
26 | #ifdef IN_RING0
|
---|
27 | # if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
28 | # include <iprt/asm.h>
|
---|
29 | # define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
|
---|
30 | # define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
|
---|
31 | # define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
|
---|
32 | # define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
|
---|
33 | __BEGIN_DECLS
|
---|
34 | # include <ntddk.h>
|
---|
35 | __END_DECLS
|
---|
36 | # undef _InterlockedExchange
|
---|
37 | # undef _InterlockedExchangeAdd
|
---|
38 | # undef _InterlockedCompareExchange
|
---|
39 | # undef _InterlockedAddLargeStatistic
|
---|
40 | # else
|
---|
41 | __BEGIN_DECLS
|
---|
42 | # include <ntddk.h>
|
---|
43 | __END_DECLS
|
---|
44 | # endif
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #include <VBox/VBoxGuest.h>
|
---|
48 |
|
---|
49 | /*******************************************************************************
|
---|
50 | * Defined Constants And Macros *
|
---|
51 | *******************************************************************************/
|
---|
52 |
|
---|
53 |
|
---|
54 | /* debug printf */
|
---|
55 | # define OSDBGPRINT(a) DbgPrint a
|
---|
56 |
|
---|
57 | /* dprintf */
|
---|
58 | #if (defined(DEBUG) && !defined(NO_LOGGING)) || defined(LOG_ENABLED)
|
---|
59 | # ifdef LOG_TO_BACKDOOR
|
---|
60 | # include <VBox/log.h>
|
---|
61 | # define dprintf(a) RTLogBackdoorPrintf a
|
---|
62 | # else
|
---|
63 | # define dprintf(a) OSDBGPRINT(a)
|
---|
64 | # endif
|
---|
65 | #else
|
---|
66 | # define dprintf(a) do {} while (0)
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | /* dprintf2 - extended logging. */
|
---|
70 | #if 0
|
---|
71 | # define dprintf2 dprintf
|
---|
72 | #else
|
---|
73 | # define dprintf2(a) do { } while (0)
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | // the maximum scatter/gather transfer length
|
---|
77 | #define MAXIMUM_TRANSFER_LENGTH 64*1024
|
---|
78 |
|
---|
79 | #define PCI_MAX_BUSES 256
|
---|
80 |
|
---|
81 | /*
|
---|
82 | * Error codes.
|
---|
83 | */
|
---|
84 |
|
---|
85 |
|
---|
86 | /*******************************************************************************
|
---|
87 | * Structures and Typedefs *
|
---|
88 | *******************************************************************************/
|
---|
89 |
|
---|
90 | // possible device states for our state machine
|
---|
91 | enum DEVSTATE
|
---|
92 | {
|
---|
93 | STOPPED,
|
---|
94 | WORKING,
|
---|
95 | PENDINGSTOP,
|
---|
96 | PENDINGREMOVE,
|
---|
97 | SURPRISEREMOVED,
|
---|
98 | REMOVED
|
---|
99 | };
|
---|
100 |
|
---|
101 | // undocumented API to set the system time
|
---|
102 | extern "C"
|
---|
103 | {
|
---|
104 | NTSYSAPI NTSTATUS NTAPI ZwSetSystemTime(IN PLARGE_INTEGER NewTime, OUT PLARGE_INTEGER OldTime OPTIONAL);
|
---|
105 | }
|
---|
106 |
|
---|
107 | #ifdef IN_RING0
|
---|
108 | typedef struct _BASE_ADDRESS {
|
---|
109 |
|
---|
110 | PHYSICAL_ADDRESS RangeStart; // Original device physical address
|
---|
111 | ULONG RangeLength; // Length of I/O or memory range
|
---|
112 | BOOLEAN RangeInMemory; // Flag: unmapped range is I/O or memory range
|
---|
113 |
|
---|
114 | PVOID MappedRangeStart; // Mapped I/O or memory range
|
---|
115 | BOOLEAN MappedRangeInMemory; // Flag: mapped range is I/O or memory range
|
---|
116 |
|
---|
117 | BOOLEAN ResourceMapped; // Flag: resource is mapped (i.e. MmMapIoSpace called)
|
---|
118 |
|
---|
119 | } BASE_ADDRESS, *PBASE_ADDRESS;
|
---|
120 |
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Device extension.
|
---|
124 | */
|
---|
125 | typedef struct VBOXGUESTDEVEXT
|
---|
126 | {
|
---|
127 | //// legacy stuff
|
---|
128 | // bus number where the device is located
|
---|
129 | ULONG busNumber;
|
---|
130 | // slot number where the device is located
|
---|
131 | ULONG slotNumber;
|
---|
132 | // device interrupt level
|
---|
133 | ULONG interruptLevel;
|
---|
134 | // device interrupt vector
|
---|
135 | ULONG interruptVector;
|
---|
136 | // affinity mask
|
---|
137 | KAFFINITY interruptAffinity;
|
---|
138 | // LevelSensitive or Latched
|
---|
139 | KINTERRUPT_MODE interruptMode;
|
---|
140 |
|
---|
141 | // PCI base address information
|
---|
142 | ULONG addressCount;
|
---|
143 | BASE_ADDRESS baseAddress[PCI_TYPE0_ADDRESSES];
|
---|
144 |
|
---|
145 | // adapter object pointer, returned by HalGetAdapter
|
---|
146 | PADAPTER_OBJECT adapterObject;
|
---|
147 |
|
---|
148 | // interrupt object pointer
|
---|
149 | PKINTERRUPT interruptObject;
|
---|
150 | /////
|
---|
151 |
|
---|
152 |
|
---|
153 | // our functional driver object
|
---|
154 | PDEVICE_OBJECT deviceObject;
|
---|
155 | // the top of the stack
|
---|
156 | PDEVICE_OBJECT nextLowerDriver;
|
---|
157 | // currently active Irp
|
---|
158 | IRP *currentIrp;
|
---|
159 | PKTHREAD workerThread;
|
---|
160 | PKTHREAD idleThread;
|
---|
161 | KEVENT workerThreadRequest;
|
---|
162 | BOOLEAN stopThread;
|
---|
163 | // device state
|
---|
164 | DEVSTATE devState;
|
---|
165 | // start port address
|
---|
166 | ULONG startPortAddress;
|
---|
167 | // start of hypervisor mapping
|
---|
168 | PVOID hypervisorMapping;
|
---|
169 | // size in bytes of the hypervisor mapping
|
---|
170 | ULONG hypervisorMappingSize;
|
---|
171 |
|
---|
172 | /* Physical address and length of VMMDev memory */
|
---|
173 | PHYSICAL_ADDRESS memoryAddress;
|
---|
174 | ULONG memoryLength;
|
---|
175 |
|
---|
176 | /* Virtual address of VMMDev memory */
|
---|
177 | VMMDevMemory *pVMMDevMemory;
|
---|
178 |
|
---|
179 | /* Pending event flags signalled by host */
|
---|
180 | ULONG u32Events;
|
---|
181 |
|
---|
182 | /* Notification semaphore */
|
---|
183 | KEVENT keventNotification;
|
---|
184 |
|
---|
185 | /* Old Windows session id */
|
---|
186 | ULONG ulOldActiveConsoleId;
|
---|
187 |
|
---|
188 | /* VRDP hook state */
|
---|
189 | BOOLEAN fVRDPEnabled;
|
---|
190 |
|
---|
191 | /* Preallocated VMMDevEvents for IRQ handler */
|
---|
192 | VMMDevEvents *irqAckEvents;
|
---|
193 |
|
---|
194 |
|
---|
195 | struct
|
---|
196 | {
|
---|
197 | uint32_t cBalloons;
|
---|
198 | uint32_t cMaxBalloons;
|
---|
199 | PMDL *paMdlMemBalloon;
|
---|
200 | } MemBalloon;
|
---|
201 |
|
---|
202 | } VBOXGUESTDEVEXT, *PVBOXGUESTDEVEXT;
|
---|
203 |
|
---|
204 | // Windows version identifier
|
---|
205 | typedef enum
|
---|
206 | {
|
---|
207 | WINNT4 = 1,
|
---|
208 | WIN2K = 2,
|
---|
209 | WINXP = 3,
|
---|
210 | WIN2K3 = 4,
|
---|
211 | WINVISTA = 5
|
---|
212 | } winVersion_t;
|
---|
213 | extern winVersion_t winVersion;
|
---|
214 |
|
---|
215 | extern "C"
|
---|
216 | {
|
---|
217 | VOID VBoxGuestDpcHandler(PKDPC dpc, PDEVICE_OBJECT pDevObj,
|
---|
218 | PIRP irp, PVOID context);
|
---|
219 | BOOLEAN VBoxGuestIsrHandler(PKINTERRUPT interrupt, PVOID serviceContext);
|
---|
220 | NTSTATUS createThreads(PVBOXGUESTDEVEXT pDevExt);
|
---|
221 | VOID unreserveHypervisorMemory(PVBOXGUESTDEVEXT pDevExt);
|
---|
222 | void VBoxInitMemBalloon(PVBOXGUESTDEVEXT pDevExt);
|
---|
223 | void VBoxCleanupMemBalloon(PVBOXGUESTDEVEXT pDevExt);
|
---|
224 | }
|
---|
225 |
|
---|
226 | #endif
|
---|
227 |
|
---|
228 | #endif // __H_VBOXGUESTINTERNAL
|
---|