VirtualBox

Changeset 107987 in vbox for trunk


Ignore:
Timestamp:
Jan 30, 2025 10:25:17 AM (3 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
167250
Message:

Windows driver installation: Implemented APIs for controlling (driver SCM) services [build fix, lazy load QueryServiceStatusEx(), required for NT4]. bugref:10762

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/installation/VBoxWinDrvInst.cpp

    r107985 r107987  
    123123typedef BOOL(WINAPI* PFNSETUPUNINSTALLOEMINFW) (PCWSTR InfFileName, DWORD Flags, PVOID Reserved);
    124124typedef BOOL(WINAPI *PFNSETUPSETNONINTERACTIVEMODE) (BOOL NonInteractiveFlag);
     125/* advapi32.dll: */
     126typedef BOOL(WINAPI *PFNQUERYSERVICESTATUSEX) (SC_HANDLE, SC_STATUS_TYPE, LPBYTE, DWORD, LPDWORD);
    125127
    126128/** Function pointer for a general try INF section callback. */
     
    146148DECL_HIDDEN_DATA(PFNSETUPUNINSTALLOEMINFW)               g_pfnSetupUninstallOEMInfW               = NULL; /* For XP+.  */
    147149DECL_HIDDEN_DATA(PFNSETUPSETNONINTERACTIVEMODE)          g_pfnSetupSetNonInteractiveMode          = NULL; /* For W2K+. */
     150/* advapi32.dll: */
     151DECL_HIDDEN_DATA(PFNQUERYSERVICESTATUSEX)                g_pfnQueryServiceStatusEx                = NULL; /* For W2K+. */
    148152
    149153/**
     
    223227};
    224228
     229/* newdev.dll: */
     230static VBOXWINDRVINSTIMPORTSYMBOL s_aAdvApi32Imports[] =
     231{
     232    /* Only for Windows 2000 and up. */
     233    { "QueryServiceStatusEx", (void **)&g_pfnQueryServiceStatusEx }
     234};
     235
    225236
    226237/*********************************************************************************************************************************
     
    525536    /* rc ignored, keep going */ vboxWinDrvInstResolveMod(pCtx, "newdev.dll",
    526537                                                          s_aNewDevImports, RT_ELEMENTS(s_aNewDevImports));
    527 
     538    /* rc ignored, keep going */ vboxWinDrvInstResolveMod(pCtx, "advapi32.dll",
     539                                                          s_aAdvApi32Imports, RT_ELEMENTS(s_aAdvApi32Imports));
    528540    return VINF_SUCCESS;
    529541}
     
    23872399        rc = VERR_NO_CHANGE; /* No change yet. */
    23882400
    2389         vboxWinDrvInstLogInfo(pCtx, "Waiting for status change of service '%s' ...", pszService);
    2390         for (;;)
    2391         {
    2392             DWORD dwBytes;
    2393             if (!QueryServiceStatusEx(hSvc,
    2394                                       SC_STATUS_PROCESS_INFO,
    2395                                       (LPBYTE)&enmSvcSts,
    2396                                       sizeof(SERVICE_STATUS_PROCESS),
    2397                                       &dwBytes))
     2401        if (!g_pfnQueryServiceStatusEx)
     2402        {
     2403            vboxWinDrvInstLogWarn(pCtx, "Waiting for status change of service '%s' not supported on this OS, skipping",
     2404                                  pszService);
     2405            rc = VINF_SUCCESS;
     2406        }
     2407        else
     2408        {
     2409            vboxWinDrvInstLogInfo(pCtx, "Waiting for status change of service '%s' ...", pszService);
     2410            for (;;)
    23982411            {
    2399                 rc = vboxWinDrvInstLogLastError(pCtx, "Failed to query service status");
    2400                 break;
    2401             }
    2402 
    2403             if ((RTTimeMilliTS() - msStartTS) % RT_MS_1SEC == 0) /* Don't spam. */
    2404                 vboxWinDrvInstLogVerbose(pCtx, 3, "Service '%s' status is %#x: %u",
    2405                                          pszService, enmSvcSts.dwCurrentState, (RTTimeMilliTS() - msStartTS) % 100 == 0);
    2406 
    2407             switch (enmSvcSts.dwCurrentState)
    2408             {
    2409                 case SERVICE_STOP_PENDING:
    2410                 case SERVICE_START_PENDING:
    2411                     RTThreadSleep(100); /* Wait a bit before retrying. */
    2412                     break;
    2413 
    2414                 case SERVICE_RUNNING:
     2412                DWORD dwBytes;
     2413                if (!g_pfnQueryServiceStatusEx(hSvc,
     2414                                               SC_STATUS_PROCESS_INFO,
     2415                                               (LPBYTE)&enmSvcSts,
     2416                                               sizeof(SERVICE_STATUS_PROCESS),
     2417                                               &dwBytes))
    24152418                {
    2416                     if (enmFn == VBOXWINDRVSVCFN_START)
    2417                         rc = VINF_SUCCESS;
     2419                    rc = vboxWinDrvInstLogLastError(pCtx, "Failed to query service status");
    24182420                    break;
    24192421                }
    24202422
    2421                 case SERVICE_STOPPED:
     2423                if ((RTTimeMilliTS() - msStartTS) % RT_MS_1SEC == 0) /* Don't spam. */
     2424                    vboxWinDrvInstLogVerbose(pCtx, 3, "Service '%s' status is %#x: %u",
     2425                                             pszService, enmSvcSts.dwCurrentState, (RTTimeMilliTS() - msStartTS) % 100 == 0);
     2426
     2427                switch (enmSvcSts.dwCurrentState)
    24222428                {
    2423                     if (enmFn == VBOXWINDRVSVCFN_START)
     2429                    case SERVICE_STOP_PENDING:
     2430                    case SERVICE_START_PENDING:
     2431                        RTThreadSleep(100); /* Wait a bit before retrying. */
     2432                        break;
     2433
     2434                    case SERVICE_RUNNING:
    24242435                    {
    2425                         vboxWinDrvInstLogError(pCtx, "Service '%s' stopped unexpectedly", pszService);
     2436                        if (enmFn == VBOXWINDRVSVCFN_START)
     2437                            rc = VINF_SUCCESS;
     2438                        break;
     2439                    }
     2440
     2441                    case SERVICE_STOPPED:
     2442                    {
     2443                        if (enmFn == VBOXWINDRVSVCFN_START)
     2444                        {
     2445                            vboxWinDrvInstLogError(pCtx, "Service '%s' stopped unexpectedly", pszService);
     2446                            rc = VERR_INVALID_STATE;
     2447                        }
     2448                        else
     2449                            rc = VINF_SUCCESS;
     2450                        break;
     2451                    }
     2452
     2453                    default:
     2454                    {
     2455                        vboxWinDrvInstLogError(pCtx, "Service '%s' reported an unexpected state (%#x)",
     2456                                               pszService, enmSvcSts.dwCurrentState);
    24262457                        rc = VERR_INVALID_STATE;
    24272458                    }
    2428                     else
    2429                         rc = VINF_SUCCESS;
     2459                }
     2460
     2461                if (   RT_FAILURE(rc)
     2462                    && rc != VERR_NO_CHANGE)
     2463                    break;
     2464
     2465                if (RT_SUCCESS(rc))
     2466                    break;
     2467
     2468                if (RTTimeMilliTS() - msStartTS >= msTimeout)
     2469                {
     2470                    vboxWinDrvInstLogError(pCtx, "Waiting for service '%s' timed out (%ums)", pszService, msTimeout);
     2471                    rc = VERR_TIMEOUT;
    24302472                    break;
    24312473                }
    2432 
    2433                 default:
    2434                 {
    2435                     vboxWinDrvInstLogError(pCtx, "Service '%s' reported an unexpected state (%#x)",
    2436                                            pszService, enmSvcSts.dwCurrentState);
    2437                     rc = VERR_INVALID_STATE;
    2438                 }
    2439             }
    2440 
    2441             if (   RT_FAILURE(rc)
    2442                 && rc != VERR_NO_CHANGE)
    2443                 break;
    2444 
    2445             if (RT_SUCCESS(rc))
    2446                 break;
    2447 
    2448             if (RTTimeMilliTS() - msStartTS >= msTimeout)
    2449             {
    2450                 vboxWinDrvInstLogError(pCtx, "Waiting for service '%s' timed out (%ums)", pszService, msTimeout);
    2451                 rc = VERR_TIMEOUT;
    2452                 break;
    24532474            }
    24542475        }
Note: See TracChangeset for help on using the changeset viewer.

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