SUPLibInternal.h revision 6efdbcc3d25b1c4533f7a5c323c8b7f4352885a2
/* $Id$ */
/** @file
* VirtualBox Support Library - Internal header.
*/
/*
* Copyright (C) 2006-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___SUPLibInternal_h___
#define ___SUPLibInternal_h___
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** @def SUPLIB_DLL_SUFF
#if defined(RT_OS_DARWIN)
# define SUPLIB_DLL_SUFF ".dylib"
# define SUPLIB_DLL_SUFF ".s.so"
# define SUPLIB_DLL_SUFF ".dll"
#else
# define SUPLIB_DLL_SUFF ".so"
#endif
#ifdef RT_OS_SOLARIS
/** Number of dummy files to open (2:ip4, 1:ip6, 1:extra) see
* @bugref{4650}. */
# define SUPLIB_FLT_DUMMYFILES 4
#endif
/** @def SUPLIB_EXE_SUFF
* The (typical) executable suffix. */
#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
# define SUPLIB_EXE_SUFF ".exe"
#else
# define SUPLIB_EXE_SUFF ""
#endif
/** @def SUP_HARDENED_SUID
* Whether we're employing set-user-ID-on-execute in the hardening.
*/
# define SUP_HARDENED_SUID
#else
#endif
#ifdef IN_SUP_HARDENED_R3
/** @name Make the symbols in SUPR3HardenedStatic different from the VBoxRT ones.
* We cannot rely on DECLHIDDEN to make this separation for us since it doesn't
* work with all GCC versions. So, we resort to old fashion precompiler hacking.
* @{
*/
# define supR3HardenedLogV supR3HardenedStaticLogV
# define supR3HardenedLog supR3HardenedStaticLog
/** @} */
#endif /* IN_SUP_HARDENED_R3 */
/** @name CRT function mappings (not using CRT on Windows).
* @{
*/
#if defined(IN_SUP_HARDENED_R3) && defined(RT_OS_WINDOWS)
# define SUP_HARDENED_NEED_CRT_FUNCTIONS
#else
# define suplibHardenedMemComp memcmp
# define suplibHardenedMemCopy memcpy
# define suplibHardenedMemSet memset
# define suplibHardenedStrCopy strcpy
# define suplibHardenedStrLen strlen
# define suplibHardenedStrCat strcat
# define suplibHardenedStrCmp strcmp
# define suplibHardenedStrNCmp strncmp
#endif
/** @} */
/** Debug output macro. */
#ifdef IN_SUP_HARDENED_R3
# if defined(DEBUG_bird) && defined(RT_OS_WINDOWS)
# else
# define SUP_DPRINTF(a) do { supR3HardenedStaticLog a; } while (0)
# endif
#else
# if defined(DEBUG_bird) && defined(RT_OS_WINDOWS)
# define SUP_DPRINTF(a) RTLogPrintf a
# else
# define SUP_DPRINTF(a) do { } while (0)
# endif
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The type of an installed file.
*/
typedef enum SUPINSTFILETYPE
{
kSupIFT_Invalid = 0,
/**
* Installation directory specifier.
*/
typedef enum SUPINSTDIR
{
kSupID_Invalid = 0,
} SUPINSTDIR;
/**
* Installed file.
*/
typedef struct SUPINSTFILE
{
/** File type. */
/** Install directory. */
/** Optional (true) or mandatory (false. */
bool fOptional;
/** File name. */
const char *pszFile;
} SUPINSTFILE;
typedef SUPINSTFILE *PSUPINSTFILE;
typedef SUPINSTFILE const *PCSUPINSTFILE;
/**
* Status data for a verified file.
*/
typedef struct SUPVERIFIEDFILE
{
/** The file handle or descriptor. -1 if not open. */
/** Whether the file has been validated. */
bool fValidated;
#ifdef RT_OS_WINDOWS
/** Whether we've checked the signature of the file. */
bool fCheckedSignature;
#endif
typedef SUPVERIFIEDFILE *PSUPVERIFIEDFILE;
typedef SUPVERIFIEDFILE const *PCSUPVERIFIEDFILE;
/**
* Status data for a verified directory.
*/
typedef struct SUPVERIFIEDDIR
{
/** The directory handle or descriptor. -1 if not open. */
/** Whether the directory has been validated. */
bool fValidated;
typedef SUPVERIFIEDDIR *PSUPVERIFIEDDIR;
typedef SUPVERIFIEDDIR const *PCSUPVERIFIEDDIR;
/**
* SUPLib instance data.
*
* This is data that is passed from the static to the dynamic SUPLib
* in a hardened setup.
*/
typedef struct SUPLIBDATA
{
/** The device handle. */
#if defined(RT_OS_WINDOWS)
void *hDevice;
#else
int hDevice;
#endif
/** Indicates whether we have unrestricted (true) or restricted access to the
* support device. */
bool fUnrestricted;
#if defined(RT_OS_DARWIN)
/** The connection to the VBoxSupDrv service. */
#elif defined(RT_OS_LINUX)
/** Indicates whether madvise(,,MADV_DONTFORK) works. */
bool fSysMadviseWorks;
#elif defined(RT_OS_SOLARIS)
/** Extra dummy file descriptors to prevent growing file-descriptor table on
* clean up (see @bugref{4650}). */
int ahDummy[SUPLIB_FLT_DUMMYFILES];
#elif defined(RT_OS_WINDOWS)
#endif
} SUPLIBDATA;
/** Pointer to the pre-init data. */
typedef SUPLIBDATA *PSUPLIBDATA;
/** Pointer to const pre-init data. */
typedef SUPLIBDATA const *PCSUPLIBDATA;
/** The NIL value of SUPLIBDATA::hDevice. */
#if defined(RT_OS_WINDOWS)
# define SUP_HDEVICE_NIL NULL
#else
# define SUP_HDEVICE_NIL (-1)
#endif
/**
* Pre-init data that is handed over from the hardened executable stub.
*/
typedef struct SUPPREINITDATA
{
/** Magic value (SUPPREINITDATA_MAGIC). */
/** The SUPLib instance data. */
/** The number of entries in paInstallFiles and paVerifiedFiles. */
/** g_aSupInstallFiles. */
/** g_aSupVerifiedFiles. */
/** The number of entries in paVerifiedDirs. */
/** g_aSupVerifiedDirs. */
/** Magic value (SUPPREINITDATA_MAGIC). */
typedef SUPPREINITDATA *PSUPPREINITDATA;
typedef SUPPREINITDATA const *PCSUPPREINITDATA;
/** Magic value for SUPPREINITDATA::u32Magic and SUPPREINITDATA::u32EndMagic. */
/** @copydoc supR3PreInit */
/** Pointer to supR3PreInit. */
typedef FNSUPR3PREINIT *PFNSUPR3PREINIT;
/** The current SUPR3HardenedMain state / location. */
typedef enum SUPR3HARDENEDMAINSTATE
{
SUPR3HARDENEDMAINSTATE_32BIT_HACK = 0x7fffffff
/*******************************************************************************
* Global Variables *
*******************************************************************************/
#ifdef ___SUPDrvIOC_h___
#endif
#ifdef RT_OS_WINDOWS
extern DECLHIDDEN(bool) g_fSupEarlyProcessInit;
#endif
/*******************************************************************************
* OS Specific Function *
*******************************************************************************/
int suplibOsInstall(void);
int suplibOsUninstall(void);
int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted, SUPINITOP *penmWhat, PRTERRINFO pErrInfo);
int suplibOsHardenedVerifyInit(void);
int suplibOsHardenedVerifyTerm(void);
int suplibOsQueryVTxSupported(void);
/**
* Performs the pre-initialization of the support library.
*
* This is dynamically resolved and invoked by the static library before it
* calls RTR3InitEx and thereby SUPR3Init.
*
* @returns IPRT status code.
* @param pPreInitData The pre init data.
* @param fFlags The SUPR3HardenedMain flags.
*/
/** @copydoc RTPathAppPrivateNoArch */
/** @copydoc RTPathAppPrivateArch */
/** @copydoc RTPathSharedLibs */
/** @copydoc RTPathAppDocs */
/** @copydoc RTPathExecDir */
/** @copydoc RTPathFilename */
/**
* Display a fatal error and try call TrustedError or quit.
*/
DECLHIDDEN(void) supR3HardenedFatalMsgV(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va);
/**
* Display a fatal error and try call TrustedError or quit.
*/
DECLHIDDEN(void) supR3HardenedFatalMsg(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, ...);
/**
* Display a fatal error and quit.
*/
/**
* Display a fatal error and quit.
*/
/**
* Display an error which may or may not be fatal.
*/
/**
* Display an error which may or may not be fatal.
*/
/**
* Open any startup log file specified in the argument.
*/
/**
* Write to the startup log file.
*/
/**
* Write to the startup log file.
*/
DECLHIDDEN(int) supR3HardenedVerifyDir(const char *pszDirPath, bool fRecursive, bool fCheckFiles, PRTERRINFO pErrInfo);
DECLHIDDEN(int) supR3HardenedVerifyFile(const char *pszFilename, RTHCUINTPTR hNativeFile, bool fMaybe3rdParty,
#ifdef RT_OS_WINDOWS
DECLHIDDEN(void) supR3HardenedWinInitVersion(void);
DECLHIDDEN(void) supR3HardenedWinInitImports(void);
# ifdef ___iprt_nt_nt_h___
# endif
DECLHIDDEN(void) supR3HardenedWinEnableThreadCreation(void);
DECLHIDDEN(void) supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation(const char *pszProgName);
# ifdef _WINDEF_
# endif
# ifdef RTPATH_MAX
extern char g_szSupLibHardenedExePath[RTPATH_MAX];
# endif
DECLHIDDEN(void) supR3HardenedWinCompactHeaps(void);
DECLHIDDEN(void) supR3HardenedMainOpenDevice(void);
DECLHIDDEN(char *) supR3HardenedWinReadErrorInfoDevice(char *pszErrorInfo, size_t cbErrorInfo, const char *pszPrefix);
DECLHIDDEN(void) supR3HardenedWinReportErrorToParent(const char *pszWhere, SUPINITOP enmWhat, int rc,
#endif
#endif