VBoxGuestR3Lib.cpp revision 4faf92053d9cec5599c0ab8577231df0f7d615b3
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, Core.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * Copyright (C) 2007 Sun Microsystems, Inc.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * available from http://www.virtualbox.org. This file is free software;
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * General Public License (GPL) as published by the Free Software
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * additional information or have any questions.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/*******************************************************************************
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync* Header Files *
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync*******************************************************************************/
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync || defined(RT_OS_LINUX) \
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync# if defined(RT_OS_LINUX) /** @todo check this on solaris+freebsd as well. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/* Rather than try to resolve all the header file conflicts, I will just
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync prototype what we need here. */
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsynctypedef void *pointer;
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsyncextern "C" int xf86ioctl(int, unsigned long, pointer);
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync/*******************************************************************************
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync* Global Variables *
ee5869bb73f07de9c139dc6a608836a7b5767933vboxsync*******************************************************************************/
f6dde23cd488aee26203b38ec67220270f5c4273vboxsync/** The VBoxGuest device handle. */
ee5869bb73f07de9c139dc6a608836a7b5767933vboxsync/** User counter.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * A counter of the number of times the library has been initialised, for use with
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * X.org drivers, where the library may be shared by multiple independant modules
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * inside a single process space.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * Implementation of VbglR3Init and VbglR3InitUser
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * This will fail if two (or more) threads race each other calling VbglR3Init.
d91dc86210d602f51a4701762488a5e696c80a45vboxsync * However it will work fine for single threaded or otherwise serialized
d91dc86210d602f51a4701762488a5e696c80a45vboxsync * processed calling us more than once.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * Have to use CreateFile here as we want to specify FILE_FLAG_OVERLAPPED
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * and possible some other bits not availble thru iprt/file.h.
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * We might wish to compile this with Watcom, so stick to
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync * the OS/2 APIs all the way. And in any case we have to use
f6dde23cd488aee26203b38ec67220270f5c4273vboxsync * DosDevIOCtl for the requests, why not use Dos* for everything.
f6dde23cd488aee26203b38ec67220270f5c4273vboxsync APIRET rc = DosOpen((PCSZ)pszDeviceName, &hf, &ulAction, 0, FILE_NORMAL,
8184f68cdef3c26869cdebc6a18829c854d0d17dvboxsync OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
d91dc86210d602f51a4701762488a5e696c80a45vboxsync unsigned i;
if (!rc)
fulState &= OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT; /* Turn off non-participating bits. */
if (!rc)
return VERR_OPEN_FAILED;
return rc;
return VINF_SUCCESS;
if (cInits > 0)
#if !defined(VBOX_VBGLR3_XFREE86)
# if defined(RT_OS_WINDOWS)
#if defined(RT_OS_WINDOWS)
if (!DeviceIoControl(g_hFile, iFunction, pvData, (DWORD)cbData, pvData, (DWORD)cbData, &cbReturned, NULL))
/** @todo The passing of error codes needs to be tested and fixed (as does *all* the other hosts except for
return VINF_SUCCESS;
return vrc;
return VINF_SUCCESS;
# ifdef VBOX_VBGLR3_XFREE86
return VINF_SUCCESS;
if (rc > 0)
# ifdef VBOX_VBGLR3_XFREE86
return rc;
/* PORTME - This is preferred over the RTFileIOCtl variant below, just be careful with the (int). */
return VINF_SUCCESS;
return rc;