VirtualBox

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

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

SUPDrv: Added an interface for probing MSRs.

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