VBoxGuestR3LibModule.cpp revision 8e9add8eb6b051d148d0e0d3c9153fed3b851269
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync/* $Id$ */
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync/** @file
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Shared modules.
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync */
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2007-2010 Oracle Corporation
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync *
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * available from http://www.virtualbox.org. This file is free software;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * General Public License (GPL) as published by the Free Software
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync *
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * The contents of this file may alternatively be used under the terms
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * of the Common Development and Distribution License Version 1.0
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * CDDL are applicable instead of those of the GPL.
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync *
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * You may elect to license modified versions of this file under the
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * terms and conditions of either the GPL or the CDDL or both.
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync */
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync/*******************************************************************************
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync* Header Files *
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync*******************************************************************************/
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync#include "VBGLR3Internal.h"
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync#include <iprt/mem.h>
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync#include <iprt/string.h>
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync/**
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * Registers a new shared module for the VM
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync *
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @returns IPRT status code.
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param pszModuleName Module name
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param pszVersion Module version
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param GCBaseAddr Module base address
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param cbModule Module size
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param cRegions Number of shared region descriptors
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param pRegions Shared region(s)
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync */
f8df398d066204e2bf0ba209ea3554fc113fb484vboxsyncVBGLR3DECL(int) VbglR3RegisterSharedModule(char *pszModuleName, char *pszVersion,
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync RTGCPTR64 GCBaseAddr, uint32_t cbModule,
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync unsigned cRegions, VMMDEVSHAREDREGIONDESC *pRegions)
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync{
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync VMMDevSharedModuleRegistrationRequest *pReq;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync int rc;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync /* Sanity check. */
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync AssertReturn(cRegions < VMMDEVSHAREDREGIONDESC_MAX, VERR_INVALID_PARAMETER);
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync pReq = (VMMDevSharedModuleRegistrationRequest *)RTMemAllocZ(RT_OFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[cRegions]));
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync AssertReturn(pReq, VERR_NO_MEMORY);
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync vmmdevInitRequest(&pReq->header, VMMDevReq_RegisterSharedModule);
a2269e19277f3a9d353323ea6cd8e14451323cd6vboxsync pReq->header.size = RT_OFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[cRegions]);
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync pReq->GCBaseAddr = GCBaseAddr;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync pReq->cbModule = cbModule;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync pReq->cRegions = cRegions;
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync#ifdef RT_OS_WINDOWS
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync# if ARCH_BITS == 32
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync pReq->enmGuestOS = VBOXOSFAMILY_Windows32;
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync# else
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync pReq->enmGuestOS = VBOXOSFAMILY_Windows64;
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync# endif
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync#else
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync /** todo */
8e9add8eb6b051d148d0e0d3c9153fed3b851269vboxsync pReq->enmGuestOS = VBOXOSFAMILY_Unknown;
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync#endif
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync for (unsigned i = 0; i < cRegions; i++)
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync pReq->aRegions[i] = pRegions[i];
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync if ( RTStrCopy(pReq->szName, sizeof(pReq->szName), pszModuleName) != VINF_SUCCESS
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync || RTStrCopy(pReq->szVersion, sizeof(pReq->szVersion), pszVersion) != VINF_SUCCESS)
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync {
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync rc = VERR_BUFFER_OVERFLOW;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync goto end;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync }
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync rc = vbglR3GRPerform(&pReq->header);
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsyncend:
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync RTMemFree(pReq);
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync return rc;
f8df398d066204e2bf0ba209ea3554fc113fb484vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync}
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync/**
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * Unregisters a shared module for the VM
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync *
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @returns IPRT status code.
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param pszModuleName Module name
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param pszVersion Module version
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param GCBaseAddr Module base address
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @param cbModule Module size
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync */
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsyncVBGLR3DECL(int) VbglR3UnregisterSharedModule(char *pszModuleName, char *pszVersion, RTGCPTR64 GCBaseAddr, uint32_t cbModule)
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync{
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync VMMDevSharedModuleUnregistrationRequest Req;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync vmmdevInitRequest(&Req.header, VMMDevReq_UnregisterSharedModule);
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync Req.GCBaseAddr = GCBaseAddr;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync Req.cbModule = cbModule;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync if ( RTStrCopy(Req.szName, sizeof(Req.szName), pszModuleName) != VINF_SUCCESS
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync || RTStrCopy(Req.szVersion, sizeof(Req.szVersion), pszVersion) != VINF_SUCCESS)
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync {
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync return VERR_BUFFER_OVERFLOW;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync }
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync return vbglR3GRPerform(&Req.header);
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync}
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync/**
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync * Checks registered modules for shared pages
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync *
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync * @returns IPRT status code.
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync */
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsyncVBGLR3DECL(int) VbglR3CheckSharedModules()
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync{
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync VMMDevSharedModuleCheckRequest Req;
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync vmmdevInitRequest(&Req.header, VMMDevReq_CheckSharedModules);
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync return vbglR3GRPerform(&Req.header);
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync}
11cb3503f2fc9b6a75d10d35fe97886703c46dc9vboxsync
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync/**
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync * Checks if page sharing is enabled.
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync *
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync * @returns true/false enabled/disabled
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync */
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsyncVBGLR3DECL(bool) VbglR3PageSharingIsEnabled()
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync{
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync VMMDevPageSharingStatusRequest Req;
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync vmmdevInitRequest(&Req.header, VMMDevReq_GetPageSharingStatus);
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync int rc = vbglR3GRPerform(&Req.header);
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync if (RT_SUCCESS(rc))
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync return Req.fEnabled;
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync return false;
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync}
4f4da0da54c6ffb166be2538d43cd0f79e0eb97cvboxsync