VirtualBox

Changeset 6132 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 18, 2007 4:06:36 PM (17 years ago)
Author:
vboxsync
Message:

Fixed guest driver session handling, fixed daemonizing. timesync works.

Location:
trunk/src/VBox/Additions/common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-solaris.c

    r6118 r6132  
    162162    /** VMMDev Version. */
    163163    uint32_t                u32Version;
     164#ifndef USE_SESSION_HASH
     165    /** Pointer to the session handle. */
     166    PVBOXGUESTSESSION       pSession;
     167#endif
    164168} VBoxAddDevState;
    165169
     
    174178/** Spinlock protecting g_apSessionHashTab. */
    175179static RTSPINLOCK           g_Spinlock = NIL_RTSPINLOCK;
     180#ifdef USE_SESSION_HASH
    176181/** Hash table */
    177182static PVBOXGUESTSESSION    g_apSessionHashTab[19];
    178183/** Calculates the index into g_apSessionHashTab.*/
    179184#define SESSION_HASH(sfn) ((sfn) % RT_ELEMENTS(g_apSessionHashTab))
     185#endif /* USE_SESSION_HASH */
    180186
    181187/** GCC C++ hack. */
     
    238244
    239245            instance = ddi_get_instance(pDip);
     246#ifdef USE_SESSION_HASH
    240247            rc = ddi_soft_state_zalloc(g_pVBoxAddSolarisState, instance);
    241248            if (rc != DDI_SUCCESS)
     
    252259                return DDI_FAILURE;
    253260            }
     261#else
     262            pState = RTMemAllocZ(sizeof(VBoxAddDevState));
     263            if (!pState)
     264            {
     265                VBA_LOGNOTE("RTMemAllocZ failed to allocate %d bytes\n", sizeof(VBoxAddDevState));
     266                return DDI_FAILURE;
     267            }
     268#endif
    254269
    255270            /*
     
    405420            int rc;
    406421            int instance = ddi_get_instance(pDip);
     422#ifdef USE_SESSION_HASH
    407423            VBoxAddDevState *pState = ddi_get_soft_state(g_pVBoxAddSolarisState, instance);
     424#else
     425            VBoxAddDevState *pState = ddi_get_driver_private(g_pDip);
     426#endif
    408427            if (pState)
    409428            {
     
    412431                ddi_regs_map_free(&pState->PciMMIOHandle);
    413432                ddi_remove_minor_node(pDip, NULL);
     433#ifdef USE_SESSION_HASH
    414434                ddi_soft_state_free(g_pVBoxAddSolarisState, instance);
     435#else
     436                RTMemFree(pState);
     437#endif
    415438
    416439                rc = RTSpinlockDestroy(g_Spinlock);
     
    480503    VBA_LOGCONT("VBoxAddSolarisOpen\n");
    481504
     505#ifndef USE_SESSION_HASH
     506    VBoxAddDevState *pState = NULL;
     507    unsigned iOpenInstance;
     508    for (iOpenInstance = 0; iOpenInstance < 4096; iOpenInstance++)
     509    {
     510        if (    !ddi_get_soft_state(g_pVBoxAddSolarisState, iOpenInstance) /* faster */
     511            &&  ddi_soft_state_zalloc(g_pVBoxAddSolarisState, iOpenInstance) == DDI_SUCCESS)
     512        {
     513            pState = ddi_get_soft_state(g_pVBoxAddSolarisState, iOpenInstance);
     514            break;
     515        }
     516    }
     517    if (!pState)
     518    {
     519        VBA_LOGNOTE("VBoxAddSolarisOpen: too many open instances.");
     520        return ENXIO;
     521    }
     522
     523    /*
     524     * Create a new session.
     525     */
     526    rc = VBoxGuestCreateUserSession(&g_DevExt, &pSession);
     527    if (RT_SUCCESS(rc))
     528    {
     529        pState->pSession = pSession;
     530        VBA_LOGCONT("VBoxAddSolarisOpen: pSession=%p pState=%p\n", pSession, pState);
     531        return 0;
     532    }
     533
     534    /* Failed, clean up. */
     535    ddi_soft_state_free(g_pVBoxAddSolarisState, iOpenInstance);
     536#else
    482537    /*
    483538     * Create a new session.
     
    500555        return 0;
    501556    }
     557#endif
    502558    LogRel(("VBoxAddSolarisOpen: VBoxGuestCreateUserSession failed. rc=%d\n", rc));
    503559    return rc;
     
    509565    VBA_LOGCONT("VBoxAddSolarisClose pid=%d\n", (int)RTProcSelf());
    510566
     567#ifdef USE_SESSION_HASH
    511568    /*
    512569     * Remove from the hash table.
     
    551608        return VERR_INVALID_PARAMETER;
    552609    }
     610#else
     611    PVBOXGUESTSESSION pSession;
     612    VBoxAddDevState *pState = ddi_get_soft_state(g_pVBoxAddSolarisState, getminor(Dev));
     613    if (!pState)
     614    {
     615        VBA_LOGNOTE("VBoxAddSolarisClose: failed to get pState.\n");
     616        return DDI_FAILURE;
     617    }
     618
     619    pSession = pState->pSession;
     620    pState->pSession = NULL;
     621    ddi_soft_state_free(g_pVBoxAddSolarisState, getminor(Dev));
     622    if (!pSession)
     623    {
     624        VBA_LOGNOTE("VBoxAddSolarisClose: failed to get pSession.\n");
     625        return DDI_FAILURE;
     626    }
     627#endif
    553628
    554629    /*
     
    598673
    599674    /** @todo use the faster way to find pSession (using the soft state) */
     675#ifdef USE_SESSION_HASH
    600676    RTSPINLOCKTMP       Tmp = RTSPINLOCKTMP_INITIALIZER;
    601677    const RTPROCESS     Process = RTProcSelf();
     
    620696        return EINVAL;
    621697    }
     698#else
     699    /*
     700     * Get the session from the soft state item.
     701     */
     702    VBoxAddDevState *pState = ddi_get_soft_state(g_pVBoxAddSolarisState, getminor(Dev));
     703    if (!pState)
     704    {
     705        VBA_LOGNOTE("VBoxAddSolarisIOCtl: no state data for %d\n", getminor(Dev));
     706        return EINVAL;
     707    }
     708
     709    PVBOXGUESTSESSION pSession = pState->pSession;
     710    if (!pSession)
     711    {
     712        VBA_LOGNOTE("VBoxAddSolarisIOCtl: no session data for %d\n", getminor(Dev));
     713        return DDI_SUCCESS;
     714    }
     715#endif
    622716
    623717    /** @todo I'll remove this size check after testing. */
     
    691785#endif
    692786
    693     cbBuf = IOCPARM_LEN(Cmd);   
     787    cbBuf = IOCPARM_LEN(Cmd);
    694788    void *pvBuf = RTMemTmpAlloc(cbBuf);
    695789    if (RT_UNLIKELY(!pvBuf))
  • trunk/src/VBox/Additions/common/VBoxService/Makefile.kmk

    r6118 r6132  
    3939        $(VBOX_LIB_VBGL_R3) \
    4040        $(VBOX_LIB_IPRT_GUEST_R3)
     41VBoxService_LIBS.solaris  = daemon
    4142
    4243include $(PATH_KBUILD)/subfooter.kmk
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService-solaris.cpp

    r6121 r6132  
    2626#include <signal.h>
    2727#include <fcntl.h>
     28#include <libdaemon/dfork.h>
     29#include <libdaemon/dsignal.h>
    2830
    2931/**
    30  * Solaris daemon() call. Probably might work for other Unix.
     32 * Solaris daemon() call uses libdaemon.
    3133 *
    3234 * @returns 0 on success
     
    3436int daemon(int nochdir, int noclose)
    3537{
     38    pid_t pid = daemon_fork();
     39    if (pid < 0)
     40    {
     41        daemon_retval_done();
     42        return -1;
     43    }
     44
     45    if (pid)
     46        exit(0);
     47
     48    daemon_close_all(-1);
     49    return 0;
     50#if 0
    3651    if (getppid() == 1) /* We already belong to init process */
    3752        return -1;
     
    5267    int size = getdtablesize();
    5368    if (size < 0)
    54         size = 3;
     69        size = 2;
    5570
    5671    for (int i = size; i >= 0; i--)
     
    7489    }
    7590    return 0;
     91#endif
    7692}
    7793
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