VirtualBox

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

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

Testcase fix.

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

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