1 | /* $Id: tstSupLoadModule.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * SUP Testcase - Test SUPR3LoadModule.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 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 <VBox/sup.h>
|
---|
42 | #include <iprt/errcore.h>
|
---|
43 |
|
---|
44 | #include <iprt/getopt.h>
|
---|
45 | #include <iprt/initterm.h>
|
---|
46 | #include <iprt/mem.h>
|
---|
47 | #include <iprt/message.h>
|
---|
48 | #include <iprt/path.h>
|
---|
49 | #include <iprt/stream.h>
|
---|
50 |
|
---|
51 |
|
---|
52 | int main(int argc, char **argv)
|
---|
53 | {
|
---|
54 | /*
|
---|
55 | * Init.
|
---|
56 | */
|
---|
57 | int rc = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
|
---|
58 | if (RT_FAILURE(rc))
|
---|
59 | return RTMsgInitFailure(rc);
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * Process arguments.
|
---|
63 | */
|
---|
64 | static const RTGETOPTDEF s_aOptions[] =
|
---|
65 | {
|
---|
66 | { "--keep", 'k', RTGETOPT_REQ_NOTHING },
|
---|
67 | { "--no-keep", 'n', RTGETOPT_REQ_NOTHING },
|
---|
68 | };
|
---|
69 |
|
---|
70 | bool fKeepLoaded = false;
|
---|
71 |
|
---|
72 | int ch;
|
---|
73 | RTGETOPTUNION ValueUnion;
|
---|
74 | RTGETOPTSTATE GetState;
|
---|
75 | RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
|
---|
76 | while ((ch = RTGetOpt(&GetState, &ValueUnion)))
|
---|
77 | {
|
---|
78 | switch (ch)
|
---|
79 | {
|
---|
80 | case VINF_GETOPT_NOT_OPTION:
|
---|
81 | {
|
---|
82 | void *pvImageBase;
|
---|
83 | RTERRINFOSTATIC ErrInfo;
|
---|
84 | RTErrInfoInitStatic(&ErrInfo);
|
---|
85 | rc = SUPR3LoadModule(ValueUnion.psz, RTPathFilename(ValueUnion.psz), &pvImageBase, &ErrInfo.Core);
|
---|
86 | if (RT_FAILURE(rc))
|
---|
87 | {
|
---|
88 | RTMsgError("%Rrc when attempting to load '%s': %s\n", rc, ValueUnion.psz, ErrInfo.Core.pszMsg);
|
---|
89 | return 1;
|
---|
90 | }
|
---|
91 | RTPrintf("Loaded '%s' at %p\n", ValueUnion.psz, pvImageBase);
|
---|
92 |
|
---|
93 | if (!fKeepLoaded)
|
---|
94 | {
|
---|
95 | rc = SUPR3FreeModule(pvImageBase);
|
---|
96 | if (RT_FAILURE(rc))
|
---|
97 | {
|
---|
98 | RTMsgError("%Rrc when attempting to load '%s'\n", rc, ValueUnion.psz);
|
---|
99 | return 1;
|
---|
100 | }
|
---|
101 | }
|
---|
102 | break;
|
---|
103 | }
|
---|
104 |
|
---|
105 | case 'k':
|
---|
106 | fKeepLoaded = true;
|
---|
107 | break;
|
---|
108 |
|
---|
109 | case 'n':
|
---|
110 | fKeepLoaded = false;
|
---|
111 | break;
|
---|
112 |
|
---|
113 | case 'h':
|
---|
114 | RTPrintf("%s [mod1 [mod2...]]\n", argv[0]);
|
---|
115 | return 1;
|
---|
116 |
|
---|
117 | case 'V':
|
---|
118 | RTPrintf("$Revision: 106061 $\n");
|
---|
119 | return 0;
|
---|
120 |
|
---|
121 | default:
|
---|
122 | return RTGetOptPrintError(ch, &ValueUnion);
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | return 0;
|
---|
127 | }
|
---|
128 |
|
---|