VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPLibInternal.h@ 52160

Last change on this file since 52160 was 52160, checked in by vboxsync, 11 years ago

SUP: some cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.3 KB
Line 
1/* $Id: SUPLibInternal.h 52160 2014-07-24 09:47:27Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2013 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/** @name CRT function mappings (not using CRT on Windows).
103 * @{
104 */
105#if defined(IN_SUP_HARDENED_R3) && defined(RT_OS_WINDOWS)
106# define SUP_HARDENED_NEED_CRT_FUNCTIONS
107DECLHIDDEN(int) suplibHardenedMemComp(void const *pvDst, const void *pvSrc, size_t cbToComp);
108DECLHIDDEN(void *) suplibHardenedMemCopy(void *pvDst, const void *pvSrc, size_t cbToCopy);
109DECLHIDDEN(void *) suplibHardenedMemSet(void *pvDst, int ch, size_t cbToSet);
110DECLHIDDEN(char *) suplibHardenedStrCopy(char *pszDst, const char *pszSrc);
111DECLHIDDEN(size_t) suplibHardenedStrLen(const char *psz);
112DECLHIDDEN(char *) suplibHardenedStrCat(char *pszDst, const char *pszSrc);
113DECLHIDDEN(int) suplibHardenedStrCmp(const char *psz1, const char *psz2);
114DECLHIDDEN(int) suplibHardenedStrNCmp(const char *psz1, const char *psz2, size_t cchMax);
115#else
116# undef SUP_HARDENED_NEED_CRT_FUNCTIONS
117# define suplibHardenedMemComp memcmp
118# define suplibHardenedMemCopy memcpy
119# define suplibHardenedMemSet memset
120# define suplibHardenedStrCopy strcpy
121# define suplibHardenedStrLen strlen
122# define suplibHardenedStrCat strcat
123# define suplibHardenedStrCmp strcmp
124# define suplibHardenedStrNCmp strncmp
125#endif
126DECLNORETURN(void) suplibHardenedExit(RTEXITCODE rcExit);
127DECLHIDDEN(void) suplibHardenedPrintF(const char *pszFormat, ...);
128DECLHIDDEN(void) suplibHardenedPrintFV(const char *pszFormat, va_list va);
129
130/** @} */
131
132/** Debug output macro. */
133#ifdef DEBUG_bird
134# ifdef IN_SUP_HARDENED_R3
135# define SUP_DPRINTF(a) suplibHardenedPrintF a
136# else
137# define SUP_DPRINTF(a) RTLogPrintf a
138# endif
139#else
140# define SUP_DPRINTF(a) do { } while (0)
141#endif
142
143
144/*******************************************************************************
145* Structures and Typedefs *
146*******************************************************************************/
147/**
148 * The type of an installed file.
149 */
150typedef enum SUPINSTFILETYPE
151{
152 kSupIFT_Invalid = 0,
153 kSupIFT_Exe,
154 kSupIFT_Dll,
155 kSupIFT_Rc,
156 kSupIFT_Sys,
157 kSupIFT_Script,
158 kSupIFT_Data,
159 kSupIFT_TestExe,
160 kSupIFT_TestDll,
161 kSupIFT_End
162} SUPINSTFILETYPE;
163
164/**
165 * Installation directory specifier.
166 */
167typedef enum SUPINSTDIR
168{
169 kSupID_Invalid = 0,
170 kSupID_Bin,
171 kSupID_AppBin,
172 kSupID_SharedLib,
173 kSupID_AppPrivArch,
174 kSupID_AppPrivArchComp,
175 kSupID_AppPrivNoArch,
176 kSupID_Testcase,
177 kSupID_End
178} SUPINSTDIR;
179
180/**
181 * Installed file.
182 */
183typedef struct SUPINSTFILE
184{
185 /** File type. */
186 SUPINSTFILETYPE enmType;
187 /** Install directory. */
188 SUPINSTDIR enmDir;
189 /** Optional (true) or mandatory (false. */
190 bool fOptional;
191 /** File name. */
192 const char *pszFile;
193} SUPINSTFILE;
194typedef SUPINSTFILE *PSUPINSTFILE;
195typedef SUPINSTFILE const *PCSUPINSTFILE;
196
197/**
198 * Status data for a verified file.
199 */
200typedef struct SUPVERIFIEDFILE
201{
202 /** The file handle or descriptor. -1 if not open. */
203 intptr_t hFile;
204 /** Whether the file has been validated. */
205 bool fValidated;
206#ifdef RT_OS_WINDOWS
207 /** Whether we've checked the signature of the file. */
208 bool fCheckedSignature;
209#endif
210} SUPVERIFIEDFILE;
211typedef SUPVERIFIEDFILE *PSUPVERIFIEDFILE;
212typedef SUPVERIFIEDFILE const *PCSUPVERIFIEDFILE;
213
214/**
215 * Status data for a verified directory.
216 */
217typedef struct SUPVERIFIEDDIR
218{
219 /** The directory handle or descriptor. -1 if not open. */
220 intptr_t hDir;
221 /** Whether the directory has been validated. */
222 bool fValidated;
223} SUPVERIFIEDDIR;
224typedef SUPVERIFIEDDIR *PSUPVERIFIEDDIR;
225typedef SUPVERIFIEDDIR const *PCSUPVERIFIEDDIR;
226
227
228/**
229 * SUPLib instance data.
230 *
231 * This is data that is passed from the static to the dynamic SUPLib
232 * in a hardened setup.
233 */
234typedef struct SUPLIBDATA
235{
236 /** The device handle. */
237#if defined(RT_OS_WINDOWS)
238 void *hDevice;
239#else
240 int hDevice;
241#endif
242 /** Indicates whether we have unrestricted (true) or restricted access to the
243 * support device. */
244 bool fUnrestricted;
245#if defined(RT_OS_DARWIN)
246 /** The connection to the VBoxSupDrv service. */
247 uintptr_t uConnection;
248#elif defined(RT_OS_LINUX)
249 /** Indicates whether madvise(,,MADV_DONTFORK) works. */
250 bool fSysMadviseWorks;
251#elif defined(RT_OS_SOLARIS)
252 /** Extra dummy file descriptors to prevent growing file-descriptor table on
253 * clean up (see @bugref{4650}). */
254 int ahDummy[SUPLIB_FLT_DUMMYFILES];
255#elif defined(RT_OS_WINDOWS)
256#endif
257} SUPLIBDATA;
258/** Pointer to the pre-init data. */
259typedef SUPLIBDATA *PSUPLIBDATA;
260/** Pointer to const pre-init data. */
261typedef SUPLIBDATA const *PCSUPLIBDATA;
262
263/** The NIL value of SUPLIBDATA::hDevice. */
264#if defined(RT_OS_WINDOWS)
265# define SUP_HDEVICE_NIL NULL
266#else
267# define SUP_HDEVICE_NIL (-1)
268#endif
269
270
271/**
272 * Pre-init data that is handed over from the hardened executable stub.
273 */
274typedef struct SUPPREINITDATA
275{
276 /** Magic value (SUPPREINITDATA_MAGIC). */
277 uint32_t u32Magic;
278 /** The SUPLib instance data. */
279 SUPLIBDATA Data;
280 /** The number of entries in paInstallFiles and paVerifiedFiles. */
281 size_t cInstallFiles;
282 /** g_aSupInstallFiles. */
283 PCSUPINSTFILE paInstallFiles;
284 /** g_aSupVerifiedFiles. */
285 PCSUPVERIFIEDFILE paVerifiedFiles;
286 /** The number of entries in paVerifiedDirs. */
287 size_t cVerifiedDirs;
288 /** g_aSupVerifiedDirs. */
289 PCSUPVERIFIEDDIR paVerifiedDirs;
290 /** Magic value (SUPPREINITDATA_MAGIC). */
291 uint32_t u32EndMagic;
292} SUPPREINITDATA;
293typedef SUPPREINITDATA *PSUPPREINITDATA;
294typedef SUPPREINITDATA const *PCSUPPREINITDATA;
295
296/** Magic value for SUPPREINITDATA::u32Magic and SUPPREINITDATA::u32EndMagic. */
297#define SUPPREINITDATA_MAGIC UINT32_C(0xbeef0001)
298
299/** @copydoc supR3PreInit */
300typedef DECLCALLBACK(int) FNSUPR3PREINIT(PSUPPREINITDATA pPreInitData, uint32_t fFlags);
301/** Pointer to supR3PreInit. */
302typedef FNSUPR3PREINIT *PFNSUPR3PREINIT;
303
304/** The current SUPR3HardenedMain state / location. */
305typedef enum SUPR3HARDENEDMAINSTATE
306{
307 SUPR3HARDENEDMAINSTATE_NOT_YET_CALLED = 0,
308 SUPR3HARDENEDMAINSTATE_VERIFY_TRUST_READY,
309 SUPR3HARDENEDMAINSTATE_INIT_RUNTIME,
310 SUPR3HARDENEDMAINSTATE_GET_TRUSTED_MAIN,
311 SUPR3HARDENEDMAINSTATE_CALLED_TRUSTED_MAIN,
312 SUPR3HARDENEDMAINSTATE_END
313} SUPR3HARDENEDMAINSTATE;
314
315
316/*******************************************************************************
317* Global Variables *
318*******************************************************************************/
319extern DECLHIDDEN(uint32_t) g_u32Cookie;
320extern DECLHIDDEN(uint32_t) g_u32SessionCookie;
321extern DECLHIDDEN(SUPLIBDATA) g_supLibData;
322extern DECLHIDDEN(uint32_t) g_uSupFakeMode;
323extern DECLHIDDEN(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPageR0;
324#ifdef ___SUPDrvIOC_h___
325extern DECLHIDDEN(PSUPQUERYFUNCS) g_pSupFunctions;
326#endif
327extern DECLHIDDEN(SUPR3HARDENEDMAINSTATE) g_enmSupR3HardenedMainState;
328
329
330/*******************************************************************************
331* OS Specific Function *
332*******************************************************************************/
333RT_C_DECLS_BEGIN
334int suplibOsInstall(void);
335int suplibOsUninstall(void);
336int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted);
337int suplibOsTerm(PSUPLIBDATA pThis);
338int suplibOsHardenedVerifyInit(void);
339int suplibOsHardenedVerifyTerm(void);
340int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq);
341int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu);
342int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages);
343int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t cPages);
344int suplibOsQueryVTxSupported(void);
345
346
347/**
348 * Performs the pre-initialization of the support library.
349 *
350 * This is dynamically resolved and invoked by the static library before it
351 * calls RTR3InitEx and thereby SUPR3Init.
352 *
353 * @returns IPRT status code.
354 * @param pPreInitData The pre init data.
355 * @param fFlags The SUPR3HardenedMain flags.
356 */
357DECLEXPORT(int) supR3PreInit(PSUPPREINITDATA pPreInitData, uint32_t fFlags);
358
359
360/** @copydoc RTPathAppPrivateNoArch */
361DECLHIDDEN(int) supR3HardenedPathAppPrivateNoArch(char *pszPath, size_t cchPath);
362/** @copydoc RTPathAppPrivateArch */
363DECLHIDDEN(int) supR3HardenedPathAppPrivateArch(char *pszPath, size_t cchPath);
364/** @copydoc RTPathSharedLibs */
365DECLHIDDEN(int) supR3HardenedPathSharedLibs(char *pszPath, size_t cchPath);
366/** @copydoc RTPathAppDocs */
367DECLHIDDEN(int) supR3HardenedPathAppDocs(char *pszPath, size_t cchPath);
368/** @copydoc RTPathExecDir */
369DECLHIDDEN(int) supR3HardenedPathExecDir(char *pszPath, size_t cchPath);
370/** @copydoc RTPathFilename */
371DECLHIDDEN(char *) supR3HardenedPathFilename(const char *pszPath);
372
373/**
374 * Display a fatal error and try call TrustedError or quit.
375 */
376DECLHIDDEN(void) supR3HardenedFatalMsgV(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va);
377
378/**
379 * Display a fatal error and try call TrustedError or quit.
380 */
381DECLHIDDEN(void) supR3HardenedFatalMsg(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, ...);
382
383/**
384 * Display a fatal error and quit.
385 */
386DECLHIDDEN(void) supR3HardenedFatalV(const char *pszFormat, va_list va);
387
388/**
389 * Display a fatal error and quit.
390 */
391DECLHIDDEN(void) supR3HardenedFatal(const char *pszFormat, ...);
392
393/**
394 * Display an error which may or may not be fatal.
395 */
396DECLHIDDEN(int) supR3HardenedErrorV(int rc, bool fFatal, const char *pszFormat, va_list va);
397
398/**
399 * Display an error which may or may not be fatal.
400 */
401DECLHIDDEN(int) supR3HardenedError(int rc, bool fFatal, const char *pszFormat, ...);
402
403DECLHIDDEN(int) supR3HardenedVerifyAll(bool fFatal, const char *pszProgName);
404DECLHIDDEN(int) supR3HardenedVerifyFixedDir(SUPINSTDIR enmDir, bool fFatal);
405DECLHIDDEN(int) supR3HardenedVerifyFixedFile(const char *pszFilename, bool fFatal);
406DECLHIDDEN(int) supR3HardenedVerifyDir(const char *pszDirPath, bool fRecursive, bool fCheckFiles, PRTERRINFO pErrInfo);
407DECLHIDDEN(int) supR3HardenedVerifyFile(const char *pszFilename, RTHCUINTPTR hNativeFile, bool fMaybe3rdParty,
408 PRTERRINFO pErrInfo);
409DECLHIDDEN(void) supR3HardenedGetPreInitData(PSUPPREINITDATA pPreInitData);
410DECLHIDDEN(int) supR3HardenedRecvPreInitData(PCSUPPREINITDATA pPreInitData);
411
412#ifdef RT_OS_WINDOWS
413DECLHIDDEN(void) supR3HardenedWinInit(uint32_t fFlags);
414DECLHIDDEN(void) supR3HardenedWinInitVersion(void);
415DECLHIDDEN(void) supR3HardenedWinVerifyProcess(void);
416DECLHIDDEN(void) supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(void);
417DECLHIDDEN(bool) supR3HardenedWinIsReSpawnNeeded(int iWhich, int cArgs, char **papszArgs);
418DECLHIDDEN(int) supR3HardenedWinReSpawn(int iWhich);
419DECLHIDDEN(void *) supR3HardenedWinLoadLibrary(const char *pszName, bool fSystem32Only);
420extern RTUTF16 g_wszSupLibHardenedExePath[1024];
421# ifdef RTPATH_MAX
422extern char g_szSupLibHardenedExePath[RTPATH_MAX];
423# endif
424#endif
425
426SUPR3DECL(int) supR3PageLock(void *pvStart, size_t cPages, PSUPPAGE paPages);
427SUPR3DECL(int) supR3PageUnlock(void *pvStart);
428
429RT_C_DECLS_END
430
431
432#endif
433
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette