[23] | 1 | /* $Id: tstGlobalConfig.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[5240] | 3 | * Ring-3 Management program for the GCFGM mock-up.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2007-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 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
|
---|
[1] | 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
[57358] | 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[35346] | 32 | #include <VBox/vmm/vmm.h>
|
---|
[76454] | 33 | #include <iprt/errcore.h>
|
---|
[1] | 34 | #include <iprt/assert.h>
|
---|
[5240] | 35 | #include <iprt/initterm.h>
|
---|
[1] | 36 | #include <iprt/stream.h>
|
---|
[5240] | 37 | #include <iprt/string.h>
|
---|
[1] | 38 |
|
---|
| 39 |
|
---|
[5240] | 40 | /**
|
---|
| 41 | * Prints the usage and returns 1.
|
---|
| 42 | * @return 1
|
---|
| 43 | */
|
---|
| 44 | static int Usage(void)
|
---|
| 45 | {
|
---|
| 46 | RTPrintf("usage: tstGlobalConfig <value-name> [new value]\n");
|
---|
| 47 | return 1;
|
---|
| 48 | }
|
---|
[1] | 49 |
|
---|
| 50 |
|
---|
[51906] | 51 | /**
|
---|
| 52 | * Entry point.
|
---|
| 53 | */
|
---|
| 54 | extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
|
---|
[1] | 55 | {
|
---|
[62869] | 56 | RT_NOREF1(envp);
|
---|
[38636] | 57 | RTR3InitExe(argc, &argv, 0);
|
---|
[1] | 58 |
|
---|
| 59 | /*
|
---|
[5240] | 60 | * Parse args, building the request as we do so.
|
---|
[1] | 61 | */
|
---|
[5240] | 62 | if (argc <= 1)
|
---|
| 63 | return Usage();
|
---|
| 64 | if (argc > 3)
|
---|
[1] | 65 | {
|
---|
[5240] | 66 | RTPrintf("syntax error: too many arguments\n");
|
---|
| 67 | Usage();
|
---|
| 68 | return 1;
|
---|
| 69 | }
|
---|
[1] | 70 |
|
---|
[5240] | 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);
|
---|
[1] | 76 |
|
---|
[5240] | 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 | {
|
---|
[50694] | 86 | RTPrintf("syntax error: the name '%s' is too long. (max %zu chars)\n", argv[1], sizeof(Req.szName) - 1);
|
---|
[5240] | 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)
|
---|
[1] | 97 | {
|
---|
[5240] | 98 | RTPrintf("syntax error: '%s' didn't convert successfully to a number. (%Rrc,'%s')\n", argv[2], rc, pszNext);
|
---|
| 99 | return 1;
|
---|
[1] | 100 | }
|
---|
[5240] | 101 | enmOp = VMMR0_DO_GCFGM_SET_VALUE;
|
---|
[1] | 102 | }
|
---|
[5240] | 103 |
|
---|
| 104 | /*
|
---|
| 105 | * Open the session, load ring-0 and issue the request.
|
---|
| 106 | */
|
---|
| 107 | PSUPDRVSESSION pSession;
|
---|
[11794] | 108 | int rc = SUPR3Init(&pSession);
|
---|
[5240] | 109 | if (RT_FAILURE(rc))
|
---|
[1] | 110 | {
|
---|
[11794] | 111 | RTPrintf("tstGlobalConfig: SUPR3Init -> %Rrc\n", rc);
|
---|
[5240] | 112 | return 1;
|
---|
[1] | 113 | }
|
---|
| 114 |
|
---|
[85506] | 115 | rc = SUPR3LoadVMM("./VMMR0.r0", NULL /*pErrInfo*/);
|
---|
[5240] | 116 | if (RT_SUCCESS(rc))
|
---|
| 117 | {
|
---|
| 118 | Req.pSession = pSession;
|
---|
[20864] | 119 | rc = SUPR3CallVMMR0Ex(NIL_RTR0PTR, NIL_VMCPUID, enmOp, 0, &Req.Hdr);
|
---|
[5240] | 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 | }
|
---|
[20864] | 133 | SUPR3Term(false /*fForced*/);
|
---|
[5240] | 134 |
|
---|
| 135 | return RT_FAILURE(rc) ? 1 : 0;
|
---|
[1] | 136 | }
|
---|
[51906] | 137 |
|
---|
| 138 |
|
---|
| 139 | #if !defined(VBOX_WITH_HARDENING) || !defined(RT_OS_WINDOWS)
|
---|
| 140 | /**
|
---|
| 141 | * Main entry point.
|
---|
| 142 | */
|
---|
| 143 | int main(int argc, char **argv, char **envp)
|
---|
| 144 | {
|
---|
| 145 | return TrustedMain(argc, argv, envp);
|
---|
| 146 | }
|
---|
| 147 | #endif
|
---|
| 148 |
|
---|