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