1 | /* $Id: SUPLibInternal.h 44528 2013-02-04 14:27:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Support Library - Internal header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 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 ___SUPLibInternal_h___
|
---|
28 | #define ___SUPLibInternal_h___
|
---|
29 |
|
---|
30 | #include <VBox/cdefs.h>
|
---|
31 | #include <VBox/types.h>
|
---|
32 | #include <iprt/stdarg.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /*******************************************************************************
|
---|
36 | * Defined Constants And Macros *
|
---|
37 | *******************************************************************************/
|
---|
38 | /** @def SUPLIB_DLL_SUFF
|
---|
39 | * The (typical) DLL/DYLIB/SO suffix. */
|
---|
40 | #if defined(RT_OS_DARWIN)
|
---|
41 | # define SUPLIB_DLL_SUFF ".dylib"
|
---|
42 | #elif defined(RT_OS_L4)
|
---|
43 | # define SUPLIB_DLL_SUFF ".s.so"
|
---|
44 | #elif defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
|
---|
45 | # define SUPLIB_DLL_SUFF ".dll"
|
---|
46 | #else
|
---|
47 | # define SUPLIB_DLL_SUFF ".so"
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | #ifdef RT_OS_SOLARIS
|
---|
51 | /** Number of dummy files to open (2:ip4, 1:ip6, 1:extra) see
|
---|
52 | * @bugref{4650}. */
|
---|
53 | # define SUPLIB_FLT_DUMMYFILES 4
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | /** @def SUPLIB_EXE_SUFF
|
---|
57 | * The (typical) executable suffix. */
|
---|
58 | #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
|
---|
59 | # define SUPLIB_EXE_SUFF ".exe"
|
---|
60 | #else
|
---|
61 | # define SUPLIB_EXE_SUFF ""
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | /** @def SUP_HARDENED_SUID
|
---|
65 | * Whether we're employing set-user-ID-on-execute in the hardening.
|
---|
66 | */
|
---|
67 | #if !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS) && !defined(RT_OS_L4)
|
---|
68 | # define SUP_HARDENED_SUID
|
---|
69 | #else
|
---|
70 | # undef SUP_HARDENED_SUID
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | #ifdef IN_SUP_HARDENED_R3
|
---|
74 | /** @name Make the symbols in SUPR3HardenedStatic different from the VBoxRT ones.
|
---|
75 | * We cannot rely on DECLHIDDEN to make this separation for us since it doesn't
|
---|
76 | * work with all GCC versions. So, we resort to old fashion precompiler hacking.
|
---|
77 | * @{
|
---|
78 | */
|
---|
79 | # define supR3HardenedPathAppPrivateNoArch supR3HardenedStaticPathAppPrivateNoArch
|
---|
80 | # define supR3HardenedPathAppPrivateArch supR3HardenedStaticPathAppPrivateArch
|
---|
81 | # define supR3HardenedPathSharedLibs supR3HardenedStaticPathSharedLibs
|
---|
82 | # define supR3HardenedPathAppDocs supR3HardenedStaticPathAppDocs
|
---|
83 | # define supR3HardenedPathExecDir supR3HardenedStaticPathExecDir
|
---|
84 | # define supR3HardenedPathFilename supR3HardenedStaticPathFilename
|
---|
85 | # define supR3HardenedFatalV supR3HardenedStaticFatalV
|
---|
86 | # define supR3HardenedFatal supR3HardenedStaticFatal
|
---|
87 | # define supR3HardenedFatalMsgV supR3HardenedStaticFatalMsgV
|
---|
88 | # define supR3HardenedFatalMsg supR3HardenedStaticFatalMsg
|
---|
89 | # define supR3HardenedErrorV supR3HardenedStaticErrorV
|
---|
90 | # define supR3HardenedError supR3HardenedStaticError
|
---|
91 | # define supR3HardenedVerifyAll supR3HardenedStaticVerifyAll
|
---|
92 | # define supR3HardenedVerifyFixedDir supR3HardenedStaticVerifyFixedDir
|
---|
93 | # define supR3HardenedVerifyFixedFile supR3HardenedStaticVerifyFixedFile
|
---|
94 | # define supR3HardenedVerifyDir supR3HardenedStaticVerifyDir
|
---|
95 | # define supR3HardenedVerifyFile supR3HardenedStaticVerifyFile
|
---|
96 | # define supR3HardenedGetPreInitData supR3HardenedStaticGetPreInitData
|
---|
97 | # define supR3HardenedRecvPreInitData supR3HardenedStaticRecvPreInitData
|
---|
98 | /** @} */
|
---|
99 | #endif /* IN_SUP_HARDENED_R3 */
|
---|
100 |
|
---|
101 |
|
---|
102 | /*******************************************************************************
|
---|
103 | * Structures and Typedefs *
|
---|
104 | *******************************************************************************/
|
---|
105 | /**
|
---|
106 | * The type of an installed file.
|
---|
107 | */
|
---|
108 | typedef enum SUPINSTFILETYPE
|
---|
109 | {
|
---|
110 | kSupIFT_Invalid = 0,
|
---|
111 | kSupIFT_Exe,
|
---|
112 | kSupIFT_Dll,
|
---|
113 | kSupIFT_Sys,
|
---|
114 | kSupIFT_Script,
|
---|
115 | kSupIFT_Data,
|
---|
116 | kSupIFT_End
|
---|
117 | } SUPINSTFILETYPE;
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Installation directory specifier.
|
---|
121 | */
|
---|
122 | typedef enum SUPINSTDIR
|
---|
123 | {
|
---|
124 | kSupID_Invalid = 0,
|
---|
125 | kSupID_Bin,
|
---|
126 | kSupID_AppBin,
|
---|
127 | kSupID_SharedLib,
|
---|
128 | kSupID_AppPrivArch,
|
---|
129 | kSupID_AppPrivArchComp,
|
---|
130 | kSupID_AppPrivNoArch,
|
---|
131 | kSupID_End
|
---|
132 | } SUPINSTDIR;
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Installed file.
|
---|
136 | */
|
---|
137 | typedef struct SUPINSTFILE
|
---|
138 | {
|
---|
139 | /** File type. */
|
---|
140 | SUPINSTFILETYPE enmType;
|
---|
141 | /** Install directory. */
|
---|
142 | SUPINSTDIR enmDir;
|
---|
143 | /** Optional (true) or mandatory (false. */
|
---|
144 | bool fOptional;
|
---|
145 | /** File name. */
|
---|
146 | const char *pszFile;
|
---|
147 | } SUPINSTFILE;
|
---|
148 | typedef SUPINSTFILE *PSUPINSTFILE;
|
---|
149 | typedef SUPINSTFILE const *PCSUPINSTFILE;
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Status data for a verified file.
|
---|
153 | */
|
---|
154 | typedef struct SUPVERIFIEDFILE
|
---|
155 | {
|
---|
156 | /** The file handle or descriptor. -1 if not open. */
|
---|
157 | intptr_t hFile;
|
---|
158 | /** Whether the file has been validated. */
|
---|
159 | bool fValidated;
|
---|
160 | } SUPVERIFIEDFILE;
|
---|
161 | typedef SUPVERIFIEDFILE *PSUPVERIFIEDFILE;
|
---|
162 | typedef SUPVERIFIEDFILE const *PCSUPVERIFIEDFILE;
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Status data for a verified directory.
|
---|
166 | */
|
---|
167 | typedef struct SUPVERIFIEDDIR
|
---|
168 | {
|
---|
169 | /** The directory handle or descriptor. -1 if not open. */
|
---|
170 | intptr_t hDir;
|
---|
171 | /** Whether the directory has been validated. */
|
---|
172 | bool fValidated;
|
---|
173 | } SUPVERIFIEDDIR;
|
---|
174 | typedef SUPVERIFIEDDIR *PSUPVERIFIEDDIR;
|
---|
175 | typedef SUPVERIFIEDDIR const *PCSUPVERIFIEDDIR;
|
---|
176 |
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * SUPLib instance data.
|
---|
180 | *
|
---|
181 | * This is data that is passed from the static to the dynamic SUPLib
|
---|
182 | * in a hardened setup.
|
---|
183 | */
|
---|
184 | typedef struct SUPLIBDATA
|
---|
185 | {
|
---|
186 | /** The device handle. */
|
---|
187 | #if defined(RT_OS_WINDOWS)
|
---|
188 | void *hDevice;
|
---|
189 | #else
|
---|
190 | int hDevice;
|
---|
191 | #endif
|
---|
192 | /** Indicates whether we have unrestricted (true) or restricted access to the
|
---|
193 | * support device. */
|
---|
194 | bool fUnrestricted;
|
---|
195 | #if defined(RT_OS_DARWIN)
|
---|
196 | /** The connection to the VBoxSupDrv service. */
|
---|
197 | uintptr_t uConnection;
|
---|
198 | #elif defined(RT_OS_LINUX)
|
---|
199 | /** Indicates whether madvise(,,MADV_DONTFORK) works. */
|
---|
200 | bool fSysMadviseWorks;
|
---|
201 | #elif defined(RT_OS_SOLARIS)
|
---|
202 | /** Extra dummy file descriptors to prevent growing file-descriptor table on
|
---|
203 | * clean up (see @bugref{4650}). */
|
---|
204 | int ahDummy[SUPLIB_FLT_DUMMYFILES];
|
---|
205 | #elif defined(RT_OS_WINDOWS)
|
---|
206 | #endif
|
---|
207 | } SUPLIBDATA;
|
---|
208 | /** Pointer to the pre-init data. */
|
---|
209 | typedef SUPLIBDATA *PSUPLIBDATA;
|
---|
210 | /** Pointer to const pre-init data. */
|
---|
211 | typedef SUPLIBDATA const *PCSUPLIBDATA;
|
---|
212 |
|
---|
213 | /** The NIL value of SUPLIBDATA::hDevice. */
|
---|
214 | #if defined(RT_OS_WINDOWS)
|
---|
215 | # define SUP_HDEVICE_NIL NULL
|
---|
216 | #else
|
---|
217 | # define SUP_HDEVICE_NIL (-1)
|
---|
218 | #endif
|
---|
219 |
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Pre-init data that is handed over from the hardened executable stub.
|
---|
223 | */
|
---|
224 | typedef struct SUPPREINITDATA
|
---|
225 | {
|
---|
226 | /** Magic value (SUPPREINITDATA_MAGIC). */
|
---|
227 | uint32_t u32Magic;
|
---|
228 | /** The SUPLib instance data. */
|
---|
229 | SUPLIBDATA Data;
|
---|
230 | /** The number of entries in paInstallFiles and paVerifiedFiles. */
|
---|
231 | size_t cInstallFiles;
|
---|
232 | /** g_aSupInstallFiles. */
|
---|
233 | PCSUPINSTFILE paInstallFiles;
|
---|
234 | /** g_aSupVerifiedFiles. */
|
---|
235 | PCSUPVERIFIEDFILE paVerifiedFiles;
|
---|
236 | /** The number of entries in paVerifiedDirs. */
|
---|
237 | size_t cVerifiedDirs;
|
---|
238 | /** g_aSupVerifiedDirs. */
|
---|
239 | PCSUPVERIFIEDDIR paVerifiedDirs;
|
---|
240 | /** Magic value (SUPPREINITDATA_MAGIC). */
|
---|
241 | uint32_t u32EndMagic;
|
---|
242 | } SUPPREINITDATA;
|
---|
243 | typedef SUPPREINITDATA *PSUPPREINITDATA;
|
---|
244 | typedef SUPPREINITDATA const *PCSUPPREINITDATA;
|
---|
245 |
|
---|
246 | /** Magic value for SUPPREINITDATA::u32Magic and SUPPREINITDATA::u32EndMagic. */
|
---|
247 | #define SUPPREINITDATA_MAGIC UINT32_C(0xbeef0001)
|
---|
248 |
|
---|
249 | /** @copydoc supR3PreInit */
|
---|
250 | typedef DECLCALLBACK(int) FNSUPR3PREINIT(PSUPPREINITDATA pPreInitData, uint32_t fFlags);
|
---|
251 | /** Pointer to supR3PreInit. */
|
---|
252 | typedef FNSUPR3PREINIT *PFNSUPR3PREINIT;
|
---|
253 |
|
---|
254 |
|
---|
255 | /*******************************************************************************
|
---|
256 | * Global Variables *
|
---|
257 | *******************************************************************************/
|
---|
258 | extern DECLHIDDEN(uint32_t) g_u32Cookie;
|
---|
259 | extern DECLHIDDEN(uint32_t) g_u32SessionCookie;
|
---|
260 | extern DECLHIDDEN(SUPLIBDATA) g_supLibData;
|
---|
261 |
|
---|
262 |
|
---|
263 | /*******************************************************************************
|
---|
264 | * OS Specific Function *
|
---|
265 | *******************************************************************************/
|
---|
266 | RT_C_DECLS_BEGIN
|
---|
267 | int suplibOsInstall(void);
|
---|
268 | int suplibOsUninstall(void);
|
---|
269 | int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted);
|
---|
270 | int suplibOsTerm(PSUPLIBDATA pThis);
|
---|
271 | int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq);
|
---|
272 | int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu);
|
---|
273 | int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages);
|
---|
274 | int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t cPages);
|
---|
275 | int suplibOsQueryVTxSupported(void);
|
---|
276 |
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * Performs the pre-initialization of the support library.
|
---|
280 | *
|
---|
281 | * This is dynamically resolved and invoked by the static library before it
|
---|
282 | * calls RTR3InitEx and thereby SUPR3Init.
|
---|
283 | *
|
---|
284 | * @returns IPRT status code.
|
---|
285 | * @param pPreInitData The pre init data.
|
---|
286 | * @param fFlags The SUPR3HardenedMain flags.
|
---|
287 | */
|
---|
288 | DECLEXPORT(int) supR3PreInit(PSUPPREINITDATA pPreInitData, uint32_t fFlags);
|
---|
289 |
|
---|
290 |
|
---|
291 | /** @copydoc RTPathAppPrivateNoArch */
|
---|
292 | DECLHIDDEN(int) supR3HardenedPathAppPrivateNoArch(char *pszPath, size_t cchPath);
|
---|
293 | /** @copydoc RTPathAppPrivateArch */
|
---|
294 | DECLHIDDEN(int) supR3HardenedPathAppPrivateArch(char *pszPath, size_t cchPath);
|
---|
295 | /** @copydoc RTPathSharedLibs */
|
---|
296 | DECLHIDDEN(int) supR3HardenedPathSharedLibs(char *pszPath, size_t cchPath);
|
---|
297 | /** @copydoc RTPathAppDocs */
|
---|
298 | DECLHIDDEN(int) supR3HardenedPathAppDocs(char *pszPath, size_t cchPath);
|
---|
299 | /** @copydoc RTPathExecDir */
|
---|
300 | DECLHIDDEN(int) supR3HardenedPathExecDir(char *pszPath, size_t cchPath);
|
---|
301 | /** @copydoc RTPathFilename */
|
---|
302 | DECLHIDDEN(char *) supR3HardenedPathFilename(const char *pszPath);
|
---|
303 |
|
---|
304 | /**
|
---|
305 | * Display a fatal error and try call TrustedError or quit.
|
---|
306 | */
|
---|
307 | DECLHIDDEN(void) supR3HardenedFatalMsgV(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va);
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * Display a fatal error and try call TrustedError or quit.
|
---|
311 | */
|
---|
312 | DECLHIDDEN(void) supR3HardenedFatalMsg(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, ...);
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * Display a fatal error and quit.
|
---|
316 | */
|
---|
317 | DECLHIDDEN(void) supR3HardenedFatalV(const char *pszFormat, va_list va);
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * Display a fatal error and quit.
|
---|
321 | */
|
---|
322 | DECLHIDDEN(void) supR3HardenedFatal(const char *pszFormat, ...);
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Display an error which may or may not be fatal.
|
---|
326 | */
|
---|
327 | DECLHIDDEN(int) supR3HardenedErrorV(int rc, bool fFatal, const char *pszFormat, va_list va);
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * Display an error which may or may not be fatal.
|
---|
331 | */
|
---|
332 | DECLHIDDEN(int) supR3HardenedError(int rc, bool fFatal, const char *pszFormat, ...);
|
---|
333 | DECLHIDDEN(int) supR3HardenedVerifyAll(bool fFatal, bool fLeaveFilesOpen, const char *pszProgName);
|
---|
334 | DECLHIDDEN(int) supR3HardenedVerifyFixedDir(SUPINSTDIR enmDir, bool fFatal);
|
---|
335 | DECLHIDDEN(int) supR3HardenedVerifyFixedFile(const char *pszFilename, bool fFatal);
|
---|
336 | DECLHIDDEN(int) supR3HardenedVerifyDir(const char *pszDirPath, bool fRecursive, bool fCheckFiles, PRTERRINFO pErrInfo);
|
---|
337 | DECLHIDDEN(int) supR3HardenedVerifyFile(const char *pszFilename, RTHCUINTPTR hNativeFile, PRTERRINFO pErrInfo);
|
---|
338 | DECLHIDDEN(void) supR3HardenedGetPreInitData(PSUPPREINITDATA pPreInitData);
|
---|
339 | DECLHIDDEN(int) supR3HardenedRecvPreInitData(PCSUPPREINITDATA pPreInitData);
|
---|
340 |
|
---|
341 |
|
---|
342 | SUPR3DECL(int) supR3PageLock(void *pvStart, size_t cPages, PSUPPAGE paPages);
|
---|
343 | SUPR3DECL(int) supR3PageUnlock(void *pvStart);
|
---|
344 |
|
---|
345 | RT_C_DECLS_END
|
---|
346 |
|
---|
347 |
|
---|
348 | #endif
|
---|
349 |
|
---|