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