VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstGlobalConfig.cpp@ 101665

Last change on this file since 101665 was 98103, checked in by vboxsync, 22 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.2 KB
Line 
1/* $Id: tstGlobalConfig.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Ring-3 Management program for the GCFGM mock-up.
4 */
5
6/*
7 * Copyright (C) 2007-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 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <VBox/vmm/vmm.h>
33#include <iprt/errcore.h>
34#include <iprt/assert.h>
35#include <iprt/initterm.h>
36#include <iprt/stream.h>
37#include <iprt/string.h>
38
39
40/**
41 * Prints the usage and returns 1.
42 * @return 1
43 */
44static int Usage(void)
45{
46 RTPrintf("usage: tstGlobalConfig <value-name> [new value]\n");
47 return 1;
48}
49
50
51/**
52 * Entry point.
53 */
54extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
55{
56 RT_NOREF1(envp);
57 RTR3InitExe(argc, &argv, 0);
58
59 /*
60 * Parse args, building the request as we do so.
61 */
62 if (argc <= 1)
63 return Usage();
64 if (argc > 3)
65 {
66 RTPrintf("syntax error: too many arguments\n");
67 Usage();
68 return 1;
69 }
70
71 VMMR0OPERATION enmOp = VMMR0_DO_GCFGM_QUERY_VALUE;
72 GCFGMVALUEREQ Req;
73 memset(&Req, 0, sizeof(Req));
74 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
75 Req.Hdr.cbReq = sizeof(Req);
76
77 /* arg[1] = szName */
78 size_t cch = strlen(argv[1]);
79 if (cch < 2 || argv[1][0] != '/')
80 {
81 RTPrintf("syntax error: malformed name '%s'\n", argv[1]);
82 return 1;
83 }
84 if (cch >= sizeof(Req.szName))
85 {
86 RTPrintf("syntax error: the name '%s' is too long. (max %zu chars)\n", argv[1], sizeof(Req.szName) - 1);
87 return 1;
88 }
89 memcpy(&Req.szName[0], argv[1], cch + 1);
90
91 /* argv[2] = u64SetValue; optional */
92 if (argc == 3)
93 {
94 char *pszNext = NULL;
95 int rc = RTStrToUInt64Ex(argv[2], &pszNext, 0, &Req.u64Value);
96 if (RT_FAILURE(rc) || *pszNext)
97 {
98 RTPrintf("syntax error: '%s' didn't convert successfully to a number. (%Rrc,'%s')\n", argv[2], rc, pszNext);
99 return 1;
100 }
101 enmOp = VMMR0_DO_GCFGM_SET_VALUE;
102 }
103
104 /*
105 * Open the session, load ring-0 and issue the request.
106 */
107 PSUPDRVSESSION pSession;
108 int rc = SUPR3Init(&pSession);
109 if (RT_FAILURE(rc))
110 {
111 RTPrintf("tstGlobalConfig: SUPR3Init -> %Rrc\n", rc);
112 return 1;
113 }
114
115 rc = SUPR3LoadVMM("./VMMR0.r0", NULL /*pErrInfo*/);
116 if (RT_SUCCESS(rc))
117 {
118 Req.pSession = pSession;
119 rc = SUPR3CallVMMR0Ex(NIL_RTR0PTR, NIL_VMCPUID, enmOp, 0, &Req.Hdr);
120 if (RT_SUCCESS(rc))
121 {
122 if (enmOp == VMMR0_DO_GCFGM_QUERY_VALUE)
123 RTPrintf("%s = %RU64 (%#RX64)\n", Req.szName, Req.u64Value, Req.u64Value);
124 else
125 RTPrintf("Successfully set %s = %RU64 (%#RX64)\n", Req.szName, Req.u64Value, Req.u64Value);
126 }
127 else if (enmOp == VMMR0_DO_GCFGM_QUERY_VALUE)
128 RTPrintf("error: Failed to query '%s', rc=%Rrc\n", Req.szName, rc);
129 else
130 RTPrintf("error: Failed to set '%s' to %RU64, rc=%Rrc\n", Req.szName, Req.u64Value, rc);
131
132 }
133 SUPR3Term(false /*fForced*/);
134
135 return RT_FAILURE(rc) ? 1 : 0;
136}
137
138
139#if !defined(VBOX_WITH_HARDENING) || !defined(RT_OS_WINDOWS)
140/**
141 * Main entry point.
142 */
143int main(int argc, char **argv, char **envp)
144{
145 return TrustedMain(argc, argv, envp);
146}
147#endif
148
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette