VirtualBox

Ignore:
Timestamp:
Jan 28, 2008 7:50:14 PM (17 years ago)
Author:
vboxsync
Message:

Additions/R3 Guest library: created a reduced version of the library which depends on the X server runtime instead of ours, for use in old X server drivers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp

    r6470 r6538  
    3434#include <iprt/asm.h>
    3535#include <iprt/string.h>
    36 #include <iprt/file.h>
    37 #include <iprt/assert.h>
    38 #include <iprt/mem.h>
    39 #include <iprt/alloca.h>
     36#ifdef VBOX_VBGLR3_XFREE86
     37/* Definitions for X server library functions such as xf86open and mappings to C functions. */
     38/* Make the headers C++-compatible */
     39# define class xf86_vbox_class
     40# define bool xf86_vbox_bool
     41# define private xf86_vbox_private
     42# define new xf86_vbox_new
     43extern "C"
     44{
     45# include "xf86.h"
     46# include "xf86_OSproc.h"
     47# include "xf86Resources.h"
     48# include "xf86_ansic.h"
     49}
     50# undef class
     51# undef bool
     52# undef private
     53# undef new
     54#else
     55# include <iprt/file.h>
     56# include <iprt/assert.h>
     57# include <iprt/thread.h>
     58#endif
    4059#include <VBox/VBoxGuest.h>
    4160#include "VBGLR3Internal.h"
     
    4665*******************************************************************************/
    4766/** The VBoxGuest device handle. */
     67#ifdef VBOX_VBGLR3_XFREE86
     68static int g_File = -1;
     69#else
    4870static RTFILE g_File = NIL_RTFILE;
    49 
     71#endif
     72/**
     73 * A counter of the number of times the library has been initialised, for use with
     74 * X.org drivers, where the library may be shared by multiple independant modules
     75 * inside a single process space.
     76 */
     77static uint32_t g_cInits = 0;
    5078
    5179VBGLR3DECL(int) VbglR3Init(void)
    5280{
    53     if (g_File != NIL_RTFILE)
     81    uint32_t cInits = ASMAtomicIncU32(&g_cInits);
     82#ifdef VBOX_VBGLR3_XFREE86
     83    if (1 != cInits)
    5484        return VINF_SUCCESS;
     85    if (-1 != g_File)
     86        return VERR_INTERNAL_ERROR;
     87#else
     88    Assert(cInits > 0);
     89    if (1 > cInits)
     90    {
     91        /* This will not work when the library is shared inside a multi-threaded
     92           process.  Hopefully no-one will try that, as we can't use the threads
     93           APIs here. */
     94        if (NIL_RTFILE == g_File)
     95            return VERR_INTERNAL_ERROR;
     96        return VINF_SUCCESS;
     97    }
     98    if (NIL_RTFILE != g_File)
     99        return VERR_INTERNAL_ERROR;
     100#endif
    55101
    56102#if defined(RT_OS_OS2)
     
    105151    g_File = hf;
    106152
    107      /* PORTME */
     153#elif defined(VBOX_VBGLR3_XFREE86)
     154    int File = open(VBOXGUEST_DEVICE_NAME, O_RDWR);
     155    if (-1 == File)
     156    {
     157        return VERR_UNRESOLVED_ERROR;
     158    }
     159    g_File = File;
     160
    108161#else
    109162    /* the default implemenation. (linux, solaris) */
     
    122175VBGLR3DECL(void) VbglR3Term(void)
    123176{
     177    uint32_t cInits = ASMAtomicDecU32(&g_cInits);
     178    if (cInits > 0)
     179        return;
     180#ifndef VBOX_VBGLR3_XFREE86
     181    AssertReturnVoid(0 == cInits);
    124182    RTFILE File = g_File;
    125183    g_File = NIL_RTFILE;
    126     if (File == NIL_RTFILE)
     184    AssertReturnVoid(NIL_RTFILE != File);
     185#else
     186    int File = g_File;
     187    g_File = -1;
     188    if (-1 == File)
    127189        return;
     190#endif
    128191#if defined(RT_OS_OS2)
    129192    APIRET rc = DosClose(File);
    130193    AssertMsg(!rc, ("%ld\n", rc));
     194#elif defined(VBOX_VBGLR3_XFREE86)
     195    /* if (-1 == close(File))
     196    {
     197        int iErr = errno;
     198        AssertRC(RTErrConvertFromErrno(iErr));
     199    } */
     200    close(File);  /* iprt is not available here. */
     201    File = -1;
    131202#else
    132203    int rc = RTFileClose(File);
     
    171242    int rc = ioctl((int)g_File, iFunction, &Hdr);
    172243    if (rc == -1)
     244    {
    173245        rc = errno;
    174     return rc;
     246        return RTErrConvertFromErrno(rc);
     247    }
     248    return VINF_SUCCESS;
    175249
    176250#else
    177251    /* Default implementation - PORTME: Do not use this without testings that error passing works! */
     252# ifdef VBOX_VBGLR3_XFREE86
     253    int rc = ioctl(g_File, (int) iFunction, pvData);
     254    if (rc == -1)
     255    {
     256        rc = errno;
     257        return RTErrConvertFromErrno(rc);
     258    }
     259    return VINF_SUCCESS;
     260# else
    178261    int rc2 = VERR_INTERNAL_ERROR;
    179262    int rc = RTFileIoCtl(g_File, (int)iFunction, pvData, cbData, &rc2);
     
    181264        rc = rc2;
    182265    return rc;
    183 #endif
    184 }
    185 
     266# endif
     267#endif
     268}
     269
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette