SUPLibInternal.h revision 78edef1df590edefed7cef91b6bcbf4d84f79947
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * VirtualBox Support Library - Internal header.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * available from http://www.virtualbox.org. This file is free software;
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * General Public License (GPL) as published by the Free Software
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * The contents of this file may alternatively be used under the terms
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * of the Common Development and Distribution License Version 1.0
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * VirtualBox OSE distribution, in which case the provisions of the
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * CDDL are applicable instead of those of the GPL.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * You may elect to license modified versions of this file under the
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * terms and conditions of either the GPL or the CDDL or both.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * additional information or have any questions.
2f827df539da232220444c27f2b207a707a045b0vboxsync/*******************************************************************************
2f827df539da232220444c27f2b207a707a045b0vboxsync* Defined Constants And Macros *
2f827df539da232220444c27f2b207a707a045b0vboxsync*******************************************************************************/
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync/** @def SUPLIB_DLL_SUFF
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * The (typical) DLL/DYLIB/SO suffix. */
7cca5a9aeb06913531b982bf772508d09b4c2f0bvboxsync/** @def SUPLIB_EXE_SUFF
2f827df539da232220444c27f2b207a707a045b0vboxsync * The (typical) executable suffix. */
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync/** @def SUP_HARDENED_SUID
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Whether we're employing set-user-ID-on-execute in the hardening.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync#if !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS) && !defined(RT_OS_L4)
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync/** @name Make the symbols in SUPR3HardenedStatic different from the VBoxRT ones.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * We cannot rely on DECLHIDDEN to make this separation for us since it doesn't
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * work with all GCC versions. So, we resort to old fashion precompiler hacking.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedPathAppPrivateNoArch supR3HardenedStaticPathAppPrivateNoArch
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedPathAppPrivateArch supR3HardenedStaticPathAppPrivateArch
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedPathSharedLibs supR3HardenedStaticPathSharedLibs
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedPathAppDocs supR3HardenedStaticPathAppDocs
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedPathProgram supR3HardenedStaticPathProgram
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedPathFilename supR3HardenedStaticPathFilename
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedFatalV supR3HardenedStaticFatalV
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedFatal supR3HardenedStaticFatal
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedErrorV supR3HardenedStaticErrorV
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedError supR3HardenedStaticError
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedVerifyAll supR3HardenedStaticVerifyAll
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedVerifyDir supR3HardenedStaticVerifyDir
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedVerifyFile supR3HardenedStaticVerifyFile
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedGetPreInitData supR3HardenedStaticGetPreInitData
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync# define supR3HardenedRecvPreInitData supR3HardenedStaticRecvPreInitData
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync#endif /* IN_SUP_HARDENED_R3 */
2f827df539da232220444c27f2b207a707a045b0vboxsync/*******************************************************************************
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync* Global Variables *
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync*******************************************************************************/
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync/** The negotiated interrupt number. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync/** The negotiated cookie. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync/** The negotiated cookie. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync/*******************************************************************************
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync* Structures and Typedefs *
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync*******************************************************************************/
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync * The type of an installed file.
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync * Installation directory specifier.
2f827df539da232220444c27f2b207a707a045b0vboxsync * Installed file.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsynctypedef struct SUPINSTFILE
2cb52dd865592ea8e27b588beb22898d189646b1vboxsync /** File type. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** Install directory. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** Optional (true) or mandatory (false. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** File name. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync const char *pszFile;
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * Status data for a verified file.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** The file handle or descriptor. -1 if not open. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** Whether the file has been validated. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * Status data for a verified directory.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** The directory handle or descriptor. -1 if not open. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** Whether the directory has been validated. */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * SUPLib instance data.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * This is data that is passed from the static to the dynamic SUPLib
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * in a hardened setup.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsynctypedef struct SUPLIBDATA
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync /** The device handle. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** The connection to the VBoxSupDrv service. */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync /** Indicates whether madvise(,,MADV_DONTFORK) works. */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** Pointer to the pre-init data. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync/** Pointer to const pre-init data. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync * Pre-init data that is handed over from the hardened executable stub.
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** Magic value (SUPPREINITDATA_MAGIC). */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** The SUPLib instance data. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** The number of entries in paInstallFiles and paVerifiedFiles. */
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsync /** g_aSupInstallFiles. */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync /** g_aSupVerifiedFiles. */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync /** The number of entries in paVerifiedDirs. */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync /** g_aSupVerifiedDirs. */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync /** Magic value (SUPPREINITDATA_MAGIC). */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** Magic value for SUPPREINITDATA::u32Magic and SUPPREINITDATA::u32EndMagic. */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** @copydoc supR3PreInit */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsynctypedef DECLCALLBACK(int) FNSUPR3PREINIT(PSUPPREINITDATA pPreInitData, uint32_t fFlags);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** Pointer to supR3PreInit. */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/*******************************************************************************
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync* OS Specific Function *
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync*******************************************************************************/
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncint suplibOsInit(PSUPLIBDATA pThis, bool fPreInited);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncint suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncint suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncint suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncint suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t cPages);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * Performs the pre-initialization of the support library.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * This is dynamically resolved and invoked by the static library before it
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * calls RTR3Init and thereby SUPR3Init.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * @returns IPRT status code.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * @param pPreInitData The pre init data.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * @param fFlags The SUPR3HardenedMain flags.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncDECLEXPORT(int) supR3PreInit(PSUPPREINITDATA pPreInitData, uint32_t fFlags);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** @copydoc RTPathAppPrivateNoArch */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncDECLHIDDEN(int) supR3HardenedPathAppPrivateNoArch(char *pszPath, size_t cchPath);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** @copydoc RTPathAppPrivateArch */
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsyncDECLHIDDEN(int) supR3HardenedPathAppPrivateArch(char *pszPath, size_t cchPath);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** @copydoc RTPathSharedLibs */
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsyncDECLHIDDEN(int) supR3HardenedPathSharedLibs(char *pszPath, size_t cchPath);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** @copydoc RTPathAppDocs */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncDECLHIDDEN(int) supR3HardenedPathAppDocs(char *pszPath, size_t cchPath);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** @copydoc RTPathProgram */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncDECLHIDDEN(int) supR3HardenedPathProgram(char *pszPath, size_t cchPath);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync/** @copydoc RTPathFilename */
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncDECLHIDDEN(char *) supR3HardenedPathFilename(const char *pszPath);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * Display a fatal error and quit.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsyncDECLHIDDEN(void) supR3HardenedFatalV(const char *pszFormat, va_list va);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * Display a fatal error and quit.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncDECLHIDDEN(void) supR3HardenedFatal(const char *pszFormat, ...);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsync * Display an error which may or may not be fatal.
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncDECLHIDDEN(int) supR3HardenedErrorV(int rc, bool fFatal, const char *pszFormat, va_list va);
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsync * Display an error which may or may not be fatal.
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsyncDECLHIDDEN(int) supR3HardenedError(int rc, bool fFatal, const char *pszFormat, ...);
f46e7db81f80ea09725c6cc048fa0cad86573dc2vboxsyncDECLHIDDEN(int) supR3HardenedVerifyAll(bool fFatal, bool fLeaveFilesOpen, const char *pszProgName);
b6517c5cc3b7a38889416706905a3cf2fd010785vboxsyncDECLHIDDEN(int) supR3HardenedVerifyDir(SUPINSTDIR enmDir, bool fFatal);
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsyncDECLHIDDEN(int) supR3HardenedVerifyFile(const char *pszFilename, bool fFatal);
56f538fa476fdbd9cc3d60438083a3f0d5f3ff7fvboxsyncDECLHIDDEN(void) supR3HardenedGetPreInitData(PSUPPREINITDATA pPreInitData);