1 | /* $Id: VBoxGuestR0LibInternal.h 76557 2019-01-01 02:37:24Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestLibR0 - Internal header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 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 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
34 | # pragma once
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | /*
|
---|
38 | * Define the private IDC handle structure before we include the VBoxGuestLib.h header.
|
---|
39 | */
|
---|
40 | #include <iprt/types.h>
|
---|
41 | #include <iprt/assert.h>
|
---|
42 | RT_C_DECLS_BEGIN
|
---|
43 |
|
---|
44 | # ifndef VBGL_VBOXGUEST
|
---|
45 | /**
|
---|
46 | * The hidden part of VBGLIDCHANDLE.
|
---|
47 | */
|
---|
48 | struct VBGLIDCHANDLEPRIVATE
|
---|
49 | {
|
---|
50 | /** Pointer to the session handle. */
|
---|
51 | void *pvSession;
|
---|
52 | # if defined(RT_OS_WINDOWS) && (defined(IPRT_INCLUDED_nt_ntddk_h) || defined(IPRT_INCLUDED_nt_nt_h))
|
---|
53 | /** Pointer to the NT device object. */
|
---|
54 | PDEVICE_OBJECT pDeviceObject;
|
---|
55 | /** Pointer to the NT file object. */
|
---|
56 | PFILE_OBJECT pFileObject;
|
---|
57 | # elif defined(RT_OS_SOLARIS) && defined(_SYS_SUNLDI_H)
|
---|
58 | /** LDI device handle to keep the device attached. */
|
---|
59 | ldi_handle_t hDev;
|
---|
60 | # endif
|
---|
61 | };
|
---|
62 | /** Indicate that the VBGLIDCHANDLEPRIVATE structure is present. */
|
---|
63 | # define VBGLIDCHANDLEPRIVATE_DECLARED 1
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | #include <VBox/VMMDev.h>
|
---|
67 | #include <VBox/VBoxGuest.h>
|
---|
68 | #include <VBox/VBoxGuestLib.h>
|
---|
69 |
|
---|
70 | #ifdef VBGLIDCHANDLEPRIVATE_DECLARED
|
---|
71 | AssertCompile(RT_SIZEOFMEMB(VBGLIDCHANDLE, apvPadding) >= sizeof(struct VBGLIDCHANDLEPRIVATE));
|
---|
72 | #endif
|
---|
73 |
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * Native IDC functions.
|
---|
77 | */
|
---|
78 | int VBOXCALL vbglR0IdcNativeOpen(PVBGLIDCHANDLE pHandle, PVBGLIOCIDCCONNECT pReq);
|
---|
79 | int VBOXCALL vbglR0IdcNativeClose(PVBGLIDCHANDLE pHandle, PVBGLIOCIDCDISCONNECT pReq);
|
---|
80 |
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * Deprecated logging macro
|
---|
84 | */
|
---|
85 | #include <VBox/log.h>
|
---|
86 | #ifdef RT_OS_WINDOWS /** @todo dprintf() -> Log() */
|
---|
87 | # if (defined(DEBUG) && !defined(NO_LOGGING)) || defined(LOG_ENABLED)
|
---|
88 | # define dprintf(a) RTLogBackdoorPrintf a
|
---|
89 | # else
|
---|
90 | # define dprintf(a) do {} while (0)
|
---|
91 | # endif
|
---|
92 | #else
|
---|
93 | # define dprintf(a) Log(a)
|
---|
94 | #endif
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * Lazy bird: OS/2 doesn't currently implement the RTSemMutex API in ring-0, so
|
---|
98 | * use a fast mutex instead. Unlike Windows, the OS/2 implementation
|
---|
99 | * doesn't have any nasty side effects on IRQL-like context properties, so the
|
---|
100 | * fast mutexes on OS/2 are identical to normal mutexes except for the missing
|
---|
101 | * timeout aspec. Fortunately we don't need timeouts here.
|
---|
102 | */
|
---|
103 | #ifdef RT_OS_OS2
|
---|
104 | # define VBGLDATA_USE_FAST_MUTEX
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | struct _VBGLPHYSHEAPBLOCK;
|
---|
108 | typedef struct _VBGLPHYSHEAPBLOCK VBGLPHYSHEAPBLOCK;
|
---|
109 | struct _VBGLPHYSHEAPCHUNK;
|
---|
110 | typedef struct _VBGLPHYSHEAPCHUNK VBGLPHYSHEAPCHUNK;
|
---|
111 |
|
---|
112 | enum VbglLibStatus
|
---|
113 | {
|
---|
114 | VbglStatusNotInitialized = 0,
|
---|
115 | VbglStatusInitializing,
|
---|
116 | VbglStatusReady
|
---|
117 | };
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Global VBGL ring-0 data.
|
---|
121 | * Lives in VbglR0Init.cpp.
|
---|
122 | */
|
---|
123 | typedef struct VBGLDATA
|
---|
124 | {
|
---|
125 | enum VbglLibStatus status;
|
---|
126 |
|
---|
127 | RTIOPORT portVMMDev;
|
---|
128 |
|
---|
129 | VMMDevMemory *pVMMDevMemory;
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Physical memory heap data.
|
---|
133 | * @{
|
---|
134 | */
|
---|
135 |
|
---|
136 | VBGLPHYSHEAPBLOCK *pFreeBlocksHead;
|
---|
137 | VBGLPHYSHEAPBLOCK *pAllocBlocksHead;
|
---|
138 | VBGLPHYSHEAPCHUNK *pChunkHead;
|
---|
139 |
|
---|
140 | RTSEMFASTMUTEX mutexHeap;
|
---|
141 | /** @} */
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * The host version data.
|
---|
145 | */
|
---|
146 | VMMDevReqHostVersion hostVersion;
|
---|
147 |
|
---|
148 |
|
---|
149 | #ifndef VBGL_VBOXGUEST
|
---|
150 | /** The IDC handle. This is used for talking to the main driver. */
|
---|
151 | VBGLIDCHANDLE IdcHandle;
|
---|
152 | /** Mutex used to serialize IDC setup. */
|
---|
153 | # ifdef VBGLDATA_USE_FAST_MUTEX
|
---|
154 | RTSEMFASTMUTEX hMtxIdcSetup;
|
---|
155 | # else
|
---|
156 | RTSEMMUTEX hMtxIdcSetup;
|
---|
157 | # endif
|
---|
158 | #endif
|
---|
159 | } VBGLDATA;
|
---|
160 |
|
---|
161 |
|
---|
162 | extern VBGLDATA g_vbgldata;
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Internal macro for checking whether we can pass physical page lists to the
|
---|
166 | * host.
|
---|
167 | *
|
---|
168 | * ASSUMES that vbglR0Enter has been called already.
|
---|
169 | *
|
---|
170 | * @param a_fLocked For the windows shared folders workarounds.
|
---|
171 | *
|
---|
172 | * @remarks Disabled the PageList feature for locked memory on Windows,
|
---|
173 | * because a new MDL is created by VBGL to get the page addresses
|
---|
174 | * and the pages from the MDL are marked as dirty when they should not.
|
---|
175 | */
|
---|
176 | #if defined(RT_OS_WINDOWS)
|
---|
177 | # define VBGLR0_CAN_USE_PHYS_PAGE_LIST(a_fLocked) \
|
---|
178 | ( !(a_fLocked) && (g_vbgldata.hostVersion.features & VMMDEV_HVF_HGCM_PHYS_PAGE_LIST) )
|
---|
179 | #else
|
---|
180 | # define VBGLR0_CAN_USE_PHYS_PAGE_LIST(a_fLocked) \
|
---|
181 | ( !!(g_vbgldata.hostVersion.features & VMMDEV_HVF_HGCM_PHYS_PAGE_LIST) )
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | int vbglR0Enter (void);
|
---|
185 |
|
---|
186 | #ifdef VBOX_WITH_HGCM
|
---|
187 | struct VBGLHGCMHANDLEDATA *vbglR0HGCMHandleAlloc(void);
|
---|
188 | void vbglR0HGCMHandleFree(struct VBGLHGCMHANDLEDATA *pHandle);
|
---|
189 | #endif /* VBOX_WITH_HGCM */
|
---|
190 |
|
---|
191 | #ifndef VBGL_VBOXGUEST
|
---|
192 | /**
|
---|
193 | * Get the IDC handle to the main VBoxGuest driver.
|
---|
194 | * @returns VERR_TRY_AGAIN if the main driver has not yet been loaded.
|
---|
195 | */
|
---|
196 | int VBOXCALL vbglR0QueryIdcHandle(PVBGLIDCHANDLE *ppIdcHandle);
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | RT_C_DECLS_END
|
---|
200 |
|
---|
201 | #endif /* !___VBoxGuestLib_VBoxGuestR0LibInternal_h */
|
---|
202 |
|
---|