[11725] | 1 | /* $Id: SUPR3HardenedIPRT.cpp 15352 2008-12-12 06:08:19Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VirtualBox Support Library - Hardened Support Routines using IPRT.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
| 7 | * Copyright (C) 2006-2008 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 | /*******************************************************************************
|
---|
| 32 | * Header Files *
|
---|
| 33 | *******************************************************************************/
|
---|
| 34 | #define LOG_GROUP LOG_GROUP_SUP
|
---|
| 35 | #include <VBox/sup.h>
|
---|
| 36 | #include <VBox/err.h>
|
---|
| 37 | #include <VBox/log.h>
|
---|
| 38 | #include <iprt/string.h>
|
---|
| 39 | #include <iprt/stdarg.h>
|
---|
| 40 | #include <iprt/assert.h>
|
---|
| 41 | #include <iprt/path.h>
|
---|
| 42 | #include <iprt/param.h>
|
---|
| 43 |
|
---|
| 44 | #include "SUPLibInternal.h"
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * @copydoc RTPathFilename
|
---|
| 49 | */
|
---|
| 50 | DECLHIDDEN(char *) supR3HardenedPathFilename(const char *pszPath)
|
---|
| 51 | {
|
---|
| 52 | return RTPathFilename(pszPath);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | /**
|
---|
| 57 | * @copydoc RTPathAppPrivateNoArch
|
---|
| 58 | */
|
---|
| 59 | DECLHIDDEN(int) supR3HardenedPathAppPrivateNoArch(char *pszPath, size_t cchPath)
|
---|
| 60 | {
|
---|
| 61 | return RTPathAppPrivateNoArch(pszPath, cchPath);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * @copydoc RTPathAppPrivateArch
|
---|
| 67 | */
|
---|
| 68 | DECLHIDDEN(int) supR3HardenedPathAppPrivateArch(char *pszPath, size_t cchPath)
|
---|
| 69 | {
|
---|
| 70 | return RTPathAppPrivateArch(pszPath, cchPath);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | /**
|
---|
| 75 | * @copydoc RTPathSharedLibs
|
---|
| 76 | */
|
---|
| 77 | DECLHIDDEN(int) supR3HardenedPathSharedLibs(char *pszPath, size_t cchPath)
|
---|
| 78 | {
|
---|
| 79 | return RTPathSharedLibs(pszPath, cchPath);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
| 84 | * @copydoc RTPathAppDocs
|
---|
| 85 | */
|
---|
| 86 | DECLHIDDEN(int) supR3HardenedPathAppDocs(char *pszPath, size_t cchPath)
|
---|
| 87 | {
|
---|
| 88 | return RTPathAppDocs(pszPath, cchPath);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | /**
|
---|
| 93 | * @copydoc RTPathProgram
|
---|
| 94 | */
|
---|
| 95 | DECLHIDDEN(int) supR3HardenedPathProgram(char *pszPath, size_t cchPath)
|
---|
| 96 | {
|
---|
| 97 | return RTPathProgram(pszPath, cchPath);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
[13458] | 101 | DECLHIDDEN(void) supR3HardenedFatalMsgV(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, va_list va)
|
---|
| 102 | {
|
---|
| 103 | va_list vaCopy;
|
---|
| 104 | va_copy(vaCopy, va);
|
---|
| 105 | AssertFatalMsgFailed(("%s (rc=%Rrc): %N", pszWhere, rc, pszMsgFmt, &vaCopy));
|
---|
| 106 | va_end(vaCopy);
|
---|
| 107 | }
|
---|
[11725] | 108 |
|
---|
[13458] | 109 |
|
---|
| 110 | DECLHIDDEN(void) supR3HardenedFatalMsg(const char *pszWhere, SUPINITOP enmWhat, int rc, const char *pszMsgFmt, ...)
|
---|
| 111 | {
|
---|
| 112 | va_list va;
|
---|
| 113 | va_start(va, pszMsgFmt);
|
---|
| 114 | supR3HardenedFatalMsgV(pszWhere, enmWhat, rc, pszMsgFmt, va);
|
---|
| 115 | va_end(va);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 |
|
---|
[11725] | 119 | DECLHIDDEN(void) supR3HardenedFatalV(const char *pszFormat, va_list va)
|
---|
| 120 | {
|
---|
| 121 | va_list vaCopy;
|
---|
| 122 | va_copy(vaCopy, va);
|
---|
| 123 | AssertFatalMsgFailed(("%N", pszFormat, &vaCopy));
|
---|
| 124 | va_end(vaCopy);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | DECLHIDDEN(void) supR3HardenedFatal(const char *pszFormat, ...)
|
---|
| 129 | {
|
---|
| 130 | va_list va;
|
---|
| 131 | va_start(va, pszFormat);
|
---|
| 132 | supR3HardenedFatalV(pszFormat, va);
|
---|
| 133 | va_end(va);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | DECLHIDDEN(int) supR3HardenedErrorV(int rc, bool fFatal, const char *pszFormat, va_list va)
|
---|
| 138 | {
|
---|
| 139 | if (fFatal)
|
---|
| 140 | supR3HardenedFatalV(pszFormat, va);
|
---|
| 141 |
|
---|
| 142 | va_list vaCopy;
|
---|
| 143 | va_copy(vaCopy, va);
|
---|
[15352] | 144 | AssertLogRelMsgFailed(("%N", pszFormat, &vaCopy)); /** @todo figure out why this ain't working, or at seems to be that way... */
|
---|
[11725] | 145 | va_end(vaCopy);
|
---|
[15352] | 146 |
|
---|
| 147 | RTLogRelPrintfV(pszFormat, va);
|
---|
[11725] | 148 | return rc;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | DECLHIDDEN(int) supR3HardenedError(int rc, bool fFatal, const char *pszFormat, ...)
|
---|
| 153 | {
|
---|
| 154 | va_list va;
|
---|
| 155 | va_start(va, pszFormat);
|
---|
| 156 | supR3HardenedErrorV(rc, fFatal, pszFormat, va);
|
---|
| 157 | va_end(va);
|
---|
| 158 | return rc;
|
---|
| 159 | }
|
---|
| 160 |
|
---|