VirtualBox

Changeset 6360 in vbox


Ignore:
Timestamp:
Jan 15, 2008 5:37:15 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27282
Message:

Guest Additions NT4: Dynamic display resizing works now.

Guest Additions NT4: Bugfix: VBoxService was eating up 99% of CPU time.

Location:
trunk/src/VBox/Additions/WINNT/VBoxService
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxDisplay.cpp

    r5999 r6360  
    3333    /* ChangeDisplaySettingsEx does not exist in NT. ResizeDisplayDevice uses the function. */
    3434    LONG (WINAPI * pfnChangeDisplaySettingsEx)(LPCTSTR lpszDeviceName, LPDEVMODE lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam);
     35
     36    /* EnumDisplayDevices does not exist in NT. isVBoxDisplayDriverActive et al. are using these functions. */
     37    BOOL (WINAPI * pfnEnumDisplayDevices)(IN LPCSTR lpDevice, IN DWORD iDevNum, OUT PDISPLAY_DEVICEA lpDisplayDevice, IN DWORD dwFlags);
     38
    3539} VBOXDISPLAYCONTEXT;
    3640
     
    3943int VBoxDisplayInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
    4044{
     45    OSVERSIONINFO OSinfo;
     46    OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
     47    GetVersionEx (&OSinfo);
     48
    4149    HMODULE hUser = GetModuleHandle("USER32");
    4250
    4351    gCtx.pEnv = pEnv;
    4452
    45     if (hUser)
     53    if (NULL == hUser)
     54    {
     55        dprintf(("VBoxService: Could not get module handle of USER32.DLL!\n"));
     56        return VERR_NOT_IMPLEMENTED;
     57    }
     58    else if (OSinfo.dwMajorVersion >= 5)        /* APIs available only on W2K and up! */
    4659    {
    4760        *(uintptr_t *)&gCtx.pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
    48         dprintf(("VBoxService: pChangeDisplaySettingsEx = %p\n", gCtx.pfnChangeDisplaySettingsEx));
    49     }
     61        dprintf(("VBoxService: pfnChangeDisplaySettingsEx = %p\n", gCtx.pfnChangeDisplaySettingsEx));
     62
     63        *(uintptr_t *)&gCtx.pfnEnumDisplayDevices = (uintptr_t)GetProcAddress(hUser, "EnumDisplayDevicesA");
     64        dprintf(("VBoxService: pfnEnumDisplayDevices = %p\n", gCtx.pfnEnumDisplayDevices));
     65    }
     66    else if (OSinfo.dwMajorVersion <= 4)            /* Windows NT 4.0 */
     67    {
     68        /* Nothing to do here yet */
     69    }
     70    else                                /* Unsupported platform */
     71    {
     72        dprintf(("VBoxService: Warning, display for platform not handled yet!\n"));
     73        return VERR_NOT_IMPLEMENTED;
     74    }
     75
     76    dprintf(("VBoxService: Display init successful.\n"));
    5077
    5178    *pfStartThread = true;
     
    5986}
    6087
    61 static bool isVBoxDisplayDriverActive (void)
     88static bool isVBoxDisplayDriverActive (VBOXDISPLAYCONTEXT *pCtx)
    6289{
    6390    bool result = false;
    6491
    65     DISPLAY_DEVICE dispDevice;
    66 
    67     FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
    68 
    69     dispDevice.cb = sizeof(DISPLAY_DEVICE);
    70 
    71     INT devNum = 0;
    72 
    73     while (EnumDisplayDevices(NULL,
    74                               devNum,
    75                               &dispDevice,
    76                               0))
    77     {
    78         dprintf(("DevNum:%d\nName:%s\nString:%s\nID:%s\nKey:%s\nFlags=%08X\n\n",
    79                       devNum,
    80                       &dispDevice.DeviceName[0],
    81                       &dispDevice.DeviceString[0],
    82                       &dispDevice.DeviceID[0],
    83                       &dispDevice.DeviceKey[0],
    84                       dispDevice.StateFlags));
    85 
    86         if (dispDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
    87         {
    88             dprintf(("Primary device.\n"));
    89 
    90             if (strcmp(&dispDevice.DeviceString[0], "VirtualBox Graphics Adapter") == 0)
     92    if( pCtx->pfnEnumDisplayDevices )
     93    {
     94        INT devNum = 0;
     95        DISPLAY_DEVICE dispDevice;
     96        FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
     97        dispDevice.cb = sizeof(DISPLAY_DEVICE);
     98
     99        dprintf(("Checking for active VBox display driver (W2K+)...\n"));
     100
     101        while (EnumDisplayDevices(NULL,
     102                                  devNum,
     103                                  &dispDevice,
     104                                  0))
     105        {
     106            dprintf(("DevNum:%d\nName:%s\nString:%s\nID:%s\nKey:%s\nFlags=%08X\n\n",
     107                          devNum,
     108                          &dispDevice.DeviceName[0],
     109                          &dispDevice.DeviceString[0],
     110                          &dispDevice.DeviceID[0],
     111                          &dispDevice.DeviceKey[0],
     112                          dispDevice.StateFlags));
     113   
     114            if (dispDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
    91115            {
    92                 dprintf(("VBox display driver is active.\n"));
    93                 result = true;
     116                dprintf(("Primary device.\n"));
     117   
     118                if (strcmp(&dispDevice.DeviceString[0], "VirtualBox Graphics Adapter") == 0)
     119                    result = true;
     120   
     121                break;
    94122            }
    95 
    96             break;
    97         }
    98 
    99         FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
    100 
    101         dispDevice.cb = sizeof(DISPLAY_DEVICE);
    102 
    103         devNum++;
     123   
     124            FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
     125   
     126            dispDevice.cb = sizeof(DISPLAY_DEVICE);
     127   
     128            devNum++;
     129        }
     130    }
     131    else    /* This must be NT 4 or something really old, so don't use EnumDisplayDevices() here  ... */
     132    {       
     133        dprintf(("Checking for active VBox display driver (NT or older)...\n"));
     134
     135        DEVMODE tempDevMode;
     136        ZeroMemory (&tempDevMode, sizeof (tempDevMode));
     137        tempDevMode.dmSize = sizeof(DEVMODE);
     138        EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &tempDevMode);     /* Get current display device settings */
     139
     140        /* Check for the short name, because all long stuff would be truncated */
     141        if (strcmp((char*)&tempDevMode.dmDeviceName[0], "VBoxDisp") == 0)
     142            result = true;
    104143    }
    105144
     
    272311            paDeviceModes[i].dmBitsPerPel = BitsPerPixel;
    273312        }
    274 dprintf(("calling pfnChangeDisplaySettingsEx %x\n", gCtx.pfnChangeDisplaySettingsEx));     
     313
     314        dprintf(("calling pfnChangeDisplaySettingsEx %x\n", gCtx.pfnChangeDisplaySettingsEx));     
     315
    275316        gCtx.pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName,
    276                  &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL);
     317                                        &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL);
     318
    277319        dprintf(("ChangeDisplaySettings position err %d\n", GetLastError ()));
    278320    }
     
    372414                         * Only try to change video mode if the active display driver is VBox additions.
    373415                         */
    374                         if (isVBoxDisplayDriverActive ())
     416                        if (isVBoxDisplayDriverActive (pCtx))
    375417                        {
     418                            dprintf(("VBoxDisplayThread : Display driver is active!\n"));
     419
    376420                            if (pCtx->pfnChangeDisplaySettingsEx != 0)
    377421                            {
     422                                dprintf(("VBoxDisplayThread : Detected W2K or later."));
     423
    378424                                /* W2K or later. */
    379425                                if (!ResizeDisplayDevice(displayChangeRequest.display,
     
    387433                            else
    388434                            {
     435                                dprintf(("VBoxDisplayThread : Detected NT.\n"));
     436
    389437                                /* Single monitor NT. */
    390438                                DEVMODE devMode;
     
    413461                                    {
    414462                                        /* All zero values means a forced mode reset. Do nothing. */
     463                                        dprintf(("VBoxDisplayThread : Forced mode reset.\n"));
    415464                                    }
    416465
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxDisplay.h

    r5999 r6360  
    2323void               VBoxDisplayDestroy (const VBOXSERVICEENV *pEnv, void *pInstance);
    2424
     25static bool isVBoxDisplayDriverActive (void);
    2526
    2627#endif /* __VBOXSERVICEDISPLAY__H */
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxSeamless.cpp

    r5999 r6360  
    5656    gCtx.pEnv = pEnv;
    5757
     58    OSVERSIONINFO OSinfo;
     59    OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
     60    GetVersionEx (&OSinfo);
     61
     62    /* We have to jump out here when using NT4, otherwise it complains about
     63       a missing API function "UnhookWinEvent" used by the dynamically loaded VBoxHook.dll below */
     64    if (OSinfo.dwMajorVersion <= 4)         /* Windows NT 4.0 or older */
     65    {
     66        dprintf(("VBoxSeamlessInit: Windows NT 4.0 or older not supported!"));
     67        return VERR_NOT_SUPPORTED;
     68    }
     69
    5870    /* Will fail if SetWinEventHook is not present (version < NT4 SP6 apparently) */
    5971    gCtx.hModule = LoadLibrary(VBOXHOOK_DLL_NAME);
     
    7284                             &vmmreqGuestCaps, sizeof(vmmreqGuestCaps), &cbReturned, NULL))
    7385        {
    74             dprintf(("VMMDevReq_ReportGuestCapabilities: error doing IOCTL, last error: %d\n", GetLastError()));
     86            dprintf(("VBoxSeamlessInit: VMMDevReq_ReportGuestCapabilities: error doing IOCTL, last error: %d\n", GetLastError()));
    7587            return VERR_INVALID_PARAMETER;
    7688        }
     
    8294    else
    8395    {
    84         dprintf(("VBoxSeamlessInit LoadLibrary failed with %d\n", GetLastError()));
     96        dprintf(("VBoxSeamlessInit: LoadLibrary failed with %d\n", GetLastError()));
    8597        return VERR_INVALID_PARAMETER;
    8698    }
     
    405417}
    406418
    407 
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxService.cpp

    r6169 r6360  
    3030
    3131#include "helpers.h"
    32 
    3332#include <sddl.h>
    3433
     
    6968    pReq->header.size += strlen(pReq->szString);
    7069
     70    printf("%s\n", pReq->szString);
     71
     72    FILE* pFh = fopen("c:\\VBoxServiceDebug.txt", "at");
     73
     74    /* Does maybe not work on Vista (write protection when starting without admin rights),
     75       so do this check! */
     76    if (NULL != pFh)       
     77    {
     78        fprintf(pFh, "%s", pReq->szString);
     79        fclose(pFh);
     80    }
     81
    7182    DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_VMMREQUEST, pReq, pReq->header.size,
    7283                    pReq, pReq->header.size, &cbReturned, NULL);
     
    135146static int vboxStartServices (VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
    136147{
     148    dprintf(("VBoxService: Starting services...\n"));
     149
    137150    pEnv->hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    138151
     
    262275    if (gVBoxDriver == INVALID_HANDLE_VALUE)
    263276    {
    264         dprintf(("VBoxService: could not open VBox Guest Additions driver! rc = %d\n", GetLastError()));
     277        dprintf(("VBoxService: could not open VBox Guest Additions driver! Please install / start it first! rc = %d\n", GetLastError()));
    265278        status = ERROR_GEN_FAILURE;
    266279    }
     
    315328        if (gStopSem == NULL)
    316329        {
    317             dprintf(("VBoxService: CreateEvent failed: rc = %d\n", GetLastError()));
     330            dprintf(("VBoxService: CreateEvent for Stopping failed: rc = %d\n", GetLastError()));
    318331            return;
    319332        }
     
    377390        }
    378391
    379         ghSeamlessNotifyEvent = CreateEvent(&SecAttr, FALSE, FALSE, VBOXHOOK_GLOBAL_EVENT_NAME);
    380         if (ghSeamlessNotifyEvent == NULL)
    381         {
    382             dprintf(("VBoxService: CreateEvent failed: rc = %d\n", GetLastError()));
    383             return;
     392        if (dwMajorVersion >= 5)        /* Only for W2K and up ... */
     393        {
     394            ghSeamlessNotifyEvent = CreateEvent(&SecAttr, FALSE, FALSE, VBOXHOOK_GLOBAL_EVENT_NAME);
     395            if (ghSeamlessNotifyEvent == NULL)
     396            {
     397                dprintf(("VBoxService: CreateEvent for Seamless failed: rc = %d\n", GetLastError()));
     398                return;
     399            }
    384400        }
    385401    }
     
    430446     * Wait for the stop semaphore to be posted or a window event to arrive
    431447     */
     448
     449    DWORD dwEventCount = 2;
    432450    HANDLE hWaitEvent[2] = {gStopSem, ghSeamlessNotifyEvent};
     451
     452    if (0 == ghSeamlessNotifyEvent)         /* If seamless mode is not active / supported, reduce event array count */
     453        dwEventCount = 1;                       
     454
     455    dprintf(("VBoxService: Number of events to wait in main loop: %ld\n", dwEventCount));
     456
    433457    while(true)
    434458    {
    435         DWORD waitResult = MsgWaitForMultipleObjectsEx(2, hWaitEvent, 500, QS_ALLINPUT, 0);
    436         if (waitResult == WAIT_OBJECT_0)
    437         {
    438             dprintf(("VBoxService: exit\n"));
     459        DWORD waitResult = MsgWaitForMultipleObjectsEx(dwEventCount, hWaitEvent, 500, QS_ALLINPUT, 0);
     460        waitResult = waitResult - WAIT_OBJECT_0;
     461
     462        dprintf(("VBoxService: Wait result  = %ld.\n", waitResult));
     463
     464        if (waitResult == 0)
     465        {
     466            dprintf(("VBoxService: Event 'Exit' triggered.\n"));
    439467            /* exit */
    440468            break;
    441469        }
    442         else
    443         if (waitResult == WAIT_OBJECT_0+1)
    444         {
     470        else if ((waitResult == 1) && (ghSeamlessNotifyEvent!=0))       /* Only jump in, if seamless is active! */
     471        {
     472            dprintf(("VBoxService: Event 'Seamless' triggered.\n"));
     473
    445474            /* seamless window notification */
    446475            VBoxSeamlessCheckWindows();
     
    504533    dprintf(("VBoxService: WinMain\n"));
    505534    gInstance = hInstance;
    506     VBoxServiceStart ();
     535    VBoxServiceStart();
     536   
    507537    return 0;
    508538}
     
    546576    return 0;
    547577}
    548 
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