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