1 | /* $Id: LoadVBoxDDU.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Runtime - Try Load VBoxDDU to get VFS chain providers from storage.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <iprt/initterm.h>
|
---|
42 | #include <iprt/ldr.h>
|
---|
43 | #include <iprt/errcore.h>
|
---|
44 | #include <iprt/path.h>
|
---|
45 | #include <iprt/string.h>
|
---|
46 |
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Class used for registering a VFS chain element provider.
|
---|
50 | */
|
---|
51 | class LoadVBoxDDU
|
---|
52 | {
|
---|
53 | private:
|
---|
54 | /** The VBoxDDU handle. */
|
---|
55 | RTLDRMOD g_hLdrMod;
|
---|
56 |
|
---|
57 | public:
|
---|
58 | LoadVBoxDDU(void) : g_hLdrMod(NIL_RTLDRMOD)
|
---|
59 | {
|
---|
60 | int rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
|
---|
61 | if (RT_SUCCESS(rc))
|
---|
62 | {
|
---|
63 | char szPath[RTPATH_MAX];
|
---|
64 |
|
---|
65 | /* Try private arch dir first. */
|
---|
66 | rc = RTPathAppPrivateArch(szPath, sizeof(szPath));
|
---|
67 | if (RT_SUCCESS(rc))
|
---|
68 | rc = RTPathAppend(szPath, sizeof(szPath), "VBoxDDU");
|
---|
69 | if (RT_SUCCESS(rc))
|
---|
70 | rc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
71 | if (RT_SUCCESS(rc))
|
---|
72 | {
|
---|
73 | rc = RTLdrLoad(szPath, &g_hLdrMod);
|
---|
74 | if (RT_SUCCESS(rc))
|
---|
75 | return;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /* Try shared libs dir next. */
|
---|
79 | rc = RTPathSharedLibs(szPath, sizeof(szPath));
|
---|
80 | if (RT_SUCCESS(rc))
|
---|
81 | rc = RTPathAppend(szPath, sizeof(szPath), "VBoxDDU");
|
---|
82 | if (RT_SUCCESS(rc))
|
---|
83 | rc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
84 | if (RT_SUCCESS(rc))
|
---|
85 | {
|
---|
86 | rc = RTLdrLoad(szPath, &g_hLdrMod);
|
---|
87 | if (RT_SUCCESS(rc))
|
---|
88 | return;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /* Try exec dir after that. */
|
---|
92 | rc = RTPathExecDir(szPath, sizeof(szPath));
|
---|
93 | if (RT_SUCCESS(rc))
|
---|
94 | rc = RTPathAppend(szPath, sizeof(szPath), "VBoxDDU");
|
---|
95 | if (RT_SUCCESS(rc))
|
---|
96 | rc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
97 | if (RT_SUCCESS(rc))
|
---|
98 | {
|
---|
99 | rc = RTLdrLoad(szPath, &g_hLdrMod);
|
---|
100 | if (RT_SUCCESS(rc))
|
---|
101 | return;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /* Try exec dir parent after that. */
|
---|
105 | rc = RTPathExecDir(szPath, sizeof(szPath));
|
---|
106 | if (RT_SUCCESS(rc))
|
---|
107 | rc = RTPathAppend(szPath, sizeof(szPath), ".." RTPATH_SLASH_STR "VBoxDDU");
|
---|
108 | if (RT_SUCCESS(rc))
|
---|
109 | rc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
110 | if (RT_SUCCESS(rc))
|
---|
111 | {
|
---|
112 | rc = RTLdrLoad(szPath, &g_hLdrMod);
|
---|
113 | if (RT_SUCCESS(rc))
|
---|
114 | return;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /* Didn't work out, don't sweat it. */
|
---|
118 | g_hLdrMod = NIL_RTLDRMOD;
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | ~LoadVBoxDDU()
|
---|
123 | {
|
---|
124 | if (g_hLdrMod != NIL_RTLDRMOD)
|
---|
125 | {
|
---|
126 | RTLdrClose(g_hLdrMod);
|
---|
127 | g_hLdrMod = NIL_RTLDRMOD;
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | static LoadVBoxDDU s_LoadVBoxDDU;
|
---|
132 | };
|
---|
133 |
|
---|
134 | /* static*/ LoadVBoxDDU LoadVBoxDDU::s_LoadVBoxDDU;
|
---|
135 |
|
---|