VirtualBox

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

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

Solaris/SUPLib: fix for #4650 (fix fd table from growing on vboxflt close)

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