VirtualBox

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

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

SUPDRV_USE_NATIVE_LOADER -> VBOX_WITH_NATIVE_R0_LOADER

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