1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/* $Id: tstGlobalConfig.cpp $ */
/** @file
* Ring-3 Management program for the GCFGM mock-up.
*/
/*
* Copyright (C) 2007-2020 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*********************************************************************************************************************************
* Header Files *
*********************************************************************************************************************************/
#include <VBox/vmm/vmm.h>
#include <iprt/errcore.h>
#include <iprt/assert.h>
#include <iprt/initterm.h>
#include <iprt/stream.h>
#include <iprt/string.h>
/**
* Prints the usage and returns 1.
* @return 1
*/
static int Usage(void)
{
RTPrintf("usage: tstGlobalConfig <value-name> [new value]\n");
return 1;
}
/**
* Entry point.
*/
extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
{
RT_NOREF1(envp);
RTR3InitExe(argc, &argv, 0);
/*
* Parse args, building the request as we do so.
*/
if (argc <= 1)
return Usage();
if (argc > 3)
{
RTPrintf("syntax error: too many arguments\n");
Usage();
return 1;
}
VMMR0OPERATION enmOp = VMMR0_DO_GCFGM_QUERY_VALUE;
GCFGMVALUEREQ Req;
memset(&Req, 0, sizeof(Req));
Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
Req.Hdr.cbReq = sizeof(Req);
/* arg[1] = szName */
size_t cch = strlen(argv[1]);
if (cch < 2 || argv[1][0] != '/')
{
RTPrintf("syntax error: malformed name '%s'\n", argv[1]);
return 1;
}
if (cch >= sizeof(Req.szName))
{
RTPrintf("syntax error: the name '%s' is too long. (max %zu chars)\n", argv[1], sizeof(Req.szName) - 1);
return 1;
}
memcpy(&Req.szName[0], argv[1], cch + 1);
/* argv[2] = u64SetValue; optional */
if (argc == 3)
{
char *pszNext = NULL;
int rc = RTStrToUInt64Ex(argv[2], &pszNext, 0, &Req.u64Value);
if (RT_FAILURE(rc) || *pszNext)
{
RTPrintf("syntax error: '%s' didn't convert successfully to a number. (%Rrc,'%s')\n", argv[2], rc, pszNext);
return 1;
}
enmOp = VMMR0_DO_GCFGM_SET_VALUE;
}
/*
* Open the session, load ring-0 and issue the request.
*/
PSUPDRVSESSION pSession;
int rc = SUPR3Init(&pSession);
if (RT_FAILURE(rc))
{
RTPrintf("tstGlobalConfig: SUPR3Init -> %Rrc\n", rc);
return 1;
}
rc = SUPR3LoadVMM("./VMMR0.r0", NULL /*pErrInfo*/);
if (RT_SUCCESS(rc))
{
Req.pSession = pSession;
rc = SUPR3CallVMMR0Ex(NIL_RTR0PTR, NIL_VMCPUID, enmOp, 0, &Req.Hdr);
if (RT_SUCCESS(rc))
{
if (enmOp == VMMR0_DO_GCFGM_QUERY_VALUE)
RTPrintf("%s = %RU64 (%#RX64)\n", Req.szName, Req.u64Value, Req.u64Value);
else
RTPrintf("Successfully set %s = %RU64 (%#RX64)\n", Req.szName, Req.u64Value, Req.u64Value);
}
else if (enmOp == VMMR0_DO_GCFGM_QUERY_VALUE)
RTPrintf("error: Failed to query '%s', rc=%Rrc\n", Req.szName, rc);
else
RTPrintf("error: Failed to set '%s' to %RU64, rc=%Rrc\n", Req.szName, Req.u64Value, rc);
}
SUPR3Term(false /*fForced*/);
return RT_FAILURE(rc) ? 1 : 0;
}
#if !defined(VBOX_WITH_HARDENING) || !defined(RT_OS_WINDOWS)
/**
* Main entry point.
*/
int main(int argc, char **argv, char **envp)
{
return TrustedMain(argc, argv, envp);
}
#endif
|