VirtualBox

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

Last change on this file since 26512 was 26402, checked in by vboxsync, 15 years ago

SUPLib: ahDummy.

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