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