SysHlp.cpp revision 3d27b794dc7450a9e848b504a701fb139b3f7e66
/* $Revision$ */
/** @file
* VBoxGuestLibR0 - IDC with VBoxGuest and HGCM helpers.
*/
/*
* Copyright (C) 2006-2009 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#define LOG_GROUP LOG_GROUP_HGCM
#include <VBox/VBoxGuestLib.h>
#include "SysHlp.h"
#ifdef VBGL_VBOXGUEST
#if !defined (RT_OS_WINDOWS)
#endif
/**
* Internal worker for locking a range of linear addresses.
*
* @returns VBox status code.
* @param ppvCtx Where to store context data.
* @param pv The start of the range.
* @param u32Size The size of the range.
* @param fWriteAccess Lock for read-write (true) or readonly (false).
* @param fFlags HGCM call flags, VBGLR0_HGCM_F_XXX.
*/
{
int rc = VINF_SUCCESS;
#ifndef RT_OS_WINDOWS
#endif
/* Zero size buffers shouldn't be locked. */
if (u32Size == 0)
{
#ifdef RT_OS_WINDOWS
#else
*ppvCtx = NIL_RTR0MEMOBJ;
#endif
return VINF_SUCCESS;
}
/** @todo just use IPRT here. the extra allocation shouldn't matter much...
* Then we can move all this up one level even. */
#ifdef RT_OS_WINDOWS
{
}
else
{
__try {
/** @todo (fFlags & VBGLR0_HGCMCALL_F_MODE_MASK) == VBGLR0_HGCMCALL_F_USER? UserMode: KernelMode */
/** @todo */
}
}
#else
/*
* Lock depending on context.
*
* Note: We will later use the memory object here to convert the HGCM
* linear buffer parameter into a physical page list. This is why
* we lock both kernel pages on all systems, even those where we
* know they aren't pageable.
*/
else
if (RT_SUCCESS(rc))
else
*ppvCtx = NIL_RTR0MEMOBJ;
#endif
return rc;
}
{
#ifdef RT_OS_WINDOWS
{
}
#else
#endif
}
#else /* !VBGL_VBOXGUEST */
# ifdef RT_OS_OS2
/*
* On OS/2 we'll do the connecting in the assembly code of the
* client driver, exporting a g_VBoxGuestIDC symbol containing
* the connection information obtained from the 16-bit IDC.
*/
extern VBOXGUESTOS2IDCCONNECT g_VBoxGuestIDC;
# endif
# if !defined(RT_OS_OS2) \
&& !defined(RT_OS_WINDOWS)
extern DECLVBGL(int) VBoxGuestIDCCall (void *pvOpaque, unsigned int iCmd, void *pvData, size_t cbSize, size_t *pcbReturn);
# endif
{
# ifdef RT_OS_WINDOWS
# else
# endif
}
{
# ifdef RT_OS_WINDOWS
&pFileObject, &pDeviceObject);
if (NT_SUCCESS (rc))
{
return VINF_SUCCESS;
}
/** @todo return RTErrConvertFromNtStatus(rc)! */
return rc;
/*
* Just check whether the connection was made or not.
*/
{
return VINF_SUCCESS;
}
Log(("vbglDriverOpen: failed\n"));
return VERR_FILE_NOT_FOUND;
# else
&& u32VMMDevVersion == VMMDEV_VERSION)
return VINF_SUCCESS;
Log(("vbglDriverOpen: failed\n"));
return VERR_FILE_NOT_FOUND;
# endif
}
# ifdef RT_OS_WINDOWS
{
return STATUS_MORE_PROCESSING_REQUIRED;
}
# endif
{
Log(("vbglDriverIOCtl: pDriver: %p, Func: %x, pvData: %p, cbData: %d\n", pDriver, u32Function, pvData, cbData));
# ifdef RT_OS_WINDOWS
/* Have to use the IoAllocateIRP method because this code is generic and
* must work in any thread context.
* The IoBuildDeviceIoControlRequest, which was used here, does not work
* when APCs are disabled, for example.
*/
{
Log(("vbglDriverIOCtl: IRP allocation failed!\n"));
return VERR_NO_MEMORY;
}
/*
* Setup the IRP_MJ_DEVICE_CONTROL IRP.
*/
nextStack->MinorFunction = 0;
/* A completion routine is required to signal the Event. */
if (NT_SUCCESS (rc))
{
/* Wait the event to be signalled by the completion routine. */
NULL);
}
if (rc != STATUS_SUCCESS)
if ( pDriver->u32Session
Log(("vbglDriverIOCtl: No connection\n"));
return VERR_WRONG_ORDER;
# else
# endif
}
{
# ifdef RT_OS_WINDOWS
pDriver->u32Session = 0;
# else
# endif
}
#endif /* !VBGL_VBOXGUEST */