1 | /* $Id: LoadVBoxDDU.cpp 76452 2018-12-25 01:41:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Runtime - Try Load VBoxDDU to get VFS chain providers from storage.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 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 | #include <iprt/initterm.h>
|
---|
32 | #include <iprt/ldr.h>
|
---|
33 | #include <iprt/errcore.h>
|
---|
34 | #include <iprt/path.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Class used for registering a VFS chain element provider.
|
---|
40 | */
|
---|
41 | class LoadVBoxDDU
|
---|
42 | {
|
---|
43 | private:
|
---|
44 | /** The VBoxDDU handle. */
|
---|
45 | RTLDRMOD g_hLdrMod;
|
---|
46 |
|
---|
47 | public:
|
---|
48 | LoadVBoxDDU(void) : g_hLdrMod(NIL_RTLDRMOD)
|
---|
49 | {
|
---|
50 | int rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
|
---|
51 | if (RT_SUCCESS(rc))
|
---|
52 | {
|
---|
53 | char szPath[RTPATH_MAX];
|
---|
54 |
|
---|
55 | /* Try private arch dir first. */
|
---|
56 | rc = RTPathAppPrivateArch(szPath, sizeof(szPath));
|
---|
57 | if (RT_SUCCESS(rc))
|
---|
58 | rc = RTPathAppend(szPath, sizeof(szPath), "VBoxDDU");
|
---|
59 | if (RT_SUCCESS(rc))
|
---|
60 | rc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
61 | if (RT_SUCCESS(rc))
|
---|
62 | {
|
---|
63 | rc = RTLdrLoad(szPath, &g_hLdrMod);
|
---|
64 | if (RT_SUCCESS(rc))
|
---|
65 | return;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /* Try shared libs dir next. */
|
---|
69 | rc = RTPathSharedLibs(szPath, sizeof(szPath));
|
---|
70 | if (RT_SUCCESS(rc))
|
---|
71 | rc = RTPathAppend(szPath, sizeof(szPath), "VBoxDDU");
|
---|
72 | if (RT_SUCCESS(rc))
|
---|
73 | rc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
74 | if (RT_SUCCESS(rc))
|
---|
75 | {
|
---|
76 | rc = RTLdrLoad(szPath, &g_hLdrMod);
|
---|
77 | if (RT_SUCCESS(rc))
|
---|
78 | return;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* Try exec dir after that. */
|
---|
82 | rc = RTPathExecDir(szPath, sizeof(szPath));
|
---|
83 | if (RT_SUCCESS(rc))
|
---|
84 | rc = RTPathAppend(szPath, sizeof(szPath), "VBoxDDU");
|
---|
85 | if (RT_SUCCESS(rc))
|
---|
86 | rc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
87 | if (RT_SUCCESS(rc))
|
---|
88 | {
|
---|
89 | rc = RTLdrLoad(szPath, &g_hLdrMod);
|
---|
90 | if (RT_SUCCESS(rc))
|
---|
91 | return;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* Try exec dir parent after that. */
|
---|
95 | rc = RTPathExecDir(szPath, sizeof(szPath));
|
---|
96 | if (RT_SUCCESS(rc))
|
---|
97 | rc = RTPathAppend(szPath, sizeof(szPath), ".." RTPATH_SLASH_STR "VBoxDDU");
|
---|
98 | if (RT_SUCCESS(rc))
|
---|
99 | rc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
|
---|
100 | if (RT_SUCCESS(rc))
|
---|
101 | {
|
---|
102 | rc = RTLdrLoad(szPath, &g_hLdrMod);
|
---|
103 | if (RT_SUCCESS(rc))
|
---|
104 | return;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* Didn't work out, don't sweat it. */
|
---|
108 | g_hLdrMod = NIL_RTLDRMOD;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | ~LoadVBoxDDU()
|
---|
113 | {
|
---|
114 | if (g_hLdrMod != NIL_RTLDRMOD)
|
---|
115 | {
|
---|
116 | RTLdrClose(g_hLdrMod);
|
---|
117 | g_hLdrMod = NIL_RTLDRMOD;
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | static LoadVBoxDDU s_LoadVBoxDDU;
|
---|
122 | };
|
---|
123 |
|
---|
124 | /* static*/ LoadVBoxDDU LoadVBoxDDU::s_LoadVBoxDDU;
|
---|
125 |
|
---|