1 | /* $Id: VBoxGuestR0LibInternal.h 72627 2018-06-20 13:53:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestLibR0 - Internal header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person
|
---|
10 | * obtaining a copy of this software and associated documentation
|
---|
11 | * files (the "Software"), to deal in the Software without
|
---|
12 | * restriction, including without limitation the rights to use,
|
---|
13 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
14 | * copies of the Software, and to permit persons to whom the
|
---|
15 | * Software is furnished to do so, subject to the following
|
---|
16 | * conditions:
|
---|
17 | *
|
---|
18 | * The above copyright notice and this permission notice shall be
|
---|
19 | * included in all copies or substantial portions of the Software.
|
---|
20 | *
|
---|
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
28 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifndef ___VBoxGuestLib_VBoxGuestR0LibInternal_h
|
---|
32 | #define ___VBoxGuestLib_VBoxGuestR0LibInternal_h
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * Define the private IDC handle structure before we include the VBoxGuestLib.h header.
|
---|
36 | */
|
---|
37 | #include <iprt/types.h>
|
---|
38 | #include <iprt/assert.h>
|
---|
39 | RT_C_DECLS_BEGIN
|
---|
40 |
|
---|
41 | # ifndef VBGL_VBOXGUEST
|
---|
42 | /**
|
---|
43 | * The hidden part of VBGLIDCHANDLE.
|
---|
44 | */
|
---|
45 | struct VBGLIDCHANDLEPRIVATE
|
---|
46 | {
|
---|
47 | /** Pointer to the session handle. */
|
---|
48 | void *pvSession;
|
---|
49 | # if defined(RT_OS_WINDOWS) && (defined(___iprt_nt_ntddk_h___) || defined(___iprt_nt_nt_h___))
|
---|
50 | /** Pointer to the NT device object. */
|
---|
51 | PDEVICE_OBJECT pDeviceObject;
|
---|
52 | /** Pointer to the NT file object. */
|
---|
53 | PFILE_OBJECT pFileObject;
|
---|
54 | # elif defined(RT_OS_SOLARIS) && defined(_SYS_SUNLDI_H)
|
---|
55 | /** LDI device handle to keep the device attached. */
|
---|
56 | ldi_handle_t hDev;
|
---|
57 | # endif
|
---|
58 | };
|
---|
59 | /** Indicate that the VBGLIDCHANDLEPRIVATE structure is present. */
|
---|
60 | # define VBGLIDCHANDLEPRIVATE_DECLARED 1
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | #include <VBox/VMMDev.h>
|
---|
64 | #include <VBox/VBoxGuest.h>
|
---|
65 | #include <VBox/VBoxGuestLib.h>
|
---|
66 |
|
---|
67 | #ifdef VBGLIDCHANDLEPRIVATE_DECLARED
|
---|
68 | AssertCompile(RT_SIZEOFMEMB(VBGLIDCHANDLE, apvPadding) >= sizeof(struct VBGLIDCHANDLEPRIVATE));
|
---|
69 | #endif
|
---|
70 |
|
---|
71 |
|
---|
72 | /*
|
---|
73 | * Native IDC functions.
|
---|
74 | */
|
---|
75 | int VBOXCALL vbglR0IdcNativeOpen(PVBGLIDCHANDLE pHandle, PVBGLIOCIDCCONNECT pReq);
|
---|
76 | int VBOXCALL vbglR0IdcNativeClose(PVBGLIDCHANDLE pHandle, PVBGLIOCIDCDISCONNECT pReq);
|
---|
77 |
|
---|
78 |
|
---|
79 | /*
|
---|
80 | * Deprecated logging macro
|
---|
81 | */
|
---|
82 | #include <VBox/log.h>
|
---|
83 | #ifdef RT_OS_WINDOWS /** @todo dprintf() -> Log() */
|
---|
84 | # if (defined(DEBUG) && !defined(NO_LOGGING)) || defined(LOG_ENABLED)
|
---|
85 | # define dprintf(a) RTLogBackdoorPrintf a
|
---|
86 | # else
|
---|
87 | # define dprintf(a) do {} while (0)
|
---|
88 | # endif
|
---|
89 | #else
|
---|
90 | # define dprintf(a) Log(a)
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | /*
|
---|
94 | * Lazy bird: OS/2 doesn't currently implement the RTSemMutex API in ring-0, so
|
---|
95 | * use a fast mutex instead. Unlike Windows, the OS/2 implementation
|
---|
96 | * doesn't have any nasty side effects on IRQL-like context properties, so the
|
---|
97 | * fast mutexes on OS/2 are identical to normal mutexes except for the missing
|
---|
98 | * timeout aspec. Fortunately we don't need timeouts here.
|
---|
99 | */
|
---|
100 | #ifdef RT_OS_OS2
|
---|
101 | # define VBGLDATA_USE_FAST_MUTEX
|
---|
102 | #endif
|
---|
103 |
|
---|
104 | struct _VBGLPHYSHEAPBLOCK;
|
---|
105 | typedef struct _VBGLPHYSHEAPBLOCK VBGLPHYSHEAPBLOCK;
|
---|
106 | struct _VBGLPHYSHEAPCHUNK;
|
---|
107 | typedef struct _VBGLPHYSHEAPCHUNK VBGLPHYSHEAPCHUNK;
|
---|
108 |
|
---|
109 | #ifndef VBGL_VBOXGUEST
|
---|
110 | struct VBGLHGCMHANDLEDATA
|
---|
111 | {
|
---|
112 | uint32_t fAllocated;
|
---|
113 | VBGLIDCHANDLE IdcHandle;
|
---|
114 | };
|
---|
115 | #endif
|
---|
116 |
|
---|
117 | enum VbglLibStatus
|
---|
118 | {
|
---|
119 | VbglStatusNotInitialized = 0,
|
---|
120 | VbglStatusInitializing,
|
---|
121 | VbglStatusReady
|
---|
122 | };
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Global VBGL ring-0 data.
|
---|
126 | * Lives in VbglR0Init.cpp.
|
---|
127 | */
|
---|
128 | typedef struct VBGLDATA
|
---|
129 | {
|
---|
130 | enum VbglLibStatus status;
|
---|
131 |
|
---|
132 | RTIOPORT portVMMDev;
|
---|
133 |
|
---|
134 | VMMDevMemory *pVMMDevMemory;
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Physical memory heap data.
|
---|
138 | * @{
|
---|
139 | */
|
---|
140 |
|
---|
141 | VBGLPHYSHEAPBLOCK *pFreeBlocksHead;
|
---|
142 | VBGLPHYSHEAPBLOCK *pAllocBlocksHead;
|
---|
143 | VBGLPHYSHEAPCHUNK *pChunkHead;
|
---|
144 |
|
---|
145 | RTSEMFASTMUTEX mutexHeap;
|
---|
146 | /** @} */
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * The host version data.
|
---|
150 | */
|
---|
151 | VMMDevReqHostVersion hostVersion;
|
---|
152 |
|
---|
153 |
|
---|
154 | #ifndef VBGL_VBOXGUEST
|
---|
155 | /** The IDC handle. This is used for talking to the main driver. */
|
---|
156 | VBGLIDCHANDLE IdcHandle;
|
---|
157 | /** Mutex used to serialize IDC setup. */
|
---|
158 | # ifdef VBGLDATA_USE_FAST_MUTEX
|
---|
159 | RTSEMFASTMUTEX hMtxIdcSetup;
|
---|
160 | # else
|
---|
161 | RTSEMMUTEX hMtxIdcSetup;
|
---|
162 | # endif
|
---|
163 | #endif
|
---|
164 | } VBGLDATA;
|
---|
165 |
|
---|
166 |
|
---|
167 | extern VBGLDATA g_vbgldata;
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Internal macro for checking whether we can pass physical page lists to the
|
---|
171 | * host.
|
---|
172 | *
|
---|
173 | * ASSUMES that vbglR0Enter has been called already.
|
---|
174 | *
|
---|
175 | * @param a_fLocked For the windows shared folders workarounds.
|
---|
176 | *
|
---|
177 | * @remarks Disabled the PageList feature for locked memory on Windows,
|
---|
178 | * because a new MDL is created by VBGL to get the page addresses
|
---|
179 | * and the pages from the MDL are marked as dirty when they should not.
|
---|
180 | */
|
---|
181 | #if defined(RT_OS_WINDOWS)
|
---|
182 | # define VBGLR0_CAN_USE_PHYS_PAGE_LIST(a_fLocked) \
|
---|
183 | ( !(a_fLocked) && (g_vbgldata.hostVersion.features & VMMDEV_HVF_HGCM_PHYS_PAGE_LIST) )
|
---|
184 | #else
|
---|
185 | # define VBGLR0_CAN_USE_PHYS_PAGE_LIST(a_fLocked) \
|
---|
186 | ( !!(g_vbgldata.hostVersion.features & VMMDEV_HVF_HGCM_PHYS_PAGE_LIST) )
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | int vbglR0Enter (void);
|
---|
190 |
|
---|
191 | #ifdef VBOX_WITH_HGCM
|
---|
192 | struct VBGLHGCMHANDLEDATA *vbglR0HGCMHandleAlloc(void);
|
---|
193 | void vbglR0HGCMHandleFree(struct VBGLHGCMHANDLEDATA *pHandle);
|
---|
194 | #endif /* VBOX_WITH_HGCM */
|
---|
195 |
|
---|
196 | #ifndef VBGL_VBOXGUEST
|
---|
197 | /**
|
---|
198 | * Get the IDC handle to the main VBoxGuest driver.
|
---|
199 | * @returns VERR_TRY_AGAIN if the main driver has not yet been loaded.
|
---|
200 | */
|
---|
201 | int VBOXCALL vbglR0QueryIdcHandle(PVBGLIDCHANDLE *ppIdcHandle);
|
---|
202 | #endif
|
---|
203 |
|
---|
204 | RT_C_DECLS_END
|
---|
205 |
|
---|
206 | #endif /* !___VBoxGuestLib_VBoxGuestR0LibInternal_h */
|
---|
207 |
|
---|