1 | /* $Id: SUPR3HardenedIPRT.cpp 85127 2020-07-08 23:42:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Support Library - Hardened Support Routines using IPRT.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
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 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #define LOG_GROUP LOG_GROUP_SUP
|
---|
32 | #include <VBox/sup.h>
|
---|
33 | #include <iprt/errcore.h>
|
---|
34 | #include <VBox/log.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 | #include <iprt/stdarg.h>
|
---|
37 | #include <iprt/assert.h>
|
---|
38 | #include <iprt/path.h>
|
---|
39 | #include <iprt/param.h>
|
---|
40 |
|
---|
41 | #include "SUPLibInternal.h"
|
---|
42 |
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * @copydoc RTPathFilename
|
---|
46 | */
|
---|
47 | DECLHIDDEN(char *) supR3HardenedPathFilename(const char *pszPath)
|
---|
48 | {
|
---|
49 | return RTPathFilename(pszPath);
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * @copydoc RTPathAppPrivateNoArch
|
---|
55 | */
|
---|
56 | DECLHIDDEN(int) supR3HardenedPathAppPrivateNoArch(char *pszPath, size_t cchPath)
|
---|
57 | {
|
---|
58 | return RTPathAppPrivateNoArch(pszPath, cchPath);
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * @copydoc RTPathAppPrivateArch
|
---|
64 | */
|
---|
65 | DECLHIDDEN(int) supR3HardenedPathAppPrivateArch(char *pszPath, size_t cchPath)
|
---|
66 | {
|
---|
67 | return RTPathAppPrivateArch(pszPath, cchPath);
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * @copydoc RTPathSharedLibs
|
---|
73 | */
|
---|
74 | DECLHIDDEN(int) supR3HardenedPathAppSharedLibs(char *pszPath, size_t cchPath)
|
---|
75 | {
|
---|
76 | return RTPathSharedLibs(pszPath, cchPath);
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * @copydoc RTPathAppDocs
|
---|
82 | */
|
---|
83 | DECLHIDDEN(int) supR3HardenedPathAppDocs(char *pszPath, size_t cchPath)
|
---|
84 | {
|
---|
85 | return RTPathAppDocs(pszPath, cchPath);
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * @copydoc RTPathExecDir
|
---|
91 | */
|
---|
92 | DECLHIDDEN(int) supR3HardenedPathAppBin(char *pszPath, size_t cchPath)
|
---|
93 | {
|
---|
94 | return RTPathExecDir(pszPath, cchPath);
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | DECL_NO_RETURN(DECLHIDDEN(void)) supR3HardenedFatalMsgV(const char *pszWhere, SUPINITOP enmWhat, int rc,
|
---|
99 | const char *pszMsgFmt, va_list va)
|
---|
100 | {
|
---|
101 | va_list vaCopy;
|
---|
102 | va_copy(vaCopy, va);
|
---|
103 | AssertFatalMsgFailed(("%s (rc=%Rrc): %N", pszWhere, rc, pszMsgFmt, &vaCopy));
|
---|
104 | NOREF(enmWhat);
|
---|
105 | /* not reached */
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | DECL_NO_RETURN(DECLHIDDEN(void)) supR3HardenedFatalMsg(const char *pszWhere, SUPINITOP enmWhat, int rc,
|
---|
110 | const char *pszMsgFmt, ...)
|
---|
111 | {
|
---|
112 | va_list va;
|
---|
113 | va_start(va, pszMsgFmt);
|
---|
114 | supR3HardenedFatalMsgV(pszWhere, enmWhat, rc, pszMsgFmt, va);
|
---|
115 | /* not reached */
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | DECL_NO_RETURN(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 | /* not reached */
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | DECL_NO_RETURN(DECLHIDDEN(void)) supR3HardenedFatal(const char *pszFormat, ...)
|
---|
129 | {
|
---|
130 | va_list va;
|
---|
131 | va_start(va, pszFormat);
|
---|
132 | supR3HardenedFatalV(pszFormat, va);
|
---|
133 | /* not reached */
|
---|
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);
|
---|
144 | AssertLogRelMsgFailed(("%N", pszFormat, &vaCopy)); /** @todo figure out why this ain't working, or at seems to be that way... */
|
---|
145 | va_end(vaCopy);
|
---|
146 |
|
---|
147 | RTLogRelPrintfV(pszFormat, va);
|
---|
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 |
|
---|