VirtualBox

source: vbox/trunk/src/VBox/VMM/tools/VBoxVMMPreload.cpp@ 50653

Last change on this file since 50653 was 46175, checked in by vboxsync, 11 years ago

Fix non-hardened debug win.amd64 build.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: VBoxVMMPreload.cpp 46175 2013-05-20 12:38:38Z vboxsync $ */
2/** @file
3 * VBoxVMMPreload - Preload VBox the ring-0 modules.
4 */
5
6/*
7 * Copyright (C) 2012 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
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <iprt/buildconfig.h>
23#include <iprt/getopt.h>
24#include <iprt/initterm.h>
25#include <iprt/message.h>
26#include <iprt/path.h>
27#include <iprt/stream.h>
28#include <iprt/string.h>
29#include <iprt/thread.h>
30
31#include <VBox/sup.h>
32#include <VBox/version.h>
33
34
35/*******************************************************************************
36* Global Variables *
37*******************************************************************************/
38/**
39 * Known modules and their associated data (there are only known modules!).
40 */
41static struct
42{
43 const char *pszName;
44 bool fPreload;
45 void *pvImageBase;
46} g_aModules[] =
47{
48 { "VMMR0.r0", true, NULL },
49 { "VBoxDDR0.r0", true, NULL },
50 { "VBoxDD2R0.r0", true, NULL },
51};
52
53static uint32_t g_cVerbose = 1;
54
55
56/**
57 * Parses the options.
58 *
59 * @returns RTEXITCODE_SUCCESS on success.
60 * @param argc Argument count .
61 * @param argv Argument vector.
62 * @param pfExit Set to @c true if we should exit.
63 */
64static RTEXITCODE ParseOptions(int argc, char **argv, bool *pfExit)
65{
66 /*
67 * Parse arguments.
68 */
69 static const RTGETOPTDEF s_aOptions[] =
70 {
71 { "--only", 'o', RTGETOPT_REQ_STRING },
72 { "--quiet", 'q', RTGETOPT_REQ_NOTHING },
73 { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
74 };
75
76 bool fAll = true;
77
78 int ch;
79 RTGETOPTUNION ValueUnion;
80 RTGETOPTSTATE GetState;
81 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /* fFlags */);
82 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
83 {
84 switch(ch)
85 {
86 case 'o':
87 {
88 uint32_t i;
89
90 if (fAll)
91 {
92 fAll = false;
93 for (i = 0; i < RT_ELEMENTS(g_aModules); i++)
94 g_aModules[i].fPreload = false;
95 }
96
97 i = RT_ELEMENTS(g_aModules);
98 while (i-- > 0)
99 if (!strcmp(ValueUnion.psz, g_aModules[i].pszName))
100 {
101 g_aModules[i].fPreload = true;
102 break;
103 }
104 if (i > RT_ELEMENTS(g_aModules))
105 return RTMsgErrorExit(RTEXITCODE_FAILURE, "No known module '%s'", ValueUnion.psz);
106 break;
107 }
108
109 case 'v':
110 g_cVerbose++;
111 break;
112
113 case 'q':
114 g_cVerbose = 0;
115 break;
116
117 case 'h':
118 RTPrintf(VBOX_PRODUCT " VMM ring-0 Module Preloader Version " VBOX_VERSION_STRING
119 "(C) 2005-" VBOX_C_YEAR " " VBOX_VENDOR "\n"
120 "All rights reserved.\n"
121 "\n"
122 "Usage: VBoxVMMPreload [-hqvV] [-o|--only <mod>]\n"
123 "\n");
124 *pfExit = true;
125 return RTEXITCODE_SUCCESS;
126
127 case 'V':
128 RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
129 *pfExit = true;
130 return RTEXITCODE_SUCCESS;
131
132 default:
133 return RTGetOptPrintError(ch, &ValueUnion);
134 }
135 }
136 return RTEXITCODE_SUCCESS;
137}
138
139
140/**
141 * Loads the modules.
142 *
143 * @returns RTEXITCODE_SUCCESS on success.
144 */
145static RTEXITCODE LoadModules(void)
146{
147 for (uint32_t i = 0; i < RT_ELEMENTS(g_aModules); i++)
148 {
149 if (g_aModules[i].fPreload)
150 {
151 char szPath[RTPATH_MAX];
152 int rc = RTPathAppPrivateArch(szPath, sizeof(szPath));
153 if (RT_SUCCESS(rc))
154 rc = RTPathAppend(szPath, sizeof(szPath), g_aModules[i].pszName);
155 if (RT_FAILURE(rc))
156 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTPathAppPrivateArch or RTPathAppend returned %Rrc", rc);
157
158 RTERRINFOSTATIC ErrInfo;
159 RTErrInfoInitStatic(&ErrInfo);
160 rc = SUPR3LoadModule(szPath, g_aModules[i].pszName, &g_aModules[i].pvImageBase, &ErrInfo.Core);
161 if (RT_FAILURE(rc))
162 return RTMsgErrorExit(RTEXITCODE_FAILURE, "SUPR3LoadModule failed for %s (%s): %s (rc=%Rrc)",
163 g_aModules[i].pszName, szPath, ErrInfo.Core.pszMsg, rc);
164 if (g_cVerbose >= 1)
165 RTMsgInfo("Loaded '%s' ('%s') at %p\n", szPath, g_aModules[i].pszName, g_aModules[i].pvImageBase);
166 }
167 }
168
169 RTStrmFlush(g_pStdOut);
170 return RTEXITCODE_SUCCESS;
171}
172
173
174/**
175 * Entry point.
176 */
177extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
178{
179 bool fExit = false;
180 RTEXITCODE rcExit = ParseOptions(argc, argv, &fExit);
181 if (rcExit == RTEXITCODE_SUCCESS && !fExit)
182 {
183 rcExit = LoadModules();
184 if (rcExit == RTEXITCODE_SUCCESS)
185 {
186 for (;;)
187 RTThreadSleep(RT_INDEFINITE_WAIT);
188 }
189 }
190 return rcExit;
191}
192
193
194#ifndef VBOX_WITH_HARDENING
195/**
196 * Main entry point.
197 */
198int main(int argc, char **argv, char **envp)
199{
200 int rc = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
201 if (RT_FAILURE(rc))
202 return RTMsgInitFailure(rc);
203 return TrustedMain(argc, argv, envp);
204}
205#endif /* !VBOX_WITH_HARDENING */
206
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use