VirtualBox

Ignore:
Timestamp:
Feb 1, 2024 4:17:38 PM (10 months ago)
Author:
vboxsync
Message:

Guest Control/VbglR3: Made handling the CWD for starting processes more compatible with older VBox hosts (< 7.1). This now only gets set and handled if the host really supports it (by host feature flags). bugref:8053

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestCtrl.cpp

    r102881 r103165  
    6666*********************************************************************************************************************************/
    6767/** Set if GUEST_MSG_PEEK_WAIT and friends are supported. */
    68 static int g_fVbglR3GuestCtrlHavePeekGetCancel = -1;
     68static int      g_fVbglR3GuestCtrlHavePeekGetCancel = -1;
     69/** Represents the currently cached host features 0.
     70 *  Set to 0 if not available / not cached yet. */
     71static uint64_t g_fVbglR3GuestCtrlHostFeatures0 = 0;
     72
     73
     74/*********************************************************************************************************************************
     75*   Prototypes                                                                                                                   *
     76*********************************************************************************************************************************/
     77static int vbglR3GuestCtrlQueryFeatures(uint32_t idClient, uint64_t *pfHostFeatures0, uint64_t *pfHostFeatures1);
     78
     79
     80/**
     81 * Invalidates the internal state of the Guest Control API.
     82 *
     83 * @returns VBox status code.
     84 * @param   idClient        The client ID returned by VbglR3GuestCtrlConnect().
     85 */
     86static int vbglR3GuestCtrlInvalidate(uint32_t idClient)
     87{
     88    uint64_t fVbglR3GuestCtrlHostFeatures0 = 0;
     89    int const rc2 = vbglR3GuestCtrlQueryFeatures(idClient,
     90                                                 &fVbglR3GuestCtrlHostFeatures0, NULL /* pfHostFeatures1, unused */);
     91    if (RT_SUCCESS(rc2))
     92    {
     93        /* Check if the host's feature set has changed. This might happen on a VM restore. */
     94        if (   g_fVbglR3GuestCtrlHostFeatures0
     95            && g_fVbglR3GuestCtrlHostFeatures0 != fVbglR3GuestCtrlHostFeatures0)
     96            LogRelFunc(("Host feature set has changed (%#x -> %#x)\n",
     97                        g_fVbglR3GuestCtrlHostFeatures0, fVbglR3GuestCtrlHostFeatures0));
     98
     99        g_fVbglR3GuestCtrlHostFeatures0 = fVbglR3GuestCtrlHostFeatures0;
     100    }
     101    else
     102        LogRelFunc(("Querying host features not supported, rc=%Rrc\n", rc2));
     103    /* Note: Very old hosts don't know about querying host features, so this isn't fatal for the caller. */
     104
     105    return VINF_SUCCESS;
     106}
    69107
    70108
     
    78116VBGLR3DECL(int) VbglR3GuestCtrlConnect(uint32_t *pidClient)
    79117{
    80     return VbglR3HGCMConnect("VBoxGuestControlSvc", pidClient);
     118    AssertPtrReturn(pidClient, VERR_INVALID_POINTER);
     119
     120    int rc = VbglR3HGCMConnect("VBoxGuestControlSvc", pidClient);
     121    if (RT_SUCCESS(rc))
     122        rc = vbglR3GuestCtrlInvalidate(*pidClient);
     123
     124    return rc;
    81125}
    82126
     
    324368
    325369/**
    326  * Reports features to the host and retrieve host feature set.
     370 * Reports features to the host and retrieve host features set.
    327371 *
    328372 * @returns VBox status code.
     
    364408
    365409/**
    366  * Query the host features.
    367  *
    368  * @returns VBox status code.
    369  * @param   idClient        The client ID returned by VbglR3GuestCtrlConnect().
    370  * @param   pfHostFeatures  Where to store the host feature, VBOX_GUESTCTRL_HF_XXX.
    371  */
    372 VBGLR3DECL(int) VbglR3GuestCtrlQueryFeatures(uint32_t idClient, uint64_t *pfHostFeatures)
     410 * Queries the host features, internal version.
     411 *
     412 * @returns VBox status code.
     413 * @param   idClient         The client ID returned by VbglR3GuestCtrlConnect().
     414 * @param   pfHostFeatures0  Where to store the host features, VBOX_GUESTCTRL_HF_0_XXX.
     415 *                           Optional and can be NULL.
     416 * @param   pfHostFeatures1  Where to store the host features, VBOX_GUESTCTRL_HF_1_XXX.
     417 *                           Currently unused. Optional and can be NULL.
     418 */
     419static int vbglR3GuestCtrlQueryFeatures(uint32_t idClient, uint64_t *pfHostFeatures0, uint64_t *pfHostFeatures1)
    373420{
    374421    int rc;
     
    392439            if (Msg.f64Features1.u.value64 & RT_BIT_64(63))
    393440                rc = VERR_NOT_SUPPORTED;
    394             else if (pfHostFeatures)
    395                 *pfHostFeatures = Msg.f64Features0.u.value64;
     441            else
     442            {
     443                if (pfHostFeatures0)
     444                    *pfHostFeatures0 = Msg.f64Features0.u.value64;
     445                if (pfHostFeatures1)
     446                    *pfHostFeatures1 = Msg.f64Features1.u.value64;
     447            }
    396448            break;
    397449        }
    398450    } while (rc == VERR_INTERRUPTED);
    399451    return rc;
    400 
     452}
     453
     454
     455/**
     456 * Queries the host features.
     457 *
     458 * @returns VBox status code.
     459 * @param   idClient        The client ID returned by VbglR3GuestCtrlConnect().
     460 * @param   pfHostFeatures  Where to store the host features, VBOX_GUESTCTRL_HF_0_XXX. Optional and can be NULL.
     461 */
     462VBGLR3DECL(int) VbglR3GuestCtrlQueryFeatures(uint32_t idClient, uint64_t *pfHostFeatures)
     463{
     464    return vbglR3GuestCtrlQueryFeatures(idClient, pfHostFeatures, NULL /* pfHostFeatures1, unused */);
    401465}
    402466
     
    16741738        VbglHGCMParmUInt32Set(&Msg.cb_env, 0);
    16751739        VbglHGCMParmPtrSet(&Msg.env, pStartupInfo->pszEnv, pStartupInfo->cbEnv);
    1676         if (pCtx->uProtocol < 2)
     1740        if (pCtx->uProtocol < 2) /* Protocol v1, deprecated. */
    16771741        {
    16781742            VbglHGCMParmPtrSet(&Msg.u.v1.username, pStartupInfo->pszUser, pStartupInfo->cbUser);
     
    16801744            VbglHGCMParmUInt32Set(&Msg.u.v1.timeout, 0);
    16811745        }
    1682         else
     1746        else /* Protocol v2. */
    16831747        {
    16841748            VbglHGCMParmUInt32Set(&Msg.u.v2.timeout, 0);
     
    16861750            VbglHGCMParmUInt32Set(&Msg.u.v2.num_affinity, 0);
    16871751            VbglHGCMParmPtrSet(&Msg.u.v2.affinity, pStartupInfo->uAffinity, sizeof(pStartupInfo->uAffinity));
    1688             /* v2.cwd was added in 7.1.  If the host is older, the Msg struct it sends is
    1689              * shorter and these fields are zero-filled, which equals 'no cwd requested'. */
    1690             VbglHGCMParmPtrSet(&Msg.u.v2.cwd, pStartupInfo->pszCwd, pStartupInfo->cbCwd);
    1691         }
    1692 
    1693         rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
     1752        }
     1753
     1754        /* CWD support was added in VBox 7.1. Otherwise just skip setting it. */
     1755        if (g_fVbglR3GuestCtrlHostFeatures0 & VBOX_GUESTCTRL_HF_0_PROCESS_CWD)
     1756            VbglHGCMParmPtrSet(&Msg.cwd, pStartupInfo->pszCwd, pStartupInfo->cbCwd);
     1757
     1758        /*
     1759         * We need to calculate the data size ourselves here and not rely on sizeof(),
     1760         * as sizeof(Msg) might be different to what the host expects.
     1761         *
     1762         * This first was needed when excluding the CWD support for hosts running VBox < 7.1.
     1763         */
     1764        rc = VbglR3HGCMCall(&Msg.hdr, sizeof(VBGLIOCHGCMCALL) + pCtx->uNumParms * sizeof(HGCMFunctionParameter));
    16941765        if (RT_FAILURE(rc))
    16951766        {
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