VirtualBox

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

Last change on this file since 32431 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.3 KB
Line 
1/* $Id: SUPLibInternal.h 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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 supR3HardenedVerifyDir supR3HardenedStaticVerifyDir
93# define supR3HardenedVerifyFile supR3HardenedStaticVerifyFile
94# define supR3HardenedGetPreInitData supR3HardenedStaticGetPreInitData
95# define supR3HardenedRecvPreInitData supR3HardenedStaticRecvPreInitData
96/** @} */
97#endif /* IN_SUP_HARDENED_R3 */
98
99
100/*******************************************************************************
101* Structures and Typedefs *
102*******************************************************************************/
103/**
104 * The type of an installed file.
105 */
106typedef enum SUPINSTFILETYPE
107{
108 kSupIFT_Invalid = 0,
109 kSupIFT_Exe,
110 kSupIFT_Dll,
111 kSupIFT_Sys,
112 kSupIFT_Script,
113 kSupIFT_Data,
114 kSupIFT_End
115} SUPINSTFILETYPE;
116
117/**
118 * Installation directory specifier.
119 */
120typedef enum SUPINSTDIR
121{
122 kSupID_Invalid = 0,
123 kSupID_Bin,
124 kSupID_AppBin,
125 kSupID_SharedLib,
126 kSupID_AppPrivArch,
127 kSupID_AppPrivArchComp,
128 kSupID_AppPrivNoArch,
129 kSupID_End
130} SUPINSTDIR;
131
132/**
133 * Installed file.
134 */
135typedef struct SUPINSTFILE
136{
137 /** File type. */
138 SUPINSTFILETYPE enmType;
139 /** Install directory. */
140 SUPINSTDIR enmDir;
141 /** Optional (true) or mandatory (false. */
142 bool fOptional;
143 /** File name. */
144 const char *pszFile;
145} SUPINSTFILE;
146typedef SUPINSTFILE *PSUPINSTFILE;
147typedef SUPINSTFILE const *PCSUPINSTFILE;
148
149/**
150 * Status data for a verified file.
151 */
152typedef struct SUPVERIFIEDFILE
153{
154 /** The file handle or descriptor. -1 if not open. */
155 intptr_t hFile;
156 /** Whether the file has been validated. */
157 bool fValidated;
158} SUPVERIFIEDFILE;
159typedef SUPVERIFIEDFILE *PSUPVERIFIEDFILE;
160typedef SUPVERIFIEDFILE const *PCSUPVERIFIEDFILE;
161
162/**
163 * Status data for a verified directory.
164 */
165typedef struct SUPVERIFIEDDIR
166{
167 /** The directory handle or descriptor. -1 if not open. */
168 intptr_t hDir;
169 /** Whether the directory has been validated. */
170 bool fValidated;
171} SUPVERIFIEDDIR;
172typedef SUPVERIFIEDDIR *PSUPVERIFIEDDIR;
173typedef SUPVERIFIEDDIR const *PCSUPVERIFIEDDIR;
174
175
176/**
177 * SUPLib instance data.
178 *
179 * This is data that is passed from the static to the dynamic SUPLib
180 * in a hardened setup.
181 */
182typedef struct SUPLIBDATA
183{
184 /** The device handle. */
185 RTFILE hDevice;
186#if defined(RT_OS_DARWIN)
187 /** The connection to the VBoxSupDrv service. */
188 uintptr_t uConnection;
189#elif defined(RT_OS_LINUX)
190 /** Indicates whether madvise(,,MADV_DONTFORK) works. */
191 bool fSysMadviseWorks;
192#elif defined(RT_OS_SOLARIS)
193 /** Extra dummy file descriptors to prevent growing file-descriptor table on
194 * clean up (see @bugref{4650}). */
195 int ahDummy[SUPLIB_FLT_DUMMYFILES];
196#elif defined(RT_OS_WINDOWS)
197#endif
198} SUPLIBDATA;
199/** Pointer to the pre-init data. */
200typedef SUPLIBDATA *PSUPLIBDATA;
201/** Pointer to const pre-init data. */
202typedef SUPLIBDATA const *PCSUPLIBDATA;
203
204
205/**
206 * Pre-init data that is handed over from the hardened executable stub.
207 */
208typedef struct SUPPREINITDATA
209{
210 /** Magic value (SUPPREINITDATA_MAGIC). */
211 uint32_t u32Magic;
212 /** The SUPLib instance data. */
213 SUPLIBDATA Data;
214 /** The number of entries in paInstallFiles and paVerifiedFiles. */
215 size_t cInstallFiles;
216 /** g_aSupInstallFiles. */
217 PCSUPINSTFILE paInstallFiles;
218 /** g_aSupVerifiedFiles. */
219 PCSUPVERIFIEDFILE paVerifiedFiles;
220 /** The number of entries in paVerifiedDirs. */
221 size_t cVerifiedDirs;
222 /** g_aSupVerifiedDirs. */
223 PCSUPVERIFIEDDIR paVerifiedDirs;
224 /** Magic value (SUPPREINITDATA_MAGIC). */
225 uint32_t u32EndMagic;
226} SUPPREINITDATA;
227typedef SUPPREINITDATA *PSUPPREINITDATA;
228typedef SUPPREINITDATA const *PCSUPPREINITDATA;
229
230/** Magic value for SUPPREINITDATA::u32Magic and SUPPREINITDATA::u32EndMagic. */
231#define SUPPREINITDATA_MAGIC UINT32_C(0xbeef0001)
232
233/** @copydoc supR3PreInit */
234typedef DECLCALLBACK(int) FNSUPR3PREINIT(PSUPPREINITDATA pPreInitData, uint32_t fFlags);
235/** Pointer to supR3PreInit. */
236typedef FNSUPR3PREINIT *PFNSUPR3PREINIT;
237
238
239/*******************************************************************************
240* Global Variables *
241*******************************************************************************/
242extern DECLHIDDEN(uint32_t) g_u32Cookie;
243extern DECLHIDDEN(uint32_t) g_u32SessionCookie;
244extern DECLHIDDEN(SUPLIBDATA) g_supLibData;
245
246
247/*******************************************************************************
248* OS Specific Function *
249*******************************************************************************/
250RT_C_DECLS_BEGIN
251int suplibOsInstall(void);
252int suplibOsUninstall(void);
253int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited);
254int suplibOsTerm(PSUPLIBDATA pThis);
255int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq);
256int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu);
257int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages);
258int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t cPages);
259int suplibOsQueryVTxSupported(void);
260
261
262/**
263 * Performs the pre-initialization of the support library.
264 *
265 * This is dynamically resolved and invoked by the static library before it
266 * calls RTR3Init and thereby SUPR3Init.
267 *
268 * @returns IPRT status code.
269 * @param pPreInitData The pre init data.
270 * @param fFlags The SUPR3HardenedMain flags.
271 */
272DECLEXPORT(int) supR3PreInit(PSUPPREINITDATA pPreInitData, uint32_t fFlags);
273
274
275/** @copydoc RTPathAppPrivateNoArch */
276DECLHIDDEN(int) supR3HardenedPathAppPrivateNoArch(char *pszPath, size_t cchPath);
277/** @copydoc RTPathAppPrivateArch */
278DECLHIDDEN(int) supR3HardenedPathAppPrivateArch(char *pszPath, size_t cchPath);
279/** @copydoc RTPathSharedLibs */
280DECLHIDDEN(int) supR3HardenedPathSharedLibs(char *pszPath, size_t cchPath);
281/** @copydoc RTPathAppDocs */
282DECLHIDDEN(int) supR3HardenedPathAppDocs(char *pszPath, size_t cchPath);
283/** @copydoc RTPathExecDir */
284DECLHIDDEN(int) supR3HardenedPathExecDir(char *pszPath, size_t cchPath);
285/** @copydoc RTPathFilename */
286DECLHIDDEN(char *) supR3HardenedPathFilename(const char *pszPath);
287
288/**
289 * Display a fatal error and try call TrustedError or quit.
290 */
291DECLHIDDEN(void) supR3HardenedFatalMsgV(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va);
292
293/**
294 * Display a fatal error and try call TrustedError or quit.
295 */
296DECLHIDDEN(void) supR3HardenedFatalMsg(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, ...);
297
298/**
299 * Display a fatal error and quit.
300 */
301DECLHIDDEN(void) supR3HardenedFatalV(const char *pszFormat, va_list va);
302
303/**
304 * Display a fatal error and quit.
305 */
306DECLHIDDEN(void) supR3HardenedFatal(const char *pszFormat, ...);
307
308/**
309 * Display an error which may or may not be fatal.
310 */
311DECLHIDDEN(int) supR3HardenedErrorV(int rc, bool fFatal, const char *pszFormat, va_list va);
312
313/**
314 * Display an error which may or may not be fatal.
315 */
316DECLHIDDEN(int) supR3HardenedError(int rc, bool fFatal, const char *pszFormat, ...);
317DECLHIDDEN(int) supR3HardenedVerifyAll(bool fFatal, bool fLeaveFilesOpen, const char *pszProgName);
318DECLHIDDEN(int) supR3HardenedVerifyDir(SUPINSTDIR enmDir, bool fFatal);
319DECLHIDDEN(int) supR3HardenedVerifyFile(const char *pszFilename, bool fFatal);
320DECLHIDDEN(void) supR3HardenedGetPreInitData(PSUPPREINITDATA pPreInitData);
321DECLHIDDEN(int) supR3HardenedRecvPreInitData(PCSUPPREINITDATA pPreInitData);
322
323
324SUPR3DECL(int) supR3PageLock(void *pvStart, size_t cPages, PSUPPAGE paPages);
325SUPR3DECL(int) supR3PageUnlock(void *pvStart);
326
327RT_C_DECLS_END
328
329
330#endif
331
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