tstGlobalConfig.cpp revision 86b51be433c7032578ae50e94ebe590cc428448b
6739cf90e4aa3b3344768b8da241802f80ff455cvboxsync/* $Id$ */
46f059bea92bedbd395793702c73946ead235586vboxsync/** @file
46f059bea92bedbd395793702c73946ead235586vboxsync * Ring-3 Management program for the GCFGM mock-up.
46f059bea92bedbd395793702c73946ead235586vboxsync */
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync/*
46f059bea92bedbd395793702c73946ead235586vboxsync * Copyright (C) 2007 innotek GmbH
46f059bea92bedbd395793702c73946ead235586vboxsync *
46f059bea92bedbd395793702c73946ead235586vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
46f059bea92bedbd395793702c73946ead235586vboxsync * available from http://www.virtualbox.org. This file is free software;
46f059bea92bedbd395793702c73946ead235586vboxsync * you can redistribute it and/or modify it under the terms of the GNU
46f059bea92bedbd395793702c73946ead235586vboxsync * General Public License as published by the Free Software Foundation,
46f059bea92bedbd395793702c73946ead235586vboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
46f059bea92bedbd395793702c73946ead235586vboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync */
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync/*******************************************************************************
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync* Header Files *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync*******************************************************************************/
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync#include <VBox/vmm.h>
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync#include <VBox/err.h>
46f059bea92bedbd395793702c73946ead235586vboxsync#include <iprt/assert.h>
46f059bea92bedbd395793702c73946ead235586vboxsync#include <iprt/initterm.h>
46f059bea92bedbd395793702c73946ead235586vboxsync#include <iprt/stream.h>
46f059bea92bedbd395793702c73946ead235586vboxsync#include <iprt/string.h>
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync/**
46f059bea92bedbd395793702c73946ead235586vboxsync * Prints the usage and returns 1.
46f059bea92bedbd395793702c73946ead235586vboxsync * @return 1
46f059bea92bedbd395793702c73946ead235586vboxsync */
46f059bea92bedbd395793702c73946ead235586vboxsyncstatic int Usage(void)
46f059bea92bedbd395793702c73946ead235586vboxsync{
46f059bea92bedbd395793702c73946ead235586vboxsync RTPrintf("usage: tstGlobalConfig <value-name> [new value]\n");
46f059bea92bedbd395793702c73946ead235586vboxsync return 1;
46f059bea92bedbd395793702c73946ead235586vboxsync}
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsyncint main(int argc, char **argv)
46f059bea92bedbd395793702c73946ead235586vboxsync{
46f059bea92bedbd395793702c73946ead235586vboxsync RTR3Init(false, 0);
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync /*
46f059bea92bedbd395793702c73946ead235586vboxsync * Parse args, building the request as we do so.
46f059bea92bedbd395793702c73946ead235586vboxsync */
46f059bea92bedbd395793702c73946ead235586vboxsync if (argc <= 1)
46f059bea92bedbd395793702c73946ead235586vboxsync return Usage();
46f059bea92bedbd395793702c73946ead235586vboxsync if (argc > 3)
46f059bea92bedbd395793702c73946ead235586vboxsync {
46f059bea92bedbd395793702c73946ead235586vboxsync RTPrintf("syntax error: too many arguments\n");
46f059bea92bedbd395793702c73946ead235586vboxsync Usage();
46f059bea92bedbd395793702c73946ead235586vboxsync return 1;
46f059bea92bedbd395793702c73946ead235586vboxsync }
46f059bea92bedbd395793702c73946ead235586vboxsync
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync VMMR0OPERATION enmOp = VMMR0_DO_GCFGM_QUERY_VALUE;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync GCFGMVALUEREQ Req;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync memset(&Req, 0, sizeof(Req));
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync Req.Hdr.cbReq = sizeof(Req);
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync /* arg[1] = szName */
46f059bea92bedbd395793702c73946ead235586vboxsync size_t cch = strlen(argv[1]);
46f059bea92bedbd395793702c73946ead235586vboxsync if (cch < 2 || argv[1][0] != '/')
46f059bea92bedbd395793702c73946ead235586vboxsync {
46f059bea92bedbd395793702c73946ead235586vboxsync RTPrintf("syntax error: malformed name '%s'\n", argv[1]);
46f059bea92bedbd395793702c73946ead235586vboxsync return 1;
46f059bea92bedbd395793702c73946ead235586vboxsync }
46f059bea92bedbd395793702c73946ead235586vboxsync if (cch >= sizeof(Req.szName))
46f059bea92bedbd395793702c73946ead235586vboxsync {
1bef0d3fd3b2fe689a4eaa9ebf0647b8bf7c662evboxsync RTPrintf("syntax error: the name is too long. (max %zu chars)\n", argv[1], sizeof(Req.szName) - 1);
46f059bea92bedbd395793702c73946ead235586vboxsync return 1;
46f059bea92bedbd395793702c73946ead235586vboxsync }
46f059bea92bedbd395793702c73946ead235586vboxsync memcpy(&Req.szName[0], argv[1], cch + 1);
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync /* argv[2] = u64SetValue; optional */
46f059bea92bedbd395793702c73946ead235586vboxsync if (argc == 3)
46f059bea92bedbd395793702c73946ead235586vboxsync {
46f059bea92bedbd395793702c73946ead235586vboxsync char *pszNext = NULL;
46f059bea92bedbd395793702c73946ead235586vboxsync int rc = RTStrToUInt64Ex(argv[2], &pszNext, 0, &Req.u64Value);
46f059bea92bedbd395793702c73946ead235586vboxsync if (RT_FAILURE(rc) || *pszNext)
46f059bea92bedbd395793702c73946ead235586vboxsync {
46f059bea92bedbd395793702c73946ead235586vboxsync RTPrintf("syntax error: '%s' didn't convert successfully to a number. (%Rrc,'%s')\n", argv[2], rc, pszNext);
46f059bea92bedbd395793702c73946ead235586vboxsync return 1;
46f059bea92bedbd395793702c73946ead235586vboxsync }
46f059bea92bedbd395793702c73946ead235586vboxsync enmOp = VMMR0_DO_GCFGM_SET_VALUE;
46f059bea92bedbd395793702c73946ead235586vboxsync }
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync /*
46f059bea92bedbd395793702c73946ead235586vboxsync * Open the session, load ring-0 and issue the request.
46f059bea92bedbd395793702c73946ead235586vboxsync */
46f059bea92bedbd395793702c73946ead235586vboxsync PSUPDRVSESSION pSession;
46f059bea92bedbd395793702c73946ead235586vboxsync int rc = SUPInit(&pSession, 0);
46f059bea92bedbd395793702c73946ead235586vboxsync if (RT_FAILURE(rc))
46f059bea92bedbd395793702c73946ead235586vboxsync {
46f059bea92bedbd395793702c73946ead235586vboxsync RTPrintf("tstGlobalConfig: SUPInit -> %Rrc\n", rc);
46f059bea92bedbd395793702c73946ead235586vboxsync return 1;
46f059bea92bedbd395793702c73946ead235586vboxsync }
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync rc = SUPLoadVMM("./VMMR0.r0");
46f059bea92bedbd395793702c73946ead235586vboxsync if (RT_SUCCESS(rc))
46f059bea92bedbd395793702c73946ead235586vboxsync {
46f059bea92bedbd395793702c73946ead235586vboxsync Req.pSession = pSession;
df2e37f58f19997178bb9be53867a17509a3a2f9vboxsync rc = SUPCallVMMR0Ex(NIL_RTR0PTR, enmOp, 0, &Req.Hdr);
46f059bea92bedbd395793702c73946ead235586vboxsync if (RT_SUCCESS(rc))
46f059bea92bedbd395793702c73946ead235586vboxsync {
46f059bea92bedbd395793702c73946ead235586vboxsync if (enmOp == VMMR0_DO_GCFGM_QUERY_VALUE)
46f059bea92bedbd395793702c73946ead235586vboxsync RTPrintf("%s = %RU64 (%#RX64)\n", Req.szName, Req.u64Value, Req.u64Value);
46f059bea92bedbd395793702c73946ead235586vboxsync else
46f059bea92bedbd395793702c73946ead235586vboxsync RTPrintf("Successfully set %s = %RU64 (%#RX64)\n", Req.szName, Req.u64Value, Req.u64Value);
46f059bea92bedbd395793702c73946ead235586vboxsync }
46f059bea92bedbd395793702c73946ead235586vboxsync else if (enmOp == VMMR0_DO_GCFGM_QUERY_VALUE)
46f059bea92bedbd395793702c73946ead235586vboxsync RTPrintf("error: Failed to query '%s', rc=%Rrc\n", Req.szName, rc);
46f059bea92bedbd395793702c73946ead235586vboxsync else
46f059bea92bedbd395793702c73946ead235586vboxsync RTPrintf("error: Failed to set '%s' to %RU64, rc=%Rrc\n", Req.szName, Req.u64Value, rc);
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync }
46f059bea92bedbd395793702c73946ead235586vboxsync SUPTerm(false /* not forced */);
46f059bea92bedbd395793702c73946ead235586vboxsync
46f059bea92bedbd395793702c73946ead235586vboxsync return RT_FAILURE(rc) ? 1 : 0;
46f059bea92bedbd395793702c73946ead235586vboxsync}
46f059bea92bedbd395793702c73946ead235586vboxsync